Subversion Repositories tendra.SVN

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 7
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2005 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997
32
    		 Crown Copyright (c) 1997
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
Line 56... Line 86...
56
#include "error.h"
86
#include "error.h"
57
#include "syntax.h"
87
#include "syntax.h"
58
 
88
 
59
/*--------------------------------------------------------------------------*/
89
/*--------------------------------------------------------------------------*/
60
 
90
 
61
#define TAG_TABLE_SIZE (127)
91
#define TAG_TABLE_SIZE		(127)
62
#define ERROR_TABLE_SIZE (127)
92
#define ERROR_TABLE_SIZE	(127)
63
#define STRING_TABLE_SIZE (127)
93
#define STRING_TABLE_SIZE	(127)
64
 
94
 
65
/*--------------------------------------------------------------------------*/
95
/*--------------------------------------------------------------------------*/
66
 
96
 
67
static ETagP		tag_table [TAG_TABLE_SIZE];
97
static ETagP		tag_table[TAG_TABLE_SIZE];
68
static ErrorP		error_table [ERROR_TABLE_SIZE];
98
static ErrorP		error_table[ERROR_TABLE_SIZE];
69
static EStringP		string_table [STRING_TABLE_SIZE];
99
static EStringP		string_table[STRING_TABLE_SIZE];
70
static CStringP		program_name         = NIL (CStringP);
100
static CStringP		program_name         = NIL(CStringP);
71
static ErrorInitProcP	init_proc	     = NIL (ErrorInitProcP);
101
static ErrorInitProcP	init_proc	     = NIL(ErrorInitProcP);
72
static ETagP		etag_program	     = NIL (ETagP);
102
static ETagP		etag_program	     = NIL(ETagP);
73
static ETagP		etag_severity	     = NIL (ETagP);
103
static ETagP		etag_severity	     = NIL(ETagP);
74
static ETagP		etag_error_name      = NIL (ETagP);
104
static ETagP		etag_error_name      = NIL(ETagP);
75
static ETagP		etag_dollar	     = NIL (ETagP);
105
static ETagP		etag_dollar	     = NIL(ETagP);
76
static ETagP		etag_ocb	     = NIL (ETagP);
106
static ETagP		etag_ocb	     = NIL(ETagP);
77
static ETagP		etag_ccb	     = NIL (ETagP);
107
static ETagP		etag_ccb	     = NIL(ETagP);
78
static ErrorListP	error_prefix	     = NIL (ErrorListP);
108
static ErrorListP	error_prefix	     = NIL(ErrorListP);
79
static ESeverityT	min_severity	     = ERROR_SEVERITY_ERROR;
109
static ESeverityT	min_severity	     = ERROR_SEVERITY_ERROR;
80
static ESeverityT	max_reported	     = ERROR_SEVERITY_INFORMATION;
110
static ESeverityT	max_reported	     = ERROR_SEVERITY_INFORMATION;
81
static EStringDataT	severity_data []     = {
111
static EStringDataT	severity_data[]    = {
82
    UB {"error severity information",	"Info"} UE,
112
    UB {"error severity information",	"Info"} UE,
83
    UB {"error severity warning",	"Warning"} UE,
113
    UB {"error severity warning",	"Warning"} UE,
84
    UB {"error severity error",		"Error"} UE,
114
    UB {"error severity error",		"Error"} UE,
85
    UB {"error severity fatal",		"Fatal"} UE,
115
    UB {"error severity fatal",		"Fatal"} UE,
86
    UB {"error severity internal",	"Internal"} UE,
116
    UB {"error severity internal",	"Internal"} UE,
Line 88... Line 118...
88
};
118
};
89
 
119
 
90
/*--------------------------------------------------------------------------*/
120
/*--------------------------------------------------------------------------*/
91
 
121
 
92
static void
122
static void
93
error_deallocate_error_list PROTO_N ((error_list))
123
error_deallocate_error_list(ErrorListP error_list)
94
			    PROTO_T (ErrorListP error_list)
-
 
95
{
124
{
96
    while (error_list) {
125
    while (error_list) {
97
	ErrorListP tmp = error_list;
126
	ErrorListP tmp = error_list;
98
 
127
 
99
	if (error_list->tag == ERROR_TAG_STRING) {
128
	if (error_list->tag == ERROR_TAG_STRING) {
100
	    nstring_destroy (&(error_list->u.string));
129
	    nstring_destroy(&(error_list->u.string));
101
	}
130
	}
102
	error_list = error_list->next;
131
	error_list = error_list->next;
103
	DEALLOCATE (tmp);
132
	DEALLOCATE(tmp);
104
    }
133
    }
105
}
134
}
106
 
135
 
107
static ErrorListP
136
static ErrorListP
108
error_parse_message PROTO_N ((message))
137
error_parse_message(CStringP message)
109
		    PROTO_T (CStringP message)
-
 
