Annotation of researchv10no/cmd/docgen/docgen.c, revision 1.1.1.1

1.1       root        1: /**********
                      2:                                docgen.c
                      3: 
                      4:        (091984 version: from llc 080284; minor changes by vbt)
                      5: 
                      6:        modify *mmfile, *msfile, and *mcfile strings as needed to supply
                      7:                full pathnames for mmdata, msdata, and mcsdata files;
                      8: 
                      9: **********/
                     10: #include <stdio.h>
                     11: #include <signal.h>
                     12: char *mmfile="/usr/lib/docgen/mmdata";
                     13: char *msfile="/usr/lib/docgen/msdata";
                     14: char *mcfile="/usr/lib/docgen/mcsdata";
                     15: char *wr = "/usr/lib/docgen/wr";
                     16: #define eatblanks(a) while((c=getc(a)) == ' '|| c == '\t')
                     17: #define MAX 100
                     18: #define CMAX 7500
                     19: #define LMAX 200
                     20: #define QMAX 100
                     21: #define NPATH 10
                     22: #define NENT 200
                     23: #define BUFS 512
                     24: #define LABMAX 20
                     25: #define STACK 10
                     26: #define NEST 10
                     27: 
                     28: int inap;
                     29: int debug = 0;
                     30: int sdebug = 0;
                     31: int verbose = 0;
                     32: #define ARGS 1
                     33: #define ONELINE 2
                     34: #define MANY 4
                     35: #define OUT 8
                     36: #define PRINT 16
                     37: #define SKIP 32
                     38: #define BLOOP 128
                     39: #define PATH 256
                     40: #define QUEST 512
                     41: #define STUFF 1024
                     42: #define NAME 2048
                     43: #define SUM 4096
                     44: #define PAR 8192
                     45: #define FLOOP 16384
                     46: #define SEVERAL        32768
                     47: #define QSTUFF 65536
                     48: 
                     49: struct q_a {
                     50:        char *qtext;
                     51:        char *text;
                     52:        char *macro;
                     53:        unsigned long type;
                     54:        struct qa *argq;
                     55: }  s[MAX];
                     56: struct q_a *p = s;
                     57: 
                     58: unsigned long gettype();
                     59: int sig_in_ed();
                     60: char buf[CMAX];
                     61: char *ptr = buf;
                     62: char obuf[BUFS];
                     63: char *optr = obuf;
                     64: FILE *outp;
                     65: char *ofile;
                     66: char line[LMAX];
                     67: char sline[LMAX];
                     68: char *first;
                     69: int lineno = 1;
                     70: 
                     71: struct qa {
                     72:        char *text;
                     73:        struct qa *nexta;
                     74: } ques[QMAX];
                     75: struct qa *qp = ques;
                     76: 
                     77: struct pa {
                     78:        char *name;
                     79:        struct list *root;
                     80: } paths[NPATH];
                     81: struct pa *pp = paths;
                     82: 
                     83: struct list {
                     84:        struct q_a *entry;
                     85:        struct list *next;
                     86:        struct list *loop;
                     87:        char *quest;
                     88:        struct list *floop;
                     89: } list[NENT];
                     90: struct list *lp = list;
                     91: struct list *stack[STACK];
                     92: struct list **st = stack;
                     93: 
                     94: struct pa *findpath();
                     95: struct lab {
                     96:        struct list *path;
                     97:        struct list *place;
                     98: } save[LABMAX], *sav=save;
                     99: struct lab *savp;
                    100: struct lab *savc[10];
                    101: unsigned stype[10];
                    102: int curly = 0;
                    103: char *onepath;
                    104: char *qfile;
                    105: char *namesf="tagfile";
                    106: char nname[50];
                    107: FILE *popen(), *edp;
                    108: 
                    109: main(argc,argv)
                    110: int argc;
                    111: char *argv[];
                    112: {
                    113: 
                    114:        qfile = mcfile;
                    115:        while(argc > 1 && *argv[1] == '-'){
                    116:                switch(argv[1][1]){
                    117:                case 'f':
                    118:                        if(argc > 2)qfile=argv[2];
                    119:                        argc--;
                    120:                        argv++;
                    121:                        break;
                    122:                case 'm':
                    123:                        if(argv[1][2] == 's')qfile=msfile;
                    124:                        else if(argv[1][2] == 'c')qfile=mcfile;
                    125:                        else if(argv[1][2] == 'm')qfile=mmfile;
                    126:                        else {
                    127:                                fprintf("unknown macro package %s\n",argv);
                    128:                                exit(0);
                    129:                        }
                    130:                        break;
                    131:                case 'w':
                    132:                        qfile = wr;
                    133:                        break;
                    134:                case 'd':
                    135:                        sdebug=1;
                    136:                        break;
                    137:                case 'p':
                    138:                        debug=1;
                    139:                        break;
                    140:                case 'v':
                    141:                        verbose=1;
                    142:                        break;
                    143:                default:
                    144:                        fprintf(stderr,"unknown flag %c\n",argv[1][1]);
                    145:                        exit(0);
                    146:                }
                    147:                argc--; argv++;
                    148:        }
                    149:        if(argc > 1)ofile=argv[1];
                    150:        init(qfile);
                    151:        if(onepath != 0){
                    152:                pp=findpath(onepath);
                    153:                lp=pp->root;
                    154:                process(1);
                    155:        }
                    156:        else process(0);
                    157:        done();
                    158: }
                    159: init(file)
                    160: char *file;
                    161: {
                    162:        FILE *inp;
                    163:        int c;
                    164:        int i;
                    165:        int printall=0;
                    166:        char command[50];
                    167:        FILE *dumb;
                    168: 
                    169:        if(ofile == 0){
                    170:                if(file == wr){
                    171:                        printf("Tags going to file tagfile\n");
                    172:                        ofile = namesf;
                    173:                }
                    174:                else if(file == mcfile){
                    175:                        printf("Output going to file temp.cover\n");
                    176:                        ofile = "temp.cover";
                    177:                }
                    178:                else {
                    179:                        printf("Output going to file temp\n");
                    180:                        ofile = "temp";
                    181:                }
                    182:        }
                    183:        if((inp=fopen(file,"r"))==NULL){
                    184:                fprintf(stderr,"can't open script file %s\n",file);
                    185:                exit(0);
                    186:        }
                    187:        pp->name = onepath = ptr;
                    188:        i=0;
                    189:        while((c=getc(inp)) != '\n'){
                    190:                if(c == ','){
                    191:                        *ptr++ = '\0';
                    192:                        (++pp)->name = ptr;
                    193:                        i++;
                    194:                        if(pp > &paths[NPATH-1])
                    195:                                error("more than 10 paths-NPATH");
                    196:                }
                    197:                else if(c != ' ' && c != '\t')
                    198:                        *ptr++ = c;
                    199:        }
                    200:        *ptr++ = '\0';
                    201:        if(i > 0)onepath=0;
                    202:        lineno++;
                    203:        first = ptr;
                    204:        if(getstr(inp)== 0)
                    205:                if(onepath == 0)
                    206:                        error("text string expected");
                    207:        while(getentry(inp) != 0){
                    208:                if(p++ >= &s[MAX-1])
                    209:                        error("number of instructions exceeded-MAX");
                    210:        }
                    211:        if(debug)printf("\n");
                    212:        if((dumb = fopen(ofile,"r")) != NULL){
                    213:                if(file == wr){
                    214:                printf("File %s already exists; Tags will be appended\n",ofile);
                    215:                printall++;
                    216:                }
                    217:                else {
                    218:                        printf("File %s already exists; Text will be appended\n",ofile);
                    219:                }
                    220:                fclose(dumb);
                    221:        }
                    222:        if((dumb = fopen(ofile,"a")) == NULL){
                    223:                fprintf(stderr,"can't open %s\n",ofile);
                    224:                exit(1);
                    225:        }
                    226:        fclose(dumb);
                    227:        sprintf(command,"ed - %s\n",ofile);
                    228:        signal(SIGINT,sig_in_ed);
                    229:        if((edp = popen(command,"w")) == NULL){
                    230:                printf("can't involk ed\n");
                    231:                exit(0);
                    232:        }
                    233:        setbuf(edp,NULL);
                    234:        if(printall){
                    235:                printf("The following tags are already defined:\n");
                    236:                fputs("1,$p\n",edp);
                    237:                fflush(edp);
                    238:                sleep(8);
                    239:                printf("\n");
                    240:        }
                    241:        fputs("a\n",edp);
                    242:        inap = 1;
                    243: }
                    244: 
                    245: getentry(inp)
                    246: FILE *inp;
                    247: {
                    248:        char *l;
                    249:        int c;
                    250:        int comment = 0;
                    251: 
                    252:        if(debug)printf("\n place %o ",p);
                    253:        savp = sav;
                    254:        l = line;
                    255:        while((*l = c = getc(inp)) != ':'){
                    256:                if(c == EOF)return(0);
                    257:                if(c == '*'){
                    258:                        if(comment){
                    259:                                comment=0;
                    260:                                continue;
                    261:                        }
                    262:                        else {
                    263:                                comment=1;
                    264:                                continue;
                    265:                        }
                    266:                }
                    267:                if(comment){
                    268:                        if(c == '\n')lineno++;
                    269:                        continue;
                    270:                }
                    271:                if(c == '\\'){
                    272:                        *l = getc(inp);
                    273:                        if(++l >= &line[LMAX-1])
                    274:                                error("line length exceeded-LMAX");
                    275:                        continue;
                    276:                }
                    277:                if(c == '}'){
                    278:                        if(debug)printf("found }\n");
                    279:                        l=ptr;
                    280:                        getstr(inp);
                    281:                        addloop(--curly,l);
                    282:                        eatline(inp);
                    283:                        sav = savc[curly];
                    284:                        p->type = BLOOP;
                    285:                        return(1);
                    286:                }
                    287:                if(c == ','){
                    288:                        *l = '\0';
                    289:                        addentry(line,p);
                    290:                        l=line;
                    291:                }
                    292:                else if(c == '\n'){
                    293:                        l=line;
                    294:                        lineno++;
                    295:                }
                    296:                else if(c != ' ' && c != '\t'){
                    297:                        if(l++ >= &line[LMAX-1])
                    298:                                error("line length exceeded-LMAX");
                    299:                }
                    300:        }
                    301:        *l = '\0';
                    302:        addentry(line,p);
                    303:        p->macro = ptr;
                    304:        while((*ptr = c = getc(inp))!= ':'){
                    305:                if(c == '\\'){
                    306:                        *ptr = getc(inp);
                    307:                        if(++ptr >= &buf[CMAX-1])
                    308:                                error("string buffer exceeded-CMAX");
                    309:                }
                    310:                else if(c == ' ' && ptr == p->macro);
                    311:                else if(c == '{' && ptr == p->macro){
                    312:                        if(debug)printf("in { savp %o\n",savp);
                    313:                        (sav++)->path = 0;
                    314:                        stype[curly] = BLOOP;
                    315:                        savc[curly++] = savp;
                    316:                        if(curly >= NEST)
                    317:                                error("nesting depth exceeded-NEST");
                    318:                        if((c = getc(inp)) == ' '|| c == '\t')
                    319:                                eatblanks(inp);
                    320:                        if(c == '\n'){
                    321:                                lineno++;
                    322:                                if((c = getc(inp)) == ' '|| c == '\t')
                    323:                                        eatblanks(inp);
                    324:                        }
                    325:                        if(c == '"'){
                    326:                                p->type = FLOOP;
                    327:                                ungetc(c,inp);
                    328:                                l=ptr;
                    329:                                getstr(inp);
                    330:                                p->qtext = l;
                    331:                                stype[curly-1] = FLOOP;
                    332:                        }
                    333:                        else {
                    334:                                ungetc(c,inp);
                    335:                                p->type = BLOOP;
                    336:                        }
                    337:                        return(1);
                    338:                }
                    339:                else if(ptr++ >= &buf[CMAX-1])
                    340:                        error("string buffer exceeded-CMAX");
                    341:        }
                    342:        if(p->macro == ptr)p->macro=0;
                    343:        else *ptr++ = '\0';
                    344:        p->type = gettype(inp);
                    345:        if(p->type&QUEST){
                    346:                p->qtext = ptr;
                    347:                if(getstr(inp) == 0)
                    348:                        error("text string expected");
                    349:        }
                    350:        else p->qtext = 0;
                    351:        p->text = ptr;
                    352:        if(p->type&(ONELINE|SEVERAL|PRINT|MANY|PATH))
                    353:                if(getstr(inp)== 0)
                    354:                        error("text string expected");
                    355:        if(p->text == ptr)p->text = 0;
                    356:        if(debug)printf(" macro %s type %d text %s ",p->macro,p->type,p->text);
                    357:        if(sdebug)db(p);
                    358:        if(p->type & (ARGS |SKIP)){
                    359:                p->argq = qp;
                    360:                qp->text = ptr;
                    361:                while(getstr(inp) != 0){
                    362:                        qp->nexta = (qp+1);
                    363:                        if(debug||sdebug)printf("\n     arg question= %s",qp->text);
                    364:                        if(debug)printf(" next %o",qp->nexta);
                    365:                        if(qp++ >= &ques[QMAX-1])
                    366:                                error("number of questions exceeded-QMAX");
                    367:                        qp->text = ptr;
                    368:                }
                    369:                (qp-1)->nexta = 0;
                    370:                if(debug)printf("\n     last %s next %o",(qp-1)->text,(qp-1)->nexta);
                    371:                if(sdebug)printf("\n");
                    372:        }
                    373:        sav = savp;
                    374:        return(1);
                    375: }
                    376: getstr(inp)
                    377: FILE *inp;
                    378: {
                    379:        int c;
                    380:        while((c=getc(inp)) == ' ' || c == '\t' || c == '\n')if(c == '\n')lineno++;
                    381:        if(c != '\"'){
                    382:                ungetc(c,inp);
                    383:                return(0);
                    384:        }
                    385:        while((*ptr=c=getc(inp)) != '\"'){
                    386:                if(ptr++ >= &buf[CMAX])
                    387:                        error("string buffer exceeded-CMAX");
                    388:                if(c == '\n')lineno++;
                    389:        }
                    390:        *ptr++ = '\0';
                    391:        return(1);
                    392: }
                    393: addentry(ch,p)
                    394: char *ch;
                    395: struct q_a *p;
                    396: {
                    397:        struct list *ll;
                    398:        if(debug || sdebug)printf("path= %s, ",ch);
                    399: 
                    400:        for(pp=paths;pp->name != 0 && pp < &paths[NPATH];pp++){
                    401:                if(match(ch,pp->name)){
                    402:                        if(pp->root == 0){
                    403:                                pp->root = lp;
                    404:                        }
                    405:                        else {
                    406:                                ll=pp->root;
                    407:                                while(ll->next != 0)ll=ll->next;
                    408:                                ll->next = lp;
                    409:                        }
                    410:                        if(debug)printf("entry %o path %o\n",lp,pp);
                    411:                        sav->path = (struct list *)pp;
                    412:                        sav->place = lp;
                    413:                        lp->entry = p;
                    414:                        if(lp++ >= &list[NENT-1])
                    415:                                error("tree exceeded-NENT");
                    416:                        if(sav++ >= &save[LABMAX-1])
                    417:                                error("saved paths exceeded-LABMAX");
                    418:                        return;
                    419:                }
                    420:        }
                    421:        printf("no path to %s\n",ch);
                    422:        exit(0);
                    423: }
                    424: 
                    425: addloop(in,cp)
                    426: char *cp;
                    427: {
                    428:        struct lab *sp;
                    429:        struct list *ll;
                    430: 
                    431:        sp = savc[in];
                    432:        while((ll = sp->path) != 0){
                    433:                if(debug)printf("addloop sp %o path %o",sp,sp->path);
                    434:                while(ll->next != 0){
                    435:                        ll=ll->next;
                    436:                }
                    437:                if(debug)printf("ll %o place %o\n",ll,sp->place);
                    438:                if(ll->loop != 0){
                    439:                        ll->next = lp;
                    440:                        lp->loop = sp->place;
                    441:                        lp->quest = cp;
                    442:                        lp->entry = p;
                    443:                        if(lp++ >= &list[NENT-1])
                    444:                                error("tree exceeded - NENT");
                    445:                }
                    446:                else {
                    447:                        ll->loop = sp->place;
                    448:                        ll->quest = cp;
                    449:                }
                    450:                if(stype[in] == FLOOP){
                    451:                        sp->place->floop = lp;
                    452:                        lp->entry = p;
                    453:                        if(lp++ >= &list[NENT-1])
                    454:                                error("tree exceeded - NENT");
                    455:                }
                    456:                sp++;
                    457:        }
                    458: }
                    459: unsigned long
                    460: gettype(inp)
                    461: FILE *inp;
                    462: {
                    463:        int c;
                    464:        unsigned long i;
                    465:        i=0;
                    466: another:
                    467:        while((c=getc(inp)) == ' ' || c == '\t');
                    468:        switch(c){
                    469:        case 'A':
                    470:                i |= ARGS;
                    471:                break;
                    472:        case 'M':
                    473:                i |= MANY;
                    474:                break;
                    475:        case 'O':
                    476:                if((c=getc(inp)) == 'U')
                    477:                        i |= OUT;
                    478:                else if(c == 'N')
                    479:                        i|= ONELINE;
                    480:                else error("unknown action");
                    481:                break;
                    482:        case 'P':
                    483:                if((c=getc(inp)) == 'R')
                    484:                        i |= PRINT;
                    485:                else if(c == 'A'){
                    486:                        if((c=getc(inp)) == 'T')
                    487:                                i |= PATH;
                    488:                        else if(c == 'R')
                    489:                                i |= PAR|MANY;
                    490:                        else error("unknown action");
                    491:                }
                    492:                else error("unknown action");
                    493:                break;
                    494:        case 'S':
                    495:                if((c=getc(inp)) == 'T')
                    496:                        i |= STUFF|ARGS;
                    497:                else if(c == 'K')
                    498:                        i |= SKIP;
                    499:                else if(c == 'U')
                    500:                        i |= SUM|MANY;
                    501:                else if(c == 'E')
                    502:                        i |= SEVERAL;
                    503:                else error("unknown action");
                    504:                break;
                    505:        case 'Q':
                    506:                if((c=getc(inp)) == 'U')
                    507:                        i |= QUEST;
                    508:                else if(c == 'S')
                    509:                        i |= QSTUFF|ARGS;
                    510:                else error("unknown action");
                    511:                break;
                    512:        case 'N':
                    513:                i |= NAME|ONELINE;
                    514:                break;
                    515:        default:
                    516:                error("unknown action");
                    517:        }
                    518:        while((c=getc(inp))!= '\n')
                    519:                if(c == '&')goto another;
                    520:        lineno++;
                    521:        if(i&OUT)
                    522:                if(i & ~OUT){
                    523:                        if(i & ~(OUT|QUEST))
                    524:                                error("action error - OUT not alone");
                    525:                }
                    526:        if(i & PRINT)
                    527:                if(i & ~PRINT){
                    528:                        if(i & ~(PRINT|QUEST))
                    529:                                error("action error - PRINT not alone");
                    530:                }
                    531:        if(i & PATH)
                    532:                if(i & ~PATH)error("action error - PATH not alone");
                    533:        if((i&(MANY|ONELINE))==(MANY|ONELINE))
                    534:                error("contridictory actions - MANY & ONELINE");
                    535:        return(i);
                    536: }
                    537: 
                    538: process(start)
                    539: int start;
                    540: {
                    541:        if(start == 0){
                    542:                printf("%s\n",first);
                    543:                getl(stdin,line);
                    544:                pp=findpath(line);
                    545:                lp = pp->root;
                    546:        }
                    547: more:
                    548:        while(lp){
                    549:                if(question(lp->entry)== 1)
                    550:                        continue;
                    551:                if(lp->loop != 0){
                    552:                        printf("%s\n",lp->quest);
                    553:                        getl(stdin,line);
                    554:                        if(line[0] == 'y'|| line[0] == 'Y')
                    555:                                lp=lp->loop;
                    556:                        else{
                    557:                                if(lp->loop->entry->type & 1){
                    558:                                        lp->loop->entry->type &= 0177776;
                    559:                                }
                    560:                                if(line[0] == 'q')done();
                    561:                                else lp=lp->next;
                    562:                        }
                    563:                }
                    564:                else
                    565:                        lp = lp->next;
                    566:        }
                    567:        if(*st != 0){
                    568:                lp = *st--;
                    569:                if(lp->loop != 0){
                    570:                        printf("%s\n",lp->quest);
                    571:                        getl(stdin,line);
                    572:                        if(line[0] == 'y' || line[0] == 'Y')
                    573:                                lp=lp->loop;
                    574:                        else{
                    575:                                if(lp->loop->entry->type & 1)
                    576:                                        lp->loop->entry->type &= 0177776;
                    577:                                if(line[0] == 'q')done();
                    578:                                else lp=lp->next;
                    579:                        }
                    580:                }
                    581:                else lp=lp->next;
                    582:                goto more;
                    583:        }
                    584: }
                    585: 
                    586: question(rp)
                    587: struct q_a *rp;
                    588: {
                    589:        int blanks;
                    590:        char *ch, *sv;
                    591: 
                    592: rest:
                    593:        if(debug)printf("in question %o\n",rp);
                    594:        if(rp->type & BLOOP)
                    595:                return(0);
                    596:        if(rp->type & FLOOP){
                    597:                if(rp->type & 1)return(0);
                    598:                printf("%s\n",rp->qtext);
                    599:                getl(stdin,line);
                    600:                if(line[0] == 'y' || line[0] == 'Y'){
                    601:                        lp = lp->next;
                    602:                        rp->type |= 1;
                    603:                }
                    604:                else if(line[0] == 'q')done();
                    605:                else lp= lp->floop;
                    606:                return(1);
                    607:        }
                    608:        if(rp->type & PATH){
                    609:                *(++st) = lp;
                    610:                if(st >= &stack[STACK-1])
                    611:                        error("stack depth exceeded-STACK");
                    612:                printf("%s\n",rp->text);
                    613:                getl(stdin,line);
                    614:                if(line[0] == '\0'){
                    615:                        st--;
                    616:                        return(0);
                    617:                }
                    618:                pp=findpath(line);
                    619:                lp = pp->root;
                    620:                return(1);
                    621:        }
                    622:        if(rp->type&QUEST){
                    623:                printf("%s\n",rp->qtext);
                    624:                getl(stdin,line);
                    625:                if(line[0] != 'Y' && line[0] != 'y')return(0);
                    626:        }
                    627:        if(rp->text != 0)
                    628:                if((rp->type&MANY) == 0)printf("%s\n",rp->text);
                    629:        if(rp->type&(ONELINE|SEVERAL))
                    630:                getl(stdin,sline);
                    631:        if(rp->type&NAME){
                    632:                return(newname(sline));
                    633:        }
                    634:        if(rp->type&SUM){
                    635:                summary();
                    636:        }
                    637:        if(rp->type&PAR){
                    638:                par();
                    639:        }
                    640:        if(rp->type&(STUFF|QSTUFF)){
                    641:                sv = ch = rp->macro;
                    642:                qp = rp->argq;
                    643:                do{
                    644:                        while(*ch != '$'){
                    645:                                if(*ch == '\\')ch++;
                    646:                                if(*ch == '\0')break;
                    647:                                ch++;
                    648:                        }
                    649:                        if(*ch == '$'){
                    650:                                *ch = '\0';
                    651:                                out(sv);
                    652:                                *ch++ = '$';
                    653:                                sv = ch;
                    654:                        }
                    655:                        printf("%s\n",qp->text);
                    656:                        getl(stdin,line);
                    657:                        if(rp->type&QSTUFF)
                    658:                                if(line[0] == '\0')break;
                    659:                        if(*(ch-1) == '$')
                    660:                                out(line);
                    661:                        qp = qp->nexta;
                    662:                } while(qp != 0);
                    663:                if(rp->type&STUFF)
                    664:                        out(sv);
                    665:                else if(*sv == '"')out("\"");
                    666:                out("\n");
                    667:        }
                    668:        else if(rp->type&(ARGS | SKIP)){
                    669:                if((rp->type&SKIP) == 0 && rp->macro != 0)
                    670:                        out(rp->macro);
                    671:                qp = rp->argq;
                    672:                do{
                    673:                        printf("%s\n",qp->text);
                    674:                        blanks = getl(stdin,line);
                    675:                        if(rp->type&SKIP){
                    676:                                if(line[0] == '\0')
                    677:                                        return(0);
                    678:                                else out(rp->macro);
                    679:                        }
                    680:                        out(" ");
                    681:                        if(line[0] == '\0')blanks++;
                    682:                        if(blanks)out("\"");
                    683:                        out(line);
                    684:                        if(blanks)out("\"");
                    685:                        qp=qp->nexta;
                    686:                } while(qp != 0);
                    687:                out("\n");
                    688:        }
                    689:        else if((rp->type&(OUT|ONELINE|MANY))&& rp->macro != 0){
                    690:                out(rp->macro);
                    691:                out("\n");
                    692:        }
                    693:        if(rp->type&SEVERAL){
                    694:                out(rp->macro);
                    695:                out(" ");
                    696:                out(sline);
                    697:                out("\n");
                    698:        }
                    699:        if(rp->type&ONELINE){
                    700:                out(sline);
                    701:                out("\n");
                    702:        }
                    703:        if(rp->type&MANY){
                    704:                if(rp->type&(SUM))
                    705:                        printf("%s named %s.sum\n",rp->text,nname);
                    706:                else if(rp->type&PAR)
                    707:                        printf("%s named %s.par\n",rp->text,nname);
                    708:                else printf("%s\n",rp->text);
                    709:                printf("        end with : alone on a line (or read a file with :r filename)\n");
                    710:                getl(stdin,line);
                    711:                if(line[0] == ':' && line[1] == 'r'){
                    712:                        ch = &line[2];
                    713:        more:
                    714:                        readfiles(ch);
                    715:                        printf("Type other file names or return\n");
                    716:                        getl(stdin,line);
                    717:                        if(line[0] == '\0')return(0);
                    718:                        ch = line;
                    719:                        goto more;
                    720:                }
                    721:                toed();
                    722:        }
                    723:        return(0);
                    724: }
                    725: sig_in_ed(){
                    726:        inap = 0;
                    727:        printf("type q to quit ");
                    728:        getl(stdin,line);
                    729:        if(line[0] == 'q')done();
                    730:        fputs("a\n",edp);
                    731:        optr = obuf;
                    732:        inap=1;
                    733:        signal(SIGINT,sig_in_ed);
                    734:        process(1);
                    735:        done();
                    736: }
                    737: 
                    738: getl(inp,l)
                    739: char *l;
                    740: FILE *inp;
                    741: {
                    742:        int c;
                    743:        int blanks;
                    744: 
                    745:        blanks=0;
                    746:        while((*l = c = getc(inp)) != '\n'){
                    747:                l++;
                    748:                if(c == ' ' || c == '\t')blanks++;
                    749:        }
                    750:        *l++ = 0;
                    751:        return(blanks);
                    752: }
                    753: 
                    754: out(ch)
                    755: char *ch;
                    756: {
                    757:        char c;
                    758: 
                    759:        while(*ch != '\0'){
                    760:                if(*ch == '\n'){
                    761:                        *optr++ = *ch++;
                    762:                        *optr = '\0';
                    763:                        fputs(obuf,edp);
                    764:                        optr=obuf;
                    765:                        if(verbose)printf("%s",obuf);
                    766:                }
                    767:                else *optr++ = *ch++;
                    768:                if(optr >= &obuf[BUFS-1]){
                    769:                        *optr = '\0';
                    770:                        fputs(obuf,edp);
                    771:                        optr = obuf;
                    772:                }
                    773:        }
                    774: }
                    775: ofl()
                    776: {
                    777:        if(optr != obuf){
                    778:                *optr='\0';
                    779:                fputs(obuf,edp);
                    780:                optr=obuf;
                    781:        }
                    782:        if(inap)
                    783:                fputs(".\nw\na\n",edp);
                    784:        else {
                    785:                fputs("w\na\n",edp);
                    786:                inap=1;
                    787:        }
                    788: }
                    789: done(){
                    790:        ofl();
                    791:        fputs(".\nq\n",edp);
                    792:        exit(0);
                    793: }
                    794: 
                    795: match(ch,hh)
                    796: char *ch, *hh;
                    797: {
                    798:        while(*ch == *hh){
                    799:                if(*ch == '\0')return(1);
                    800:                ch++;
                    801:                hh++;
                    802:        }
                    803:        return(0);
                    804: }
                    805: 
                    806: struct pa *
                    807: findpath(ch)
                    808: char *ch;
                    809: {
                    810:        for(pp=paths;pp->name != 0;pp++){
                    811:                if(match(ch,pp->name))
                    812:                        return(pp);
                    813:        }
                    814:        printf("can't find path for %s\n",ch);
                    815:        exit(0);
                    816: }
                    817: eatline(inp)
                    818: FILE *inp;
                    819: {
                    820:        while(getc(inp) != '\n');
                    821:        lineno++;
                    822: }
                    823: readfiles(ptr)
                    824: char *ptr;
                    825: {
                    826:        FILE *io;
                    827:        int nomore;
                    828:        char *bp;
                    829:        char fname[50];
                    830: 
                    831:        ofl();
                    832:        fputs(".\n",edp);
                    833:        nomore = 0;
                    834:        while(1){
                    835:                while(*ptr == ' ')ptr++;
                    836:                bp = ptr;
                    837:                while(*ptr != ' ' && *ptr != '\0')ptr++;
                    838:                if(*ptr == '\0')nomore++;
                    839:                else *ptr++ = '\0';
                    840:                sprintf(fname,"$r %s\n",bp);
                    841:                fputs(fname,edp);
                    842:                if(nomore != 0)break;
                    843:        }
                    844:        fputs("a\n",edp);
                    845: }
                    846: error(sp)
                    847: char *sp;
                    848: {
                    849:        fprintf(stderr,"%s at line %d file %s\n",sp,lineno,qfile);
                    850:        exit(1);
                    851: }
                    852: db(dbp)
                    853: struct q_a *dbp;
                    854: {
                    855:        printf(" macro= %s type=",dbp->macro);
                    856:        if(dbp->type&ARGS)printf(" ARGS");
                    857:        if(dbp->type&SKIP)printf(" SKIP");
                    858:        if(dbp->type&OUT)printf(" OUT");
                    859:        if(dbp->type&PRINT)printf(" PRINT");
                    860:        if(dbp->type&ONELINE)printf(" ONELINE");
                    861:        if(dbp->type&SEVERAL)printf(" SEVERAL");
                    862:        if(dbp->type&MANY)printf(" MANY");
                    863:        if(dbp->type&PATH)printf(" PATH");
                    864:        if(dbp->text != 0)printf("\nmain text= %s\n",dbp->text);
                    865:        else printf("\n");
                    866: }
                    867: newname(s)
                    868: char *s;
                    869: {
                    870:        int i;
                    871:        char *name1, *name2;
                    872:        int pid, rpid, retcode;
                    873:        char *sp,spac[10];
                    874: restart:
                    875:        sp = spac;
                    876:        *sp = '\0';
                    877:        if(*s == ' ' || *s == '\t')
                    878:                while(*s== ' ' || *s == '\t')*sp++ = *s++;
                    879:        *sp = '\0';
                    880:        for(i=0;*s != '\0';i++)
                    881:                nname[i] = *s++;
                    882:        if(nname[0] == ':'){
                    883:                switch(nname[1]){
                    884:                case 'p':
                    885:                        sprintf(line,".\nw\ne %s\n1,$p\na\n",ofile);
                    886:                        fputs(line,edp);
                    887:                        sleep(8);
                    888:                        return(1);
                    889:                case 'r':
                    890:                        sprintf(line,".\nw\ne %s\na\n",&nname[3]);
                    891:                        printf("Type text to append to file %s\n",&nname[3]);
                    892:                        fputs(line,edp);
                    893:                        getl(stdin,line);
                    894:                        toed();
                    895:                        return(1);
                    896:                case 'j':
                    897:                        name1=0;
                    898:                        name2 = nname;
                    899:        nextn:
                    900:                        for(; *name2 != ' ';name2++)
                    901:                                if(*name2 == '\0'){
                    902:                                        printf("error in command line: %s\nplease retype\n",nname);
                    903:                                        getl(stdin,sline);
                    904:                                        s=sline;
                    905:                                        goto restart;
                    906:                                }
                    907:                        *name2++ = '\0';
                    908:                        while(*name2 == ' ')name2++;
                    909:                        if(name1 == 0){
                    910:                                name1 = name2;
                    911:                                goto nextn;
                    912:                        }
                    913:                        sprintf(line,".\nw\ne %s.sum\n$r %s.sum\nw\n",name1,name2);
                    914:                        fputs(line,edp);
                    915:                        sprintf(line,"e %s.par\n$r %s.par\nw\n",name1,name2);
                    916:                        fputs(line,edp);
                    917:                        sprintf(line,"e %s\n/%s/d\nw\na\n",ofile);
                    918:                        fputs(line,edp);
                    919:                        return(1);
                    920:                default:
                    921:                        printf("unknown command %s\n",nname);
                    922:                        printf("please retype\n");
                    923:                        goto restart;
                    924:                }
                    925:        }
                    926:        if(nname[0] == '!'){
                    927:                if((pid = fork()) == 0){
                    928:                        execl("/bin/sh","sh","-c",&nname[1],0);
                    929:                        exit(0);
                    930:                }
                    931:                while((rpid=wait(&retcode))!=pid&& rpid != -1);
                    932:                printf("!\n");
                    933:                return(1);
                    934:        }
                    935:        if(i > 10){
                    936:                printf("tag too long - please type new tag ");
                    937:                getl(stdin,sline);
                    938:                s=sline;
                    939:                goto restart;
                    940:        }
                    941:        nname[i] = '\0';
                    942:        sprintf(line, ".\nw\ne %s\na\n%s%s\n",ofile,spac,nname);
                    943:        fputs(line,edp);
                    944:        return(0);
                    945: }
                    946: summary(){
                    947:        FILE *ff;
                    948:        sprintf(line,"%s.sum",nname);
                    949:        if((ff = fopen(line,"a")) == NULL){
                    950:                printf("can't open %s\n",line);
                    951:        }
                    952:        sprintf(line,".\nw\ne %s.sum\na\n",nname);
                    953:        fputs(line,edp);
                    954:        fclose(ff);
                    955: }
                    956: par(){
                    957:        FILE *ff;
                    958:        sprintf(line,"%s.par",nname);
                    959:        if((ff=fopen(line,"a")) == NULL){
                    960:                printf("can't open %s\n",line);
                    961:                exit(1);
                    962:        }
                    963:        sprintf(line,".\nw\ne %s.par\na\n",nname);
                    964:        fputs(line,edp);
                    965:        fclose(ff);
                    966: }
                    967: toed(){
                    968:        while(1){
                    969:                if(line[1] == '\0'){
                    970:                switch(line[0]){
                    971:                case 'i':
                    972:                case 'a':
                    973:                case 'c':
                    974:                        inap++;
                    975:                        break;
                    976:                case '.':
                    977:                        inap = 0;
                    978:                        break;
                    979:                case 'q':
                    980:                        if(inap != 0)break;
                    981:                case ':':
                    982:                        if(inap == 0){fputs("a\n",edp);
                    983:                                inap++;
                    984:                        }
                    985:                        return(0);
                    986:                }
                    987:                }
                    988:                fputs(line,edp);
                    989:                fputs("\n",edp);
                    990:                getl(stdin,line);
                    991:        }
                    992: }

unix.superglobalmegacorp.com

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