Annotation of researchv10no/cmd/cref/ind0.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.