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-2006 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, 
170
		 PROTO_T (OStreamP   ostream X
-
 
171
			  ErrorListP error_list X
-
 
172
			  ErrorP     error X
198
			  ErrorP     error, 
173
			  ErrorProcP proc X
199
			  ErrorProcP proc, 
174
			  GenericP   closure)
200
			  GenericP   closure)
175
{
201
{
176
    while (error_list) {
202
    while (error_list) {
177
	switch (error_list->tag) EXHAUSTIVE {
203
	switch (error_list->tag)EXHAUSTIVE {
178
	  case ERROR_TAG_STRING:
204
	  case ERROR_TAG_STRING:
179
	    write_nstring (ostream, &(error_list->u.string));
205
	    write_nstring(ostream, & (error_list->u.string));
180
	    break;
206
	    break;
181
	  case ERROR_TAG_TAG:
207
	  case ERROR_TAG_TAG:
182
	    if (error_list->u.tag == etag_program) {
208
	    if (error_list->u.tag == etag_program) {
183
		write_cstring (ostream, program_name);
209
		write_cstring(ostream, program_name);
184
	    } else if (error_list->u.tag == etag_severity) {
210
	    } else if (error_list->u.tag == etag_severity) {
185
		EStringP estring =
211
		EStringP estring =
186
		    severity_data [(error->severity)].estring;
212
		    severity_data[(error->severity)].estring;
187
 
213
 
188
		write_cstring (ostream, error_string_contents (estring));
214
		write_cstring(ostream, error_string_contents(estring));
189
	    } else if (error_list->u.tag == etag_error_name) {
215
	    } else if (error_list->u.tag == etag_error_name) {
190
		write_cstring (ostream, error->name);
216
		write_cstring(ostream, error->name);
191
	    } else if (error_list->u.tag == etag_dollar) {
217
	    } else if (error_list->u.tag == etag_dollar) {
192
		write_char (ostream, '$');
218
		write_char(ostream, '$');
193
	    } else if (error_list->u.tag == etag_ocb) {
219
	    } else if (error_list->u.tag == etag_ocb) {
194
		write_char (ostream, '{');
220
		write_char(ostream, '{');
195
	    } else if (error_list->u.tag == etag_ccb) {
221
	    } else if (error_list->u.tag == etag_ccb) {
196
		write_char (ostream, '}');
222
		write_char(ostream, '}');
197
	    } else if (proc) {
223
	    } else if (proc) {
198
		((*proc) (ostream, error_list->u.tag, closure));
224
		((*proc)(ostream, error_list->u.tag, closure));
199
	    }
225
	    }
200
	    break;
226
	    break;
201
	}
227
	}
202
	error_list = error_list->next;
228
	error_list = error_list->next;
203
    }
229
    }
204
}
230
}
205
 
231
 
206
static void
232
static void
207
write_error_list_text PROTO_N ((ostream, error_list))
233
write_error_list_text(OStreamP   ostream,			       ErrorListP error_list)
208
		      PROTO_T (OStreamP   ostream X
-
 
209
			       ErrorListP error_list)
-
 
