int main(int argc, char *argv[]) { if (argc < 2) return 1; if (strcmp(argv[1], "fields") == 0) mkdfa(fields, SIZEOF(fields), 1, (argc == 3)); else if (strcmp(argv[1], "methods") == 0) mkdfa(methods, SIZEOF(methods), 0, (argc == 3)); else if (strcmp(argv[1], "statuses") == 0) mkdfa(statuses, SIZEOF(statuses), 0, (argc == 3)); else if (strcmp(argv[1], "schemes") == 0) mkdfa(schemes, SIZEOF(schemes), 0, (argc == 3)); else if (strcmp(argv[1], "days") == 0) mkdfa(days, SIZEOF(days), 0, (argc == 3)); else if (strcmp(argv[1], "months") == 0) mkdfa(months, SIZEOF(months), 0, (argc == 3)); else if (strcmp(argv[1], "connections") == 0) mkdfa(connections, SIZEOF(connections), 0, (argc == 3)); else if (strcmp(argv[1], "cache-controls") == 0) mkdfa(cache_controls, SIZEOF(cache_controls), 0, (argc == 3)); return 0; }
fa *makedfa(const char *s, int anchor) /* returns dfa for reg expr s */ { int i, use, nuse; fa *pfa; static int now = 1; if (setvec == 0) { /* first time through any RE */ maxsetvec = MAXLIN; setvec = (int *) malloc(maxsetvec * sizeof(int)); tmpset = (int *) malloc(maxsetvec * sizeof(int)); if (setvec == 0 || tmpset == 0) overflo("out of space initializing makedfa"); } if (compile_time) /* a constant for sure */ return mkdfa(s, anchor); for (i = 0; i < nfatab; i++) /* is it there already? */ if (fatab[i]->anchor == anchor && strcmp((const char *) fatab[i]->restr, s) == 0) { fatab[i]->use = now++; return fatab[i]; } pfa = mkdfa(s, anchor); if (nfatab < NFA) { /* room for another */ fatab[nfatab] = pfa; fatab[nfatab]->use = now++; nfatab++; return pfa; } use = fatab[0]->use; /* replace least-recently used */ nuse = 0; for (i = 1; i < nfatab; i++) if (fatab[i]->use < use) { use = fatab[i]->use; nuse = i; } freefa(fatab[nuse]); fatab[nuse] = pfa; pfa->use = now++; return pfa; }