Annotation of cci/usr/src/bin/make/gram.c, revision 1.1.1.2

1.1       root        1: 
                      2: # line 1 "gram.y"
                      3: #include "defs"
                      4: static char *sccsid = "@(#)gram.y      4.1 (Berkeley) 81/02/28";
                      5: 
                      6: # line 6 "gram.y"
                      7: typedef union 
                      8:        {
                      9:        struct shblock *yshblock;
                     10:        struct depblock *ydepblock;
                     11:        struct nameblock *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 yyclearin yychar = -1
                     21: #define yyerrok yyerrflag = 0
                     22: extern int yychar;
                     23: extern short yyerrflag;
                     24: #ifndef YYMAXDEPTH
                     25: #define YYMAXDEPTH 150
                     26: #endif
                     27: YYSTYPE yylval, yyval;
                     28: 
                     29: # line 21 "gram.y"
                     30: struct depblock *pp;
                     31: FSTATIC struct shblock *prevshp;
                     32: 
                     33: FSTATIC struct nameblock *lefts[NLEFTS];
                     34: struct nameblock *leftp;
                     35: FSTATIC int nlefts;
                     36: 
                     37: struct lineblock *lp, *lpp;
                     38: FSTATIC struct depblock *prevdep;
                     39: FSTATIC int sepc;
                     40: # define YYERRCODE 256
                     41: 
                     42: # line 118 "gram.y"
                     43: 
                     44: 
                     45: char *zznextc; /* zero if need another line; otherwise points to next char */
                     46: int yylineno;
                     47: extern FILE * fin;
                     48: 
                     49: yylex()
                     50: {
                     51: register char *p;
                     52: register char *q;
                     53: char word[INMAX];
                     54: 
                     55: if(zznextc == 0)
                     56:        return( nextlin() );
                     57: 
                     58: while( isspace(*zznextc) )
                     59:        ++zznextc;
                     60: 
                     61: if(*zznextc == '\0')
                     62:        return( nextlin() );
                     63: 
                     64: if(*zznextc == ':')
                     65:        {
                     66:        if(*++zznextc == ':')
                     67:                {
                     68:                ++zznextc;
                     69:                return(DOUBLECOLON);
                     70:                }
                     71:        else    return(COLON);
                     72:        }
                     73: 
                     74: if(*zznextc == '>')
                     75:        {
                     76:        ++zznextc;
                     77:        return(GREATER);
                     78:        }
                     79: 
                     80: if(*zznextc == ';')
                     81:        return( retsh(zznextc) );
                     82: 
                     83: p = zznextc;
                     84: q = word;
                     85: 
                     86: while( ! ( funny[*p] & TERMINAL) )
                     87:        *q++ = *p++;
                     88: 
                     89: if(p != zznextc)
                     90:        {
                     91:        *q = '\0';
                     92:        if((yylval.ynameblock=srchname(word))==0)
                     93:                yylval.ynameblock = makename(word);
                     94:        zznextc = p;
                     95:        return(NAME);
                     96:        }
                     97: 
                     98: else   {
                     99:        fprintf(stderr,"Bad character %c (octal %o), line %d",
                    100:                *zznextc,*zznextc,yylineno);
                    101:        fatal( (char *) NULL );
                    102:        }
                    103: return(0);     /* never executed */
                    104: }
                    105: 
                    106: 
                    107: 
                    108: 
                    109: 
                    110: retsh(q)
                    111: char *q;
                    112: {
                    113: register char *p;
                    114: struct shblock *sp;
                    115: char *copys();
                    116: 
                    117: for(p=q+1 ; *p==' '||*p=='\t' ; ++p)  ;
                    118: 
                    119: sp = ALLOC(shblock);
                    120: sp->nxtshblock = NULL;
                    121: sp->shbp = (fin == NULL ? p : copys(p) );
                    122: yylval.yshblock = sp;
                    123: zznextc = 0;
                    124: return(SHELLINE);
                    125: }
                    126: 
                    127: nextlin()
                    128: {
                    129: static char yytext[INMAX];
                    130: static char *yytextl   = yytext+INMAX;
                    131: char *text, templin[INMAX];
                    132: register char c;
                    133: register char *p, *t;
                    134: char lastch, *lastchp;
                    135: extern char **linesptr;
                    136: int incom;
                    137: int kc;
                    138: 
                    139: again:
                    140: 
                    141:        incom = NO;
                    142:        zznextc = 0;
                    143: 
                    144: if(fin == NULL)
                    145:        {
                    146:        if( (text = *linesptr++) == 0)
                    147:                return(0);
                    148:        ++yylineno;
                    149:        }
                    150: 
                    151: else   {
                    152:        for(p = text = yytext ; p<yytextl ; *p++ = kc)
                    153:                switch(kc = getc(fin))
                    154:                        {
                    155:                        case '\t':
                    156:                                if(p != yytext)
                    157:                                        break;
                    158:                        case ';':
                    159:                                incom = YES;
                    160:                                break;
                    161: 
                    162:                        case '#':
                    163:                                if(! incom)
                    164:                                        kc = '\0';
                    165:                                break;
                    166: 
                    167:                        case '\n':
                    168:                                ++yylineno;
                    169:                                if(p==yytext || p[-1]!='\\')
                    170:                                        {
                    171:                                        *p = '\0';
                    172:                                        goto endloop;
                    173:                                        }
                    174:                                p[-1] = ' ';
                    175:                                while( (kc=getc(fin))=='\t' || kc==' ' || kc=='\n')
                    176:                                        if(kc == '\n')
                    177:                                                ++yylineno;
                    178:        
                    179:                                if(kc != EOF)
                    180:                                        break;
                    181:                        case EOF:
                    182:                                *p = '\0';
                    183:                                return(0);
                    184:                        }
                    185: 
                    186:        fatal("line too long");
                    187:        }
                    188: 
                    189: endloop:
                    190: 
                    191:        if((c = text[0]) == '\t')
                    192:                return( retsh(text) );
                    193:        
                    194:        if(isalpha(c) || isdigit(c) || c==' ' || c=='.')
                    195:                for(p=text+1; *p!='\0'; )
                    196:                        if(*p == ':')
                    197:                                break;
                    198:                        else if(*p++ == '=')
                    199:                                {
                    200:                                eqsign(text);
                    201:                                return(MACRODEF);
                    202:                                }
                    203: 
                    204: /* substitute for macros on dependency line up to the semicolon if any */
                    205: 
                    206: for(t = yytext ; *t!='\0' && *t!=';' ; ++t)
                    207:        ;
                    208: 
                    209: lastchp = t;
                    210: lastch = *t;
                    211: *t = '\0';
                    212: 
                    213: subst(yytext, templin);                /* Substitute for macros on dependency lines */
                    214: 
                    215: if(lastch)
                    216:        {
                    217:        for(t = templin ; *t ; ++t)
                    218:                ;
                    219:        *t = lastch;
                    220:        while( *++t = *++lastchp ) ;
                    221:        }
                    222: 
                    223: p = templin;
                    224: t = yytext;
                    225: while( *t++ = *p++ )
                    226:        ;
                    227: 
                    228: for(p = zznextc = text ; *p ; ++p )
                    229:        if(*p!=' ' && *p!='\t')
                    230:                return(START);
                    231: goto again;
                    232: }
                    233: short yyexca[] ={
                    234: -1, 1,
                    235:        0, -1,
                    236:        -2, 0,
                    237:        };
                    238: # define YYNPROD 19
                    239: # define YYLAST 18
                    240: short yyact[]={
                    241: 
                    242:    9,  11,  18,   5,  12,  13,   3,   4,  16,  17,
                    243:    7,   2,   1,  10,   8,   6,  14,  15 };
                    244: short yypact[]={
                    245: 
                    246: -1000,-253,-1000,-247,-1000,-1000,-257,-1000,-250,-1000,
                    247: -248,-1000,-1000,-1000,-1000,-256,-1000,-1000,-1000 };
                    248: short yypgo[]={
                    249: 
                    250:    0,  17,  16,  15,  14,  13,  12,  11,   1 };
                    251: short yyr1[]={
                    252: 
                    253:    0,   6,   6,   7,   7,   7,   7,   3,   3,   4,
                    254:    4,   5,   5,   8,   8,   2,   2,   1,   1 };
                    255: short yyr2[]={
                    256: 
                    257:    0,   0,   2,   1,   1,   4,   1,   1,   2,   0,
                    258:    1,   1,   2,   1,   1,   0,   1,   1,   2 };
                    259: short yychk[]={
                    260: 
                    261: -1000,  -6,  -7, 259, 260, 256,  -3, 257,  -4, 257,
                    262:   -5,  -8, 261, 262,  -2,  -1, 258, 257, 258 };
                    263: short yydef[]={
                    264: 
                    265:    1,  -2,   2,   3,   4,   6,   9,   7,  15,   8,
                    266:   10,  11,  13,  14,   5,  16,  17,  12,  18 };
1.1.1.2 ! root      267: #ifndef lint
        !           268: static char yaccpar_sccsid[] = "@(#)yaccpar    4.1     (Berkeley)      2/11/83";
        !           269: #endif not lint
        !           270: 
1.1       root      271: #
                    272: # define YYFLAG -1000
                    273: # define YYERROR goto yyerrlab
                    274: # define YYACCEPT return(0)
                    275: # define YYABORT return(1)
                    276: 
                    277: /*     parser for yacc output  */
                    278: 
                    279: #ifdef YYDEBUG
                    280: int yydebug = 0; /* 1 for debugging */
                    281: #endif
                    282: YYSTYPE yyv[YYMAXDEPTH]; /* where the values are stored */
                    283: int yychar = -1; /* current input token number */
                    284: int yynerrs = 0;  /* number of errors */
                    285: short yyerrflag = 0;  /* error recovery flag */
                    286: 
                    287: yyparse() {
                    288: 
                    289:        short yys[YYMAXDEPTH];
                    290:        short yyj, yym;
                    291:        register YYSTYPE *yypvt;
                    292:        register short yystate, *yyps, yyn;
                    293:        register YYSTYPE *yypv;
                    294:        register short *yyxi;
                    295: 
                    296:        yystate = 0;
                    297:        yychar = -1;
                    298:        yynerrs = 0;
                    299:        yyerrflag = 0;
                    300:        yyps= &yys[-1];
                    301:        yypv= &yyv[-1];
                    302: 
                    303:  yystack:    /* put a state and value onto the stack */
                    304: 
                    305: #ifdef YYDEBUG
                    306:        if( yydebug  ) printf( "state %d, char 0%o\n", yystate, yychar );
                    307: #endif
                    308:                if( ++yyps> &yys[YYMAXDEPTH] ) { yyerror( "yacc stack overflow" ); return(1); }
                    309:                *yyps = yystate;
                    310:                ++yypv;
                    311:                *yypv = yyval;
                    312: 
                    313:  yynewstate:
                    314: 
                    315:        yyn = yypact[yystate];
                    316: 
                    317:        if( yyn<= YYFLAG ) goto yydefault; /* simple state */
                    318: 
                    319:        if( yychar<0 ) if( (yychar=yylex())<0 ) yychar=0;
                    320:        if( (yyn += yychar)<0 || yyn >= YYLAST ) goto yydefault;
                    321: 
                    322:        if( yychk[ yyn=yyact[ yyn ] ] == yychar ){ /* valid shift */
                    323:                yychar = -1;
                    324:                yyval = yylval;
                    325:                yystate = yyn;
                    326:                if( yyerrflag > 0 ) --yyerrflag;
                    327:                goto yystack;
                    328:                }
                    329: 
                    330:  yydefault:
                    331:        /* default state action */
                    332: 
                    333:        if( (yyn=yydef[yystate]) == -2 ) {
                    334:                if( yychar<0 ) if( (yychar=yylex())<0 ) yychar = 0;
                    335:                /* look through exception table */
                    336: 
                    337:                for( yyxi=yyexca; (*yyxi!= (-1)) || (yyxi[1]!=yystate) ; yyxi += 2 ) ; /* VOID */
                    338: 
                    339:                while( *(yyxi+=2) >= 0 ){
                    340:                        if( *yyxi == yychar ) break;
                    341:                        }
                    342:                if( (yyn = yyxi[1]) < 0 ) return(0);   /* accept */
                    343:                }
                    344: 
                    345:        if( yyn == 0 ){ /* error */
                    346:                /* error ... attempt to resume parsing */
                    347: 
                    348:                switch( yyerrflag ){
                    349: 
                    350:                case 0:   /* brand new error */
                    351: 
                    352:                        yyerror( "syntax error" );
                    353:                yyerrlab:
                    354:                        ++yynerrs;
                    355: 
                    356:                case 1:
                    357:                case 2: /* incompletely recovered error ... try again */
                    358: 
                    359:                        yyerrflag = 3;
                    360: 
                    361:                        /* find a state where "error" is a legal shift action */
                    362: 
                    363:                        while ( yyps >= yys ) {
                    364:                           yyn = yypact[*yyps] + YYERRCODE;
                    365:                           if( yyn>= 0 && yyn < YYLAST && yychk[yyact[yyn]] == YYERRCODE ){
                    366:                              yystate = yyact[yyn];  /* simulate a shift of "error" */
                    367:                              goto yystack;
                    368:                              }
                    369:                           yyn = yypact[*yyps];
                    370: 
                    371:                           /* the current yyps has no shift onn "error", pop stack */
                    372: 
                    373: #ifdef YYDEBUG
                    374:                           if( yydebug ) printf( "error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1] );
                    375: #endif
                    376:                           --yyps;
                    377:                           --yypv;
                    378:                           }
                    379: 
                    380:                        /* there is no state on the stack with an error shift ... abort */
                    381: 
                    382:        yyabort:
                    383:                        return(1);
                    384: 
                    385: 
                    386:                case 3:  /* no shift yet; clobber input char */
                    387: 
                    388: #ifdef YYDEBUG
                    389:                        if( yydebug ) printf( "error recovery discards char %d\n", yychar );
                    390: #endif
                    391: 
                    392:                        if( yychar == 0 ) goto yyabort; /* don't discard EOF, quit */
                    393:                        yychar = -1;
                    394:                        goto yynewstate;   /* try again in the same state */
                    395: 
                    396:                        }
                    397: 
                    398:                }
                    399: 
                    400:        /* reduction by production yyn */
                    401: 
                    402: #ifdef YYDEBUG
                    403:                if( yydebug ) printf("reduce %d\n",yyn);
                    404: #endif
                    405:                yyps -= yyr2[yyn];
                    406:                yypvt = yypv;
                    407:                yypv -= yyr2[yyn];
                    408:                yyval = yypv[1];
                    409:                yym=yyn;
                    410:                        /* consult goto table to find next state */
                    411:                yyn = yyr1[yyn];
                    412:                yyj = yypgo[yyn] + *yyps + 1;
                    413:                if( yyj>=YYLAST || yychk[ yystate = yyact[yyj] ] != -yyn ) yystate = yyact[yypgo[yyn]];
                    414:                switch(yym){
                    415:                        
                    416: case 5:
                    417: # line 40 "gram.y"
                    418:  {
                    419:            while( --nlefts >= 0)
                    420:                {
                    421:                leftp = lefts[nlefts];
                    422:                if(leftp->septype == 0)
                    423:                        leftp->septype = sepc;
                    424:                else if(leftp->septype != sepc)
                    425:                        fprintf(stderr, "Inconsistent rules lines for `%s'\n",
                    426:                                leftp->namep);
                    427:                else if(sepc==ALLDEPS && *(leftp->namep)!='.' && yypvt[-0].yshblock!=0)
                    428:                        {
                    429:                        for(lp=leftp->linep; lp->nxtlineblock!=0; lp=lp->nxtlineblock)
                    430:                            if(lp->shp)
                    431:                                fprintf(stderr, "Multiple rules lines for `%s'\n",
                    432:                                    leftp->namep);
                    433:                        }
                    434: 
                    435:                lp = ALLOC(lineblock);
                    436:                lp->nxtlineblock = NULL;
                    437:                lp->depp = yypvt[-1].ydepblock;
                    438:                lp->shp = yypvt[-0].yshblock;
                    439: 
                    440:                if(! unequal(leftp->namep, ".SUFFIXES") && yypvt[-1].ydepblock==0)
                    441:                        leftp->linep = 0;
                    442:                else if(leftp->linep == 0)
                    443:                        leftp->linep = lp;
                    444:                else    {
                    445:                        for(lpp = leftp->linep; lpp->nxtlineblock;
                    446:                                lpp = lpp->nxtlineblock) ;
                    447:                                if(sepc==ALLDEPS && leftp->namep[0]=='.')
                    448:                                        lpp->shp = 0;
                    449:                        lpp->nxtlineblock = lp;
                    450:                        }
                    451:                }
                    452:        } break;
                    453: case 7:
                    454: # line 78 "gram.y"
                    455:  { lefts[0] = yypvt[-0].ynameblock; nlefts = 1; } break;
                    456: case 8:
                    457: # line 79 "gram.y"
                    458:  { lefts[nlefts++] = yypvt[-0].ynameblock;
                    459:                if(nlefts>=NLEFTS) fatal("Too many lefts"); } break;
                    460: case 9:
                    461: # line 84 "gram.y"
                    462: {
                    463:                char junk[10];
                    464:                sprintf(junk, "%d", yylineno);
                    465:                fatal1("Must be a separator on rules line %s", junk);
                    466:                } break;
                    467: case 11:
                    468: # line 92 "gram.y"
                    469:  { prevdep = 0;  yyval.ydepblock = 0; } break;
                    470: case 12:
                    471: # line 93 "gram.y"
                    472:  {
                    473:                          pp = ALLOC(depblock);
                    474:                          pp->nxtdepblock = NULL;
                    475:                          pp->depname = yypvt[-0].ynameblock;
                    476:                          if(prevdep == 0) yyval.ydepblock = pp;
                    477:                          else  prevdep->nxtdepblock = pp;
                    478:                          prevdep = pp;
                    479:                          } break;
                    480: case 13:
                    481: # line 103 "gram.y"
                    482:  { sepc = ALLDEPS; } break;
                    483: case 14:
                    484: # line 104 "gram.y"
                    485:  { sepc = SOMEDEPS; } break;
                    486: case 15:
                    487: # line 107 "gram.y"
                    488:  {yyval.yshblock = 0; } break;
                    489: case 16:
                    490: # line 108 "gram.y"
                    491:  { yyval.yshblock = yypvt[-0].yshblock; } break;
                    492: case 17:
                    493: # line 111 "gram.y"
                    494:  { yyval.yshblock = yypvt[-0].yshblock;  prevshp = yypvt[-0].yshblock; } break;
                    495: case 18:
                    496: # line 112 "gram.y"
                    497:  { yyval.yshblock = yypvt[-1].yshblock;
                    498:                        prevshp->nxtshblock = yypvt[-0].yshblock;
                    499:                        prevshp = yypvt[-0].yshblock;
                    500:                        } break;
                    501:                }
                    502:                goto yystack;  /* stack new state and value */
                    503: 
                    504:        }

unix.superglobalmegacorp.com

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