Annotation of researchv9/cmd/lex/lmain.c, revision 1.1.1.1

1.1       root        1: # include "ldefs.c"
                      2: # include "once.c"
                      3: 
                      4:        /* lex [-[drcyvntf]] [file] ... [file] */
                      5: 
                      6:        /* Copyright 1976, Bell Telephone Laboratories, Inc.,
                      7:            written by Eric Schmidt, August 27, 1976   */
                      8: 
                      9: main(argc,argv)
                     10:   int argc;
                     11:   char **argv; {
                     12:        register int i;
                     13: # ifdef DEBUG
                     14:        signal(10,buserr);
                     15:        signal(11,segviol);
                     16: # endif
                     17:        while (argc > 1 && argv[1][0] == '-' ){
                     18:                i = 0;
                     19:                while(argv[1][++i]){
                     20:                        switch (argv[1][i]){
                     21: # ifdef DEBUG
                     22:                                case 'd': debug++; break;
                     23:                                case 'y': yydebug = TRUE; break;
                     24: # endif
                     25:                                case 'r': case 'R':
                     26:                                        warning("Ratfor not currently supported with lex");
                     27:                                        ratfor=TRUE; break;
                     28:                                case 'c': case 'C':
                     29:                                        ratfor=FALSE; break;
                     30:                                case 't': case 'T':
                     31:                                        fout = stdout;
                     32:                                        errorf = stderr;
                     33:                                        break;
                     34:                                case 'v': case 'V':
                     35:                                        report = 1;
                     36:                                        break;
                     37:                                case 'n': case 'N':
                     38:                                        report = 0;
                     39:                                        break;
                     40:                                default:
                     41:                                        warning("Unknown option %c",argv[1][i]);
                     42:                                }
                     43:                        }
                     44:                argc--;
                     45:                argv++;
                     46:                }
                     47:        sargc = argc;
                     48:        sargv = argv;
                     49:        if (argc > 1){
                     50:                fin = fopen(argv[++fptr], "r");         /* open argv[1] */
                     51:                sargc--;
                     52:                sargv++;
                     53:                }
                     54:        else fin = stdin;
                     55:        if(fin == NULL)
                     56:                error ("Can't read input file %s",argc>1?argv[1]:"standard input");
                     57:        gch();
                     58:                /* may be gotten: def, subs, sname, schar, ccl, dchar */
                     59:        get1core();
                     60:                /* may be gotten: name, left, right, nullstr, parent */
                     61:        scopy("INITIAL",sp);
                     62:        sname[0] = sp;
                     63:        sp += slength("INITIAL") + 1;
                     64:        sname[1] = 0;
                     65:        if(yyparse(0)) exit(1); /* error return code */
                     66:                /* may be disposed of: def, subs, dchar */
                     67:        free1core();
                     68:                /* may be gotten: tmpstat, foll, positions, gotof, nexts, nchar, state, atable, sfall, cpackflg */
                     69:        get2core();
                     70:        ptail();
                     71:        mkmatch();
                     72: # ifdef DEBUG
                     73:        if(debug) pccl();
                     74: # endif
                     75:        sect  = ENDSECTION;
                     76:        if(tptr>0)cfoll(tptr-1);
                     77: # ifdef DEBUG
                     78:        if(debug)pfoll();
                     79: # endif
                     80:        cgoto();
                     81: # ifdef DEBUG
                     82:        if(debug){
                     83:                printf("Print %d states:\n",stnum+1);
                     84:                for(i=0;i<=stnum;i++)stprt(i);
                     85:                }
                     86: # endif
                     87:                /* may be disposed of: positions, tmpstat, foll, state, name, left, right, parent, ccl, schar, sname */
                     88:                /* may be gotten: verify, advance, stoff */
                     89:        free2core();
                     90:        get3core();
                     91:        layout();
                     92:                /* may be disposed of: verify, advance, stoff, nexts, nchar,
                     93:                        gotof, atable, ccpackflg, sfall */
                     94: # ifdef DEBUG
                     95:        free3core();
                     96: # endif
                     97:        if (ZCH>NCH) cname="/usr/lib/lex/ebcform";
                     98:        fother = fopen(ratfor?ratname:cname,"r");
                     99:        if(fother == NULL)
                    100:                error("Lex driver missing, file %s",ratfor?ratname:cname);
                    101:        while ( (i=getc(fother)) != EOF)
                    102:                putc(i,fout);
                    103: 
                    104:        fclose(fother);
                    105:        fclose(fout);
                    106:        if(
                    107: # ifdef DEBUG
                    108:                debug   ||
                    109: # endif
                    110:                        report == 1)statistics();
                    111:        fclose(stdout);
                    112:        fclose(stderr);
                    113:        exit(0);        /* success return code */
                    114:        }
                    115: get1core(){
                    116:        register int i, val;
                    117:        register char *p;
                    118: ccptr =        ccl = myalloc(CCLSIZE,sizeof(*ccl));
                    119: pcptr = pchar = myalloc(pchlen, sizeof(*pchar));
                    120:        def = (char **)myalloc(DEFSIZE,sizeof(*def));
                    121:        subs = (char **)myalloc(DEFSIZE,sizeof(*subs));
                    122:        dp = dchar = myalloc(DEFCHAR,sizeof(*dchar));
                    123:        sname = (char **)myalloc(STARTSIZE,sizeof(*sname));
                    124: sp =   schar = myalloc(STARTCHAR,sizeof(*schar));
                    125:        if(ccl == 0 || def == 0 || subs == 0 || dchar == 0 || sname == 0 || schar == 0)
                    126:                error("Too little core to begin");
                    127:        }
                    128: free1core(){
                    129:        cfree((char *)def,DEFSIZE,sizeof(*def));
                    130:        cfree((char *)subs,DEFSIZE,sizeof(*subs));
                    131:        cfree((char *)dchar,DEFCHAR,sizeof(*dchar));
                    132:        }
                    133: get2core(){
                    134:        register int i, val;
                    135:        register char *p;
                    136:        gotof = (int *)myalloc(nstates,sizeof(*gotof));
                    137:        nexts = (int *)myalloc(ntrans,sizeof(*nexts));
                    138:        nchar = myalloc(ntrans,sizeof(*nchar));
                    139:        state = (int **)myalloc(nstates,sizeof(*state));
                    140:        atable = (int *)myalloc(nstates,sizeof(*atable));
                    141:        sfall = (int *)myalloc(nstates,sizeof(*sfall));
                    142:        cpackflg = myalloc(nstates,sizeof(*cpackflg));
                    143:        tmpstat = myalloc(tptr+1,sizeof(*tmpstat));
                    144:        foll = (int **)myalloc(tptr+1,sizeof(*foll));
                    145:        nxtpos = positions = (int *)myalloc(maxpos,sizeof(*positions));
                    146:        if(tmpstat == 0 || foll == 0 || positions == 0 ||
                    147:                gotof == 0 || nexts == 0 || nchar == 0 || state == 0 || atable == 0 || sfall == 0 || cpackflg == 0 )
                    148:                error("Too little core for state generation");
                    149:        for(i=0;i<=tptr;i++)foll[i] = 0;
                    150:        }
                    151: free2core(){
                    152:        cfree((char *)positions,maxpos,sizeof(*positions));
                    153:        cfree((char *)tmpstat,tptr+1,sizeof(*tmpstat));
                    154:        cfree((char *)foll,tptr+1,sizeof(*foll));
                    155:        cfree((char *)name,treesize,sizeof(*name));
                    156:        cfree((char *)left,treesize,sizeof(*left));
                    157:        cfree((char *)right,treesize,sizeof(*right));
                    158:        cfree((char *)parent,treesize,sizeof(*parent));
                    159:        cfree((char *)nullstr,treesize,sizeof(*nullstr));
                    160:        cfree((char *)state,nstates,sizeof(*state));
                    161:        cfree((char *)sname,STARTSIZE,sizeof(*sname));
                    162:        cfree((char *)schar,STARTCHAR,sizeof(*schar));
                    163:        cfree((char *)ccl,CCLSIZE,sizeof(*ccl));
                    164:        }
                    165: get3core(){
                    166:        register int i, val;
                    167:        register char *p;
                    168:        verify = (int *)myalloc(outsize,sizeof(*verify));
                    169:        advance = (int *)myalloc(outsize,sizeof(*advance));
                    170:        stoff = (int *)myalloc(stnum+2,sizeof(*stoff));
                    171:        if(verify == 0 || advance == 0 || stoff == 0)
                    172:                error("Too little core for final packing");
                    173:        }
                    174: # ifdef DEBUG
                    175: free3core(){
                    176:        cfree((char *)advance,outsize,sizeof(*advance));
                    177:        cfree((char *)verify,outsize,sizeof(*verify));
                    178:        cfree((char *)stoff,stnum+1,sizeof(*stoff));
                    179:        cfree((char *)gotof,nstates,sizeof(*gotof));
                    180:        cfree((char *)nexts,ntrans,sizeof(*nexts));
                    181:        cfree((char *)nchar,ntrans,sizeof(*nchar));
                    182:        cfree((char *)atable,nstates,sizeof(*atable));
                    183:        cfree((char *)sfall,nstates,sizeof(*sfall));
                    184:        cfree((char *)cpackflg,nstates,sizeof(*cpackflg));
                    185:        }
                    186: # endif
                    187: char *myalloc(a,b)
                    188:   int a,b; {
                    189:        register int i;
                    190:        i = (int)calloc(a, b);
                    191:        if(i==0)
                    192:                warning("OOPS - calloc returns a 0");
                    193:        else if(i == -1){
                    194: # ifdef DEBUG
                    195:                warning("calloc returns a -1");
                    196: # endif
                    197:                return(0);
                    198:                }
                    199:        return((char *)i);
                    200:        }
                    201: # ifdef DEBUG
                    202: buserr(){
                    203:        fflush(errorf);
                    204:        fflush(fout);
                    205:        fflush(stdout);
                    206:        fprintf(errorf,"Bus error\n");
                    207:        if(report == 1)statistics();
                    208:        fflush(errorf);
                    209:        }
                    210: segviol(){
                    211:        fflush(errorf);
                    212:        fflush(fout);
                    213:        fflush(stdout);
                    214:        fprintf(errorf,"Segmentation violation\n");
                    215:        if(report == 1)statistics();
                    216:        fflush(errorf);
                    217:        }
                    218: # endif
                    219: 
                    220: yyerror(s)
                    221: char *s;
                    222: {
                    223:        fprintf(stderr, "line %d: %s\n", yyline, s);
                    224: }

unix.superglobalmegacorp.com

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