Annotation of coherent/b/bin/c/common/diag.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * h/diag.c
                      3:  *
                      4:  * These routines write diagnostics for all the compiler phases.
                      5:  * They are do-it-yourself routines because the "printf"
                      6:  * in the VAX-11 C library lacks the undocumented "%r" format.
                      7:  * The routines defined below are:
                      8:  *     cbotch  for internal compiler errors
                      9:  *     cerror  for user program errors (e.g. syntax errors)
                     10:  *     cfatal  for instantly fatal errors (e.g. fixed limits)
                     11:  *     cnomem  for out of memory errors
                     12:  *     cstrict for strict warning messages
                     13:  *     cwarn   for warning messages
                     14:  * cbotch, cfatal and cnomem errors are all instantly fatal.
                     15:  * cerror errors allow the current pass to continue but bump the error count
                     16:  * so that compilation terminates after the current pass.
                     17:  * cstrict and cwarn are warning messages only, with no other effect.
                     18:  */
                     19: 
                     20: #include       <stdio.h>
                     21: #include       <setjmp.h>
                     22: #ifdef vax
                     23: #include       "INC$LIB:mch.h"
                     24: #include       "INC$LIB:host.h"
                     25: #include       "INC$LIB:stream.h"
                     26: #include       "INC$LIB:var.h"
                     27: #else
                     28: #include       "mch.h"
                     29: #include       "host.h"
                     30: #include       "stream.h"
                     31: #include       "var.h"
                     32: #endif
                     33: 
                     34: int    nerr    = 0;                    /* Error counter */
                     35: char   *passname = NULL;               /* Pass identifier string */
                     36: 
                     37: extern int     line;                   /* Line number */
                     38: extern char    file[];                 /* File name */
                     39: extern FILE    *ifp;                   /* Input stream */
                     40: extern long    ftell();                /* Standard I/O routine */
                     41: 
                     42: #if    OVERLAID
                     43: extern jmp_buf death;                  /* Fatal errors */
                     44: #endif
                     45: 
                     46: /*
                     47:  * Put out error.
                     48:  * Bump the error count.
                     49:  */
                     50: cerror(fp, args)
                     51: char   *fp;
                     52: {
                     53:        cmsg(fp, &args, NULL, 0);
                     54:        ++nerr;
                     55: }
                     56: 
                     57: /*
                     58:  * Put out warning.
                     59:  */
                     60: cwarn(fp, args)
                     61: char   *fp;
                     62: {
                     63:        if (notvariant(VNOWARN))
                     64:                cmsg(fp, &args, "Warning", 0);
                     65: }
                     66: 
                     67: /*
                     68:  * Put out strict check.
                     69:  */
                     70: cstrict(fp, args)
                     71: char   *fp;
                     72: {
                     73:        if (notvariant(VNOWARN))
                     74:                cmsg(fp, &args, "Strict", 0);
                     75: }
                     76: 
                     77: /*
                     78:  * Put out fatal message and die.
                     79:  */
                     80: cfatal(fp, args)
                     81: char   *fp;
                     82: {
                     83:        cmsg(fp, &args, "Fatal error", 1);
                     84: #if    !OVERLAID
                     85:        exit(ABORT);
                     86: #else
                     87:        longjmp(death, 1);
                     88: #endif
                     89: }
                     90: 
                     91: #if    TINY
                     92: /*
                     93:  * Sanitize a botch message for external consumption.
                     94:  */
                     95: char *botch_message(msg) char *msg;
                     96: {
                     97:        static char newmsg[32];
                     98:        static char digit[] = "0123456789ABCDEF";
                     99:        char *p, *q, c, sw;
                    100:        unsigned crypt;
                    101: 
                    102:        crypt = 0x3141;
                    103:        sw = 0;
                    104:        q = newmsg+4;
                    105:        for(p = msg; c = *p++;) {
                    106:                if(crypt & 0x8000)
                    107:                        crypt ^= 0xE178;
                    108:                crypt = c ^ (crypt << 1);
                    109: 
                    110:                if('%' == c)  /* save the printf token */
                    111:                        sw = 1;
                    112:                if(sw && (' ' == (*q++ = c)))
                    113:                        sw = 0;
                    114:        }
                    115:        *q = '\0';
                    116: 
                    117:        newmsg[3] = digit[crypt&0xF];
                    118:        crypt >>= 4; newmsg[2] = digit[crypt&0xF];
                    119:        crypt >>= 4; newmsg[1] = digit[crypt&0xF];
                    120:        crypt >>= 4; newmsg[0] = digit[crypt&0xF];
                    121:        return newmsg;
                    122: }
                    123: #endif
                    124: 
                    125: /*
                    126:  * Put out botch message and die.
                    127:  * Prepend an informative message if !TINY.
                    128:  */
                    129: cbotch(fp, args)
                    130: char *fp;
                    131: {
                    132: #if    TINY
                    133:        fp = botch_message(fp);
                    134: #endif
                    135:        cmsg(fp, &args, "Internal compiler error: ", 1);
                    136: #if !OVERLAID
                    137:        exit(ABORT);
                    138: #else
                    139:        longjmp(death, 1);
                    140: #endif
                    141: }
                    142: 
                    143: /*
                    144:  * Put out "out of space" error message and die.
                    145:  */
                    146: cnomem(fp, args)
                    147: char *fp;
                    148: {
                    149: #if    !TINY
                    150:        cmsg(fp, &args, "Out of space", 1);
                    151: #endif
                    152:        cfatal("out of space");
                    153: }
                    154: 
                    155: /*
                    156:  * Put out a message.
                    157:  * Tag it with the line number and file name.
                    158:  */
                    159: static
                    160: cmsg(fp, ap, bp, flag)
                    161: char   *fp;
                    162: int    *ap;
                    163: char   *bp;
                    164: {
                    165:        register int    c;
                    166: 
                    167:        if (isvariant(VQUIET))
                    168:                return;
                    169:        if (line != 0)
                    170:                fprintf(stderr, "%d: ", line);
                    171:        if (file[0])
                    172:                fprintf(stderr, "%s: ", file);
                    173: #if    !TINY
                    174:        if (flag != 0) {
                    175:                if (ifp != NULL)
                    176:                        fprintf(stderr, "At %ld: ", ftell(ifp));
                    177: #if    TEMPBUF
                    178:                else if (inbuf != NULL)
                    179:                        fprintf(stderr, "At %d: ", inbufp - inbuf);
                    180: #endif
                    181:        }
                    182: #endif
                    183:        if (flag!=0 && passname != NULL)
                    184:                fprintf(stderr, "In %s: ", passname);
                    185:        if (bp != NULL)
                    186:                fprintf(stderr, "%s: ", bp);
                    187:        while ((c = *fp++) != '\0') {
                    188:                if (c != '%')
                    189:                        fputc(c, stderr);
                    190:                else {
                    191:                        c = *fp++;
                    192:                        switch (c) {
                    193:                        case 'd':
                    194:                                fprintf(stderr, "%d", *ap++);
                    195:                                break;
                    196:                        case 's':
                    197:                                fprintf(stderr, "%s", *((char **)ap)++);
                    198:                                break;
                    199:                        case 'X':
                    200:                                fprintf(stderr, "%lx", *((long *)ap)++);
                    201:                                break;
                    202:                        default:
                    203:                                fputc(c, stderr);
                    204:                        }
                    205:                }
                    206:        }
                    207:        fputc('\n', stderr);
                    208: }
                    209: 
                    210: /* end of h/diag.c */

unix.superglobalmegacorp.com

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