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