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
*/
29
 
59
 
30
 
60
 
31
#include "config.h"
61
#include "config.h"
32
#include <ctype.h>
62
#include <ctype.h>
33
#include "types.h"
63
#include "types.h"
34
#include "file.h"
64
#include "file.h"
Line 42... Line 72...
42
#include "write.h"
72
#include "write.h"
43
 
73
 
44
 
74
 
45
/*
75
/*
46
    FLAGS CONTROLLING OUTPUT OF TOKENS ETC
76
    FLAGS CONTROLLING OUTPUT OF TOKENS ETC
47
 
77
 
48
    The output is in the fully expanded form if verbose is true.  The
78
    The output is in the fully expanded form if verbose is true.  The
49
    shape of each expression is printed if print_shapes is true.  The
79
    shape of each expression is printed if print_shapes is true.  The
50
    flag func_output controls whether the output should be lisp-like
80
    flag func_output controls whether the output should be lisp-like
51
    (default) or c-like.
81
    (default) or c-like.
52
*/
82
*/
53
 
83
 
54
boolean verbose = 0 ;
84
boolean verbose = 0;
55
boolean print_shapes = 0 ;
85
boolean print_shapes = 0;
56
boolean func_output = 0 ;
86
boolean func_output = 0;
-
 
87
 
57
 
88
 
-
 
89
static void	print_spaces(int);
58
 
90
 
59
/*
91
/*
60
    PRINT A NUMBER OF SPACES
92
    PRINT A NUMBER OF SPACES
61
 
93
 
62
    An indentation of d spaces is printed to the output file.
94
    An indentation of d spaces is printed to the output file.
63
*/
95
*/
64
 
96
 
65
void print_spaces
97
static void
66
    PROTO_N ( ( d ) )
-
 
67
    PROTO_T ( int d )
98
print_spaces(int d)
68
{
99
{
69
    int n = 2 * d ;
100
    int n = 2 * d;
70
    while ( n >= 8 ) {
101
    while (n >= 8) {
71
	IGNORE fputc ( '\t', output ) ;
102
	IGNORE fputc('\t', output);
72
	n -= 8 ;
103
	n -= 8;
73
    }
104
    }
74
    while ( n ) {
105
    while (n) {
75
	IGNORE fputc ( ' ', output ) ;
106
	IGNORE fputc(' ', output);
76
	n-- ;
107
	n--;
77
    }
108
    }
78
    return ;
109
    return;
79
}
110
}
80
 
111
 
81
 
112
 
82
/*
113
/*
83
    PRINT A NODE
114
    PRINT A NODE
84
 
115
 
85
    The node p is printed to the output file with an indentation of
116
    The node p is printed to the output file with an indentation of
86
    d spaces.
117
    d spaces.
87
*/
118
*/
88
 
119
 
89
static boolean print_node
120
static boolean
90
    PROTO_N ( ( p, d ) )
-
 
91
    PROTO_T ( node *p X int d )