110
{
138
{
111
    ErrorListP  error_list;
139
    ErrorListP  error_list;
112
    ErrorListP *error_list_next = &error_list;
140
    ErrorListP *error_list_next = &error_list;
113
    CStringP    message_copy    = cstring_duplicate (message);
141
    CStringP    message_copy    = cstring_duplicate(message);
114
    CStringP    scan            = message = message_copy;
142
    CStringP    scan            = message = message_copy;
115
 
143
 
116
    while (*scan) {
144
    while (*scan) {
117
	if ((*scan ++ == '$') && (*scan == '{')) {
145
	if ((*scan++ == '$') && (*scan == '{')) {
118
	    if (scan > (message + 1)) {
146
	    if (scan > (message + 1)) {
119
		ErrorListP tmp = ALLOCATE (ErrorListT);
147
		ErrorListP tmp = ALLOCATE(ErrorListT);
120
 
148
 
121
		tmp->tag  = ERROR_TAG_STRING;
149
		tmp->tag  = ERROR_TAG_STRING;
122
		scan [-1] = '\0';
150
		scan[-1] = '\0';
123
		nstring_copy_cstring (&(tmp->u.string), message);
151
		nstring_copy_cstring(&(tmp->u.string), message);
124
		*error_list_next = tmp;
152
		*error_list_next = tmp;
125
		error_list_next  = &(tmp->next);
153
		error_list_next  = &(tmp->next);
126
	    }
154
	    }
127
	    scan ++;
155
	    scan++;
128
	    message = scan;
156
	    message = scan;
129
	    while (*scan != '}') {
157
	    while (*scan != '}') {
130
		if ((*scan == '\0') || (*scan == '$') || (*scan == '{') ||
158
		if ((*scan == '\0') || (*scan == '$') || (*scan == '{') ||
131
		    ((!syntax_is_printable (*scan)) && (*scan != ' '))) {
159
		    ((!syntax_is_printable(*scan)) && (*scan != ' '))) {
132
		    *error_list_next = NIL (ErrorListP);
160
		    *error_list_next = NIL(ErrorListP);
133
		    error_deallocate_error_list (error_list);
161
		    error_deallocate_error_list(error_list);
134
		    return (NIL (ErrorListP));
162
		    return(NIL(ErrorListP));
135
		}
163
		}
136
		scan ++;
164
		scan++;
137
	    }
165
	    }
138
	    if (scan ++ > message) {
166
	    if (scan++ > message) {
139
		ErrorListP tmp = ALLOCATE (ErrorListT);
167
		ErrorListP tmp = ALLOCATE(ErrorListT);
140
		CStringP   tag;
168
		CStringP   tag;
141
 
169
 
142
		tmp->tag   = ERROR_TAG_TAG;
170
		tmp->tag   = ERROR_TAG_TAG;
143
		scan [-1]  = '\0';
171
		scan[-1] = '\0';
144
		tag        = cstring_duplicate (message);
172
		tag        = cstring_duplicate(message);
145
		tmp->u.tag = error_define_tag (tag);
173
		tmp->u.tag = error_define_tag(tag);
146
		if (tmp->u.tag->name != tag) {
174
		if (tmp->u.tag->name != tag) {
147
		    DEALLOCATE (tag);
175
		    DEALLOCATE(tag);
148
		}
176
		}
149
		*error_list_next = tmp;
177
		*error_list_next = tmp;
150
		error_list_next  = &(tmp->next);
178
		error_list_next  = &(tmp->next);
151
	    }
179
	    }
152
	    message = scan;
180
	    message = scan;
153
	}
181
	}
154
    }
182
    }
155
    if (scan > message) {
183
    if (scan > message) {
156
	ErrorListP tmp = ALLOCATE (ErrorListT);
184
	ErrorListP tmp = ALLOCATE(ErrorListT);
157
 
185
 
158
	tmp->tag = ERROR_TAG_STRING;
186
	tmp->tag = ERROR_TAG_STRING;
159
	nstring_copy_cstring (&(tmp->u.string), message);
187
	nstring_copy_cstring(&(tmp->u.string), message);
160
	*error_list_next = tmp;
188
	*error_list_next = tmp;
161
	error_list_next  = &(tmp->next);
189
	error_list_next  = &(tmp->next);
162
    }
190
    }
163
    *error_list_next = NIL (ErrorListP);
191
    *error_list_next = NIL(ErrorListP);
164
    DEALLOCATE (message_copy);
192
    DEALLOCATE(message_copy);
165
    return (error_list);
193
    return(error_list);
166
}
194
}
167
 
195
 
168
static void
196
static void
169
write_error_list PROTO_N ((ostream, error_list, error, proc, closure))
197
write_error_list(OStreamP ostream, ErrorListP error_list, ErrorP error,
170
		 PROTO_T (OStreamP   ostream X
-
 
171
			  ErrorListP error_list X
-
 
172
			  ErrorP     error X
-
 
173
			  ErrorProcP proc X
-
 
174
			  GenericP   closure)
198
		 ErrorProcP proc, GenericP closure)
