# HG changeset patch # User Rob Landley # Date 1393306483 21600 # Node ID f170f978e81e060252d25b2244dc1561f65903c4 # Parent c86b1579c383280e5355cd9d8ad5cdbfe497d551 Put all FOR_xxx blocks after all CLEANUP_xxx in generated/flags.h so the usages don't have to be in alphabetical order. diff -r c86b1579c383 -r f170f978e81e scripts/mkflags.c --- a/scripts/mkflags.c Sun Feb 23 20:11:06 2014 -0600 +++ b/scripts/mkflags.c Mon Feb 24 23:34:43 2014 -0600 @@ -72,6 +72,11 @@ int main(int argc, char *argv[]) { char command[256], flags[1023], allflags[1024]; + char *out, *outbuf = malloc(1024*1024); + + // Yes, the output buffer is 1 megabyte with no bounds checking. + // See "intentionally crappy", above. + if (!(out = outbuf)) return 1; for (;;) { struct flag *flist, *aflist, *offlist; @@ -81,10 +86,10 @@ command, flags, allflags)) break; printf("// %s %s %s\n", command, flags, allflags); + flist = digest(flags); offlist = aflist = digest(allflags); - printf("#ifdef CLEANUP_%s\n#undef CLEANUP_%s\n#undef FOR_%s\n", command, command, command); @@ -99,32 +104,43 @@ } printf("#endif\n\n"); - printf("#ifdef FOR_%s\n#ifndef TT\n#define TT this.%s\n#endif\n", - command, command); + sprintf(out, "#ifdef FOR_%s\n#ifndef TT\n#define TT this.%s\n#endif\n", + command, command); + out += strlen(out); while (aflist) { if (aflist->lopt) { if (flist && flist->lopt && !strcmp(flist->lopt->command, aflist->lopt->command)) { - printf("#define FLAG_%s (1<<%d)\n", flist->lopt->command, bit); + sprintf(out, "#define FLAG_%s (1<<%d)\n", flist->lopt->command, bit); flist->lopt = flist->lopt->next; - } else printf("#define FLAG_%s 0\n", aflist->lopt->command); + } else sprintf(out, "#define FLAG_%s 0\n", aflist->lopt->command); aflist->lopt = aflist->lopt->next; if (!aflist->command) aflist = aflist->next; } else if (aflist->command) { if (flist && (!aflist->command || *aflist->command == *flist->command)) { if (aflist->command) - printf("#define FLAG_%c (1<<%d)\n", *aflist->command, bit); + sprintf(out, "#define FLAG_%c (1<<%d)\n", *aflist->command, bit); bit++; flist = flist->next; - } else printf("#define FLAG_%c 0\n", *aflist->command); + } else sprintf(out, "#define FLAG_%c 0\n", *aflist->command); aflist = aflist->next; } + out += strlen(out); } - printf("#endif\n\n"); + sprintf(out, "#endif\n\n"); + out += strlen(out); } - return fflush(0) && ferror(stdout); + if (fflush(0) && ferror(stdout)) return 1; + + out = outbuf; + while (*out) { + int i = write(1, outbuf, strlen(outbuf)); + + if (i<0) return 1; + out += i; + } }