121
print_node(node *p, int d)
92
{
122
{
93
    boolean negate = 0 ;
123
    boolean negate = 0;
94
    boolean newline = 0 ;
124
    boolean newline = 0;
95
    while ( p ) {
125
    while (p) {
96
	construct *q = p->cons ;
126
	construct *q = p->cons;
97
	sortname s = q->sortnum ;
127
	sortname s = q->sortnum;
98
	long m = q->encoding ;
128
	long m = q->encoding;
99
	newline = 0 ;
129
	newline = 0;
100
	switch ( s ) {
130
	switch (s) {
101
 
131
 
102
	    case SORT_tdfbool : {
132
	    case SORT_tdfbool: {
103
		/* Set neg for subsequent number */
133
		/* Set neg for subsequent number */
104
		negate = ( boolean ) ( m ? 1 : 0 ) ;
134
		negate = (boolean)(m ? 1 : 0);
105
		break ;
135
		break;
106
	    }
136
	    }
107
 
137
 
108
	    case SORT_bytestream : {
138
	    case SORT_bytestream: {
109
		/* Print a bytestream */
139
		/* Print a bytestream */
110
		newline = print_node ( p->son, d ) ;
140
		newline = print_node(p->son, d);
111
		break ;
141
		break;
112
	    }
142
	    }
113
 
143
 
114
	    case SORT_completion : {
144
	    case SORT_completion: {
115
		/* Print a completion */
145
		/* Print a completion */
116
		newline = print_node ( p->son, d ) ;
146
		newline = print_node(p->son, d);
117
		break ;
147
		break;
118
	    }
148
	    }
119
 
149
 
120
	    case SORT_small_tdfint : {
150
	    case SORT_small_tdfint: {
121
		/* Print a small number */
151
		/* Print a small number */
122
		long n = q->encoding ;
152
		long n = q->encoding;
123
		print_spaces ( d ) ;
153
		print_spaces(d);
124
		if ( negate ) n = -n ;
154
		if (negate)n = -n;
125
		IGNORE fprintf ( output, "%ld", n ) ;
155
		IGNORE fprintf(output, "%ld", n);
126
		negate = 0 ;
156
		negate = 0;
127
		newline = 1 ;
157
		newline = 1;
128
		break ;
158
		break;
129
	    }
159
	    }
130
 
160
 
131
	    case SORT_tdfint : {
161
	    case SORT_tdfint: {
132
		/* Print a number */
162
		/* Print a number */
133
		char *num = q->name ;
163
		char *num = q->name;
134
		print_spaces ( d ) ;
164
		print_spaces(d);
135
		if ( fits_ulong ( num, 0 ) ) {
165
		if (fits_ulong(num, 0)) {
136
		    unsigned long n = octal_to_ulong ( num ) ;
166
		    unsigned long n = octal_to_ulong(num);
137
		    if ( negate && n ) IGNORE fputc ( '-', output ) ;
167
		    if (negate && n)IGNORE fputc('-', output);
138
		    IGNORE fprintf ( output, "%lu", n ) ;
168
		    IGNORE fprintf(output, "%lu", n);
139
		} else {
169
		} else {
140
		    if ( negate ) IGNORE fputc ( '-', output ) ;
170
		    if (negate)IGNORE fputc('-', output);
141
		    IGNORE fprintf ( output, "0%s", num ) ;
171
		    IGNORE fprintf(output, "0%s", num);
142
		}
172
		}
143
		negate = 0 ;
173
		negate = 0;
144
		newline = 1 ;
174
		newline = 1;
145
		break ;
175
		break;
146
	    }
176
	    }
147
 
177
 
148
	    case SORT_option : {
178
	    case SORT_option: {
149
		/* Print an optional argument */
179
		/* Print an optional argument */
150
		if ( p->son ) {
180
		if (p->son) {
151
		    newline = print_node ( p->son, d ) ;
181
		    newline = print_node(p->son, d);
152
		} else {
182
		} else {
153
		    print_spaces ( d ) ;
183
		    print_spaces(d);
154
		    IGNORE fputc ( '-', output ) ;
184
		    IGNORE fputc('-', output);
155
		    newline = 1 ;
185
		    newline = 1;
156
		}
186
		}
157
		break ;
187
		break;
158
	    }
188
	    }
159
 
189
 
160
	    case SORT_repeat : {
190
	    case SORT_repeat: {
161
		/* Print a repeated argument */
191
		/* Print a repeated argument */
162
		if ( m == 0 ) {
192
		if (m == 0) {
163
		    print_spaces ( d ) ;
193
		    print_spaces(d);
164
		    IGNORE fputc ( '|', output ) ;
194
		    IGNORE fputc('|', output);
165
		    newline = 1 ;
195
		    newline = 1;
166
		} else {
196
		} else {
167
		    newline = print_node ( p->son, d ) ;
197
		    newline = print_node(p->son, d);
168
		    if ( func_output ) IGNORE fputc ( ',', output ) ;
198
		    if (func_output)IGNORE fputc(',', output);
169
		    IGNORE fputs ( " |", output ) ;
199
		    IGNORE fputs(" |", output);
170
		}
200
		}
171
		break ;
201
		break;
172
	    }
202
	    }
173
 
203
 
174
	    case SORT_tdfstring : {
204
	    case SORT_tdfstring: {
175
		/* Print a string */
205
		/* Print a string */
176
		int i, n = ( int ) m ;
206
		int i, n = (int)m;
177
		print_spaces ( d ) ;
207
		print_spaces(d);
178
		if ( n == -1 ) {
208
		if (n == -1) {
179
		    char *f = ( func_output ? "%s (\n" : "( %s\n" ) ;
209
		    char *f = (func_output ? "%s (\n" : "( %s\n");
180
		    IGNORE fprintf ( output, f, MAKE_STRING ) ;
210
		    IGNORE fprintf(output, f, MAKE_STRING);
181
		    newline = print_node ( p->son, d + 1 ) ;
211
		    newline = print_node(p->son, d + 1);
182
		    IGNORE fputs ( " )", output ) ;
212
		    IGNORE fputs(" )", output);
183
		} else {
213
		} else {
184
		    IGNORE fputc ( '"', output ) ;
214
		    IGNORE fputc('"', output);
185
		    for ( i = 0 ; i < n ; i++ ) {
215
		    for (i = 0; i < n; i++) {
186
			int c = ( ( q->name [i] ) & 0xff ) ;
216
			int c = ((q->name[i]) & 0xff);
187
			if ( isprint ( c ) ) {
217
			if (isprint(c)) {
188
			    if ( c == '\\' || c == '"' ) {
218
			    if (c == '\\' || c == '"') {
189
				IGNORE fputc ( '\\', output ) ;
219
				IGNORE fputc('\\', output);
190
			    }
220
			    }
191
			    IGNORE fputc ( c, output ) ;
221
			    IGNORE fputc(c, output);
192
			} else {
222
			} else {
193
			    if ( c == '\n' ) {
223
			    if (c == '\n') {
194
				IGNORE fputs ( "\\n", output ) ;
224
				IGNORE fputs("\\n", output);
195
			    } else if ( c == '\t' ) {
225
			    } else if (c == '\t') {
196
				IGNORE fputs ( "\\t", output ) ;
226
				IGNORE fputs("\\t", output);
197
			    } else {
227
			    } else {
198
				unsigned co = ( unsigned ) c ;
228
				unsigned co = (unsigned)c;
199
				IGNORE fprintf ( output, "\\%03o", co ) ;
229
				IGNORE fprintf(output, "\\%03o", co);
200
			    }
230
			    }
201
			}
231
			}
202
		    }
232
		    }
203
		    IGNORE fputc ( '"', output ) ;
233
		    IGNORE fputc('"', output);
204
		    newline = 1 ;
234
		    newline = 1;
205
		}
235
		}
206
		break ;
236
		break;
207
	    }
237
	    }
208
 
238
 
209
	    case SORT_nat : {
239
	    case SORT_nat: {
210
		/* Print a nat */
240
		/* Print a nat */
211
		if ( m != ENC_make_nat ) goto default_label ;
241
		if (m != ENC_make_nat)goto default_label;
212
		newline = print_node ( p->son, d ) ;
242
		newline = print_node(p->son, d);
213
		break ;
243
		break;
214
	    }
244
	    }
215
 
245
 
216
	    case SORT_signed_nat : {
246
	    case SORT_signed_nat: {
217
		/* Print a signed_nat */
247
		/* Print a signed_nat */
218
		if ( m != ENC_make_signed_nat ) goto default_label ;
248
		if (m != ENC_make_signed_nat)goto default_label;
219
		newline = print_node ( p->son, d ) ;
249
		newline = print_node(p->son, d);
220
		break ;
250
		break;
221
	    }
251
	    }
222
 
252
 
223
	    case SORT_string : {
253
	    case SORT_string: {
224
		/* Print a string */
254
		/* Print a string */
225
		if ( m != ENC_make_string ) goto default_label ;
255
		if (m != ENC_make_string)goto default_label;
226
		newline = print_node ( p->son, d ) ;
256
		newline = print_node(p->son, d);
227
		break ;
257
		break;
228
	    }
258
	    }
229
 
259
 
230
	    case SORT_al_tag : {
260
	    case SORT_al_tag: {
231
		/* Print an alignment tag */
261
		/* Print an alignment tag */
232
		if ( verbose || m != ENC_make_al_tag || p->son == null ) {
262
		if (verbose || m != ENC_make_al_tag || p->son == null) {
233
		    goto default_label ;
263
		    goto default_label;
234
		}
264
		}
235
		newline = print_node ( p->son, d ) ;
265
		newline = print_node(p->son, d);
236
		break ;
266
		break;
237
	    }
267
	    }
238
 
268
 
239
	    case SORT_label : {
269
	    case SORT_label: {
240
		/* Print a label */
270
		/* Print a label */
241
		if ( verbose || m != ENC_make_label || p->son == null ) {
271
		if (verbose || m != ENC_make_label || p->son == null) {
242
		    goto default_label ;
272
		    goto default_label;
243
		}
273
		}
244
		newline = print_node ( p->son, d ) ;
274
		newline = print_node(p->son, d);
245
		break ;
275
		break;
246
	    }
276
	    }
247
 
277
 
248
	    case SORT_tag : {
278
	    case SORT_tag: {
249
		/* Print a tag */
279
		/* Print a tag */
250
		if ( verbose || m != ENC_make_tag || p->son == null ) {
280
		if (verbose || m != ENC_make_tag || p->son == null) {
251
		    goto default_label ;
281
		    goto default_label;
252
		}
282
		}
253
		newline = print_node ( p->son, d ) ;
283
		newline = print_node(p->son, d);
254
		break ;
284
		break;
255
	    }
285
	    }
256
 
286
 
257
	    case SORT_exp : {
287
	    case SORT_exp: {
258
		static node special_node ;
288
		static node special_node;
259
		if ( print_shapes && p->shape != &special_node ) {
289
		if (print_shapes && p->shape != &special_node) {
260
		    /* Change exp to show shape */
290
		    /* Change exp to show shape */
261
		    node *z = new_node () ;
291
		    node *z = new_node();
262
		    z->cons = &exp_shape ;
292
		    z->cons = &exp_shape;
263
		    z->bro = p->bro ;
293
		    z->bro = p->bro;
264
		    z->son = p ;
294
		    z->son = p;
265
		    if ( p->shape ) {
295
		    if (p->shape) {
266
			z->son->bro = copy_node ( p->shape ) ;
296
			z->son->bro = copy_node(p->shape);
267
		    } else {
297
		    } else {
268
			z->son->bro = new_node () ;
298
			z->son->bro = new_node();
269
			z->son->bro->cons = &unknown_cons ;
299
			z->son->bro->cons = &unknown_cons;
270
		    }
300
		    }
271
		    p->shape = &special_node ;
301
		    p->shape = &special_node;
272
		    p = z ;
302
		    p = z;
273
		    q = p->cons ;
303
		    q = p->cons;
274
		    m = q->encoding ;
304
		    m = q->encoding;
275
		}
305
		}
276
		goto default_label ;
306
		goto default_label;
277
	    }
307
	    }
278
 
308
 
279
	    default : {
309
	    default : {
280
		/* Print a simple sort */
310
		/* Print a simple sort */
281
		default_label : {
311
		default_label : {
282
		    if ( !verbose && m == sort_tokens [s] && p->son &&
312
		    if (!verbose && m == sort_tokens[s] && p->son &&
283
			 p->son->cons->sortnum == SORT_token ) {
313
			 p->son->cons->sortnum == SORT_token) {
284
			newline = print_node ( p->son, d ) ;
314
			newline = print_node(p->son, d);
285
		    } else {
315
		    } else {
286
			print_spaces ( d ) ;
316
			print_spaces(d);
287
			if ( p->son ) {
317
			if (p->son) {
288
			    char *f = ( func_output ? "%s (\n" : "( %s\n" ) ;
318
			    char *f = (func_output ? "%s (\n" : "( %s\n");
289
			    IGNORE fprintf ( output, f, q->name ) ;
319
			    IGNORE fprintf(output, f, q->name);
290
			    newline = print_node ( p->son, d + 1 ) ;
320
			    newline = print_node(p->son, d + 1);
291
			    IGNORE fputs ( " )", output ) ;
321
			    IGNORE fputs(" )", output);
292
			} else {
322
			} else {
293
			    IGNORE fprintf ( output, "%s", q->name ) ;
323
			    IGNORE fprintf(output, "%s", q->name);
294
			    newline = 1 ;
324
			    newline = 1;
295
			}
325
			}
296
		    }
326
		    }
297
		}
327
		}
298
		break ;
328
		break;
299
	    }
329
	    }
300
	}
330
	}
301
	p = p->bro ;
331
	p = p->bro;
302
	if ( newline && p ) {
332
	if (newline && p) {
303
	    if ( func_output ) IGNORE fputc ( ',', output ) ;
333
	    if (func_output)IGNORE fputc(',', output);
304
	    IGNORE fputc ( '\n', output ) ;
334
	    IGNORE fputc('\n', output);
305
	    newline = 0 ;
335
	    newline = 0;
306
	}
336
	}
307
    }
337
    }
308
    return ( newline ) ;
338
    return(newline);
309
}
339
}
310
 