175
{
199
{
176
    while (error_list) {
200
    while (error_list) {
177
	switch (error_list->tag) EXHAUSTIVE {
201
	switch (error_list->tag)EXHAUSTIVE {
178
	  case ERROR_TAG_STRING:
202
	  case ERROR_TAG_STRING:
179
	    write_nstring (ostream, &(error_list->u.string));
203
	    write_nstring(ostream, &(error_list->u.string));
180
	    break;
204
	    break;
181
	  case ERROR_TAG_TAG:
205
	  case ERROR_TAG_TAG:
182
	    if (error_list->u.tag == etag_program) {
206
	    if (error_list->u.tag == etag_program) {
183
		write_cstring (ostream, program_name);
207
		write_cstring(ostream, program_name);
184
	    } else if (error_list->u.tag == etag_severity) {
208
	    } else if (error_list->u.tag == etag_severity) {
185
		EStringP estring =
209
		EStringP estring =
186
		    severity_data [(error->severity)].estring;
210
		    severity_data[(error->severity)].estring;
187
 
211
 
188
		write_cstring (ostream, error_string_contents (estring));
212
		write_cstring(ostream, error_string_contents(estring));
189
	    } else if (error_list->u.tag == etag_error_name) {
213
	    } else if (error_list->u.tag == etag_error_name) {
190
		write_cstring (ostream, error->name);
214
		write_cstring(ostream, error->name);
191
	    } else if (error_list->u.tag == etag_dollar) {
215
	    } else if (error_list->u.tag == etag_dollar) {
192
		write_char (ostream, '$');
216
		write_char(ostream, '$');
193
	    } else if (error_list->u.tag == etag_ocb) {
217
	    } else if (error_list->u.tag == etag_ocb) {
194
		write_char (ostream, '{');
218
		write_char(ostream, '{');
195
	    } else if (error_list->u.tag == etag_ccb) {
219
	    } else if (error_list->u.tag == etag_ccb) {
196
		write_char (ostream, '}');
220
		write_char(ostream, '}');
197
	    } else if (proc) {
221
	    } else if (proc) {
198
		((*proc) (ostream, error_list->u.tag, closure));
222
		((*proc)(ostream, error_list->u.tag, closure));
199
	    }
223
	    }
200
	    break;
224
	    break;
201
	}
225
	}
202
	error_list = error_list->next;
226
	error_list = error_list->next;
203
    }
227
    }
204
}
228
}
205
 
229
 
206
static void
230
static void
207
write_error_list_text PROTO_N ((ostream, error_list))
231
write_error_list_text(OStreamP ostream, ErrorListP error_list)
208
		      PROTO_T (OStreamP   ostream X
-
 
209
			       ErrorListP error_list)
-
 
210
{
232
{
211
    NStringP nstring;
233
    NStringP nstring;
212
    CStringP contents;
234
    CStringP contents;
213
    unsigned length;
235
    unsigned length;
214
 
236
 
215
    write_char (ostream, '"');
237
    write_char(ostream, '"');
216
    while (error_list) {
238
    while (error_list) {
217
	switch (error_list->tag) EXHAUSTIVE {
239
	switch (error_list->tag)EXHAUSTIVE {
218
	  case ERROR_TAG_STRING:
240
	  case ERROR_TAG_STRING:
219
	    nstring  = &(error_list->u.string);
241
	    nstring  = &(error_list->u.string);
220
	    contents = nstring_contents (nstring);
242
	    contents = nstring_contents(nstring);
221
	    length   = nstring_length (nstring);
243
	    length   = nstring_length(nstring);
222
 
244
 
223
	    while (length --) {
245
	    while (length--) {
224
		switch (*contents) {
246
		switch (*contents) {
225
		  case '\n':
247
		  case '\n':
226
		    write_cstring (ostream, "\\n\\");
248
		    write_cstring(ostream, "\\n\\");
227
		    write_newline (ostream);
249
		    write_newline(ostream);
228
		    break;
250
		    break;
229
		  case '"':
251
		  case '"':
230
		    write_cstring (ostream, "\\\"");
252
		    write_cstring(ostream, "\\\"");
231
		    break;
253
		    break;
232
		  default:
254
		  default:
233
		    ASSERT (*contents != '\0');
255
		    ASSERT(*contents != '\0');
234
		    write_char (ostream, *contents);
256
		    write_char(ostream, *contents);
235
		    break;
257
		    break;
236
		}
258
		}
237
		contents ++;
259
		contents++;
238
	    }
260
	    }
239
	    break;
261
	    break;
240
	  case ERROR_TAG_TAG:
262
	  case ERROR_TAG_TAG:
241
	    write_cstring (ostream, "${");
263
	    write_cstring(ostream, "${");
242
	    write_cstring (ostream, error_list->u.tag->name);
264
	    write_cstring(ostream, error_list->u.tag->name);
243
	    write_char (ostream, '}');
265
	    write_char(ostream, '}');
244
	    break;
266
	    break;
245
	}
267
	}
246
	error_list = error_list->next;
268
	error_list = error_list->next;
247
    }
269
    }
248
    write_char (ostream, '"');
270
    write_char(ostream, '"');
249
}
271
}
250
 
