Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – tendra.SVN – Blame – /branches/tendra5/src/utilities/sid/error-file.c – Rev 2

Subversion Repositories tendra.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
2
    		 Crown Copyright (c) 1997
3
 
4
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
12
 
13
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
15
 
16
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
19
 
20
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
22
        these conditions;
23
 
24
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
27
        it may be put.
28
*/
29
 
30
 
31
/**** error-file.c --- Error file parsing routines.
32
 *
33
 ** Author: Steve Folkes <smf@hermes.mod.uk>
34
 *
35
 **** Commentary:
36
 *
37
 * This file implements the error file parsing facility specified in the file
38
 * "error-file.h".  See that file for more details.
39
 *
40
 **** Change Log:
41
 * $Log: error-file.c,v $
42
 * Revision 1.1.1.1  1998/01/17  15:57:45  release
43
 * First version to be checked into rolling release.
44
 *
45
 * Revision 1.3  1994/12/12  11:44:37  smf
46
 * Performing changes for 'CR94_178.sid+tld-update' - bringing in line with
47
 * OSSG C Coding Standards.
48
 *
49
 * Revision 1.2  1994/08/22  09:36:44  smf
50
 * Fixed bug DR114:ids-too-long.
51
 *
52
 * Revision 1.1.1.1  1994/07/25  16:05:49  smf
53
 * Initial import of library shared files.
54
 *
55
**/
56
 
57
/****************************************************************************/
58
 
59
#include "error-file.h"
60
#include "dstring.h"
61
#include "error.h"
62
#include "gen-errors.h"
63
#include "syntax.h"
64
 
65
/*--------------------------------------------------------------------------*/
66
 
67
#ifdef FS_NO_ENUM
68
typedef int ErrorFileTagT, *ErrorFileTagP;
69
#define EFTOKEN_NAME		(0)
70
#define EFTOKEN_STRING		(1)
71
#define EFTOKEN_BLT_STRINGS	(2)
72
#define EFTOKEN_BLT_PREFIX	(3)
73
#define EFTOKEN_BLT_ERRORS	(4)
74
#define EFTOKEN_EOF		(5)
75
#else
76
typedef enum {
77
    EFTOKEN_NAME,
78
    EFTOKEN_STRING,
79
    EFTOKEN_BLT_STRINGS,
80
    EFTOKEN_BLT_PREFIX,
81
    EFTOKEN_BLT_ERRORS,
82
    EFTOKEN_EOF
83
} ErrorFileTagT, *ErrorFileTagP;
84
#endif /* defined (FS_NO_ENUM) */
85
 
86
typedef struct ErrorFileLexT {
87
    ErrorFileTagT		tag;
88
    union {
89
	CStringP		string;
90
    } u;
91
} ErrorFileLexT, *ErrorFileLexP;
92
 
93
#ifdef FS_NO_ENUM
94
typedef int ErrorFileTokenT, *ErrorFileTokenP;
95
#define EFN_BUILTIN	(0)
96
#define EFN_NAME	(1)
97
#define EFN_STRING	(2)
98
#else
99
typedef enum {
100
    EFN_BUILTIN,
101
    EFN_NAME,
102
    EFN_STRING
103
} ErrorFileTokenT, *ErrorFileTokenP;
104
#endif /* defined (FS_NO_ENUM) */
105
 
106
/*--------------------------------------------------------------------------*/
107
 
108
static BoolT
109
error_file_skip_white_space PROTO_N ((istream, c_ref))
110
			    PROTO_T (IStreamP istream X
111
				     char    *c_ref)
112
{
113
    BoolT comment = FALSE;
114
 
115
    for (;;) {
116
	char c;
117
 
118
      redo:
119
	switch (c = ISTREAM_READ_CHAR (istream)) {
120
	  case '\0':
121
	    ISTREAM_HANDLE_NULL (istream, redo, eof);
122
	    break;
123
	  case '\n':
124
	    istream_inc_line (istream);
125
	    comment = FALSE;
126
	    break;
127
	  case '#':
128
	    comment = TRUE;
129
	    break;
130
	  default:
131
	    if ((!comment) && (!syntax_is_white_space (c))) {
132
		*c_ref = c;
133
		return (TRUE);
134
	    }
135
	}
136
    }
137
  eof:
138
    return (FALSE);
139
}
140
 
141
static void
142
error_file_null_character PROTO_N ((istream, type))
143
			  PROTO_T (IStreamP        istream X
144
				   ErrorFileTokenT type)
145
{
146
    switch (type) EXHAUSTIVE {
147
      case EFN_NAME:
148
	E_errf_null_character_in_name (istream);
149
	UNREACHED;
150
      case EFN_BUILTIN:
151
	E_errf_null_char_in_builtin (istream);
152
	UNREACHED;
153
      case EFN_STRING:
154
	E_errf_null_character_in_string (istream);
155
	UNREACHED;
156
    }
157
}
158
 
