Bump plugin API version. This should have been done in r24587. Also, because the...
[kugel-rb.git] / apps / plugins / frotz / err.c
blob61ca78ce3bd13f8207740104f432f1cddc420107
1 /* err.c - Runtime error reporting functions
2 * Written by Jim Dunleavy <jim.dunleavy@erha.ie>
4 * This file is part of Frotz.
6 * Frotz is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Frotz is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
21 #include "frotz.h"
23 /* Define stuff for stricter Z-code error checking, for the generic
24 Unix/DOS/etc terminal-window interface. Feel free to change the way
25 player prefs are specified, or replace report_zstrict_error()
26 completely if you want to change the way errors are reported. */
28 /* int err_report_mode = ERR_DEFAULT_REPORT_MODE; */
30 static int error_count[ERR_NUM_ERRORS];
32 static char *err_messages[] = {
33 "Text buffer overflow",
34 "Store out of dynamic memory",
35 "Division by zero",
36 "Illegal object",
37 "Illegal attribute",
38 "No such property",
39 "Stack overflow",
40 "Call to illegal address",
41 "Call to non-routine",
42 "Stack underflow",
43 "Illegal opcode",
44 "Bad stack frame",
45 "Jump to illegal address",
46 "Can't save while in interrupt",
47 "Nesting stream #3 too deep",
48 "Illegal window",
49 "Illegal window property",
50 "Print at illegal address",
51 "@jin called with object 0",
52 "@get_child called with object 0",
53 "@get_parent called with object 0",
54 "@get_sibling called with object 0",
55 "@get_prop_addr called with object 0",
56 "@get_prop called with object 0",
57 "@put_prop called with object 0",
58 "@clear_attr called with object 0",
59 "@set_attr called with object 0",
60 "@test_attr called with object 0",
61 "@move_object called moving object 0",
62 "@move_object called moving into object 0",
63 "@remove_object called with object 0",
64 "@get_next_prop called with object 0"
67 static void print_long (unsigned long value, int base);
70 * init_err
72 * Initialise error reporting.
76 void init_err (void)
78 int i;
80 /* Initialize the counters. */
82 for (i = 0; i < ERR_NUM_ERRORS; i++)
83 error_count[i] = 0;
87 * runtime_error
89 * An error has occurred. Ignore it, pass it to os_fatal or report
90 * it according to err_report_mode.
92 * errnum : Numeric code for error (1 to ERR_NUM_ERRORS)
96 void runtime_error (int errnum)
98 int wasfirst;
100 if (errnum <= 0 || errnum > ERR_NUM_ERRORS)
101 return;
103 if (f_setup.err_report_mode == ERR_REPORT_FATAL
104 || (!f_setup.ignore_errors && errnum <= ERR_MAX_FATAL)) {
105 flush_buffer ();
106 os_fatal (err_messages[errnum - 1]);
107 return;
110 wasfirst = (error_count[errnum - 1] == 0);
111 error_count[errnum - 1]++;
113 if ((f_setup.err_report_mode == ERR_REPORT_ALWAYS)
114 || (f_setup.err_report_mode == ERR_REPORT_ONCE && wasfirst)) {
115 long pc;
117 GET_PC (pc);
118 print_string ("Warning: ");
119 print_string (err_messages[errnum - 1]);
120 print_string (" (PC = ");
121 print_long (pc, 16);
122 print_char (')');
124 if (f_setup.err_report_mode == ERR_REPORT_ONCE) {
125 print_string (" (will ignore further occurrences)");
126 } else {
127 print_string (" (occurence ");
128 print_long (error_count[errnum - 1], 10);
129 print_char (')');
131 new_line ();
134 } /* report_error */
137 * print_long
139 * Print an unsigned 32bit number in decimal or hex.
143 static void print_long (unsigned long value, int base)
145 unsigned long i;
146 char c;
148 for (i = (base == 10 ? 1000000000 : 0x10000000); i != 0; i /= base)
149 if (value >= i || i == 1) {
150 c = (value / i) % base;
151 print_char (c + (c <= 9 ? '0' : 'a' - 10));
154 }/* print_long */