272
 
251
static void
273
static void
252
write_error_table PROTO_N ((ostream))
274
write_error_table(OStreamP ostream)
253
		  PROTO_T (OStreamP ostream)
-
 
254
{
275
{
255
    unsigned i;
276
    unsigned i;
256
 
277
 
257
    for (i = 0; i < ERROR_TABLE_SIZE; i ++) {
278
    for (i = 0; i < ERROR_TABLE_SIZE; i++) {
258
	ErrorP error = error_table [i];
279
	ErrorP error = error_table[i];
259
 
280
 
260
	while (error) {
281
	while (error) {
261
	    write_char (ostream, '\'');
282
	    write_char(ostream, '\'');
262
	    write_cstring (ostream, error->name);
283
	    write_cstring(ostream, error->name);
263
	    write_char (ostream, '\'');
284
	    write_char(ostream, '\'');
264
	    write_newline (ostream);
285
	    write_newline(ostream);
265
	    write_cstring (ostream, "    ");
286
	    write_cstring(ostream, "    ");
266
	    write_error_list_text (ostream, error->error_list);
287
	    write_error_list_text(ostream, error->error_list);
267
	    write_newline (ostream);
288
	    write_newline(ostream);
268
	    error = error->next;
289
	    error = error->next;
269
	}
290
	}
270
    }
291
    }
271
}
292
}
272
 
293
 
273
static void
294
static void
274
write_string_table PROTO_N ((ostream))
295
write_string_table(OStreamP ostream)
275
		   PROTO_T (OStreamP ostream)
-
 
276
{
296
{
277
    unsigned i;
297
    unsigned i;
278
 
298
 
279
    for (i = 0; i < STRING_TABLE_SIZE; i ++) {
299
    for (i = 0; i < STRING_TABLE_SIZE; i++) {
280
	EStringP string = string_table [i];
300
	EStringP string = string_table[i];
281
 
301
 
282
	while (string) {
302
	while (string) {
283
	    CStringP contents = string->contents;
303
	    CStringP contents = string->contents;
284
 
304
 
285
	    write_char (ostream, '\'');
305
	    write_char(ostream, '\'');
286
	    write_cstring (ostream, string->name);
306
	    write_cstring(ostream, string->name);
287
	    write_char (ostream, '\'');
307
	    write_char(ostream, '\'');
288
	    write_newline (ostream);
308
	    write_newline(ostream);
289
	    write_cstring (ostream, "    ");
309
	    write_cstring(ostream, "    ");
290
	    write_char (ostream, '"');
310
	    write_char(ostream, '"');
291
	    while (*contents) {
311
	    while (*contents) {
292
		switch (*contents) {
312
		switch (*contents) {
293
		  case '\n':
313
		  case '\n':
294
		    write_cstring (ostream, "\\n\\");
314
		    write_cstring(ostream, "\\n\\");
295
		    write_newline (ostream);
315
		    write_newline(ostream);
296
		    break;
316
		    break;
297
		  case '"':
317
		  case '"':
298
		    write_cstring (ostream, "\\\"");
318
		    write_cstring(ostream, "\\\"");
299
		    break;
319
		    break;
300
		  default:
320
		  default:
301
		    write_char (ostream, *contents);
321
		    write_char(ostream, *contents);
302
		    break;
322
		    break;
303
		}
323
		}
304
		contents ++;
324
		contents++;
305
	    }
325
	    }
306
	    write_char (ostream, '"');
326
	    write_char(ostream, '"');
307
	    write_newline (ostream);
327
	    write_newline(ostream);
308
	    string = string->next;
328
	    string = string->next;
309
	}
329
	}
310
    }
330
    }
311
}
331
}
312
 
332
 
313
/*--------------------------------------------------------------------------*/
333
/*--------------------------------------------------------------------------*/
314
 
334
 
315
void
335
void
316
error_init PROTO_N ((name, proc))
-
 
317
	   PROTO_T (CStringP       name X
-
 
318
		    ErrorInitProcP proc)
