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

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 };
        !           267: #
        !           268: # define YYFLAG -1000
        !           269: # define YYERROR goto yyerrlab
        !           270: # define YYACCEPT return(0)
        !           271: # define YYABORT return(1)
        !           272: 
        !           273: /*     parser for yacc output  */
        !           274: 
        !           275: #ifdef YYDEBUG
        !           276: int yydebug = 0; /* 1 for debugging */
        !           277: #endif
        !           278: YYSTYPE yyv[YYMAXDEPTH]; /* where the values are stored */
        !           279: int yychar = -1; /* current input token number */
        !           280: int yynerrs = 0;  /* number of errors */
        !           281: short yyerrflag = 0;  /* error recovery flag */
        !           282: 
        !           283: yyparse() {
        !           284: 
        !           285:        short yys[YYMAXDEPTH];
        !           286:        short yyj, yym;
        !           287:        register YYSTYPE *yypvt;
        !           288:        register short yystate, *yyps, yyn;
        !           289:        register YYSTYPE *yypv;
        !           290:        register short *yyxi;
        !           291: 
        !           292:        yystate = 0;
        !           293:        yychar = -1;
        !           294:        yynerrs = 0;
        !           295:        yyerrflag = 0;
        !           296:        yyps= &yys[-1];
        !           297:        yypv= &yyv[-1];
        !           298: 
        !           299:  yystack:    /* put a state and value onto the stack */
        !           300: 
        !           301: #ifdef YYDEBUG
        !           302:        if( yydebug  ) printf( "state %d, char 0%o\n", yystate, yychar );
        !           303: #endif
        !           304:                if( ++yyps> &yys[YYMAXDEPTH] ) { yyerror( "yacc stack overflow" ); return(1); }
        !           305:                *yyps = yystate;
        !           306:                ++yypv;
        !           307:                *yypv = yyval;
        !           308: 
        !           309:  yynewstate:
        !           310: 
        !           311:        yyn = yypact[yystate];
        !           312: 
        !           313:        if( yyn<= YYFLAG ) goto yydefault; /* simple state */
        !           314: 
        !           315:        if( yychar<0 ) if( (yychar=yylex())<0 ) yychar=0;
        !           316:        if( (yyn += yychar)<0 || yyn >= YYLAST ) goto yydefault;
        !           317: 
        !           318:        if( yychk[ yyn=yyact[ yyn ] ] == yychar ){ /* valid shift */
        !           319:                yychar = -1;
        !           320:                yyval = yylval;
        !           321:                yystate = yyn;
        !           322:                if( yyerrflag > 0 ) --yyerrflag;
        !           323:                goto yystack;
        !           324:                }
        !           325: 
        !           326:  yydefault:
        !           327:        /* default state action */
        !           328: 
        !           329:        if( (yyn=yydef[yystate]) == -2 ) {
        !           330:                if( yychar<0 ) if( (yychar=yylex())<0 ) yychar = 0;
        !           331:                /* look through exception table */
        !           332: 
        !           333:                for( yyxi=yyexca; (*yyxi!= (-1)) || (yyxi[1]!=yystate) ; yyxi += 2 ) ; /* VOID */
        !           334: 
        !           335:                while( *(yyxi+=2) >= 0 ){
        !           336:                        if( *yyxi == yychar ) break;
        !           337:                        }
        !           338:                if( (yyn = yyxi[1]) < 0 ) return(0);   /* accept */
        !           339:                }
        !           340: 
        !           341:        if( yyn == 0 ){ /* error */
        !           342:                /* error ... attempt to resume parsing */
        !           343: 
        !           344:                switch( yyerrflag ){
        !           345: 
        !           346:                case 0:   /* brand new error */
        !           347: 
        !           348:                        yyerror( "syntax error" );
        !           349:                yyerrlab:
        !           350:                        ++yynerrs;
        !           351: 
        !           352:                case 1:
        !           353:                case 2: /* incompletely recovered error ... try again */
        !           354: 
        !           355:                        yyerrflag = 3;
        !           356: 
        !           357:                        /* find a state where "error" is a legal shift action */
        !           358: 
        !           359:                        while ( yyps >= yys ) {
        !           360:                           yyn = yypact[*yyps] + YYERRCODE;
        !           361:                           if( yyn>= 0 && yyn < YYLAST && yychk[yyact[yyn]] == YYERRCODE ){
        !           362:                              yystate = yyact[yyn];  /* simulate a shift of "error" */
        !           363:                              goto yystack;
        !           364:                              }
        !           365:                           yyn = yypact[*yyps];
        !           366: 
        !           367:                           /* the current yyps has no shift onn "error", pop stack */
        !           368: 
        !           369: #ifdef YYDEBUG
        !           370:                           if( yydebug ) printf( "error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1] );
        !           371: #endif
        !           372:                           --yyps;
        !           373:                           --yypv;
        !           374:                           }
        !           375: 
        !           376:                        /* there is no state on the stack with an error shift ... abort */
        !           377: 
        !           378:        yyabort:
        !           379:                        return(1);
        !           380: 
        !           381: 
        !           382:                case 3:  /* no shift yet; clobber input char */
        !           383: 
        !           384: #ifdef YYDEBUG
        !           385:                        if( yydebug ) printf( "error recovery discards char %d\n", yychar );
        !           386: #endif
        !           387: 
        !           388:                        if( yychar == 0 ) goto yyabort; /* don't discard EOF, quit */
        !           389:                        yychar = -1;
        !           390:                        goto yynewstate;   /* try again in the same state */
        !           391: 
        !           392:                        }
        !           393: 
        !           394:                }
        !           395: 
        !           396:        /* reduction by production yyn */
        !           397: 
        !           398: #ifdef YYDEBUG
        !           399:                if( yydebug ) printf("reduce %d\n",yyn);
        !           400: #endif
        !           401:                yyps -= yyr2[yyn];
        !           402:                yypvt = yypv;
        !           403:                yypv -= yyr2[yyn];
        !           404:                yyval = yypv[1];
        !           405:                yym=yyn;
        !           406:                        /* consult goto table to find next state */
        !           407:                yyn = yyr1[yyn];
        !           408:                yyj = yypgo[yyn] + *yyps + 1;
        !           409:                if( yyj>=YYLAST || yychk[ yystate = yyact[yyj] ] != -yyn ) yystate = yyact[yypgo[yyn]];
        !           410:                switch(yym){
        !           411:                        
        !           412: case 5:
        !           413: # line 40 "gram.y"
        !           414:  {
        !           415:            while( --nlefts >= 0)
        !           416:                {
        !           417:                leftp = lefts[nlefts];
        !           418:                if(leftp->septype == 0)
        !           419:                        leftp->septype = sepc;
        !           420:                else if(leftp->septype != sepc)
        !           421:                        fprintf(stderr, "Inconsistent rules lines for `%s'\n",
        !           422:                                leftp->namep);
        !           423:                else if(sepc==ALLDEPS && *(leftp->namep)!='.' && yypvt[-0].yshblock!=0)
        !           424:                        {
        !           425:                        for(lp=leftp->linep; lp->nxtlineblock!=0; lp=lp->nxtlineblock)
        !           426:                            if(lp->shp)
        !           427:                                fprintf(stderr, "Multiple rules lines for `%s'\n",
        !           428:                                    leftp->namep);
        !           429:                        }
        !           430: 
        !           431:                lp = ALLOC(lineblock);
        !           432:                lp->nxtlineblock = NULL;
        !           433:                lp->depp = yypvt[-1].ydepblock;
        !           434:                lp->shp = yypvt[-0].yshblock;
        !           435: 
        !           436:                if(! unequal(leftp->namep, ".SUFFIXES") && yypvt[-1].ydepblock==0)
        !           437:                        leftp->linep = 0;
        !           438:                else if(leftp->linep == 0)
        !           439:                        leftp->linep = lp;
        !           440:                else    {
        !           441:                        for(lpp = leftp->linep; lpp->nxtlineblock;
        !           442:                                lpp = lpp->nxtlineblock) ;
        !           443:                                if(sepc==ALLDEPS && leftp->namep[0]=='.')
        !           444:                                        lpp->shp = 0;
        !           445:                        lpp->nxtlineblock = lp;
        !           446:                        }
        !           447:                }
        !           448:        } break;
        !           449: case 7:
        !           450: # line 78 "gram.y"
        !           451:  { lefts[0] = yypvt[-0].ynameblock; nlefts = 1; } break;
        !           452: case 8:
        !           453: # line 79 "gram.y"
        !           454:  { lefts[nlefts++] = yypvt[-0].ynameblock;
        !           455:                if(nlefts>=NLEFTS) fatal("Too many lefts"); } break;
        !           456: case 9:
        !           457: # line 84 "gram.y"
        !           458: {
        !           459:                char junk[10];
        !           460:                sprintf(junk, "%d", yylineno);
        !           461:                fatal1("Must be a separator on rules line %s", junk);
        !           462:                } break;
        !           463: case 11:
        !           464: # line 92 "gram.y"
        !           465:  { prevdep = 0;  yyval.ydepblock = 0; } break;
        !           466: case 12:
        !           467: # line 93 "gram.y"
        !           468:  {
        !           469:                          pp = ALLOC(depblock);
        !           470:                          pp->nxtdepblock = NULL;
        !           471:                          pp->depname = yypvt[-0].ynameblock;
        !           472:                          if(prevdep == 0) yyval.ydepblock = pp;
        !           473:                          else  prevdep->nxtdepblock = pp;
        !           474:                          prevdep = pp;
        !           475:                          } break;
        !           476: case 13:
        !           477: # line 103 "gram.y"
        !           478:  { sepc = ALLDEPS; } break;
        !           479: case 14:
        !           480: # line 104 "gram.y"
        !           481:  { sepc = SOMEDEPS; } break;
        !           482: case 15:
        !           483: # line 107 "gram.y"
        !           484:  {yyval.yshblock = 0; } break;
        !           485: case 16:
        !           486: # line 108 "gram.y"
        !           487:  { yyval.yshblock = yypvt[-0].yshblock; } break;
        !           488: case 17:
        !           489: # line 111 "gram.y"
        !           490:  { yyval.yshblock = yypvt[-0].yshblock;  prevshp = yypvt[-0].yshblock; } break;
        !           491: case 18:
        !           492: # line 112 "gram.y"
        !           493:  { yyval.yshblock = yypvt[-1].yshblock;
        !           494:                        prevshp->nxtshblock = yypvt[-0].yshblock;
        !           495:                        prevshp = yypvt[-0].yshblock;
        !           496:                        } break;
        !           497:                }
        !           498:                goto yystack;  /* stack new state and value */
        !           499: 
        !           500:        }

unix.superglobalmegacorp.com

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