|
|
1.1 root 1: /*******************************************************************
2: * *
3: * File: CIFPLOT/error.c *
4: * Written by Dan Fitzpatrick *
5: * copyright 1980 -- Regents of the University of California *
6: * *
7: ********************************************************************/
8:
9:
10: #include <stdio.h>
11: #include <signal.h>
12: #include "defs.h"
13: #include "globals.h"
14: #include "scanner.h"
15:
16: IMPORT string Concat();
17: IMPORT alloc();
18:
19: /* The struct 'ErrorType' is used to create a linked listed which
20: * contains error messages. The error messages are held till the
21: * entire line has been read, then are printed out with an arrow
22: * marking the spot where the error occured. */
23: struct ErrorType {
24: struct ErrorType *ELink;
25: int LineNo,CharNo;
26: string EString;
27: } *ErrorList,*ErrorEnd;
28:
29: int FatalError;
30:
31: yyerror()
32: /* YACC wants this */
33: {
34: return(0);
35: }
36:
37: Error(s,type)
38: char *s;
39: int type;
40: /* 'Error' is the general error reporting facility */
41: {
42: char buf[128];
43: switch(type) {
44: case INTERNAL:
45: fprintf(stderr,"Internal Error: %s\n",s);
46: abort();
47: case RUNTIME:
48: fprintf(stderr,"Run Time Error: %s\n",s);
49: abort();
50: case WARNING:
51: sprintf(buf,"warning: %s",s);
52: DispError(TokenLine,TokenChar,buf);
53: break;
54: case RECOVERABLE:
55: sprintf(buf,"error: %s",s);
56: DispError(TokenLine,TokenChar,buf);
57: break;
58: case FATAL:
59: FatalError = 1;
60: sprintf(buf,"Error: %s",s);
61: DispError(TokenLine,TokenChar,buf);
62: break;
63: default:
64: fprintf(stderr,"Unknown Error Type: %s\n",s);
65: abort();
66: }
67: }
68:
69: DispError(ln,cn,s)
70: int ln,cn;
71: string s;
72: /* 'DispError' places an error message,'s', on the error list */
73: {
74: struct ErrorType *p;
75:
76: p = (struct ErrorType *) alloc(sizeof(struct ErrorType));
77: p->LineNo = ln;
78: p->CharNo = cn;
79: p->EString = Concat(s,0);
80: if (ErrorList == NIL){
81: ErrorEnd = ErrorList = p;
82: }
83: else
84: ErrorEnd->ELink = p;
85: ErrorEnd = p;
86: p->ELink = NIL;
87: PrintError();
88: }
89:
90:
91: PrintError()
92: /* 'PrintError' prints the error messages on 'ErrorList' if the
93: * line which the error occured on has been completely read in. */
94: {
95: int i;
96: while(ErrorList != NIL) {
97: PrintLine(ErrorList->LineNo);
98: if (ErrorList->LineNo <= maxlines) {
99: if (ErrorList->LineNo < maxlines) {
100: /* The line which the error occured on has been passed.
101: * Print the line number and the message */
102: fprintf(stderr,"Line %d %s\n",ErrorList->LineNo,ErrorList->EString);
103: }
104: else {
105: /* A negitive CharNo indicates the error was on
106: * the previous line */
107: if (ErrorList->CharNo < 0)
108: ErrorList->CharNo = OldLength-ErrorList->CharNo-2;
109: /* Print the line number */
110: fprintf(stderr,"%6d----",ErrorList->LineNo);
111: /* Step out the proper number of places and put an up-
112: * arrow under the offender. */
113: for(i=1; i<ErrorList->CharNo;i++) fprintf(stderr,"-");
114: fprintf(stderr,"^----");
115: for(i=ErrorList->CharNo; i<10;i++) fprintf(stderr,"-");
116: /* Print the error message */
117: fprintf(stderr,"%s\n",ErrorList->EString);
118: Free(ErrorList->EString);
119: }
120: ErrorList = ErrorList->ELink;
121: }
122: else
123: /* If we have not reached the offending line just return */
124: return;
125: }
126: }
127:
128: ErrorSummary()
129: {
130: PrintError();
131: while(ErrorList != NIL) {
132: fprintf(stderr,"Line %d %s\n",ErrorList->LineNo,ErrorList->EString);
133: ErrorList = ErrorList->ELink;
134: }
135: if(FatalError) fprintf(stderr,"Plotting Supressed\n");
136: return;
137: }
138: extern Abort(); /* Forward reference Abort */
139: extern Trap(); /* Forward reference Trap */
140:
141: InitError()
142: {
143: int i;
144:
145: ErrorList = NIL;
146: ErrorEnd = NIL;
147: FatalError = 0;
148:
149: if(signal(SIGINT,SIG_IGN) == SIG_IGN) {
150: signal(SIGHUP,SIG_IGN);
151: signal(SIGQUIT,SIG_IGN);
152: signal(SIGINT,SIG_IGN);
153: background = 1;
154: }
155: else {
156: signal(SIGHUP,Trap);
157: signal(SIGQUIT,Trap);
158: signal(SIGINT,Trap);
159: background = 0;
160: }
161: /* Catch traps */
162: for(i=4;i<16;i++)
163: signal(i,Trap);
164: }
165:
166: /*
167: background()
168: {
169: signal(SIGHUP,SIG_IGN);
170: signal(SIGQUIT,SIG_IGN);
171: signal(SIGINT,SIG_IGN);
172: }
173: */
174:
175: Trap(n)
176: int n;
177: {
178: switch(n) {
179: case SIGHUP:
180: fprintf(stderr,"hangup - ");
181: break;
182: case SIGINT:
183: fprintf(stderr,"interrupt - ");
184: break;
185: case SIGQUIT:
186: fprintf(stderr,"quit - ");
187: break;
188: case SIGILL:
189: break;
190: case SIGTRAP:
191: fprintf(stderr,"trap - ");
192: break;
193: case SIGIOT:
194: fprintf(stderr,"IOT instruction - ");
195: break;
196: case SIGEMT:
197: fprintf(stderr,"EMT instruction - ");
198: break;
199: case SIGFPE:
200: fprintf(stderr,"floating point exception - ");
201: break;
202: case SIGBUS:
203: fprintf(stderr,"bus error - ");
204: break;
205: case SIGSEGV:
206: fprintf(stderr,"segmentation violation - ");
207: break;
208: case SIGSYS:
209: fprintf(stderr,"bad argument to system call - ");
210: break;
211: case SIGPIPE:
212: fprintf(stderr,"write on a pipe with no one to read it - ");
213: break;
214: case SIGALRM:
215: fprintf(stderr,"alarm clock - ");
216: break;
217: case SIGTERM:
218: fprintf(stderr,"cifplot killed - ");
219: break;
220: default:
221: fprintf(stderr,"unknown error - ");
222: break;
223: }
224: Abort();
225: }
226:
227: Abort()
228: /* Abort does a semi-graceful closing of the program */
229: {
230: fprintf(stderr,"abort\n");
231: signal(SIGILL,SIG_DFL);
232: fflush(stdout);
233: /*
234: Summary();
235: */
236: fflush(stdout);
237: if(fileopen) {
238: DumpBuf(-INFINITY);
239: vclose();
240: }
241: unlock();
242: if(debug) {
243: AllocSummary();
244: abort();
245: }
246: exit(2);
247: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.