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