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 55... Line 85...
55
#include "tdf.h"
85
#include "tdf.h"
56
#include "utility.h"
86
#include "utility.h"
57
 
87
 
58
 
88
 
59
/* INITIALISE CONSTRUCTS */
89
/* INITIALISE CONSTRUCTS */
60
 
90
 
-
 
91
void
61
void init_constructs
92
init_constructs(void)
62
    PROTO_Z ()
-
 
63
{
93
{
64
    sortname s ;
94
    sortname s;
65
@loop sort
95
@loop sort
66
@if sort.basic
96
@if sort.basic
67
@if !sort.special
97
@if !sort.special
68
 
98
 
69
    s = SORT_%SN ;
99
    s = SORT_%SN;
70
@if sort.eq.sortname
100
@if sort.eq.sortname
71
    new_sort ( s, %3SM ) ;
101
    new_sort(s, %3SM);
72
@else
102
@else
73
    sort_letters [s] = '%SX' ;
103
    sort_letters[s] = '%SX';
74
    sort_encoding [s] = %SB ;
104
    sort_encoding[s] = %SB;
75
    sort_extension [s] = %SE ;
105
    sort_extension[s] = %SE;
76
    sort_decode [s] = de_%SN ;
106
    sort_decode[s] = de_%SN;
77
    sort_read [s] = read_%SN ;
107
    sort_read[s] = read_%SN;
78
    new_sort ( s, %1SM ) ;
108
    new_sort(s, %1SM);
79
@endif
109
@endif
80
@loop sort.cons
110
@loop sort.cons
81
@if cons.params
111
@if cons.params
82
@if cons.token
112
@if cons.token
83
    new_cons ( "%CN", s, %CE, "!" ) ;
113
    new_cons("%CN", s, %CE, "!");
84
    sort_tokens [s] = %CE ;
114
    sort_tokens[s] = %CE;
85
@else
115
@else
86
@if cons.eq.identify
116
@if cons.eq.identify
87
    new_cons ( "%CN", s, %CE, "?[u]t^x{x}" ) ;
117
    new_cons("%CN", s, %CE, "?[u]t^x{x}");
88
@else
118
@else
89
    new_cons ( "%CN", s, %CE, "%CX" ) ;
119
    new_cons("%CN", s, %CE, "%CX");
90
@if cons.cond
120
@if cons.cond
91
    sort_conds [s] = %CE ;
121
    sort_conds[s] = %CE;
92
@endif
122
@endif
93
@endif
123
@endif
94
@endif
124
@endif
95
@else
125
@else
96
@if cons.eq.alignment_sort
126
@if cons.eq.alignment_sort
97
    new_cons ( "alignment", s, %CE, ( char * ) null ) ;
127
    new_cons("alignment", s, %CE,(char *)null);
98
@else
128
@else
99
    new_cons ( "%CN", s, %CE, ( char * ) null ) ;
129
    new_cons("%CN", s, %CE,(char *)null);
100
@endif
130
@endif
101
@endif
131
@endif
102
@end
132
@end
103
@if sort.eq.sortname
133
@if sort.eq.sortname
104
    new_cons ( "callees", s, %1SM, ( char * ) null ) ;
134
    new_cons("callees", s, %1SM,(char *)null);
105
    new_cons ( "error_code", s, %2SM, ( char * ) null ) ;
135
    new_cons("error_code", s, %2SM,(char *)null);
106
@endif
136
@endif
107
@endif
137
@endif
108
@endif
138
@endif
109
@end
139
@end
110
    return ;
140
    return;
111
}
141
}
112
@special sortname
142
@special sortname
113
 
143
 
114
 
144
 
115
/* FIND A SORT NAME */
145
/* FIND A SORT NAME */
116
 
146
 
117
sortname find_sort
147
sortname
118
    PROTO_N ( ( c ) )
-
 
119
    PROTO_T ( char c )