210
{
234
{
211
    NStringP nstring;
235
    NStringP nstring;
212
    CStringP contents;
236
    CStringP contents;
213
    unsigned length;
237
    unsigned length;
214
 
238
 
215
    write_char (ostream, '"');
239
    write_char(ostream, '"');
216
    while (error_list) {
240
    while (error_list) {
217
	switch (error_list->tag) EXHAUSTIVE {
241
	switch (error_list->tag)EXHAUSTIVE {
218
	  case ERROR_TAG_STRING:
242
	  case ERROR_TAG_STRING:
219
	    nstring  = &(error_list->u.string);
243
	    nstring  = & (error_list->u.string);
220
	    contents = nstring_contents (nstring);
244
	    contents = nstring_contents(nstring);
221
	    length   = nstring_length (nstring);
245
	    length   = nstring_length(nstring);
222
 
246
 
223
	    while (length --) {
247
	    while (length--) {
224
		switch (*contents) {
248
		switch (*contents) {
225
		  case '\n':
249
		  case '\n':
226
		    write_cstring (ostream, "\\n\\");
250
		    write_cstring(ostream, "\\n\\");
227
		    write_newline (ostream);
251
		    write_newline(ostream);
228
		    break;
252
		    break;
229
		  case '"':
253
		  case '"':
230
		    write_cstring (ostream, "\\\"");
254
		    write_cstring(ostream, "\\\"");
231
		    break;
255
		    break;
232
		  default:
256
		  default:
233
		    ASSERT (*contents != '\0');
257
		    ASSERT(*contents != '\0');
234
		    write_char (ostream, *contents);
258
		    write_char(ostream, *contents);
235
		    break;
259
		    break;
236
		}
260
		}
237
		contents ++;
261
		contents++;
238
	    }
262
	    }
239
	    break;
263
	    break;
240
	  case ERROR_TAG_TAG:
264
	  case ERROR_TAG_TAG:
241
	    write_cstring (ostream, "${");
265
	    write_cstring(ostream, "${");
242
	    write_cstring (ostream, error_list->u.tag->name);
266
	    write_cstring(ostream, error_list->u.tag->name);
243
	    write_char (ostream, '}');
267
	    write_char(ostream, '}');
244
	    break;
268
	    break;
245
	}
269
	}
246
	error_list = error_list->next;
270
	error_list = error_list->next;
247
    }
271
    }
248
    write_char (ostream, '"');
272
    write_char(ostream, '"');
249
}
273
}
250
 
274
 
251
static void
275
static void
252
write_error_table PROTO_N ((ostream))
276
write_error_table(OStreamP ostream)
253
		  PROTO_T (OStreamP ostream)
-
 
254
{
277
{
255
    unsigned i;
278
    unsigned i;
256
 
279
 
257
    for (i = 0; i < ERROR_TABLE_SIZE; i ++) {
280
    for (i = 0; i < ERROR_TABLE_SIZE; i++) {
258
	ErrorP error = error_table [i];
281
	ErrorP error = error_table[i];
259
 
282
 
260
	while (error) {
283
	while (error) {
261
	    write_char (ostream, '\'');
284
	    write_char(ostream, '\'');
262
	    write_cstring (ostream, error->name);
285
	    write_cstring(ostream, error->name);
263
	    write_char (ostream, '\'');
286
	    write_char(ostream, '\'');
264
	    write_newline (ostream);
287
	    write_newline(ostream);
265
	    write_cstring (ostream, "    ");
288
	    write_cstring(ostream, "    ");
266
	    write_error_list_text (ostream, error->error_list);
289
	    write_error_list_text(ostream, error->error_list);
267
	    write_newline (ostream);
290
	    write_newline(ostream);
268
	    error = error->next;
291
	    error = error->next;
269
	}
292
	}
270
    }
293
    }
271
}
294
}
272
 
295
 
273
static void
296
static void
274
write_string_table PROTO_N ((ostream))
297
write_string_table(OStreamP ostream)
275
		   PROTO_T (OStreamP ostream)
-
 
276
{
298
{
277
    unsigned i;
299
    unsigned i;
278
 
300
 
279
    for (i = 0; i < STRING_TABLE_SIZE; i ++) {
301
    for (i = 0; i < STRING_TABLE_SIZE; i++) {
280
	EStringP string = string_table [i];
302
	EStringP string = string_table[i];
281
 
303
 
282
	while (string) {
304
	while (string) {
283
	    CStringP contents = string->contents;
305
	    CStringP contents = string->contents;
284
 
306
 
285
	    write_char (ostream, '\'');
307
	    write_char(ostream, '\'');
286
	    write_cstring (ostream, string->name);
308
	    write_cstring(ostream, string->name);
287
	    write_char (ostream, '\'');
309
	    write_char(ostream, '\'');
288
	    write_newline (ostream);
310
	    write_newline(ostream);
289
	    write_cstring (ostream, "    ");
311
	    write_cstring(ostream, "    ");
290
	    write_char (ostream, '"');
312
	    write_char(ostream, '"');
291
	    while (*contents) {
313
	    while (*contents) {
292
		switch (*contents) {
314
		switch (*contents) {
293
		  case '\n':
315
		  case '\n':
294
		    write_cstring (ostream, "\\n\\");
316
		    write_cstring(ostream, "\\n\\");
295
		    write_newline (ostream);
317
		    write_newline(ostream);
296
		    break;
318
		    break;
297
		  case '"':
319
		  case '"':
298
		    write_cstring (ostream, "\\\"");
320
		    write_cstring(ostream, "\\\"");
299
		    break;
321
		    break;
300
		  default:
322
		  default:
301
		    write_char (ostream, *contents);
323
		    write_char(ostream, *contents);
302
		    break;
324
		    break;
303
		}
325
		}
304
		contents ++;
326
		contents++;
305
	    }
327
	    }
306
	    write_char (ostream, '"');
328
	    write_char(ostream, '"');
307
	    write_newline (ostream);
329
	    write_newline(ostream);
308
	    string = string->next;
330
	    string = string->next;
309
	}
331
	}
310
    }
332
    }
311
}
333
}
312
 
