Annotation of researchv9/cmd/make/gram.c, revision 1.1.1.1

1.1       root        1: 
                      2: # line 1 "gram.y"
                      3: #include "defs"
                      4: static char *sccsid = "@(#)gram.y      8th Edition (Bell Labs) 85/05/14";
                      5: 
                      6: # line 6 "gram.y"
                      7: typedef union 
                      8:        {
                      9:        struct shblock *yshblock;
                     10:        depblkp ydepblock;
                     11:        nameblkp ynameblock;
                     12:        } YYSTYPE;
                     13: # define NAME 257
                     14: # define SHELLINE 258
                     15: # define START 259
                     16: # define MACRODEF 260
                     17: # define COLON 261
                     18: # define DOUBLECOLON 262
                     19: # define GREATER 263
                     20: # define AMPER 264
                     21: # define AMPERAMPER 265
                     22: #define yyclearin yychar = -1
                     23: #define yyerrok yyerrflag = 0
                     24: extern int yychar;
                     25: extern short yyerrflag;
                     26: #ifndef YYMAXDEPTH
                     27: #define YYMAXDEPTH 150
                     28: #endif
                     29: YYSTYPE yylval, yyval;
                     30: 
                     31: # line 21 "gram.y"
                     32: struct depblock *pp;
                     33: FSTATIC struct shblock *prevshp;
                     34: 
                     35: FSTATIC struct nameblock *lefts[NLEFTS];
                     36: struct nameblock *leftp;
                     37: FSTATIC int nlefts;
                     38: 
                     39: struct lineblock *lp, *lpp;
                     40: FSTATIC struct depblock *prevdep;
                     41: FSTATIC int sepc;
                     42: FSTATIC int allnowait;
                     43: 
                     44: FSTATIC struct fstack
                     45:        {
                     46:        FILE *fin;
                     47:        char *fname;
                     48:        int lineno;
                     49:        } filestack[MAXINCLUDE];
                     50: FSTATIC int ninclude = 0;
                     51: # define YYERRCODE 256
                     52: 
                     53: # line 150 "gram.y"
                     54: 
                     55: 
                     56: FSTATIC char *zznextc; /* null if need another line;
                     57:                           otherwise points to next char */
                     58: FSTATIC int yylineno;
                     59: FSTATIC FILE * fin;
                     60: 
                     61: parse(name)
                     62: char *name;
                     63: {
                     64: extern int yylineno;
                     65: FILE *stream;
                     66: extern char *zznextc;
                     67: 
                     68: if(name == CHNULL)
                     69:        {
                     70:        stream = NULL;
                     71:        name = "(builtin-rules)";
                     72:        }
                     73: else if(equal(name, "-"))
                     74:        {
                     75:        stream = stdin;
                     76:        name = "(stdin)";
                     77:        }
                     78: else if( (stream = fopen(name, "r")) == NULL)
                     79:        return NO;
                     80: filestack[0].fname = copys(name);
                     81: ninclude = 1;
                     82: fin = stream;
                     83: yylineno = 0;
                     84: zznextc = 0;
                     85: 
                     86: if( yyparse() )
                     87:        fatal("Description file error");
                     88: 
                     89: if(fin)
                     90:        fclose(fin);
                     91: return YES;
                     92: }
                     93: 
                     94: 
                     95: yylex()
                     96: {
                     97: register char *p;
                     98: register char *q;
                     99: char word[INMAX];
                    100: 
                    101: if(! zznextc )
                    102:        return nextlin() ;
                    103: 
                    104: while( isspace(*zznextc) )
                    105:        ++zznextc;
                    106: switch(*zznextc)
                    107:        {
                    108:        case '\0':
                    109:                return nextlin() ;
                    110: 
                    111:        case '|':
                    112:                if(zznextc[1]==':')
                    113:                        {
                    114:                        zznextc += 2;
                    115:                        return DOUBLECOLON;
                    116:                        }
                    117:                break;
                    118:        case ':':
                    119:                if(*++zznextc == ':')
                    120:                        {
                    121:                        ++zznextc;
                    122:                        return DOUBLECOLON;
                    123:                        }
                    124:                return COLON;
                    125:        case '>':
                    126:                ++zznextc;
                    127:                return GREATER;
                    128:        case '&':
                    129:                if(*++zznextc == '&')
                    130:                        {
                    131:                        ++zznextc;
                    132:                        return AMPERAMPER;
                    133:                        }
                    134:                return AMPER;
                    135:        case ';':
                    136:                return retsh(zznextc) ;
                    137:        }
                    138: 
                    139: p = zznextc;
                    140: q = word;
                    141: 
                    142: while( ! ( funny[*p] & TERMINAL) )
                    143:        *q++ = *p++;
                    144: 
                    145: if(p != zznextc)
                    146:        {
                    147:        *q = '\0';
                    148:        if((yylval.ynameblock=srchname(word))==0)
                    149:                yylval.ynameblock = makename(word);
                    150:        zznextc = p;
                    151:        return NAME;
                    152:        }
                    153: 
                    154: else   {
                    155:        char junk[100];
                    156:        sprintf(junk, "Bad character %c (octal %o), line %d of file %s",
                    157:                *zznextc, *zznextc, yylineno, filestack[ninclude-1].fname);
                    158:        fatal(junk);
                    159:        }
                    160: return 0;      /* never executed */
                    161: }
                    162: 
                    163: 
                    164: 
                    165: 
                    166: 
                    167: retsh(q)
                    168: char *q;
                    169: {
                    170: register char *p;
                    171: struct shblock *sp;
                    172: char *copys();
                    173: 
                    174: for(p=q+1 ; *p==' '||*p=='\t' ; ++p)  ;
                    175: 
                    176: sp = ALLOC(shblock);
                    177: sp->nxtshblock = NULL;
                    178: sp->shbp = (fin ? copys(p) : p );
                    179: yylval.yshblock = sp;
                    180: zznextc = 0;
                    181: return SHELLINE;
                    182: }
                    183: 
                    184: nextlin()
                    185: {
                    186: static char yytext[INMAX];
                    187: static char *yytextl   = yytext+INMAX;
                    188: char *text, templin[INMAX];
                    189: register char c;
                    190: register char *p, *t;
                    191: char lastch, *lastchp;
                    192: extern char **linesptr;
                    193: int incom;
                    194: int kc;
                    195: 
                    196: again:
                    197: 
                    198:        incom = NO;
                    199:        zznextc = 0;
                    200: 
                    201: if(fin == NULL)
                    202:        {
                    203:        if( (text = *linesptr++) == 0)
                    204:                return 0;
                    205:        ++yylineno;
                    206:        }
                    207: 
                    208: else   {
                    209:        for(p = text = yytext ; p<yytextl ; *p++ = kc)
                    210:                switch(kc = getc(fin))
                    211:                        {
                    212:                        case '\t':
                    213:                                if(p == yytext)
                    214:                                        incom = YES;
                    215:                                break;
                    216: 
                    217:                        case ';':
                    218:                                incom = YES;
                    219:                                break;
                    220: 
                    221:                        case '#':
                    222:                                if(! incom)
                    223:                                        kc = '\0';
                    224:                                break;
                    225: 
                    226:                        case '\n':
                    227:                                ++yylineno;
                    228:                                if(p==yytext || p[-1]!='\\')
                    229:                                        {
                    230:                                        *p = '\0';
                    231:                                        goto endloop;
                    232:                                        }
                    233:                                p[-1] = ' ';
                    234:                                while( (kc=getc(fin))=='\t' || kc==' ' || kc=='\n')
                    235:                                        if(kc == '\n')
                    236:                                                ++yylineno;
                    237:        
                    238:                                if(kc != EOF)
                    239:                                        break;
                    240:                        case EOF:
                    241:                                *p = '\0';
                    242:                                if(ninclude > 1)
                    243:                                        {
                    244:                                        register struct fstack *stp;
                    245:                                        fclose(fin);
                    246:                                        --ninclude;
                    247:                                        stp = filestack + ninclude;
                    248:                                        fin = stp->fin;
                    249:                                        yylineno = stp->lineno;
                    250:                                        free(stp->fname);
                    251:                                        goto again;
                    252:                                        }
                    253:                                return 0;
                    254:                        }
                    255: 
                    256:        fatal("line too long");
                    257:        }
                    258: 
                    259: endloop:
                    260: 
                    261:        if((c = text[0]) == '\t')
                    262:                return retsh(text) ;
                    263:        
                    264:        if(isalpha(c) || isdigit(c) || c==' ' || c=='.')
                    265:                for(p=text+1; *p!='\0'; )
                    266:                        if(*p == ':')
                    267:                                break;
                    268:                        else if(*p++ == '=')
                    269:                                {
                    270:                                eqsign(text);
                    271:                                return MACRODEF;
                    272:                                }
                    273: 
                    274: 
                    275: if(!strncmp(text, "include", 7) && isinclude(text+7))
                    276:        goto again;
                    277: 
                    278: /* substitute for macros on dependency line up to the semicolon if any */
                    279: 
                    280: for(t = yytext ; *t!='\0' && *t!=';' ; ++t)
                    281:        ;
                    282: 
                    283: lastchp = t;
                    284: lastch = *t;
                    285: *t = '\0';     /* replace the semi with a null so subst will stop */
                    286: 
                    287: subst(yytext, templin);                /* Substitute for macros on dependency lines */
                    288: 
                    289: if(lastch)     /* copy the stuff after the semicolon */
                    290:        {
                    291:        *lastchp = lastch;
                    292:        strcat(templin, lastchp);
                    293:        }
                    294: 
                    295: strcpy(yytext, templin);
                    296: 
                    297: for(p = zznextc = text ; *p ; ++p )
                    298:        if(*p!=' ' && *p!='\t')
                    299:                return START;
                    300: goto again;
                    301: }
                    302: 
                    303: 
                    304: 
                    305: isinclude(s)
                    306: register char *s;
                    307: {
                    308: register char *t;
                    309: register struct fstack *p;
                    310: 
                    311: for(t=s; *t==' ' || *t=='\t' ; ++t)
                    312:        ;
                    313: if(t == s)
                    314:        return NO;
                    315: 
                    316: for(s = t; *s!='\n' && *s!='#' && *s!='\0' ; ++s)
                    317:        if(*s == ':')
                    318:                return NO;
                    319: *s = '\0';
                    320: 
                    321: if(ninclude >= MAXINCLUDE)
                    322:        fatal("include depth exceeded");
                    323: p = filestack + ninclude;
                    324: p->fin = fin;
                    325: p->lineno = yylineno;
                    326: p->fname = copys(t);
                    327: if( (fin = fopen(t, "r")) == NULL)
                    328:        fatal1("Cannot open include file %s", t);
                    329: yylineno = 0;
                    330: ++ninclude;
                    331: return YES;
                    332: }
                    333: 
                    334: 
                    335: 
                    336: yyerror(s)
                    337: char *s;
                    338: {
                    339: char buf[100];
                    340: 
                    341: sprintf(buf, "line %d of file %s: %s",
                    342:                yylineno, filestack[ninclude-1].fname, s);
                    343: fatal(buf);
                    344: }
                    345: short yyexca[] ={
                    346: -1, 1,
                    347:        0, -1,
                    348:        -2, 0,
                    349:        };
                    350: # define YYNPROD 22
                    351: # define YYLAST 21
                    352: short yyact[]={
                    353: 
                    354:   17,  20,  21,  16,   7,   9,  11,  18,  19,  12,
                    355:   13,   5,   2,   1,   3,   4,  10,   8,   6,  14,
                    356:   15 };
                    357: short yypact[]={
                    358: 
                    359: -1000,-245,-1000,-253,-1000,-1000,-252,-1000,-255,-1000,
                    360: -257,-263,-1000,-1000,-1000,-256,-1000,-1000,-1000,-1000,
                    361: -1000,-1000 };
                    362: short yypgo[]={
                    363: 
                    364:    0,  20,  19,  18,  17,  16,  13,  12,   6 };
                    365: short yyr1[]={
                    366: 
                    367:    0,   6,   6,   7,   7,   7,   7,   3,   3,   4,
                    368:    4,   5,   5,   5,   5,   5,   8,   8,   2,   2,
                    369:    1,   1 };
                    370: short yyr2[]={
                    371: 
                    372:    0,   0,   2,   1,   1,   4,   1,   1,   2,   0,
                    373:    1,   1,   2,   2,   2,   2,   1,   1,   0,   1,
                    374:    1,   2 };
                    375: short yychk[]={
                    376: 
                    377: -1000,  -6,  -7, 259, 260, 256,  -3, 257,  -4, 257,
                    378:   -5,  -8, 261, 262,  -2,  -1, 258, 257, 264, 265,
                    379:  264, 258 };
                    380: short yydef[]={
                    381: 
                    382:    1,  -2,   2,   3,   4,   6,   9,   7,  18,   8,
                    383:   10,  11,  16,  17,   5,  19,  20,  13,  14,  15,
                    384:   12,  21 };
                    385: #ifndef lint
                    386: static char yaccpar_sccsid[] = "@(#)yaccpar 1.1 85/12/19 SMI"; /* from UCB 4.1 83/02/11 */
                    387: #endif
                    388: 
                    389: #
                    390: # define YYFLAG -1000
                    391: # define YYERROR goto yyerrlab
                    392: # define YYACCEPT return(0)
                    393: # define YYABORT return(1)
                    394: 
                    395: /*     parser for yacc output  */
                    396: 
                    397: #ifdef YYDEBUG
                    398: int yydebug = 0; /* 1 for debugging */
                    399: #endif
                    400: YYSTYPE yyv[YYMAXDEPTH]; /* where the values are stored */
                    401: int yychar = -1; /* current input token number */
                    402: int yynerrs = 0;  /* number of errors */
                    403: short yyerrflag = 0;  /* error recovery flag */
                    404: 
                    405: yyparse() {
                    406: 
                    407:        short yys[YYMAXDEPTH];
                    408:        short yyj, yym;
                    409:        register YYSTYPE *yypvt;
                    410:        register short yystate, *yyps, yyn;
                    411:        register YYSTYPE *yypv;
                    412:        register short *yyxi;
                    413: 
                    414:        yystate = 0;
                    415:        yychar = -1;
                    416:        yynerrs = 0;
                    417:        yyerrflag = 0;
                    418:        yyps= &yys[-1];
                    419:        yypv= &yyv[-1];
                    420: 
                    421:  yystack:    /* put a state and value onto the stack */
                    422: 
                    423: #ifdef YYDEBUG
                    424:        if( yydebug  ) printf( "state %d, char 0%o\n", yystate, yychar );
                    425: #endif
                    426:                if( ++yyps> &yys[YYMAXDEPTH] ) { yyerror( "yacc stack overflow" ); return(1); }
                    427:                *yyps = yystate;
                    428:                ++yypv;
                    429:                *yypv = yyval;
                    430: 
                    431:  yynewstate:
                    432: 
                    433:        yyn = yypact[yystate];
                    434: 
                    435:        if( yyn<= YYFLAG ) goto yydefault; /* simple state */
                    436: 
                    437:        if( yychar<0 ) if( (yychar=yylex())<0 ) yychar=0;
                    438:        if( (yyn += yychar)<0 || yyn >= YYLAST ) goto yydefault;
                    439: 
                    440:        if( yychk[ yyn=yyact[ yyn ] ] == yychar ){ /* valid shift */
                    441:                yychar = -1;
                    442:                yyval = yylval;
                    443:                yystate = yyn;
                    444:                if( yyerrflag > 0 ) --yyerrflag;
                    445:                goto yystack;
                    446:                }
                    447: 
                    448:  yydefault:
                    449:        /* default state action */
                    450: 
                    451:        if( (yyn=yydef[yystate]) == -2 ) {
                    452:                if( yychar<0 ) if( (yychar=yylex())<0 ) yychar = 0;
                    453:                /* look through exception table */
                    454: 
                    455:                for( yyxi=yyexca; (*yyxi!= (-1)) || (yyxi[1]!=yystate) ; yyxi += 2 ) ; /* VOID */
                    456: 
                    457:                while( *(yyxi+=2) >= 0 ){
                    458:                        if( *yyxi == yychar ) break;
                    459:                        }
                    460:                if( (yyn = yyxi[1]) < 0 ) return(0);   /* accept */
                    461:                }
                    462: 
                    463:        if( yyn == 0 ){ /* error */
                    464:                /* error ... attempt to resume parsing */
                    465: 
                    466:                switch( yyerrflag ){
                    467: 
                    468:                case 0:   /* brand new error */
                    469: 
                    470:                        yyerror( "syntax error" );
                    471:                yyerrlab:
                    472:                        ++yynerrs;
                    473: 
                    474:                case 1:
                    475:                case 2: /* incompletely recovered error ... try again */
                    476: 
                    477:                        yyerrflag = 3;
                    478: 
                    479:                        /* find a state where "error" is a legal shift action */
                    480: 
                    481:                        while ( yyps >= yys ) {
                    482:                           yyn = yypact[*yyps] + YYERRCODE;
                    483:                           if( yyn>= 0 && yyn < YYLAST && yychk[yyact[yyn]] == YYERRCODE ){
                    484:                              yystate = yyact[yyn];  /* simulate a shift of "error" */
                    485:                              goto yystack;
                    486:                              }
                    487:                           yyn = yypact[*yyps];
                    488: 
                    489:                           /* the current yyps has no shift onn "error", pop stack */
                    490: 
                    491: #ifdef YYDEBUG
                    492:                           if( yydebug ) printf( "error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1] );
                    493: #endif
                    494:                           --yyps;
                    495:                           --yypv;
                    496:                           }
                    497: 
                    498:                        /* there is no state on the stack with an error shift ... abort */
                    499: 
                    500:        yyabort:
                    501:                        return(1);
                    502: 
                    503: 
                    504:                case 3:  /* no shift yet; clobber input char */
                    505: 
                    506: #ifdef YYDEBUG
                    507:                        if( yydebug ) printf( "error recovery discards char %d\n", yychar );
                    508: #endif
                    509: 
                    510:                        if( yychar == 0 ) goto yyabort; /* don't discard EOF, quit */
                    511:                        yychar = -1;
                    512:                        goto yynewstate;   /* try again in the same state */
                    513: 
                    514:                        }
                    515: 
                    516:                }
                    517: 
                    518:        /* reduction by production yyn */
                    519: 
                    520: #ifdef YYDEBUG
                    521:                if( yydebug ) printf("reduce %d\n",yyn);
                    522: #endif
                    523:                yyps -= yyr2[yyn];
                    524:                yypvt = yypv;
                    525:                yypv -= yyr2[yyn];
                    526:                yyval = yypv[1];
                    527:                yym=yyn;
                    528:                        /* consult goto table to find next state */
                    529:                yyn = yyr1[yyn];
                    530:                yyj = yypgo[yyn] + *yyps + 1;
                    531:                if( yyj>=YYLAST || yychk[ yystate = yyact[yyj] ] != -yyn ) yystate = yyact[yypgo[yyn]];
                    532:                switch(yym){
                    533:                        
                    534: case 5:
                    535: # line 49 "gram.y"
                    536:  {
                    537:            while( --nlefts >= 0)
                    538:                {
                    539:                wildp iswild(), wp;
                    540: 
                    541:                leftp = lefts[nlefts];
                    542:                if(wp = iswild(leftp->namep))
                    543:                        {
                    544:                        leftp->septype = SOMEDEPS;
                    545:                        if(lastwild)
                    546:                                lastwild->next = wp;
                    547:                        else
                    548:                                firstwild = wp;
                    549:                        lastwild = wp;
                    550:                        }
                    551: 
                    552:                if(leftp->septype == 0)
                    553:                        leftp->septype = sepc;
                    554:                else if(leftp->septype != sepc)
                    555:                        {
                    556:                        if(! wp)
                    557:                                fprintf(stderr,
                    558:                                        "Inconsistent rules lines for `%s'\n",
                    559:                                        leftp->namep);
                    560:                        }
                    561:                else if(sepc==ALLDEPS && leftp->namep[0]!='.' && yypvt[-0].yshblock!=0)
                    562:                        {
                    563:                        for(lp=leftp->linep; lp->nxtlineblock; lp=lp->nxtlineblock)
                    564:                        if(lp->shp)
                    565:                                fprintf(stderr,
                    566:                                        "Multiple rules lines for `%s'\n",
                    567:                                        leftp->namep);
                    568:                        }
                    569: 
                    570:                lp = ALLOC(lineblock);
                    571:                lp->nxtlineblock = NULL;
                    572:                lp->depp = yypvt[-1].ydepblock;
                    573:                lp->shp = yypvt[-0].yshblock;
                    574:                if(wp)
                    575:                        wp->linep = lp;
                    576: 
                    577:                if(equal(leftp->namep, ".SUFFIXES") && yypvt[-1].ydepblock==0)
                    578:                        leftp->linep = 0;
                    579:                else if(leftp->linep == 0)
                    580:                        leftp->linep = lp;
                    581:                else    {
                    582:                        for(lpp = leftp->linep; lpp->nxtlineblock;
                    583:                                lpp = lpp->nxtlineblock) ;
                    584:                                if(sepc==ALLDEPS && leftp->namep[0]=='.')
                    585:                                        lpp->shp = 0;
                    586:                        lpp->nxtlineblock = lp;
                    587:                        }
                    588:                }
                    589:        } break;
                    590: case 7:
                    591: # line 106 "gram.y"
                    592:  { lefts[0] = yypvt[-0].ynameblock; nlefts = 1; } break;
                    593: case 8:
                    594: # line 107 "gram.y"
                    595:  { lefts[nlefts++] = yypvt[-0].ynameblock;
                    596:                if(nlefts>=NLEFTS) fatal("Too many lefts"); } break;
                    597: case 9:
                    598: # line 112 "gram.y"
                    599: {
                    600:                char junk[10];
                    601:                sprintf(junk, "%d", yylineno);
                    602:                fatal1("Must be a separator on rules line %s", junk);
                    603:                } break;
                    604: case 11:
                    605: # line 120 "gram.y"
                    606:  { prevdep = 0;  yyval.ydepblock = 0; allnowait = NO; } break;
                    607: case 12:
                    608: # line 121 "gram.y"
                    609:  { prevdep = 0; yyval.ydepblock = 0; allnowait = YES; } break;
                    610: case 13:
                    611: # line 122 "gram.y"
                    612:  {
                    613:                          pp = ALLOC(depblock);
                    614:                          pp->nxtdepblock = NULL;
                    615:                          pp->depname = yypvt[-0].ynameblock;
                    616:                          pp->nowait = allnowait;
                    617:                          if(prevdep == 0) yyval.ydepblock = pp;
                    618:                          else  prevdep->nxtdepblock = pp;
                    619:                          prevdep = pp;
                    620:                          } break;
                    621: case 14:
                    622: # line 131 "gram.y"
                    623:  { if(prevdep) prevdep->nowait = YES; } break;
                    624: case 16:
                    625: # line 135 "gram.y"
                    626:  { sepc = ALLDEPS; } break;
                    627: case 17:
                    628: # line 136 "gram.y"
                    629:  { sepc = SOMEDEPS; } break;
                    630: case 18:
                    631: # line 139 "gram.y"
                    632:  {yyval.yshblock = 0; } break;
                    633: case 19:
                    634: # line 140 "gram.y"
                    635:  { yyval.yshblock = yypvt[-0].yshblock; } break;
                    636: case 20:
                    637: # line 143 "gram.y"
                    638:  { yyval.yshblock = yypvt[-0].yshblock;  prevshp = yypvt[-0].yshblock; } break;
                    639: case 21:
                    640: # line 144 "gram.y"
                    641:  { yyval.yshblock = yypvt[-1].yshblock;
                    642:                        prevshp->nxtshblock = yypvt[-0].yshblock;
                    643:                        prevshp = yypvt[-0].yshblock;
                    644:                        } break;
                    645:                }
                    646:                goto yystack;  /* stack new state and value */
                    647: 
                    648:        }

unix.superglobalmegacorp.com

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