148
find_sort(char c)
120
{
149
{
121
    sortname s ;
150
    sortname s;
122
    switch ( c ) {
151
    switch (c) {
123
@loop sort
152
@loop sort
124
@if sort.basic
153
@if sort.basic
125
@if !sort.special
154
@if !sort.special
126
	case '%SX' : s = SORT_%SN ; break ;
155
	case '%SX': s = SORT_%SN; break;
127
@endif
156
@endif
128
@endif
157
@endif
129
@end
158
@end
130
	default : {
159
	default : {
131
	    input_error ( "Illegal decode letter, %%c", c ) ;
160
	    input_error("Illegal decode letter, %%c", c);
132
	    s = SORT_unknown ;
161
	    s = SORT_unknown;
133
	    break ;
162
	    break;
134
	}
163
	}
135
    }
164
    }
136
    return ( s ) ;
165
    return(s);
137
}
166
}
138
@loop sort
167
@loop sort
139
@if sort.basic
168
@if sort.basic
140
 
169
 
141
 
170
 
142
/* DECODE A %ST */
171
/* DECODE A %ST */
143
 
172
 
144
@if sort.special
173
@if sort.special
-
 
174
long
145
long de_%SN_bits
175
de_%SN_bits(void)
146
@else
176
@else
147
node *de_%SN
177
node *
-
 
178
de_%SN(void)
148
@endif
179
@endif
149
    PROTO_Z ()
-
 
150
{
180
{
151
@if sort.extends
181
@if sort.extends
152
    long n = fetch_extn ( %SB%1u ) ;
182
    long n = fetch_extn(%SB%1u);
153
@else
183
@else
154
    long n = fetch ( %SB%0u ) ;
184
    long n = fetch(%SB%0u);
155
@endif
185
@endif
156
@if sort.special
186
@if sort.special
157
    if ( n < %u || n > %SM ) {
187
    if (n < %u || n > %SM) {
158
	input_error ( "Illegal %SN value, %%ld", n ) ;
188
	input_error("Illegal %SN value, %%ld", n);
159
    }
189
    }
160
    return ( n ) ;
190
    return(n);
161
@else
191
@else
162
    char *args ;
192
    char *args;
163
    node *p = new_node () ;
193
    node *p = new_node();
164
    construct *cons = cons_no ( SORT_%SN, n ) ;
194
    construct *cons = cons_no(SORT_%SN, n);
165
    p->cons = cons ;
195
    p->cons = cons;
166
    if ( n < %u || n > %SM || cons->name == null ) {
196
    if (n < %u || n > %SM || cons->name == null) {
167
	input_error ( "Illegal %SN value, %%ld", n ) ;
197
	input_error("Illegal %SN value, %%ld", n);
168
    }
198
    }
169
@if sort.eq.callees
199
@if sort.eq.callees
170
    args = get_char_info ( cons ) ;
200
    args = get_char_info(cons);
-
 
201
    if (args) {
171
    if ( args ) p->son = de_node ( args ) ;
202
	p->son = de_node(args);
-
 
203
    }
172
@else
204
@else
173
@if sort.eq.error_code
205
@if sort.eq.error_code
174
    args = get_char_info ( cons ) ;
206
    args = get_char_info(cons);
-
 
207
    if (args) {
175
    if ( args ) p->son = de_node ( args ) ;
208
	p->son = de_node(args);
-
 
209
    }
176
@else
210
@else
177
    switch ( n ) {
211
    switch (n) {
178
@loop sort.cons
212
@loop sort.cons
179
@if cons.token
213
@if cons.token
180
	case %CE : {
214
	case %CE: {
181
	    IGNORE de_token ( p, SORT_%SN ) ;
215
	    IGNORE de_token(p, SORT_%SN);
182
	    break ;
216
	    break;
183
	}
217
	}
184
@else
218
@else
185
@if cons.cond
219
@if cons.cond
186
	case %CE : {
220
	case %CE: {
187
	    args = get_char_info ( cons ) ;
221
	    args = get_char_info(cons);
188
	    p->son = de_node ( args ) ;
222
	    p->son = de_node(args);
189
	    if ( do_check ) {
223
	    if (do_check) {
190
		checking = "%CN" ;
224
		checking = "%CN";
191
		IGNORE check1 ( ENC_integer, p->son ) ;
225
		IGNORE check1(ENC_integer, p->son);
192
	    }
226
	    }
193
	    break ;
227
	    break;
194
	}
228
	}
195
@else
229
@else
196
@if cons.edge
230
@if cons.edge
197
	case %CE : {
231
	case %CE: {
198
@if sort.link
232
@if sort.link
199
	    p->son = de_var_sort ( %SN_var ) ;
233
	    p->son = de_var_sort(%SN_var);
200
@else
234
@else
201
	    long m = tdf_int () ;
235
	    long m = tdf_int();
202
	    p->son = new_node () ;
236
	    p->son = new_node();
203
	    p->son->cons = find_%SN ( m ) ;
237
	    p->son->cons = find_%SN(m);
204
@endif
238
@endif
205
	    break ;
239
	    break;
206
	}
240
	}
207
@endif
241
@endif
208
@endif
242
@endif
209
@endif
243
@endif
210
@end
244
@end
211
	default : {
245
	default : {
212
	    args = get_char_info ( cons ) ;
246
	    args = get_char_info(cons);
-
 
247
	    if (args) {
213
	    if ( args ) p->son = de_node ( args ) ;
248
		p->son = de_node(args);
-
 
249
	    }
214
	    break ;
250
	    break;
215
	}
251
	}
216
    }
252
    }
217
@endif
253
@endif
218
@endif
254
@endif
219
#ifdef check_%SN
255
#ifdef check_%SN
220
    check_%SN ( p ) ;
256
    check_%SN(p);
221
#endif
257
#endif
222
    return ( p ) ;
258
    return(p);
223
@endif
259
@endif
224
}
260
}
225
@endif
261
@endif
226
@end
262
@end
227
@loop sort
263
@loop sort
228
@if sort.basic
264
@if sort.basic
229
@if sort.special
265
@if sort.special
230
 
