diff options
Diffstat (limited to 'libraries/embryo/src/bin/embryo_cc_sc5.c')
-rw-r--r-- | libraries/embryo/src/bin/embryo_cc_sc5.c | 154 |
1 files changed, 154 insertions, 0 deletions
diff --git a/libraries/embryo/src/bin/embryo_cc_sc5.c b/libraries/embryo/src/bin/embryo_cc_sc5.c new file mode 100644 index 0000000..57b1744 --- /dev/null +++ b/libraries/embryo/src/bin/embryo_cc_sc5.c | |||
@@ -0,0 +1,154 @@ | |||
1 | /* Small compiler - Error message system | ||
2 | * In fact a very simple system, using only 'panic mode'. | ||
3 | * | ||
4 | * Copyright (c) ITB CompuPhase, 1997-2003 | ||
5 | * | ||
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. | ||
9 | * | ||
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: | ||
13 | * | ||
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. | ||
21 | * | ||
22 | * Version: $Id: embryo_cc_sc5.c 61433 2011-07-16 23:19:02Z caro $ | ||
23 | */ | ||
24 | |||
25 | |||
26 | #ifdef HAVE_CONFIG_H | ||
27 | # include <config.h> | ||
28 | #endif | ||
29 | |||
30 | #include <stdio.h> | ||
31 | #include <stdlib.h> | ||
32 | #include <stdarg.h> | ||
33 | #include <string.h> | ||
34 | |||
35 | #ifdef HAVE_UNISTD_H | ||
36 | # include <unistd.h> | ||
37 | #endif | ||
38 | |||
39 | #include "embryo_cc_sc.h" | ||
40 | #include "embryo_cc_sc5.scp" | ||
41 | |||
42 | static int errflag; | ||
43 | static int errstart; /* line number at which the instruction started */ | ||
44 | |||
45 | /* error | ||
46 | * | ||
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). | ||
51 | * | ||
52 | * Global references: inpfname (referred to only) | ||
53 | * fline (referred to only) | ||
54 | * fcurrent (referred to only) | ||
55 | * errflag (altered) | ||
56 | */ | ||
57 | int | ||
58 | error(int number, ...) | ||
59 | { | ||
60 | static int lastline, lastfile, errorcount; | ||
61 | char *msg; | ||
62 | va_list argptr; | ||
63 | char string[1024]; | ||
64 | int start; | ||
65 | |||
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. | ||
70 | */ | ||
71 | if (((errflag) || (sc_status != statWRITE)) && | ||
72 | ((number < 100) || (number >= 200))) | ||
73 | return 0; | ||
74 | |||
75 | if (number < 100) | ||
76 | { | ||
77 | msg = errmsg[number - 1]; | ||
78 | errflag = TRUE; /* set errflag (skip rest of erroneous expression) */ | ||
79 | errnum++; | ||
80 | } | ||
81 | else if (number < 200) | ||
82 | { | ||
83 | msg = fatalmsg[number - 100]; | ||
84 | errnum++; /* a fatal error also counts as an error */ | ||
85 | } | ||
86 | else | ||
87 | { | ||
88 | msg = warnmsg[number - 200]; | ||
89 | warnnum++; | ||
90 | } | ||
91 | |||
92 | strexpand(string, (unsigned char *)msg, sizeof string, SCPACK_TABLE); | ||
93 | |||
94 | va_start(argptr, number); | ||
95 | |||
96 | start = (errstart == fline) ? -1 : errstart; | ||
97 | |||
98 | if (sc_error(number, string, inpfname, start, fline, argptr)) | ||
99 | { | ||
100 | sc_closeasm(outf); | ||
101 | outf = NULL; | ||
102 | longjmp(errbuf, 3); | ||
103 | } | ||
104 | |||
105 | va_end(argptr); | ||
106 | |||
107 | if (((number >= 100) && (number < 200)) || (errnum > 250)) | ||
108 | { | ||
109 | va_start(argptr, number); | ||
110 | sc_error(0, "\nCompilation aborted.", NULL, 0, 0, argptr); | ||
111 | va_end(argptr); | ||
112 | |||
113 | if (outf) | ||
114 | { | ||
115 | sc_closeasm(outf); | ||
116 | outf = NULL; | ||
117 | } /* if */ | ||
118 | longjmp(errbuf, 2); /* fatal error, quit */ | ||
119 | } /* if */ | ||
120 | |||
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)) | ||
124 | errorcount = 0; | ||
125 | lastline = fline; | ||
126 | lastfile = fcurrent; | ||
127 | if (number < 200) | ||
128 | errorcount++; | ||
129 | if (errorcount >= 3) | ||
130 | error(107); /* too many error/warning messages on one line */ | ||
131 | return 0; | ||
132 | } | ||
133 | |||
134 | void | ||
135 | errorset(int code) | ||
136 | { | ||
137 | switch (code) | ||
138 | { | ||
139 | case sRESET: | ||
140 | errflag = FALSE; /* start reporting errors */ | ||
141 | break; | ||
142 | case sFORCESET: | ||
143 | errflag = TRUE; /* stop reporting errors */ | ||
144 | break; | ||
145 | case sEXPRMARK: | ||
146 | errstart = fline; /* save start line number */ | ||
147 | break; | ||
148 | case sEXPRRELEASE: | ||
149 | errstart = -1; /* forget start line number */ | ||
150 | break; | ||
151 | default: | ||
152 | break; | ||
153 | } | ||
154 | } | ||