340
 
311
 
341
 
312
/*
342
/*
313
    PRINT AN EXTERNAL NAME
343
    PRINT AN EXTERNAL NAME
314
 
344
 
315
    The start of a statement with name title concerning the construct
345
    The start of a statement with name title concerning the construct
316
    p is output.  dec is true if this is the first statement concerning p.
346
    p is output.  dec is true if this is the first statement concerning p.
317
*/
347
*/
318
 
348
 
319
static void print_name
349
static void
320
    PROTO_N ( ( title, p, dec ) )
-
 
321
    PROTO_T ( char *title X construct *p X int dec )
350
print_name(char *title, construct *p, int dec)
322
{
351
{
323
    if ( !func_output ) IGNORE fputs ( "( ", output ) ;
352
    if (!func_output)IGNORE fputs("( ", output);
324
    if ( p->ename == null ) IGNORE fprintf ( output, "%s ", LOCAL_DECL ) ;
353
    if (p->ename == null)IGNORE fprintf(output, "%s ", LOCAL_DECL);
325
    IGNORE fprintf ( output, "%s", title ) ;
354
    IGNORE fprintf(output, "%s", title);
326
    if ( func_output ) IGNORE fputs ( " (", output ) ;
355
    if (func_output)IGNORE fputs(" (", output);
327
    if ( p->ename && p->ename->cons->encoding && dec ) {
356
    if (p->ename && p->ename->cons->encoding && dec) {
328
	char *f = ( func_output ? "\n  %s (\n" : "\n  ( %s\n" ) ;
357
	char *f = (func_output ? "\n  %s (\n" : "\n  ( %s\n");
329
	if ( p->ename->son->cons->sortnum == SORT_tdfstring ) {
358
	if (p->ename->son->cons->sortnum == SORT_tdfstring) {
330
	    if ( p->ename->son->bro == null ) {
359
	    if (p->ename->son->bro == null) {
331
		IGNORE fprintf ( output, f, MAKE_STRING_EXTERN ) ;
360
		IGNORE fprintf(output, f, MAKE_STRING_EXTERN);
332
	    } else {
361
	    } else {
333
		IGNORE fprintf ( output, f, MAKE_CHAIN_EXTERN ) ;
362
		IGNORE fprintf(output, f, MAKE_CHAIN_EXTERN);
334
	    }
363
	    }
335
	} else {
364
	} else {
336
	    IGNORE fprintf ( output, f, MAKE_UNIQUE_EXTERN ) ;
365
	    IGNORE fprintf(output, f, MAKE_UNIQUE_EXTERN);
337
	}
366
	}
338
	IGNORE print_node ( p->ename->son, 2 ) ;
367
	IGNORE print_node(p->ename->son, 2);
339
	if ( func_output ) {
368
	if (func_output) {
340
	    IGNORE fputs ( " ),\n  ", output ) ;
369
	    IGNORE fputs(" ),\n  ", output);
341
	} else {
370
	} else {
342
	    IGNORE fputs ( " )\n  ", output ) ;
371
	    IGNORE fputs(" )\n  ", output);
343
	}
372
	}
344
    } else {
373
    } else {
345
	IGNORE fputc ( ' ', output ) ;
374
	IGNORE fputc(' ', output);
346
    }
375
    }
347
    IGNORE fprintf ( output, "%s", p->name ) ;
376
    IGNORE fprintf(output, "%s", p->name);
348
    return ;
377
    return;
349
}
378
}
350
 
