Subversion Repositories tendra.SVN

Rev

Rev 2 | Go to most recent revision | Details | Compare with Previous | 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
@use all
32
@special external
33
@special sortname
34
@special token
35
@special tokdec
36
@special tokdef
37
@special tagdec
38
@special tagdef
39
@special al_tagdef
40
@special diag_tagdef
41
@special token_defn
42
@special exp case
43
@special exp labelled
44
@special exp make_proc
45
@special exp sequence
46
@special nat make_nat
47
@special signed_nat make_signed_nat
48
@special string make_string
49
@special version make_version
50
/* AUTOMATICALLY GENERATED BY %ZX VERSION %ZV FROM TDF %VA.%VB */
51
 
52
#include "config.h"
53
#include "types.h"
54
#include "basic.h"
55
#include "binding.h"
56
#include "file.h"
57
#include "sort.h"
58
#include "tdf.h"
59
#include "tree.h"
60
#include "unit.h"
61
#include "utility.h"
62
@loop sort
63
@if sort.basic
64
 
65
 
66
/* DECODE A %ST */
67
 
68
long de_%SN
69
    PROTO_Z ()
70
{
71
@if sort.extends
72
    long n = fetch_extn ( %SB%1u ) ;
73
@else
74
    long n = fetch ( %SB%0u ) ;
75
@endif
76
@if sort.special
77
    if ( n < %u || n > %SM ) {
78
	out ( "<error>" ) ;
79
	input_error ( "Illegal %ST value, %%ld", n ) ;
80
	n = -1 ;
81
    }
82
@else
83
    switch ( n ) {
84
@loop sort.cons
85
	case %CE : {
86
@if cons.simple
87
@if cons.params
88
	    format ( VERT_BRACKETS, "%CN", "%CX" ) ;
89
@else
90
	    out ( "%CN" ) ;
91
@endif
92
@else
93
@if cons.cond
94
	    format ( VERT_BRACKETS, "%CN", "%CX" ) ;
95
@else
96
@if cons.token
97
@if sort.name.foreign
98
	    sortname sn = find_sortname ( '%SX' ) ;
99
	    IGNORE de_token_aux ( sn, "%SN" ) ;
100
@else
101
	    IGNORE de_token_aux ( sort_%20SN, "%SN" ) ;
102
@endif
103
@else
104
@if cons.edge
105
	    long t = tdf_int () ;
106
@if sort.link
107
	    out_object ( t, ( object * ) null, var_%SN ) ;
108
@else
109
	    de_%CN ( t ) ;
110
@endif
111
@else
112
	    /* Decode string "%CX" */
113
	    de_%CN ( "%CN" ) ;
114
@endif
115
@endif
116
@endif
117
@endif
118
	    break ;
119
	}
120
@end
121
	default : {
122
	    out ( "<error>" ) ;
123
	    input_error ( "Illegal %ST value, %%ld", n ) ;
124
	    n = -1 ;
125
	    break ;
126
	}
127
    }
128
@endif
129
    return ( n ) ;
130
}
131
@endif
132
@end
133
 
134
 
135
/*
136
    SKIP TEXT ENCLOSED IN [...]
137
 
138
    On input, s, points to the character '['.  The routine returns a
139
    pointer to the character following the corresponding ']'.
140
*/
141
 
142
static char *skip_sub
143
    PROTO_N ( ( s ) )
144
    PROTO_T ( char *s )
145
{
146
    char c = *( s++ ) ;
147
    if ( c == '[' ) {
148
	int n = 0 ;
149
	while ( c = *( s++ ), c != 0 ) {
150
	    if ( c == '[' ) n++ ;
151
	    if ( c == ']' ) {
152
		if ( n == 0 ) return ( s ) ;
153
		n-- ;
154
	    }
155
	}
156
    }
157
    input_error ( "Illegal decoding string" ) ;
158
    return ( "" ) ;
159
}
160
 
161
 
162
/*
163
    DECODE A STRING OF DECODE CHARACTERS
164
 
165
    This routine takes a string of characters, reads it one character
166
    at a time, and, according to what it is, calls a particular TDF
167
    decoding routine (the character is vaguely mnemonic).  For example,
168
    decode ( "Sn*[x]" ) means, decode a SHAPE and a NAT, then read a
169
    TDF integer and decode that number of EXPs.
170
*/
171
 
