Remove a few more warnings.
[suif.git] / src / basesuif / snoot / error.cc
blob668be168c41dc37fe25a72103fe654e55f83dcdd
1 /* file "error.cc" */
3 /* Copyright (c) 1994 Stanford University
5 All rights reserved.
7 This software is provided under the terms described in
8 the "suif_copyright.h" include file. */
10 #include <suif_copyright.h>
12 /* snoot error reporting */
14 #include "c.h"
16 int errcnt; /* number of compilation errors */
17 int errlimit = 20; /* compilation error limit */
18 boolean wflag; /* TRUE to suppress warning messages */
20 static void printtoken(void);
22 /* error - issue error message */
23 void error(const char *fmt, ...)
25 va_list ap;
27 va_start(ap, fmt);
28 if ((firstfile != file) && (firstfile != NULL) && (*firstfile != 0))
29 fprint(stderr, "%s: ", firstfile);
30 fprint(stderr, "%w: ", &src);
31 vfprint(stderr, fmt, ap);
32 if (++errcnt >= errlimit)
34 errcnt = -1;
35 error("too many errors\n");
36 exit(1);
38 va_end(ap);
41 /* expect - advance if t is tok, otherwise issue message */
42 int expect(int tok)
44 if (t == tok)
46 t = gettok();
47 return t;
49 errcnt--;
50 error("syntax error; found");
51 printtoken();
52 fprint(stderr, " expecting `%k'\n", tok);
53 errcnt++;
54 return 0;
57 /* fatal - issue fatal error message and exit */
58 int fatal(const char *name, const char *fmt, int n)
60 fputc('\n', stdout);
61 outflush();
62 error("compiler error in %s--", name);
63 fprint(stderr, fmt, n);
64 exit(1);
65 return 0;
68 /* printtoken - print current token preceeded by a space */
69 static void printtoken(void)
71 switch (t)
73 case ID:
74 fprint(stderr, " `%s'", token); break;
75 case ICON:
76 if (*token == '\'')
78 char *s;
79 case SCON:
80 fprint(stderr, " ");
81 for (s = token; (*s != 0) && (s - token < 20); s++)
83 if (*s < ' ' || *s >= 0177)
84 fprint(stderr, "\\%o", *s);
85 else
86 fprint(stderr, "%c", *s);
88 if (*s != 0)
89 fprint(stderr, " ...");
90 else
91 fprint(stderr, "%c", *token);
92 break;
93 } /* else fall through */
94 case FCON:
96 char c = *cp;
97 *cp = 0;
98 fprint(stderr, " `%s'", token);
99 *cp = c;
100 break;
102 case '`':
103 case '\'':
104 fprint(stderr, " \"%k\"", t);
105 break;
106 default:
107 fprint(stderr, " `%k'", t);
111 /* skipto - skip input up to tok U set, for a token where kind[t] is in set */
112 void skipto(int tok, char set[])
114 int n;
115 char *s;
117 for (n = 0; (t != EOI) && (t != tok); t = gettok())
119 if (set)
121 for (s = set; (*s != 0) && (kind[t] != *s); s++)
123 if (kind[t] == *s)
124 break;
126 if (n++ == 0)
128 errcnt--;
129 error("skipping", 0, 0, 0, 0);
131 if (n <= 8)
132 printtoken();
133 else if (n == 9)
134 fprint(stderr, " ...\n");
136 if (n > 8)
138 errcnt--;
139 error("up to", 0, 0, 0, 0);
140 printtoken();
142 if (n > 0)
143 fprint(stderr, "\n");
146 /* test - check for token tok, skip to tok U set, if necessary */
147 void test(int tok, char set[])
149 if (t == tok)
151 t = gettok();
153 else
155 expect(tok);
156 skipto(tok, set);
157 if (t == tok)
158 t = gettok();
162 /* warning - issue warning error message */
163 void warning(const char *fmt, ...)
165 va_list ap;
167 va_start(ap, fmt);
168 if (!wflag)
170 errcnt--; /* compensate for increment in error */
171 error("warning: ");
172 vfprint(stderr, fmt, ap);
174 va_end(ap);