1: #
   2: # include "econs.h"
   3: # include "ecmn.h"
   4: /*int	mbuf[1024];	/*INSTR*/
   5: /*int	tbuf[12];	/*INSTR*/
   6: 
   7: int (*acts[])() {0,
   8:             &coll,
   9:             &save,
  10:             &out,
  11:             &error,
  12:             &hyphen,
  13:             &pno
  14:             };
  15: 
  16: char    *tmp[2] {"/tmp/crt0a",
  17:         "/tmp/crt1a"
  18:         };
  19: 
  20: char    *ignonl "/usr/lib/eign";
  21: char    *gtab   "/usr/lib/etab";
  22: 
  23: main(argc,argv)
  24:     char    *argv[];
  25: {
  26:     auto    i,j,tm1,tm2,tm3;
  27:     char    *fn,*av[8];
  28: /*	extern	etext;	/*INSTR*/
  29: 
  30: /*	monitor(&main,&etext,&mbuf,1024);	/*INSTR*/
  31: 
  32:     if(*argv[1] == '-') {
  33:         j = flags(argv);
  34:         argv =+ j;
  35:         argc =- j;
  36:     }
  37: 
  38:     init();
  39: 
  40:     i = 0;
  41:     if(argc == 1) {
  42:         *ibuf1 = 0;
  43:         curfl = 2;
  44:         curf[0] = '_';
  45:         curf[1] = '\t';
  46:         goto pipe;
  47:     }
  48:     while(++i < argc) {
  49:         curs[4] = '\t';
  50: 
  51:         if(fopen(argv[i],ibuf1) < 0) {
  52:             printf("Can't open %s\n",argv[i]);
  53:             dexit();
  54:         }
  55: 
  56:         curfl = 0;
  57:         while((curf[curfl] = *argv[i]++) != 0 && curfl <=8)
  58:             if(curf[curfl++] == '/')    curfl = 0;
  59:         curf[curfl++] = '\t';
  60:         if(curfl == 8) curf[8] = -1;
  61: 
  62: pipe:
  63:         ibuf = ibuf1;
  64:         lno = 1;
  65: 
  66:         driver();
  67: 
  68:         close(file);
  69:     }
  70:     flsh(0);
  71:     close(tp[0]);
  72: 
  73: 
  74: /*	monitor(0);	/*INSTR*/
  75: /*	dexit();	/*INSTR*/
  76: 
  77: /*	times(tbuf);	/*INSTR*/
  78: /*	tm1 = tbuf[0]/6;	/*INSTR*/
  79: /*	tm2 = tbuf[1]/6;	/*INSTR*/
  80: /*	printf("Prep:  %d  %d\n", tm1, tm2);	/*INSTR*/
  81: 
  82: /*	exit();	/*DEBUG*/
  83:     fn = "/bin/sort";
  84:     av[0] = "sort";
  85:     av[1] = tmp[0];
  86:     av[2] = "-o";
  87:     av[3] = tmp[0];
  88:     av[4] = 0;
  89: 
  90:     callsys(fn, av);
  91: 
  92: /*	times(tbuf);	/*INSTR*/
  93: /*	tm1 = tbuf[3]/6;	/*INSTR*/
  94: /*	tm2 = tbuf[5]/6;	/*INSTR*/
  95: /*	printf("Sort:  %d  %d\n", tm1, tm2);	/*INSTR*/
  96: 
  97:     if(usw) {
  98:         fn = "/usr/bin/upost";
  99:         av[0] = "upost";
 100:         i = 0;
 101:     } else if(count) {
 102:         fn = "count";
 103:         av[0] = "count";
 104:         i = 0;
 105:     } else {
 106:         fn = "/usr/bin/crpost";
 107:         av[0] = "crpost";
 108:         av[1] = "-E";
 109:         i = 1;
 110:     }
 111:     av[++i] = tmp[0];
 112:     av[++i] = 0;
 113: 
 114:     callsys(fn,av);
 115: 
 116: /*	times(tbuf);	/*INSTR*/
 117: /*	tm1 = tbuf[3]/6 - tm1;	/*INSTR*/
 118: /*	tm2 = tbuf[5]/6 - tm2;	/*INSTR*/
 119: /*	printf("Post:  %d  %d\n", tm1, tm2);	/*INSTR*/
 120: 
 121:     dexit();
 122: }
 123: 
 124: driver()
 125: {
 126:     auto    p;
 127: 
 128: top:
 129:     l = -1;
 130:     while((c = line[++l] = getc(ibuf)) != -1) {
 131: /*	printf("driver: c = %o l = %d\n",c,l); /*DEBUG*/
 132:         if(l >= 299) {
 133:             printf("Line too long: %d.\n",lno);
 134:             dexit();
 135:         }
 136: 
 137:         if(c & 0200) {
 138:             printf("Illegal character: %o line %d\n",c,lno);
 139:             dexit();
 140:         }
 141: 
 142:         if(fl) {
 143:             if((*flag[fl])())
 144:                 continue;
 145:         }
 146: 
 147: /*printf("cs = %d cc = %c ca = %d\n",cs,c,tab[cs].cl[c]);	/*DEBUG*/
 148: 
 149:         if(p = tab[cs].cl[c])
 150:             (*acts[p])();
 151:         continue;
 152:     }
 153:     if(ibuf == ibuf1)   return;
 154:     ibuf = ibuf1;
 155:     goto top;
 156: 
 157: }
 158: 
 159: init()
 160: {
 161:     int b[3];
 162:     auto    fi,i;
 163:     extern  coll(),save(),out(),asym(),asw(),csym(),csw();
 164:     extern  incl(),decl(),sk(),sk2();
 165:     extern  dexit();
 166: 
 167:     ibuf1 = &ib1;
 168: 
 169: 
 170: 
 171:     if((fi = open(gtab,0)) < 0) {
 172:         printf("Cannot open grammar table; see lem\n");
 173:         dexit();
 174:     }
 175: 
 176:     i = -1;
 177:     while(++i < NUMS)
 178:         if(read(fi,tab[i].cl,256) < 256) {
 179:             printf("Bad grammar table; see lem\n");
 180:             dexit();
 181:         }
 182: 
 183:     close(fi);
 184: 
 185: 
 186: 
 187:     if(signal(1,1) != 1)    signal(1,&dexit);
 188:     if(signal(2,1) != 1)    signal(2,&dexit);
 189:     if(signal(3,1) != 1)    signal(3,&dexit);
 190:     while((tp[1] = creat(tmp[1],0)) < 0)
 191:         tmp[1][9]++;
 192:     close(tp[1]);
 193:     tmp[0][9] = tmp[1][9];
 194:     tp[0] = creat(tmp[0],CREATC);
 195: 
 196:     if(count)   return;
 197: 
 198:     itab.hptr = &ipsp;
 199:     itab.symt = &issp;
 200:     itab.hsiz = PTRI;
 201:     itab.ssiz = CHARI;
 202:     itab.nsym = 0;
 203:     itab.curb = 1;
 204: 
 205:     if((fi = open(ignonl,0)) < 0) {
 206:         printf("Cannot open ignore/only file.\n");
 207:         dexit();
 208:     }
 209:     if((read(fi,b,6) == 6) && (b[0] == 0100200)) {
 210:         if(read(fi,itab.hptr,b[1]) < b[1]) {
 211:             printf("Cannot read ignore/only file.\n");
 212:             dexit();
 213:         }
 214:         if(read(fi,itab.symt,b[2]) < b[2]) {
 215:             printf("Cannot read ignor/only file.\n");
 216:             dexit();
 217:         }
 218:         close(fi);
 219:     } else {
 220:         close(fi);
 221:         compile();
 222:     }
 223:     return;
 224: }
 225: 
 226: error(a)
 227: {
 228:     printf("Error %d\n",a);
 229:     dexit();
 230: }
 231: 
 232: dexit()
 233: {
 234:     extern  nflush;
 235: 
 236: /*	printf("nflush = %d\n",nflush);	/*DEBUG*/
 237:     if(tp[0] > 0 && utmp == 0) {
 238:         unlink(tmp[0]);
 239:         unlink(tmp[1]);
 240:     }
 241:     exit();
 242: }
 243: 
 244: callsys(f,v)
 245:     char    f[],*v[];
 246: {
 247:     int t,status,i;
 248: 
 249:     if((t = fork()) == 0) {
 250:         for(i = 1; i <= 12; i++)    signal(i,0);
 251:         execv(f,v);
 252:         printf("Can't find %s\n",f);
 253:         exit(1);
 254:     } else {
 255:         if(t == -1) {
 256:             printf("Try again\n");
 257:             return(1);
 258:         }
 259:     }
 260: 
 261:     while(t != wait(&status));
 262: /*	printf("Status = %o, %s\n",status,f);	/*DEBUG*/
 263:     if((t = (status & 0377)) != 0) {
 264:         if(t != 2) {
 265:             printf("Fatal error in %s\n",f);
 266:             printf("t = %d\n",t);
 267:         }
 268:         dexit();
 269:     }
 270:     return((status>>8) & 0377);
 271: }
 272: 
 273: flags(argv)
 274:     char    *argv[];
 275: {
 276:     int j,xx;
 277:     char    *ap;
 278: 
 279:     j = 1;
 280:     ap = argv[1];
 281:     while(*++ap != '\0') {
 282:         switch(*ap) {
 283: 
 284:             default:
 285:                 printf("Unrecognized flag: %c\n",*ap);
 286:                 dexit();
 287: 
 288:             case 'c':
 289:                 count = 1;
 290:                 continue;
 291: 
 292:             case 'i':   /* Ignore file */
 293:                 if(!xx) {
 294:                     xx = 1;
 295:                     only = 0;
 296:                     ignonl = argv[++j];
 297:                 }
 298:                 continue;
 299: 
 300:             case 'o':   /*only file*/
 301:                 if(!xx) {
 302:                     xx = 1;
 303:                     only = 1;
 304:                     ignonl = argv[++j];
 305:                 }
 306:                 continue;
 307: 
 308:             case 'p':
 309:                 page = 1;
 310:                 continue;
 311: 
 312:             case 't':
 313:                 utmp = argv[++j];
 314:                 tmp[0] = argv[j];
 315:                 continue;
 316: 
 317:             case 'u':   /* Unique symbols only */
 318:                 usw = 1;
 319:                 continue;
 320: 
 321:             case 'w':   /* Word list only */
 322:                 word = 1;
 323:                 continue;
 324: 
 325:         }
 326:     }
 327:     return(j);
 328: }
 329: 
 330: 
 331: compile()
 332: {
 333:     char    buf[40],*b;
 334:     int i,v;
 335: 
 336:     fopen(ignonl,ibuf1);
 337: 
 338:     b = buf - 1;
 339:     while((*++b = getc(ibuf1)) != -1) {
 340:         if(*b == '\n') {
 341:             *b = '\0';
 342:             search(buf,b - buf,&itab,1);
 343:             b = buf - 1;
 344:         } else {
 345:             if(*b == '\t') {
 346:                 v = 0;
 347:                 while((i = getc(ibuf1)) != -1) {
 348:                     if(i == '\n')   break;
 349:                     v = v*10 + (i - '0');
 350:                 }
 351:                 search(buf,b - buf,&itab,v);
 352:                 b = buf - 1;
 353:             } else {
 354:                 if((b - buf) > 39) {
 355:                     printf("Ignore/only symbol too long.\n");
 356:                     dexit();
 357:                 }
 358:             }
 359:         }
 360:     }
 361:     close(ibuf1);
 362:     return;
 363: }

Defined functions

callsys defined in line 244; used 2 times
compile defined in line 331; used 1 times
dexit defined in line 232; used 19 times
driver defined in line 124; used 1 times
  • in line 66
error defined in line 226; used 2 times
flags defined in line 273; used 1 times
  • in line 33
init defined in line 159; used 1 times
  • in line 38
main defined in line 23; never used

Defined variables

gtab defined in line 21; used 1 times
ignonl defined in line 20; used 4 times
tmp defined in line 16; used 11 times
Last modified: 1975-05-14
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1252
Valid CSS Valid XHTML 1.0 Strict