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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
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",
40 "Call to illegal address",
41 "Call to non-routine",
45 "Jump to illegal address",
46 "Can't save while in interrupt",
47 "Nesting stream #3 too deep",
49 "Illegal window property",
50 "Print at illegal address",
51 "Illegal dictionary word length",
52 "@jin called with object 0",
53 "@get_child called with object 0",
54 "@get_parent called with object 0",
55 "@get_sibling called with object 0",
56 "@get_prop_addr called with object 0",
57 "@get_prop called with object 0",
58 "@put_prop called with object 0",
59 "@clear_attr called with object 0",
60 "@set_attr called with object 0",
61 "@test_attr called with object 0",
62 "@move_object called moving object 0",
63 "@move_object called moving into object 0",
64 "@remove_object called with object 0",
65 "@get_next_prop called with object 0"
68 static void print_long (unsigned long value, int base);
73 * Initialise error reporting.
81 /* Initialize the counters. */
83 for (i = 0; i < ERR_NUM_ERRORS; i++)
90 * An error has occurred. Ignore it, pass it to os_fatal or report
91 * it according to err_report_mode.
93 * errnum : Numeric code for error (1 to ERR_NUM_ERRORS)
97 void runtime_error (int errnum)
101 if (errnum <= 0 || errnum > ERR_NUM_ERRORS)
104 if (option_err_report_mode == ERR_REPORT_FATAL
105 || (!option_ignore_errors && errnum <= ERR_MAX_FATAL)) {
107 os_fatal (err_messages[errnum - 1]);
111 wasfirst = (error_count[errnum - 1] == 0);
112 error_count[errnum - 1]++;
114 if ((option_err_report_mode == ERR_REPORT_ALWAYS)
115 || (option_err_report_mode == ERR_REPORT_ONCE && wasfirst)) {
119 print_string ("Warning: ");
120 print_string (err_messages[errnum - 1]);
121 print_string (" (PC = ");
125 if (option_err_report_mode == ERR_REPORT_ONCE) {
126 print_string (" (will ignore further occurrences)");
128 print_string (" (occurence ");
129 print_long (error_count[errnum - 1], 10);
140 * Print an unsigned 32bit number in decimal or hex.
144 static void print_long (unsigned long value, int base)
149 for (i = (base == 10 ? 1000000000 : 0x10000000); i != 0; i /= base)
150 if (value >= i || i == 1) {
151 c = (value / i) % base;
152 print_char (c + (c <= 9 ? '0' : 'a' - 10));