379
 
351
 
380
 
352
/*
381
/*
353
    ALIGNMENT TAG DECLARATION AUXILIARY PRINTING ROUTINE
382
    ALIGNMENT TAG DECLARATION AUXILIARY PRINTING ROUTINE
354
 
383
 
355
    Print the declaration of the alignment tag p.
384
    Print the declaration of the alignment tag p.
356
*/
385
*/
357
 
386
 
358
static void print_aldec
387
static void
359
    PROTO_N ( ( p ) )
-
 
360
    PROTO_T ( construct *p )
388
print_aldec(construct *p)
361
{
389
{
362
    if ( p->encoding == -1 ) return ;
390
    if (p->encoding == -1) return;
363
    print_name ( MAKE_ALDEC, p, 1 ) ;
391
    print_name(MAKE_ALDEC, p, 1);
364
    IGNORE fputs ( ( func_output ? " ) ;\n\n" : " )\n\n" ), output ) ;
392
    IGNORE fputs((func_output ? " ) ;\n\n" : " )\n\n"), output);
365
    return ;
393
    return;
366
}
394
}
367
 
395
 
368
 
396
 
369
/*
397
/*
370
    ALIGNMENT TAG DEFINITION AUXILIARY PRINTING ROUTINE
398
    ALIGNMENT TAG DEFINITION AUXILIARY PRINTING ROUTINE
371
 
399
 
372
    Print the definition of the alignment tag p.
400
    Print the definition of the alignment tag p.
373
*/
401
*/
374
 