336
error_init(CStringP name, ErrorInitProcP proc)
319
{
337
{
320
    static CStringP prefix = "${program name}: ${severity}: ";
338
    static CStringP prefix = "${program name}: ${severity}: ";
321
 
339
 
322
    program_name = name;
340
    program_name = name;
323
    while (*name) {
341
    while (*name) {
324
	if (*name ++ == '/') {
342
	if (*name++ == '/') {
325
	    program_name = name;
343
	    program_name = name;
326
	}
344
	}
327
    }
345
    }
328
    init_proc       = proc;
346
    init_proc       = proc;
329
    etag_program    = error_define_tag ("program name");
347
    etag_program    = error_define_tag("program name");
330
    etag_severity   = error_define_tag ("severity");
348
    etag_severity   = error_define_tag("severity");
331
    etag_error_name = error_define_tag ("this error name");
349
    etag_error_name = error_define_tag("this error name");
332
    etag_dollar     = error_define_tag ("dollar");
350
    etag_dollar     = error_define_tag("dollar");
333
    etag_ocb        = error_define_tag ("open brace");
351
    etag_ocb        = error_define_tag("open brace");
334
    etag_ccb        = error_define_tag ("close brace");
352
    etag_ccb        = error_define_tag("close brace");
335
    error_prefix    = error_parse_message (prefix);
353
    error_prefix    = error_parse_message(prefix);
336
    error_intern_strings (severity_data);
354
    error_intern_strings(severity_data);
337
    ostream_buffer (ostream_error);
355
    ostream_buffer(ostream_error);
338
}
356
}
339
 
357
 
340
void
358
void
341
error_call_init_proc PROTO_Z ()
359
error_call_init_proc(void)
342
{
360
{
343
    if (init_proc) {
361
    if (init_proc) {
344
	(*init_proc) ();
362
	(*init_proc)();
345
	init_proc = NIL (ErrorInitProcP);
363
	init_proc = NIL(ErrorInitProcP);
346
    }
364
    }
347
}
365
}
348
 
366
 
349
ETagP
367
ETagP
350
error_define_tag PROTO_N ((name))
368
error_define_tag(CStringP name)
351
		 PROTO_T (CStringP name)
-
 
352
{
369
{
353
    unsigned hash   = (cstring_hash_value (name) % TAG_TABLE_SIZE);
370
    unsigned hash   = (cstring_hash_value(name)% TAG_TABLE_SIZE);
354
    ETagP   *entryp = &(tag_table [hash]);
371
    ETagP   *entryp = &(tag_table[hash]);
355
    ETagP    entry;
372
    ETagP    entry;
356
 
373
 
357
    while ((entry = *entryp) != NIL (ETagP)) {
374
    while ((entry = *entryp) != NIL(ETagP)) {
358
	if (cstring_equal (entry->name, name)) {
375
	if (cstring_equal(entry->name, name)) {
359
	    return (entry);
376
	    return(entry);
360
	}
377
	}
361
	entryp = &(entry->next);
378
	entryp = &(entry->next);
362
    }
379
    }
363
    entry       = ALLOCATE (ETagT);
380
    entry       = ALLOCATE(ETagT);
364
    entry->next = NIL (ETagP);
381
    entry->next = NIL(ETagP);
365
    entry->name = name;
382
    entry->name = name;
366
    *entryp     = entry;
383
    *entryp     = entry;
367
    return (entry);
384
    return(entry);
368
}
385
}
369
 
386
 
370
ErrorP
387
ErrorP
371
error_define_error PROTO_N ((name, severity, message, data))
388
error_define_error(CStringP name, ESeverityT severity, CStringP message,
372
		   PROTO_T (CStringP   name X
-
 
373
			    ESeverityT severity X
-
 
374
			    CStringP   message X
-
 
375
			    GenericP   data)
389
		   GenericP data)
376
{
390
{
377
    ErrorListP error_list = error_parse_message (message);
391
    ErrorListP error_list = error_parse_message(message);
378
    unsigned   hash       = (cstring_hash_value (name) % ERROR_TABLE_SIZE);
392
    unsigned   hash       = (cstring_hash_value(name)% ERROR_TABLE_SIZE);
379
    ErrorP    *entryp     = &(error_table [hash]);
393
    ErrorP    *entryp     = &(error_table[hash]);
380
    ErrorP     entry;
394
    ErrorP     entry;
381
 
395
 
382
    while ((entry = *entryp) != NIL (ErrorP)) {
396
    while ((entry = *entryp) != NIL(ErrorP)) {
383
	ASSERT (!cstring_equal (entry->name, name));
397
	ASSERT(!cstring_equal(entry->name, name));
384
	entryp = &(entry->next);
398
	entryp = &(entry->next);
385
    }
399
    }
386
    ASSERT (error_list);
400
    ASSERT(error_list);
387
    entry             = ALLOCATE (ErrorT);
401
    entry             = ALLOCATE(ErrorT);
388
    entry->next       = NIL (ErrorP);
402
    entry->next       = NIL(ErrorP);
389
    entry->name       = name;
403
    entry->name       = name;
390
    entry->severity   = severity;
404
    entry->severity   = severity;
391
    entry->error_list = error_list;
405
    entry->error_list = error_list;
392
    entry->data       = data;
406
    entry->data       = data;
393
    *entryp           = entry;
407
    *entryp           = entry;
394
    return (entry);
408
    return(entry);
395
}
409
}
396
 
