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 42... Line 72...
42
 
72
 
43
    This routine is used to construct the hash tables.  It takes a
73
    This routine is used to construct the hash tables.  It takes a
44
    string s and returns a value in the range 0 <= n < hash_size.
74
    string s and returns a value in the range 0 <= n < hash_size.
45
*/
75
*/
46
 
76
 
47
static int hash
77
static int
48
    PROTO_N ( ( s ) )
-
 
49
    PROTO_T ( char *s )
78
hash(char *s)
50
{
79
{
51
    int n = 0 ;
80
    int n = 0;
52
    for ( ; *s ; s++ ) n += *s ;
81
    for (; *s; s++)n += *s;
53
    return ( n % hash_size ) ;
82
    return(n % hash_size);
54
}
83
}
55
 
84
 
56
 
85
 
57
/*
86
/*
58
    CONSTRUCT TABLES
87
    CONSTRUCT TABLES
Line 63... Line 92...
63
    cons_hash_tables and var_hash_tables give the corresponding
92
    cons_hash_tables and var_hash_tables give the corresponding
64
    hash tables (arranged by sort).  The table cons_sizes gives
93
    hash tables (arranged by sort).  The table cons_sizes gives
65
    the number of built-in constructs of each sort.
94
    the number of built-in constructs of each sort.
66
*/
95
*/
67
 
96
 
68
construct **var_table ;
97
construct **var_table;
69
construct **cons_table ;
98
construct **cons_table;
70
static int *cons_sizes ;
99
static int *cons_sizes;
71
construct **cons_hash_tables ;
100
construct **cons_hash_tables;
72
static construct **var_hash_tables ;
101
static construct **var_hash_tables;
73
 
102
 
74
 
103
 
75
/*
104
/*
76
    SORT INFORMATION TABLES
105
    SORT INFORMATION TABLES
77
 
106
 
Line 79... Line 108...
79
    number of them created, their decode letters, the number of bits
108
    number of them created, their decode letters, the number of bits
80
    in their encoding, the encoding of their "apply_token" construct,
109
    in their encoding, the encoding of their "apply_token" construct,
81
    and the number of them removed from the hash tables.
110
    and the number of them removed from the hash tables.
82
*/
111
*/
83
 
112
 
84
long *sort_count ;
113
long *sort_count;
85
char *sort_letters ;
114
char *sort_letters;
86
int *sort_encoding ;
115
int *sort_encoding;
87
int *sort_extension ;
116
int *sort_extension;
88
long *sort_tokens ;
117
long *sort_tokens;
89
long *sort_conds ;
118
long *sort_conds;
90
long *sort_removed ;
119
long *sort_removed;
91
decode_func *sort_decode ;
120
decode_func *sort_decode;
92
read_func *sort_read ;
121
read_func *sort_read;
93
 
122
 
94
 
123
 
95
/*
124
/*
96
    CREATE A TABLE FOR A NEW SORT
125
    CREATE A TABLE FOR A NEW SORT
97
 
126
 
98
    A table of sz constructs of sort s is created and cleared.
127
    A table of sz constructs of sort s is created and cleared.
99
*/
128
*/
100
 
129
 
101
void new_sort
130
void
102
    PROTO_N ( ( s, sz ) ) 
-
 
103
    PROTO_T ( sortname s X int sz )
131
new_sort(sortname s, int sz)
104
{
132
{
105
    int i ;
133
    int i;
106
    construct *p = alloc_nof ( construct, sz ) ;
134
    construct *p = alloc_nof(construct, sz);
107
    for ( i = 0 ; i < sz ; i++ ) {
135
    for (i = 0; i < sz; i++) {
108
	( p + i )->sortnum = s ;
136
	(p + i) ->sortnum = s;
109
	( p + i )->encoding = i ;
137
	(p + i) ->encoding = i;
-
 
138
	(p + i)->alias = null;
-
 
139
	(p + i)->ename = null;
110
	( p + i )->name = null ;
140
	(p + i) ->name = null;
111
	( p + i )->next = null ;
141
	(p + i) ->next = null;
112
	get_char_info ( p + i ) = null ;
142
	get_char_info(p + i) = null;
113
    }
143
    }
114
    cons_table [s] = p ;
144
    cons_table[s] = p;
115
    cons_sizes [s] = ( int ) sz ;
145
    cons_sizes[s] = (int)sz;
116
    return ;
146
    return;
117
}
147
}
118
 
