DEADSOFTWARE

Patched for Linux
[mp3cc.git] / MPC.3.5.LINUX / util / error.c
1 /********************************************************************
3 error.c - implementation of error-handling routines
5 Niksa Orlic, 2004-04-19
7 ********************************************************************/
9 #include <stdio.h>
10 #include <stdlib.h>
12 extern char msgstr[1024];
13 extern char *source_file_name;
14 extern int linenum;
16 char locbuf[1024];
17 short int error_count = 0;
18 long int last_error_linenum = -1;
19 int new_linenum = 0;
20 short int warning_count = 0;
23 char *msg(int i){
24 switch(i)
25 {
26 // General messages
27 case 1: return "Out of memory";
28 case 2: return "Too many errors";
29 case 3: return "Cannot create record file";
30 case 4: return "Cannot create class file";
31 case 5: return "Cannot open source file";
32 case 6: return "Serious error occured, stopping compilation";
33 case 7: return "Cannot create binary symbol file";
34 case 10: return "Internal error #010";
35 case 11: return "Internal error #011";
36 case 12: return "Internal error #012";
37 case 13: return "Internal error #013";
38 case 14: return "Internal error #014";
39 case 15: return "Internal error #015";
40 case 16: return "Internal error #016";
41 case 17: return "Internal error #017";
42 case 18: return "Internal error #018";
43 case 19: return "Internal error #019";
44 case 20: return "Internal error #020";
45 case 21: return "Internal error #021";
46 case 22: return "Internal error #022";
47 case 23: return "Internal error #023";
48 case 24: return "Internal error #024";
49 case 25: return "Internal error #025";
50 case 26: return "Internal error #026 memory";
51 // Scanner errors
52 case 100: return "unknown character \'%s\', ignored";
53 case 101: return "newline in string constant";
54 case 102: return "error in preprocessor statement";
55 // Parser errors
56 case 200: return "character \'%s\' expected, \'%s\' found";
57 case 201: return "unexpected text \'%s\' after program end";
58 case 202: return "identifier (name) expected";
59 case 203: return "keyword \'%s\' expected, \'%s\' found";
60 case 204: return "unexpected token \'%s\'";
61 case 205: return "operator \'=\' expected, \'%s\' found";
62 case 206: return "constant expected";
63 case 207: return "unexpected end of file found";
64 case 208: return "error in parameter list on token \'%s\'";
65 case 209: return "operator \':=\' expected, \'%s\' found";
66 case 210: return "\'packed\' arrays not supported; ordinary array are used";
67 case 211: return "sets are not supported in this version";
68 case 212: return "enumerated types are not supported in this version";
69 case 213: return "operator \'..\' expected, \'%s\' found";
70 case 214: return "keyword \'end\' expected, \'%s\' found";
71 case 215: return "\'with\' is not supported in this version";
72 case 216: return "keyword \'then\' expected, \'%s\' found";
73 case 217: return "constant of type integer or char expected";
74 case 218: return "operator \':=\' expected";
75 case 219: return "\'break\' statemnt found outside of do-while, repeat-until or for loop";
76 case 220: return "compiler does ot support the \'finalization\' part of the unit";
77 case 221: return "procedures and functions may not contain body inside unit interface part";
78 // Semantic errors
79 case 400: return "identifier \'%s\' already defined";
80 case 401: return "method was already declared as forward";
81 case 402: return "a %s with the same name was declared as forward";
82 case 403: return "parameter list is shorter than the list in previous forward declaration";
83 case 404: return "parameter list differs on element %s from the list in previous forward declaration";
84 case 405: return "return type is different than the return type declared in the previous forward declaration";
85 case 406: return "unknown type \'%s\'";
86 case 407: return "%s type expected";
87 case 408: return "integer, char or string type expected";
88 case 409: return "constant of type %s expected, %s found";
89 case 410: return "\'%s\' is not a constant";
90 case 411: return "integer or char type expected";
91 case 412: return "%s type expected, %s type found";
92 case 413: return "wrong type in interval definition";
93 case 414: return "\'%s\' is not a constant";
94 case 415: return "type name or integer/char constant expected, \'%s\' found";
95 case 416: return "error in interval definition";
96 case 417: return "operand is wrong type";
97 case 418: return "name \'%s\' already exists in a record declaration";
98 case 419: return "procedure/function takes 0 arguments, brackets must be left out";
99 case 420: return "procedure/function takes more than 0 arguments, '(' expected";
100 case 421: return "parameter list is too short";
101 case 422: return "error on parameter %s";
102 case 423: return "left and right operands to \':=\' must have the same type";
103 case 424: return "\'.\' operator can only be used on record types";
104 case 425: return "the record does not contain element named \'%s\'";
105 case 426: return "\'[\' operator can only be used on array types";
106 case 427: return "error in array dimensions (array has %s dimensions, %s are specified)";
107 case 428: return "identifier \'%s\' is not procedure, function, variable or unit name";
108 case 429: return "identifier \'%s\' is not constant, function or variable name";
109 case 430: return "only interval types can be used for array indexes";
110 case 431: return "nested functions or procedures are not supported";
111 case 432: return "function \'%s\' cannot be called from here; procedure call or assignement expected";
112 case 433: return "\'run\' is reserved name and cannot be used as a function or procedure name";
113 case 434: return "only string, character, integer or boolean can be appended to string";
114 case 435: return "files are not supported in this version";
115 case 436: return "variable parameters are not supported and are ignored";
116 case 437: return "invalid interval";
117 case 438: return "interval too large";
118 case 439: return "only integer type can be used as string index";
119 case 440: return "variables of interval type are not supported";
120 case 441: return "only forward declaration supplied; the implementation is missing";
121 case 442: return "case statement is not supported in this version";
122 case 443: return "a value cannot be asigned to an array. This is a limitation of MIDletPascal";
123 case 444: return "unknown identifier";
124 case 445: return "name of the procedure/function has already been taken by another identifier";
125 case 446: return "arrays in records (\'%s\') are not implemented. This is a limitation of MIDletPascal";
126 case 447: return "unknown record element \'%s\'";
127 case 448: return "failed to load \'%s\' library/unit";
128 case 449: return "error reading external library file";
129 case 450: return "could not load library/unit \'%s\' because identifier of the same name already exists";
130 case 451: return "serious internal error in library";
131 case 452: return "library/unit contains a method with an incorrect argument type";
132 case 453: return "library/unit does not contain function \'%s\'";
133 case 454: return "unit name must contain at least 2 characters";
134 case 455: return "library/unit does not contain type \'%s\'";
135 case 456: return "iterator used in for-loop must not be defined inside a library/unit";
136 case 457: return "identifier \'%s\' is not a procedure or variable name";
137 case 458: return "identifier \'%s\' is not a function, variable or constant name";
138 case 459: return "identifier \'%s\' found in more units; use syntax 'unit_name'.'identifier' to resolve ambiguity";
139 case 460: return "inlined label \'%d\' (offs:%d) not found";
140 case 461: return "inlined label \'%d\' (offs:%d) already defined";
141 case 462: return "inlined label \'%d\' (offs:%d) tableswitch / loookupswitch";
142 case 463: return "keyword \'%s\' is not allowed here.";
143 case 464: return "use bytecode/end instead of inline() which might be deprecated";
148 /*
149 Terminate the program and output the error message
150 */
152 void die(int i)
154 sprintf(msgstr,"Fatal error: %s\n", msg(i));
155 compileMSG();
156 compile_terminate();
160 /*
161 Add an error message, if the total number of errors exceeds 100,
162 die
163 */
164 void add_error_message(int num, char *additional_data1, char *additional_data2)
166 if (new_linenum==0)
167 new_linenum=linenum;
168 if (new_linenum != last_error_linenum) {
169 // j-a-s-d
170 if (num < 100)
171 sprintf(locbuf, "[Compiler Error] %s(%d): E%d %s\n", source_file_name, new_linenum, num, msg(num));
172 else
173 sprintf(locbuf, "[Pascal Error] %s(%d): E%d %s\n", source_file_name, new_linenum, num, msg(num));
175 sprintf(msgstr, locbuf, additional_data1, additional_data2);
176 compileMSG();
177 error_count ++;
178 if (error_count > 100)
179 die(2);
180 last_error_linenum = new_linenum;
182 new_linenum=0;
186 /*
187 Add warning message, if the total number of errors exceeds 100,
188 die
189 */
190 void add_warning_message(int num, char *additional_data1, char *additional_data2)
192 if (new_linenum==0)
193 new_linenum=linenum;
194 // j-a-s-d
195 sprintf(locbuf, "[Pascal Warning] %s(%d): W%d %s\n", source_file_name, new_linenum, num, msg(num));
197 sprintf(msgstr, locbuf, additional_data1, additional_data2);
198 compileMSG();
199 warning_count ++;
200 if (warning_count > 100)
201 die(2);
202 new_linenum=0;