5 static int check_defines(const char **defs, int defcount, char *tdef)
10 for (i = 0; i < len; i++)
11 if (tdef[i] == ' ' || tdef[i] == '\r' || tdef[i] == '\n') break;
14 for (i = 0; i < defcount; i++)
16 if (strcmp(defs[i], tdef) == 0)
24 static void do_counters(char *str)
26 static int counters[4] = { 1, 1, 1, 1 };
31 while ((s = strstr(s, "@@")))
33 if (s[2] < '0' || s[2] > '3') { s++; continue; }
36 snprintf(buff, sizeof(buff), "%i%s", counters[counter]++, s + 3);
42 int main(int argc, char *argv[])
46 int skip_mode = 0, ifdef_level = 0, line = 0;
50 printf("usage:\n%s <file_in> <file_out> [defines...]\n", argv[0]);
54 fi = fopen(argv[1], "r");
57 printf("failed to open: %s\n", argv[1]);
61 fo = fopen(argv[2], "w");
64 printf("failed to open: %s\n", argv[2]);
68 for (++line; !feof(fi); line++)
72 fgs = fgets(buff, sizeof(buff), fi);
73 if (fgs == NULL) break;
78 if (strncmp(buff, "#ifdef ", 7) == 0)
80 if (!check_defines((void *) &argv[3], argc-3, buff + 7)) skip_mode = 1;
83 else if (strncmp(buff, "#ifndef ", 8) == 0)
85 if ( check_defines((void *) &argv[3], argc-3, buff + 7)) skip_mode = 1;
88 else if (strncmp(buff, "#else", 5) == 0)
92 else if (strncmp(buff, "#endif", 6) == 0)
95 if (ifdef_level == 0) skip_mode = 0;
98 printf("%i: warning: #endif without #ifdef, ignoring\n", line);