|
|
1.1 root 1: #
2: # include "mcons.c"
3: # include "ccmn.c"
4:
5: int cross 1;
6: int order 1;
7: char mone -1;
8:
9: coll()
10: {
11: cs = COLLECT;
12: temp[t1].beg = &line[l];
13: return;
14: }
15:
16: save()
17: {
18: extern wspace();
19:
20: line[l] = '\0';
21: temp[t1].ct = &line[l] - temp[t1].beg;
22: temp[t1].term = c;
23:
24: if((c == ' ' || c == '\t') && cflag) {
25: gch[++fl] = mone;
26: flag[fl] = &wspace;
27: } else {
28: sav1();
29: }
30: return;
31: }
32:
33: sav1()
34: {
35: extern only;
36: struct tempent *ptr;
37: int a,tt,val;
38: int xval;
39:
40: ptr = &temp[t1];
41: val = search(ptr->beg,ptr->ct,&itab,0);
42: if(cflag && c == '(' && level == 0 && hlevel == 0)
43: csym();
44:
45: cs = SKIP;
46:
47: if(xsw) {
48: switch(val) {
49: case 0:
50: if((!level&&!hlevel)||(c == '(')||xtrn
51: || ssw) {
52: xval = search(ptr->beg,ptr->ct,&xtab,1);
53: goto yes;
54: } else {
55: if(xval = search(ptr->beg,ptr->ct,&xtab,0)) {
56: goto yes;
57: }
58: }
59: goto no;
60:
61: case 1:
62: break;
63:
64: case 2:
65: xtrn = 1;
66: goto no;
67:
68: case 3:
69: if(hlevel) type = 1;
70: if(!level&&!hlevel) ssw = 1;
71: goto no;
72:
73: case 4:
74: if(hlevel) type = 1;
75: goto no;
76:
77: case 5:
78: goto no;
79: }
80: }
81:
82: if(hlevel && (val == 4 || val == 3)) type = 1;
83: if(!val == !only) goto yes;
84: no:
85: *(ptr->beg + ptr->ct) = ptr->term;
86: return(0);
87: yes:
88: tt = t1;
89: while(tt)
90: if(comp(ptr->beg,temp[--tt].beg)) goto no;
91: t1++;
92: return(1);
93: }
94:
95: out()
96: {
97: auto i,ct;
98: if(cs == COLLECT) save();
99:
100: ct = t1;
101: while(ct--)
102: temp[ct].beg[temp[ct].ct] = temp[ct].term;
103:
104: while(t1--) {
105: /*printf("t1 = %d beg = %d ct = %d\n",t1,temp[t1].beg,temp[t1].ct); /* DEBUG */
106:
107: switch(order) {
108:
109: case 1:
110: if(utmp)
111: i = 0;
112: else
113: i = dfile(temp[t1].beg);
114:
115: if((ct = temp[t1].ct) >= 8) {
116: ct = 8;
117: *curf = -1;
118: } else {
119: *curf = '\t';
120: }
121:
122: put(i,temp[t1].beg,ct);
123: if(!single)
124: put(i, curf, curfl);
125: else
126: put(i, curf, 1);
127: if(cross) put(i,curs,cursl);
128: conf(lno,4,lbuf);
129: put(i,lbuf,5);
130: break;
131:
132: case 2:
133: i = dfile(curf+1);
134: put(i,curf+1,curfl-1);
135: if(cross) put(i,curs,cursl);
136: else {
137: conf(lno,4,lbuf);
138: put(i,lbuf,5);
139: }
140: if((ct = temp[t1].ct) >= 8) {
141: put(i,temp[t1].beg,8);
142: put(i,&mone,1);
143: } else {
144: put(i,temp[t1].beg,ct);
145: put(i,"\t",1);
146: }
147: if(cross) {
148: conf(lno,4,lbuf);
149: put(i,lbuf,5);
150: }
151: break;
152:
153: case 3:
154: i = dfile(curs);
155: put(i,curs,cursl);
156: if((ct = temp[t1].ct) >= 8) {
157: put(i,temp[t1].beg,8);
158: *curf = -1;
159: } else {
160: put(i,temp[t1].beg,ct);
161: *curf = '\t';
162: }
163: put(i,curf,curfl);
164: conf(lno,4,lbuf);
165: put(i,lbuf,5);
166: }
167: if(!nocont)
168: put(i,line,l + 1);
169:
170: }
171: t1 = 0;
172: l = -1;
173: lno++;
174: cs = SKIP;
175:
176: return;
177: }
178:
179:
180: asym()
181: {
182: int i;
183: char *p;
184:
185: if(cs == COLLECT) {
186: if(cross) {
187: p = temp[t1].beg;
188: cursl = &line[l] - p;
189: cursl = cursl>8?8:cursl;
190: i = -1;
191: while(++i < cursl)
192: curs[i] = *p++;
193: if(cursl < 8)
194: curs[cursl++] = '\t';
195: else
196: curs[cursl++] = -1;
197: }
198: save();
199: }
200: cs = SKIP;
201: }
202:
203: asw()
204: {
205: switch(gch[fl]) {
206:
207: case 0:
208: if(cs == COLLECT) save();
209: cs = SKIP;
210: flag[++fl] = &asw;
211: gch[fl] = c;
212: return(1);
213:
214: case '\'':
215: if(c == '\\') {
216: gch[fl] = c;
217: return(1);
218: }
219: break;
220:
221: case '"':
222: gch[fl] = '\'';
223:
224: if(c == '\\') {
225: flag[++fl] = &asw;
226: gch[fl] = c;
227: return(1);
228: }
229: return(1);
230:
231: case '<':
232: if(c == '\n') out();
233: if(c == '\\') {
234: flag[++fl] = &asw;
235: gch[fl] = c;
236: return(1);
237: }
238: if(c != '>') return(1);
239: break;
240:
241: case '/':
242: if(c != '\n') return(1);
243:
244: case '\\':
245: if(c == '\n') out();
246:
247: }
248: fl--;
249: return(1);
250:
251: }
252:
253: csw()
254: {
255: if(cs == COLLECT) save();
256:
257: switch(gch[fl]) {
258:
259: case 0:
260: if(c == '*')
261: if(line[l - 1] != '/')
262: return(1);
263: gch[++fl] = c;
264: flag[fl] = &csw;
265: return(1);
266:
267: case '*':
268: if(c == '\n') out();
269: if(c == '/' && line[l - 1] == '*')
270: break;
271: return(1);
272:
273: case '\'':
274: case '"':
275: if(c == gch[fl])
276: break;
277: if(c == '\\') {
278: gch[++fl] = c;
279: flag[fl] = &csw;
280: }
281: return(1);
282:
283: case '\\':
284: break;
285: }
286: fl--;
287: return(1);
288: }
289:
290: incl()
291: {
292: /* printf("incl: l = %d hl = %d dl = %d\n",level,hlevel,dlevel);/*DEBUG*/
293: if(cs == COLLECT) save();
294: if(hlevel) {
295: hlevel = 0;
296: level++;
297: } else {
298: dlevel++;
299: }
300:
301: cs = SKIP;
302: }
303:
304: decl()
305: {
306: /* printf("decl: l = %d hl = %d dl = %d\n",level,hlevel,dlevel);/*DEBUG*/
307: if(cs == COLLECT) save();
308: cs = SKIP;
309: if(dlevel) {
310: dlevel--;
311: return;
312: }
313: if(--level > 0) return;
314: curs[0] = '_';
315: curs[1] = '\t';
316: cursl = 2;
317: level = 0;
318: return;
319: }
320:
321: csym()
322: {
323: int i;
324: char *p;
325:
326: /* printf("csym: l = %d hl = %d dl = %d\n",level,hlevel,dlevel);/*DEBUG*/
327: /* printf("%s\n", temp[t1].beg); /*DEBUG */
328: p = temp[t1].beg;
329: if(cs == COLLECT && level == 0) {
330: if(cross) {
331: cursl = temp[t1].ct;
332: cursl = cursl>8?8:cursl;
333: i = -1;
334: while(++i < cursl)
335: curs[i] = *p++;
336: if(cursl < 8)
337: curs[cursl++] = '\t';
338: else
339: curs[cursl++] = -1;
340: }
341: hlevel = 1;
342: }
343: cs = SKIP;
344: }
345:
346: dfile(a)
347: char *a;
348: {
349: if(*a < 'c') return(0);
350: if(*a < 'h') return(1);
351: if(*a < 'r') return(2);
352: return(3);
353: }
354:
355:
356: sk2()
357: {
358: cs = SKIP2;
359: }
360:
361: sk()
362: {
363: cs = SKIP;
364: }
365:
366: tabs()
367: {
368: if(l == 0) l = -1;
369: }
370:
371:
372: search(symbol,length,params,install)
373: char *symbol;
374: int length;
375: struct htab *params;
376: int install;
377: {
378: char *sp,*p;
379: static int curb,*hptr,hsiz,nsym,ssiz;
380: static char *symt;
381: auto h,i,j,k;
382:
383: if(hptr != params->hptr) {
384: hptr = params->hptr;
385: hsiz = params->hsiz;
386: symt = params->symt;
387: ssiz = params->ssiz;
388: curb = params->curb;
389: nsym = params->nsym;
390: }
391:
392: symbol[length] = '\0';
393: sp = symbol;
394:
395: i = length;
396: h = 1;
397: while(i--)
398: h =* *sp++;
399:
400: if(h == 0100000) {
401: h = 1;
402: } else {
403: h = h<0?(-h)%hsiz:h%hsiz;
404: }
405: if(h == 0) h++;
406: /* printf("%s %d\n",symbol,h); /*DEBUG*/
407:
408: while((p = &symt[hptr[h]]) > symt) {
409: j = length + 2;
410: sp = symbol;
411: while(--j) {
412: if(*p++ != *sp++) goto no;
413: }
414: return(*p);
415: no:
416: h = (h + h)%hsiz;
417: }
418: if(install) {
419: if(++nsym >= hsiz) {
420: printf("Too many symbols.\n");
421: dexit();
422: }
423:
424: hptr[h] = curb;
425: length++;
426: if((curb + length) >= ssiz) {
427: printf("Too many characters in symbols.\n");
428: dexit();
429: }
430:
431: while(length--)
432: symt[curb++] = *symbol++;
433: symt[curb++] = install;
434: params->curb = curb;
435: params->nsym = nsym;
436: }
437: return(0);
438: }
439:
440: conf(n,width,buf)
441: char *buf;
442: {
443: auto i,a;
444:
445: i = width;
446: while(i--) buf[i] = ' ';
447:
448: buf[(a = n/10)?conf(a,--width,buf):--width] = n%10 + '0';
449:
450: return(++width);
451: }
452:
453:
454: comp(a,b)
455: char *a;
456: char *b;
457: {
458: a--;
459: b--;
460: while(*++a == *++b)
461: if(*a == '\0') return(1);
462: return(0);
463: }
464:
465: semi()
466: {
467: if(cs == COLLECT) save();
468: if(only) return;
469: xtrn = 0;
470: if(!level) {
471: ssw = 0;
472: if(!type) {
473: hlevel = 0;
474: curs[0] = '_';
475: curs[1] = '\t';
476: cursl = 2;
477: }
478: type = 0;
479: }
480: cs = SKIP;
481: }
482:
483: wspace()
484: {
485: if(c == ' ' || c == '\t')
486: return(1);
487: sav1();
488: fl--;
489: return(0);
490: }
491:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.