410
 
397
void
411
void
398
error_intern_tags PROTO_N ((vector))
412
error_intern_tags(ETagDataP vector)
399
		  PROTO_T (ETagDataP vector)
-
 
400
{
413
{
401
    while (vector->name) {
414
    while (vector->name) {
402
	ETagP tag = error_define_tag (vector->name);
415
	ETagP tag = error_define_tag(vector->name);
403
 
416
 
404
	vector->tag = tag;
417
	vector->tag = tag;
405
	vector ++;
418
	vector++;
406
    }
419
    }
407
}
420
}
408
 
421
 
409
void
422
void
410
error_intern_errors PROTO_N ((vector))
423
error_intern_errors(ErrorDataP vector)
411
		    PROTO_T (ErrorDataP vector)
-
 
412
{
424
{
413
    while (vector->s.name) {
425
    while (vector->s.name) {
414
	ErrorP error = error_define_error (vector->s.name, vector->s.severity,
426
	ErrorP error = error_define_error(vector->s.name, vector->s.severity,
415
					   vector->s.message, vector->s.data);
427
					   vector->s.message, vector->s.data);
416
 
428
 
417
	vector->error = error;
429
	vector->error = error;
418
	vector ++;
430
	vector++;
419
    }
431
    }
420
}
432
}
421
 
433
 
422
ErrorStatusT
434
ErrorStatusT
423
error_redefine_error PROTO_N ((name, message))
435
error_redefine_error(CStringP name, CStringP message)
424
		     PROTO_T (CStringP name X
-
 
425
			      CStringP message)
-
 
426
{
436
{
427
    error_call_init_proc ();
437
    error_call_init_proc();
428
    {
438
    {
429
	unsigned hash  = (cstring_hash_value (name) % ERROR_TABLE_SIZE);
439
	unsigned hash  = (cstring_hash_value(name)% ERROR_TABLE_SIZE);
430
	ErrorP   entry = (error_table [hash]);
440
	ErrorP   entry = (error_table[hash]);
431
 
441
 
432
	while (entry) {
442
	while (entry) {
433
	    if (cstring_equal (entry->name, name)) {
443
	    if (cstring_equal(entry->name, name)) {
434
		ErrorListP error_list = error_parse_message (message);
444
		ErrorListP error_list = error_parse_message(message);
435
 
445
 
436
		if (error_list == NIL (ErrorListP)) {
446
		if (error_list == NIL(ErrorListP)) {
437
		    return (ERROR_STATUS_BAD_MESSAGE);
447
		    return(ERROR_STATUS_BAD_MESSAGE);
438
		}
448
		}
439
		error_deallocate_error_list (entry->error_list);
449
		error_deallocate_error_list(entry->error_list);
440
		entry->error_list = error_list;
450
		entry->error_list = error_list;
441
		return (ERROR_STATUS_SUCCESS);
451
		return(ERROR_STATUS_SUCCESS);
442
	    }
452
	    }
443
	    entry = entry->next;
453
	    entry = entry->next;
444
	}
454
	}
445
	return (ERROR_STATUS_BAD_ERROR);
455
	return(ERROR_STATUS_BAD_ERROR);
446
    }
456
    }
447
}
457
}
448
 
458
 
449
ErrorP
459
ErrorP
450
error_lookup_error PROTO_N ((name))
460
error_lookup_error(CStringP name)
451
		   PROTO_T (CStringP name)
-
 
452
{
461
{
453
    error_call_init_proc ();
462
    error_call_init_proc();
454
    {
463
    {
455
	unsigned hash  = (cstring_hash_value (name) % ERROR_TABLE_SIZE);
464
	unsigned hash  = (cstring_hash_value(name)% ERROR_TABLE_SIZE);
456
	ErrorP   entry = (error_table [hash]);
465
	ErrorP   entry = (error_table[hash]);
457
 
466
 
458
	while (entry) {
467
	while (entry) {
459
	    if (cstring_equal (entry->name, name)) {
468
	    if (cstring_equal(entry->name, name)) {
460
		return (entry);
469
		return(entry);
461
	    }
470
	    }
462
	    entry = entry->next;
471
	    entry = entry->next;
463
	}
472
	}
464
	return (NIL (ErrorP));
473
	return(NIL(ErrorP));
465
    }
474
    }
466
}
475
}
467
 
476
 
468
GenericP
477
GenericP
469
error_data PROTO_N ((error))
478
error_data(ErrorP error)
470
	   PROTO_T (ErrorP error)
-
 
471
{
479
{
472
    return (error->data);
480
    return(error->data);
473
}
481
}
474
 
482
 
475
void
483
void
476
error_report PROTO_N ((error, proc, closure))
484
error_report(ErrorP error, ErrorProcP proc, GenericP closure)
477
	     PROTO_T (ErrorP     error X
-
 
478
		      ErrorProcP proc X
-
 
479
		      GenericP   closure)
