Annotation of researchv9/jerq/sgs/comp/common, revision 1.1

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

unix.superglobalmegacorp.com

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