-
Notifications
You must be signed in to change notification settings - Fork 1
/
error.c
224 lines (211 loc) · 5.69 KB
/
error.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
error.c
*/
#include <stdio.h>
#include <stdlib.h>
#include "my.h"
#include "label.h"
#include "global_vars.h"
#include "parser.h"
#include "error.h"
extern int cntError;
extern int cntWarning;
extern int error;
extern FILE *my_stderr; /* handle for error-output */
extern int verbose;
extern int warning;
int Error(int err_num,const char *s)
{
int fatal = 0;
if ( err_num < 0 ){
fatal = 1;
err_num = -err_num;
}
++error;
++cntError;
if ( fatal ){
fprintf(stderr,"Fatal Error %d!\n",err_num);
}
if (Current.File >= 0){
if ( Current.Macro.Line ){
fprintf(my_stderr,"ERROR: %s;%d:Macro-Line %5d:<%s>: '%s'\n",
file_list[Current.File].name,Current.Line,
Current.Macro.Line,file_list[Current.Macro.File].name,
srcLine);
} else {
fprintf(my_stderr,"ERROR: %s:%5d: '%s'\n",
file_list[Current.File].name,Current.Line, srcLine);
}
}
switch (err_num) {
case INCLUDE_ERR:
fprintf(my_stderr,"To many includes\n");
break;
case FILE_ERR:
fprintf(my_stderr,"Can't open file <%s>\n",s);
break;
case LABEL_ERR:
fprintf(my_stderr,"Wrong character in label\n");
break;
case MLABEL_ERR:
fprintf(my_stderr,"Macro-label outside macro\n");
break;
case NOMEM_ERR:
fprintf(my_stderr,"No more memory available\n");
break;
case REDEF_ERR:
fprintf(my_stderr,"Label redefined ! First use here: %5d : <%s>\n",
((label_t *)s)->line,file_list[ ((label_t *)s)->file ].name );
break;
case LREDEF_ERR:
fprintf(my_stderr,"Local label redefined ! First use here: %5d : <%s>\n",
((label_t *)s)->line,file_list[ ((label_t *)s)->file ].name );
break;
case LMREDEF_ERR:
fprintf(my_stderr,"Local macro label redefined ! First use here: %5d : <%s>\n",
((label_t *)s)->line,file_list[ ((label_t *)s)->file ].name );
break;
case MREDEF_ERR:
fprintf(my_stderr,"Macro-name redefined ! First use here: %5d : <%s>\n",
((label_t *)s)->line,file_list[ ((label_t *)s)->file ].name );
break;
case TOOMANY_ERR:
fprintf(my_stderr,"Global symbol memory exhausted\n");
break;
case LTOOMANY_ERR:
fprintf(my_stderr,"Local symbol memory exhausted\n");
break;
case LMTOOMANY_ERR:
fprintf(my_stderr,"Local-macro symbol memory exhausted\n");
break;
case MTOOMANY_ERR:
fprintf(my_stderr,"Macro-name memory exhausted\n");
break;
case UNKNOWN_ERR:
fprintf(my_stderr,"Unknown opcode : (%s)\n",s);
break;
case TOOBIG_ERR:
fprintf(my_stderr,"Constant to big\n");
break;
case EXPR_ERR:
fprintf(my_stderr,"Error in expression\n");
break;
case SYNTAX_ERR:
if ( s ){
fprintf(my_stderr,"Syntax Error:%s\n",s);
} else {
fprintf(my_stderr,"Syntax Error\n");
}
break;
case NEEDCONST_ERR:
fprintf(my_stderr,"%s needs constant expression\n",s);
break;
case MLABEL2_ERR:
fprintf(my_stderr,"Only .\\label allowed inside a macro\n");
break;
case CODEMEM_ERR:
fprintf(my_stderr,"Code-memory exhausted. Code > %dK\n",MAX_CODE_SIZE/1024);
break;
case DISTANCE_ERR:
fprintf(my_stderr,"Relative distance to large\n");
break;
case NOREFMEM_ERR:
fprintf(my_stderr,"No more reference-memory\n");
break;
case GARBAGE_ERR:
fprintf(my_stderr,"Garbage at the end of line:'%s'\n",s);
break;
case MACRONESTED_ERR:
fprintf(my_stderr,"Macro-definition nested to deep (max. 2)\n");
break;
case BYTE_ERR:
fprintf(my_stderr,"Byte value out of range\n");
break;
case WORD_ERR:
fprintf(my_stderr,"Word value out of range\n");
break;
case TYPE_ERR:
fprintf(my_stderr,"Label-type mismatch\n");
break;
case UNSOLVED_ERR:
fprintf(my_stderr,"Unsolved %s labels\n",s);
break;
case TOOMANYIF_ERR:
fprintf(my_stderr,"To many nested IF\n");
break;
case ENDIF1_ERR:
fprintf(my_stderr,"ENDIF without IF\n");
break;
case FAIL_ERR:
break;
case SWITCH_ERR:
fprintf(my_stderr,"Nested SWITCH\n");
break;
case CASE_ERR:
fprintf(my_stderr,"CASE without SWITCH\n");
break;
case DEFAULT_ERR:
fprintf(my_stderr,"DEFAULT/ELSES without SWITCH\n");
break;
case ENDS_ERR:
fprintf(my_stderr,"ENDS without SWITCH\n");
break;
case REPT1_ERR:
fprintf(my_stderr,"Nested REPT\n");
break;
case REPT2_ERR:
fprintf(my_stderr,"ENDR without REPT\n");
break;
case ISYMS_ERR:
fprintf(my_stderr,"ISYMS only supported in the original Atari version!\n");
break;
case CMD_ERR:
fprintf(my_stderr,"Error in command-line\n");
break;
case WRITE_ERR:
fprintf(my_stderr,"Could not write :%s\n",s);
break;
case LOAD_ERR:
fprintf(my_stderr,"LoadBuffer not big enough for :%s\n",s);
break;
case IMM_ERR:
fprintf(my_stderr,"Quick immediate value out of range (%s)!\n",s);
break;
case REG_ERR:
if ( s ) {
fprintf(my_stderr,"Missing Register:%s\n",s);
} else {
fprintf(my_stderr,"Missing Register\n");
}
break;
case REG1_ERR:
fprintf(my_stderr,"Redefining register-symbol\n");
break;
case MISC_ERR:
fprintf(my_stderr,"%s\n",s);
break;
}
if ( !verbose) verbose=1;
killLine();
if ( fatal ){
fprintf(stderr,"leaving ...\n");
exit(1);
}
return err_num;
}
void Warning(const char *s)
{
cntWarning++;
if (warning && Current.File >= 0){
if ( Current.Macro.Line ){
fprintf(my_stderr,"WARNING: %s;%d:Macro-Line %5d:<%s>: '%s'\n",
file_list[Current.File].name,Current.Line,
Current.Macro.Line,file_list[Current.Macro.File].name,
srcLine);
} else {
fprintf(my_stderr,"WARNING: %s:%5d: '%s'\n",
file_list[Current.File].name,Current.Line, srcLine);
}
printf("%s\n",s);
}
}