148
 
119
 
149
 
120
/*
150
/*
121
    PUT A NAME INTO A CONSTRUCT
151
    PUT A NAME INTO A CONSTRUCT
122
 
152
 
123
    The nth construct of sort s is set to have name nm and argument
153
    The nth construct of sort s is set to have name nm and argument
124
    string args.
154
    string args.
125
*/
155
*/
126
 
156
 
127
void new_cons
157
void
128
    PROTO_N ( ( nm, s, n, args ) )
-
 
129
    PROTO_T ( char *nm X sortname s X int n X char *args )
158
new_cons(char *nm, sortname s, int n, char *args)
130
{
159
{
131
    construct *p = cons_no ( s, n ) ;
160
    construct *p = cons_no(s, n);
132
    p->name = nm ;
161
    p->name = nm;
133
    if ( add_to_cons_hash ( p, s ) ) {
162
    if (add_to_cons_hash(p, s)) {
134
	fatal_error ( "Construct %s already defined", nm ) ;
163
	fatal_error("Construct %s already defined", nm);
135
    }
164
    }
136
    get_char_info ( p ) = args ;
165
    get_char_info(p) = args;
137
    return ;
166
    return;
138
}
167
}
139
 
168
 
140
 
169
 
141
/*
170
/*
142
    DUMMY DECODING FUNCTION
171
    DUMMY DECODING FUNCTION
143
 
172
 
144
    This routine is a dummy which is used for uninitialised decode functions.
173
    This routine is a dummy which is used for uninitialised decode functions.
145
*/
174
*/
146
 
175
 
147
static node *de_dummy
176
static node *
148
    PROTO_Z ()
177
de_dummy(void)
149
{
178
{
150
    fatal_error ( "Invalid decode function" ) ;
179
    fatal_error("Invalid decode function");
151
    return ( null ) ;
180
    return(null);
152
}
181
}
153
 
182
 
154
 
183
 
155
/*
184
/*
156
    DUMMY READING FUNCTION
185
    DUMMY READING FUNCTION
157
 
186
 
158
    This routine is a dummy which is used for uninitialised read functions.
187
    This routine is a dummy which is used for uninitialised read functions.
159
*/
188
*/
160
 
189
 
161
static node *read_dummy
190
static node *
162
    PROTO_N ( ( n ) )
-
 
163
    PROTO_T ( long n )
191
read_dummy(long n)
164
{
192
{
165
    fatal_error ( "Invalid read function" ) ;
193
    fatal_error("Invalid read function");
166
    UNUSED ( n ) ;
194
    UNUSED(n);
167
    return ( null ) ;
195
    return(null);
168
}
196
}
169
 
197
 
170
 
198
 
171
/*
199
/*
172
    INITIALIZE CONSTRUCT TABLES
200
    INITIALIZE CONSTRUCT TABLES
173
 
201
 
174
    The various construct and sort tables are initialized.
202
    The various construct and sort tables are initialized.
175
*/
203
*/
176
 
204
 
177
void init_tables
205
void
178
    PROTO_Z ()
