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 43... Line 73...
43
 
73
 
44
/*
74
/*
45
    DATABASE HEADER INFORMATION
75
    DATABASE HEADER INFORMATION
46
 
76
 
47
    These variables are used to store the standard header information.
77
    These variables are used to store the standard header information.
48
*/
78
*/
49
 
79
 
50
char *db_name = "ERRORS" ;
80
char *db_name = "ERRORS";
51
char *db_name_alt = "ERRORS" ;
81
char *db_name_alt = "ERRORS";
52
char *rig_name = "ERR_" ;
82
char *rig_name = "ERR_";
53
char *rig_comp_output = "ERR_" ;
83
char *rig_comp_output = "ERR_";
54
char *rig_from_comp = "ERR_USE_" ;
84
char *rig_from_comp = "ERR_USE_";
55
char *rig_from_db = "ERR_NO_" ;
85
char *rig_from_db = "ERR_NO_";
56
 
86
 
57
 
87
 
58
/*
88
/*
59
    DATABASE SECTION LISTS
89
    DATABASE SECTION LISTS
60
 
90
 
61
    These variables are used to store the various lists of information
91
    These variables are used to store the various lists of information
62
    built up by the parser.
92
    built up by the parser.
63
*/
93
*/
64
 
94
 
65
LIST ( ENTRY ) all_entries = NULL_list ( ENTRY ) ;
95
LIST(ENTRY)all_entries = NULL_list(ENTRY);
66
LIST ( KEY ) all_keys = NULL_list ( KEY ) ;
96
LIST(KEY)all_keys = NULL_list(KEY);
67
LIST ( PROPERTY ) all_props = NULL_list ( PROPERTY ) ;
97
LIST(PROPERTY)all_props = NULL_list(PROPERTY);
68
LIST ( TYPE ) all_types = NULL_list ( TYPE ) ;
98
LIST(TYPE)all_types = NULL_list(TYPE);
69
LIST ( USAGE ) all_usages = NULL_list ( USAGE ) ;
99
LIST(USAGE)all_usages = NULL_list(USAGE);
70
LIST ( KEY ) all_keys_aux = NULL_list ( KEY ) ;
100
LIST(KEY)all_keys_aux = NULL_list(KEY);
71
LIST ( PROPERTY ) all_props_aux = NULL_list ( PROPERTY ) ;
101
LIST(PROPERTY)all_props_aux = NULL_list(PROPERTY);
72
LIST ( TYPE ) all_types_aux = NULL_list ( TYPE ) ;
102
LIST(TYPE)all_types_aux = NULL_list(TYPE);
73
LIST ( USAGE ) all_usages_aux = NULL_list ( USAGE ) ;
103
LIST(USAGE)all_usages_aux = NULL_list(USAGE);
74
LIST ( KEY ) all_keys_alt = NULL_list ( KEY ) ;
104
LIST(KEY)all_keys_alt = NULL_list(KEY);
75
LIST ( PROPERTY ) all_props_alt = NULL_list ( PROPERTY ) ;
105
LIST(PROPERTY)all_props_alt = NULL_list(PROPERTY);
76
LIST ( TYPE ) all_types_alt = NULL_list ( TYPE ) ;
106
LIST(TYPE)all_types_alt = NULL_list(TYPE);
77
LIST ( USAGE ) all_usages_alt = NULL_list ( USAGE ) ;
107
LIST(USAGE)all_usages_alt = NULL_list(USAGE);
78
 
108
 
79
 
109
 
80
/*
110
/*
81
    FIND CODE LETTER
111
    FIND CODE LETTER
82
 
112
 
83
    This routine finds a code letter corresponding to the number n.  It
113
    This routine finds a code letter corresponding to the number n.  It
84
    assumes the ASCII character set.
114
    assumes the ASCII character set.
85
*/
115
*/
86
 
116
 
87
static int code_letter
117
static int
88
    PROTO_N ( ( n ) )
-
 
89
    PROTO_T ( int n )
118
code_letter(int n)
90
{
119
{
-
 
120
	if (n < 10) {
91
    if ( n < 10 ) return ( '0' + n ) ;
121
		return ('0' + n);
-
 
122
	}
-
 
123
	if (n < 36) {
92
    if ( n < 36 ) return ( 'A' + ( n - 10 ) ) ;
124
		return ('A' + (n - 10));
-
 
125
	}
-
 
126
	if (n < 72) {
93
    if ( n < 72 ) return ( 'a' + ( n - 36 ) ) ;
127
		return ('a' + (n - 36));
-
 
128
	}
94
    return ( n + 128 ) ;
129
	return (n + 128);
95
}
130
}
96
 
131
 
97
 
132
 
98
/*
133
/*
99
    LOOK UP AN ERROR MAP
134
    LOOK UP AN ERROR MAP
100
 
135
 
101
    This routine looks up the value of the property named s in the list
136
    This routine looks up the value of the property named s in the list
102
    of property mappings p.
137
    of property mappings p.
103
*/
138
*/
104
 
139
 
105
static MAP find_map
140
static MAP
106
    PROTO_N ( ( p, s ) )
-
 
107
    PROTO_T ( LIST ( MAP ) p X string s )
141
find_map(LIST(MAP)p, string s)
108
{
142
{
109
    while ( !IS_NULL_list ( p ) ) {
143
	while (!IS_NULL_list(p)) {
110
	MAP m = DEREF_map ( HEAD_list ( p ) ) ;
144
		MAP m = DEREF_map(HEAD_list(p));
111
	NAME n = DEREF_name ( map_key ( m ) ) ;
145
		NAME n = DEREF_name(map_key(m));
112
	if ( !IS_NULL_name ( n ) ) {
146
		if (!IS_NULL_name(n)) {
113
	    string t = DEREF_string ( name_id ( n ) ) ;
147
			string t = DEREF_string(name_id(n));
114
	    if ( streq ( s, t ) ) return ( m ) ;
148
			if (streq(s, t)) {
-
 
149
				return (m);
-
 
150
			}
-
 
151
		}
-
 
152
		p = TAIL_list(p);
115
	}
153
	}
116
	p = TAIL_list ( p ) ;
-
 
117
    }
-
 
118
    return ( NULL_map ) ;
154
	return (NULL_map);
119
}
155
}
120
 
156
 
121
 
157
 
122
/*
158
/*
123
    OUTPUT A MESSAGE LIST
159
    OUTPUT A MESSAGE LIST
124
 
160
 
125
    This routine prints the message list p to the file f.
161
    This routine prints the message list p to the file f.
126
*/
162
*/
127
 
163
 
128
static void output_msg
164
static void
129
    PROTO_N ( ( f, p ) )
-
 
130
    PROTO_T ( FILE *f X LIST ( MESSAGE ) p )
