Annotation of researchv10dc/vol2/index/tools/xsed/sed0.c, revision 1.1

1.1     ! root        1: #include <stdio.h>
        !             2: #include "sed.h"
        !             3: 
        !             4: struct label   *labtab = ltab;
        !             5: char   CGMES[] = "sed: Command garbled: %s\n";
        !             6: char   TMMES[] = "sed: Too much text: %s\n";
        !             7: char   LTL[]   = "sed: Label too long: %s\n";
        !             8: char   AD0MES[]        = "sed: No addresses allowed: %s\n";
        !             9: char   AD1MES[]        = "sed: Only one address allowed: %s\n";
        !            10: char   bittab[]  = {
        !            11:                1,
        !            12:                2,
        !            13:                4,
        !            14:                8,
        !            15:                16,
        !            16:                32,
        !            17:                64,
        !            18:                128
        !            19:        };
        !            20: 
        !            21: main(argc, argv)
        !            22: char   *argv[];
        !            23: {
        !            24: 
        !            25:        eargc = argc;
        !            26:        eargv = argv;
        !            27: 
        !            28:        badp = &bad;
        !            29:        aptr = abuf;
        !            30:        hspend = holdsp;
        !            31:        lab = labtab + 1;       /* 0 reserved for end-pointer */
        !            32:        rep = ptrspace;
        !            33:        rep->r1.ad1 = respace;
        !            34:        lbend = &linebuf[LBSIZE];
        !            35:        hend = &holdsp[LBSIZE];
        !            36:        lcomend = &genbuf[71];
        !            37:        ptrend = &ptrspace[PTRSIZE];
        !            38:        reend = &respace[RESIZE];
        !            39:        labend = &labtab[LABSIZE];
        !            40:        lnum = 0;
        !            41:        pending = 0;
        !            42:        depth = 0;
        !            43:        spend = linebuf;
        !            44:        hspend = holdsp;
        !            45:        fcode[0] = stdout;
        !            46:        nfiles = 1;
        !            47:        lastre = NULL;
        !            48: 
        !            49:        if(eargc == 1)
        !            50:                exit(0);
        !            51: 
        !            52: 
        !            53:        while (--eargc > 0 && (++eargv)[0][0] == '-')
        !            54:                switch (eargv[0][1]) {
        !            55: 
        !            56:                case 'n':
        !            57:                        nflag++;
        !            58:                        continue;
        !            59: 
        !            60:                case 'f':
        !            61:                        if(eargc-- <= 0)        exit(2);
        !            62: 
        !            63:                        if((fin = fopen(*++eargv, "r")) == NULL) {
        !            64:                                fprintf(stderr, "sed: Cannot open pattern-file: %s\n", *eargv);
        !            65:                                exit(2);
        !            66:                        }
        !            67: 
        !            68:                        fcomp();
        !            69:                        fclose(fin);
        !            70:                        continue;
        !            71: 
        !            72:                case 'e':
        !            73:                        eflag++;
        !            74:                        fcomp();
        !            75:                        eflag = 0;
        !            76:                        continue;
        !            77: 
        !            78:                case 'g':
        !            79:                        gflag++;
        !            80:                        continue;
        !            81: 
        !            82:                default:
        !            83:                        fprintf(stderr, "sed: Unknown flag: %c\n", eargv[0][1]);
        !            84:                        continue;
        !            85:                }
        !            86: 
        !            87: 
        !            88:        if(compfl == 0) {
        !            89:                eargv--;
        !            90:                eargc++;
        !            91:                eflag++;
        !            92:                fcomp();
        !            93:                eargv++;
        !            94:                eargc--;
        !            95:                eflag = 0;
        !            96:        }
        !            97: 
        !            98:        if(depth) {
        !            99:                fprintf(stderr, "sed: Too many {'s\n");
        !           100:                exit(2);
        !           101:        }
        !           102: 
        !           103:        labtab->address = rep;
        !           104: 
        !           105:        dechain();
        !           106: 
        !           107: /*     abort();        /*DEBUG*/
        !           108: 
        !           109:        if(eargc <= 0)
        !           110:                execute((char *)NULL);
        !           111:        else while(--eargc >= 0) {
        !           112:                execute(*eargv++);
        !           113:        }
        !           114:        fclose(stdout);
        !           115:        exit(0);
        !           116: }
        !           117: fcomp()
        !           118: {
        !           119: 
        !           120:        register char   *p, *op, *tp;
        !           121:        char    *address();
        !           122:        union reptr     *pt, *pt1;
        !           123:        int     i;
        !           124:        struct label    *lpt;
        !           125: 
        !           126:        compfl = 1;
        !           127:        op = lastre;
        !           128: 
        !           129:        if(rline(linebuf) < 0) {
        !           130:                lastre = op;
        !           131:                return;
        !           132:        }
        !           133:        if(*linebuf == '#') {
        !           134:                if(linebuf[1] == 'n')
        !           135:                        nflag = 1;
        !           136:        }
        !           137:        else {
        !           138:                cp = linebuf;
        !           139:                goto comploop;
        !           140:        }
        !           141: 
        !           142:        for(;;) {
        !           143:                if(rline(linebuf) < 0)  break;
        !           144: 
        !           145:                cp = linebuf;
        !           146: 
        !           147: comploop:
        !           148: /*     fprintf(stdout, "cp: %s\n", cp);        /*DEBUG*/
        !           149:                while(*cp == ' ' || *cp == '\t')        cp++;
        !           150:                if(*cp == '\0' || *cp == '#')           continue;
        !           151:                if(*cp == ';') {
        !           152:                        cp++;
        !           153:                        goto comploop;
        !           154:                }
        !           155: 
        !           156:                p = address(rep->r1.ad1);
        !           157:                if(p == badp) {
        !           158:                        fprintf(stderr, CGMES, linebuf);
        !           159:                        exit(2);
        !           160:                }
        !           161: 
        !           162:                if(p == 0) {
        !           163:                        p = rep->r1.ad1;
        !           164:                        rep->r1.ad1 = 0;
        !           165:                } else {
        !           166:                        if(p == rep->r1.ad1) {
        !           167:                                if(op)
        !           168:                                        rep->r1.ad1 = op;
        !           169:                                else {
        !           170:                                        fprintf(stderr, "sed: First RE may not be null\n");
        !           171:                                        exit(2);
        !           172:                                }
        !           173:                        }
        !           174:                        op = rep->r1.ad1;
        !           175:                        if(*cp == ',' || *cp == ';') {
        !           176:                                cp++;
        !           177:                                if((rep->r1.ad2 = p) > reend) {
        !           178:                                        fprintf(stderr,"1st\n");
        !           179:                                        fprintf(stderr, TMMES, linebuf);
        !           180:                                        exit(2);
        !           181:                                }
        !           182:                                p = address(rep->r1.ad2);
        !           183:                                if(p == badp || p == 0) {
        !           184:                                        fprintf(stderr, CGMES, linebuf);
        !           185:                                        exit(2);
        !           186:                                }
        !           187:                                if(p == rep->r1.ad2)
        !           188:                                        rep->r1.ad2 = op;
        !           189:                                else
        !           190:                                        op = rep->r1.ad2;
        !           191: 
        !           192:                        } else
        !           193:                                rep->r1.ad2 = 0;
        !           194:                }
        !           195: 
        !           196:                if(p > reend) {
        !           197:                        fprintf(stderr,"1a\n");
        !           198:                        fprintf(stderr, "sed: Too much text: %s\n", linebuf);
        !           199:                        exit(2);
        !           200:                }
        !           201: 
        !           202:                while(*cp == ' ' || *cp == '\t')        cp++;
        !           203: 
        !           204: swit:
        !           205:                switch(*cp++) {
        !           206: 
        !           207:                        default:
        !           208: /*fprintf(stderr, "cp = %d; *cp = %o\n", cp - linebuf, *cp);*/
        !           209:                                fprintf(stderr, "sed: Unrecognized command: %s\n", linebuf);
        !           210:                                exit(2);
        !           211: 
        !           212:                        case '!':
        !           213:                                rep->r1.negfl = 1;
        !           214:                                goto swit;
        !           215: 
        !           216:                        case '{':
        !           217:                                rep->r1.command = BCOM;
        !           218:                                rep->r1.negfl = !(rep->r1.negfl);
        !           219:                                cmpend[depth++] = &rep->r2.lb1;
        !           220:                                if(++rep >= ptrend) {
        !           221:                                        fprintf(stderr, "sed: Too many commands: %s\n", linebuf);
        !           222:                                        exit(2);
        !           223:                                }
        !           224:                                rep->r1.ad1 = p;
        !           225:                                if(*cp == '\0') continue;
        !           226: 
        !           227:                                goto comploop;
        !           228: 
        !           229:                        case '}':
        !           230:                                if(rep->r1.ad1) {
        !           231:                                        fprintf(stderr, AD0MES, linebuf);
        !           232:                                        exit(2);
        !           233:                                }
        !           234: 
        !           235:                                if(--depth < 0) {
        !           236:                                        fprintf(stderr, "sed: Too many }'s\n");
        !           237:                                        exit(2);
        !           238:                                }
        !           239:                                *cmpend[depth] = rep;
        !           240: 
        !           241:                                rep->r1.ad1 = p;
        !           242:                                if(*cp == 0)    continue;
        !           243:                                goto comploop;
        !           244: 
        !           245:                        case '=':
        !           246:                                rep->r1.command = EQCOM;
        !           247:                                if(rep->r1.ad2) {
        !           248:                                        fprintf(stderr, AD1MES, linebuf);
        !           249:                                        exit(2);
        !           250:                                }
        !           251:                                break;
        !           252: 
        !           253:                        case ':':
        !           254:                                if(rep->r1.ad1) {
        !           255:                                        fprintf(stderr, AD0MES, linebuf);
        !           256:                                        exit(2);
        !           257:                                }
        !           258: 
        !           259:                                while(*cp++ == ' ');
        !           260:                                cp--;
        !           261: 
        !           262: 
        !           263:                                tp = lab->asc;
        !           264:                                while((*tp++ = *cp++))
        !           265:                                        if(tp >= &(lab->asc[8])) {
        !           266:                                                fprintf(stderr, LTL, linebuf);
        !           267:                                                exit(2);
        !           268:                                        }
        !           269:                                *--tp = '\0';
        !           270: 
        !           271:                                if(lpt = search(lab)) {
        !           272:                                        if(lpt->address) {
        !           273:                                                fprintf(stderr, "sed: Duplicate labels: %s\n", linebuf);
        !           274:                                                exit(2);
        !           275:                                        }
        !           276:                                } else {
        !           277:                                        lab->chain = 0;
        !           278:                                        lpt = lab;
        !           279:                                        if(++lab >= labend) {
        !           280:                                                fprintf(stderr, "sed: Too many labels: %s\n", linebuf);
        !           281:                                                exit(2);
        !           282:                                        }
        !           283:                                }
        !           284:                                lpt->address = rep;
        !           285:                                rep->r1.ad1 = p;
        !           286: 
        !           287:                                continue;
        !           288: 
        !           289:                        case 'a':
        !           290:                                rep->r1.command = ACOM;
        !           291:                                if(rep->r1.ad2) {
        !           292:                                        fprintf(stderr, AD1MES, linebuf);
        !           293:                                        exit(2);
        !           294:                                }
        !           295:                                if(*cp == '\\') cp++;
        !           296:                                if(*cp++ != '\n') {
        !           297:                                        fprintf(stderr, CGMES, linebuf);
        !           298:                                        exit(2);
        !           299:                                }
        !           300:                                rep->r1.re1 = p;
        !           301:                                p = text(rep->r1.re1);
        !           302:                                break;
        !           303:                        case 'c':
        !           304:                                rep->r1.command = CCOM;
        !           305:                                if(*cp == '\\') cp++;
        !           306:                                if(*cp++ != ('\n')) {
        !           307:                                        fprintf(stderr, CGMES, linebuf);
        !           308:                                        exit(2);
        !           309:                                }
        !           310:                                rep->r1.re1 = p;
        !           311:                                p = text(rep->r1.re1);
        !           312:                                break;
        !           313:                        case 'i':
        !           314:                                rep->r1.command = ICOM;
        !           315:                                if(rep->r1.ad2) {
        !           316:                                        fprintf(stderr, AD1MES, linebuf);
        !           317:                                        exit(2);
        !           318:                                }
        !           319:                                if(*cp == '\\') cp++;
        !           320:                                if(*cp++ != ('\n')) {
        !           321:                                        fprintf(stderr, CGMES, linebuf);
        !           322:                                        exit(2);
        !           323:                                }
        !           324:                                rep->r1.re1 = p;
        !           325:                                p = text(rep->r1.re1);
        !           326:                                break;
        !           327: 
        !           328:                        case 'g':
        !           329:                                rep->r1.command = GCOM;
        !           330:                                break;
        !           331: 
        !           332:                        case 'G':
        !           333:                                rep->r1.command = CGCOM;
        !           334:                                break;
        !           335: 
        !           336:                        case 'h':
        !           337:                                rep->r1.command = HCOM;
        !           338:                                break;
        !           339: 
        !           340:                        case 'H':
        !           341:                                rep->r1.command = CHCOM;
        !           342:                                break;
        !           343: 
        !           344:                        case 't':
        !           345:                                rep->r1.command = TCOM;
        !           346:                                goto jtcommon;
        !           347: 
        !           348:                        case 'b':
        !           349:                                rep->r1.command = BCOM;
        !           350: jtcommon:
        !           351:                                while(*cp++ == ' ');
        !           352:                                cp--;
        !           353: 
        !           354:                                if(*cp == '\0') {
        !           355:                                        if(pt = labtab->chain) {
        !           356:                                                while(pt1 = pt->r2.lb1)
        !           357:                                                        pt = pt1;
        !           358:                                                pt->r2.lb1 = rep;
        !           359:                                        } else
        !           360:                                                labtab->chain = rep;
        !           361:                                        break;
        !           362:                                }
        !           363:                                tp = lab->asc;
        !           364:                                while((*tp++ = *cp++))
        !           365:                                        if(tp >= &(lab->asc[8])) {
        !           366:                                                fprintf(stderr, LTL, linebuf);
        !           367:                                                exit(2);
        !           368:                                        }
        !           369:                                cp--;
        !           370:                                *--tp = '\0';
        !           371: 
        !           372:                                if(lpt = search(lab)) {
        !           373:                                        if(lpt->address) {
        !           374:                                                rep->r2.lb1 = lpt->address;
        !           375:                                        } else {
        !           376:                                                pt = lpt->chain;
        !           377:                                                while(pt1 = pt->r2.lb1)
        !           378:                                                        pt = pt1;
        !           379:                                                pt->r2.lb1 = rep;
        !           380:                                        }
        !           381:                                } else {
        !           382:                                        lab->chain = rep;
        !           383:                                        lab->address = 0;
        !           384:                                        if(++lab >= labend) {
        !           385:                                                fprintf(stderr, "sed: Too many labels: %s\n", linebuf);
        !           386:                                                exit(2);
        !           387:                                        }
        !           388:                                }
        !           389:                                break;
        !           390: 
        !           391:                        case 'n':
        !           392:                                rep->r1.command = NCOM;
        !           393:                                break;
        !           394: 
        !           395:                        case 'N':
        !           396:                                rep->r1.command = CNCOM;
        !           397:                                break;
        !           398: 
        !           399:                        case 'p':
        !           400:                                rep->r1.command = PCOM;
        !           401:                                break;
        !           402: 
        !           403:                        case 'P':
        !           404:                                rep->r1.command = CPCOM;
        !           405:                                break;
        !           406: 
        !           407:                        case 'r':
        !           408:                                rep->r1.command = RCOM;
        !           409:                                if(rep->r1.ad2) {
        !           410:                                        fprintf(stderr, AD1MES, linebuf);
        !           411:                                        exit(2);
        !           412:                                }
        !           413:                                if(*cp++ != ' ') {
        !           414:                                        fprintf(stderr, CGMES, linebuf);
        !           415:                                        exit(2);
        !           416:                                }
        !           417:                                rep->r1.re1 = p;
        !           418:                                p = text(rep->r1.re1);
        !           419:                                break;
        !           420: 
        !           421:                        case 'd':
        !           422:                                rep->r1.command = DCOM;
        !           423:                                break;
        !           424: 
        !           425:                        case 'D':
        !           426:                                rep->r1.command = CDCOM;
        !           427:                                rep->r2.lb1 = ptrspace;
        !           428:                                break;
        !           429: 
        !           430:                        case 'q':
        !           431:                                rep->r1.command = QCOM;
        !           432:                                if(rep->r1.ad2) {
        !           433:                                        fprintf(stderr, AD1MES, linebuf);
        !           434:                                        exit(2);
        !           435:                                }
        !           436:                                break;
        !           437: 
        !           438:                        case 'l':
        !           439:                                rep->r1.command = LCOM;
        !           440:                                break;
        !           441: 
        !           442:                        case 's':
        !           443:                                rep->r1.command = SCOM;
        !           444:                                seof = *cp++;
        !           445:                                rep->r1.re1 = p;
        !           446:                                p = compile(rep->r1.re1);
        !           447:                                if(p == badp) {
        !           448:                                        fprintf(stderr, CGMES, linebuf);
        !           449:                                        exit(2);
        !           450:                                }
        !           451:                                if(p == rep->r1.re1) {
        !           452:                                        if(op == NULL) {
        !           453:                                                fprintf(stderr, "sed: First RE may not be null.\n");
        !           454:                                                exit(2);
        !           455:                                        }
        !           456:                                        rep->r1.re1 = op;
        !           457:                                } else {
        !           458:                                        op = rep->r1.re1;
        !           459:                                }
        !           460: 
        !           461:                                if((rep->r1.rhs = p) > reend) {
        !           462:                                        fprintf(stderr,"2nd\n");
        !           463:                                        fprintf(stderr, TMMES, linebuf);
        !           464:                                        exit(2);
        !           465:                                }
        !           466: 
        !           467:                                if((p = compsub(rep->r1.rhs)) == badp) {
        !           468:                                        fprintf(stderr, CGMES, linebuf);
        !           469:                                        exit(2);
        !           470:                                }
        !           471:                                if(*cp == 'g') {
        !           472:                                        cp++;
        !           473:                                        rep->r1.gfl++;
        !           474:                                } else if(gflag)
        !           475:                                        rep->r1.gfl++;
        !           476: 
        !           477:                                if(*cp == 'p') {
        !           478:                                        cp++;
        !           479:                                        rep->r1.pfl = 1;
        !           480:                                }
        !           481: 
        !           482:                                if(*cp == 'P') {
        !           483:                                        cp++;
        !           484:                                        rep->r1.pfl = 2;
        !           485:                                }
        !           486: 
        !           487:                                if(*cp == 'w') {
        !           488:                                        cp++;
        !           489:                                        if(*cp++ !=  ' ') {
        !           490:                                                fprintf(stderr, CGMES, linebuf);
        !           491:                                                exit(2);
        !           492:                                        }
        !           493:                                        if(nfiles >= MAXFILES) {
        !           494:                                                fprintf(stderr, "sed: Too many files in w commands 1 \n");
        !           495:                                                exit(2);
        !           496:                                        }
        !           497: 
        !           498:                                        text(fname[nfiles]);
        !           499:                                        for(i = nfiles - 1; i >= 0; i--)
        !           500:                                                if(cmp(fname[nfiles],fname[i]) == 0) {
        !           501:                                                        rep->r1.fcode = fcode[i];
        !           502:                                                        goto done;
        !           503:                                                }
        !           504:                                        if((rep->r1.fcode = fopen(fname[nfiles], "w")) == NULL) {
        !           505:                                                fprintf(stderr, "sed: Cannot open %s\n", fname[nfiles]);
        !           506:                                                exit(2);
        !           507:                                        }
        !           508:                                        fcode[nfiles++] = rep->r1.fcode;
        !           509:                                }
        !           510:                                break;
        !           511: 
        !           512:                        case 'w':
        !           513:                                rep->r1.command = WCOM;
        !           514:                                if(*cp++ != ' ') {
        !           515:                                        fprintf(stderr, CGMES, linebuf);
        !           516:                                        exit(2);
        !           517:                                }
        !           518:                                if(nfiles >= MAXFILES){
        !           519:                                        fprintf(stderr, "sed: Too many files in w commands 2 \n");
        !           520:                                        fprintf(stderr, "nfiles = %d; MAXF = %d\n", nfiles, MAXFILES);
        !           521:                                        exit(2);
        !           522:                                }
        !           523: 
        !           524:                                text(fname[nfiles]);
        !           525:                                for(i = nfiles - 1; i >= 0; i--)
        !           526:                                        if(cmp(fname[nfiles], fname[i]) == 0) {
        !           527:                                                rep->r1.fcode = fcode[i];
        !           528:                                                goto done;
        !           529:                                        }
        !           530: 
        !           531:                                if((rep->r1.fcode = fopen(fname[nfiles], "w")) == NULL) {
        !           532:                                        fprintf(stderr, "sed: Cannot create %s\n", fname[nfiles]);
        !           533:                                        exit(2);
        !           534:                                }
        !           535:                                fcode[nfiles++] = rep->r1.fcode;
        !           536:                                break;
        !           537: 
        !           538:                        case 'x':
        !           539:                                rep->r1.command = XCOM;
        !           540:                                break;
        !           541: 
        !           542:                        case 'y':
        !           543:                                rep->r1.command = YCOM;
        !           544:                                seof = *cp++;
        !           545:                                rep->r1.re1 = p;
        !           546:                                p = ycomp(rep->r1.re1);
        !           547:                                if(p == badp) {
        !           548:                                        fprintf(stderr, CGMES, linebuf);
        !           549:                                        exit(2);
        !           550:                                }
        !           551:                                if(p > reend) {
        !           552:                                        fprintf(stderr,"3rd\n");
        !           553:                                        fprintf(stderr, TMMES, linebuf);
        !           554:                                        exit(2);
        !           555:                                }
        !           556:                                break;
        !           557: 
        !           558:                }
        !           559: done:
        !           560:                if(++rep >= ptrend) {
        !           561:                        fprintf(stderr, "sed: Too many commands, last: %s\n", linebuf);
        !           562:                        exit(2);
        !           563:                }
        !           564: 
        !           565:                rep->r1.ad1 = p;
        !           566: 
        !           567:                if(*cp++ != '\0') {
        !           568:                        if(cp[-1] == ';')
        !           569:                                goto comploop;
        !           570:                        fprintf(stderr, CGMES, linebuf);
        !           571:                        exit(2);
        !           572:                }
        !           573: 
        !           574:        }
        !           575: }
        !           576: char   *
        !           577: compsub(rhsbuf)
        !           578: char   *rhsbuf;
        !           579: {
        !           580:        register char   *p, *q;
        !           581: 
        !           582:        p = rhsbuf;
        !           583:        q = cp;
        !           584:        for(;;) {
        !           585:                if((*p = *q++) == '\\') {
        !           586:                        *p = *q++;
        !           587:                        if(*p > numbra + '0' && *p <= '9')
        !           588:                                return(badp);
        !           589:                        if(*p == 'n')
        !           590:                                *p = '\n';
        !           591:                        if(*p == 'b'){
        !           592:                                *p++ = '\b';
        !           593:                                continue;
        !           594:                        }
        !           595:                        *p++ |= 0200;
        !           596:                        continue;
        !           597:                }
        !           598:                if(*p == seof) {
        !           599:                        *p++ = '\0';
        !           600:                        cp = q;
        !           601:                        return(p);
        !           602:                }
        !           603:                if(*p++ == '\0') {
        !           604:                        return(badp);
        !           605:                }
        !           606: 
        !           607:        }
        !           608: }
        !           609: 
        !           610: char *
        !           611: compile(expbuf)
        !           612: char   *expbuf;
        !           613: {
        !           614:        register c;
        !           615:        register char *ep, *sp;
        !           616:        char    neg;
        !           617:        char *lastep, *cstart;
        !           618:        int cclcnt;
        !           619:        int     closed;
        !           620:        char    bracket[NBRA], *bracketp;
        !           621: 
        !           622:        if(*cp == seof) {
        !           623:                cp++;
        !           624:                return(expbuf);
        !           625:        }
        !           626: 
        !           627:        ep = expbuf;
        !           628:        lastep = 0;
        !           629:        bracketp = bracket;
        !           630:        closed = numbra = 0;
        !           631:        sp = cp;
        !           632:        if (*sp == '^') {
        !           633:                *ep++ = 1;
        !           634:                sp++;
        !           635:        } else {
        !           636:                *ep++ = 0;
        !           637:        }
        !           638:        for (;;) {
        !           639:                if (ep >= reend) {
        !           640:                        cp = sp;
        !           641:                        return(badp);
        !           642:                }
        !           643:                if((c = *sp++) == seof) {
        !           644:                        if(bracketp != bracket) {
        !           645:                                cp = sp;
        !           646:                                return(badp);
        !           647:                        }
        !           648:                        cp = sp;
        !           649:                        *ep++ = CEOF;
        !           650:                        return(ep);
        !           651:                }
        !           652:                if(c != '*')
        !           653:                        lastep = ep;
        !           654:                switch (c) {
        !           655: 
        !           656:                case '\\':
        !           657:                        if((c = *sp++) == '(') {
        !           658:                                if(numbra >= NBRA) {
        !           659:                                        cp = sp;
        !           660:                                        return(badp);
        !           661:                                }
        !           662:                                *bracketp++ = numbra;
        !           663:                                *ep++ = CBRA;
        !           664:                                *ep++ = numbra++;
        !           665:                                continue;
        !           666:                        }
        !           667:                        if(c == ')') {
        !           668:                                if(bracketp <= bracket) {
        !           669:                                        cp = sp;
        !           670:                                        return(badp);
        !           671:                                }
        !           672:                                *ep++ = CKET;
        !           673:                                *ep++ = *--bracketp;
        !           674:                                closed++;
        !           675:                                continue;
        !           676:                        }
        !           677: 
        !           678:                        if(c >= '1' && c <= '9') {
        !           679:                                if((c -= '1') >= closed)
        !           680:                                        return(badp);
        !           681:        
        !           682:                                *ep++ = CBACK;
        !           683:                                *ep++ = c;
        !           684:                                continue;
        !           685:                        }
        !           686:                        if(c == '\n') {
        !           687:                                cp = sp;
        !           688:                                return(badp);
        !           689:                        }
        !           690:                        if(c == 'n') {
        !           691:                                c = '\n';
        !           692:                        }
        !           693:                        if(c == 'b'){
        !           694:                                c = '\b';
        !           695:                        }
        !           696:                        goto defchar;
        !           697: 
        !           698:                case '\0':
        !           699:                case '\n':
        !           700:                        cp = sp;
        !           701:                        return(badp);
        !           702: 
        !           703:                case '.':
        !           704:                        *ep++ = CDOT;
        !           705:                        continue;
        !           706: 
        !           707:                case '*':
        !           708:                        if (lastep == 0)
        !           709:                                goto defchar;
        !           710:                        if(*lastep == CKET) {
        !           711:                                cp = sp;
        !           712:                                return(badp);
        !           713:                        }
        !           714:                        *lastep |= STAR;
        !           715:                        continue;
        !           716: 
        !           717:                case '$':
        !           718:                        if (*sp != seof)
        !           719:                                goto defchar;
        !           720:                        *ep++ = CDOL;
        !           721:                        continue;
        !           722: 
        !           723:                case '[':
        !           724:                        if(&ep[17] >= reend) {
        !           725:                                fprintf(stderr, "sed: RE too long: %s\n", linebuf);
        !           726:                                exit(2);
        !           727:                        }
        !           728: 
        !           729:                        *ep++ = CCL;
        !           730: 
        !           731:                        neg = 0;
        !           732:                        if((c = *sp++) == '^') {
        !           733:                                neg = 1;
        !           734:                                c = *sp++;
        !           735:                        }
        !           736: 
        !           737:                        cstart = sp;
        !           738:                        do {
        !           739:                                if(c == '\0') {
        !           740:                                        fprintf(stderr, CGMES, linebuf);
        !           741:                                        exit(2);
        !           742:                                }
        !           743:                                if (c=='-' && sp>cstart && *sp!=']') {
        !           744:                                        for (c = sp[-2]; c<*sp; c++)
        !           745:                                                ep[c>>3] |= bittab[c&07];
        !           746:                                }
        !           747:                                if(c == '\\') {
        !           748:                                        switch(c = *sp++) {
        !           749:                                                case 'n':
        !           750:                                                        c = '\n';
        !           751:                                                        break;
        !           752:                                        }
        !           753:                                }
        !           754: 
        !           755:                                ep[c >> 3] |= bittab[c & 07];
        !           756:                        } while((c = *sp++) != ']');
        !           757: 
        !           758:                        if(neg)
        !           759:                                for(cclcnt = 0; cclcnt < 16; cclcnt++)
        !           760:                                        ep[cclcnt] ^= -1;
        !           761:                        ep[0] &= 0376;
        !           762: 
        !           763:                        ep += 16;
        !           764: 
        !           765:                        continue;
        !           766: 
        !           767:                defchar:
        !           768:                default:
        !           769:                        *ep++ = CCHR;
        !           770:                        *ep++ = c;
        !           771:                }
        !           772:        }
        !           773: }
        !           774: rline(lbuf)
        !           775: char   *lbuf;
        !           776: {
        !           777:        register char   *p, *q;
        !           778:        register        t;
        !           779:        static char     *saveq;
        !           780: 
        !           781:        p = lbuf - 1;
        !           782: 
        !           783:        if(eflag) {
        !           784:                if(eflag > 0) {
        !           785:                        eflag = -1;
        !           786:                        if(eargc-- <= 0)
        !           787:                                exit(2);
        !           788:                        q = *++eargv;
        !           789:                        while(*++p = *q++) {
        !           790:                                if(*p == '\\') {
        !           791:                                        if((*++p = *q++) == '\0') {
        !           792:                                                saveq = 0;
        !           793:                                                return(-1);
        !           794:                                        } else
        !           795:                                                continue;
        !           796:                                }
        !           797:                                if(*p == '\n') {
        !           798:                                        *p = '\0';
        !           799:                                        saveq = q;
        !           800:                                        return(1);
        !           801:                                }
        !           802:                        }
        !           803:                        saveq = 0;
        !           804:                        return(1);
        !           805:                }
        !           806:                if((q = saveq) == 0)    return(-1);
        !           807: 
        !           808:                while(*++p = *q++) {
        !           809:                        if(*p == '\\') {
        !           810:                                if((*++p = *q++) == '0') {
        !           811:                                        saveq = 0;
        !           812:                                        return(-1);
        !           813:                                } else
        !           814:                                        continue;
        !           815:                        }
        !           816:                        if(*p == '\n') {
        !           817:                                *p = '\0';
        !           818:                                saveq = q;
        !           819:                                return(1);
        !           820:                        }
        !           821:                }
        !           822:                saveq = 0;
        !           823:                return(1);
        !           824:        }
        !           825: 
        !           826:        while((t = getc(fin)) != EOF) {
        !           827:                *++p = t;
        !           828:                if(*p == '\\') {
        !           829:                        t = getc(fin);
        !           830:                        *++p = t;
        !           831:                }
        !           832:                else if(*p == '\n') {
        !           833:                        *p = '\0';
        !           834:                        return(1);
        !           835:                }
        !           836:        }
        !           837:        *++p = '\0';
        !           838:        return(-1);
        !           839: }
        !           840: 
        !           841: char   *address(expbuf)
        !           842: char   *expbuf;
        !           843: {
        !           844:        register char   *rcp;
        !           845:        long    lno;
        !           846: 
        !           847:        if(*cp == '$') {
        !           848:                cp++;
        !           849:                *expbuf++ = CEND;
        !           850:                *expbuf++ = CEOF;
        !           851:                return(expbuf);
        !           852:        }
        !           853: 
        !           854:        if(*cp == '/') {
        !           855:                seof = '/';
        !           856:                cp++;
        !           857:                return(compile(expbuf));
        !           858:        }
        !           859: 
        !           860:        rcp = cp;
        !           861:        lno = 0;
        !           862: 
        !           863:        while(*rcp >= '0' && *rcp <= '9')
        !           864:                lno = lno*10 + *rcp++ - '0';
        !           865: 
        !           866:        if(rcp > cp) {
        !           867:                *expbuf++ = CLNUM;
        !           868:                *expbuf++ = lno;
        !           869:                *expbuf++ = lno >> 8;
        !           870:                *expbuf++ = lno >> 16;
        !           871:                *expbuf++ = lno >> 24;
        !           872:                *expbuf++ = CEOF;
        !           873:                cp = rcp;
        !           874:                return(expbuf);
        !           875:        }
        !           876:        return(0);
        !           877: }
        !           878: cmp(a, b)
        !           879: char   *a,*b;
        !           880: {
        !           881:        register char   *ra, *rb;
        !           882: 
        !           883:        ra = a - 1;
        !           884:        rb = b - 1;
        !           885: 
        !           886:        while(*++ra == *++rb)
        !           887:                if(*ra == '\0') return(0);
        !           888:        return(1);
        !           889: }
        !           890: 
        !           891: char   *text(textbuf)
        !           892: char   *textbuf;
        !           893: {
        !           894:        register char   *p, *q;
        !           895: 
        !           896:        p = textbuf;
        !           897:        q = cp;
        !           898:        while(*q == '\t' || *q == ' ')  q++;
        !           899:        for(;;) {
        !           900: 
        !           901:                if((*p = *q++) == '\\')
        !           902:                        *p = *q++;
        !           903:                if(*p == '\0') {
        !           904:                        cp = --q;
        !           905:                        return(++p);
        !           906:                }
        !           907:                if(*p == '\n') {
        !           908:                        while(*q == '\t' || *q == ' ')  q++;
        !           909:                }
        !           910:                p++;
        !           911:        }
        !           912: }
        !           913: 
        !           914: 
        !           915: struct label   *search(ptr)
        !           916: struct label   *ptr;
        !           917: {
        !           918:        struct label    *rp;
        !           919: 
        !           920:        rp = labtab;
        !           921:        while(rp < ptr) {
        !           922:                if(cmp(rp->asc, ptr->asc) == 0)
        !           923:                        return(rp);
        !           924:                rp++;
        !           925:        }
        !           926: 
        !           927:        return(0);
        !           928: }
        !           929: 
        !           930: 
        !           931: dechain()
        !           932: {
        !           933:        struct label    *lptr;
        !           934:        union reptr     *rptr, *trptr;
        !           935: 
        !           936:        for(lptr = labtab; lptr < lab; lptr++) {
        !           937: 
        !           938:                if(lptr->address == 0) {
        !           939:                        fprintf(stderr, "sed: Undefined label: %s\n", lptr->asc);
        !           940:                        exit(2);
        !           941:                }
        !           942: 
        !           943:                if(lptr->chain) {
        !           944:                        rptr = lptr->chain;
        !           945:                        while(trptr = rptr->r2.lb1) {
        !           946:                                rptr->r2.lb1 = lptr->address;
        !           947:                                rptr = trptr;
        !           948:                        }
        !           949:                        rptr->r2.lb1 = lptr->address;
        !           950:                }
        !           951:        }
        !           952: }
        !           953: 
        !           954: char *ycomp(expbuf)
        !           955: char   *expbuf;
        !           956: {
        !           957:        register char   c, *ep, *tsp;
        !           958:        char    *sp;
        !           959: 
        !           960:        ep = expbuf;
        !           961:        sp = cp;
        !           962:        for(tsp = cp; *tsp != seof; tsp++) {
        !           963:                if(*tsp == '\\')
        !           964:                        tsp++;
        !           965:                if(*tsp == '\n' || *tsp == '\0')
        !           966:                        return(badp);
        !           967:        }
        !           968:        tsp++;
        !           969: 
        !           970:        while((c = *sp++ & 0177) != seof) {
        !           971:                if(c == '\\' && *sp == 'n') {
        !           972:                        sp++;
        !           973:                        c = '\n';
        !           974:                }
        !           975:                if((ep[c] = *tsp++) == '\\' && *tsp == 'n') {
        !           976:                        ep[c] = '\n';
        !           977:                        tsp++;
        !           978:                }
        !           979:                if(ep[c] == seof || ep[c] == '\0')
        !           980:                        return(badp);
        !           981:        }
        !           982:        if(*tsp != seof)
        !           983:                return(badp);
        !           984:        cp = ++tsp;
        !           985: 
        !           986:        for(c = 0; !(c & 0200); c++)
        !           987:                if(ep[c] == 0)
        !           988:                        ep[c] = c;
        !           989: 
        !           990:        return(ep + 0200);
        !           991: }
        !           992: 

unix.superglobalmegacorp.com

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