402
 
375
static void print_aldef
403
static void
376
    PROTO_N ( ( p ) )
-
 
377
    PROTO_T ( construct *p )
404
print_aldef(construct *p)
378
{
405
{
379
    al_tag_info *info = get_al_tag_info ( p ) ;
406
    al_tag_info *info = get_al_tag_info(p);
380
    if ( p->encoding == -1 ) return ;
407
    if (p->encoding == -1) return;
381
    if ( info->def == null ) return ;
408
    if (info->def == null) return;
382
    print_name ( MAKE_ALDEF, p, !show_aldecs ) ;
409
    print_name(MAKE_ALDEF, p, !show_aldecs);
383
    if ( func_output ) IGNORE fputc ( ',', output ) ;
410
    if (func_output)IGNORE fputc(',', output);
384
    IGNORE fputc ( '\n', output ) ;
411
    IGNORE fputc('\n', output);
385
    IGNORE print_node ( info->def, 1 ) ;
412
    IGNORE print_node(info->def, 1);
386
    IGNORE fputs ( ( func_output ? " ) ;\n\n" : " )\n\n" ), output ) ;
413
    IGNORE fputs((func_output ? " ) ;\n\n" : " )\n\n"), output);
387
    return ;
414
    return;
388
}
415
}
389
 
416
 
390
 
417
 
391
/*
418
/*
392
    TAG DECLARATION AUXILIARY PRINTING ROUTINE
419
    TAG DECLARATION AUXILIARY PRINTING ROUTINE
393
 
420
 
394
    Print the declaration of the tag p.
421
    Print the declaration of the tag p.
395
*/
422
*/
396
 
423
 
397
static void print_tagdec
424
static void
398
    PROTO_N ( ( p ) )
-
 
399
    PROTO_T ( construct *p )
425
print_tagdec(construct *p)
400
{
426
{
401
    tag_info *info = get_tag_info ( p ) ;
427
    tag_info *info = get_tag_info(p);
402
    if ( p->encoding == -1 || info->dec == null ) return ;
428
    if (p->encoding == -1 || info->dec == null) return;
403
    switch ( info->var ) {
429
    switch (info->var) {
404
	case 0 : print_name ( MAKE_ID_TAGDEC, p, 1 ) ; break ;
430
	case 0: print_name(MAKE_ID_TAGDEC, p, 1); break;
405
	case 1 : print_name ( MAKE_VAR_TAGDEC, p, 1 ) ; break ;
431
	case 1: print_name(MAKE_VAR_TAGDEC, p, 1); break;
406
	case 2 : print_name ( COMMON_TAGDEC, p, 1 ) ; break ;
432
	case 2: print_name(COMMON_TAGDEC, p, 1); break;
407
    }
433
    }
408
    if ( func_output ) IGNORE fputc ( ',', output ) ;
434
    if (func_output)IGNORE fputc(',', output);
409
    IGNORE fputc ( '\n', output ) ;
435
    IGNORE fputc('\n', output);
410
    IGNORE print_node ( info->dec, 1 ) ;
436
    IGNORE print_node(info->dec, 1);
411
    IGNORE fputs ( ( func_output ? " ) ;\n\n" : " )\n\n" ), output ) ;
437
    IGNORE fputs((func_output ? " ) ;\n\n" : " )\n\n"), output);
412
    return ;
438
    return;
413
}
439
}
414
 
440
 
415
 
441
 
416
/*
442
/*
417
    TAG DEFINITION AUXILIARY PRINTING ROUTINE
443
    TAG DEFINITION AUXILIARY PRINTING ROUTINE
418
 
444
 
419
    Print the definition of the tag p.
445
    Print the definition of the tag p.
420
*/
446
*/
421
 
447
 
422
static void print_tagdef
448
static void
423
    PROTO_N ( ( p ) )
-
 
424
    PROTO_T ( construct *p )
449
print_tagdef(construct *p)
425
{
450
{
426
    char *instr ;
451
    char *instr;
427
    tag_info *info = get_tag_info ( p ) ;
452
    tag_info *info = get_tag_info(p);
428
    node *d = info->def ;
453
    node *d = info->def;
429
    if ( p->encoding == -1 || d == null ) return ;
454
    if (p->encoding == -1 || d == null) return;
430
    switch ( info->var ) EXHAUSTIVE {
455
    switch (info->var)EXHAUSTIVE {
431
	case 0 : instr = MAKE_ID_TAGDEF ; break ;
456
	case 0: instr = MAKE_ID_TAGDEF; break;
432
	case 1 : instr = MAKE_VAR_TAGDEF ; break ;
457
	case 1: instr = MAKE_VAR_TAGDEF; break;
433
	case 2 : instr = COMMON_TAGDEF ; break ;
458
	case 2: instr = COMMON_TAGDEF; break;
434
    }
459
    }
435
    while ( d ) {
460
    while (d) {
436
	/* Can have multiple definitions */
461
	/* Can have multiple definitions */
437
	print_name ( instr, p, !show_tagdecs ) ;
462
	print_name(instr, p, !show_tagdecs);
438
	if ( func_output ) IGNORE fputc ( ',', output ) ;
463
	if (func_output)IGNORE fputc(',', output);
439
	IGNORE fputc ( '\n', output ) ;
464
	IGNORE fputc('\n', output);
440
	IGNORE print_node ( d->son, 1 ) ;
465
	IGNORE print_node(d->son, 1);
441
	IGNORE fputs ( ( func_output ? " ) ;\n\n" : " )\n\n" ), output ) ;
466
	IGNORE fputs((func_output ? " ) ;\n\n" : " )\n\n"), output);
442
	d = d->bro ;
467
	d = d->bro;
443
    }
468
    }
444
    return ;
469
    return;
445
}
470
}
446
 