165
output_msg(FILE *f, LIST(MESSAGE) p)
131
{
166
{
132
    int sp = 0 ;
167
	int sp = 0;
133
    fputc_v ( '"', f ) ;
168
	fputc_v('"', f);
134
    while ( !IS_NULL_list ( p ) ) {
169
	while (!IS_NULL_list(p)) {
135
	MESSAGE m = DEREF_msg ( HEAD_list ( p ) ) ;
170
		MESSAGE m = DEREF_msg(HEAD_list(p));
136
	if ( !IS_NULL_msg ( m ) ) {
171
		if (!IS_NULL_msg(m)) {
137
	    if ( IS_msg_param ( m ) ) {
172
			if (IS_msg_param(m)) {
138
		PARAM a = DEREF_param ( msg_param_arg ( m ) ) ;
173
				PARAM a = DEREF_param(msg_param_arg(m));
139
		int an = DEREF_int ( param_number ( a ) ) ;
174
				int an = DEREF_int(param_number(a));
140
		an = code_letter ( an ) ;
175
				an = code_letter(an);
141
		if ( sp ) {
176
				if (sp) {
142
		    fputc_v ( ' ', f ) ;
177
					fputc_v(' ', f);
143
		    sp = 0 ;
178
					sp = 0;
144
		}
179
				}
145
		fprintf_v ( f, "%%%c", an ) ;
180
				fprintf_v(f, "%%%c", an);
146
	    } else {
181
			} else {
147
		char c ;
182
				char c;
148
		string s = DEREF_string ( msg_text_arg ( m ) ) ;
183
				string s = DEREF_string(msg_text_arg(m));
149
		while ( c = *( s++ ), c != 0 ) {
184
				while (c = *(s++), c != 0) {
150
		    if ( c == ' ' || c == '\t' || c == '\n' ) {
185
					if (c == ' ' || c == '\t' ||
-
 
186
					    c == '\n') {
151
			sp = 1 ;
187
						sp = 1;
152
		    } else {
188
					} else {
153
			if ( sp ) {
189
						if (sp) {
154
			    fputc_v ( ' ', f ) ;
190
							fputc_v(' ', f);
155
			    sp = 0 ;
191
							sp = 0;
-
 
192
						}
-
 
193
						fputc_v(c, f);
-
 
194
					}
-
 
195
				}
-
 
196
			}
-
 
197
		}
-
 
198
		p = TAIL_list(p);
-
 
199
	}
-
 
200
	fputc_v('"', f);
-
 
201
	return;
-
 
202
}
-
 
203
 
-
 
204
 
-
 
205
/*
-
 
206
    OUTPUT ERROR DEFINITIONS
-
 
207
 
-
 
208
    This routine outputs all the error definitions to the file f.
-
 
209
*/
-
 
210
 
-
 
211
static void
-
 
212
output_defn(FILE *f)
-
 
213
{
-
 
214
	/* Print error catalog */
-
 
215
	LIST(NAME) p;
-
 
216
	char *d1 = db_name;
-
 
217
	char *d2 = db_name_alt;
-
 
218
	char *pre = rig_comp_output;
-
 
219
	char *pre_comp = rig_from_comp;
-
 
220
	LIST(ENTRY) q = all_entries;
-
 
221
 
-
 
222
	/* Print each catalogue entry */
-
 
223
	fprintf_v ( f, "/* Error catalogue */\n\n" ) ;
-
 
224
	if (streq(d1, d2)) {
-
 
225
		fprintf_v(f, "%sCONST char *%sNAME = \"%s\" ;\n", pre, pre, d1);
-
 
226
	} else {
-
 
227
		fprintf_v(f, "#ifndef %sALTERNATE\n", pre);
-
 
228
		fprintf_v(f, "%sCONST char *%sNAME = \"%s\" ;\n", pre, pre, d1);
-
 
229
		fprintf_v(f, "#else\n");
-
 
230
		fprintf_v(f, "%sCONST char *%sNAME = \"%s\" ;\n", pre, pre, d2);
-
 
231
		fprintf_v(f, "#endif\n");
-
 
232
	}
-
 
233
	fprintf_v(f, "\n%sDATA %sCATALOG [] = {\n", pre, pre);
-
 
234
	while (!IS_NULL_list(q)) {
-
 
235
		unsigned u = 0;
-
 
236
		char *suff = ",\n";
-
 
237
		ENTRY e = DEREF_entry(HEAD_list(q));
-
 
238
		string en = DEREF_string(entry_name(e));
-
 
239
		USAGE eu = DEREF_name(entry_use(e));
-
 
240
		USAGE ev = DEREF_name(entry_alt_use(e));
-
 
241
		LIST(MAP) em = DEREF_list(entry_maps(e));
-
 
242
		LIST(PROPERTY) eq = DEREF_list(entry_props(e));
-
 
243
		LIST(PARAM) ep = DEREF_list(entry_signature(e));
-
 
244
 
-
 
245
		/* Print error name */
-
 
246
		fprintf_v(f, "    {\n\t\"%s\",\n", en);
-
 
247
 
-
 
248
		/* Print error signature */
-
 
249
		if (IS_NULL_list(ep)) {
-
 
250
			fprintf_v(f, "\tNULL,\n");
-
 
251
		} else {
-
 
252
			fprintf_v(f, "\t\"");
-
 
253
			while (!IS_NULL_list(ep)) {
-
 
254
				PARAM a = DEREF_param(HEAD_list(ep));
-
 
255
				TYPE at = DEREF_name(param_type(a));
-
 
256
				int an = DEREF_int(name_number(at));
-
 
257
				an = code_letter(an);
-
 
258
				fputc_v(an, f);
-
 
259
				ep = TAIL_list(ep);
-
 
260
			}
-
 
261
			fprintf_v(f, "\",\n");
-
 
262
		}
-
 
263
 
-
 
264
		/* Print error usage */
-
 
265
		if (!EQ_name(eu, ev)) {
-
 
266
			fprintf_v(f, "#ifndef %sALTERNATE\n", pre);
-
 
267
		}
-
 
268
		if (IS_NULL_name(eu)) {
-
 
269
			fprintf_v(f, "\t0,\n");
-
 
270
		} else {
-
 
271
			string un = DEREF_string(name_id(eu));
-
 
272
			fprintf_v(f, "\t%s%s,\n", pre_comp, un);
-
 
273
		}
-
 
274
		if (!EQ_name(eu, ev)) {
-
 
275
			fprintf_v(f, "#else\n");
-
 
276
			if (IS_NULL_name(ev)) {
-
 
277
				fprintf_v(f, "\t0,\n");
-
 
278
			} else {
-
 
279
				string vn = DEREF_string(name_id(ev));
-
 
280
				fprintf_v(f, "\t%s%s,\n", pre_comp, vn);
-
 
281
			}
-
 
282
			fprintf_v(f, "#endif\n");
-
 
283
		}
-
 
284
 
-
 
285
		/* Print error properties */
-
 
286
		p = all_keys;
-
 
287
		if (IS_NULL_list(p)) {
-
 
288
			suff = "\n";
-
 
289
		}
-
 
290
		while (!IS_NULL_list(eq)) {
-
 
291
			PROPERTY nq = DEREF_name(HEAD_list(eq));
-
 
292
			unsigned n = (unsigned)DEREF_int(name_number(nq));
-
 
293
			u |= (((unsigned)1) << n);
-
 
294
			eq = TAIL_list(eq);
-
 
295
		}
-
 
296
		fprintf_v(f, "\t%u%s", u, suff);
-
 
297
 
-
 
298
		/* Print error keys */
-
 
299
		while (!IS_NULL_list(p)) {
-
 
300
			NAME n = DEREF_name(HEAD_list(p));
-
 
301
			string pn = DEREF_string(name_id(n));
-
 
302
			MAP pm = find_map(em, pn);
-
 
303
			p = TAIL_list(p);
-
 
304
			if (IS_NULL_list(p)) {
-
 
305
				suff = "\n";
-
 
306
			}
-
 
307
			if (IS_NULL_map(pm)) {
-
 
308
				fprintf_v(f, "\tNULL%s", suff);
-
 
309
			} else {
-
 
310
				LIST(MESSAGE)m1 = DEREF_list(map_msg(pm));
-
 
311
				LIST(MESSAGE)m2 = DEREF_list(map_alt_msg(pm));
-
 
312
				if (!EQ_list(m1, m2)) {
-
 
313
					fprintf_v(f, "#ifndef %sALTERNATE\n",
-
 
314
						  pre);
-
 
315
				}
-
 
316
				fprintf_v(f, "\t");
-
 
317
				output_msg(f, m1);
-
 
318
				fprintf_v(f, "%s", suff);
-
 
319
				if (!EQ_list(m1, m2)) {
-
 
320
					fprintf_v(f, "#else\n\t");
-
 
321
					output_msg(f, m2);
-
 
322
					fprintf_v(f, "%s#endif\n", suff);
-
 
323
				}
-
 
324
			}
-
 
325
		}
-
 
326
		fprintf_v(f, "    },\n");
-
 
327
		q = TAIL_list(q);
-
 
328
	}
-
 
329
 
-
 
330
	/* Print dummy end marker */
-
 
331
	fprintf_v(f, "    {\n");
-
 
332
	fprintf_v(f, "\tNULL,\n");
-
 
333
	fprintf_v(f, "\tNULL,\n");
-
 
334
	fprintf_v(f, "\t0,\n");
-
 
335
	fprintf_v(f, "\t0");
-
 
336
	p = all_keys;
-
 
337
	while (!IS_NULL_list(p)) {
-
 
338
		fprintf_v(f, ",\n\tNULL");
-
 
339
		p = TAIL_list(p);
-
 
340
	}
-
 
341
	fprintf_v(f, "\n    }\n");
-
 
342
	fprintf_v(f, "} ;\n");
-
 
343
	return;
-
 
344
}
-
 
345
 
-
 
346
 
-
 
347
/*
-
 
348
    OUTPUT ERROR DECLARATIONS
-
 
349
 
-
 
350
    This routine outputs all the error declarations to the file f.
-
 
351
*/
-
 
352
 
-
 
353
static void
-
 
354
output_decl(FILE *f)
-
 
355
{
-
 
356
	int qn = 0;
-
 
357
	LIST(ENTRY) q = all_entries;
-
 
358
 
-
 
359
	/* Print main type definition */
-
 
360
	char *pre = rig_comp_output;
-
 
361
	char *pre_comp = rig_from_comp;
-
 
362
	LIST(NAME) p = all_keys;
-
 
363
	fprintf_v(f, "#ifndef %sINCLUDED\n", pre);
-
 
364
	fprintf_v(f, "#define %sINCLUDED\n\n\n", pre);
-
 
365
	fprintf_v(f, "/* Error data structure */\n\n");
-
 
366
	fprintf_v(f, "#ifndef %sCONST\n", pre);
-
 
367
	fprintf_v(f, "#define %sCONST\n", pre);
-
 
368
	fprintf_v(f, "#endif\n\n");
-
 
369
	if (LENGTH_list(all_props) < 16) {
-
 
370
		fprintf_v(f, "typedef unsigned %sPROPS ;\n\n", pre);
-
 
371
	} else {
-
 
372
		fprintf_v(f, "typedef unsigned long %sPROPS ;\n\n", pre);
-
 
373
	}
-
 
374
	fprintf_v(f, "typedef struct {\n");
-
 
375
	fprintf_v(f, "    %sCONST char *name ;\n", pre);
-
 
376
	fprintf_v(f, "    %sCONST char *signature ;\n", pre);
-
 
377
	fprintf_v(f, "    int usage ;\n");
-
 
378
	fprintf_v(f, "    %sPROPS props ;\n", pre);
-
 
379
	while (!IS_NULL_list(p)) {
-
 
380
		NAME t = DEREF_name(HEAD_list(p));
-
 
381
		string tn = DEREF_string(name_id(t));
-
 
382
		fprintf_v(f, "    %sCONST char *key_%s ;\n", pre, tn);
-
 
383
		p = TAIL_list(p);
-
 
384
	}
-
 
385
	fprintf_v(f, "} %sDATA ;\n\n", pre);
-
 
386
	fprintf_v(f, "extern %sDATA %sCATALOG [] ;\n", pre, pre);
-
 
387
	fprintf_v(f, "extern %sCONST char *%sNAME ;\n\n\n", pre, pre);
-
 
388
 
-
 
389
	/* Print type keys */
-
 
390
	p = all_types;
-
 
391
	fprintf_v(f, "/* Error type keys */\n\n");
-
 
392
	while (!IS_NULL_list(p)) {
-
 
393
		NAME t = DEREF_name(HEAD_list(p));
-
 
394
		string tn = DEREF_string(name_id(t));
-
 
395
		int n = DEREF_int(name_number(t));
-
 
396
		n = code_letter(n);
-
 
397
		fprintf_v(f, "#define %sKEY_%s '%c'\n", pre, tn, n);
-
 
398
		p = TAIL_list(p);
-
 
399
	}
-
 
400
	fprintf_v(f, "\n\n");
-
 
401
 
-
 
402
	/* Print usage keys */
-
 
403
	p = all_usages;
-
 
404
	fprintf_v(f, "/* Error usage keys */\n\n");
-
 
405
	fprintf_v(f, "#ifndef %sUSE\n", pre);
-
 
406
	while (!IS_NULL_list(p)) {
-
 
407
		NAME t = DEREF_name(HEAD_list(p));
-
 
408
		string tn = DEREF_string(name_id(t));
-
 
409
		int n = DEREF_int(name_number(t));
-
 
410
		fprintf_v(f, "#define %s%s %d\n", pre_comp, tn, n);
-
 
411
		p = TAIL_list(p);
-
 
412
	}
-
 
413
	fprintf_v(f, "#endif\n\n\n");
-
 
414
 
-
 
415
	/* Print property keys */
-
 
416
	p = all_props;
-
 
417
	fprintf_v(f, "/* Error property keys */\n\n");
-
 
418
	fprintf_v(f, "#ifndef %sPROP\n", pre);
-
 
419
	while (!IS_NULL_list(p)) {
-
 
420
		NAME t = DEREF_name(HEAD_list(p));
-
 
421
		string tn = DEREF_string(name_id(t));
-
 
422
		unsigned n = (unsigned)DEREF_int(name_number(t));
-
 
423
		unsigned u = (((unsigned)1) << n);
-
 
424
		fprintf_v(f, "#define %sPROP_%s ( ( %sPROPS ) 0x%x )\n",
-
 
425
			  pre, tn, pre, u);
-
 
426
		p = TAIL_list(p);
-
 
427
	}
-
 
428
	fprintf_v(f, "#endif\n\n\n");
-
 
429
 
-
 
430
	/* Print type checking macros */
-
 
431
	p = all_types;
-
 
432
	fprintf_v(f, "/* Error type checking */\n\n");
-
 
433
	fprintf_v(f, "#if defined ( %sCHECK ) && defined ( __STDC__ )\n", pre);
-
 
434
	while (!IS_NULL_list(p)) {
-
 
435
		NAME t = DEREF_name(HEAD_list(p));
-
 
436
		string tn = DEREF_string(name_id(t));
-
 
437
		int n = DEREF_int(name_number(t));
-
 
438
		n = code_letter(n);
-
 
439
		fprintf_v(f, "extern %s chk_%c ( %s ) ;\n", tn, n, tn);
-
 
440
		p = TAIL_list(p);
-
 
441
	}
-
 
442
	fprintf_v(f, "#else\n");
-
 
443
	p = all_types;
-
 
444
	while (!IS_NULL_list(p)) {
-
 
445
		NAME t = DEREF_name(HEAD_list(p));
-
 
446
		int n = DEREF_int(name_number(t));
-
 
447
		n = code_letter(n);
-
 
448
		fprintf_v(f, "#define chk_%c( A ) ( A )\n", n);
-
 
449
		p = TAIL_list(p);
-
 
450
	}
-
 
451
	fprintf_v(f, "#endif\n\n\n");
-
 
452
 
-
 
453
	/* Print error macros */
-
 
454
	fprintf_v ( f, "/* Error message macros */\n\n" ) ;
-
 
455
	fprintf_v(f, "#ifdef %sGEN\n\n", pre);
-
 
456
	while (!IS_NULL_list(q)) {
-
 
457
		ENTRY e = DEREF_entry(HEAD_list(q));
-
 
458
		string en = DEREF_string(entry_name(e));
-
 
459
		LIST(PARAM) ep = DEREF_list(entry_signature(e));
-
 
460
		unsigned np = LENGTH_list(ep);
-
 
461
		fprintf_v(f, "#define %s%s(", pre, en);
-
 
462
		if (!IS_NULL_list(ep)) {
-
 
463
			/* Print parameter list */
-
 
464
			int arg = 0;
-
 
465
			LIST(PARAM)eq = ep;
-
 
466
			while (!IS_NULL_list(eq)) {
-
 
467
				if (arg) {
-
 
468
					fputc_v(',', f);
-
 
469
				}
-
 
470
				fprintf_v(f, " %c", 'A' + arg);
-
 
471
				eq = TAIL_list(eq);
-
 
472
				arg++;
-
 
473
			}
-
 
474
			fputc_v(' ', f);
-
 
475
		}
-
 
476
		fprintf_v(f, ")\\\n");
-
 
477
		fprintf_v(f, "\t%sGEN ( %d", pre, qn);
-
 
478
		if (np) {
-
 
479
			/* Print error definition */
-
 
480
			int arg = 0;
-
 
481
			LIST(PARAM) eq = ep;
-
 
482
			while (!IS_NULL_list(eq)) {
-
 
483
				PARAM a = DEREF_param(HEAD_list(eq));
-
 
484
				TYPE at = DEREF_name(param_type(a));
-
 
485
				int an = DEREF_int(name_number(at));
-
 
486
				an = code_letter(an);
-
 
487
				fprintf_v(f, ", chk_%c ( %c )", an, 'A' + arg);
-
 
488
				eq = TAIL_list(eq);
-
 
489
				arg++;
156
			}
490
			}
157
			fputc_v ( c, f ) ;
-
 
158
		    }
-
 
159
		}
491
		}
-
 
492
		fprintf_v(f, " )\n\n");
-
 
493
		q = TAIL_list(q);
-
 
494
		qn++;
-
 
495
	}
-
 
496
	fprintf_v(f, "\n#endif\n#endif\n");
-
 
497
	return;
-
 
498
}
-
 
499
 
-
 
500
 
-
 
501
/*
-
 
502
    OUTPUT ERROR NUMBERS
-
 
503
 
-
 
504
    This routine outputs all the error numbers to the file f.
-
 
505
*/
-
 
506
 
-
 
507
static void
-
 
508
output_number(FILE *f)
-
 
509
{
-
 
510
	int qn = 0;
-
 
511
	LIST(ENTRY) q = all_entries;
-
 
512
	char *pre = rig_comp_output;
-
 
513
	char *pre_db = rig_from_db;
-
 
514
	fprintf_v(f, "#ifndef %sNO_INCLUDED\n", pre);
-
 
515
	fprintf_v(f, "#define %sNO_INCLUDED\n\n\n", pre);
-
 
516
	fprintf_v(f, "/* Error message macros */\n\n");
-
 
517
	while (!IS_NULL_list(q)) {
-
 
518
		ENTRY e = DEREF_entry(HEAD_list(q));
-
 
519
		string en = DEREF_string(entry_name(e));
-
 
520
		fprintf_v(f, "#define %s%s %d\n", pre_db, en, qn);
-
 
521
		q = TAIL_list(q);
-
 
522
		qn++;
-
 
523
	}
-
 
524
	fprintf_v(f, "\n#endif\n");
-
 
525
	return;
-
 
526
}
-
 
527
 
-
 
528
 
-
 
529
/*
-
 
530
    OUTPUT USAGES
-
 
531
 
-
 
532
    This routine output all the usages to the file f.
-
 
533
*/
-
 
534
 
-
 
535
static void
-
 
536
output_usage(FILE *f)
-
 
537
{
-
 
538
	char *pre = rig_comp_output;
-
 
539
	char *pre_comp = rig_from_comp;
-
 
540
	LIST(USAGE) p = all_usages;
-
 
541
	LIST(USAGE) q = all_usages_aux;
-
 
542
	LIST(USAGE) r = all_usages_alt;
-
 
543
	while (!IS_NULL_list(p)) {
-
 
544
		USAGE u = DEREF_name(HEAD_list(p));
-
 
545
		USAGE v = DEREF_name(HEAD_list(q));
-
 
546
		USAGE w = DEREF_name(HEAD_list(r));
-
 
547
		string s = DEREF_string(name_id(u));
-
 
548
		string t = DEREF_string(name_id(v));
-
 
549
		if (!EQ_name(v, w)) {
-
 
550
			fprintf_v(f, "#ifndef %sALTERNATE\n", pre);
-
 
551
		}
-
 
552
		fprintf_v(f, "{ \"%s\", %sVALUE_%s },\n", s, pre_comp, t);
-
 
553
		if (!EQ_name(v, w)) {
-
 
554
			t = DEREF_string(name_id(w));
-
 
555
			fprintf_v(f, "#else\n");
-
 
556
			fprintf_v(f, "{ \"%s\", %sVALUE_%s },\n", s, pre_comp,
-
 
557
				  t);
-
 
558
			fprintf_v(f, "#endif\n");
160
	    }
559
		}
-
 
560
		r = TAIL_list(r);
-
 
561
		q = TAIL_list(q);
-
 
562
		p = TAIL_list(p);
161
	}
563
	}
162
	p = TAIL_list ( p ) ;
-
 
163
    }
-
 
164
    fputc_v ( '"', f ) ;
-
 
165
    return ;
564
	return;
166
}
565
}
167
 
