|
|
1.1 ! root 1: #include <stdio.h> ! 2: #include "re.h" ! 3: ! 4: #ifdef PROFILING ! 5: short profb[50000]; ! 6: #endif ! 7: ! 8: main(argc, argv) ! 9: char **argv; ! 10: { ! 11: re_re *r; ! 12: char *pat, *s; ! 13: char buf[4096]; ! 14: unsigned char map[256]; ! 15: FILE *exprs[1024]; ! 16: char *match[10][2]; ! 17: int n, i, bufc; ! 18: extern re_debug; ! 19: ! 20: #ifdef PROFILING ! 21: { extern etext(); monitor((int (*)())2, etext, profb, ((int)etext) - 2+12+2400, 300); } ! 22: #endif ! 23: if((argc%2) || (argc < 2)){ ! 24: fprintf(stderr, "Usage: %s {pattern file}* sequence\n", argv[0]); ! 25: fprintf(stderr, "\tEg: %s '^(a|b)+$' temp0 '(gh+|hb)' temp1 01101\n", argv[0]); ! 26: exit(1); ! 27: } ! 28: for(n = 0; n < 256; n++) ! 29: map[n] = n; ! 30: for(n = 0, i = 1; i < argc-1; i++, n++){ ! 31: pat = argv[i++]; ! 32: r = re_recomp(pat, pat+strlen(pat), map); ! 33: if(r == 0) ! 34: exit(1); ! 35: if((exprs[n] = fopen(argv[i], "w+r")) == NULL){ ! 36: perror(argv[i]); ! 37: exit(1); ! 38: } ! 39: re_refile(r, exprs[n]); ! 40: } ! 41: bufc = fread(buf, 1, sizeof buf, stdin); ! 42: for(s = argv[i]; *s; s++){ ! 43: rewind(exprs[n = *s-'0']); ! 44: r = re_filere(exprs[n]); ! 45: re_debug = 20; ! 46: if(re_reexec(r, buf, buf+bufc, match)){ ! 47: printf("%s matched:", argv[1+2*n]); ! 48: for(i = 0; i < 10; i++) ! 49: if(match[i][0]){ ! 50: printf(" G%d='", i); ! 51: fwrite(match[i][0], 1, match[i][1]-match[i][0], stdout); ! 52: putchar('\''); ! 53: } ! 54: putchar('\n'); ! 55: } ! 56: re_refree(r); ! 57: } ! 58: exit(0); ! 59: } ! 60: ! 61: void ! 62: re_error(char *s) ! 63: { ! 64: fprintf(stderr, "pattern error: %s\n", s); ! 65: /* NOTREACHED */ ! 66: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.