206
init_tables(void)
179
{
207
{
180
    int i ;
208
    int i;
181
 
209
 
182
    /* Allocate tables */
210
    /* Allocate tables */
183
    cons_table = alloc_nof ( construct *, SORT_no ) ;
211
    cons_table = alloc_nof(construct *, SORT_no);
184
    cons_sizes = alloc_nof ( int, SORT_no ) ;
212
    cons_sizes = alloc_nof(int, SORT_no);
185
    cons_hash_tables = alloc_nof ( construct *, SORT_no * hash_size ) ;
213
    cons_hash_tables = alloc_nof(construct *, SORT_no * hash_size);
186
    var_table = alloc_nof ( construct *, SORT_no ) ;
214
    var_table = alloc_nof(construct *, SORT_no);
187
    var_hash_tables = alloc_nof ( construct *, SORT_no * hash_size ) ;
215
    var_hash_tables = alloc_nof(construct *, SORT_no * hash_size);
188
    sort_count = alloc_nof ( long, SORT_no ) ;
216
    sort_count = alloc_nof(long, SORT_no);
189
    sort_letters = alloc_nof ( char, SORT_no + 1 ) ;
217
    sort_letters = alloc_nof(char, SORT_no + 1);
190
    sort_encoding = alloc_nof ( int, SORT_no ) ;
218
    sort_encoding = alloc_nof(int, SORT_no);
191
    sort_extension = alloc_nof ( int, SORT_no ) ;
219
    sort_extension = alloc_nof(int, SORT_no);
192
    sort_tokens = alloc_nof ( long, SORT_no ) ;
220
    sort_tokens = alloc_nof(long, SORT_no);
193
    sort_conds = alloc_nof ( long, SORT_no ) ;
221
    sort_conds = alloc_nof(long, SORT_no);
194
    sort_removed = alloc_nof ( long, SORT_no ) ;
222
    sort_removed = alloc_nof(long, SORT_no);
195
    sort_decode = alloc_nof ( decode_func, SORT_no ) ;
223
    sort_decode = alloc_nof(decode_func, SORT_no);
196
    sort_read = alloc_nof ( read_func, SORT_no ) ;
224
    sort_read = alloc_nof(read_func, SORT_no);
197
 
225
 
198
    /* Clear out tables */
226
    /* Clear out tables */
199
    for ( i = 0 ; i < SORT_no ; i++ ) {
227
    for (i = 0; i < SORT_no; i++) {
200
	cons_table [i] = null ;
228
	cons_table[i] = null;
201
	cons_sizes [i] = 0 ;
229
	cons_sizes[i] = 0;
202
	var_table [i] = null ;
230
	var_table[i] = null;
203
	sort_count [i] = 0 ;
231
	sort_count[i] = 0;
204
	sort_letters [i] = 'F' ;
232
	sort_letters[i] = 'F';
205
	sort_encoding [i] = 0 ;
233
	sort_encoding[i] = 0;
206
	sort_extension [i] = 0 ;
234
	sort_extension[i] = 0;
207
	sort_tokens [i] = -2 ;
235
	sort_tokens[i] = -2;
208
	sort_conds [i] = -2 ;
236
	sort_conds[i] = -2;
209
	sort_removed [i] = 0 ;
237
	sort_removed[i] = 0;
210
	sort_decode [i] = de_dummy ;
238
	sort_decode[i] = de_dummy;
211
	sort_read [i] = read_dummy ;
239
	sort_read[i] = read_dummy;
212
    }
240
    }
213
    sort_letters [ SORT_no ] = 0 ;
241
    sort_letters[SORT_no] = 0;
214
 
242
 
215
    /* Initialize construct hash tables */
243
    /* Initialize construct hash tables */
216
    for ( i = 0 ; i < SORT_no * hash_size ; i++ ) {
244
    for (i = 0; i < SORT_no * hash_size; i++) {
217
	cons_hash_tables [i] = null ;
245
	cons_hash_tables[i] = null;
218
	var_hash_tables [i] = null ;
246
	var_hash_tables[i] = null;
219
    }
247
    }
220
    return ;
248
    return;
221
}
249
}
222
 
250
 
223
 
251
 
224
/*
252
/*
225
    SPECIAL CONSTRUCTS
253
    SPECIAL CONSTRUCTS
226
 
254
 
227
    These constructs are predefined.
255
    These constructs are predefined.
228
*/
256
*/
229
 
257
 
230
construct bytestream_cons = { SORT_bytestream, 0, null, null, null } ;
258
construct bytestream_cons = { SORT_bytestream, 0, null, null, null, null };
231
construct false_cons = { SORT_tdfbool, 0, null, null, null } ;
259
construct false_cons = { SORT_tdfbool, 0, null, null, null, null };
232
construct optional_cons = { SORT_option, 0, null, null, null } ;
260
construct optional_cons = { SORT_option, 0, null, null, null, null };
233
construct string_cons = { SORT_tdfstring, -1, null, null, null } ;
261
construct string_cons = { SORT_tdfstring, -1, null, null, null, null };
234
construct token_cons = { SORT_token, 0, null, null, null } ;
262
construct token_cons = { SORT_token, 0, null, null, null, null };
235
construct true_cons = { SORT_tdfbool, 1, null, null, null } ;
263
construct true_cons = { SORT_tdfbool, 1, null, null, null, null };
236
construct unknown_cons = { SORT_unknown, 0, "....", null, null } ;
264
construct unknown_cons = { SORT_unknown, 0, "....", null, null, null };
237
construct exp_shape = { SORT_exp, 0, "~exp_with_shape", null, null } ;
265
construct exp_shape = { SORT_exp, 0, "~exp_with_shape", null, null, null };
238
construct shape_of = { SORT_shape, -1, "~shape_of", null, null } ;
266
construct shape_of = { SORT_shape, -1, "~shape_of", null, null, null };
239
 
