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

1.1       root        1: #
                      2: # include "mcons.c"
                      3: # include "ccmn.c"
                      4: /*int  mbuf[1024];     /*INSTR*/
                      5: /*int  tbuf[36];       /*INSTR*/
                      6: 
                      7: int    (*acts[])()     {0,
                      8:                        &coll,
                      9:                        &save,
                     10:                        &out,
                     11:                        &asym,
                     12:                        &asw,
                     13:                        &csym,
                     14:                        &csw,
                     15:                        &incl,
                     16:                        &decl,
                     17:                        &sk2,
                     18:                        &sk,
                     19:                        &tabs,
                     20:                        &semi
                     21:                        };
                     22: 
                     23: char   *tmp[5] {"/usr/tmp/crt0a",
                     24:                "/usr/tmp/crt1a",
                     25:                "/usr/tmp/crt2a",
                     26:                "/usr/tmp/crt3a",
                     27:                "/usr/tmp/crt4a"
                     28:                };
                     29: 
                     30: char   *ignonl "/usr/lib/aign";
                     31: char   *gtab   "/usr/lib/atab";
                     32: 
                     33: main(argc,argv)
                     34:        char    *argv[];
                     35: {
                     36:        auto    i,j,tm1,tm2,tm3;
                     37:        char    *fn,*av[8];
                     38: /*     extern  etext;  /*INSTR*/
                     39: 
                     40: /*     monitor(&main,&etext,&mbuf,1024);       /*INSTR*/
                     41:        if(argc < 2) {
                     42:                printf("Usage: cref [-acilonstux123] file1 ...\n");
                     43:                exit();
                     44:        }
                     45: 
                     46:        lbuf[4] = '\t';
                     47:        if(*argv[1] == '-') {
                     48:                j = flags(argv);
                     49:                argv =+ j;
                     50:                argc =- j;
                     51:        }
                     52:        if(argc == 2)   single = 1;
                     53: 
                     54: 
                     55:        init();
                     56: 
                     57:        i = 0;
                     58:        while(++i < argc) {
                     59:                curs[0] = '_';
                     60:                curs[1] = '\t';
                     61:                curs[4] = '\t';
                     62:                cursl = 2;
                     63: 
                     64:                if(fopen(argv[i],ibuf1) < 0) {
                     65:                        printf("Can't open %s\n",argv[i]);
                     66:                        dexit();
                     67:                }
                     68:                ibuf = ibuf1;
                     69: 
                     70:                curf[0] = '\t';
                     71:                curfl = 1;
                     72:                while((curf[curfl] = *argv[i]++) != 0 && curfl <= 14)
                     73:                        if(curf[curfl++] == '/')        curfl = 1;
                     74:                curf[curfl++] = '\t';
                     75: /*             printf("%s %d\n",curf,curfl);/*DEBUG*/
                     76: 
                     77:                lno = 1;
                     78: 
                     79:                driver();
                     80: 
                     81:                close(file);
                     82:        }
                     83:        for(j = 0; j < 4;) {
                     84:                flsh(j,0);
                     85:                close(tp[j++]);
                     86:        }
                     87: 
                     88: /*     monitor(0);     /*INSTR*/
                     89: /*     dexit();        /*INSTR*/
                     90: 
                     91: /*     times(tbuf);    /*INSTR*/
                     92: /*     tm1 = tbuf[15]/6;       /*INSTR*/
                     93: /*     tm2 = tbuf[19]/6;       /*INSTR*/
                     94: /*     tm3 = tbuf[23]/6;       /*INSTR*/
                     95: /*     printf("Prep: %d  %d  %d\n",tm1,tm2,tm3);       /*INSTR*/
                     96: 
                     97:        if(utmp)        exit();
                     98:        fn = "/bin/sort";
                     99:        av[0] = "sort";
                    100:        av[1] = "-d";
                    101:        av[3] = "-o";
                    102:        av[5] = 0;
                    103:        for(i = 0; i < 4; i++) {
                    104:                av[4] = av[2] = tmp[i];
                    105:                callsys(fn,av);
                    106:                if(utmp)        break;
                    107:        }
                    108: 
                    109: /*     times(tbuf);    /*INSTR*/
                    110: /*     tm1 = tbuf[27]/6;       /*INSTR*/
                    111: /*     tm2 = tbuf[31]/6;       /*INSTR*/
                    112: /*     tm3 = tbuf[35]/6;       /*INSTR*/
                    113: /*     printf("Sort: %d  %d  %d\n",tm1,tm2,tm3);       /*INSTR*/
                    114: 
                    115:        if(usw) {
                    116:                fn = "/usr/lib/upost";
                    117:                av[0] = "upost";
                    118:                i = 0;
                    119:        } else {
                    120:                fn = "/usr/lib/crpost";
                    121:                av[0] = "crpost";
                    122:                av[1] = cross? "-4x": "-3";
                    123:                if(single)      av[1][1]--;
                    124:                i = 1;
                    125:        }
                    126:        j = -1;
                    127:        while(++j < 4) {
                    128:                av[++i] = tmp[j];
                    129:                if(utmp)        break;
                    130:        }
                    131:        av[++i] = 0;
                    132: 
                    133:        callsys(fn,av);
                    134: 
                    135: /*     times(tbuf);    /*INSTR*/
                    136: /*     tm1 = tbuf[27]/6 - tm1; /*INSTR*/
                    137: /*     tm2 = tbuf[31]/6 - tm2; /*INSTR*/
                    138: /*     tm3 = tbuf[35]/6 - tm3; /*INSTR*/
                    139: /*     printf("Post: %d  %d  %d\n",tm1,tm2,tm3);       /*INSTR*/
                    140: 
                    141:        dexit();
                    142: }
                    143: 
                    144: driver()
                    145: {
                    146:        auto    p;
                    147: 
                    148: top:
                    149:        l = -1;
                    150:        while((c = line[++l] = getc(ibuf)) != -1) {
                    151:                if(l >= 131) {
                    152:                        printf("Line too long: %d %s\n",lno,curf);
                    153:                        dexit();
                    154:                }
                    155: 
                    156:                if(c & 0200) {
                    157:                        printf("Illegal character: %o line %d\n",c,lno);
                    158:                        dexit();
                    159:                }
                    160: 
                    161:                if(fl) {
                    162:                        if((*flag[fl])())
                    163:                                continue;
                    164:                }
                    165: 
                    166: /*printf("cs = %d cc = %c ca = %d\n",cs,c,tab[cs].cl[c]);      /*DEBUG*/
                    167: 
                    168:                if(p = tab[cs].cl[c])
                    169:                        (*acts[p])();
                    170:                continue;
                    171:        }
                    172:        if(ibuf == ibuf1)       return;
                    173:        ibuf = ibuf1;
                    174:        goto top;
                    175: 
                    176: }
                    177: 
                    178: init()
                    179: {
                    180:        int     b[3];
                    181:        auto    fi,i;
                    182:        extern  coll(),save(),out(),asym(),asw(),csym(),csw();
                    183:        extern  incl(),decl(),sk(),sk2();
                    184:        extern  dexit();
                    185: 
                    186:        ibuf1 = &ib1;
                    187:        ibuf2 = &ib2;
                    188: 
                    189:        xtab.hptr = &xpsp;
                    190:        xtab.symt = &xssp;
                    191:        xtab.hsiz = PTRX;
                    192:        xtab.ssiz = CHARX;
                    193:        xtab.nsym = 0;
                    194:        xtab.curb = 1;
                    195: 
                    196:        itab.hptr = &ipsp;
                    197:        itab.symt = &issp;
                    198:        itab.hsiz = PTRI;
                    199:        itab.ssiz = CHARI;
                    200:        itab.nsym = 0;
                    201:        itab.curb = 1;
                    202: 
                    203:        if((fi = open(gtab,0)) < 0) {
                    204:                printf("Cannot open grammar table; see lem\n");
                    205:                dexit();
                    206:        }
                    207: 
                    208:        i = -1;
                    209:        while(++i < NUMS)
                    210:                if(read(fi,tab[i].cl,256) < 256) {
                    211:                        printf("Bad grammar table.\n");
                    212:                        dexit();
                    213:                }
                    214: 
                    215:        close(fi);
                    216: 
                    217: 
                    218:        if((fi = open(ignonl,0)) < 0) {
                    219:                printf("Cannot open ignore/only file: %s\n",ignonl);
                    220:                dexit();
                    221:        }
                    222:        if(gtty(fi, b) != -1) {
                    223:                close(fi);
                    224:                compile();
                    225:                goto on;
                    226:        }
                    227:        if((read(fi,b,6) == 6) && (b[0] == 0100200)) {
                    228:                if(read(fi,itab.hptr,b[1]) < b[1]) {
                    229:                        printf("Cannot read ignore/only file: %s\n",ignonl);
                    230:                        dexit();
                    231:                }
                    232:                if(read(fi,itab.symt,b[2]) < b[2]) {
                    233:                        printf("Cannot read ignore/only file: %s\n",ignonl);
                    234:                        dexit();
                    235:                }
                    236:                close(fi);
                    237:        } else {
                    238:                close(fi);
                    239:                compile();
                    240:        }
                    241: 
                    242: on:
                    243:        if((signal(1,1) & 1) == 0)      signal(1,&dexit);
                    244:        if((signal(2,1) & 1) == 0)      signal(2,&dexit);
                    245:        if((signal(3,1) & 1) == 0)      signal(3,&dexit);
                    246: /*     signal(4,&dexit);
                    247:        signal(5,&dexit);
                    248:        signal(6,&dexit);
                    249:        signal(7,&dexit);
                    250:        signal(8,&dexit);
                    251:        signal(10,&dexit);
                    252:        signal(11,&dexit);
                    253:        signal(12,&dexit);
                    254: */
                    255:        if(utmp == 0) {
                    256:                while((tp[4] = creat(tmp[4],0)) < 0)
                    257:                        tmp[4][13]++;
                    258:                close(tp[4]);
                    259:                tmp[0][13] = tmp[4][13];
                    260:                tmp[1][13] = tmp[4][13];
                    261:                tmp[2][13] = tmp[4][13];
                    262:                tmp[3][13] = tmp[4][13];
                    263:                tp[0] = creat(tmp[0],CREATC);
                    264:                tp[1] = creat(tmp[1],CREATC);
                    265:                tp[2] = creat(tmp[2],CREATC);
                    266:                tp[3] = creat(tmp[3],CREATC);
                    267:        } else {
                    268:                if((tp[0] = creat(utmp,CREATC)) < 0) {
                    269:                printf("Can't create user's temp file.\n");
                    270:                        exit();
                    271:                }
                    272:        }
                    273: 
                    274:        return;
                    275: }
                    276: 
                    277: error(a)
                    278: {
                    279:        printf("Error %d\n",a);
                    280:        dexit();
                    281: }
                    282: 
                    283: dexit()
                    284: {
                    285:        extern  nflush;
                    286: 
                    287: /*     printf("nflush = %d\n",nflush); /*DEBUG*/
                    288:        if(tp[0] > 0 && utmp == 0) {
                    289:                unlink(tmp[0]);
                    290:                unlink(tmp[1]);
                    291:                unlink(tmp[2]);
                    292:                unlink(tmp[3]);
                    293:                unlink(tmp[4]);
                    294:        }
                    295:        exit();
                    296: }
                    297: 
                    298: callsys(f,v)
                    299:        char    f[],*v[];
                    300: {
                    301:        int     t,status,i;
                    302: 
                    303:        if((t = fork()) == 0) {
                    304:                execv(f,v);
                    305:                printf("Can't find %s\n",f);
                    306:                exit(1);
                    307:        } else {
                    308:                if(t == -1) {
                    309:                        printf("Try again\n");
                    310:                        return(1);
                    311:                }
                    312:        }
                    313: 
                    314:        while(t != wait(&status));
                    315: /*     printf("Status = %o, %s\n",status,f);   /*DEBUG*/
                    316:        if((t = (status & 0377)) != 0) {
                    317:                if(t != 2) {
                    318:                        printf("Fatal error in %s\n",f);
                    319:                        printf("t = %d\n",t);
                    320:                }
                    321:                dexit();
                    322:        }
                    323:        return((status>>8) & 0377);
                    324: }
                    325: 
                    326: flags(argv)
                    327:        char    *argv[];
                    328: {
                    329:        int     j,xx;
                    330:        char    *ap;
                    331: 
                    332:        j = 1;
                    333:        ap = argv[1];
                    334:        while(*++ap != '\0') {
                    335:                switch(*ap) {
                    336: 
                    337:                        default:
                    338:                                printf("Unrecognized flag: %c\n",*ap);
                    339:                                dexit();
                    340: 
                    341:                        case '1':       /* Symbol first */
                    342:                                order = 1;
                    343:                                continue;
                    344: 
                    345:                        case '2':       /* Current file first */
                    346:                                order = 2;
                    347:                                continue;
                    348: 
                    349:                        case '3':       /* Current symbol first */
                    350:                                order = 3;
                    351:                                continue;
                    352: 
                    353:                        case 'a':       /* Assembler */
                    354:                                cflag = 0;
                    355:                                continue;
                    356: 
                    357:                        case 'c':       /* C */
                    358:                                gtab = "/usr/lib/ctab";
                    359:                                if(!xx)
                    360:                                        ignonl = "/usr/lib/cign";
                    361:                                cflag = 1;
                    362:                                continue;
                    363: 
                    364:                        case 'e':       /* English */
                    365:                                gtab = "/usr/lib/etab";
                    366:                                if(!xx)
                    367:                                        ignonl = "/usr/lib/eign";
                    368:                                continue;
                    369: 
                    370:                        case 'i':       /* Ignore file */
                    371:                                if(!xx) {
                    372:                                        xx = 1;
                    373:                                        only = 0;
                    374:                                        ignonl = argv[++j];
                    375:                                }
                    376:                                continue;
                    377: 
                    378:                        case 'l':       /* Line numbers in col. 3 */
                    379:                                cross = 0;
                    380:                                continue;
                    381: 
                    382:                        case 'o':       /* Only file */
                    383:                                if(!xx) {
                    384:                                        xx = 1;
                    385:                                        only = 1;
                    386:                                        ignonl = argv[++j];
                    387:                                }
                    388:                                continue;
                    389: 
                    390:                        case 'n':       /* No context */
                    391:                                nocont = 1;
                    392:                                lbuf[4] = '\n';
                    393:                                continue;
                    394: 
                    395:                        case 's':       /* Symbols in col. 3 */
                    396:                                cross = 1;
                    397:                                continue;
                    398: 
                    399:                        case 't':
                    400:                                utmp = argv[++j];
                    401:                                tmp[0] = argv[j];
                    402:                                continue;
                    403: 
                    404:                        case 'u':       /* Unique symbols only */
                    405:                                usw = 1;
                    406:                                continue;
                    407: 
                    408:                        case 'x':       /* C externals */
                    409:                                xsw = 1;
                    410:                                gtab = "/usr/lib/ctab";
                    411:                                if(!xx)
                    412:                                        ignonl = "/usr/lib/cign";
                    413:                                cflag = 1;
                    414:                                continue;
                    415:                }
                    416:        }
                    417:        return(j);
                    418: }
                    419: 
                    420: 
                    421: compile()
                    422: {
                    423:        char    buf[40],*b;
                    424:        int     i,v;
                    425: 
                    426:        fopen(ignonl,ibuf1);
                    427: 
                    428:        b = buf - 1;
                    429:        while((*++b = getc(ibuf1)) != -1) {
                    430:                if(*b == '\n') {
                    431:                        *b = '\0';
                    432:                        search(buf,b - buf,&itab,1);
                    433:                        b = buf - 1;
                    434:                } else {
                    435:                        if(*b == '\t') {
                    436:                                v = 0;
                    437:                                while((i = getc(ibuf1)) != -1) {
                    438:                                        if(i == '\n')   break;
                    439:                                        v = v*10 + (i - '0');
                    440:                                }
                    441:                                search(buf,b - buf,&itab,v);
                    442:                                b = buf - 1;
                    443:                        } else {
                    444:                                if((b - buf) > 39) {
                    445:                                        printf("Ignore/only symbol too long");
                    446:                                        dexit();
                    447:                                }
                    448:                        }
                    449:                }
                    450:        }
                    451:        close(ibuf1);
                    452:        return;
                    453: }

unix.superglobalmegacorp.com

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