Annotation of xinu/con/y.tab.c, revision 1.1

1.1     ! root        1: # define DEFBRK 257
        !             2: # define COLON 258
        !             3: # define OCTAL 259
        !             4: # define INTEGER 260
        !             5: # define IDENT 261
        !             6: # define CSR 262
        !             7: # define IVEC 263
        !             8: # define OVEC 264
        !             9: # define IINT 265
        !            10: # define OINT 266
        !            11: # define INIT 267
        !            12: # define OPEN 268
        !            13: # define CLOSE 269
        !            14: # define READ 270
        !            15: # define WRITE 271
        !            16: # define SEEK 272
        !            17: # define CNTL 273
        !            18: # define IS 274
        !            19: # define ON 275
        !            20: # define GETC 276
        !            21: # define PUTC 277
        !            22: 
        !            23: # line 4 "config.y"
        !            24: #include <stdio.h>
        !            25: 
        !            26: #define        NIL     (dvptr)0
        !            27: 
        !            28: #define        CONFIGC         "../sys/conf.c"         /* name of .c output    */
        !            29: #define        CONFIGH         "../h/conf.h"           /* name of .h output    */
        !            30: #define        DISPCONF        "../h/dispconf.h"       /* name of dispatcher .h*/
        !            31: #define        IODISP          "../h/iodisp.h"         /* name of dispat loc .h*/
        !            32: #define        CONFHREF        "<conf.h>"              /* how conf.h referenced*/
        !            33: #define        CONFIGIN        "Configuration"         /* name of input file   */
        !            34: 
        !            35: FILE   *confc;
        !            36: FILE   *confh;
        !            37: FILE   *dispconf;
        !            38: FILE   *iodisp;
        !            39: 
        !            40: char   *dbstr;
        !            41: extern char *malloc();
        !            42: int    ndevs = 0;
        !            43: int    currname = -1;
        !            44: int    currtname = -1;
        !            45: int    currdname = -1;
        !            46: int    brkcount = 0;
        !            47: 
        !            48: struct syment  {                       /* symbol table                 */
        !            49:        char    *symname;
        !            50:        int     symoccurs;
        !            51:        } symtab[250];
        !            52: 
        !            53: int    nsym = 0;
        !            54: int    lookup();
        !            55: int    linectr = 1;
        !            56: char   *doing = "device type declaration";
        !            57: char   *s;
        !            58: struct dvtype {
        !            59:        char            *dvname;        /* device name (not used in types)*/
        !            60:        char            *dvtname;       /* type name                    */
        !            61:        int             dvtnum;         /* symbol table index of type   */
        !            62:        char            *dvdevice;      /* device name                  */
        !            63:        int             dvcsr;          /* Control Status Register addr */
        !            64:        int             dvivec;         /* input interrupt vector       */
        !            65:        int             dvovec;         /* Output interrupt vector      */
        !            66:        char            dviint[20];     /* input interrupt routine      */
        !            67:        char            dvoint[20];     /* output interrupt routine     */
        !            68:        char            dvinit[20];     /* init routine name            */
        !            69:        char            dvopen[20];     /* open routine name            */
        !            70:        char            dvclose[20];    /* close routine name           */
        !            71:        char            dvread[20];     /* read routine name            */
        !            72:        char            dvwrite[20];    /* write routine name           */
        !            73:        char            dvcntl[20];     /* control routine name         */
        !            74:        char            dvseek[20];     /* seek routine name            */
        !            75:        char            dvgetc[20];     /* getc routine name            */
        !            76:        char            dvputc[20];     /* putc routine name            */
        !            77:        int             dvminor;        /* device number 0,1,...        */
        !            78:        struct dvtype   *dvnext;        /* next node on the list        */
        !            79:        };
        !            80: typedef        struct  dvtype  *dvptr;
        !            81:        dvptr   ftypes = NIL;           /* linked list of device types  */
        !            82:        dvptr   devs = NIL;             /* linked list of device decls. */
        !            83:        dvptr   lastdv = NIL;
        !            84:        dvptr   currtype = NIL;
        !            85: 
        !            86: char   *ftout[] = 
        !            87:               {"#ifndef\tASM\n",
        !            88:                "struct\tdevsw\t{\t\t\t/* device table entry */\n",
        !            89:                "\tint\tdvnum;\n",
        !            90:                "\tchar\t*dvname;\n",
        !            91:                "\tint\t(*dvinit)();\n",
        !            92:                "\tint\t(*dvopen)();\n",
        !            93:                "\tint\t(*dvclose)();\n",
        !            94:                "\tint\t(*dvread)();\n",
        !            95:                "\tint\t(*dvwrite)();\n",
        !            96:                "\tint\t(*dvseek)();\n",
        !            97:                "\tint\t(*dvgetc)();\n",
        !            98:                "\tint\t(*dvputc)();\n",
        !            99:                "\tint\t(*dvcntl)();\n",
        !           100:                "\tint\tdvcsr;\n",
        !           101:                "\tint\tdvivec;\n",
        !           102:                "\tint\tdvovec;\n",
        !           103:                "\tint\t(*dviint)();\n",
        !           104:                "\tint\t(*dvoint)();\n",
        !           105:                "\tchar\t*dvioblk;\n",
        !           106:                "\tint\tdvminor;\n",
        !           107:                "\t};\n\n",
        !           108:                "extern\tstruct\tdevsw devtab[];",
        !           109:                "\t\t/* one entry per device */\n",
        !           110:                "#endif\n\n",
        !           111:                NULL};
        !           112: #define yyclearin yychar = -1
        !           113: #define yyerrok yyerrflag = 0
        !           114: extern int yychar;
        !           115: extern short yyerrflag;
        !           116: #ifndef YYMAXDEPTH
        !           117: #define YYMAXDEPTH 150
        !           118: #endif
        !           119: #ifndef YYSTYPE
        !           120: #define YYSTYPE int
        !           121: #endif
        !           122: YYSTYPE yylval, yyval;
        !           123: # define YYERRCODE 256
        !           124: 
        !           125: # line 176 "config.y"
        !           126: 
        !           127: #include "lex.yy.c"
        !           128: main(argc, argv)
        !           129:        int     argc;
        !           130:        char    *argv[];
        !           131: {
        !           132:        int     n, i, j, l, fcount;
        !           133:        dvptr   s;
        !           134:        int     verbose = 0;
        !           135:        char    *p;
        !           136:        char    c;
        !           137: 
        !           138:        if (argc>1 && (strcmp("-v",argv[1])==0)) {
        !           139:                argc--;
        !           140:                argv++;
        !           141:                verbose++;
        !           142:        }
        !           143:        if (argc>2) {
        !           144:                fprintf(stderr,"use: config [-v] [file]\n");
        !           145:                exit(1);
        !           146:        }
        !           147:        if (verbose)
        !           148:                printf("Opening input file...\n");
        !           149:        if (argc == 2) {
        !           150:                if (freopen(argv[1], "r", stdin) == NULL) {
        !           151:                        fprintf(stderr,"Can't open %s\n",argv[1]);
        !           152:                        exit(1);
        !           153:                }
        !           154:        } else {        /* try to open Configuration file */
        !           155:                if (freopen(CONFIGIN, "r", stdin) == NULL) {
        !           156:                        fprintf(stderr,"Can't open %s\n", CONFIGIN);
        !           157:                        exit(1);
        !           158:                }
        !           159:        }
        !           160: 
        !           161:        /* Parse the Configuration file */
        !           162: 
        !           163:        if (verbose)
        !           164:                printf("Parsing configuration specs...\n");
        !           165:        if ((n=yyparse()) != 0)
        !           166:                exit(n);
        !           167: 
        !           168:        /* write config.h and config.c */
        !           169: 
        !           170:        if (verbose)
        !           171:                printf("Opening output files...\n");
        !           172:        if ( (confc=fopen(CONFIGC,"w") ) == NULL) {
        !           173:                fprintf(stderr, "Can't write on %s\n", CONFIGC);
        !           174:                exit(1);
        !           175:        }
        !           176: 
        !           177:        if ( (confh=fopen(CONFIGH,"w") ) == NULL) {
        !           178:                fprintf(stderr, "Can't write on %s\n", CONFIGH);
        !           179:                exit(1);
        !           180:        }
        !           181:        if ( (dispconf=fopen(DISPCONF,"w") ) == NULL) {
        !           182:                fprintf(stderr, "Can't write on %s\n",DISPCONF);
        !           183:                exit(1);
        !           184:        }
        !           185:        if ( (iodisp=fopen(IODISP,"w") ) == NULL) {
        !           186:                fprintf(stderr, "Can't write on %s\n",IODISP);
        !           187:                exit(1);
        !           188:        }
        !           189:        fprintf(confh,
        !           190:                "/* conf.h (GENERATED FILE; DO NOT EDIT) */\n");
        !           191:        fprintf(confc,
        !           192:                "/* conf.c (GENERATED FILE; DO NOT EDIT) */\n");
        !           193:        fprintf(dispconf,
        !           194:                "/* dispconf.h (GENERATED FILE; DO NOT EDIT) */\n");
        !           195:        fprintf(iodisp,
        !           196:                "/* iodisp.h (GENERATED FILE; DO NOT EDIT) */\n");
        !           197:        fprintf(confc, "\n#include %s\n", CONFHREF);
        !           198:        fprintf(confh, "\n#define\tNULLPTR\t(char *)0\n");
        !           199: 
        !           200: 
        !           201:        if (verbose)
        !           202:                printf("Writing output...\n");
        !           203:        fprintf(confh,"\n/* Device table declarations */\n");
        !           204:        for (i=0 ; (p=ftout[i])!=NULL ; i++)
        !           205:                fprintf(confh, "%s", p);
        !           206:        fprintf(dispconf,"\n/* vector-to points for each device */\n\n");
        !           207:        fprintf(iodisp,"\n/* i/o dispatch vector-to location externs */\n\n");
        !           208:        /* write device declarations and definitions; count type refs. */
        !           209: 
        !           210:        fprintf(confh, "\n/* Device name definitions */\n\n");
        !           211:        for (i=0,s=devs; s!=NIL ; s=s->dvnext,i++) {
        !           212:                fprintf(confh, "#define\t%-12s%d\t\t\t/* type %-8s */\n",
        !           213:                        s->dvname, i, s->dvtname);
        !           214:                s->dvminor = symtab[s->dvtnum].symoccurs++;
        !           215:        }
        !           216: 
        !           217:        /* write count of device types */
        !           218: 
        !           219:        fprintf(confh,"\n/* Control block sizes */\n\n");
        !           220:        for (i=0 ; i<nsym ; i++)
        !           221:                if (symtab[i].symoccurs > 0) {
        !           222:                        fprintf(confh, "#define\tN%s\t%d\n",
        !           223:                                symtab[i].symname, symtab[i].symoccurs);
        !           224:                }
        !           225:        if (ndevs > 0)
        !           226:                fprintf(confh, "\n#define\tNDEVS\t%d\n\n", ndevs);
        !           227: 
        !           228:        /* empty symbol table, collect, and write names of all I/O routines */
        !           229: 
        !           230:        nsym = 0;
        !           231:        for (s=devs; s!=NIL ; s=s->dvnext) {
        !           232:                lookup(s->dvinit,strlen(s->dvinit));
        !           233:                lookup(s->dvopen,strlen(s->dvopen));
        !           234:                lookup(s->dvclose,strlen(s->dvclose));
        !           235:                lookup(s->dvread,strlen(s->dvread));
        !           236:                lookup(s->dvwrite,strlen(s->dvwrite));
        !           237:                lookup(s->dvseek,strlen(s->dvseek));
        !           238:                lookup(s->dvcntl,strlen(s->dvcntl));
        !           239:                lookup(s->dvgetc,strlen(s->dvgetc));
        !           240:                lookup(s->dvputc,strlen(s->dvputc));
        !           241:                lookup(s->dviint,strlen(s->dviint));
        !           242:                lookup(s->dvoint,strlen(s->dvoint));
        !           243:                
        !           244:        }
        !           245:        fprintf(confh,
        !           246:                "/* Declarations of I/O routines referenced */\n\n");
        !           247:        fprintf(confh, "#ifndef\tASM\n");
        !           248:        for (i=0 ; i<nsym ; i++)
        !           249:                fprintf(confh, "extern\tint\t%s();\n", symtab[i].symname);
        !           250:        fprintf(confh, "#endif\n");
        !           251: 
        !           252: 
        !           253:        /* produce devtab (giant I/O switch table) */
        !           254: 
        !           255:        fprintf(confc, "\n/* device independent I/O switch */\n\n");
        !           256:        if (ndevs > 0) {
        !           257:                fprintf(confc, "struct\tdevsw\tdevtab[NDEVS] = {\n");
        !           258:                fprintf(confc, "\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
        !           259:                        "/*  Format of entries is:",
        !           260:                        "device-number, device-name,",
        !           261:                        "init, open, close,",
        !           262:                        "read, write, seek,",
        !           263:                        "getc, putc, cntl,",
        !           264:                        "device-csr-address, input-vector, output-vector,",
        !           265:                        "iint-handler, oint-handler, control-block, minor-device,",
        !           266:                        "*/");
        !           267:        }
        !           268:        for (fcount=0,s=devs ; s!=NIL ; s=s->dvnext,fcount++) {
        !           269:                fprintf(confc, "\n/*  %s  is %s  */\n\n",s->dvname,s->dvtname);
        !           270:                fprintf(confc, "%d, \"%s\",\n", fcount, s->dvname);
        !           271:                fprintf(confc, "%s, %s, %s,\n",
        !           272:                        s->dvinit, s->dvopen, s->dvclose);
        !           273:                fprintf(confc, "%s, %s, %s,\n",
        !           274:                        s->dvread, s->dvwrite, s->dvseek);
        !           275:                fprintf(confc, "%s, %s, %s,\n",
        !           276:                        s->dvgetc, s->dvputc, s->dvcntl);
        !           277:                fprintf(confc, "0%06o, 0%03o, 0%03o,\n",
        !           278:                        s->dvcsr, s->dvivec, s->dvovec);
        !           279:                fprintf(confc, "%s, %s, NULLPTR, %d",
        !           280:                        s->dviint, s->dvoint, s->dvminor);
        !           281:                if ( s->dvnext != NIL )
        !           282:                        fprintf(confc, ",\n");
        !           283:                else
        !           284:                        fprintf(confc, "\n\t};");
        !           285:        }
        !           286:        for (i=0; i<ndevs; i++) {
        !           287:                fprintf(dispconf,"\t.globl\t_devveci%-1d\n",i);
        !           288:                fprintf(dispconf,"\t.globl\t_devveco%-1d\n",i);
        !           289:                fprintf(dispconf,"\t.align\t2\n");
        !           290:                fprintf(dispconf,"_devveci%-1d:\n",i);
        !           291:                fprintf(dispconf,"\tmtpr\t$DISABLE, $IPL\n");
        !           292:                fprintf(dispconf,"\tbsbw\tioint\n");
        !           293:                fprintf(dispconf,"\t.align\t2\n");
        !           294:                fprintf(dispconf,"_devveco%-1d:\n",i);
        !           295:                fprintf(dispconf,"\tmtpr\t$DISABLE, $IPL\n");
        !           296:                fprintf(dispconf,"\tbsbw\tioint\n\n",i);
        !           297:                fprintf(iodisp, "extern\tint\tdevveci%-1d();\n",i);
        !           298:                fprintf(iodisp, "extern\tint\tdevveco%-1d();\n",i);
        !           299:        }
        !           300: 
        !           301:        /* Copy definitions to output */
        !           302: 
        !           303:        if (brkcount == 2 && verbose)
        !           304:                printf("Copying definitions to %s...\n", CONFIGH);
        !           305:        if (brkcount == 2 )
        !           306:                while ( (c=input()) != 0)       /* lex input routine */
        !           307:                        putc(c, confh);
        !           308: 
        !           309:        /* guarantee conf.c written later than conf.c for make */
        !           310: 
        !           311:        fclose(confh);
        !           312:        fprintf(confc, "\n");
        !           313:        fclose(confc);
        !           314:        fclose(dispconf);
        !           315:        fclose(iodisp);
        !           316: 
        !           317:        /* finish up and write report for user if requested */
        !           318: 
        !           319:        if (verbose) {
        !           320:            printf("\nConfiguration complete. Number of devs=%d:\n\n",ndevs);
        !           321:            for (s=devs; s!=NIL ; s=s->dvnext)
        !           322:              printf(
        !           323:                "Device %s (on %s) csr=0%-7o, ivec=0%-3o, ovec=0%-3o, minor=%d\n",
        !           324:                s->dvname, s->dvdevice, s->dvcsr, s->dvivec, s->dvovec,
        !           325:                s->dvminor);
        !           326:        }
        !           327:        
        !           328: 
        !           329: }
        !           330: 
        !           331: 
        !           332: yyerror(s)
        !           333:        char *s;
        !           334: {
        !           335:        fprintf(stderr,"Syntax error in %s on line %d\n",
        !           336:                doing,linectr);
        !           337: }
        !           338: 
        !           339: 
        !           340: /*  lookup  --  lookup a name in the symbol table; return position */
        !           341: 
        !           342: lookup(str,len)
        !           343:        char    *str;
        !           344:        int     len;
        !           345: {
        !           346:        int     i;
        !           347:        char    *s;
        !           348: 
        !           349:        if (len >= 20) {
        !           350:                len = 19;
        !           351:                fprintf(stderr,"warning: name %s truncated\n",str);
        !           352:                }
        !           353:        s = malloc(len+1);
        !           354:        strncpy(s,str,len);
        !           355:        s[len] = '\000';
        !           356:        for (i=0 ; i<nsym ; i++)
        !           357:                if (strcmp(s,symtab[i].symname) == 0){
        !           358:                        return(i);
        !           359:                }
        !           360:        symtab[nsym].symname = s;
        !           361:        symtab[nsym].symoccurs = 0;
        !           362:        return(nsym++);
        !           363: }
        !           364: 
        !           365: atoi(str,len)
        !           366:        char *str;
        !           367:        int len;
        !           368: {
        !           369:        int i;
        !           370:        char c;
        !           371: 
        !           372:        for (i=0; len > 0 ; len--) {
        !           373:                c = *str++;
        !           374:                i = 10*i + (c - '0');
        !           375:                }
        !           376: }
        !           377: otoi(str,len)
        !           378:        char *str;
        !           379:        int len;
        !           380: {
        !           381:        int i;
        !           382:        char c;
        !           383: 
        !           384:        for (i=0; len > 0 ; len--) {
        !           385:                c = *str++;
        !           386:                if (c > '7')
        !           387:                        fprintf(stderr,"invalid octal digit on line %d\n",
        !           388:                                linectr);
        !           389:                else
        !           390:                        i = 8*i + (c - '0');
        !           391:                }
        !           392: }
        !           393: 
        !           394: /* newattr -- add a new attribute spec to current type/device description      */
        !           395: 
        !           396: newattr(tok,val)
        !           397:        int     tok;                    /* token type (attribute type)  */
        !           398:        int     val;                    /* symbol number of value       */
        !           399: {
        !           400:        char    *c;
        !           401:        dvptr   s;
        !           402: 
        !           403:        if (devs == NIL)                /* doing types                  */
        !           404:                s = currtype;
        !           405:        else
        !           406:                s = lastdv;
        !           407:        if (val>=0 && val<nsym) {
        !           408:                c = symtab[val].symname;
        !           409:                if (strlen(c) > 20 ) {
        !           410:                        fprintf(stderr,"Internal overflow\n");
        !           411:                        exit(1);
        !           412:                }
        !           413:        } else
        !           414:                c = NULL;
        !           415: 
        !           416:        switch (tok) {
        !           417: 
        !           418:        case CSR:       s->dvcsr = val;
        !           419:                        break;
        !           420:        case IVEC:      s->dvivec = val;
        !           421:                        break;
        !           422:        case OVEC:      s->dvovec = val;
        !           423:                        break;
        !           424:        case IINT:      strcpy(s->dviint,c);
        !           425:                        break;
        !           426:        case OINT:      strcpy(s->dvoint,c);
        !           427:                        break;
        !           428:        case READ:      strcpy(s->dvread,c);
        !           429:                        break;
        !           430:        case WRITE:     strcpy(s->dvwrite,c);
        !           431:                        break;
        !           432:        case GETC:      strcpy(s->dvgetc,c);
        !           433:                        break;
        !           434:        case PUTC:      strcpy(s->dvputc,c);
        !           435:                        break;
        !           436:        case OPEN:      strcpy(s->dvopen,c);
        !           437:                        break;
        !           438:        case CLOSE:     strcpy(s->dvclose,c);
        !           439:                        break;
        !           440:        case INIT:      strcpy(s->dvinit,c);
        !           441:                        break;
        !           442:        case SEEK:      strcpy(s->dvseek,c);
        !           443:                        break;
        !           444:        case CNTL:      strcpy(s->dvcntl,c);
        !           445:                        break;
        !           446:        default:        fprintf(stderr, "Internal error 1\n");
        !           447:        }
        !           448: }
        !           449: 
        !           450: /* cktname  --  check type name for duplicates */
        !           451: 
        !           452: cktname(symid)
        !           453:        int symid;
        !           454: {
        !           455:        dvptr   s;
        !           456: extern dvptr   ftypes;
        !           457:        char    *name;
        !           458: 
        !           459:        name = symtab[symid].symname;
        !           460:        for (s=ftypes; s!=NIL ; s=s->dvnext) {
        !           461:                if (s->dvtname == name) {
        !           462:                        fprintf(stderr,"Duplicate type name %s on line %d\n",
        !           463:                                name,linectr);
        !           464:                        exit(1);
        !           465:                        }
        !           466:                }
        !           467:        return(symid);
        !           468: }
        !           469: 
        !           470: /* mktype  --  make a node in the type list and initialize to defaults */
        !           471: 
        !           472: mktype(deviceid)
        !           473:        int deviceid;
        !           474: {
        !           475:        dvptr   s,p;
        !           476:        char    *tn,*dn;
        !           477: 
        !           478:        p = NIL;
        !           479:        tn = symtab[currtname].symname;
        !           480:        dn = symtab[deviceid].symname;
        !           481:        for (s = ftypes; s!=NIL ; s=s->dvnext) {
        !           482:                if (s->dvtname == tn && s->dvdevice==dn) {
        !           483:                   fprintf(stderr,
        !           484:                     "Duplicate device %s for type %s on line %d\n",
        !           485:                     dn, tn, linectr);
        !           486:                   exit(1);
        !           487:                }
        !           488:                p = s;
        !           489:        }
        !           490:        currtype = s = (dvptr) malloc( sizeof(struct dvtype));
        !           491:        if (ftypes != NIL) {
        !           492:                p->dvnext = s;
        !           493:        }
        !           494:        else {
        !           495:                ftypes = s;
        !           496:        }
        !           497:        initattr(s, currtname, deviceid);
        !           498: }
        !           499: 
        !           500: /* initialize attributes in a type declaration node to typename...     */
        !           501: 
        !           502: initattr(fstr, tnum, deviceid)
        !           503:        dvptr   fstr;
        !           504:        int     tnum;
        !           505:        int     deviceid;
        !           506: {
        !           507:        char    *typnam;
        !           508: 
        !           509:        typnam = symtab[tnum].symname;
        !           510:        fstr->dvname = NULL;
        !           511:        fstr->dvtname = typnam;
        !           512:        fstr->dvtnum = tnum;
        !           513:        fstr->dvdevice = symtab[deviceid].symname;
        !           514:        fstr->dvcsr = 0;
        !           515:        fstr->dvivec = 0;
        !           516:        fstr->dvovec = 0;
        !           517:        strcpy(fstr->dviint,typnam);
        !           518:        strcat(fstr->dviint,"iin");
        !           519:        strcpy(fstr->dvoint,typnam);
        !           520:        strcat(fstr->dvoint,"oin");
        !           521:        strcpy(fstr->dvinit,typnam);
        !           522:        strcat(fstr->dvinit,"init");
        !           523:        strcpy(fstr->dvopen,typnam);
        !           524:        strcat(fstr->dvopen,"open");
        !           525:        strcpy(fstr->dvclose,typnam);
        !           526:        strcat(fstr->dvclose,"close");
        !           527:        strcpy(fstr->dvread,typnam);
        !           528:        strcat(fstr->dvread,"read");
        !           529:        strcpy(fstr->dvwrite,typnam);
        !           530:        strcat(fstr->dvwrite,"write");
        !           531:        strcpy(fstr->dvcntl,typnam);
        !           532:        strcat(fstr->dvcntl,"control");
        !           533:        strcpy(fstr->dvseek,typnam);
        !           534:        strcat(fstr->dvseek,"seek");
        !           535:        strcpy(fstr->dvgetc,typnam);
        !           536:        strcat(fstr->dvgetc,"getc");
        !           537:        strcpy(fstr->dvputc,typnam);
        !           538:        strcat(fstr->dvputc,"putc");
        !           539:        fstr->dvminor = 0;
        !           540: }
        !           541: 
        !           542: /* mkdev  --  make a node on the device list */
        !           543: 
        !           544: mkdev(nameid, typid, deviceid)
        !           545:        int     nameid, typid, deviceid;
        !           546: {
        !           547:        dvptr   s;
        !           548:        char    *devn,*tn,*dn;
        !           549:        int     found;
        !           550: 
        !           551:        s = (dvptr) malloc(sizeof(struct dvtype));
        !           552:        s->dvnext = NIL;
        !           553:        if (devs == NIL) {
        !           554:                devs = s;
        !           555:                lastdv = s;
        !           556:        } else {
        !           557:                lastdv->dvnext = s;
        !           558:                lastdv = s;
        !           559:        }
        !           560:        ndevs++;
        !           561:        tn = symtab[typid].symname;
        !           562:        devn = symtab[nameid].symname;
        !           563:        if (deviceid >= 0)
        !           564:                dn = symtab[deviceid].symname;
        !           565:        else
        !           566:                dn = NULL;
        !           567:        found = 0;
        !           568:        for (s=ftypes ; s != NULL ; s=s->dvnext)
        !           569:                if (s->dvtname == tn && (dn==NULL || s->dvdevice==dn)) {
        !           570:                        strdup(lastdv,s,sizeof(struct dvtype));
        !           571:                        found=1;
        !           572:                        break;
        !           573:                }
        !           574:        if (found==0) {
        !           575:                fprintf(stderr,
        !           576:                  "Bad type or device name in declaration of %s on line %d\n",
        !           577:                  devn, linectr);
        !           578:                exit(1);
        !           579:        }
        !           580:        lastdv->dvnext = NIL;
        !           581:        lastdv->dvname = devn;
        !           582: }
        !           583: 
        !           584: 
        !           585: /* chdname  -- check for duplicate device name */
        !           586: 
        !           587: ckdname(devid)
        !           588:        int devid;
        !           589: {
        !           590:        dvptr   s;
        !           591: extern dvptr   devs;
        !           592:        char    *name;
        !           593: 
        !           594:        name = symtab[devid].symname;
        !           595:        for (s=devs; s!=NIL ; s=s->dvnext) {
        !           596:                if (s->dvname == name) {
        !           597:                        fprintf(stderr,"Duplicate device name %s on line %d\n",
        !           598:                                name,linectr);
        !           599:                        exit(1);
        !           600:                        }
        !           601:                }
        !           602:        return(devid);
        !           603: }
        !           604: 
        !           605: strdup(tostr,fromstr,len)
        !           606:        char    *tostr, *fromstr;
        !           607:        int     len;
        !           608: {
        !           609:        for( ; len > 0 ; len--)
        !           610:                *tostr++ = *fromstr++;
        !           611: }
        !           612: short yyexca[] ={
        !           613: -1, 1,
        !           614:        0, -1,
        !           615:        -2, 0,
        !           616:        };
        !           617: # define YYNPROD 36
        !           618: # define YYLAST 79
        !           619: short yyact[]={
        !           620: 
        !           621:   24,  25,  26,  27,  28,  31,  29,  30,  34,  35,
        !           622:   36,  37,  57,  19,  32,  33,  16,   5,   9,  17,
        !           623:    8,   9,  42,  41,  15,  13,  18,  56,  12,  11,
        !           624:   10,  23,  14,  40,   7,   6,   3,  22,   4,  20,
        !           625:   38,   2,  21,   1,   0,   0,   0,  39,  45,  46,
        !           626:   47,  48,  49,  50,  51,  52,  53,  54,  55,  43,
        !           627:   44,   0,   0,   0,   0,   0,   0,   0,   0,   0,
        !           628:    0,   0,   0,   0,   0,   0,   0,   0,  58 };
        !           629: short yypact[]={
        !           630: 
        !           631: -1000,-1000,-1000,-240,-243,-1000,-1000,-259,-239,-1000,
        !           632: -1000,-1000,-261,-1000,-259,-1000,-243,-1000,-262,-243,
        !           633: -1000,-262,-1000,-1000,-237,-237,-237,-243,-243,-243,
        !           634: -243,-243,-243,-243,-243,-243,-243,-243,-263,-262,
        !           635: -1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,
        !           636: -1000,-1000,-1000,-1000,-1000,-1000,-1000,-243,-1000 };
        !           637: short yypgo[]={
        !           638: 
        !           639:    0,  43,  41,  38,  36,  35,  34,  32,  24,  26,
        !           640:   20,  31,  33,  30,  29,  28,  27 };
        !           641: short yyr1[]={
        !           642: 
        !           643:    0,   1,   2,   4,   4,   5,   7,   7,   8,   6,
        !           644:   10,   9,   9,  11,  11,  11,  11,  11,  11,  11,
        !           645:   11,  11,  11,  11,  11,  11,  11,  12,  12,   3,
        !           646:    3,  13,  14,  15,  16,  16 };
        !           647: short yyr2[]={
        !           648: 
        !           649:    0,   2,   2,   0,   2,   2,   2,   3,   2,   2,
        !           650:    1,   0,   2,   2,   2,   2,   2,   2,   2,   2,
        !           651:    2,   2,   2,   2,   2,   2,   2,   1,   1,   0,
        !           652:    2,   2,   4,   1,   0,   2 };
        !           653: short yychk[]={
        !           654: 
        !           655: -1000,  -1,  -2,  -4,  -3, 257,  -5,  -6, -10, 261,
        !           656:  -13, -14, -15, -10,  -7,  -8, 275, 258,  -9, 274,
        !           657:   -8,  -9, -10, -11, 262, 263, 264, 265, 266, 268,
        !           658:  269, 267, 276, 277, 270, 271, 272, 273, -10,  -9,
        !           659:  -12, 260, 259, -12, -12, -10, -10, -10, -10, -10,
        !           660:  -10, -10, -10, -10, -10, -10, -16, 275, -10 };
        !           661: short yydef[]={
        !           662: 
        !           663:    3,  -2,  29,   0,   1,   2,   4,   0,   0,  10,
        !           664:   30,  11,   0,  33,   5,  11,   0,   9,  31,   0,
        !           665:   11,   6,   8,  12,   0,   0,   0,   0,   0,   0,
        !           666:    0,   0,   0,   0,   0,   0,   0,   0,  34,   7,
        !           667:   13,  27,  28,  14,  15,  16,  17,  18,  19,  20,
        !           668:   21,  22,  23,  24,  25,  26,  32,   0,  35 };
        !           669: #ifndef lint
        !           670: static char yaccpar_sccsid[] = "@(#)yaccpar    4.1     (Berkeley)      2/11/83";
        !           671: #endif not lint
        !           672: 
        !           673: #
        !           674: # define YYFLAG -1000
        !           675: # define YYERROR goto yyerrlab
        !           676: # define YYACCEPT return(0)
        !           677: # define YYABORT return(1)
        !           678: 
        !           679: /*     parser for yacc output  */
        !           680: 
        !           681: #ifdef YYDEBUG
        !           682: int yydebug = 0; /* 1 for debugging */
        !           683: #endif
        !           684: YYSTYPE yyv[YYMAXDEPTH]; /* where the values are stored */
        !           685: int yychar = -1; /* current input token number */
        !           686: int yynerrs = 0;  /* number of errors */
        !           687: short yyerrflag = 0;  /* error recovery flag */
        !           688: 
        !           689: yyparse() {
        !           690: 
        !           691:        short yys[YYMAXDEPTH];
        !           692:        short yyj, yym;
        !           693:        register YYSTYPE *yypvt;
        !           694:        register short yystate, *yyps, yyn;
        !           695:        register YYSTYPE *yypv;
        !           696:        register short *yyxi;
        !           697: 
        !           698:        yystate = 0;
        !           699:        yychar = -1;
        !           700:        yynerrs = 0;
        !           701:        yyerrflag = 0;
        !           702:        yyps= &yys[-1];
        !           703:        yypv= &yyv[-1];
        !           704: 
        !           705:  yystack:    /* put a state and value onto the stack */
        !           706: 
        !           707: #ifdef YYDEBUG
        !           708:        if( yydebug  ) printf( "state %d, char 0%o\n", yystate, yychar );
        !           709: #endif
        !           710:                if( ++yyps> &yys[YYMAXDEPTH] ) { yyerror( "yacc stack overflow" ); return(1); }
        !           711:                *yyps = yystate;
        !           712:                ++yypv;
        !           713:                *yypv = yyval;
        !           714: 
        !           715:  yynewstate:
        !           716: 
        !           717:        yyn = yypact[yystate];
        !           718: 
        !           719:        if( yyn<= YYFLAG ) goto yydefault; /* simple state */
        !           720: 
        !           721:        if( yychar<0 ) if( (yychar=yylex())<0 ) yychar=0;
        !           722:        if( (yyn += yychar)<0 || yyn >= YYLAST ) goto yydefault;
        !           723: 
        !           724:        if( yychk[ yyn=yyact[ yyn ] ] == yychar ){ /* valid shift */
        !           725:                yychar = -1;
        !           726:                yyval = yylval;
        !           727:                yystate = yyn;
        !           728:                if( yyerrflag > 0 ) --yyerrflag;
        !           729:                goto yystack;
        !           730:                }
        !           731: 
        !           732:  yydefault:
        !           733:        /* default state action */
        !           734: 
        !           735:        if( (yyn=yydef[yystate]) == -2 ) {
        !           736:                if( yychar<0 ) if( (yychar=yylex())<0 ) yychar = 0;
        !           737:                /* look through exception table */
        !           738: 
        !           739:                for( yyxi=yyexca; (*yyxi!= (-1)) || (yyxi[1]!=yystate) ; yyxi += 2 ) ; /* VOID */
        !           740: 
        !           741:                while( *(yyxi+=2) >= 0 ){
        !           742:                        if( *yyxi == yychar ) break;
        !           743:                        }
        !           744:                if( (yyn = yyxi[1]) < 0 ) return(0);   /* accept */
        !           745:                }
        !           746: 
        !           747:        if( yyn == 0 ){ /* error */
        !           748:                /* error ... attempt to resume parsing */
        !           749: 
        !           750:                switch( yyerrflag ){
        !           751: 
        !           752:                case 0:   /* brand new error */
        !           753: 
        !           754:                        yyerror( "syntax error" );
        !           755:                yyerrlab:
        !           756:                        ++yynerrs;
        !           757: 
        !           758:                case 1:
        !           759:                case 2: /* incompletely recovered error ... try again */
        !           760: 
        !           761:                        yyerrflag = 3;
        !           762: 
        !           763:                        /* find a state where "error" is a legal shift action */
        !           764: 
        !           765:                        while ( yyps >= yys ) {
        !           766:                           yyn = yypact[*yyps] + YYERRCODE;
        !           767:                           if( yyn>= 0 && yyn < YYLAST && yychk[yyact[yyn]] == YYERRCODE ){
        !           768:                              yystate = yyact[yyn];  /* simulate a shift of "error" */
        !           769:                              goto yystack;
        !           770:                              }
        !           771:                           yyn = yypact[*yyps];
        !           772: 
        !           773:                           /* the current yyps has no shift onn "error", pop stack */
        !           774: 
        !           775: #ifdef YYDEBUG
        !           776:                           if( yydebug ) printf( "error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1] );
        !           777: #endif
        !           778:                           --yyps;
        !           779:                           --yypv;
        !           780:                           }
        !           781: 
        !           782:                        /* there is no state on the stack with an error shift ... abort */
        !           783: 
        !           784:        yyabort:
        !           785:                        return(1);
        !           786: 
        !           787: 
        !           788:                case 3:  /* no shift yet; clobber input char */
        !           789: 
        !           790: #ifdef YYDEBUG
        !           791:                        if( yydebug ) printf( "error recovery discards char %d\n", yychar );
        !           792: #endif
        !           793: 
        !           794:                        if( yychar == 0 ) goto yyabort; /* don't discard EOF, quit */
        !           795:                        yychar = -1;
        !           796:                        goto yynewstate;   /* try again in the same state */
        !           797: 
        !           798:                        }
        !           799: 
        !           800:                }
        !           801: 
        !           802:        /* reduction by production yyn */
        !           803: 
        !           804: #ifdef YYDEBUG
        !           805:                if( yydebug ) printf("reduce %d\n",yyn);
        !           806: #endif
        !           807:                yyps -= yyr2[yyn];
        !           808:                yypvt = yypv;
        !           809:                yypv -= yyr2[yyn];
        !           810:                yyval = yypv[1];
        !           811:                yym=yyn;
        !           812:                        /* consult goto table to find next state */
        !           813:                yyn = yyr1[yyn];
        !           814:                yyj = yypgo[yyn] + *yyps + 1;
        !           815:                if( yyj>=YYLAST || yychk[ yystate = yyact[yyj] ] != -yyn ) yystate = yyact[yypgo[yyn]];
        !           816:                switch(yym){
        !           817:                        
        !           818: case 2:
        !           819: # line 97 "config.y"
        !           820: {doing = "device definitions";} break;
        !           821: case 8:
        !           822: # line 108 "config.y"
        !           823: {mktype(yypvt[-0]);} break;
        !           824: case 9:
        !           825: # line 111 "config.y"
        !           826: {yyval = currtname = cktname(yypvt[-1]);} break;
        !           827: case 10:
        !           828: # line 114 "config.y"
        !           829: {yyval = currname =
        !           830:                                         lookup(yytext,yyleng);
        !           831:                                        } break;
        !           832: case 13:
        !           833: # line 122 "config.y"
        !           834: {newattr(CSR,yypvt[-0]);} break;
        !           835: case 14:
        !           836: # line 124 "config.y"
        !           837: {newattr(IVEC,yypvt[-0]);} break;
        !           838: case 15:
        !           839: # line 126 "config.y"
        !           840: {newattr(OVEC,yypvt[-0]);} break;
        !           841: case 16:
        !           842: # line 128 "config.y"
        !           843: {newattr(IINT,yypvt[-0]);} break;
        !           844: case 17:
        !           845: # line 130 "config.y"
        !           846: {newattr(OINT,yypvt[-0]);} break;
        !           847: case 18:
        !           848: # line 132 "config.y"
        !           849: {newattr(OPEN,yypvt[-0]);} break;
        !           850: case 19:
        !           851: # line 134 "config.y"
        !           852: {newattr(CLOSE,yypvt[-0]);} break;
        !           853: case 20:
        !           854: # line 136 "config.y"
        !           855: {newattr(INIT,yypvt[-0]);} break;
        !           856: case 21:
        !           857: # line 138 "config.y"
        !           858: {newattr(GETC,yypvt[-0]);} break;
        !           859: case 22:
        !           860: # line 140 "config.y"
        !           861: {newattr(PUTC,yypvt[-0]);} break;
        !           862: case 23:
        !           863: # line 142 "config.y"
        !           864: {newattr(READ,yypvt[-0]);} break;
        !           865: case 24:
        !           866: # line 144 "config.y"
        !           867: {newattr(WRITE,yypvt[-0]);} break;
        !           868: case 25:
        !           869: # line 146 "config.y"
        !           870: {newattr(SEEK,yypvt[-0]);} break;
        !           871: case 26:
        !           872: # line 148 "config.y"
        !           873: {newattr(CNTL,yypvt[-0]);} break;
        !           874: case 27:
        !           875: # line 156 "config.y"
        !           876: {yyval = otoi(yytext,yyleng);} break;
        !           877: case 28:
        !           878: # line 158 "config.y"
        !           879: {yyval = otoi(yytext,yyleng);} break;
        !           880: case 32:
        !           881: # line 166 "config.y"
        !           882: {mkdev(yypvt[-3],yypvt[-1],yypvt[-0]);} break;
        !           883: case 33:
        !           884: # line 169 "config.y"
        !           885: {yyval = currdname = ckdname(yypvt[-0]);} break;
        !           886: case 34:
        !           887: # line 172 "config.y"
        !           888: {yyval = 0;} break;
        !           889: case 35:
        !           890: # line 174 "config.y"
        !           891: {yyval = yypvt[-0];} break;
        !           892:                }
        !           893:                goto yystack;  /* stack new state and value */
        !           894: 
        !           895:        }

unix.superglobalmegacorp.com

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