|
|
1.1 root 1: #include "hdr.h"
2:
3: #ifdef DOSTATS
4: char statsflags[1024], *statsfptr = statsflags;
5: #endif
6:
7: State states[NSTATES];
8: State *nxtst();
9: int state[NSTATES];
10: int line = 1;
11: int name[MAXLIN];
12: int left[MAXLIN];
13: int right[MAXLIN];
14: int parent[MAXLIN];
15: int foll[MAXLIN];
16: int positions[MAXPOS];
17: char chars[MAXLIN];
18: int nxtpos = 0;
19: int inxtpos;
20: int nxtchar = 0;
21: int tmpstat[MAXLIN];
22: int begstat[MAXLIN];
23: int colpos[MAXLIN];
24: State *istat;
25: int nstate = 1;
26: int xstate;
27: int count;
28: int icount;
29: char *input;
30: char *progname;
31: int begout;
32: int begcnt;
33: int cntpos;
34: int nxtfoll;
35:
36: char reinit = 0;
37:
38: long lnum;
39: int bflag;
40: int cflag;
41: int fflag;
42: int hflag = 1;
43: int iflag;
44: int lflag;
45: int nflag;
46: int sflag;
47: int vflag;
48: int nfile;
49: long tln;
50: int nsucc;
51: int badbotch;
52:
53: int expfile;
54: int bmegrep = 0;
55: int scanexit = 0;
56:
57: extern char *optarg;
58: extern int optind, getopt();
59:
60: usage()
61: {
62: fprint(2, "usage: %s [ -bchilnsv ] [ -e pattern ] [ -f file ] [ pattern ] [ file ] ...\n", progname);
63: exit(2);
64: }
65:
66: main(argc, argv)
67: char **argv;
68: {
69: register c;
70: int errflg = 0;
71: int (*fn)(), execute(), bmexecute();
72: int etext();
73: char *ffile;
74: char buf[2048];
75:
76: if(progname = strrchr(argv[0], '/'))
77: progname++;
78: else
79: progname = argv[0];
80:
81: while(( c = getopt(argc, argv, "bchie:f:lnsv?")) != -1){
82: #ifdef DOSTATS
83: *statsfptr++ = c;
84: #endif
85: switch(c) {
86:
87: case 'b':
88: bflag++;
89: continue;
90:
91: case 'c':
92: cflag++;
93: continue;
94:
95: case 'e':
96: input = optarg;
97: continue;
98:
99: case 'f':
100: fflag++;
101: ffile = optarg;
102: continue;
103:
104: case 'h':
105: hflag = 0;
106: continue;
107:
108: case 'i':
109: iflag++;
110: continue;
111:
112: case 'l':
113: lflag++;
114: continue;
115:
116: case 'n':
117: nflag++;
118: continue;
119:
120: case 's':
121: sflag++;
122: continue;
123:
124: case 'v':
125: vflag++;
126: continue;
127:
128: case '?':
129: errflg++;
130: continue;
131: }
132: }
133:
134: if (errflg)
135: usage();
136:
137: #ifdef DOSTATS
138: statsexpr = statspat = (char *)malloc(MAXPOS);
139: onexit(dostats);
140: #endif
141: argc -= optind;
142: argv += optind;
143: if (fflag) {
144: if ((expfile = open(ffile, 0)) < 0) {
145: fprint(2, "%s: can't open %s\n", progname, ffile);
146: exit(2);
147: }
148: } else if (input == 0) {
149: if ((input = *argv++) == 0)
150: usage();
151: argc--;
152: }
153: Finit(1, (char *)0);
154:
155: #ifdef MAILPREP
156: mailprep();
157: #endif /* MAILPREP */
158:
159: yyparse();
160:
161: #ifdef MAILPREP
162: maildone();
163: #endif /* MAILPREP */
164:
165: if(!vflag && islit(buf)){
166: bmprep(buf);
167: fn = bmexecute;
168: } else
169: fn = execute;
170:
171: cgotofn();
172: nfile = argc;
173: if (argc<=0) {
174: if (lflag) exit(1);
175: scanexit = 1;
176: (*fn)((char *)0);
177: }
178: else while (--argc >= 0) {
179: if (reinit == 1) clearg();
180: scanexit = argc == 0;
181: (*fn)(*argv++);
182: }
183: exit(badbotch ? 2 : nsucc==0);
184: }
185:
186: #ifdef DOSTATS
187: #include <errno.h>
188: #define NAME "/tmp/grepdata"
189: dostats()
190: {
191: int mailfd;
192:
193: umask(0);
194: mailfd = open(NAME, 1);
195: if((mailfd < 0) && (errno != ECONC)){
196: umask(0);
197: mailfd = creat(NAME, 03666);
198: }
199: if(mailfd >= 0){
200: Finit(mailfd, (char *)0);
201: Fseek(mailfd, 0L, 2);
202: *statsfptr = 0;
203: Fprint(mailfd, "\321egrep:%s:%d:%d:%d:%d:%d: %s\n",
204: statsflags, nlines, nbytes, ntrans, nfollow, nmaxfoll, statspat);
205: Fflush(mailfd);
206: }
207: }
208: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.