266
 
231
 
267
 
232
/* ENCODE A %ST */
268
/* ENCODE A %ST */
233
 
269
 
-
 
270
void
-
 
271
enc_%SN_bits(bitstream *p, int n)
-
 
272
{
234
void enc_%SN_bits
273
@if sort.extends
-
 
274
    enc_bits_extn(p, %SB,(long)n);
-
 
275
@else
235
    PROTO_N ( ( p, n ) )
276
    enc_bits(p, %SB,(long)n);
-
 
277
@endif
-
 
278
    return;
-
 
279
}
-
 
280
@else
-
 
281
@if sort.edge
-
 
282
 
-
 
283
 
-
 
284
/* ENCODE A %ST */
-
 
285
 
-
 
286
void
236
    PROTO_T ( bitstream *p X int n )
287
enc_%SN_bits(bitstream *p, int n)
237
{
288
{
238
@if sort.extends
289
@if sort.extends
239
    enc_bits_extn ( p, %SB, ( long ) n ) ;
290
    enc_bits_extn(p, %SB,(long)n);
240
@else
291
@else
241
    enc_bits ( p, %SB, ( long ) n ) ;
292
    enc_bits(p, %SB,(long)n);
242
@endif
293
@endif
243
    return ;
294
    return;
244
}
-
 
245
@else
-
 
246
@if sort.edge
-
 
247
 
-
 
248
 
-
 
249
/* ENCODE A %ST */
-
 
250
 
-
 
251
void enc_%SN_bits
-
 
252
    PROTO_N ( ( p, n ) )
-
 
253
    PROTO_T ( bitstream *p X int n )
-
 
254
{
-
 
255
@if sort.extends
-
 
256
    enc_bits_extn ( p, %SB, ( long ) n ) ;
-
 
257
@else
-
 
258
    enc_bits ( p, %SB, ( long ) n ) ;
-
 
259
@endif
-
 
260
    return ;
-
 
261
}
295
}
262
@endif
296
@endif
263
@endif
297
@endif
264
@endif
298
@endif
265
@end
299
@end
Line 270... Line 304...
270
@if !sort.special
304
@if !sort.special
271
 
305
 
272
 
306
 