267
 
240
 
268
 
241
/*
269
/*
242
    OUTPUT OPTIONS
270
    OUTPUT OPTIONS
243
 
271
 
244
    These flags give information on the form of the output.
272
    These flags give information on the form of the output.
245
*/
273
*/
246
 
274
 
247
boolean show_tokdecs = 1 ;
275
boolean show_tokdecs = 1;
248
boolean show_tokdefs = 1 ;
276
boolean show_tokdefs = 1;
249
boolean show_aldecs = 1 ;
277
boolean show_aldecs = 1;
250
boolean show_aldefs = 1 ;
278
boolean show_aldefs = 1;
251
boolean show_tagdecs = 1 ;
279
boolean show_tagdecs = 1;
252
boolean show_tagdefs = 1 ;
280
boolean show_tagdefs = 1;
253
 
281
 
254
 
282
 
255
/*
283
/*
256
    FIND THE NAME OF A GIVEN SORT
284
    FIND THE NAME OF A GIVEN SORT
257
 
285
 
258
    Given the sort s, this routine returns the name of s.
286
    Given the sort s, this routine returns the name of s.
259
*/
287
*/
260
 
288
 
261
char *sort_name
289
char *
262
    PROTO_N ( ( s ) )
-
 
263
    PROTO_T ( sortname s )
290
sort_name(sortname s)
264
{
291
{
265
    if ( is_high ( s ) ) {
292
    if (is_high(s)) {
266
	high_sort *h = high_sorts + high_no ( s ) ;
293
	high_sort *h = high_sorts + high_no(s);
267
	return ( h->name ) ;
294
	return(h->name);
268
    } else if ( s == SORT_unknown || s < 0 ) {
295
    } else if (s == SORT_unknown || s < 0) {
269
	return ( "...." ) ;
296
	return("....");
270
    } else {
297
    } else {
271
	construct *p = cons_no ( SORT_sortname, s ) ;
298
	construct *p = cons_no(SORT_sortname, s);
272
	return ( p->name ) ;
299
	return(p->name);
273
    }
300
    }
274
}
301
}
275
 
302
 
276
 
303
 
277
/*
304
/*
Line 280... Line 307...
280
    The construct p of sort s is added to the built-in construct hash
307
    The construct p of sort s is added to the built-in construct hash
281
    table.  The routine returns a pointer to any existing entry of
308
    table.  The routine returns a pointer to any existing entry of
282
    the same name, or null otherwise.
309
    the same name, or null otherwise.
283
*/
310
*/
284
 
311
 
285
construct *add_to_cons_hash
312
construct *
286
    PROTO_N ( ( p, s ) )
-
 
287
    PROTO_T ( construct *p X sortname s )
313
add_to_cons_hash(construct *p, sortname s)
288
{
314
{
289
    construct *q ;
315
    construct *q;
290
    int n = hash ( p->name ) ;
316
    int n = hash(p->name);
291
    construct *h = cons_hash_tables [ hash_size * s + n ] ;
317
    construct *h = cons_hash_tables[hash_size * s + n];
292
    for ( q = h ; q != null ; q = q->next ) {
318
    for (q = h; q != null; q = q->next) {
293
	if ( streq ( p->name, q->name ) ) return ( q ) ;
319
	if (streq(p->name, q->name)) return(q);
294
    }
320
    }
295
    p->next = h ;
321
    p->next = h;
296
    cons_hash_tables [ hash_size * s + n ] = p ;
322
    cons_hash_tables[hash_size * s + n] = p;
297
    return ( null ) ;
323
    return(null);
298
}
324
}
299
 