471
 
447
 
472
 
448
/*
473
/*
449
    TOKEN DECLARATION AUXILIARY PRINTING ROUTINE
474
    TOKEN DECLARATION AUXILIARY PRINTING ROUTINE
450
 
475
 
451
    Print the declaration of the token p.
476
    Print the declaration of the token p.
452
*/
477
*/
453
 
478
 
454
static void print_tokdec
479
static void
455
    PROTO_N ( ( p ) )
-
 
456
    PROTO_T ( construct *p )
480
print_tokdec(construct *p)
457
{
481
{
458
    tok_info *info = get_tok_info ( p ) ;
482
    tok_info *info = get_tok_info(p);
459
    if ( p->encoding == -1 ) return ;
483
    if (p->encoding == -1) return;
460
    if ( !info->dec ) return ;
484
    if (!info->dec) return;
461
    print_name ( MAKE_TOKDEC, p, 1 ) ;
485
    print_name(MAKE_TOKDEC, p, 1);
462
    if ( func_output ) IGNORE fputc ( ',', output ) ;
486
    if (func_output)IGNORE fputc(',', output);
463
    IGNORE fputc ( '\n', output ) ;
487
    IGNORE fputc('\n', output);
464
    if ( info->sig ) {
488
    if (info->sig) {
465
	IGNORE print_node ( info->sig, 1 ) ;
489
	IGNORE print_node(info->sig, 1);
466
    } else {
490
    } else {
467
	print_spaces ( 1 ) ;
491
	print_spaces(1);
468
	IGNORE fputc ( '-', output ) ;
492
	IGNORE fputc('-', output);
469
    }
493
    }
470
    if ( func_output ) IGNORE fputc ( ',', output ) ;
494
    if (func_output)IGNORE fputc(',', output);
471
    IGNORE fputs ( "\n  ", output ) ;
495
    IGNORE fputs("\n  ", output);
472
    if ( info->args ) {
496
    if (info->args) {
473
	int n = 0 ;
497
	int n = 0;
474
	char *q = info->args ;
498
	char *q = info->args;
475
	IGNORE fputs ( "( ", output ) ;
499
	IGNORE fputs("( ", output);
476
	while ( *q ) {
500
	while (*q) {
477
	    sortname s ;
501
	    sortname s;
478
	    q = find_sortname ( q, &s ) ;
502
	    q = find_sortname(q, &s);
479
	    q++ ;
503
	    q++;
480
	    if ( n++ == 8 ) {
504
	    if (n++ == 8) {
481
		IGNORE fputs ( "\n  ", output ) ;
505
		IGNORE fputs("\n  ", output);
482
		n = 1 ;
506
		n = 1;
483
	    }
507
	    }
484
	    IGNORE fputs ( sort_name ( s ), output ) ;
508
	    IGNORE fputs(sort_name(s), output);
485
	    if ( func_output && *q ) IGNORE fputc ( ',', output ) ;
509
	    if (func_output && *q)IGNORE fputc(',', output);
486
	    IGNORE fputc ( ' ', output ) ;
510
	    IGNORE fputc(' ', output);
487
	}
511
	}
488
	IGNORE fputs ( ") ", output ) ;
512
	IGNORE fputs(") ", output);
489
	if ( func_output ) IGNORE fputs ( "-> ", output ) ;
513
	if (func_output)IGNORE fputs("-> ", output);
490
    }
514
    }
491
    IGNORE fputs ( sort_name ( info->res ), output ) ;
515
    IGNORE fputs(sort_name(info->res), output);
492
    IGNORE fputs ( ( func_output ? " ) ;\n\n" : " )\n\n" ), output ) ;
516
    IGNORE fputs((func_output ? " ) ;\n\n" : " )\n\n"), output);
493
    return ;
517
    return;
494
}
518
}
495
 
519
 
496
 
520
 
497
/*
521
/*
498
    TOKEN DEFINITION AUXILIARY PRINTING ROUTINE
522
    TOKEN DEFINITION AUXILIARY PRINTING ROUTINE
499
 
523
 
500
    Print the definition of the token p.
524
    Print the definition of the token p.
501
*/
525
*/
502
 
526
 
503
static void print_tokdef
527
static void
504
    PROTO_N ( ( p ) )
-
 
505
    PROTO_T ( construct *p )
