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.
25 * Version: $Id: embryo_cc_sc5.c 45192 2010-01-15 19:44:25Z englebass $
29 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
45 #include "embryo_cc_sc.h"
46 #include "embryo_cc_sc5.scp"
49 static int errstart; /* line number at which the instruction started */
53 * Outputs an error message (note: msg is passed optionally).
54 * If an error is found, the variable "errflag" is set and subsequent
55 * errors are ignored until lex() finds a semicolumn or a keyword
56 * (lex() resets "errflag" in that case).
58 * Global references: inpfname (reffered to only)
59 * fline (reffered to only)
60 * fcurrent (reffered to only)
64 error(int number, ...)
66 static int lastline, lastfile, errorcount;
72 /* errflag is reset on each semicolon.
73 * In a two-pass compiler, an error should not be reported twice. Therefore
74 * the error reporting is enabled only in the second pass (and only when
75 * actually producing output). Fatal errors may never be ignored.
77 if (((errflag) || (sc_status != statWRITE)) &&
78 ((number < 100) || (number >= 200)))
83 msg = errmsg[number - 1];
84 errflag = TRUE; /* set errflag (skip rest of erroneous expression) */
87 else if (number < 200)
89 msg = fatalmsg[number - 100];
90 errnum++; /* a fatal error also counts as an error */
94 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 */