new copyright; att/bsd/shared
[unix-history] / usr / src / usr.bin / pascal / src / error.c
CommitLineData
0fc6e47b
KB
1/*-
2 * Copyright (c) 1980 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * %sccs.include.redist.c%
1259848a 6 */
549c504d 7
0cc32c21 8#ifndef lint
0fc6e47b
KB
9static char sccsid[] = "@(#)error.c 5.3 (Berkeley) %G%";
10#endif /* not lint */
549c504d
PK
11
12#include "whoami.h"
13#include "0.h"
14#ifndef PI1
0cc32c21 15#include "tree_ty.h" /* must be included for yy.h */
549c504d
PK
16#include "yy.h"
17#endif
18
19char errpfx = 'E';
20extern int yyline;
21/*
22 * Panic is called when impossible
23 * (supposedly, anyways) situations
24 * are encountered.
25 * Panic messages should be short
26 * as they do not go to the message
27 * file.
28 */
29panic(s)
30 char *s;
31{
32
33#ifdef DEBUG
34#ifdef PI1
35 printf("Snark (%s) line=%d\n", s, line);
36 abort();
37#else
38 printf("Snark (%s) line=%d, yyline=%d\n", s, line, yyline);
39 abort () ; /* die horribly */
40#endif
41#endif
42#ifdef PI1
43 Perror( "Snark in pi1", s);
44#else
45 Perror( "Snark in pi", s);
46#endif
47 pexit(DIED);
48}
49
549c504d
PK
50/*
51 * Error is called for
52 * semantic errors and
53 * prints the error and
54 * a line number.
55 */
56
0cc32c21 57/*VARARGS1*/
549c504d 58
b34994ae 59error(a1, a2, a3, a4, a5)
549c504d
PK
60 register char *a1;
61{
62 char errbuf[256]; /* was extern. why? ...pbk */
63 register int i;
64
65 if (errpfx == 'w' && opt('w') != 0) {
66 errpfx = 'E';
67 return;
68 }
0cc32c21
RT
69 Enocascade = FALSE;
70 geterr((int) a1, errbuf);
549c504d
PK
71 a1 = errbuf;
72 if (line < 0)
73 line = -line;
74#ifndef PI1
75 if (opt('l'))
76 yyoutline();
77#endif
78 yysetfile(filename);
79 if (errpfx == ' ') {
80 printf(" ");
81 for (i = line; i >= 10; i /= 10)
82 pchr( ' ' );
83 printf("... ");
84 } else if (Enoline)
85 printf(" %c - ", errpfx);
86 else
87 printf("%c %d - ", errpfx, line);
b34994ae 88 printf(a1, a2, a3, a4, a5);
549c504d
PK
89 if (errpfx == 'E')
90#ifndef PI0
6cbd3a07 91 eflg = TRUE, codeoff();
549c504d 92#else
6cbd3a07 93 eflg = TRUE;
549c504d
PK
94#endif
95 errpfx = 'E';
96 if (Eholdnl)
0cc32c21 97 Eholdnl = FALSE;
549c504d
PK
98 else
99 pchr( '\n' );
100}
101
0cc32c21 102/*VARARGS1*/
549c504d 103
b34994ae 104cerror(a1, a2, a3, a4, a5)
0cc32c21 105 char *a1;
549c504d
PK
106{
107
108 if (Enocascade)
109 return;
110 setpfx(' ');
b34994ae 111 error(a1, a2, a3, a4, a5);
549c504d
PK
112}
113
114#ifdef PI1
115
116/*VARARGS*/
117
b34994ae 118derror(a1, a2, a3, a4, a5)
0cc32c21 119 char *a1, *a2, *a3, *a4, *a5;
549c504d
PK
120{
121
122 if (!holdderr)
b34994ae 123 error(a1, a2, a3, a4, a5);
549c504d
PK
124 errpfx = 'E';
125}
126
127char *lastname, printed, hadsome;
128
129 /*
130 * this yysetfile for PI1 only.
131 * the real yysetfile is in yyput.c
132 */
133yysetfile(name)
134 char *name;
135{
136
137 if (lastname == name)
138 return;
7169b77a 139 printed |= 1;
549c504d
PK
140 gettime( name );
141 printf("%s %s:\n" , myctime( &tvec ) , name );
142 lastname = name;
143}
144#endif