159
static void
160
error_file_newline PROTO_N ((istream, type))
161
		   PROTO_T (IStreamP        istream X
162
			    ErrorFileTokenT type)
163
{
164
    switch (type) EXHAUSTIVE {
165
      case EFN_NAME:
166
	E_errf_newline_in_name (istream);
167
	UNREACHED;
168
      case EFN_BUILTIN:
169
	E_errf_newline_in_builtin (istream);
170
	UNREACHED;
171
      case EFN_STRING:
172
	E_errf_newline_in_string (istream);
173
	UNREACHED;
174
    }
175
}
176
 
177
static void
178
error_file_illegal_escape PROTO_N ((istream, type))
179
			  PROTO_T (IStreamP        istream X
180
				   ErrorFileTokenT type)
181
{
182
    switch (type) EXHAUSTIVE {
183
      case EFN_NAME:
184
	E_errf_illegal_escape_in_name (istream);
185
	UNREACHED;
186
      case EFN_BUILTIN:
187
	E_errf_illegal_esc_in_builtin (istream);
188
	UNREACHED;
189
      case EFN_STRING:
190
	E_errf_illegal_escape_in_string (istream);
191
	UNREACHED;
192
    }
193
}
194
 
195
static void
196
error_file_eof PROTO_N ((istream, type))
197
	       PROTO_T (IStreamP        istream X
198
			ErrorFileTokenT type)
199
{
200
    switch (type) EXHAUSTIVE {
201
      case EFN_NAME:
202
	E_errf_eof_in_name (istream);
203
	UNREACHED;
204
      case EFN_BUILTIN:
205
	E_errf_eof_in_builtin (istream);
206
	UNREACHED;
207
      case EFN_STRING:
208
	E_errf_eof_in_string (istream);
209
	UNREACHED;
210
    }
211
}
212
 
213
static void
214
error_file_read_until PROTO_N ((istream, term, type, token))
215
		      PROTO_T (IStreamP        istream X
216
			       char            term X
217
			       ErrorFileTokenT type X
218
			       ErrorFileLexP   token)
219
{
220
    DStringT dstring;
221
 
222
    dstring_init (&dstring);
223
    for (;;) {
224
	char c;
225
 
226
      redo:
227
	switch (c = ISTREAM_READ_CHAR (istream)) {
228
	  case '\0':
229
	    ISTREAM_HANDLE_NULL (istream, redo, eof);
230
	    error_file_null_character (istream, type);
231
	    UNREACHED;
232
	  case '\n':
233
	    istream_inc_line (istream);
234
	    error_file_newline (istream, type);
235
	    UNREACHED;
236
	  default:
237
	    if (c == term) {
238
		CStringP tmp;
239
 
240
		tmp = dstring_to_cstring (&dstring);
241
		dstring_destroy (&dstring);
242
		token->u.string = tmp;
243
		return;
244
	    } else if (c == '\\') {
245
		switch (istream_read_escaped_char (istream, &c)) EXHAUSTIVE {
246
		  case ISTREAM_STAT_READ_CHAR:
247
		    if (c == '\0') {
248
			error_file_null_character (istream, type);
249
			UNREACHED;
250
		    }
251
		    dstring_append_char (&dstring, c);
252
		    break;
253
		  case ISTREAM_STAT_SYNTAX_ERROR:
254
		    error_file_illegal_escape (istream, type);
255
		    UNREACHED;
256
		  case ISTREAM_STAT_NO_CHAR:
257
		    /*NOTHING*/
258
		    break;
259
		}
260
	    } else {
261
		dstring_append_char (&dstring, c);
262
	    }
263
	    break;
264
	}
265
    }
266
  eof:
267
    error_file_eof (istream, type);
268
    UNREACHED;
269
}
270
 
271
static void
272
error_file_check_builtin PROTO_N ((istream, token))
273
			 PROTO_T (IStreamP      istream X
274
				  ErrorFileLexP token)
275
{
276
    if (cstring_ci_equal (token->u.string, "strings")) {
277
	token->tag = EFTOKEN_BLT_STRINGS;
278
    } else if (cstring_ci_equal (token->u.string, "prefix")) {
279
	token->tag = EFTOKEN_BLT_PREFIX;
280
    } else if (cstring_ci_equal (token->u.string, "errors")) {
281
	token->tag = EFTOKEN_BLT_ERRORS;
282
    } else {
283
	E_errf_unknown_builtin (istream, token->u.string);
284
	UNREACHED;
285
    }
286
    DEALLOCATE (token->u.string);
287
}
288
 
289
static void
290
error_file_next_token PROTO_N ((istream, token))
291
		      PROTO_T (IStreamP      istream X
292
			       ErrorFileLexP token)
