2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
4 * Small compiler - Error message system
5 * In fact a very simple system, using only 'panic mode'.
7 * Copyright (c) ITB CompuPhase, 1997-2003
9 * This software is provided "as-is", without any express or implied warranty.
10 * In no event will the authors be held liable for any damages arising from
11 * the use of this software.
13 * Permission is granted to anyone to use this software for any purpose,
14 * including commercial applications, and to alter it and redistribute it
15 * freely, subject to the following restrictions:
17 * 1. The origin of this software must not be misrepresented; you must not
18 * claim that you wrote the original software. If you use this software in
19 * a product, an acknowledgment in the product documentation would be
20 * appreciated but is not required.
21 * 2. Altered source versions must be plainly marked as such, and must not be
22 * misrepresented as being the original software.
23 * 3. This notice may not be removed or altered from any source distribution.
29 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
41 #include "embryo_cc_sc.h"
42 #include "embryo_cc_sc5.scp"
45 static int errstart; /* line number at which the instruction started */
49 * Outputs an error message (note: msg is passed optionally).
50 * If an error is found, the variable "errflag" is set and subsequent
51 * errors are ignored until lex() finds a semicolumn or a keyword
52 * (lex() resets "errflag" in that case).
54 * Global references: inpfname (reffered to only)
55 * fline (reffered to only)
56 * fcurrent (reffered to only)
60 error(int number, ...)
62 static char *prefix[3] = { "error", "fatal error", "warning" };
63 static int lastline, lastfile, errorcount;
69 /* errflag is reset on each semicolon.
70 * In a two-pass compiler, an error should not be reported twice. Therefore
71 * the error reporting is enabled only in the second pass (and only when
72 * actually producing output). Fatal errors may never be ignored.
74 if (((errflag) || (sc_status != statWRITE)) &&
75 ((number < 100) || (number >= 200)))
80 msg = errmsg[number - 1];
82 errflag = TRUE; /* set errflag (skip rest of erroneous expression) */
85 else if (number < 200)
87 msg = fatalmsg[number - 100];
89 errnum++; /* a fatal error also counts as an error */
93 msg = warnmsg[number - 200];
98 strexpand(string, (unsigned char *)msg, sizeof string, SCPACK_TABLE);
100 va_start(argptr, number);
102 start = (errstart == fline) ? -1 : errstart;
104 if (sc_error(number, string, inpfname, start, fline, argptr))
113 if (((number >= 100) && (number < 200)) || (errnum > 250))
115 va_start(argptr, number);
116 sc_error(0, "\nCompilation aborted.", NULL, 0, 0, argptr);
124 longjmp(errbuf, 2); /* fatal error, quit */
127 /* check whether we are seeing many errors on the same line */
128 if (((errstart < 0) && (lastline != fline)) ||
129 (lastline < errstart) || (lastline > fline) || (fcurrent != lastfile))
136 error(107); /* too many error/warning messages on one line */
146 errflag = FALSE; /* start reporting errors */
149 errflag = TRUE; /* stop reporting errors */
152 errstart = fline; /* save start line number */
155 errstart = -1; /* forget start line number */