172
void decode
173
    PROTO_N ( ( str ) )
174
    PROTO_T ( char *str )
175
{
176
    char c ;
177
    while ( c = *( str++ ), c != 0 ) {
178
	switch ( c ) {
179
	    case '[' :
180
	    case '{' :
181
	    case '}' :
182
	    case '&' : {
183
		/* Ignore these cases */
184
		break ;
185
	    }
186
	    case ']' : {
187
		/* Marks the end of a group */
188
		return ;
189
	    }
190
	    case 'i' : {
191
		/* Decode an integer */
192
		long n = tdf_int () ;
193
		out_int ( n ) ;
194
		break ;
195
	    }
196
	    case '$' : {
197
		/* Decode a string */
198
		de_tdfstring_format () ;
199
		break ;
200
	    }
201
	    case 'T' : {
202
		/* Decode a token */
203
		IGNORE de_token_aux ( sort_unknown, "token" ) ;
204
		break ;
205
	    }
206
	    case 'F' : {
207
		/* Decode an unknown foreign sort */
208
		input_error ( "Unknown foreign sort" ) ;
209
		break ;
210
	    }
211
	    case '*' : {
212
		/* The following text is repeated n times */
213
		long i, n ;
214
		check_list () ;
215
		n = tdf_int () ;
216
		if ( n == 0 ) {
217
		    out ( "empty" ) ;
218
		} else {
219
		    for ( i = 0 ; i < n ; i++ ) decode ( str + 1 ) ;
220
		}
221
		str = skip_sub ( str ) ;
222
		break ;
223
	    }
224
	    case '+' : {
225
		/* The following text is repeated n + 1 times */
226
		long i, n ;
227
		check_list () ;
228
		n = tdf_int () ;
229
		for ( i = 0 ; i <= n ; i++ ) decode ( str + 1 ) ;
230
		str = skip_sub ( str ) ;
231
		break ;
232
	    }
233
	    case '?' : {
234
		/* The following text is optional */
235
		if ( tdf_bool () ) {
236
		    decode ( str + 1 ) ;
237
		} else {
238
		    out ( "-" ) ;
239
		}
240
		str = skip_sub ( str ) ;
241
		break ;
242
	    }
243
	    case '@' : {
244
		/* The following text is a bitstream */
245
		long p = tdf_int () ;
246
		p += posn ( here ) ;
247
		decode ( str + 1 ) ;
248
		if ( p != posn ( here ) ) {
249
		    input_error ( "Bitstream length wrong" ) ;
250
		}
251
		str = skip_sub ( str ) ;
252
		break ;
253
	    }
254
	    case '|' : {
255
		/* Align input stream */
256
		byte_align () ;
257
		break ;
258
	    }
259
@loop sort
260
@if sort.basic
261
@if !sort.special
262
	    case '%SX' : IGNORE de_%SN () ; break ;
263
@endif
264
@endif
265
@end
266
	    default : {
267
		input_error ( "Illegal decode letter, %%c", c ) ;
268
		break ;
269
	    }
270
	}
271
    }
272
    return ;
273
}
274
 
275
 
276
/*
277
    FIND THE NAME AND DECODE LETTER ASSOCIATED WITH A SORT
278
 
279
    This routine returns a sortid structure corresponding to the sort
280
    number n.
281
*/
282
 
283
sortid find_sort
284
    PROTO_N ( ( n ) )
285
    PROTO_T ( sortname n )
