main() { char reg[132]; char *ireg; char str[132]; char *match; char matstr[132]; char c; while (1) { printf ("\nexpr: "); scanf ("%s", reg); ireg = convexp(reg); match = ireg; while(*match) { switch (*match) { case '\\': case '(': case ')': case '|': printf ("%c", *match); break; default: if (isalnum(*match)) printf("%c", *match); else printf ("<%03o>", *match); break; } match++; } printf("\n"); getchar(); while(1) { printf ("string: "); match = str; while ((c = getchar()) != '\n') *match++ = c; *match = 0; if (str[0] == '#') break; matstr[0] = 0; _start = str; _escaped = 0; match = expmatch (str, ireg, matstr); if (match == 0) printf ("FAILED\n"); else printf ("match\nmatstr = %s\n", matstr); } } }
int main(int argc, char **argv) { const char *fname = ""; struct stat stbuf; char buf[BUFSIZ]; char *defs; int needbp = 0; argc--, argv++; do { char *cp; int i; if (argc > 0) { if (!strcmp(argv[0], "-h")) { if (argc == 1) { printf("'ds =H\n"); argc = 0; goto rest; } printf("'ds =H %s\n", argv[1]); argc--, argv++; argc--, argv++; if (argc > 0) continue; goto rest; } /* act as a filter like eqn */ if (!strcmp(argv[0], "-f")) { filter = true; argv[0] = argv[argc-1]; argv[argc-1] = minus; continue; } /* take input from the standard place */ if (!strcmp(argv[0], "-")) { argc = 0; goto rest; } /* build an index */ if (!strcmp(argv[0], "-x")) { idx = true; argv[0] = minusn; } /* indicate no keywords */ if (!strcmp(argv[0], "-n")) { nokeyw = true; argc--, argv++; continue; } /* specify the font size */ if (!strncmp(argv[0], "-s", 2)) { i = 0; cp = argv[0] + 2; while (*cp) i = i * 10 + (*cp++ - '0'); printf("'ps %d\n'vs %d\n", i, i+1); argc--, argv++; continue; } /* specify the language */ if (!strncmp(argv[0], "-l", 2)) { language = argv[0]+2; argc--, argv++; continue; } /* specify the language description file */ if (!strncmp(argv[0], "-d", 2)) { defsfile[0] = argv[1]; argc--, argv++; argc--, argv++; continue; } /* open the file for input */ if (freopen(argv[0], "r", stdin) == NULL) err(1, "%s", argv[0]); if (idx) printf("'ta 4i 4.25i 5.5iR\n'in .5i\n"); fname = argv[0]; argc--, argv++; } rest: /* * get the language definition from the defs file */ i = cgetent(&defs, defsfile, language); if (i == -1) { fprintf (stderr, "no entry for language %s\n", language); exit(0); } else if (i == -2) { fprintf(stderr, "cannot find vgrindefs file %s\n", defsfile[0]); exit(0); } else if (i == -3) { fprintf(stderr, "potential reference loop detected in vgrindefs file %s\n", defsfile[0]); exit(0); } if (cgetustr(defs, "kw", &cp) == -1) nokeyw = true; else { char **cpp; cpp = l_keywds; while (*cp) { while (*cp == ' ' || *cp =='\t') *cp++ = '\0'; if (*cp) *cpp++ = cp; while (*cp != ' ' && *cp != '\t' && *cp) cp++; } *cpp = NULL; } cgetustr(defs, "pb", &cp); l_prcbeg = convexp(cp); cgetustr(defs, "cb", &cp); l_combeg = convexp(cp); cgetustr(defs, "ce", &cp); l_comend = convexp(cp); cgetustr(defs, "ab", &cp); l_acmbeg = convexp(cp); cgetustr(defs, "ae", &cp); l_acmend = convexp(cp); cgetustr(defs, "sb", &cp); l_strbeg = convexp(cp); cgetustr(defs, "se", &cp); l_strend = convexp(cp); cgetustr(defs, "bb", &cp); l_blkbeg = convexp(cp); cgetustr(defs, "be", &cp); l_blkend = convexp(cp); cgetustr(defs, "lb", &cp); l_chrbeg = convexp(cp); cgetustr(defs, "le", &cp); l_chrend = convexp(cp); if (cgetustr(defs, "nc", &cp) >= 0) l_nocom = convexp(cp); l_escape = '\\'; l_onecase = (cgetcap(defs, "oc", ':') != NULL); l_toplex = (cgetcap(defs, "tl", ':') != NULL); /* initialize the program */ incomm = false; instr = false; inchr = false; _escaped = false; blklevel = 0; for (psptr=0; psptr<PSMAX; psptr++) { pstack[psptr][0] = '\0'; plstack[psptr] = 0; } psptr = -1; ps("'-F\n"); if (!filter) { printf(".ds =F %s\n", fname); ps("'wh 0 vH\n"); ps("'wh -1i vF\n"); } if (needbp) { needbp = 0; printf(".()\n"); printf(".bp\n"); } if (!filter) { fstat(fileno(stdin), &stbuf); cp = ctime(&stbuf.st_mtime); cp[16] = '\0'; cp[24] = '\0'; printf(".ds =M %s %s\n", cp+4, cp+20); } /* * MAIN LOOP!!! */ while (fgets(buf, sizeof buf, stdin) != NULL) { if (buf[0] == '\f') { printf(".bp\n"); } if (buf[0] == '.') { printf("%s", buf); if (!strncmp (buf+1, "vS", 2)) pass = true; if (!strncmp (buf+1, "vE", 2)) pass = false; continue; } prccont = false; if (!filter || pass) putScp(buf); else printf("%s", buf); if (prccont && (psptr >= 0)) { ps("'FC "); ps(pstack[psptr]); ps("\n"); } #ifdef DEBUG printf ("com %o str %o chr %o ptr %d\n", incomm, instr, inchr, psptr); #endif margin = 0; } needbp = 1; } while (argc > 0); exit(0); }