334
 
313
/*--------------------------------------------------------------------------*/
335
/*--------------------------------------------------------------------------*/
314
 
336
 
315
void
337
void
316
error_init PROTO_N ((name, proc))
-
 
317
	   PROTO_T (CStringP       name X
-
 
318
		    ErrorInitProcP proc)
338
error_init(CStringP       name,		    ErrorInitProcP proc)
319
{
339
{
320
    static CStringP prefix = "${program name}: ${severity}: ";
340
    static CStringP prefix = "${program name}: ${severity}: ";
321
 
341
 
322
    program_name = name;
342
    program_name = name;
323
    while (*name) {
343
    while (*name) {
324
	if (*name ++ == '/') {
344
	if (*name++ == '/') {
325
	    program_name = name;
345
	    program_name = name;
326
	}
346
	}
327
    }
347
    }
328
    init_proc       = proc;
348
    init_proc       = proc;
329
    etag_program    = error_define_tag ("program name");
349
    etag_program    = error_define_tag("program name");
330
    etag_severity   = error_define_tag ("severity");
350
    etag_severity   = error_define_tag("severity");
331
    etag_error_name = error_define_tag ("this error name");
351
    etag_error_name = error_define_tag("this error name");
332
    etag_dollar     = error_define_tag ("dollar");
352
    etag_dollar     = error_define_tag("dollar");
333
    etag_ocb        = error_define_tag ("open brace");
353
    etag_ocb        = error_define_tag("open brace");
334
    etag_ccb        = error_define_tag ("close brace");
354
    etag_ccb        = error_define_tag("close brace");
335
    error_prefix    = error_parse_message (prefix);
355
    error_prefix    = error_parse_message(prefix);
336
    error_intern_strings (severity_data);
356
    error_intern_strings(severity_data);
337
    ostream_buffer (ostream_error);
357
    ostream_buffer(ostream_error);
338
}
358
}
339
 
359
 
340
void
360
void
341
error_call_init_proc PROTO_Z ()
361
error_call_init_proc(void)
342
{
362
{
343
    if (init_proc) {
363
    if (init_proc) {
344
	(*init_proc) ();
364
	(*init_proc)();
345
	init_proc = NIL (ErrorInitProcP);
365
	init_proc = NIL(ErrorInitProcP);
346
    }
366
    }
347
}
367
}
348
 
368
 
349
ETagP
369
ETagP
350
error_define_tag PROTO_N ((name))
370
error_define_tag(CStringP name)
351
		 PROTO_T (CStringP name)
-
 
352
{
371
{
353
    unsigned hash   = (cstring_hash_value (name) % TAG_TABLE_SIZE);
372
    unsigned hash   = (cstring_hash_value(name)% TAG_TABLE_SIZE);
354
    ETagP   *entryp = &(tag_table [hash]);
373
    ETagP   *entryp = & (tag_table[hash]);
355
    ETagP    entry;
374
    ETagP    entry;
356
 
375
 
357
    while ((entry = *entryp) != NIL (ETagP)) {
376
    while ((entry = *entryp) != NIL(ETagP)) {
358
	if (cstring_equal (entry->name, name)) {
377
	if (cstring_equal(entry->name, name)) {
359
	    return (entry);
378
	    return(entry);
360
	}
379
	}
361
	entryp = &(entry->next);
380
	entryp = & (entry->next);
362
    }
381
    }
363
    entry       = ALLOCATE (ETagT);
382
    entry       = ALLOCATE(ETagT);
364
    entry->next = NIL (ETagP);
383
    entry->next = NIL(ETagP);
365
    entry->name = name;
384
    entry->name = name;
366
    *entryp     = entry;
385
    *entryp     = entry;
367
    return (entry);
386
    return(entry);
368
}
387
}
369
 