325
 
300
 
326
 
301
/*
327
/*
302
    LOOK UP A NAME IN A CONSTRUCT HASH TABLE
328
    LOOK UP A NAME IN A CONSTRUCT HASH TABLE
Line 304... Line 330...
304
    A construct with name p and sort s is looked up in the built-in
330
    A construct with name p and sort s is looked up in the built-in
305
    construct hash table.  The routine returns a pointer to the
331
    construct hash table.  The routine returns a pointer to the
306
    construct if it is found, or null otherwise.
332
    construct if it is found, or null otherwise.
307
*/
333
*/
308
 
334
 
309
construct *search_cons_hash
335
construct *
310
    PROTO_N ( ( p, s ) )
-
 
311
    PROTO_T ( char *p X sortname s )
336
search_cons_hash(char *p, sortname s)
312
{
337
{
313
    construct *q ;
338
    construct *q;
314
    int n = hash ( p ) ;
339
    int n = hash(p);
315
    construct *h = cons_hash_tables [ hash_size * s + n ] ;
340
    construct *h = cons_hash_tables[hash_size * s + n];
316
    for ( q = h ; q != null ; q = q->next ) {
341
    for (q = h; q != null; q = q->next) {
317
	if ( streq ( p, q->name ) ) return ( q ) ;
342
	if (streq(p, q->name)) return(q);
318
    }
343
    }
319
    return ( null ) ;
344
    return(null);
320
}
345
}
321
 
346
 
322
 
347
 
323
/*
348
/*
324
    ADD A NAME TO A VARIABLE HASH TABLE
349
    ADD A NAME TO A VARIABLE HASH TABLE
Line 326... Line 351...
326
    The construct p of sort s is added to the user-defined construct
351
    The construct p of sort s is added to the user-defined construct
327
    hash table.  The routine returns a pointer to any existing entry
352
    hash table.  The routine returns a pointer to any existing entry
328
    of the same name, or null otherwise.
353
    of the same name, or null otherwise.
329
*/
354
*/
330
 
355
 
331
construct *add_to_var_hash
356
construct *
332
    PROTO_N ( ( p, s ) )
-
 
333
    PROTO_T ( construct *p X sortname s )
357
add_to_var_hash(construct *p, sortname s)
334
{
358
{
335
    construct *q ;
359
    construct *q;
336
    int n = hash ( p->name ) ;
360
    int n = hash(p->name);
337
    construct *h = var_hash_tables [ hash_size * s + n ] ;
361
    construct *h = var_hash_tables[hash_size * s + n];
338
    for ( q = h ; q != null ; q = q->next ) {
362
    for (q = h; q != null; q = q->next) {
339
	if ( streq ( p->name, q->name ) ) return ( q ) ;
363
	if (streq(p->name, q->name)) return(q);
340
    }
364
    }
341
    p->next = h ;
365
    p->next = h;
342
    var_hash_tables [ hash_size * s + n ] = p ;
366
    var_hash_tables[hash_size * s + n] = p;
343
    return ( null ) ;
367
    return(null);
344
}
368
}
345
 
369
 
346
 
370
 
347
/*
371
/*
348
    LOOK UP A NAME IN A VARIABLE HASH TABLE
372
    LOOK UP A NAME IN A VARIABLE HASH TABLE
Line 350... Line 374...
350
    A construct with name p and sort s is looked up in the user-defined
374
    A construct with name p and sort s is looked up in the user-defined
351
    construct hash table.  The routine returns a pointer to the construct
375
    construct hash table.  The routine returns a pointer to the construct
352
    if it is found, or null otherwise.
376
    if it is found, or null otherwise.
353
*/
377
*/
354
 
378
 
355
construct *search_var_hash
379
construct *
356
    PROTO_N ( ( p, s ) )
-
 
357
    PROTO_T ( char *p X sortname s )
380
search_var_hash(char *p, sortname s)
358
{
381
{
359
    construct *q ;
382
    construct *q;
360
    int n = hash ( p ) ;
383
    int n = hash(p);
361
    construct *h = var_hash_tables [ hash_size * s + n ] ;
384
    construct *h = var_hash_tables[hash_size * s + n];
362
    for ( q = h ; q != null ; q = q->next ) {
385
    for (q = h; q != null; q = q->next) {
363
	if ( streq ( p, q->name ) ) return ( q ) ;
386
	if (streq(p, q->name)) return(q);
364
    }
387
    }
365
    return ( null ) ;
388
    return(null);
366
}
389
}
367
 