293
{
294
    char c;
295
 
296
    if (error_file_skip_white_space (istream, &c)) {
297
	switch (c) {
298
	  case '%':
299
	    error_file_read_until (istream, '%', EFN_BUILTIN, token);
300
	    error_file_check_builtin (istream, token);
301
	    break;
302
	  case '\'':
303
	    error_file_read_until (istream, '\'', EFN_NAME, token);
304
	    token->tag = EFTOKEN_NAME;
305
	    break;
306
	  case '"':
307
	    error_file_read_until (istream, '"', EFN_STRING, token);
308
	    token->tag = EFTOKEN_STRING;
309
	    break;
310
	  default:
311
	    E_errf_illegal_character (istream, c);
312
	    UNREACHED;
313
	}
314
    } else {
315
	token->tag = EFTOKEN_EOF;
316
    }
317
}
318
 
319
static void
320
error_file_parse_strings PROTO_N ((istream, token))
321
			 PROTO_T (IStreamP      istream X
322
				  ErrorFileLexP token)
323
{
324
    while (error_file_next_token (istream, token),
325
	   (token->tag == EFTOKEN_NAME)) {
326
	CStringP name = token->u.string;
327
 
328
	if (error_file_next_token (istream, token),
329
	    (token->tag != EFTOKEN_STRING)) {
330
	    E_errf_expected_string (istream);
331
	    UNREACHED;
332
	} else if (!error_redefine_string (name, token->u.string)) {
333
	    E_errf_unknown_string (istream, name);
334
	    UNREACHED;
335
	}
336
	DEALLOCATE (name);
337
    }
338
}
339
 
340
static void
341
error_file_parse_prefix PROTO_N ((istream, token))
342
			PROTO_T (IStreamP      istream X
343
				 ErrorFileLexP token)
344
{
345
    error_file_next_token (istream, token);
346
    if (token->tag != EFTOKEN_STRING) {
347
	E_errf_expected_string (istream);
348
	UNREACHED;
349
    } else if (!error_set_prefix_message (token->u.string)) {
350
	E_errf_illegal_message (istream, token->u.string);
351
	UNREACHED;
352
    }
353
    DEALLOCATE (token->u.string);
354
    error_file_next_token (istream, token);
355
}
356
 
357
static void
358
error_file_parse_errors PROTO_N ((istream, token))
359
			PROTO_T (IStreamP      istream X
360
				 ErrorFileLexP token)
361
{
362
    while (error_file_next_token (istream, token),
363
	   (token->tag == EFTOKEN_NAME)) {
364
	CStringP name = token->u.string;
365
 
366
	error_file_next_token (istream, token);
367
	if (token->tag != EFTOKEN_STRING) {
368
	    E_errf_expected_string (istream);
369
	    UNREACHED;
370
	} else {
371
	    switch (error_redefine_error (name, token->u.string)) EXHAUSTIVE {
372
	      case ERROR_STATUS_BAD_ERROR:
373
		E_errf_unknown_error (istream, name);
374
		UNREACHED;
375
	      case ERROR_STATUS_BAD_MESSAGE:
376
		E_errf_illegal_message (istream, token->u.string);
377
		UNREACHED;
378
	      case ERROR_STATUS_SUCCESS:
379
		/*NOTHING*/
380
		break;
381
	    }
382
	}
383
	DEALLOCATE (name);
384
	DEALLOCATE (token->u.string);
385
    }
386
}
387
 
388
/*--------------------------------------------------------------------------*/
389
 
390
void
391
error_file_parse PROTO_N ((name, must_open))
392
		 PROTO_T (CStringP name X
393
			  BoolT    must_open)
394
{
395
    IStreamT      istream;
396
    ErrorFileLexT token;
397
 
398
    if (istream_open (&istream, name)) {
399
	error_file_next_token (&istream, &token);
400
	while (token.tag != EFTOKEN_EOF) {
401
	    switch (token.tag) {
402
	      case EFTOKEN_BLT_STRINGS:
403
		error_file_parse_strings (&istream, &token);
404
		break;
405
	      case EFTOKEN_BLT_PREFIX:
406
		error_file_parse_prefix (&istream, &token);
407
		break;
408
	      case EFTOKEN_BLT_ERRORS:
409
		error_file_parse_errors (&istream, &token);
410
		break;
411
	      default:
412
		E_errf_expected_section (&istream);
413
		UNREACHED;
414
	    }
415
	}
416
	istream_close (&istream);
417
    } else if (must_open) {
418
	E_errf_cannot_open (name);
419
	UNREACHED;
420
    }
421
}
422
 
423
/*
424
 * Local variables(smf):
425
 * eval: (include::add-path-entry "../os-interface" "../generated")
426
 * end:
427
**/