1 /* Small compiler - Error message system
2 * In fact a very simple system, using only 'panic mode'.
4 * Copyright (c) ITB CompuPhase, 1997-2003
6 * This software is provided "as-is", without any express or implied warranty.
7 * In no event will the authors be held liable for any damages arising from
8 * the use of this software.
10 * Permission is granted to anyone to use this software for any purpose,
11 * including commercial applications, and to alter it and redistribute it
12 * freely, subject to the following restrictions:
14 * 1. The origin of this software must not be misrepresented; you must not
15 * claim that you wrote the original software. If you use this software in
16 * a product, an acknowledgment in the product documentation would be
17 * appreciated but is not required.
18 * 2. Altered source versions must be plainly marked as such, and must not be
19 * misrepresented as being the original software.
20 * 3. This notice may not be removed or altered from any source distribution.
22 * Version: $Id: embryo_cc_sc5.c 51023 2010-08-11 20:35:26Z lucas $
39 #include "embryo_cc_sc.h"
40 #include "embryo_cc_sc5.scp"
43 static int errstart; /* line number at which the instruction started */
47 * Outputs an error message (note: msg is passed optionally).
48 * If an error is found, the variable "errflag" is set and subsequent
49 * errors are ignored until lex() finds a semicolumn or a keyword
50 * (lex() resets "errflag" in that case).
52 * Global references: inpfname (reffered to only)
53 * fline (reffered to only)
54 * fcurrent (reffered to only)
58 error(int number, ...)
60 static int lastline, lastfile, errorcount;
66 /* errflag is reset on each semicolon.
67 * In a two-pass compiler, an error should not be reported twice. Therefore
68 * the error reporting is enabled only in the second pass (and only when
69 * actually producing output). Fatal errors may never be ignored.
71 if (((errflag) || (sc_status != statWRITE)) &&
72 ((number < 100) || (number >= 200)))
77 msg = errmsg[number - 1];
78 errflag = TRUE; /* set errflag (skip rest of erroneous expression) */
81 else if (number < 200)
83 msg = fatalmsg[number - 100];
84 errnum++; /* a fatal error also counts as an error */
88 msg = warnmsg[number - 200];
92 strexpand(string, (unsigned char *)msg, sizeof string, SCPACK_TABLE);
94 va_start(argptr, number);
96 start = (errstart == fline) ? -1 : errstart;
98 if (sc_error(number, string, inpfname, start, fline, argptr))
107 if (((number >= 100) && (number < 200)) || (errnum > 250))
109 va_start(argptr, number);
110 sc_error(0, "\nCompilation aborted.", NULL, 0, 0, argptr);
118 longjmp(errbuf, 2); /* fatal error, quit */
121 /* check whether we are seeing many errors on the same line */
122 if (((errstart < 0) && (lastline != fline)) ||
123 (lastline < errstart) || (lastline > fline) || (fcurrent != lastfile))
130 error(107); /* too many error/warning messages on one line */
140 errflag = FALSE; /* start reporting errors */
143 errflag = TRUE; /* stop reporting errors */
146 errstart = fline; /* save start line number */
149 errstart = -1; /* forget start line number */