566
 
168
 
567
 
169
/*
568
/*
170
    OUTPUT ERROR DEFINITIONS 
569
    OUTPUT ALL INFORMATION
171
 
570
 
172
    This routine outputs all the error definitions to the file f.
571
    This routine outputs all the information gained into the file nm using
-
 
572
    the action indicated by act.  If nm is the null string then the standard
-
 
573
    output is used.
173
*/
574
*/
174
 
575
 
175
static void output_defn
576
void
176
    PROTO_N ( ( f ) )
-
 
177
    PROTO_T ( FILE *f )
577
output_all(char *nm, int act)
178
{
578
{
179
    /* Print error catalog */
-
 
180
    LIST ( NAME ) p ;
-
 
181
    char *d1 = db_name ;
-
 
182
    char *d2 = db_name_alt ;
-
 
183
    char *pre = rig_comp_output ;
-
 
184
    char *pre_comp = rig_from_comp ;
-
 
185
    LIST ( ENTRY ) q = all_entries ;
-
 
186
 
-
 
187
    /* Print each catalogue entry */
-
 
188
    fprintf_v ( f, "/* Error catalogue */\n\n" ) ;
-
 
189
    if ( streq ( d1, d2 ) ) {
-
 
190
	fprintf_v ( f, "%sCONST char *%sNAME = \"%s\" ;\n", pre, pre, d1 ) ;
-
 
191
    } else {
-
 
192
	fprintf_v ( f, "#ifndef %sALTERNATE\n", pre ) ;
-
 
193
	fprintf_v ( f, "%sCONST char *%sNAME = \"%s\" ;\n", pre, pre, d1 ) ;
-
 
194
	fprintf_v ( f, "#else\n" ) ;
-
 
195
	fprintf_v ( f, "%sCONST char *%sNAME = \"%s\" ;\n", pre, pre, d2 ) ;
-
 
196
	fprintf_v ( f, "#endif\n" ) ;
-
 
197
    }
-
 
198
    fprintf_v ( f, "\n%sDATA %sCATALOG [] = {\n", pre, pre ) ;
-
 
199
    while ( !IS_NULL_list ( q ) ) {
-
 
200
	unsigned u = 0 ;
-
 
201
	char *suff = ",\n" ;
-
 
202
	ENTRY e = DEREF_entry ( HEAD_list ( q ) ) ;
-
 
203
	string en = DEREF_string ( entry_name ( e ) ) ;
-
 
204
	USAGE eu = DEREF_name ( entry_use ( e ) ) ;
-
 
205
	USAGE ev = DEREF_name ( entry_alt_use ( e ) ) ;
-
 
206
	LIST ( MAP ) em = DEREF_list ( entry_maps ( e ) ) ;
-
 
207
	LIST ( PROPERTY ) eq = DEREF_list ( entry_props ( e ) ) ;
-
 
208
	LIST ( PARAM ) ep = DEREF_list ( entry_signature ( e ) ) ;
-
 
209
 
-
 
210
	/* Print error name */
579
	/* Open output file */
211
	fprintf_v ( f, "    {\n\t\"%s\",\n", en ) ;
-
 
212
 
-
 
213
	/* Print error signature */
-
 
214
	if ( IS_NULL_list ( ep ) ) {
-
 
215
	    fprintf_v ( f, "\tNULL,\n" ) ;
-
 
216
	} else {
580
	FILE *f;
217
	    fprintf_v ( f, "\t\"" ) ;
-
 
218
	    while ( !IS_NULL_list ( ep ) ) {
581
	if (nm == NULL || streq(nm, "-")) {
219
		PARAM a = DEREF_param ( HEAD_list ( ep ) ) ;
-
 
220
		TYPE at = DEREF_name ( param_type ( a ) ) ;
-
 
221
		int an = DEREF_int ( name_number ( at ) ) ;
-
 
222
		an = code_letter ( an ) ;
-
 
223
		fputc_v ( an, f ) ;
582
		f = stdout;
224
		ep = TAIL_list ( ep ) ;
-
 
225
	    }
583
		nm = NULL;
226
	    fprintf_v ( f, "\",\n" ) ;
-
 
227
	}
-
 
228
 
-
 
229
	/* Print error usage */
-
 
230
	if ( !EQ_name ( eu, ev ) ) {
-
 
231
	    fprintf_v ( f, "#ifndef %sALTERNATE\n", pre ) ;
-
 
232
	}
-
 
233
	if ( IS_NULL_name ( eu ) ) {
-
 
234
	    fprintf_v ( f, "\t0,\n" ) ;
-
 
235
	} else {
584
	} else {
236
	    string un = DEREF_string ( name_id ( eu ) ) ;
-
 
237
	    fprintf_v ( f, "\t%s%s,\n", pre_comp, un ) ;
-
 
238
	}
-
 
239
	if ( !EQ_name ( eu, ev ) ) {
-
 
240
	    fprintf_v ( f, "#else\n" ) ;
-
 
241
	    if ( IS_NULL_name ( ev ) ) {
-
 
242
		fprintf_v ( f, "\t0,\n" ) ;
585
		f = fopen(nm, "w");
243
	    } else {
586
		if (f == NULL) {
244
		string vn = DEREF_string ( name_id ( ev ) ) ;
587
			error(ERROR_SERIOUS, "Can't open output file, '%s'",
245
		fprintf_v ( f, "\t%s%s,\n", pre_comp, vn ) ;
-
 
246
	    }
588
			      nm);
247
	    fprintf_v ( f, "#endif\n" ) ;
-
 
248
	}
-
 
249
 
-
 
250
	/* Print error properties */
-
 
251
	p = all_keys ;
-
 
252
	if ( IS_NULL_list ( p ) ) suff = "\n" ;
-
 
253
	while ( !IS_NULL_list ( eq ) ) {
-
 
254
	    PROPERTY nq = DEREF_name ( HEAD_list ( eq ) ) ;
-
 
255
	    unsigned n = ( unsigned ) DEREF_int ( name_number ( nq ) ) ;
-
 
256
	    u |= ( ( ( unsigned ) 1 ) << n ) ;
-
 
257
	    eq = TAIL_list ( eq ) ;
-
 
258
	}
-
 
259
	fprintf_v ( f, "\t%u%s", u, suff ) ;
-
 
260
 
-
 
261
	/* Print error keys */
-
 
262
	while ( !IS_NULL_list ( p ) ) {
-
 
263
	    NAME n = DEREF_name ( HEAD_list ( p ) ) ;
-
 
264
	    string pn = DEREF_string ( name_id ( n ) ) ;
-
 
265
	    MAP pm = find_map ( em, pn ) ;
-
 
266
	    p = TAIL_list ( p ) ;
-
 
267
	    if ( IS_NULL_list ( p ) ) suff = "\n" ;
-
 
268
	    if ( IS_NULL_map ( pm ) ) {
-
 
269
		fprintf_v ( f, "\tNULL%s", suff ) ;
-
 
270
	    } else {
589
			return;
271
		LIST ( MESSAGE ) m1 = DEREF_list ( map_msg ( pm ) ) ;
-
 
272
		LIST ( MESSAGE ) m2 = DEREF_list ( map_alt_msg ( pm ) ) ;
-
 
273
		if ( !EQ_list ( m1, m2 ) ) {
-
 
274
		    fprintf_v ( f, "#ifndef %sALTERNATE\n", pre ) ;
-
 
275
		}
-
 
276
		fprintf_v ( f, "\t" ) ;
-
 
277
		output_msg ( f, m1 ) ;
-
 
278
		fprintf_v ( f, "%s", suff ) ;
-
 
279
		if ( !EQ_list ( m1, m2 ) ) {
-
 
280
		    fprintf_v ( f, "#else\n\t" ) ;
-
 
281
		    output_msg ( f, m2 ) ;
-
 
282
		    fprintf_v ( f, "%s#endif\n", suff ) ;
-
 
283
		}
590
		}
284
	    }
-
 
285
	}
591
	}
286
	fprintf_v ( f, "    },\n" ) ;
-
 
287
	q = TAIL_list ( q ) ;
-
 
288
    }
-
 
289
 
592
 
290
    /* Print dummy end marker */
593
	/* Print header comment */
291
    fprintf_v ( f, "    {\n" ) ;
-
 
292
    fprintf_v ( f, "\tNULL,\n" ) ;
-
 
293
    fprintf_v ( f, "\tNULL,\n" ) ;
-
 
294
    fprintf_v ( f, "\t0,\n" ) ;
-
 
295
    fprintf_v ( f, "\t0" ) ;
594
	if (first_comment) {
296
    p = all_keys ;
-
 
297
    while ( !IS_NULL_list ( p ) ) {
-
 
298
	fprintf_v ( f, ",\n\tNULL" ) ;
595
		fprintf_v(f, "%s\n\n", first_comment);
299
	p = TAIL_list ( p ) ;
-
 
300
    }
-
 
301
    fprintf_v ( f, "\n    }\n" ) ;
-
 
302
    fprintf_v ( f, "} ;\n" ) ;
-
 
303
    return ;
-
 
304
}
596
	}
305
 
-
 
306
 
-
 
307
/*
-
 
308
    OUTPUT ERROR DECLARATIONS 
-
 
309
 
-
 
310
    This routine outputs all the error declarations to the file f.
-
 
311
*/
-
 
312
 
-
 
313
static void output_decl
-
 
314
    PROTO_N ( ( f ) )
-
 
315
    PROTO_T ( FILE *f )
-
 
316
{
-
 
317
    int qn = 0 ;
-
 
318
    LIST ( ENTRY ) q = all_entries ;
-
 
319
 
-
 
320
    /* Print main type definition */
-
 
321
    char *pre = rig_comp_output ;
-
 
322
    char *pre_comp = rig_from_comp ;
-
 
323
    LIST ( NAME ) p = all_keys ;
-
 
324
    fprintf_v ( f, "#ifndef %sINCLUDED\n", pre ) ;
-
 
325
    fprintf_v ( f, "#define %sINCLUDED\n\n\n", pre ) ;
-
 
326
    fprintf_v ( f, "/* Error data structure */\n\n" ) ;
-
 
327
    fprintf_v ( f, "#ifndef %sCONST\n", pre ) ;
-
 
328
    fprintf_v ( f, "#define %sCONST\n", pre ) ;
-
 
329
    fprintf_v ( f, "#endif\n\n" ) ;
-
 
330
    if ( LENGTH_list ( all_props ) < 16 ) {
-
 
331
	fprintf_v ( f, "typedef unsigned %sPROPS ;\n\n", pre ) ;
-
 
332
    } else {
-
 
333
	fprintf_v ( f, "typedef unsigned long %sPROPS ;\n\n", pre ) ;
-
 
334
    }
-
 
335
    fprintf_v ( f, "typedef struct {\n" ) ;
-
 
336
    fprintf_v ( f, "    %sCONST char *name ;\n", pre ) ;
-
 
337
    fprintf_v ( f, "    %sCONST char *signature ;\n", pre ) ;
-
 
338
    fprintf_v ( f, "    int usage ;\n" ) ;
-
 
339
    fprintf_v ( f, "    %sPROPS props ;\n", pre ) ;
-
 
340
    while ( !IS_NULL_list ( p ) ) {
-
 
341
	NAME t = DEREF_name ( HEAD_list ( p ) ) ;
-
 
342
	string tn = DEREF_string ( name_id ( t ) ) ;
-
 
343
	fprintf_v ( f, "    %sCONST char *key_%s ;\n", pre, tn ) ;
597
	fprintf_v ( f, "/* AUTOMATICALLY GENERATED BY %s FROM %s */\n\n\n",
344
	p = TAIL_list ( p ) ;
-
 
345
    }
-
 
346
    fprintf_v ( f, "} %sDATA ;\n\n", pre ) ;
-
 
347
    fprintf_v ( f, "extern %sDATA %sCATALOG [] ;\n", pre, pre ) ;
-
 
348
    fprintf_v ( f, "extern %sCONST char *%sNAME ;\n\n\n", pre, pre ) ;
-
 
349
 
-
 
350
    /* Print type keys */
-
 
351
    p = all_types ;
598
		    progname, db_name);
352
    fprintf_v ( f, "/* Error type keys */\n\n" ) ;
-
 
353
    while ( !IS_NULL_list ( p ) ) {
-
 
354
	NAME t = DEREF_name ( HEAD_list ( p ) ) ;
-
 
355
	string tn = DEREF_string ( name_id ( t ) ) ;
-
 
356
	int n = DEREF_int ( name_number ( t ) ) ;
-
 
357
	n = code_letter ( n ) ;
-
 
358
	fprintf_v ( f, "#define %sKEY_%s '%c'\n", pre, tn, n ) ;
-
 
359
	p = TAIL_list ( p ) ;
-
 
360
    }
-
 
361
    fprintf_v ( f, "\n\n" ) ;
-
 
362
 
599
 
363
    /* Print usage keys */
-
 
364
    p = all_usages ;
-
 
365
    fprintf_v ( f, "/* Error usage keys */\n\n" ) ;
-
 
366
    fprintf_v ( f, "#ifndef %sUSE\n", pre ) ;
-
 
367
    while ( !IS_NULL_list ( p ) ) {
-
 
368
	NAME t = DEREF_name ( HEAD_list ( p ) ) ;
-
 
369
	string tn = DEREF_string ( name_id ( t ) ) ;
-
 
370
	int n = DEREF_int ( name_number ( t ) ) ;
-
 
371
	fprintf_v ( f, "#define %s%s %d\n", pre_comp, tn, n ) ;
-
 
372
	p = TAIL_list ( p ) ;
-
 
373
    }
-
 
374
    fprintf_v ( f, "#endif\n\n\n" ) ;
-
 
375
 
-
 
376
    /* Print property keys */
600
	/* Print appropriate information */
377
    p = all_props ;
-
 
378
    fprintf_v ( f, "/* Error property keys */\n\n" ) ;
-
 
379
    fprintf_v ( f, "#ifndef %sPROP\n", pre ) ;
-
 
380
    while ( !IS_NULL_list ( p ) ) {
-
 
381
	NAME t = DEREF_name ( HEAD_list ( p ) ) ;
-
 
382
	string tn = DEREF_string ( name_id ( t ) ) ;
-
 
383
	unsigned n = ( unsigned ) DEREF_int ( name_number ( t ) ) ;
-
 
384
	unsigned u = ( ( ( unsigned ) 1 ) << n ) ;
-
 
385
	fprintf_v ( f, "#define %sPROP_%s ( ( %sPROPS ) 0x%x )\n",
-
 
386
		    pre, tn, pre, u ) ;
-
 
387
	p = TAIL_list ( p ) ;
601
	switch (act) {
388
    }
602
	case 0:
389
    fprintf_v ( f, "#endif\n\n\n" ) ;
-
 
390
 
-
 
391
    /* Print type checking macros */
-
 
392
    p = all_types ;
-
 
393
    fprintf_v ( f, "/* Error type checking */\n\n" ) ;
-
 
394
    fprintf_v ( f, "#if defined ( %sCHECK ) && defined ( __STDC__ )\n", pre ) ;
-
 
395
    while ( !IS_NULL_list ( p ) ) {
-
 
396
	NAME t = DEREF_name ( HEAD_list ( p ) ) ;
-
 
397
	string tn = DEREF_string ( name_id ( t ) ) ;
-
 
398
	int n = DEREF_int ( name_number ( t ) ) ;
-
 
399
	n = code_letter ( n ) ;
-
 
400
	fprintf_v ( f, "extern %s chk_%c ( %s ) ;\n", tn, n, tn ) ;
-
 
401
	p = TAIL_list ( p ) ;
603
		output_decl(f);
402
    }
604
		break;
403
    fprintf_v ( f, "#else\n" ) ;
-
 
404
    p = all_types ;
-
 
405
    while ( !IS_NULL_list ( p ) ) {
-
 
406
	NAME t = DEREF_name ( HEAD_list ( p ) ) ;
-
 
407
	int n = DEREF_int ( name_number ( t ) ) ;
-
 
408
	n = code_letter ( n ) ;
-
 
409
	fprintf_v ( f, "#define chk_%c( A ) ( A )\n", n ) ;
-
 
410
	p = TAIL_list ( p ) ;
-
 
411
    }
605
	case 1:
412
    fprintf_v ( f, "#endif\n\n\n" ) ;
-
 
413
 
-
 
414
    /* Print error macros */
-
 
415
    fprintf_v ( f, "/* Error message macros */\n\n" ) ;
-
 
416
    fprintf_v ( f, "#ifdef %sGEN\n\n", pre ) ;
-
 
417
    while ( !IS_NULL_list ( q ) ) {
-
 
418
	ENTRY e = DEREF_entry ( HEAD_list ( q ) ) ;
-
 
419
	string en = DEREF_string ( entry_name ( e ) ) ;
-
 
420
	LIST ( PARAM ) ep = DEREF_list ( entry_signature ( e ) ) ;
-
 
421
	unsigned np = LENGTH_list ( ep ) ;
-
 
422
	fprintf_v ( f, "#define %s%s(", pre, en ) ;
-
 
423
	if ( !IS_NULL_list ( ep ) ) {
-
 
424
	    /* Print parameter list */
-
 
425
	    int arg = 0 ;
606
		output_defn(f);
426
	    LIST ( PARAM ) eq = ep ;
-
 
427
	    while ( !IS_NULL_list ( eq ) ) {
-
 
428
		if ( arg ) fputc_v ( ',', f ) ;
-
 
429
		fprintf_v ( f, " %c", 'A' + arg ) ;
-
 
430
		eq = TAIL_list ( eq ) ;
-
 
431
		arg++ ;
607
		break;
432
	    }
608
	case 2:
433
	    fputc_v ( ' ', f ) ;
609
		output_number(f);
434
	}
610
		break;
435
	fprintf_v ( f, ")\\\n" ) ;
-
 
436
	fprintf_v ( f, "\t%sGEN ( %d", pre, qn ) ;
-
 
437
	if ( np ) {
611
	case 3:
438
	    /* Print error definition */
-
 
439
	    int arg = 0 ;
612
		output_usage(f);
440
	    LIST ( PARAM ) eq = ep ;
-
 
441
	    while ( !IS_NULL_list ( eq ) ) {
-
 
442
		PARAM a = DEREF_param ( HEAD_list ( eq ) ) ;
-
 
443
		TYPE at = DEREF_name ( param_type ( a ) ) ;
-
 
444
		int an = DEREF_int ( name_number ( at ) ) ;
-
 
445
		an = code_letter ( an ) ;
-
 
446
		fprintf_v ( f, ", chk_%c ( %c )", an, 'A' + arg ) ;
-
 
447
		eq = TAIL_list ( eq ) ;
-
 
448
		arg++ ;
613
		break;
449
	    }
-
 
450
	}
614
	}
451
	fprintf_v ( f, " )\n\n" ) ;
-
 
452
	q = TAIL_list ( q ) ;
-
 
453
	qn++ ;
-
 
454
    }
-
 
455
    fprintf_v ( f, "\n#endif\n#endif\n" ) ;
-
 
456
    return ;
-
 
457
}
-
 
458
 
-
 
459
 
-
 
460
/*
-
 
461
    OUTPUT ERROR NUMBERS 
-
 
462
 
-
 
463
    This routine outputs all the error numbers to the file f.
-
 
464
*/
-
 
465
 
-
 
466
static void output_number
-
 
467
    PROTO_N ( ( f ) )
-
 
468
    PROTO_T ( FILE *f )
-
 
469
{
-
 
470
    int qn = 0 ;
-
 
471
    LIST ( ENTRY ) q = all_entries ;
-
 
472
    char *pre = rig_comp_output ;
-
 
473
    char *pre_db = rig_from_db ;
-
 
474
    fprintf_v ( f, "#ifndef %sNO_INCLUDED\n", pre ) ;
-
 
475
    fprintf_v ( f, "#define %sNO_INCLUDED\n\n\n", pre ) ;
-
 
476
    fprintf_v ( f, "/* Error message macros */\n\n" ) ;
-
 
477
    while ( !IS_NULL_list ( q ) ) {
-
 
478
	ENTRY e = DEREF_entry ( HEAD_list ( q ) ) ;
-
 
479
	string en = DEREF_string ( entry_name ( e ) ) ;
-
 
480
	fprintf_v ( f, "#define %s%s %d\n", pre_db, en, qn ) ;
-
 
481
	q = TAIL_list ( q ) ;
-
 
482
	qn++ ;
-
 
483
    }
-
 
484
    fprintf_v ( f, "\n#endif\n" ) ;
-
 
485
    return ;
-
 
486
}
-
 
487
 
-
 
488
 
-
 
489
/*
-
 
490
    OUTPUT USAGES
-
 
491
 
-
 
492
    This routine output all the usages to the file f.
-
 
493
*/
-
 
494
 
-
 
495
static void output_usage
-
 
496
    PROTO_N ( ( f ) )
-
 
497
    PROTO_T ( FILE *f )
-
 
498
{
-
 
499
    char *pre = rig_comp_output ;
-
 
500
    char *pre_comp = rig_from_comp ;
-
 
501
    LIST ( USAGE ) p = all_usages ;
-
 
502
    LIST ( USAGE ) q = all_usages_aux ;
-
 
503
    LIST ( USAGE ) r = all_usages_alt ;
-
 
504
    while ( !IS_NULL_list ( p ) ) {
-
 
505
	USAGE u = DEREF_name ( HEAD_list ( p ) ) ;
-
 
506
	USAGE v = DEREF_name ( HEAD_list ( q ) ) ;
-
 
507
	USAGE w = DEREF_name ( HEAD_list ( r ) ) ;
-
 
508
	string s = DEREF_string ( name_id ( u ) ) ;
-
 
509
	string t = DEREF_string ( name_id ( v ) ) ;
-
 
510
	if ( !EQ_name ( v, w ) ) {
-
 
511
	    fprintf_v ( f, "#ifndef %sALTERNATE\n", pre ) ;
-
 
512
	}
-
 
513
	fprintf_v ( f, "{ \"%s\", %sVALUE_%s },\n", s, pre_comp, t ) ;
-
 
514
	if ( !EQ_name ( v, w ) ) {
-
 
515
	    t = DEREF_string ( name_id ( w ) ) ;
-
 
516
	    fprintf_v ( f, "#else\n" ) ;
-
 
517
	    fprintf_v ( f, "{ \"%s\", %sVALUE_%s },\n", s, pre_comp, t ) ;
-
 
518
	    fprintf_v ( f, "#endif\n" ) ;
-
 
519
	}
-
 
520
	r = TAIL_list ( r ) ;
-
 
521
	q = TAIL_list ( q ) ;
-
 
522
	p = TAIL_list ( p ) ;
-
 
523
    }
-
 
524
    return ;
-
 
525
}
-
 
526
 
-
 
527
 
-
 
528
/*
-
 
529
    OUTPUT ALL INFORMATION
-
 
530
 
-
 
531
    This routine outputs all the information gained into the file nm using
-
 
532
    the action indicated by act.  If nm is the null string then the standard
-
 
533
    output is used.
-
 
534
*/
-
 
535
 
615
 
536
void output_all
-
 
537
    PROTO_N ( ( nm, act ) )
-
 
538
    PROTO_T ( char *nm X int act )
-
 
539
{
-
 
540
    /* Open output file */
616
	/* Close output file */
541
    FILE *f ;
-
 
542
    if ( nm == NULL || streq ( nm, "-" ) ) {
-
 
543
	f = stdout ;
-
 
544
	nm = NULL ;
-
 
545
    } else {
-
 
546
	f = fopen ( nm, "w" ) ;
-
 
547
	if ( f == NULL ) {
617
	if (nm != NULL) {
548
	    error ( ERROR_SERIOUS, "Can't open output file, '%s'", nm ) ;
-
 
549
	    return ;
618
		fclose_v(f);
550
	}
619
	}
551
    }
-
 
552
 
-
 
553
    /* Print header comment */
-
 
554
    if ( first_comment ) fprintf_v ( f, "%s\n\n", first_comment ) ;
-
 
555
    fprintf_v ( f, "/* AUTOMATICALLY GENERATED BY %s FROM %s */\n\n\n",
-
 
556
		progname, db_name ) ;
-
 
557
 
-
 
558
    /* Print appropriate information */
-
 
559
    switch ( act ) {
-
 
560
	case 0 : output_decl ( f ) ; break ;
-
 
561
	case 1 : output_defn ( f ) ; break ;
-
 
562
	case 2 : output_number ( f ) ; break ;
-
 
563
	case 3 : output_usage ( f ) ; break ;
-
 
564
    }
-
 
565
 
-
 
566
    /* Close output file */
-
 
567
    if ( nm != NULL ) fclose_v ( f ) ;
-
 
568
    return ;
620
	return;
569
}
621
}