-
 
480
{
485
{
481
    if ((error->severity) >= min_severity) {
486
    if ((error->severity) >= min_severity) {
482
	write_error_list (ostream_error, error_prefix, error, NIL (ErrorProcP),
487
	write_error_list(ostream_error, error_prefix, error, NIL(ErrorProcP),
483
			  NIL (GenericP));
488
			 NIL(GenericP));
484
	write_error_list (ostream_error, error->error_list, error, proc,
489
	write_error_list(ostream_error, error->error_list, error, proc,
485
			  closure);
490
			 closure);
486
	write_newline (ostream_error);
491
	write_newline(ostream_error);
487
	ostream_flush (ostream_error);
492
	ostream_flush(ostream_error);
488
    }
493
    }
489
    if ((error->severity) > max_reported) {
494
    if ((error->severity) > max_reported) {
490
	max_reported = error->severity;
495
	max_reported = error->severity;
491
    }
496
    }
492
    if ((error->severity) >= ERROR_SEVERITY_FATAL) {
497
    if ((error->severity) >= ERROR_SEVERITY_FATAL) {
493
	if (error->severity == ERROR_SEVERITY_INTERNAL) {
498
	if (error->severity == ERROR_SEVERITY_INTERNAL) {
494
	    abort ();
499
	    abort();
495
	    UNREACHED;
500
	    UNREACHED;
496
	}
501
	}
497
	exit (EXIT_FAILURE);
502
	exit(EXIT_FAILURE);
498
	UNREACHED;
503
	UNREACHED;
499
    }
504
    }
500
}
505
}
501
 
506
 
502
void
507
void
503
error_set_min_report_severity PROTO_N ((severity))
508
error_set_min_report_severity(ESeverityT severity)
504
			      PROTO_T (ESeverityT severity)
-
 
505
{
509
{
506
    min_severity = severity;
510
    min_severity = severity;
507
}
511
}
508
 
512
 
509
ESeverityT
513
ESeverityT
510
error_get_min_report_severity PROTO_Z ()
514
error_get_min_report_severity(void)
511
{
515
{
512
    return (min_severity);
516
    return(min_severity);
513
}
517
}
514
 
518
 
515
ESeverityT
519
ESeverityT
516
error_max_reported_severity PROTO_Z ()
520
error_max_reported_severity(void)
517
{
521
{
518
    return (max_reported);
522
    return(max_reported);
519
}
523
}
520
 
524
 
521
void
525
void
522
error_set_severity_message PROTO_N ((severity, message))
526
error_set_severity_message(ESeverityT severity, CStringP message)
523
			   PROTO_T (ESeverityT severity X
-
 
524
				    CStringP   message)
-
 
525
{
527
{
526
    severity_data [severity].estring->contents = message;
528
    severity_data[severity].estring->contents = message;
527
}
529
}
528
 
530
 
529
BoolT
531
BoolT
530
error_set_prefix_message PROTO_N ((message))
532
error_set_prefix_message(CStringP message)
531
			 PROTO_T (CStringP message)
-
 
532
{
533
{
533
    ErrorListP error_list = error_parse_message (message);
534
    ErrorListP error_list = error_parse_message(message);
534
 
535
 
535
    if (error_list == NIL (ErrorListP)) {
536
    if (error_list == NIL(ErrorListP)) {
536
	return (FALSE);
537
	return(FALSE);
537
    }
538
    }
538
    error_deallocate_error_list (error_prefix);
539
    error_deallocate_error_list(error_prefix);
539
    error_prefix = error_list;
540
    error_prefix = error_list;
540
    return (TRUE);
541
    return(TRUE);
541
}
542
}
542
 
543
 
543
EStringP
544
EStringP
544
error_define_string PROTO_N ((name, contents))
545
error_define_string(CStringP name, CStringP contents)
545
		    PROTO_T (CStringP name X
-
 
546
			     CStringP contents)
-
 
547
{
546
{
548
    unsigned  hash   = (cstring_hash_value (name) % STRING_TABLE_SIZE);
547
    unsigned  hash   = (cstring_hash_value(name)% STRING_TABLE_SIZE);
549
    EStringP *entryp = &(string_table [hash]);
548
    EStringP *entryp = &(string_table[hash]);
550
    EStringP  entry;
549
    EStringP  entry;
551
 
550
 
552
    while ((entry = *entryp) != NIL (EStringP)) {
551
    while ((entry = *entryp) != NIL(EStringP)) {
553
	ASSERT (!cstring_equal (entry->name, name));
552
	ASSERT(!cstring_equal(entry->name, name));
554
	entryp = &(entry->next);
553
	entryp = &(entry->next);
555
    }
554
    }
556
    entry           = ALLOCATE (EStringT);
555
    entry           = ALLOCATE(EStringT);
557
    entry->next     = NIL (EStringP);
556
    entry->next     = NIL(EStringP);
558
    entry->name     = name;
557
    entry->name     = name;
559
    entry->contents = contents;
558
    entry->contents = contents;
560
    *entryp         = entry;
559
    *entryp         = entry;
561
    return (entry);
560
    return(entry);
562
}
561
}
563
 
