|
|
1.1 root 1: #
2: # include "econs.h"
3: # include "ecmn.h"
4: # define SKIP 0
5: # define COLLECT 1
6: # define SKIP2 2
7:
8: char mone -1;
9: int tlno 1;
10:
11: coll()
12: {
13: cs = COLLECT;
14: temp[t1].beg = &line[l];
15: return;
16: }
17:
18: save()
19: {
20: extern only;
21: char *pt1,*pt2,cbuf[30];
22: int a,tt,val;
23:
24: if(cs != COLLECT) {
25: cs = SKIP;
26: return;
27: }
28: cs = SKIP;
29: line[l] = '\0';
30: temp[t1].ct = &line[l] - temp[t1].beg;
31: if(!count)
32: if(temp[t1].ct == 1) goto no;
33: pt1 = temp[t1].beg-1;
34: pt2 = cbuf-1;
35:
36: while(*++pt2 = *++pt1)
37: if(*pt2 >= 'A' && *pt2 <= 'Z')
38: *pt2 =| 040;
39:
40: if(count)
41: goto yes;
42: val = search(cbuf,temp[t1].ct,&itab,0);
43:
44: if(!val == !only) goto yes;
45: no:
46: line[l] = c;
47: return(0);
48: yes:
49: if(count == 0) {
50: tt = t1;
51: while(tt)
52: if(comp(temp[t1].beg,temp[--tt].beg)) goto no;
53: }
54: temp[t1++].term = c;
55: return(1);
56: }
57:
58: out()
59: {
60: auto i,ct,t2;
61: char *b,*e;
62: if(lflag) {
63: printf("line too long: %s, line %d\n", curf, lno);
64: lflag = 0;
65: }
66: if(cs == COLLECT) save();
67: t2 = 0;
68: while(t2 < t1) {
69: temp[t2].beg[temp[t2].ct] = temp[t2].term;
70: t2++;
71: }
72: t2 = t1 - 1;
73: while(t1--) {
74: /*printf("t1 = %d beg = %o ct = %d\n",t1,temp[t1].beg,temp[t1].ct); /* DEBUG */
75:
76: ct = temp[t1].ct;
77: temp[t1].beg[ct] = temp[t1].term;
78: if(ct > 15) ct = 15;
79:
80: put(temp[t1].beg, ct);
81:
82: put("\t",1);
83:
84: if(!page) {
85: if(!single)
86: put(curf,curfl);
87: if(!dlineno) {
88: conf(lno,4,curs);
89: put(curs,4);
90: }
91: } else {
92: conf(pn,4,curs);
93: put(curs,4);
94: }
95: if(word == 0) {
96: put("\t",1);
97: if(t1 >= 1)
98: b = temp[t1-1].beg;
99: else
100: b = line;
101: if(t2 > t1)
102: e = temp[t1+1].beg + temp[t1+1].ct;
103: else
104: e = &line[l];
105: /*printf("e = %o b = %o\n",e,b); /*DEBUG*/
106: put(b,e-b);
107: }
108: put("\n",1);
109: }
110: t1 = 0;
111: l = -1;
112: lno =+ tlno;
113: tlno = 1;
114: cs = SKIP;
115: return;
116: }
117:
118: ctout()
119: {
120: register int i, ct;
121: register char *t2;
122:
123: if(lflag) {
124: printf("line too long: %s, line %d\n", curf, lno);
125: lflag = 0;
126: }
127: if(cs == COLLECT) save();
128:
129: while(t1--) {
130: ct = temp[t1].ct;
131: t2 = temp[t1].beg - 1;
132: /* printf("out: %s %d\n", temp[t1].beg, ct); /*DEBUG*/
133: while(*++t2)
134: if(*t2 >= 'A' && *t2 <= 'Z')
135: *t2 =| 040;
136:
137: *t2 = '\n';
138:
139: put(temp[t1].beg, ct + 1);
140: }
141: t1 = 0;
142: l = -1;
143: lno =+ tlno;
144: tlno = 1;
145: cs = SKIP;
146: return;
147: }
148:
149: search(symbol,length,params,install)
150: char *symbol;
151: int length;
152: struct htab *params;
153: int install;
154: {
155: char *sp,*p;
156: static int *hptr,hsiz,nsym;
157: static char *ssiz;
158: static int curb;
159: static char *symt;
160: auto h,i,j,k;
161:
162: if(hptr != params->hptr) {
163: hptr = params->hptr;
164: hsiz = params->hsiz;
165: symt = params->symt;
166: ssiz = params->ssiz;
167: curb = params->curb;
168: nsym = params->nsym;
169: }
170:
171: symbol[length] = '\0';
172: /*printf("ssiz = %d; nsym = %d; %s\n", ssiz, nsym, symbol);/*DEBUG*/
173: sp = symbol;
174:
175: i = length;
176: h = 1;
177: while(i--)
178: h =* *sp++;
179:
180: if(h == 0100000) {
181: h = 1;
182: } else {
183: h = h<0?(-h)%hsiz:h%hsiz;
184: }
185: if(h == 0) h++;
186: /* printf("%s %d\n",symbol,h); /*DEBUG*/
187:
188: while((p = &symt[hptr[h]]) > symt) {
189: j = length + 2;
190: sp = symbol;
191: while(--j) {
192: if(*p++ != *sp++) goto no;
193: }
194: return(*p);
195: no:
196: h = (h + h)%hsiz;
197: }
198: if(install) {
199: if(++nsym >= hsiz) {
200: printf("Too many symbols in ignore/only file.\n");
201: dexit();
202: }
203:
204: hptr[h] = curb;
205: length++;
206: if((curb + length) >= ssiz) {
207: printf("i/o file too big; ssiz = %d\n", ssiz);
208: dexit();
209: }
210:
211: while(length--)
212: symt[curb++] = *symbol++;
213: symt[curb++] = install;
214: params->curb = curb;
215: params->nsym = nsym;
216: }
217: return(0);
218: }
219:
220: conf(n,width,buf)
221: char *buf;
222: {
223: auto i,a;
224:
225: i = width;
226: while(i--) buf[i] = ' ';
227:
228: buf[(a = n/10)?conf(a,--width,buf):--width] = n%10 + '0';
229:
230: return(++width);
231: }
232:
233: comp(a,b)
234: char *a;
235: char *b;
236: {
237: a--;
238: b--;
239: while(*++a == *++b)
240: if(*a == '\0') return(1);
241: return(0);
242: }
243:
244:
245: hyphen()
246: {
247: /* printf("hyphen\n"); /*DEBUG*/
248: if(gch[fl] == 0)
249: flag[++fl] = &hyp1;
250: return(1);
251: }
252:
253: hyp1()
254: {
255: char tc;
256: /* printf("hyp1 c = %o\n",c); /*DEBUG*/
257: if(c != '\n') {
258: fl--;
259: l--;
260: tc = c;
261: c = '-';
262: save();
263: c = tc;
264: l++;
265: return(0);
266: } else {
267: l =- 2;
268: flag[fl] = &hyp2;
269: hsw = 1;
270: return(1);
271: }
272: }
273:
274: hyp2()
275: {
276: extern (*acts[]) ();
277: /* printf("hyp2 c = %o l = %d\n",c,l); /*DEBUG*/
278: if(hsw && (tab[2].cl[c] == 0)) {
279: l--;
280: if(c == 3) pno();
281: if(c == '\n') tlno++;
282: return(1);
283: }
284: hsw = 0;
285: if(tab[cs].cl[c]) {
286: line[l] = '\n';
287: (*acts[OUT])();
288: fl--;
289: return(0);
290: }
291: return(1);
292: }
293:
294: pno()
295: {
296: extern (*acts[])();
297:
298: if(flag[fl] != &pno) {
299: flag[++fl] = &pno;
300: pn = 0;
301: return(1);
302: }
303: if(c == '\n') {
304: fl--;
305: (*acts[OUT])();
306: return(1);
307: }
308: pn = pn*10 + c - '0';
309: return(1);
310: }
311: gobble2()
312: {
313: static ct2;
314:
315: if(cs == COLLECT) save();
316:
317: if(flag[fl] != gobble2) {
318: ct2 = 1;
319: flag[++fl] = gobble2;
320: return(1);
321: }
322: if(ct2--) return(1);
323:
324: fl--;
325: cs = SKIP;
326: return(1);
327: }
328:
329: bslash()
330: {
331: if(cs == COLLECT) save();
332: cs = SKIP2;
333: return(1);
334: }
335:
336:
337: error()
338: {
339: printf("Error: %c %o\n", c, cs);
340: dexit();
341: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.