1: # include <stdio.h> 2: # include "prep.h" 3: 4: int (*acts[])() = {0, 5: coll, 6: save, 7: ctout, 8: gobble2, 9: hyphen, 10: bsp, 11: bslash, 12: punc 13: }; 14: 15: 16: char *ignonl = "/usr/share/misc/eign"; 17: 18: char tab[NUMS][NUMC] = { 19: 20: /*SKIP*/ 21: 0, 0, 0, 0, 0, 0, 0, 0, 22: 0, 0, 3, 0, 0, 0, 0, 0, 23: 0, 0, 0, 0, 0, 0, 0, 0, 24: 0, 0, 0, 0, 0, 0, 0, 0, 25: 0, 8, 0, 0, 0, 0, 0, 0, 26: 8, 8, 0, 0, 8, 0, 8, 0, 27: 0, 0, 0, 0, 0, 0, 0, 0, 28: 0, 0, 8, 8, 0, 0, 0, 8, 29: 0, 1, 1, 1, 1, 1, 1, 1, 30: 1, 1, 1, 1, 1, 1, 1, 1, 31: 1, 1, 1, 1, 1, 1, 1, 1, 32: 1, 1, 1, 0, 7, 0, 0, 0, 33: 0, 1, 1, 1, 1, 1, 1, 1, 34: 1, 1, 1, 1, 1, 1, 1, 1, 35: 1, 1, 1, 1, 1, 1, 1, 1, 36: 1, 1, 1, 0, 0, 0, 0, 0, 37: /*COLLECT*/ 38: 2, 2, 2, 2, 2, 2, 2, 2, 39: 6, 2, 3, 2, 2, 2, 2, 2, 40: 2, 2, 2, 2, 2, 2, 2, 2, 41: 2, 2, 2, 2, 2, 2, 2, 2, 42: 2, 8, 2, 2, 2, 2, 2, 0, 43: 8, 8, 2, 2, 8, 5, 8, 2, 44: 2, 2, 2, 2, 2, 2, 2, 2, 45: 2, 2, 8, 8, 2, 2, 2, 8, 46: 2, 0, 0, 0, 0, 0, 0, 0, 47: 0, 0, 0, 0, 0, 0, 0, 0, 48: 0, 0, 0, 0, 0, 0, 0, 0, 49: 0, 0, 0, 2, 7, 2, 2, 2, 50: 2, 0, 0, 0, 0, 0, 0, 0, 51: 0, 0, 0, 0, 0, 0, 0, 0, 52: 0, 0, 0, 0, 0, 0, 0, 0, 53: 0, 0, 0, 2, 2, 2, 2, 2, 54: /*SKIP2*/ 55: 0, 0, 0, 0, 0, 0, 0, 0, 56: 0, 0, 3, 0, 0, 0, 0, 0, 57: 0, 0, 0, 0, 0, 0, 0, 0, 58: 0, 0, 0, 0, 0, 0, 0, 0, 59: 0, 8, 0, 0, 0, 0, 0, 0, 60: 8, 8, 0, 0, 8, 0, 8, 0, 61: 0, 0, 0, 0, 0, 0, 0, 0, 62: 0, 0, 8, 8, 0, 0, 0, 8, 63: 0, 1, 1, 1, 1, 1, 1, 1, 64: 1, 1, 1, 1, 1, 1, 1, 1, 65: 1, 1, 1, 1, 1, 1, 1, 1, 66: 1, 1, 1, 0, 0, 0, 0, 0, 67: 0, 1, 1, 1, 1, 1, 1, 1, 68: 1, 1, 1, 1, 1, 1, 1, 1, 69: 1, 1, 1, 1, 1, 1, 1, 1, 70: 1, 1, 1, 0, 0, 0, 0, 0 71: }; 72: 73: main(argc,argv) 74: char *argv[]; 75: { 76: auto i,j; 77: 78: if(argc > 1 && *argv[1] == '-') { 79: j = flags(argv); 80: argv += j; 81: argc -= j; 82: } 83: 84: init(); 85: 86: i = 0; 87: if(argc == 1) { 88: fi = stdin; 89: goto pipe; 90: } 91: while(++i < argc) { 92: 93: if((fi = fopen(argv[i], "r")) == NULL) { 94: fprintf(stderr, "Can't open %s\n",argv[i]); 95: exit(1); 96: } 97: 98: pipe: 99: lno = 1; 100: 101: driver(argv[i]); 102: 103: fclose(fi); 104: } 105: flsh(); 106: 107: exit(0); 108: } 109: 110: driver(arg) 111: char *arg; 112: { 113: auto p; 114: 115: l = -1; 116: while((c = line[++l] = getc(fi)) != -1) { 117: /* fprintf(stderr, "driver: c = %o l = %d\n",c,l); /*DEBUG*/ 118: if(l >= 299) { 119: lflag++; 120: l--; 121: } 122: 123: if(c & 0200) { 124: fprintf(stderr, "Illegal character: %o line %d file %s\n", 125: c, lno, arg); 126: exit(1); 127: } 128: 129: if(l == 0 && (c == '.' || c == '\'')) { 130: while((c = getc(fi)) != '\n' ) 131: if(c == -1) return; 132: lno++; 133: l = -1; 134: continue; 135: } 136: 137: if(fl) { 138: if((*flag[fl])()) 139: continue; 140: } 141: 142: /*fprintf(stderr, "cs = %d cc = %c ca = %d\n",cs,c,tab[cs][c]); /*DEBUG*/ 143: 144: if(p = tab[cs][c]) 145: (*acts[p])(); 146: continue; 147: } 148: return; 149: 150: } 151: 152: init() 153: { 154: FILE *fio, *fopen(); 155: extern coll(),save(),ctout(),asym(),asw(),csym(),csw(); 156: extern incl(),decl(),sk(),sk2(); 157: 158: 159: if(!igflg)return; 160: 161: itab.hptr = ipsp; 162: itab.symt = issp; 163: itab.hsiz = PTRI; 164: itab.ssiz = CHARI; 165: itab.nsym = 0; 166: itab.curb = 1; 167: 168: if((fio = fopen(ignonl, "r")) == NULL) { 169: fprintf(stderr, "Cannot open ignore/only file.\n"); 170: exit(1); 171: } 172: compile(fio); 173: return; 174: } 175: 176: 177: flags(argv) 178: char *argv[]; 179: { 180: int j; 181: char *ap; 182: 183: j = 1; 184: ap = argv[1]; 185: while(*++ap != '\0') { 186: switch(*ap) { 187: 188: default: 189: fprintf(stderr, "Unrecognized flag: %c\n",*ap); 190: exit(1); 191: 192: 193: case 'i': /* Ignore file */ 194: if(!igflg) { 195: igflg = 1; 196: only = 0; 197: ignonl = argv[++j]; 198: } 199: continue; 200: 201: case 'o': /*only file*/ 202: if(!igflg) { 203: igflg = 1; 204: only = 1; 205: ignonl = argv[++j]; 206: } 207: continue; 208: case 'd': /*word number*/ 209: wdflg = 1; 210: wdnum = 0; 211: num[WIDTH] = ' '; 212: continue; 213: 214: case 'p': 215: puncfl = 1; 216: continue; 217: } 218: 219: } 220: return(j); 221: } 222: compile(fio) 223: FILE *fio; 224: { 225: char buf[40],*b; 226: int i,v; 227: 228: 229: b = buf - 1; 230: while((i = *++b = getc(fio)) != EOF) { 231: if(*b == '\n') { 232: *b = '\0'; 233: search(buf,b - buf,&itab,1); 234: b = buf - 1; 235: } else { 236: if(*b == '\t') { 237: v = 0; 238: while((i = getc(fio)) != -1) { 239: if(i == '\n') break; 240: v = v*10 + (i - '0'); 241: } 242: search(buf,b - buf,&itab,v); 243: b = buf - 1; 244: } else { 245: if((b - buf) > 39) { 246: fprintf(stderr, "Ignore/only symbol too long.\n"); 247: exit(1); 248: } 249: } 250: } 251: } 252: return; 253: }