1 | /********************************************************************** <BR>
|
---|
2 | This file is part of Crack dot Com's free source code release of
|
---|
3 | Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
|
---|
4 | information about compiling & licensing issues visit this URL</a>
|
---|
5 | <PRE> If that doesn't help, contact Jonathan Clark at
|
---|
6 | golgotha_source@usa.net (Subject should have "GOLG" in it)
|
---|
7 | ***********************************************************************/
|
---|
8 |
|
---|
9 | #include "error/error.hh"
|
---|
10 | #include "file/file.hh"
|
---|
11 | #include "init/init.hh"
|
---|
12 | #include "string/string.hh"
|
---|
13 |
|
---|
14 | const char *i4_error_file_on;
|
---|
15 | int i4_error_line_on;
|
---|
16 |
|
---|
17 |
|
---|
18 | #include <stdlib.h>
|
---|
19 | #include <stdio.h>
|
---|
20 | #include <ctype.h>
|
---|
21 | #include <stdlib.h>
|
---|
22 | #include <string.h>
|
---|
23 | #include <stdarg.h>
|
---|
24 |
|
---|
25 |
|
---|
26 | #ifdef __sgi
|
---|
27 | #include <unistd.h>
|
---|
28 | #endif
|
---|
29 |
|
---|
30 | class i4_debug_file_class : public i4_file_class
|
---|
31 | {
|
---|
32 | public:
|
---|
33 | i4_debug_file_class() {}
|
---|
34 |
|
---|
35 | virtual w32 read (void *buffer, w32 size)
|
---|
36 | {
|
---|
37 | return fread(buffer, size, 1, stdin);
|
---|
38 | }
|
---|
39 |
|
---|
40 | virtual w32 write(const void *buffer, w32 size)
|
---|
41 | {
|
---|
42 | return fwrite(buffer, size, 1, stdout);
|
---|
43 | }
|
---|
44 |
|
---|
45 | virtual w32 seek (w32 offset) { return 0; }
|
---|
46 | virtual w32 size () { return 0; }
|
---|
47 | virtual w32 tell () { return 0; }
|
---|
48 | };
|
---|
49 | static i4_debug_file_class default_debug;
|
---|
50 |
|
---|
51 | i4_file_class *i4_debug=&default_debug; // stream you can print debug messages to
|
---|
52 | FILE *i4_error_mirror_file=0;
|
---|
53 |
|
---|
54 | int i4_default_error(const char *st)
|
---|
55 | {
|
---|
56 | static int died=0;
|
---|
57 |
|
---|
58 | setbuf(stdout, 0);
|
---|
59 |
|
---|
60 | i4_debug->printf("*****************************************************************\n"
|
---|
61 | "Error (%s:%d) : %s\n"
|
---|
62 | "*****************************************************************\n",
|
---|
63 | i4_error_file_on, i4_error_line_on, st);
|
---|
64 |
|
---|
65 | if (died)
|
---|
66 | return 1;
|
---|
67 | died = 1;
|
---|
68 |
|
---|
69 |
|
---|
70 | if (getenv("FORCE_CORE_DUMP"))
|
---|
71 | return *((int *)0xDeadBeef); // cause a memory fault to stop debugger
|
---|
72 | _exit(0);
|
---|
73 | return -1;
|
---|
74 | }
|
---|
75 |
|
---|
76 |
|
---|
77 | int i4_default_warning(const char *st)
|
---|
78 | {
|
---|
79 | i4_debug->printf("Warning (%s:%d) : %s\n", i4_error_file_on, i4_error_line_on, st);
|
---|
80 |
|
---|
81 | return 0;
|
---|
82 | }
|
---|
83 |
|
---|
84 | i4_error_function_type i4_error_function=i4_default_error;
|
---|
85 | i4_error_function_type i4_warning_function=i4_default_warning;
|
---|
86 |
|
---|
87 |
|
---|
88 | int i4_error_old(const char *format, ...)
|
---|
89 | {
|
---|
90 | va_list ap;
|
---|
91 | char st[500];
|
---|
92 |
|
---|
93 | va_start(ap, format);
|
---|
94 | vsprintf(st, format, ap);
|
---|
95 | int ret = (*i4_error_function)(st);
|
---|
96 | i4_debug->printf("Error : %s\n",st);
|
---|
97 | va_end(ap);
|
---|
98 |
|
---|
99 | return ret;
|
---|
100 | }
|
---|
101 |
|
---|
102 |
|
---|
103 |
|
---|
104 | int i4_warning_old(const char *format, ...)
|
---|
105 | {
|
---|
106 | va_list ap;
|
---|
107 | char st[500];
|
---|
108 |
|
---|
109 | va_start(ap, format);
|
---|
110 | vsprintf(st, format, ap);
|
---|
111 | int ret = (*i4_warning_function)(st);
|
---|
112 | i4_debug->printf("Warning : %s\n",st);
|
---|
113 | va_end(ap);
|
---|
114 |
|
---|
115 | return ret;
|
---|
116 | }
|
---|
117 |
|
---|
118 | i4_error_pointer_type i4_get_error_function_pointer(const char *file, int line)
|
---|
119 | {
|
---|
120 | i4_error_file_on=file;
|
---|
121 | i4_error_line_on=line;
|
---|
122 | return i4_error_old;
|
---|
123 | }
|
---|
124 |
|
---|
125 | i4_error_pointer_type i4_get_warning_function_pointer(const char *file, int line)
|
---|
126 | {
|
---|
127 | i4_error_file_on=file;
|
---|
128 | i4_error_line_on=line;
|
---|
129 | return i4_warning_old;
|
---|
130 | }
|
---|
131 |
|
---|
132 |
|
---|
133 |
|
---|
134 | void i4_set_error_function(i4_error_function_type fun)
|
---|
135 | {
|
---|
136 | i4_error_function=fun;
|
---|
137 | }
|
---|
138 |
|
---|
139 | i4_error_function_type i4_get_error_function()
|
---|
140 | {
|
---|
141 | return i4_error_function;
|
---|
142 | }
|
---|
143 |
|
---|
144 | void i4_set_warning_function(i4_error_function_type fun)
|
---|
145 | {
|
---|
146 | i4_warning_function=fun;
|
---|
147 | }
|
---|
148 |
|
---|
149 |
|
---|
150 | i4_error_function_type i4_get_warning_function()
|
---|
151 | {
|
---|
152 | return i4_warning_function;
|
---|
153 | }
|
---|
154 |
|
---|
155 |
|
---|
156 |
|
---|