Print this page
Review from Robert, and nits
Review from Yuri

@@ -333,16 +333,14 @@
 typedef enum {
         GNU,
         SUN
 } compiler_style_t;
 
-#define COMPILER_STYLE(comp) (comp->style == SUN ? "cc" : "gcc")
-
 typedef struct {
-        char *name;
-        char *path;
-        compiler_style_t style;
+        char *c_name;
+        char *c_path;
+        compiler_style_t c_style;
 } cw_compiler_t;
 
 typedef struct cw_ictx {
         cw_compiler_t   *i_compiler;
         struct aelist   *i_ae;

@@ -452,11 +450,11 @@
 };
 
 static void
 nomem(void)
 {
-        (void) errx(1, "out of memory");
+        errx(1, "out of memory");
 }
 
 static void
 newae(struct aelist *ael, const char *arg)
 {

@@ -521,11 +519,11 @@
         }
 }
 
 /* ARGSUSED */
 static void
-Xamode(struct aelist *h __attribute__((__unused__)))
+Xamode(struct aelist __unused *h)
 {
 }
 
 static void
 Xcmode(struct aelist *h)

@@ -656,11 +654,11 @@
          *
          * -Dunix is also missing in enhanced ANSI mode
          */
         newae(ctx->i_ae, "-D__sun");
 
-        if (asprintf(&nameflag, "-_%s=", ctx->i_compiler->name) == -1)
+        if (asprintf(&nameflag, "-_%s=", ctx->i_compiler->c_name) == -1)
                 nomem();
 
         /*
          * Walk the argument list, translating as we go ..
          */