388
 
370
ErrorP
389
ErrorP
371
error_define_error PROTO_N ((name, severity, message, data))
390
error_define_error(CStringP   name,			    ESeverityT severity, 
372
		   PROTO_T (CStringP   name X
-
 
373
			    ESeverityT severity X
-
 
374
			    CStringP   message X
391
			    CStringP   message, 
375
			    GenericP   data)
392
			    GenericP   data)
376
{
393
{
377
    ErrorListP error_list = error_parse_message (message);
394
    ErrorListP error_list = error_parse_message(message);
378
    unsigned   hash       = (cstring_hash_value (name) % ERROR_TABLE_SIZE);
395
    unsigned   hash       = (cstring_hash_value(name)% ERROR_TABLE_SIZE);
379
    ErrorP    *entryp     = &(error_table [hash]);
396
    ErrorP    *entryp     = & (error_table[hash]);
380
    ErrorP     entry;
397
    ErrorP     entry;
381
 
398
 
382
    while ((entry = *entryp) != NIL (ErrorP)) {
399
    while ((entry = *entryp) != NIL(ErrorP)) {
383
	ASSERT (!cstring_equal (entry->name, name));
400
	ASSERT(!cstring_equal(entry->name, name));
384
	entryp = &(entry->next);
401
	entryp = & (entry->next);
385
    }
402
    }
386
    ASSERT (error_list);
403
    ASSERT(error_list);
387
    entry             = ALLOCATE (ErrorT);
404
    entry             = ALLOCATE(ErrorT);
388
    entry->next       = NIL (ErrorP);
405
    entry->next       = NIL(ErrorP);
389
    entry->name       = name;
406
    entry->name       = name;
390
    entry->severity   = severity;
407
    entry->severity   = severity;
391
    entry->error_list = error_list;
408
    entry->error_list = error_list;
392
    entry->data       = data;
409
    entry->data       = data;
393
    *entryp           = entry;
410
    *entryp           = entry;
394
    return (entry);
411
    return(entry);
395
}
412
}
396
 
413
 
397
void
414
void
398
error_intern_tags PROTO_N ((vector))
415
error_intern_tags(ETagDataP vector)
399
		  PROTO_T (ETagDataP vector)
-
 
400
{
416
{
401
    while (vector->name) {
417
    while (vector->name) {
402
	ETagP tag = error_define_tag (vector->name);
418
	ETagP tag = error_define_tag(vector->name);
403
 
419
 
404
	vector->tag = tag;
420
	vector->tag = tag;
405
	vector ++;
421
	vector++;
406
    }
422
    }
407
}
423
}
408
 
424
 
409
void
425
void
410
error_intern_errors PROTO_N ((vector))
426
error_intern_errors(ErrorDataP vector)
411
		    PROTO_T (ErrorDataP vector)
-
 
412
{
427
{
413
    while (vector->s.name) {
428
    while (vector->s.name) {
414
	ErrorP error = error_define_error (vector->s.name, vector->s.severity,
429
	ErrorP error = error_define_error(vector->s.name, vector->s.severity,
415
					   vector->s.message, vector->s.data);
430
					   vector->s.message, vector->s.data);
416
 
431
 
417
	vector->error = error;
432
	vector->error = error;
418
	vector ++;
433
	vector++;
419
    }
434
    }
420
}
435
}
421
 
436
 
422
ErrorStatusT
437
ErrorStatusT
423
error_redefine_error PROTO_N ((name, message))
438
error_redefine_error(CStringP name,			      CStringP message)
424
		     PROTO_T (CStringP name X
-
 
425
			      CStringP message)
-
 
