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

*** 333,348 **** 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; } cw_compiler_t; typedef struct cw_ictx { cw_compiler_t *i_compiler; struct aelist *i_ae; --- 333,346 ---- typedef enum { GNU, SUN } compiler_style_t; typedef struct { ! 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,462 **** }; static void nomem(void) { ! (void) errx(1, "out of memory"); } static void newae(struct aelist *ael, const char *arg) { --- 450,460 ---- }; static void nomem(void) { ! errx(1, "out of memory"); } static void newae(struct aelist *ael, const char *arg) {
*** 521,531 **** } } /* ARGSUSED */ static void ! Xamode(struct aelist *h __attribute__((__unused__))) { } static void Xcmode(struct aelist *h) --- 519,529 ---- } } /* ARGSUSED */ static void ! Xamode(struct aelist __unused *h) { } static void Xcmode(struct aelist *h)
*** 656,666 **** * * -Dunix is also missing in enhanced ANSI mode */ newae(ctx->i_ae, "-D__sun"); ! if (asprintf(&nameflag, "-_%s=", ctx->i_compiler->name) == -1) nomem(); /* * Walk the argument list, translating as we go .. */ --- 654,664 ---- * * -Dunix is also missing in enhanced ANSI mode */ newae(ctx->i_ae, "-D__sun"); ! if (asprintf(&nameflag, "-_%s=", ctx->i_compiler->c_name) == -1) nomem(); /* * Walk the argument list, translating as we go .. */
*** 1405,1425 **** free(nameflag); if (c_files > 1 && (ctx->i_flags & CW_F_SHADOW) && op != CW_O_PREPROCESS) { ! (void) 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, "Conflicting \"-xarch=\" flags (both Studio 11 and 12)\n"); } switch (mflag) { case 0: --- 1403,1423 ---- free(nameflag); if (c_files > 1 && (ctx->i_flags & CW_F_SHADOW) && op != CW_O_PREPROCESS) { ! 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)) { ! errx(2, "Conflicting \"-xarch=\" flags (both Studio 11 and 12)\n"); } switch (mflag) { case 0:
*** 1496,1506 **** if (ctx->i_flags & CW_F_PROG) { newae(ctx->i_ae, "-V"); return; } ! if (asprintf(&nameflag, "-_%s=", ctx->i_compiler->name) == -1) nomem(); while (--ctx->i_oldargc > 0) { char *arg = *++ctx->i_oldargv; --- 1494,1504 ---- if (ctx->i_flags & CW_F_PROG) { newae(ctx->i_ae, "-V"); return; } ! if (asprintf(&nameflag, "-_%s=", ctx->i_compiler->c_name) == -1) nomem(); while (--ctx->i_oldargc > 0) { char *arg = *++ctx->i_oldargv;
*** 1572,1593 **** } static void prepctx(cw_ictx_t *ctx) { ! newae(ctx->i_ae, ctx->i_compiler->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); (void) fflush(stdout); } if (!(ctx->i_flags & CW_F_XLATE)) return; ! switch (ctx->i_compiler->style) { case SUN: do_cc(ctx); break; case GNU: do_gcc(ctx); --- 1570,1591 ---- } static void prepctx(cw_ictx_t *ctx) { ! 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->c_path); (void) fflush(stdout); } if (!(ctx->i_flags & CW_F_XLATE)) return; ! switch (ctx->i_compiler->c_style) { case SUN: do_cc(ctx); break; case GNU: do_gcc(ctx);
*** 1756,1784 **** parse_compiler(const char *spec, cw_compiler_t *compiler) { char *tspec, *token; if ((tspec = strdup(spec)) == NULL) ! err(1, "out of memory"); if ((token = strsep(&tspec, ",")) == NULL) errx(1, "Compiler is missing a name: %s", spec); ! compiler->name = token; if ((token = strsep(&tspec, ",")) == NULL) errx(1, "Compiler is missing a path: %s", spec); ! compiler->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; else if ((strcasecmp(token, "sun") == 0) || (strcasecmp(token, "cc") == 0)) ! compiler->style = SUN; else errx(1, "unknown compiler style: %s", token); if (tspec != NULL) errx(1, "Excess tokens in compiler: %s", spec); --- 1754,1782 ---- parse_compiler(const char *spec, cw_compiler_t *compiler) { char *tspec, *token; if ((tspec = strdup(spec)) == NULL) ! nomem(); if ((token = strsep(&tspec, ",")) == NULL) errx(1, "Compiler is missing a name: %s", spec); ! compiler->c_name = token; if ((token = strsep(&tspec, ",")) == NULL) errx(1, "Compiler is missing a path: %s", spec); ! 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->c_style = GNU; else if ((strcasecmp(token, "sun") == 0) || (strcasecmp(token, "cc") == 0)) ! compiler->c_style = SUN; else errx(1, "unknown compiler style: %s", token); if (tspec != NULL) errx(1, "Excess tokens in compiler: %s", spec);
*** 1799,1819 **** 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(); static struct option longopts[] = { { "compiler", no_argument, NULL, 'c' }, ! { "noecho", no_argument, NULL ,'n' }, { "primary", required_argument, NULL, 'p' }, { "shadow", required_argument, NULL, 's' }, { "versions", no_argument, NULL, 'v' }, { NULL, 0, NULL, 0 }, }; while ((ch = getopt_long(argc, argv, "C", longopts, NULL)) != -1) { switch (ch) { case 'c': cflg = B_TRUE; break; --- 1797,1822 ---- 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; static struct option longopts[] = { { "compiler", no_argument, NULL, 'c' }, ! { "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,1856 **** break; case 'n': nflg = B_TRUE; break; case 'p': ! if (primary.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); break; case 's': if (nshadows >= 10) ! 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); nshadows++; break; case 'v': vflg = B_TRUE; break; default: ! fprintf(stderr, "Did you forget '--'?\n"); usage(); } } ! if (primary.path == NULL) { warnx("A primary compiler must be specified"); usage(); } do_serial = (getenv("CW_SHADOW_SERIAL") == NULL) ? B_FALSE : B_TRUE; --- 1825,1863 ---- break; case 'n': nflg = B_TRUE; break; case 'p': ! 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); break; case 's': if (nshadows >= 10) ! 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); nshadows++; break; case 'v': vflg = B_TRUE; break; default: ! (void) fprintf(stderr, "Did you forget '--'?\n"); usage(); } } ! 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,1870 **** /* 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; --- 1865,1874 ----
*** 1873,1883 **** if (Cflg) main_ctx->i_flags |= CW_F_CXX; main_ctx->i_compiler = &primary; if (cflg) { ! fputs(primary.path, stdout); } if (vflg) { (void) printf("cw version %s\n", CW_VERSION); (void) fflush(stdout); --- 1877,1887 ---- if (Cflg) main_ctx->i_flags |= CW_F_CXX; main_ctx->i_compiler = &primary; if (cflg) { ! (void) fputs(primary.c_path, stdout); } if (vflg) { (void) printf("cw version %s\n", CW_VERSION); (void) fflush(stdout);
*** 1887,1899 **** } ret |= exec_ctx(main_ctx, do_serial); for (int i = 0; i < nshadows; i++) { ! cw_ictx_t *shadow_ctx = newictx(); ! if (shadow_ctx == NULL) nomem(); memcpy(shadow_ctx, main_ctx, sizeof (cw_ictx_t)); shadow_ctx->i_flags |= CW_F_SHADOW; --- 1891,1903 ---- } ret |= exec_ctx(main_ctx, do_serial); for (int i = 0; i < nshadows; i++) { ! cw_ictx_t *shadow_ctx; ! if ((shadow_ctx = newictx()) == NULL) nomem(); memcpy(shadow_ctx, main_ctx, sizeof (cw_ictx_t)); shadow_ctx->i_flags |= CW_F_SHADOW;