xref: /original-bsd/usr.bin/pascal/pxp/error.c (revision c3e32dec)
1 /*-
2  * Copyright (c) 1980, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)error.c	8.1 (Berkeley) 06/06/93";
10 #endif /* not lint */
11 
12 /*
13  * pi - Pascal interpreter code translator
14  *
15  * Charles Haley, Bill Joy UCB
16  * Version 1.2 January 1979
17  *
18  *
19  * pxp - Pascal execution profiler
20  *
21  * Bill Joy UCB
22  * Version 1.2 January 1979
23  */
24 
25 #include "whoami.h"
26 #include "0.h"
27 #include "yy.h"
28 
29 #ifdef PXP
30 extern	int yyline;
31 extern	char errout;
32 #endif
33 
34 char	errpfx	= 'E';
35 extern	int yyline;
36 /*
37  * Panic is called when impossible
38  * (supposedly, anyways) situations
39  * are encountered.
40 #ifdef PI
41  * Panic messages should be short
42  * as they do not go to the message
43  * file.
44 #endif
45  */
46 panic(s)
47 	char *s;
48 {
49 
50 #ifdef DEBUG
51 	fprintf(stderr, "Snark (%s) line=%d yyline=%d\n", s, line, yyline);
52 #endif
53 #ifdef PXP
54 	Perror( "Snark in pxp", s);
55 #endif
56 #ifdef PI
57 	Perror( "Snark in pi", s);
58 #endif
59 	pexit(DIED);
60 }
61 
62 extern	char *errfile;
63 /*
64  * Error is called for
65  * semantic errors and
66  * prints the error and
67  * a line number.
68  */
69 error(a1, a2, a3, a4)
70 {
71 #ifdef PI
72 	char buf[256];
73 	register int i;
74 #endif
75 #ifdef PXP
76 /*
77 	int ofout;
78 */
79 #endif
80 
81 	if (errpfx == 'w' && opt('w') != 0) {
82 		errpfx == 'E';
83 		return;
84 	}
85 #ifdef PXP
86 /*
87 	flush();
88 	ofout = fout[0];
89 	fout[0] = errout;
90 */
91 #endif
92 #ifdef PI
93 	Enocascade = 0;
94 	geterr(a1, buf);
95 	a1 = buf;
96 #endif
97 	if (line < 0)
98 		line = -line;
99 	yySsync();
100 	yysetfile(filename);
101 #ifdef PI
102 	if (errpfx == ' ') {
103 		printf("  ");
104 		for (i = line; i >= 10; i /= 10)
105 			putchar(' ');
106 		printf("... ");
107 	} else if (Enoline)
108 		printf("  %c - ", errpfx);
109 	else
110 #endif
111 		fprintf(stderr, "%c %d - ", errpfx, line);
112 	fprintf(stderr, a1, a2, a3, a4);
113 	if (errpfx == 'E')
114 #ifdef PI
115 		eflg++, cgenflg++;
116 #endif
117 #ifdef PXP
118 		eflg++;
119 #endif
120 	errpfx = 'E';
121 #ifdef PI
122 	if (Eholdnl)
123 		Eholdnl = 0;
124 	else
125 #endif
126 		putc('\n', stderr);
127 #ifdef PXP
128 /*
129 	flush();
130 	fout[0] = ofout;
131 */
132 #endif
133 }
134 
135 #ifdef PI
136 cerror(a1, a2, a3, a4)
137 {
138 
139 	if (Enocascade)
140 		return;
141 	setpfx(' ');
142 	error(a1, a2, a3, a4);
143 }
144 #endif
145