390
 
368
 
391
 
369
/*
392
/*
370
    LIST OF ALL REMOVED CONSTRUCTS
393
    LIST OF ALL REMOVED CONSTRUCTS
Line 372... Line 395...
372
    All constructs removed from the user-defined construct hash table
395
    All constructs removed from the user-defined construct hash table
373
    are formed into a list.  This is used in node.c to form the
396
    are formed into a list.  This is used in node.c to form the
374
    completion of a node.
397
    completion of a node.
375
*/
398
*/
376
 
399
 
377
construct *removals = null ;
400
construct *removals = null;
378
 
401
 
379
 
402
 
380
/*
403
/*
381
    REMOVE A NAME FROM A VARIABLE HASH TABLE
404
    REMOVE A NAME FROM A VARIABLE HASH TABLE
382
 
405
 
383
    The construct with name p and sort s is removed from the
406
    The construct with name p and sort s is removed from the
384
    user-defined hash table and added to the removals list.  There
407
    user-defined hash table and added to the removals list.  There
385
    is no error if the construct does not exist.
408
    is no error if the construct does not exist.
386
*/
409
*/
387
 
410
 
388
void remove_var_hash
411
void
389
    PROTO_N ( ( p, s ) )
-
 
390
    PROTO_T ( char *p X sortname s )
412
remove_var_hash(char *p, sortname s)
391
{
413
{
392
    int n = hash ( p ) ;
414
    int n = hash(p);
393
    construct *h = var_hash_tables [ hash_size * s + n ] ;
415
    construct *h = var_hash_tables[hash_size * s + n];
394
    if ( h == null ) return ;
416
    if (h == null) return;
395
    if ( streq ( p, h->name ) ) {
417
    if (streq(p, h->name)) {
396
	/* It is the first element */
418
	/* It is the first element */
397
	var_hash_tables [ hash_size * s + n ] = h->next ;
419
	var_hash_tables[hash_size * s + n] = h->next;
398
	h->next = removals ;
420
	h->next = removals;
399
	removals = h ;
421
	removals = h;
400
	( sort_removed [s] )++ ;
422
	(sort_removed[s]) ++;
401
	return ;
423
	return;
402
    }
424
    }
403
    while ( h->next ) {
425
    while (h->next) {
404
	if ( streq ( p, h->next->name ) ) {
426
	if (streq(p, h->next->name)) {
405
	    /* It is a subsequent element */
427
	    /* It is a subsequent element */
406
	    construct *q = h->next->next ;
428
	    construct *q = h->next->next;
407
	    h->next->next = removals ;
429
	    h->next->next = removals;
408
	    removals = h->next ;
430
	    removals = h->next;
409
	    h->next = q ;
431
	    h->next = q;
410
	    ( sort_removed [s] )++ ;
432
	   (sort_removed[s]) ++;
411
	    return ;
433
	    return;
412
	}
434
	}
413
	h = h->next ;
435
	h = h->next;
414
    }
436
    }
415
    /* Not found */
437
    /* Not found */
416
    return ;
438
    return;
417
}
439
}
418
 
440
 
419
 
441
 
420
/*
442
/*
421
    SORT A HASH TABLE
443
    SORT A HASH TABLE
Line 424... Line 446...
424
    alphabetical order.  They are formed into a list where the
446
    alphabetical order.  They are formed into a list where the
425
    constructs with hash value 0 should be.  After sorting the hash
447
    constructs with hash value 0 should be.  After sorting the hash
426
    table cannot be used.
448
    table cannot be used.
427
*/
449
*/
428
 
450
 
429
void sort_table
451
void
430
    PROTO_N ( ( tab, s ) )
-
 
431
    PROTO_T ( construct **tab X sortname s )