426
{
439
{
427
    error_call_init_proc ();
440
    error_call_init_proc();
428
    {
441
    {
429
	unsigned hash  = (cstring_hash_value (name) % ERROR_TABLE_SIZE);
442
	unsigned hash  = (cstring_hash_value(name)% ERROR_TABLE_SIZE);
430
	ErrorP   entry = (error_table [hash]);
443
	ErrorP   entry = (error_table[hash]);
431
 
444
 
432
	while (entry) {
445
	while (entry) {
433
	    if (cstring_equal (entry->name, name)) {
446
	    if (cstring_equal(entry->name, name)) {
434
		ErrorListP error_list = error_parse_message (message);
447
		ErrorListP error_list = error_parse_message(message);
435
 
448
 
436
		if (error_list == NIL (ErrorListP)) {
449
		if (error_list == NIL(ErrorListP)) {
437
		    return (ERROR_STATUS_BAD_MESSAGE);
450
		    return(ERROR_STATUS_BAD_MESSAGE);
438
		}
451
		}
439
		error_deallocate_error_list (entry->error_list);
452
		error_deallocate_error_list(entry->error_list);
440
		entry->error_list = error_list;
453
		entry->error_list = error_list;
441
		return (ERROR_STATUS_SUCCESS);
454
		return(ERROR_STATUS_SUCCESS);
442
	    }
455
	    }
443
	    entry = entry->next;
456
	    entry = entry->next;
444
	}
457
	}
445
	return (ERROR_STATUS_BAD_ERROR);
458
	return(ERROR_STATUS_BAD_ERROR);
446
    }
459
    }
447
}
460
}
448
 
461
 
449
ErrorP
462
ErrorP
450
error_lookup_error PROTO_N ((name))
463
error_lookup_error(CStringP name)
451
		   PROTO_T (CStringP name)
-
 
452
{
464
{
453
    error_call_init_proc ();
465
    error_call_init_proc();
454
    {
466
    {
455
	unsigned hash  = (cstring_hash_value (name) % ERROR_TABLE_SIZE);
467
	unsigned hash  = (cstring_hash_value(name)% ERROR_TABLE_SIZE);
456
	ErrorP   entry = (error_table [hash]);
468
	ErrorP   entry = (error_table[hash]);
457
 
469
 
458
	while (entry) {
470
	while (entry) {
459
	    if (cstring_equal (entry->name, name)) {
471
	    if (cstring_equal(entry->name, name)) {
460
		return (entry);
472
		return(entry);
461
	    }
473
	    }
462
	    entry = entry->next;
474
	    entry = entry->next;
463
	}
475
	}
464
	return (NIL (ErrorP));
476
	return(NIL(ErrorP));
465
    }
477
    }
466
}
478
}
467
 
479
 
468
GenericP
480
GenericP
469
error_data PROTO_N ((error))
481
error_data(ErrorP error)
470
	   PROTO_T (ErrorP error)
-
 
471
{
482
{
472
    return (error->data);
483
    return(error->data);
473
}
484
}
474
 
485
 
475
void
486
void
476
error_report PROTO_N ((error, proc, closure))
487
error_report(ErrorP     error,		      ErrorProcP proc, 
477
	     PROTO_T (ErrorP     error X
-
 
478
		      ErrorProcP proc X
-
 
479
		      GenericP   closure)
488
		      GenericP   closure)
480
{
489
{
481
    if ((error->severity) >= min_severity) {
490
    if ((error->severity) >= min_severity) {
482
	write_error_list (ostream_error, error_prefix, error, NIL (ErrorProcP),
491
	write_error_list(ostream_error, error_prefix, error, NIL(ErrorProcP),
483
			  NIL (GenericP));
492
			  NIL(GenericP));
484
	write_error_list (ostream_error, error->error_list, error, proc,
493
	write_error_list(ostream_error, error->error_list, error, proc,
485
			  closure);
494
			  closure);
486
	write_newline (ostream_error);
495
	write_newline(ostream_error);
487
	ostream_flush (ostream_error);
496
	ostream_flush(ostream_error);
488
    }
497
    }
489
    if ((error->severity) > max_reported) {
498
    if ((error->severity) > max_reported) {
490
	max_reported = error->severity;
499
	max_reported = error->severity;
491
    }
500
    }
492
    if ((error->severity) >= ERROR_SEVERITY_FATAL) {
501
    if ((error->severity) >= ERROR_SEVERITY_FATAL) {
493
	if (error->severity == ERROR_SEVERITY_INTERNAL) {
502
	if (error->severity == ERROR_SEVERITY_INTERNAL) {
494
	    abort ();
503
	    abort();
495
	    UNREACHED;
504
	    UNREACHED;
496
	}
505
	}
497
	exit (EXIT_FAILURE);
506
	exit(EXIT_FAILURE);
498
	UNREACHED;
507
	UNREACHED;
499
    }
508
    }
500
}
509
}
501
 