273
/* READ A %ST */
307
/* READ A %ST */
274
 
308
 
275
node *read_%SN
309
node *
276
    PROTO_N ( ( n ) )
-
 
277
    PROTO_T ( long n )
310
read_%SN(long n)
278
{
311
{
279
    char *args ;
312
    char *args;
280
    node *p = new_node () ;
313
    node *p = new_node();
281
    construct *cons = cons_no ( SORT_%SN, n ) ;
314
    construct *cons = cons_no(SORT_%SN, n);
282
    p->cons = cons ;
315
    p->cons = cons;
283
    if ( n < 0 || n > %SM || cons->name == null ) {
316
    if (n < 0 || n > %SM || cons->name == null) {
284
	input_error ( "Illegal %SN value, %%ld", n ) ;
317
	input_error("Illegal %SN value, %%ld", n);
285
    }
318
    }
286
@if sort.eq.callees
319
@if sort.eq.callees
287
    args = get_char_info ( cons ) ;
320
    args = get_char_info(cons);
-
 
321
    if (args) {
288
    if ( args ) p->son = read_node ( args ) ;
322
	p->son = read_node(args);
-
 
323
    }
289
@else
324
@else
290
@if sort.eq.error_code
325
@if sort.eq.error_code
291
    args = get_char_info ( cons ) ;
326
    args = get_char_info(cons);
-
 
327
    if (args) {
292
    if ( args ) p->son = read_node ( args ) ;
328
	p->son = read_node(args);
-
 
329
    }
293
@else
330
@else
294
    switch ( n ) {
331
    switch (n) {
295
@loop sort.cons
332
@loop sort.cons
296
@if cons.token
333
@if cons.token
297
	case %CE : {
334
	case %CE: {
298
	    read_token ( p, SORT_%SN ) ;
335
	    read_token(p, SORT_%SN);
299
	    break ;
336
	    break;
300
	}
337
	}
301
@else
338
@else
302
@if cons.cond
339
@if cons.cond
303
	case %CE : {
340
	case %CE: {
304
	    args = get_char_info ( cons ) ;
341
	    args = get_char_info(cons);
305
	    p->son = read_node ( args ) ;
342
	    p->son = read_node(args);
306
	    if ( do_check ) {
343
	    if (do_check) {
307
		checking = "%CN" ;
344
		checking = "%CN";
308
		IGNORE check1 ( ENC_integer, p->son ) ;
345
		IGNORE check1(ENC_integer, p->son);
309
	    }
346
	    }
310
	    break ;
347
	    break;
311
	}
348
	}
312
@else
349
@else
313
@if cons.edge
350
@if cons.edge
314
	case %CE : {
351
	case %CE: {
315
	    p->son = read_var_sort ( SORT_%SN ) ;
352
	    p->son = read_var_sort(SORT_%SN);
316
	    break ;
353
	    break;
317
	}
354
	}
318
@else
355
@else
319
@if cons.special
356
@if cons.special
320
	case %CE : {
357
	case %CE: {
321
	    read_%CN ( p, get_char_info ( cons ) ) ;
358
	    read_%CN(p, get_char_info(cons));
322
	    break ;
359
	    break;
323
	}
360
	}
324
@endif
361
@endif
325
@endif
362
@endif
326
@endif
363
@endif
327
@endif
364
@endif
328
@end
365
@end
329
	default : {
366
	default : {
330
	    args = get_char_info ( cons ) ;
367
	    args = get_char_info(cons);
-
 
368
	    if (args) {
331
	    if ( args ) p->son = read_node ( args ) ;
369
		p->son = read_node(args);
-
 
370
	    }
332
	    break ;
371
	    break;
333
	}
372
	}
334
    }
373
    }
335
@endif
374
@endif
336
@endif
375
@endif
337
#ifdef check_%SN
376
#ifdef check_%SN
338
    check_%SN ( p ) ;
377
    check_%SN(p);
339
#endif
378
#endif
340
    return ( p ) ;
379
    return(p);
341
}
380
}
342
@endif
381
@endif
343
@endif
382
@endif
344
@end
383
@end