452
sort_table(construct **tab, sortname s)
432
{
453
{
433
    int i ;
454
    int i;
434
    construct *q = null ;
455
    construct *q = null;
435
    for ( i = 0 ; i < hash_size ; i++ ) {
456
    for (i = 0; i < hash_size; i++) {
436
	construct *p = tab [ hash_size * s + i ] ;
457
	construct *p = tab[hash_size * s + i];
437
	tab [ hash_size * s + i ] = null ;
458
	tab[hash_size * s + i] = null;
438
	while ( p ) {
459
	while (p) {
439
	    construct *p_next = p->next ;
460
	    construct *p_next = p->next;
440
	    construct *r_last = null, *r = q ;
461
	    construct *r_last = null, *r = q;
441
	    p->next = null ;
462
	    p->next = null;
442
	    while ( r && strcmp ( r->name, p->name ) < 0 ) {
463
	    while (r && strcmp(r->name, p->name) < 0) {
443
		r_last = r ;
464
		r_last = r;
444
		r = r->next ;
465
		r = r->next;
445
	    }
466
	    }
446
	    if ( r_last == null ) {
467
	    if (r_last == null) {
447
		p->next = q ;
468
		p->next = q;
448
		q = p ;
469
		q = p;
449
	    } else {
470
	    } else {
450
		r_last->next = p ;
471
		r_last->next = p;
451
		p->next = r ;
472
		p->next = r;
452
	    }
473
	    }
453
	    p = p_next ;
474
	    p = p_next;
454
	}
475
	}
455
    }
476
    }
456
    tab [ hash_size * s ] = q ;
477
    tab[hash_size * s] = q;
457
    return ;
478
    return;
458
}
479
}
459
 
480
 
460
 
481
 
461
/*
482
/*
462
    FLAG
483
    FLAG
463
 
484
 
464
    This flag may be set to false to prevent sort_all sorting its
485
    This flag may be set to false to prevent sort_all sorting its
465
    tables.
486
    tables.
466
*/
487
*/
467
 
488
 
468
boolean order_names = 1 ;
489
boolean order_names = 1;
469
 
490
 
470
 
491
 
471
/*
492
/*
472
    SORTING ROUTINE
493
    SORTING ROUTINE
473
 
494
 
474
    The user-defined alignment tags, tags and tokens are sorted into
495
    The user-defined alignment tags, tags and tokens are sorted into
475
    alphabetical order.
496
    alphabetical order.
476
*/
497
*/
477
 
498
 
478
void sort_all
499
void
479
    PROTO_Z ()
500
sort_all(void)
480
{
501
{
481
    if ( order_names ) {
502
    if (order_names) {
482
	sort_table ( var_hash_tables, SORT_al_tag ) ;
503
	sort_table(var_hash_tables, SORT_al_tag);
483
	sort_table ( var_hash_tables, SORT_tag ) ;
504
	sort_table(var_hash_tables, SORT_tag);
484
	sort_table ( var_hash_tables, SORT_token ) ;
505
	sort_table(var_hash_tables, SORT_token);
485
    }
506
    }
486
    return ;
507
    return;
487
}
508
}
488
 
509
 
489
 
510
 
490
/*
511
/*
491
    APPLY A PROCEDURE TO ALL CONSTRUCTS
512
    APPLY A PROCEDURE TO ALL CONSTRUCTS
492
 
513
 
493
    The routine f is applied to all user-defined constructs of sort s
514
    The routine f is applied to all user-defined constructs of sort s
494
    by scanning across the hash table.
515
    by scanning across the hash table.
495
*/
516
*/
496
 
517
 
497
void apply_to_all
518
void
498
    PROTO_N ( ( f, s ) )
-
 
499
    PROTO_T ( apply_func f X sortname s )
519
apply_to_all(apply_func f, sortname s)
500
{
520
{
501
    int i ;
521
    int i;
502
    for ( i = 0 ; i < hash_size ; i++ ) {
522
    for (i = 0; i < hash_size; i++) {
503
	construct *p = var_hash_tables [ hash_size * s + i ] ;
523
	construct *p = var_hash_tables[hash_size * s + i];
504
	while ( p ) {
524
	while (p) {
505
	    construct *q = p->next ;
525
	    construct *q = p->next;
506
	    ( *f ) ( p ) ;
526
	   (*f)(p);
507
	    p = q ;
527
	    p = q;
508
	}
528
	}
509
    }
529
    }
510
    return ;
530
    return;
511
}
531
}