528
print_tokdef(construct *p)
506
{
529
{
507
    tok_info *info = get_tok_info ( p ) ;
530
    tok_info *info = get_tok_info(p);
508
    if ( p->encoding == -1 ) return ;
531
    if (p->encoding == -1) return;
509
    if ( !info->dec ) return ;
532
    if (!info->dec) return;
510
    if ( info->def == null ) return ;
533
    if (info->def == null) return;
511
    print_name ( MAKE_TOKDEF, p, !show_tagdefs ) ;
534
    print_name(MAKE_TOKDEF, p, !show_tagdefs);
512
    if ( func_output ) IGNORE fputc ( ',', output ) ;
535
    if (func_output)IGNORE fputc(',', output);
513
    IGNORE fputc ( '\n', output ) ;
536
    IGNORE fputc('\n', output);
514
    if ( info->sig ) {
537
    if (info->sig) {
515
	IGNORE print_node ( info->sig, 1 ) ;
538
	IGNORE print_node(info->sig, 1);
516
    } else {
539
    } else {
517
	print_spaces ( 1 ) ;
540
	print_spaces(1);
518
	IGNORE fputc ( '-', output ) ;
541
	IGNORE fputc('-', output);
519
    }
542
    }
520
    if ( func_output ) IGNORE fputc ( ',', output ) ;
543
    if (func_output)IGNORE fputc(',', output);
521
    IGNORE fputs ( "\n  ", output ) ;
544
    IGNORE fputs("\n  ", output);
522
    if ( info->args ) {
545
    if (info->args) {
523
	int n = 0 ;
546
	int n = 0;
524
	construct **q = info->pars ;
547
	construct **q = info->pars;
525
	IGNORE fputs ( "( ", output ) ;
548
	IGNORE fputs("( ", output);
526
	while ( *q ) {
549
	while (*q) {
527
	    tok_info *qinfo = get_tok_info ( *q ) ;
550
	    tok_info *qinfo = get_tok_info(*q);
528
	    if ( n++ == 4 ) {
551
	    if (n++ == 4) {
529
		IGNORE fputs ( "\n    ", output ) ;
552
		IGNORE fputs("\n    ", output);
530
		n = 1 ;
553
		n = 1;
531
	    }
554
	    }
532
	    IGNORE fprintf ( output, "%s %s", sort_name ( qinfo->res ),
555
	    IGNORE fprintf(output, "%s %s", sort_name(qinfo->res),
533
			     ( *q )->name ) ;
556
			    (*q) ->name);
534
	    q++ ;
557
	    q++;
535
	    if ( func_output && *q ) IGNORE fputc ( ',', output ) ;
558
	    if (func_output && *q)IGNORE fputc(',', output);
536
	    IGNORE fputc ( ' ', output ) ;
559
	    IGNORE fputc(' ', output);
537
	}
560
	}
538
	IGNORE fputs ( ") ", output ) ;
561
	IGNORE fputs(") ", output);
539
	if ( func_output ) IGNORE fputs ( "-> ", output ) ;
562
	if (func_output)IGNORE fputs("-> ", output);
540
    }
563
    }
541
    IGNORE fputs ( sort_name ( info->res ), output ) ;
564
    IGNORE fputs(sort_name(info->res), output);
542
    if ( func_output ) IGNORE fputc ( ',', output ) ;
565
    if (func_output)IGNORE fputc(',', output);
543
    IGNORE fputc ( '\n', output ) ;
566
    IGNORE fputc('\n', output);
544
    IGNORE print_node ( info->def, 1 ) ;
567
    IGNORE print_node(info->def, 1);
545
    IGNORE fputs ( ( func_output ? " ) ;\n\n" : " )\n\n" ), output ) ;
568
    IGNORE fputs((func_output ? " ) ;\n\n" : " )\n\n"), output);
546
    return ;
569
    return;
547
}
570
}
548
 
571
 
549
 
572
 
550
/*
573
/*
551
    PRINT A HIGH-LEVEL SORT
574
    PRINT A HIGH-LEVEL SORT
552
 
575
 
553
    This routine prints the high level sort h.
576
    This routine prints the high level sort h.
554
*/
577
*/
555
 
578
 
556
static void print_high_sort
579
static void
557
    PROTO_N ( ( h ) )
-
 
558
    PROTO_T ( high_sort *h )
580
print_high_sort(high_sort *h)
559
{
581
{
560
    int i, n ;
582
    int i, n;
561
    if ( h->id == SORT_unknown ) return ;
583
    if (h->id == SORT_unknown) return;
562
    if ( func_output ) {
584
    if (func_output) {
563
	IGNORE fprintf ( output, "%s ( %s, ", MAKE_SORT, h->name ) ;
585
	IGNORE fprintf(output, "%s ( %s, ", MAKE_SORT, h->name);
564
    } else {
586
    } else {
565
	IGNORE fprintf ( output, "( %s %s ", MAKE_SORT, h->name ) ;
587
	IGNORE fprintf(output, "( %s %s ", MAKE_SORT, h->name);
566
    }
588
    }
567
    n = h->no_args ;
589
    n = h->no_args;
568
    if ( n ) {
590
    if (n) {
569
	int m = 0 ;
591
	int m = 0;
570
	IGNORE fputs ( "( ", output ) ;
592
	IGNORE fputs("( ", output);
571
	for ( i = 0 ; i < n ; i++ ) {
593
	for (i = 0; i < n; i++) {
572
	    if ( m++ == 8 ) {
594
	    if (m++ == 8) {
573
		IGNORE fputs ( "\n  ", output ) ;
595
		IGNORE fputs("\n  ", output);
574
		m = 1 ;
596
		m = 1;
575
	    }
597
	    }
576
	    IGNORE fputs ( sort_name ( h->args [i] ), output ) ;
598
	    IGNORE fputs(sort_name(h->args[i]), output);
577
	    if ( func_output && i < n - 1 ) IGNORE fputc ( ',', output ) ;
599
	    if (func_output && i < n - 1)IGNORE fputc(',', output);
578
	    IGNORE fputc ( ' ', output ) ;
600
	    IGNORE fputc(' ', output);
579
	}
601
	}
580
	IGNORE fputs ( ") ", output ) ;
602
	IGNORE fputs(") ", output);
581
	if ( func_output ) IGNORE fputs ( "-> ", output ) ;
603
	if (func_output)IGNORE fputs("-> ", output);
582
    }
604
    }
583
    IGNORE fputs ( sort_name ( h->res ), output ) ;
605
    IGNORE fputs(sort_name(h->res), output);
584
    IGNORE fputs ( ( func_output ? " ) ;\n\n" : " )\n\n" ), output ) ;
606
    IGNORE fputs((func_output ? " ) ;\n\n" : " )\n\n"), output);
585
    return ;
607
    return;
586
}
608
}
587
 
