Annotation of researchv10no/cmd/ccom/common/common1.c, revision 1.1

1.1     ! root        1: /* @(#) comm1.c: 1.1 12/22/83                          */
        !             2: 
        !             3: # include "mfile1.h"
        !             4: 
        !             5: # ifndef EXIT
        !             6: # define EXIT exit
        !             7: # endif
        !             8: 
        !             9: int nerrors = 0;  /* number of errors */
        !            10: int nowarn = 0;  /* suppress warnings */
        !            11: 
        !            12: NODE *lastfree;  /* pointer to last free node; (for allocator) */
        !            13: 
        !            14: # ifndef MYWHERE
        !            15: where(c)
        !            16: {
        !            17:         /* print location of error. c is either 'u', 'c', or 'w' */
        !            18:        fprintf( stderr, "%s:%d:", ftitle, lineno );
        !            19: }
        !            20: # endif
        !            21: 
        !            22: /* VARARGS1 */
        !            23: uerror( s, a, b, c, d, e, f, g )
        !            24: char *s; 
        !            25: {
        !            26:        /* nonfatal error message 
        !            27:        ** the routine where is different for pass 1 and pass 2;
        !            28:        ** it tells where the error took place 
        !            29:        */
        !            30:        ++nerrors;
        !            31:        where('u');
        !            32:        fprintf( stderr, s, a, b, c, d, e, f, g );
        !            33:        fprintf( stderr, "\n" );
        !            34:        if( nerrors > 30 ) cerror( "too many errors");
        !            35:        fflush(stderr);
        !            36:        nowarn = 1;
        !            37: }
        !            38: 
        !            39: /* VARARGS1 */
        !            40: cerror(s, a, b, c, d)
        !            41: char *s; 
        !            42: {
        !            43:         /* compiler error: die */
        !            44:        where('c');
        !            45:        if( nerrors && nerrors <= 30 )
        !            46:        {
        !            47:                /* give the compiler the benefit of the doubt */
        !            48:                fprintf( stderr,
        !            49:                "cannot recover from earlier errors: goodbye!\n" );
        !            50:                fflush(stderr);
        !            51:        }
        !            52:        else 
        !            53:        {
        !            54:                fprintf( stderr, "compiler error: " );
        !            55:                fprintf( stderr, s, a, b, c, d);
        !            56:                fprintf( stderr, "\n" );
        !            57:                fflush(stderr);
        !            58:                fflush( stdout );
        !            59:        }
        !            60:        EXIT(1);
        !            61: }
        !            62: 
        !            63: /* VARARGS1 */
        !            64: werror( s, a, b )
        !            65: char *s; 
        !            66: {
        !            67:        /* warning */
        !            68:        if (nowarn) return;
        !            69:        where('w');
        !            70:        fprintf( stderr, "warning: " );
        !            71:        fprintf( stderr, s, a, b );
        !            72:        fprintf( stderr, "\n" );
        !            73:        fflush(stderr);
        !            74: }
        !            75: 
        !            76: tinit()
        !            77: {
        !            78:         /* initialize expression tree search */
        !            79:        register NODE *p;
        !            80: 
        !            81:        for (p=node; p < &node[TREESZ]; ++p ) {
        !            82:                p->in.op = FREE;
        !            83:        }
        !            84:        lastfree = node;
        !            85: }
        !            86: 
        !            87: NODE *
        !            88: talloc()
        !            89: {
        !            90:        register NODE *p, *q;
        !            91: 
        !            92:        p = lastfree;
        !            93:        do {
        !            94:                if (p < &node[TREESZ-1])
        !            95:                        q = p+1;
        !            96:                else
        !            97:                        q = node;
        !            98:                if (p->in.op == FREE) {
        !            99:                        lastfree = q;
        !           100:                        return p;
        !           101:                }
        !           102:        } while ((p = q) != lastfree);
        !           103:        cerror("out of tree space; simplify expression");
        !           104: }
        !           105: 
        !           106: tcheck()
        !           107: {
        !           108:         /* ensure that all nodes have been freed */
        !           109:        register NODE *q; register n;
        !           110: 
        !           111:        if (nerrors == 0) {
        !           112:                for (n=0, q=node; q < &node[TREESZ]; ++q)
        !           113:                        if (q->in.op != FREE)
        !           114:                                ++n;
        !           115:                if (n)
        !           116:                        cerror("wasted space: %d nodes", n);
        !           117:        } else
        !           118:                tinit();
        !           119:        freestr();
        !           120: }
        !           121: 
        !           122: tfree(p)
        !           123: register NODE *p; 
        !           124: {
        !           125:        /* allow tree fragments to be freed, also */
        !           126:        if (p == 0) return;
        !           127:        switch (optype(p->tn.op)) {
        !           128:        case BITYPE:
        !           129:                tfree (p->in.right);
        !           130:        case UTYPE:
        !           131:                tfree (p->in.left);
        !           132:        }
        !           133:        p->in.op = FREE;
        !           134: }
        !           135: 
        !           136: 
        !           137: NODE node[TREESZ];
        !           138: 
        !           139: char   ftitle[100] = "\"\"";   /* title of the file */
        !           140: extern int     lineno;         /* line number of the input file */
        !           141: 
        !           142: 
        !           143: #define NTSTRBUF       60
        !           144: #define TSTRSZ         2048
        !           145: char   itstrbuf[TSTRSZ];
        !           146: char   *tstrbuf[NTSTRBUF] = { itstrbuf };
        !           147: char   **curtstr = tstrbuf;
        !           148: int    tstrused;
        !           149: 
        !           150: char *
        !           151: tstr( cp )                     /* place copy of string into temp storage */
        !           152:        register char *cp;      /* strings longer than TSTRSZ will break tstr */
        !           153: {
        !           154:        register int i = strlen( cp );
        !           155:        register char *dp;
        !           156:        extern char * malloc();
        !           157:        extern char * strcpy();
        !           158: 
        !           159:        if ( tstrused + i >= TSTRSZ )
        !           160:        {
        !           161:                if ( ++curtstr >= &tstrbuf[NTSTRBUF] )
        !           162:                        cerror( "out of temporary string space" );
        !           163:                tstrused = 0;
        !           164:                if ( *curtstr == 0 )
        !           165:                {
        !           166:                        if ( ( dp = (char *) malloc( TSTRSZ ) ) == 0 )
        !           167:                                cerror( "out of memory [tstr()]" );
        !           168:                        *curtstr = dp;
        !           169:                }
        !           170:        }
        !           171:        strcpy( dp = *curtstr + tstrused, cp );
        !           172:        tstrused += i + 1;
        !           173:        return ( dp );
        !           174: }
        !           175: #include "dope.h"
        !           176: 
        !           177: mkdope()
        !           178: {
        !           179:        register struct dopest *q;
        !           180: 
        !           181:        for( q = indope; q->dopeop >= 0; ++q )
        !           182:        {
        !           183:                dope[q->dopeop] = q->dopeval;
        !           184:                opst[q->dopeop] = q->opst;
        !           185:        }
        !           186: }

unix.superglobalmegacorp.com

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