Menu

[b84aab]: / src / common / sberr.c  Maximize  Restore  History

Download this file

333 lines (268 with data), 6.1 kB

  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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
// This file is part of SmallBASIC
//
// SmallBASIC run-time errors
//
// This program is distributed under the terms of the GPL v2.0 or later
// Download the GNU Public License (GPL) from www.gnu.org
//
// Copyright(C) 2000 Nicholas Christopoulos
#include "common/smbas.h"
#include "common/pproc.h"
#include "common/messages.h"
#include <string.h>
#include <errno.h>
/**
* common message handler
*/
void err_common_msg(const char *seg, const char *file, int line, const char *descr) {
gsb_last_line = line;
gsb_last_error = prog_error;
strcpy(gsb_last_file, file);
strncpy(prog_errmsg, descr, SB_ERRMSG_SIZE);
prog_errmsg[SB_ERRMSG_SIZE] = '\0';
strcpy(gsb_last_errmsg, prog_errmsg);
log_printf("\n\033[0m\033[80m\n");
log_printf("\033[7m * %s-%s %s:%d * \033[0m\a\n\n", seg, WORD_ERROR_AT, file, line);
log_printf("\033[4m%s:\033[0m\n%s\n", WORD_DESCRIPTION, descr);
log_printf("\033[80m\033[0m");
}
/**
* raise a compiler error
*/
void sc_raise2(const char *sec, int scline, const char *buff) {
prog_error = 0x40;
err_common_msg(WORD_COMP, sec, scline, buff);
}
/**
* run-time error
*/
void rt_raise(const char *fmt, ...) {
char *buff;
va_list ap;
int i_stack, i_kw;
if (!gsb_last_error) {
prog_error = 0x80;
va_start(ap, fmt);
buff = tmp_alloc(SB_TEXTLINE_SIZE + 1);
vsprintf(buff, fmt, ap);
va_end(ap);
err_common_msg(WORD_RTE, prog_file, prog_line, buff);
tmp_free(buff);
if (prog_stack_count) {
log_printf("\033[4mStack:\033[0m\n");
}
// log the stack trace
for (i_stack = prog_stack_count; i_stack > 0; i_stack--) {
stknode_t node = prog_stack[i_stack];
switch (node.type) {
case 0xFF:
case kwBYREF:
case kwTYPE_CRVAR:
// ignore these types
break;
default:
for (i_kw = 0; keyword_table[i_kw].name[0] != '\0'; i_kw++) {
if (node.type == keyword_table[i_kw].code) {
log_printf(" %s: %d", keyword_table[i_kw].name, node.line);
}
}
}
}
}
}
/* ERROR MESSAGES */
void err_file(dword code) {
char buf[1024], *p;
strcpy(buf, strerror(code));
p = buf;
while (*p) {
*p = to_upper(*p);
p++;
}
rt_raise(FSERR_FMT, code, buf);
}
#if defined(OS_LIMITED)
void err_missing_rp(void) {
rt_raise(ERR_MISSING_RP);
}
void err_matdim(void) {
rt_raise(ERR_MATRIX_DIM);
}
void err_syntax(void) {
rt_raise(ERR_SYNTAX);
}
void err_syntaxsep(int c) {
rt_raise(ERR_MISSING_SEP, c);
}
void err_parm_num(void) {
rt_raise(ERR_PARCOUNT);
}
#endif
void err_stackoverflow(void) {
rt_raise(ERR_STACK_OVERFLOW);
}
void err_stackunderflow(void) {
rt_raise(ERR_STACK_UNDERFLOW);
}
void err_stackmess() {
rt_raise(ERR_STACK);
}
void err_arrmis_lp(void) {
rt_raise(ERR_ARRAY_MISSING_LP);
}
void err_arrmis_rp(void) {
rt_raise(ERR_ARRAY_MISSING_RP);
}
void err_arridx(int i, int m) {
rt_raise(ERR_ARRAY_RANGE, i, m);
}
void err_typemismatch(void) {
rt_raise(ERR_TYPE);
}
void err_argerr(void) {
rt_raise(ERR_PARAM);
}
void err_varisarray(void) {
rt_raise(EVAL_VAR_IS_ARRAY);
}
void err_varisnotarray(void) {
rt_raise(EVAL_VAR_IS_NOT_ARRAY);
}
void err_vararridx(int i, int m) {
rt_raise(ERR_ARRAY_RANGE, i, m);
}
void err_varnotnum(void) {
rt_raise(EVAL_NOT_A_NUM);
}
void err_evsyntax(void) {
rt_raise(EVAL_SYNTAX);
}
void err_evtype(void) {
rt_raise(EVAL_TYPE);
}
void err_evargerr(void) {
rt_raise(EVAL_PARAM);
}
void err_unsup(void) {
rt_raise(ERR_UNSUPPORTED);
}
void err_const(void) {
rt_raise(ERR_CONST);
}
void err_notavar(void) {
rt_raise(ERR_NOT_A_VAR);
}
void err_notarray(void) {
rt_raise(ERR_NOT_ARR_OR_FUNC);
}
void err_out_of_range(void) {
rt_raise(ERR_RANGE);
}
void err_missing_sep(void) {
rt_raise(ERR_MISSING_SEP_OR_PAR);
}
void err_division_by_zero(void) {
rt_raise(ERR_DIVZERO);
}
void err_matop(void) {
rt_raise(ERR_OPERATOR);
}
void err_matsig(void) {
rt_raise(ERR_MATSIG);
}
void err_missing_lp(void) {
rt_raise(ERR_MISSING_LP);
}
void err_parfmt(const char *fmt) {
rt_raise(ERR_PARFMT, fmt);
}
void err_parm_byref(int n) {
rt_raise(ERR_BYREF, n);
}
void err_stridx(int n) {
rt_raise(ERR_STR_RANGE, n);
}
void err_fopen(void) {
rt_raise(ERR_BAD_FILE_HANDLE);
}
void err_syntaxanysep(const char *seps) {
rt_raise(ERR_SEP_FMT, seps);
}
void err_parsepoly(int idx, int mark) {
rt_raise(ERR_POLY, idx, mark);
}
void err_bfn_err(long code) {
rt_raise(ERR_CRITICAL_MISSING_FUNC, code);
}
void err_gpf(addr_t addr, int bc) {
dev_printf(ERR_GPF);
rt_raise("SEG:CODE[%d]=%02X", addr, bc);
}
void err_pcode_err(long pcode) {
rt_raise(ERR_CRITICAL_MISSING_PROC, pcode);
}
void err_chain_err(const char *file) {
rt_raise(ERR_CHAIN_FILE, file);
}
void err_run_err(const char *file) {
rt_raise(ERR_RUN_FILE, file);
}
void err_invkw(addr_t addr, byte code) {
rt_raise(ERR_PARCOUNT_SP, addr, (int) code);
}
/**
* the DONE message
*/
void inf_done() {
#if USE_TERM_IO
if (!isatty(STDOUT_FILENO)) {
fprintf(stdout, "\n* %s *\n", WORD_DONE);
}
else {
#endif
dev_printf("\n\033[0m\033[80m\a\033[7m * %s * \033[0m\n", WORD_DONE);
#if USE_TERM_IO
}
#endif
}
/**
* the BREAK message
*/
void inf_break(int pline) {
gsb_last_line = pline;
gsb_last_error = prog_error;
strcpy(gsb_last_file, prog_file);
sprintf(gsb_last_errmsg, "%s %d", WORD_BREAK_AT, pline);
dev_settextcolor(15, 0);
log_printf("\n\033[0m\033[80m\a\033[7m * %s %d * \033[0m\n", WORD_BREAK_AT, pline);
}
/**
* if bytecode files are keeped; messages of the compiler why recompile is needed
*/
void inf_comprq_dv() {
if (!opt_quiet) {
dev_print("Recompile: different version\n");
} else {
dev_print("(ver)\n");
}
}
void inf_comprq_dt() {
if (!opt_quiet) {
dev_print("Recompile: source is newer\n");
} else {
dev_print("(mod)\n");
}
}
void inf_comprq_prq() {
if (!opt_quiet) {
dev_print("Recompile: no binary file\n");
} else {
dev_print("(bin)\n");
}
}
/**
* Low-battery event/signal
*/
void inf_low_battery() {
dev_print("\n\n\a* ALARM: LOW BATTERY *\a\n\n");
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.