510
 
502
void
511
void
503
error_set_min_report_severity PROTO_N ((severity))
512
error_set_min_report_severity(ESeverityT severity)
504
			      PROTO_T (ESeverityT severity)
-
 
505
{
513
{
506
    min_severity = severity;
514
    min_severity = severity;
507
}
515
}
508
 
516
 
509
ESeverityT
517
ESeverityT
510
error_get_min_report_severity PROTO_Z ()
518
error_get_min_report_severity(void)
511
{
519
{
512
    return (min_severity);
520
    return(min_severity);
513
}
521
}
514
 
522
 
515
ESeverityT
523
ESeverityT
516
error_max_reported_severity PROTO_Z ()
524
error_max_reported_severity(void)
517
{
525
{
518
    return (max_reported);
526
    return(max_reported);
519
}
527
}
520
 
528
 
521
void
529
void
522
error_set_severity_message PROTO_N ((severity, message))
530
error_set_severity_message(ESeverityT severity,				    CStringP   message)
523
			   PROTO_T (ESeverityT severity X
-
 
524
				    CStringP   message)
-
 
525
{
531
{
526
    severity_data [severity].estring->contents = message;
532
    severity_data[severity].estring->contents = message;
527
}
533
}
528
 
534
 
529
BoolT
535
BoolT
530
error_set_prefix_message PROTO_N ((message))
536
error_set_prefix_message(CStringP message)
531
			 PROTO_T (CStringP message)
-
 
532
{
537
{
533
    ErrorListP error_list = error_parse_message (message);
538
    ErrorListP error_list = error_parse_message(message);
534
 
539
 
535
    if (error_list == NIL (ErrorListP)) {
540
    if (error_list == NIL(ErrorListP)) {
536
	return (FALSE);
541
	return(FALSE);
537
    }
542
    }
538
    error_deallocate_error_list (error_prefix);
543
    error_deallocate_error_list(error_prefix);
539
    error_prefix = error_list;
544
    error_prefix = error_list;
540
    return (TRUE);
545
    return(TRUE);
541
}
546
}
542
 
547
 
543
EStringP
548
EStringP
544
error_define_string PROTO_N ((name, contents))
549
error_define_string(CStringP name,			     CStringP contents)
545
		    PROTO_T (CStringP name X
-
 
546
			     CStringP contents)
-
 
547
{
550
{
548
    unsigned  hash   = (cstring_hash_value (name) % STRING_TABLE_SIZE);
551
    unsigned  hash   = (cstring_hash_value(name)% STRING_TABLE_SIZE);
549
    EStringP *entryp = &(string_table [hash]);
552
    EStringP *entryp = & (string_table[hash]);
550
    EStringP  entry;
553
    EStringP  entry;
551
 
554
 
552
    while ((entry = *entryp) != NIL (EStringP)) {
555
    while ((entry = *entryp) != NIL(EStringP)) {
553
	ASSERT (!cstring_equal (entry->name, name));
556
	ASSERT(!cstring_equal(entry->name, name));
554
	entryp = &(entry->next);
557
	entryp = & (entry->next);
555
    }
558
    }
556
    entry           = ALLOCATE (EStringT);
559
    entry           = ALLOCATE(EStringT);
557
    entry->next     = NIL (EStringP);
560
    entry->next     = NIL(EStringP);
558
    entry->name     = name;
561
    entry->name     = name;
559
    entry->contents = contents;
562
    entry->contents = contents;
560
    *entryp         = entry;
563
    *entryp         = entry;
561
    return (entry);
564
    return(entry);
562
}
565
}
563
 
566
 
564
void
567
void
565
error_intern_strings PROTO_N ((vector))
568
error_intern_strings(EStringDataP vector)
566
		     PROTO_T (EStringDataP vector)
-
 