286
{
287
    sortid s ;
288
    switch ( n ) {
289
@loop sort
290
@if sort.name.simple
291
@if !sort.special
292
	case sort_%20SN : {
293
	    s.name = "%ST" ;
294
	    s.decode = '%SX' ;
295
	    break ;
296
	}
297
@endif
298
@endif
299
@end
300
	case sort_token : {
301
	    s.name = "TOKEN" ;
302
	    s.decode = 'T' ;
303
	    break ;
304
	}
305
	case sort_foreign : {
306
	    s.name = "FOREIGN" ;
307
	    s.decode = 'F' ;
308
	    break ;
309
	}
310
	default: {
311
	    int m = n - extra_sorts ;
312
	    if ( m >= 0 && m < no_foreign_sorts ) {
313
		s.name = foreign_sorts [m].name ;
314
		s.decode = foreign_sorts [m].decode ;
315
	    } else {
316
		input_error ( "Illegal sort value, %%d", n ) ;
317
		s.name = "<error in SORT>" ;
318
		s.decode = 'F' ;
319
	    }
320
	    break ;
321
	}
322
    }
323
    s.res = n ;
324
    s.args = null ;
325
    return ( s ) ;
326
}
327
 
328
 
329
/*
330
 
331
    CONVERT A DECODE LETTER TO A SORT VALUE
332
 
333
    This routine given a decode letter c returns the corresponding sort
334
    number.
335
*/
336
 
337
sortname find_sortname
338
    PROTO_N ( ( c ) )
339
    PROTO_T ( int c )
340
{
341
    long i ;
342
    switch ( c ) {
343
@loop sort
344
@if sort.name.simple
345
@if !sort.special
346
	case '%SX' : return ( sort_%20SN ) ;
347
@endif
348
@endif
349
@end
350
	case 'T' : return ( sort_token ) ;
351
	case 'F' : return ( sort_foreign ) ;
352
    }
353
    for ( i = 0 ; i < no_foreign_sorts ; i++ ) {
354
	if ( c == foreign_sorts [i].decode ) {
355
	    return ( ( sortname ) ( extra_sorts + i ) ) ;
356
	}
357
    }
358
    return ( sort_unknown ) ;
359
}
360
 
361
 
362
/*
363
    INITIALISE FOREIGN SORT NAMES
364
 
365
    This routine initialises the array of foreign sort names.
366
*/
367
 
368
void init_foreign_sorts
369
    PROTO_Z ()
370
{
371
@loop sort
372
@if sort.name.foreign
373
    add_foreign_sort ( "%ST", "%SCN", '%SX' ) ;
374
@endif
375
@end
376
    return ;
377
}
378
 
379
 
380
/*
381
    LINKAGE VARIABLE NUMBERS
382
 
383
    Usually "tag" and "token" etc. appear in the var_types array.  These
384
    variables indicate where (negative values mean not at all).
385
*/
386
%1u
387
@loop sort
388
@if sort.link
389
long var_%SN = -%u ;
390
@endif
391
@end
392
 
393
 
394
/*
395
    FIND A LINKAGE VARIABLE CODE
396
 
397
    This routine sets the nth element of the var_types array to the
398
    linkage variable indicated by the variable name s.
399
*/
400
 
401
char find_variable
402
    PROTO_N ( ( s, n ) )
403
    PROTO_T ( string s X long n )
404
{
405
@loop sort
406
@if sort.link
407
    if ( streq ( s, "%SL" ) ) {
408
	var_%SN = n ;
409
	return ( '%SX' ) ;
410
    }
411
@endif
412
@end
413
    return ( 'F' ) ;
414
}
415
 
416
 
417
/*
418
    FIND A EQUATION DECODING FUNCTION
419
 
420
    This routine returns the unit decoding function used to deal with
421
    units with equation name s.  It also assigns a unit description to
422
    pt and a usage flag to po.
423
*/
424
 
425
equation_func find_equation
426
    PROTO_N ( ( s, pt, po ) )
427
    PROTO_T ( string s X string *pt X int *po )
428
{
429
@loop sort
430
@if sort.unit
431
    if ( streq ( s, "%SU" ) ) {
432
	*pt = MSG_%SN ;
433
	*po = OPT_%SN ;
434
	return ( de_%SN ) ;
435
    }
436
@endif
437
@end
438
    if ( streq ( s, "tld" ) ) {
439
	*pt = MSG_tld_unit ;
440
	*po = OPT_tld_unit ;
441
	return ( de_tld_unit ) ;
442
    }
443
    if ( streq ( s, "tld2" ) ) {
444
	*pt = MSG_tld2_unit ;
445
	*po = OPT_tld2_unit ;
446
	return ( de_tld2_unit ) ;
447
    }
448
    return ( NULL ) ;
449
}