Mercurial > hg > toybox
annotate scripts/mkflags.c @ 1349:bf2e5591bdf0 draft
Cleanup strings.
author | Rob Landley <rob@landley.net> |
---|---|
date | Wed, 11 Jun 2014 08:02:55 -0500 |
parents | 23817e1675f2 |
children | 5fac2769a159 |
rev | line source |
---|---|
1076
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1 // Take three word input lines on stdin (the three space separated words are |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2 // command name, option string with current config, option string from |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3 // allyesconfig; space separated, the last two are and double quotes) |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
4 // and produce flag #defines to stdout. |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
5 |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
6 // This is intentionally crappy code because we control the inputs. It leaks |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
7 // memory like a sieve and segfaults if malloc returns null, but does the job. |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
8 |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
9 #include <stdio.h> |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
10 #include <stdlib.h> |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
11 #include <string.h> |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
12 #include <errno.h> |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
13 |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
14 struct flag { |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
15 struct flag *next; |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
16 char *command; |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
17 struct flag *lopt; |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
18 }; |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
19 |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
20 // Break down a command string into struct flag list. |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
21 |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
22 struct flag *digest(char *string) |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
23 { |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
24 struct flag *list = NULL; |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
25 |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
26 while (*string) { |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
27 // Groups must be at end. |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
28 if (*string == '[') break; |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
29 |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
30 // Longopts |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
31 if (*string == '(') { |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
32 struct flag *new = calloc(sizeof(struct flag), 1); |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
33 |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
34 new->command = ++string; |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
35 |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
36 // Attach longopt to previous short opt, if any. |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
37 if (list && list->command) { |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
38 new->next = list->lopt; |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
39 list->lopt = new; |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
40 } else { |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
41 struct flag *blank = calloc(sizeof(struct flag), 1); |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
42 |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
43 blank->next = list; |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
44 blank->lopt = new; |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
45 list = blank; |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
46 } |
1277
23817e1675f2
Catch duplicate command name (which breaks the build already, but doesn't identify the culprit).
Rob Landley <rob@landley.net>
parents:
1243
diff
changeset
|
47 // An empty longopt () would break this. |
23817e1675f2
Catch duplicate command name (which breaks the build already, but doesn't identify the culprit).
Rob Landley <rob@landley.net>
parents:
1243
diff
changeset
|
48 while (*++string != ')') if (*string == '-') *string = '_'; |
1076
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
49 *(string++) = 0; |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
50 continue; |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
51 } |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
52 |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
53 if (strchr("?&^-:#|@*; ", *string)) string++; |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
54 else if (strchr("=<>", *string)) { |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
55 while (isdigit(*++string)) { |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
56 if (!list) { |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
57 string++; |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
58 break; |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
59 } |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
60 } |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
61 } else { |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
62 struct flag *new = calloc(sizeof(struct flag), 1); |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
63 |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
64 new->command = string++; |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
65 new->next = list; |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
66 list = new; |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
67 } |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
68 } |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
69 |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
70 return list; |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
71 } |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
72 |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
73 int main(int argc, char *argv[]) |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
74 { |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
75 char command[256], flags[1023], allflags[1024]; |
1209
f170f978e81e
Put all FOR_xxx blocks after all CLEANUP_xxx in generated/flags.h so the usages don't have to be in alphabetical order.
Rob Landley <rob@landley.net>
parents:
1203
diff
changeset
|
76 char *out, *outbuf = malloc(1024*1024); |
f170f978e81e
Put all FOR_xxx blocks after all CLEANUP_xxx in generated/flags.h so the usages don't have to be in alphabetical order.
Rob Landley <rob@landley.net>
parents:
1203
diff
changeset
|
77 |
f170f978e81e
Put all FOR_xxx blocks after all CLEANUP_xxx in generated/flags.h so the usages don't have to be in alphabetical order.
Rob Landley <rob@landley.net>
parents:
1203
diff
changeset
|
78 // Yes, the output buffer is 1 megabyte with no bounds checking. |
f170f978e81e
Put all FOR_xxx blocks after all CLEANUP_xxx in generated/flags.h so the usages don't have to be in alphabetical order.
Rob Landley <rob@landley.net>
parents:
1203
diff
changeset
|
79 // See "intentionally crappy", above. |
f170f978e81e
Put all FOR_xxx blocks after all CLEANUP_xxx in generated/flags.h so the usages don't have to be in alphabetical order.
Rob Landley <rob@landley.net>
parents:
1203
diff
changeset
|
80 if (!(out = outbuf)) return 1; |
1076
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
81 |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
82 for (;;) { |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
83 struct flag *flist, *aflist, *offlist; |
1277
23817e1675f2
Catch duplicate command name (which breaks the build already, but doesn't identify the culprit).
Rob Landley <rob@landley.net>
parents:
1243
diff
changeset
|
84 unsigned bit; |
23817e1675f2
Catch duplicate command name (which breaks the build already, but doesn't identify the culprit).
Rob Landley <rob@landley.net>
parents:
1243
diff
changeset
|
85 |
23817e1675f2
Catch duplicate command name (which breaks the build already, but doesn't identify the culprit).
Rob Landley <rob@landley.net>
parents:
1243
diff
changeset
|
86 *command = 0; |
23817e1675f2
Catch duplicate command name (which breaks the build already, but doesn't identify the culprit).
Rob Landley <rob@landley.net>
parents:
1243
diff
changeset
|
87 bit = fscanf(stdin, "%255s \"%1023[^\"]\" \"%1023[^\"]\"\n", |
23817e1675f2
Catch duplicate command name (which breaks the build already, but doesn't identify the culprit).
Rob Landley <rob@landley.net>
parents:
1243
diff
changeset
|
88 command, flags, allflags); |
1076
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
89 |
1277
23817e1675f2
Catch duplicate command name (which breaks the build already, but doesn't identify the culprit).
Rob Landley <rob@landley.net>
parents:
1243
diff
changeset
|
90 if (!*command) break; |
23817e1675f2
Catch duplicate command name (which breaks the build already, but doesn't identify the culprit).
Rob Landley <rob@landley.net>
parents:
1243
diff
changeset
|
91 if (bit != 3) { |
23817e1675f2
Catch duplicate command name (which breaks the build already, but doesn't identify the culprit).
Rob Landley <rob@landley.net>
parents:
1243
diff
changeset
|
92 fprintf(stderr, "\nError in %s (duplicate command?)\n", command); |
23817e1675f2
Catch duplicate command name (which breaks the build already, but doesn't identify the culprit).
Rob Landley <rob@landley.net>
parents:
1243
diff
changeset
|
93 exit(1); |
23817e1675f2
Catch duplicate command name (which breaks the build already, but doesn't identify the culprit).
Rob Landley <rob@landley.net>
parents:
1243
diff
changeset
|
94 } |
1076
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
95 |
1277
23817e1675f2
Catch duplicate command name (which breaks the build already, but doesn't identify the culprit).
Rob Landley <rob@landley.net>
parents:
1243
diff
changeset
|
96 bit = 0; |
1076
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
97 printf("// %s %s %s\n", command, flags, allflags); |
1209
f170f978e81e
Put all FOR_xxx blocks after all CLEANUP_xxx in generated/flags.h so the usages don't have to be in alphabetical order.
Rob Landley <rob@landley.net>
parents:
1203
diff
changeset
|
98 |
1076
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
99 flist = digest(flags); |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
100 offlist = aflist = digest(allflags); |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
101 |
1203
2a68f22aa286
Make CLEANUP transitions work, so multiple NEWTOY() can exist in the same file.
Rob Landley <rob@landley.net>
parents:
1202
diff
changeset
|
102 printf("#ifdef CLEANUP_%s\n#undef CLEANUP_%s\n#undef FOR_%s\n", |
1076
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
103 command, command, command); |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
104 |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
105 while (offlist) { |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
106 struct flag *f = offlist->lopt; |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
107 while (f) { |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
108 printf("#undef FLAG_%s\n", f->command); |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
109 f = f->next; |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
110 } |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
111 if (offlist->command) printf("#undef FLAG_%c\n", *offlist->command); |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
112 offlist = offlist->next; |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
113 } |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
114 printf("#endif\n\n"); |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
115 |
1209
f170f978e81e
Put all FOR_xxx blocks after all CLEANUP_xxx in generated/flags.h so the usages don't have to be in alphabetical order.
Rob Landley <rob@landley.net>
parents:
1203
diff
changeset
|
116 sprintf(out, "#ifdef FOR_%s\n#ifndef TT\n#define TT this.%s\n#endif\n", |
f170f978e81e
Put all FOR_xxx blocks after all CLEANUP_xxx in generated/flags.h so the usages don't have to be in alphabetical order.
Rob Landley <rob@landley.net>
parents:
1203
diff
changeset
|
117 command, command); |
f170f978e81e
Put all FOR_xxx blocks after all CLEANUP_xxx in generated/flags.h so the usages don't have to be in alphabetical order.
Rob Landley <rob@landley.net>
parents:
1203
diff
changeset
|
118 out += strlen(out); |
1076
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
119 |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
120 while (aflist) { |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
121 if (aflist->lopt) { |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
122 if (flist && flist->lopt && |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
123 !strcmp(flist->lopt->command, aflist->lopt->command)) |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
124 { |
1209
f170f978e81e
Put all FOR_xxx blocks after all CLEANUP_xxx in generated/flags.h so the usages don't have to be in alphabetical order.
Rob Landley <rob@landley.net>
parents:
1203
diff
changeset
|
125 sprintf(out, "#define FLAG_%s (1<<%d)\n", flist->lopt->command, bit); |
1076
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
126 flist->lopt = flist->lopt->next; |
1209
f170f978e81e
Put all FOR_xxx blocks after all CLEANUP_xxx in generated/flags.h so the usages don't have to be in alphabetical order.
Rob Landley <rob@landley.net>
parents:
1203
diff
changeset
|
127 } else sprintf(out, "#define FLAG_%s 0\n", aflist->lopt->command); |
1076
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
128 aflist->lopt = aflist->lopt->next; |
1243
eae29e8e2bc8
_mkflags_ had an issue for generating FLAG_xxxx macros for long options.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
1225
diff
changeset
|
129 if (!aflist->command) { |
eae29e8e2bc8
_mkflags_ had an issue for generating FLAG_xxxx macros for long options.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
1225
diff
changeset
|
130 aflist = aflist->next; |
eae29e8e2bc8
_mkflags_ had an issue for generating FLAG_xxxx macros for long options.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
1225
diff
changeset
|
131 if (flist) { |
eae29e8e2bc8
_mkflags_ had an issue for generating FLAG_xxxx macros for long options.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
1225
diff
changeset
|
132 flist = flist->next; |
eae29e8e2bc8
_mkflags_ had an issue for generating FLAG_xxxx macros for long options.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
1225
diff
changeset
|
133 bit++; |
eae29e8e2bc8
_mkflags_ had an issue for generating FLAG_xxxx macros for long options.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
1225
diff
changeset
|
134 } |
eae29e8e2bc8
_mkflags_ had an issue for generating FLAG_xxxx macros for long options.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
1225
diff
changeset
|
135 } |
1198
ce31c87e1862
Fix segfault with single build of a command with bare longopts.
Rob Landley <rob@landley.net>
parents:
1076
diff
changeset
|
136 } else if (aflist->command) { |
1076
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
137 if (flist && (!aflist->command || *aflist->command == *flist->command)) |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
138 { |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
139 if (aflist->command) |
1209
f170f978e81e
Put all FOR_xxx blocks after all CLEANUP_xxx in generated/flags.h so the usages don't have to be in alphabetical order.
Rob Landley <rob@landley.net>
parents:
1203
diff
changeset
|
140 sprintf(out, "#define FLAG_%c (1<<%d)\n", *aflist->command, bit); |
1076
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
141 bit++; |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
142 flist = flist->next; |
1209
f170f978e81e
Put all FOR_xxx blocks after all CLEANUP_xxx in generated/flags.h so the usages don't have to be in alphabetical order.
Rob Landley <rob@landley.net>
parents:
1203
diff
changeset
|
143 } else sprintf(out, "#define FLAG_%c 0\n", *aflist->command); |
1076
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
144 aflist = aflist->next; |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
145 } |
1209
f170f978e81e
Put all FOR_xxx blocks after all CLEANUP_xxx in generated/flags.h so the usages don't have to be in alphabetical order.
Rob Landley <rob@landley.net>
parents:
1203
diff
changeset
|
146 out += strlen(out); |
1076
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
147 } |
1209
f170f978e81e
Put all FOR_xxx blocks after all CLEANUP_xxx in generated/flags.h so the usages don't have to be in alphabetical order.
Rob Landley <rob@landley.net>
parents:
1203
diff
changeset
|
148 sprintf(out, "#endif\n\n"); |
f170f978e81e
Put all FOR_xxx blocks after all CLEANUP_xxx in generated/flags.h so the usages don't have to be in alphabetical order.
Rob Landley <rob@landley.net>
parents:
1203
diff
changeset
|
149 out += strlen(out); |
1076
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
150 } |
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
151 |
1209
f170f978e81e
Put all FOR_xxx blocks after all CLEANUP_xxx in generated/flags.h so the usages don't have to be in alphabetical order.
Rob Landley <rob@landley.net>
parents:
1203
diff
changeset
|
152 if (fflush(0) && ferror(stdout)) return 1; |
f170f978e81e
Put all FOR_xxx blocks after all CLEANUP_xxx in generated/flags.h so the usages don't have to be in alphabetical order.
Rob Landley <rob@landley.net>
parents:
1203
diff
changeset
|
153 |
f170f978e81e
Put all FOR_xxx blocks after all CLEANUP_xxx in generated/flags.h so the usages don't have to be in alphabetical order.
Rob Landley <rob@landley.net>
parents:
1203
diff
changeset
|
154 out = outbuf; |
f170f978e81e
Put all FOR_xxx blocks after all CLEANUP_xxx in generated/flags.h so the usages don't have to be in alphabetical order.
Rob Landley <rob@landley.net>
parents:
1203
diff
changeset
|
155 while (*out) { |
f170f978e81e
Put all FOR_xxx blocks after all CLEANUP_xxx in generated/flags.h so the usages don't have to be in alphabetical order.
Rob Landley <rob@landley.net>
parents:
1203
diff
changeset
|
156 int i = write(1, outbuf, strlen(outbuf)); |
f170f978e81e
Put all FOR_xxx blocks after all CLEANUP_xxx in generated/flags.h so the usages don't have to be in alphabetical order.
Rob Landley <rob@landley.net>
parents:
1203
diff
changeset
|
157 |
f170f978e81e
Put all FOR_xxx blocks after all CLEANUP_xxx in generated/flags.h so the usages don't have to be in alphabetical order.
Rob Landley <rob@landley.net>
parents:
1203
diff
changeset
|
158 if (i<0) return 1; |
f170f978e81e
Put all FOR_xxx blocks after all CLEANUP_xxx in generated/flags.h so the usages don't have to be in alphabetical order.
Rob Landley <rob@landley.net>
parents:
1203
diff
changeset
|
159 out += i; |
f170f978e81e
Put all FOR_xxx blocks after all CLEANUP_xxx in generated/flags.h so the usages don't have to be in alphabetical order.
Rob Landley <rob@landley.net>
parents:
1203
diff
changeset
|
160 } |
1076
1c15ba60aa64
Switch flag generation from shell to C.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
161 } |