609
 
588
 
610
 
589
/*
611
/*
590
    MAIN PRINTING ROUTINE
612
    MAIN PRINTING ROUTINE
591
 
613
 
592
    This routine prints an entire capsule to the output file.
614
    This routine prints an entire capsule to the output file.
593
*/
615
*/
594
 
616
 
595
void print_capsule
617
void
596
    PROTO_Z ()
618
print_capsule(void)
597
{
619
{
598
    if ( high_sorts ) {
620
    if (high_sorts) {
599
	int i ;
621
	int i;
600
	IGNORE fputs ( "# HIGH-LEVEL SORTS\n\n", output ) ;
622
	IGNORE fputs("# HIGH-LEVEL SORTS\n\n", output);
601
	for ( i = 0 ; i < crt_high_sort ; i++ ) {
623
	for (i = 0; i < crt_high_sort; i++) {
602
	    print_high_sort ( high_sorts + i ) ;
624
	    print_high_sort(high_sorts + i);
603
	}
625
	}
604
	IGNORE fputc ( '\n', output ) ;
626
	IGNORE fputc('\n', output);
605
    }
627
    }
606
    if ( show_tokdecs ) {
628
    if (show_tokdecs) {
607
	IGNORE fputs ( "# TOKEN DECLARATIONS\n\n", output ) ;
629
	IGNORE fputs("# TOKEN DECLARATIONS\n\n", output);
608
	apply_to_all ( print_tokdec, SORT_token ) ;
630
	apply_to_all(print_tokdec, SORT_token);
609
	IGNORE fputc ( '\n', output ) ;
631
	IGNORE fputc('\n', output);
610
    }
632
    }
611
    if ( show_aldecs ) {
633
    if (show_aldecs) {
612
	IGNORE fputs ( "# ALIGNMENT TAG DECLARATIONS\n\n", output ) ;
634
	IGNORE fputs("# ALIGNMENT TAG DECLARATIONS\n\n", output);
613
	apply_to_all ( print_aldec, SORT_al_tag ) ;
635
	apply_to_all(print_aldec, SORT_al_tag);
614
	IGNORE fputc ( '\n', output ) ;
636
	IGNORE fputc('\n', output);
615
    }
637
    }
616
    if ( show_tagdecs ) {
638
    if (show_tagdecs) {
617
	IGNORE fputs ( "# TAG DECLARATIONS\n\n", output ) ;
639
	IGNORE fputs("# TAG DECLARATIONS\n\n", output);
618
	apply_to_all ( print_tagdec, SORT_tag ) ;
640
	apply_to_all(print_tagdec, SORT_tag);
619
	IGNORE fputc ( '\n', output ) ;
641
	IGNORE fputc('\n', output);
620
    }
642
    }
621
    if ( show_tokdefs ) {
643
    if (show_tokdefs) {
622
	IGNORE fputs ( "# TOKEN DEFINITIONS\n\n", output ) ;
644
	IGNORE fputs("# TOKEN DEFINITIONS\n\n", output);
623
	apply_to_all ( print_tokdef, SORT_token ) ;
645
	apply_to_all(print_tokdef, SORT_token);
624
	IGNORE fputc ( '\n', output ) ;
646
	IGNORE fputc('\n', output);
625
    }
647
    }
626
    if ( show_aldefs ) {
648
    if (show_aldefs) {
627
	IGNORE fputs ( "# ALIGNMENT TAG DEFINITIONS\n\n", output ) ;
649
	IGNORE fputs("# ALIGNMENT TAG DEFINITIONS\n\n", output);
628
	apply_to_all ( print_aldef, SORT_al_tag ) ;
650
	apply_to_all(print_aldef, SORT_al_tag);
629
	IGNORE fputc ( '\n', output ) ;
651
	IGNORE fputc('\n', output);
630
    }
652
    }
631
    if ( show_tagdefs ) {
653
    if (show_tagdefs) {
632
	IGNORE fputs ( "# TAG DEFINITIONS\n\n", output ) ;
654
	IGNORE fputs("# TAG DEFINITIONS\n\n", output);
633
	apply_to_all ( print_tagdef, SORT_tag ) ;
655
	apply_to_all(print_tagdef, SORT_tag);
634
	IGNORE fputc ( '\n', output ) ;
656
	IGNORE fputc('\n', output);
635
    }
657
    }
636
    return ;
658
    return;
637
}
659
}