562
 
564
void
563
void
565
error_intern_strings PROTO_N ((vector))
564
error_intern_strings(EStringDataP vector)
566
		     PROTO_T (EStringDataP vector)
-
 
567
{
565
{
568
    while (vector->s.name) {
566
    while (vector->s.name) {
569
	EStringP estring = error_define_string (vector->s.name,
567
	EStringP estring = error_define_string(vector->s.name,
570
						vector->s.contents);
568
					       vector->s.contents);
571
 
569
 
572
	vector->estring = estring;
570
	vector->estring = estring;
573
	vector ++;
571
	vector++;
574
    }
572
    }
575
}
573
}
576
 
574
 
577
BoolT
575
BoolT
578
error_redefine_string PROTO_N ((name, contents))
576
error_redefine_string(CStringP name, CStringP contents)
579
		      PROTO_T (CStringP name X
-
 
580
			       CStringP contents)
-
 
581
{
577
{
582
    unsigned hash  = (cstring_hash_value (name) % STRING_TABLE_SIZE);
578
    unsigned hash  = (cstring_hash_value(name)% STRING_TABLE_SIZE);
583
    EStringP entry = (string_table [hash]);
579
    EStringP entry = (string_table[hash]);
584
 
580
 
585
    while (entry) {
581
    while (entry) {
586
	if (cstring_equal (entry->name, name)) {
582
	if (cstring_equal(entry->name, name)) {
587
	    entry->contents = contents;
583
	    entry->contents = contents;
588
	    return (TRUE);
584
	    return(TRUE);
589
	}
585
	}
590
	entry = entry->next;
586
	entry = entry->next;
591
    }
587
    }
592
    return (FALSE);
588
    return(FALSE);
593
}
589
}
594
 
590
 
595
EStringP
591
EStringP
596
error_lookup_string PROTO_N ((name))
592
error_lookup_string(CStringP name)
597
		    PROTO_T (CStringP name)
-
 
598
{
593
{
599
    unsigned hash  = (cstring_hash_value (name) % STRING_TABLE_SIZE);
594
    unsigned hash  = (cstring_hash_value(name)% STRING_TABLE_SIZE);
600
    EStringP entry = (string_table [hash]);
595
    EStringP entry = (string_table[hash]);
601
 
596
 
602
    while (entry) {
597
    while (entry) {
603
	if (cstring_equal (entry->name, name)) {
598
	if (cstring_equal(entry->name, name)) {
604
	    return (entry);
599
	    return(entry);
605
	}
600
	}
606
	entry = entry->next;
601
	entry = entry->next;
607
    }
602
    }
608
    return (NIL (EStringP));
603
    return(NIL(EStringP));
609
}
604
}
610
 
605
 
611
CStringP
606
CStringP
612
error_string_contents PROTO_N ((estring))
607
error_string_contents(EStringP estring)
613
		      PROTO_T (EStringP estring)
-
 
614
{
608
{
615
    return (estring->contents);
609
    return(estring->contents);
616
}
610
}
617
 
611
 
618
void
612
void
619
write_error_file PROTO_N ((ostream))
613
write_error_file(OStreamP ostream)
620
		 PROTO_T (OStreamP ostream)
-
 
621
{
614
{
622
    error_call_init_proc ();
615
    error_call_init_proc();
623
    write_cstring (ostream, "%prefix%");
616
    write_cstring(ostream, "%prefix%");
624
    write_newline (ostream);
617
    write_newline(ostream);
625
    write_cstring (ostream, "    ");
618
    write_cstring(ostream, "    ");
626
    write_error_list_text (ostream, error_prefix);
619
    write_error_list_text(ostream, error_prefix);
627
    write_newline (ostream);
620
    write_newline(ostream);
628
    write_newline (ostream);
621
    write_newline(ostream);
629
    write_cstring (ostream, "%errors%");
622
    write_cstring(ostream, "%errors%");
630
    write_newline (ostream);
623
    write_newline(ostream);
631
    write_error_table (ostream);
624
    write_error_table(ostream);
632
    write_newline (ostream);
625
    write_newline(ostream);
633
    write_cstring (ostream, "%strings%");
626
    write_cstring(ostream, "%strings%");
634
    write_newline (ostream);
627
    write_newline(ostream);
635
    write_string_table (ostream);
628
    write_string_table(ostream);
636
}
629
}
637

630

638
/*
631
/*
639
 * Local variables(smf):
632
 * Local variables(smf):
640
 * eval: (include::add-path-entry "../os-interface" "../generated")
633
 * eval: (include::add-path-entry "../os-interface" "../generated")