567
{
569
{
568
    while (vector->s.name) {
570
    while (vector->s.name) {
569
	EStringP estring = error_define_string (vector->s.name,
571
	EStringP estring = error_define_string(vector->s.name,
570
						vector->s.contents);
572
						vector->s.contents);
571
 
573
 
572
	vector->estring = estring;
574
	vector->estring = estring;
573
	vector ++;
575
	vector++;
574
    }
576
    }
575
}
577
}
576
 
578
 
577
BoolT
579
BoolT
578
error_redefine_string PROTO_N ((name, contents))
580
error_redefine_string(CStringP name,			       CStringP contents)
579
		      PROTO_T (CStringP name X
-
 
580
			       CStringP contents)
-
 
581
{
581
{
582
    unsigned hash  = (cstring_hash_value (name) % STRING_TABLE_SIZE);
582
    unsigned hash  = (cstring_hash_value(name)% STRING_TABLE_SIZE);
583
    EStringP entry = (string_table [hash]);
583
    EStringP entry = (string_table[hash]);
584
 
584
 
585
    while (entry) {
585
    while (entry) {
586
	if (cstring_equal (entry->name, name)) {
586
	if (cstring_equal(entry->name, name)) {
587
	    entry->contents = contents;
587
	    entry->contents = contents;
588
	    return (TRUE);
588
	    return(TRUE);
589
	}
589
	}
590
	entry = entry->next;
590
	entry = entry->next;
591
    }
591
    }
592
    return (FALSE);
592
    return(FALSE);
593
}
593
}
594
 
594
 
595
EStringP
595
EStringP
596
error_lookup_string PROTO_N ((name))
596
error_lookup_string(CStringP name)
597
		    PROTO_T (CStringP name)
-
 
598
{
597
{
599
    unsigned hash  = (cstring_hash_value (name) % STRING_TABLE_SIZE);
598
    unsigned hash  = (cstring_hash_value(name)% STRING_TABLE_SIZE);
600
    EStringP entry = (string_table [hash]);
599
    EStringP entry = (string_table[hash]);
601
 
600
 
602
    while (entry) {
601
    while (entry) {
603
	if (cstring_equal (entry->name, name)) {
602
	if (cstring_equal(entry->name, name)) {
604
	    return (entry);
603
	    return(entry);
605
	}
604
	}
606
	entry = entry->next;
605
	entry = entry->next;
607
    }
606
    }
608
    return (NIL (EStringP));
607
    return(NIL(EStringP));
609
}
608
}
610
 
609
 
611
CStringP
610
CStringP
612
error_string_contents PROTO_N ((estring))
611
error_string_contents(EStringP estring)
613
		      PROTO_T (EStringP estring)
-
 
614
{
612
{
615
    return (estring->contents);
613
    return(estring->contents);
616
}
614
}
617
 
615
 
618
void
616
void
619
write_error_file PROTO_N ((ostream))
617
write_error_file(OStreamP ostream)
620
		 PROTO_T (OStreamP ostream)
-
 
621
{
618
{
622
    error_call_init_proc ();
619
    error_call_init_proc();
623
    write_cstring (ostream, "%prefix%");
620
    write_cstring(ostream, "%prefix%");
624
    write_newline (ostream);
621
    write_newline(ostream);
625
    write_cstring (ostream, "    ");
622
    write_cstring(ostream, "    ");
626
    write_error_list_text (ostream, error_prefix);
623
    write_error_list_text(ostream, error_prefix);
627
    write_newline (ostream);
624
    write_newline(ostream);
628
    write_newline (ostream);
625
    write_newline(ostream);
629
    write_cstring (ostream, "%errors%");
626
    write_cstring(ostream, "%errors%");
630
    write_newline (ostream);
627
    write_newline(ostream);
631
    write_error_table (ostream);
628
    write_error_table(ostream);
632
    write_newline (ostream);
629
    write_newline(ostream);
633
    write_cstring (ostream, "%strings%");
630
    write_cstring(ostream, "%strings%");
634
    write_newline (ostream);
631
    write_newline(ostream);
635
    write_string_table (ostream);
632
    write_string_table(ostream);
636
}
633
}
637

634

638
/*
635
/*
639
 * Local variables(smf):
636
 * Local variables(smf):
640
 * eval: (include::add-path-entry "../os-interface" "../generated")
637
 * eval: (include::add-path-entry "../os-interface" "../generated")