@@ -1405,21 +1403,21 @@
 
         free(nameflag);
 
         if (c_files > 1 && (ctx->i_flags & CW_F_SHADOW) &&
             op != CW_O_PREPROCESS) {
-                (void) errx(2, "multiple source files are "
+                errx(2, "multiple source files are "
                     "allowed only with -E or -P");
         }
 
         /*
          * Make sure that we do not have any unintended interactions between
          * the xarch options passed in and the version of the Studio compiler
          * used.
          */
         if ((mflag & (SS11|SS12)) == (SS11|SS12)) {
-                (void) errx(2,
+                errx(2,
                     "Conflicting \"-xarch=\" flags (both Studio 11 and 12)\n");
         }
 
         switch (mflag) {
         case 0:

@@ -1496,11 +1494,11 @@
         if (ctx->i_flags & CW_F_PROG) {
                 newae(ctx->i_ae, "-V");
                 return;
         }
 
-        if (asprintf(&nameflag, "-_%s=", ctx->i_compiler->name) == -1)
+        if (asprintf(&nameflag, "-_%s=", ctx->i_compiler->c_name) == -1)
                 nomem();
 
         while (--ctx->i_oldargc > 0) {
                 char *arg = *++ctx->i_oldargv;
 

@@ -1572,22 +1570,22 @@
 }
 
 static void
 prepctx(cw_ictx_t *ctx)
 {
-        newae(ctx->i_ae, ctx->i_compiler->path);
+        newae(ctx->i_ae, ctx->i_compiler->c_path);
 
         if (ctx->i_flags & CW_F_PROG) {
                 (void) printf("%s: %s\n", (ctx->i_flags & CW_F_SHADOW) ?
-                    "shadow" : "primary", ctx->i_compiler->path);
+                    "shadow" : "primary", ctx->i_compiler->c_path);
                 (void) fflush(stdout);
         }
 
         if (!(ctx->i_flags & CW_F_XLATE))
                 return;
 
-        switch (ctx->i_compiler->style) {
+        switch (ctx->i_compiler->c_style) {
         case SUN:
                 do_cc(ctx);
                 break;
         case GNU:
                 do_gcc(ctx);

@@ -1756,29 +1754,29 @@
 parse_compiler(const char *spec, cw_compiler_t *compiler)
 {
         char *tspec, *token;
 
         if ((tspec = strdup(spec)) == NULL)
-                err(1, "out of memory");
+                nomem();
 
         if ((token = strsep(&tspec, ",")) == NULL)
                 errx(1, "Compiler is missing a name: %s", spec);
-        compiler->name = token;
+        compiler->c_name = token;
 
         if ((token = strsep(&tspec, ",")) == NULL)
                 errx(1, "Compiler is missing a path: %s", spec);
-        compiler->path = token;
+        compiler->c_path = token;
 
         if ((token = strsep(&tspec, ",")) == NULL)
                 errx(1, "Compiler is missing a style: %s", spec);
 
         if ((strcasecmp(token, "gnu") == 0) ||
             (strcasecmp(token, "gcc") == 0))
-                compiler->style = GNU;
+                compiler->c_style = GNU;
         else if ((strcasecmp(token, "sun") == 0) ||
             (strcasecmp(token, "cc") == 0))
-                compiler->style = SUN;
+                compiler->c_style = SUN;
         else
                 errx(1, "unknown compiler style: %s", token);
 
         if (tspec != NULL)
                 errx(1, "Excess tokens in compiler: %s", spec);

@@ -1799,21 +1797,26 @@
         boolean_t vflg = B_FALSE;
         boolean_t Cflg = B_FALSE;
         boolean_t cflg = B_FALSE;
         boolean_t nflg = B_FALSE;
 
-        cw_ictx_t *main_ctx = newictx();
+        cw_ictx_t *main_ctx;
 
         static struct option longopts[] = {
                 { "compiler", no_argument, NULL, 'c' },
-                { "noecho", no_argument, NULL ,'n' },
+                { "noecho", no_argument, NULL, 'n' },
                 { "primary", required_argument, NULL, 'p' },
                 { "shadow", required_argument, NULL, 's' },
                 { "versions", no_argument, NULL, 'v' },
                 { NULL, 0, NULL, 0 },
         };
 
+
+        if ((main_ctx = newictx()) == NULL)
+                nomem();
+
+
         while ((ch = getopt_long(argc, argv, "C", longopts, NULL)) != -1) {
                 switch (ch) {
                 case 'c':
                         cflg = B_TRUE;
                         break;

@@ -1822,35 +1825,39 @@
                         break;
                 case 'n':
                         nflg = B_TRUE;
                         break;
                 case 'p':
-                        if (primary.path != NULL) {
-                                warnx("Only one primary compiler may be specified");
+                        if (primary.c_path != NULL) {
+                                warnx("Only one primary compiler may "
+                                    "be specified");
                                 usage();
                         }
 
                         if (parse_compiler(optarg, &primary) != 0)
-                                errx(1, "Couldn't parse %s as a compiler spec", optarg);
+                                errx(1, "Couldn't parse %s as a compiler spec",
+                                    optarg);
                         break;
                 case 's':
                         if (nshadows >= 10)
-                                errx(1, "May only use 10 shadows at the moment");
+                                errx(1, "May only use 10 shadows at "
+                                    "the moment");
                         if (parse_compiler(optarg, &shadows[nshadows]) != 0)
-                                errx(1, "Couldn't parse %s as a compiler spec", optarg);
+                                errx(1, "Couldn't parse %s as a compiler spec",
+                                    optarg);
                         nshadows++;
                         break;
                 case 'v':
                         vflg = B_TRUE;
                         break;
                 default:
-                        fprintf(stderr, "Did you forget '--'?\n");
+                        (void) fprintf(stderr, "Did you forget '--'?\n");
                         usage();
                 }
         }
 
-        if (primary.path == NULL) {
+        if (primary.c_path == NULL) {
                 warnx("A primary compiler must be specified");
                 usage();
         }
 
         do_serial = (getenv("CW_SHADOW_SERIAL") == NULL) ? B_FALSE : B_TRUE;

@@ -1858,13 +1865,10 @@
 
         /* Leave room for argv[0] */
         argc -= (optind - 1);
         argv += (optind - 1);
 
-        if (main_ctx == NULL)
-                nomem();
-
         main_ctx->i_oldargc = argc;
         main_ctx->i_oldargv = argv;
         main_ctx->i_flags = CW_F_XLATE;
         if (nflg == 0)
                 main_ctx->i_flags |= CW_F_ECHO;

@@ -1873,11 +1877,11 @@
         if (Cflg)
                 main_ctx->i_flags |= CW_F_CXX;
         main_ctx->i_compiler = &primary;
 
         if (cflg) {
-                fputs(primary.path, stdout);
+                (void) fputs(primary.c_path, stdout);
         }
 
         if (vflg) {
                 (void) printf("cw version %s\n", CW_VERSION);
                 (void) fflush(stdout);

@@ -1887,13 +1891,13 @@
         }
 
         ret |= exec_ctx(main_ctx, do_serial);
 
         for (int i = 0; i < nshadows; i++) {
-                cw_ictx_t *shadow_ctx = newictx();
+                cw_ictx_t *shadow_ctx;
 
-                if (shadow_ctx == NULL)
+                if ((shadow_ctx = newictx()) == NULL)
                         nomem();
 
                 memcpy(shadow_ctx, main_ctx, sizeof (cw_ictx_t));
 
                 shadow_ctx->i_flags |= CW_F_SHADOW;