Subversion Repositories tendra.SVN

Rev

Rev 5 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5 Rev 6
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2006 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 31... Line 61...
31
#include "config.h"
61
#include "config.h"
32
#include "c_types.h"
62
#include "c_types.h"
33
#include "error.h"
63
#include "error.h"
34
#include "xalloc.h"
64
#include "xalloc.h"
35
 
65
 
36
 
66
 
37
/*
67
/*
38
    CHECK FOR CORRECT HEADERS
68
    CHECK FOR CORRECT HEADERS
39
 
69
 
40
    The functions defined in this file give the implementations of various
70
    The functions defined in this file give the implementations of various
41
    support functions used by the c_class implementation.  They should
71
    support functions used by the c_class implementation.  They should
42
    therefore be compiled with the c_class implementation rather than the
72
    therefore be compiled with the c_class implementation rather than the
43
    specification.
73
    specification.
44
*/
74
*/
45
 
75
 
46
#if c_class_SPECIFICATION
76
#if c_class_SPECIFICATION
47
FAIL_COMPILER ( Implementation functions compiled with token specifications )
77
FAIL_COMPILER(Implementation functions compiled with token specifications)
48
#endif
78
#endif
49
 
79
 
50
 
80
 
51
/*
81
/*
52
    FREE OBJECTS
82
    FREE OBJECTS
Line 56... Line 86...
56
*/
86
*/
57
 
87
 
58
#define SMALL_BLOCK		24
88
#define SMALL_BLOCK		24
59
#define ALLOC_BLOCK		2048
89
#define ALLOC_BLOCK		2048
60
 
90
 
61
#if ( c_class_GEN_MAX > SMALL_BLOCK )
91
#if (c_class_GEN_MAX > SMALL_BLOCK)
62
FAIL_COMPILER ( Free block array is too small )
92
FAIL_COMPILER(Free block array is too small)
63
#endif
93
#endif
64
 
94
 
65
static c_class *free_c_classes = NULL ;
95
static c_class *free_c_classes = NULL;
66
static unsigned free_c_classes_left = 0 ;
96
static unsigned free_c_classes_left = 0;
67
unsigned total_c_classes = 0 ;
97
unsigned total_c_classes = 0;
68
 
98
 
69
static c_class *free_c_class_array [ SMALL_BLOCK ] = {
99
static c_class *free_c_class_array[SMALL_BLOCK] = {
70
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
100
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
71
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
101
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
72
} ;
102
};
73
 
103
 
74
 
104
 
75
/*
105
/*
76
    GENERATE A NEW OBJECT BLOCK
106
    GENERATE A NEW OBJECT BLOCK
77
 
107
 
78
    This routine generates a new block of c_classes of size sz.  Small
108
    This routine generates a new block of c_classes of size sz.  Small
79
    blocks are allocated from the c_class array, others from the main
109
    blocks are allocated from the c_class array, others from the main
80
    c_class list.
110
    c_class list.
81
*/
111
*/
82
 
112
 
83
c_class *gen_c_class
113
c_class *
84
    PROTO_N ( ( sz ) )
-
 
85
    PROTO_T ( unsigned sz )
114
gen_c_class(unsigned sz)
86
{
115
{
87
    c_class *p ;
116
	c_class *p;
88
    unsigned n = sz ;
117
	unsigned n = sz;
89
    if ( n < SMALL_BLOCK ) {
118
	if (n < SMALL_BLOCK) {
90
	/* Allocate from small block array */
119
		/* Allocate from small block array */
-
 
120
		if (n == 0) {
91
	if ( n == 0 ) return ( NULL ) ;
121
			return(NULL);
-
 
122
		}
92
	p = free_c_class_array [n] ;
123
		p = free_c_class_array[n];
93
	if ( p ) {
124
		if (p) {
94
	    free_c_class_array [n] = TAIL_list ( p ) ;
125
			free_c_class_array[n] = TAIL_list(p);
95
	    return ( p ) ;
126
			return(p);
-
 
127
		}
96
	}
128
	}
97
    }
-
 
98
    if ( n > free_c_classes_left ) {
129
	if (n > free_c_classes_left) {
99
	/* Allocate new blocks */
130
		/* Allocate new blocks */
100
	unsigned m = ALLOC_BLOCK ;
131
		unsigned m = ALLOC_BLOCK;
101
	if ( n > m ) m = n ;
132
		if (n > m) {
-
 
133
			m = n;
-
 
134
		}
102
	free_c_classes = xmalloc_nof ( c_class, m ) ;
135
		free_c_classes = xmalloc_nof(c_class, m);
103
	free_c_classes_left = m ;
136
		free_c_classes_left = m;
104
    }
137
	}
105
    p = free_c_classes ;
138
	p = free_c_classes;
106
    free_c_classes += n ;
139
	free_c_classes += n;
107
    free_c_classes_left -= n ;
140
	free_c_classes_left -= n;
108
    return ( p ) ;
141
	return(p);
109
}
142
}
110
 
143
 
111
 
144
 
112
/*
145
/*
113
    MARK AN OBJECT AS FREE
146
    MARK AN OBJECT AS FREE
Line 116... Line 149...
116
    object as having been freed.  This only has any effect in conjunction
149
    object as having been freed.  This only has any effect in conjunction
117
    with the debugging routine below.
150
    with the debugging routine below.
118
*/
151
*/
119
 
152
 
120
#ifdef RUNTIME
153
#ifdef RUNTIME
121
#define clean_c_class( P, Z )\
154
#define clean_c_class(P, Z)\
122
    {\
155
    {\
123
	ASSERT ( TYPEID ( P ) != TYPEID_free ) ;\
156
	ASSERT(TYPEID(P) != TYPEID_free);\
124
	TYPEID ( P ) = TYPEID_free ;\
157
	TYPEID(P) = TYPEID_free ;\
125
	total_c_classes -= ( Z ) ;\
158
	total_c_classes -= (Z);\
126
    }
159
    }
127
#else
160
#else
128
#define clean_c_class( P, Z )	/* empty */
161
#define clean_c_class(P, Z)	/* empty */
129
#endif
162
#endif
130
 
163
 
131
 
164
 
132
/*
165
/*
133
    GENERATE A NEW OBJECT BLOCK (DEBUG VERSION)
166
    GENERATE A NEW OBJECT BLOCK (DEBUG VERSION)
Line 136... Line 169...
136
    run-time type information t in the allocated block.
169
    run-time type information t in the allocated block.
137
*/
170
*/
138
 
171
 
139
#ifdef RUNTIME
172
#ifdef RUNTIME
140
 
173
 
141
c_class *debug_c_class
174
c_class *
142
    PROTO_N ( ( sz, t ) )
-
 
143
    PROTO_T ( unsigned sz X unsigned t )
175
debug_c_class(unsigned sz, unsigned t)
144
{
176
{
145
    c_class *p ;
177
	c_class *p;
146
    unsigned n = sz ;
178
	unsigned n = sz;
147
    total_c_classes += n ;
179
	total_c_classes += n;
148
    if ( n < SMALL_BLOCK ) {
180
	if (n < SMALL_BLOCK) {
149
	/* Allocate from small block array */
181
		/* Allocate from small block array */
-
 
182
		if (n == 0) {
150
	if ( n == 0 ) return ( NULL ) ;
183
			return(NULL);
-
 
184
		}
151
	p = free_c_class_array [n] ;
185
		p = free_c_class_array[n];
152
	if ( p ) {
186
		if (p) {
153
	    free_c_class_array [n] = TAIL_list ( p ) ;
187
			free_c_class_array[n] = TAIL_list(p);
154
	    ASSERT ( TYPEID ( p ) == TYPEID_free ) ;
188
			ASSERT(TYPEID(p) == TYPEID_free);
155
	    TYPEID ( p ) = t ;
189
			TYPEID(p) = t;
156
	    return ( p ) ;
190
			return(p);
-
 
191
		}
157
	}
192
	}
158
    }
-
 
159
    n += 1 ;
193
	n += 1;
160
    if ( n > free_c_classes_left ) {
194
	if (n > free_c_classes_left) {
161
	/* Allocate new blocks */
195
		/* Allocate new blocks */
162
	unsigned m = ALLOC_BLOCK ;
196
		unsigned m = ALLOC_BLOCK;
163
	if ( n > m ) m = n ;
197
		if (n > m) {
-
 
198
			m = n;
-
 
199
		}
164
	free_c_classes = xmalloc_nof ( c_class, m ) ;
200
		free_c_classes = xmalloc_nof(c_class, m);
165
	free_c_classes_left = m ;
201
		free_c_classes_left = m;
166
    }
202
	}
167
    p = free_c_classes + 1 ;
203
	p = free_c_classes + 1;
168
    TYPEID ( p ) = t ;
204
	TYPEID(p) = t;
169
    free_c_classes += n ;
205
	free_c_classes += n;
170
    free_c_classes_left -= n ;
206
	free_c_classes_left -= n;
171
    return ( p ) ;
207
	return(p);
172
}
208
}
173
 
209
 
174
#endif /* RUNTIME */
210
#endif /* RUNTIME */
175
 
211
 
176
 
212
 
177
/*
213
/*
178
    DESTROY AN OBJECT BLOCK
214
    DESTROY AN OBJECT BLOCK
179
 
215
 
180
    This routine destroys the block of c_classes p of size sz.
216
    This routine destroys the block of c_classes p of size sz.
181
*/
217
*/
182
 
218
 
183
void destroy_c_class
219
void
184
    PROTO_N ( ( p, sz ) )
-
 
185
    PROTO_T ( c_class *p X unsigned sz )
220
destroy_c_class(c_class *p, unsigned sz)
186
{
221
{
187
    if ( p ) {
222
	if (p) {
188
	unsigned n = sz ;
223
		unsigned n = sz;
189
	c_class **r = free_c_class_array ;
224
		c_class **r = free_c_class_array;
190
	if ( n < SMALL_BLOCK ) r += n ;
225
		if (n < SMALL_BLOCK) {
-
 
226
			r += n;
-
 
227
		}
191
	clean_c_class ( p, n ) ;
228
		clean_c_class(p, n);
192
	TAIL_list ( p ) = *r ;
229
		TAIL_list(p) = *r;
193
	*r = p ;
230
		*r = p;
194
    }
231
	}
195
    return ;
232
	return;
196
}
233
}
197
 
234
 
198
 
235
 
199
/*
236
/*
200
    DUMMY OBJECT BLOCK DESTRUCTOR
237
    DUMMY OBJECT BLOCK DESTRUCTOR
201
 
238
 
202
    This routine is a dummy destructor which does nothing.
239
    This routine is a dummy destructor which does nothing.
203
*/
240
*/
204
 
241
 
205
void dummy_destroy_c_class
242
void
206
    PROTO_N ( ( p, sz ) )
-
 
207
    PROTO_T ( c_class *p X unsigned sz )
243
dummy_destroy_c_class(c_class *p, unsigned sz)
208
{
244
{
209
    UNUSED ( p ) ;
245
	UNUSED(p);
210
    UNUSED ( sz ) ;
246
	UNUSED(sz);
211
    return ;
-
 
212
}
-
 
213
 
-
 
214
 
-
 
215
/*
-
 
216
    DESTROY A LIST OF OBJECT BLOCKS
-
 
217
 
-
 
218
    This routine destroys the list p of blocks of c_classes of size sz.
-
 
219
    The list is added to the appropriate entry of the free c_class array.
-
 
220
*/
-
 
221
 
-
 
222
void destroy_c_class_list
-
 
223
    PROTO_N ( ( p, sz ) )
-
 
224
    PROTO_T ( c_class *p X unsigned sz )
-
 
225
{
-
 
226
    if ( p ) {
-
 
227
	c_class *q = p ;
-
 
228
	unsigned n = sz + 1 ;
-
 
229
	c_class **r = free_c_class_array ;
-
 
230
	if ( n < SMALL_BLOCK ) r += n ;
-
 
231
	while ( TAIL_list ( p ) ) {
-
 
232
	    clean_c_class ( p, n ) ;
-
 
233
	    p = TAIL_list ( p ) ;
-
 
234
	}
-
 
235
	clean_c_class ( p, n ) ;
-
 
236
	TAIL_list ( p ) = *r ;
-
 
237
	*r = q ;
-
 
238
    }
-
 
239
    return ;
247
	return;
240
}
248
}
241
 
249
 
242
 
250
 
243
/*
251
/*
244
    FIND THE LENGTH OF A LIST
252
    DESTROY A LIST OF OBJECT BLOCKS
245
 
253
 
246
    This routine calculates the length of the list p.
254
    This routine destroys the list p of blocks of c_classes of size sz.
-
 
255
    The list is added to the appropriate entry of the free c_class array.
247
*/
256
*/
248
 
257
 
-
 
258
void
-
 
259
destroy_c_class_list(c_class *p, unsigned sz)
-
 
260
{
-
 
261
	if (p) {
-
 
262
		c_class *q = p;
249
unsigned length_c_class_list
263
		unsigned n = sz + 1;
-
 
264
		c_class **r = free_c_class_array;
-
 
265
		if (n < SMALL_BLOCK) {
-
 
266
			r += n;
-
 
267
		}
-
 
268
		while (TAIL_list(p)) {
-
 
269
			clean_c_class(p, n);
-
 
270
			p = TAIL_list(p);
-
 
271
		}
-
 
272
		clean_c_class(p, n);
-
 
273
		TAIL_list(p) = *r;
-
 
274
		*r = q;
-
 
275
	}
-
 
276
	return;
-
 
277
}
-
 
278
 
-
 
279
 
-
 
280
/*
250
    PROTO_N ( ( p ) )
281
    FIND THE LENGTH OF A LIST
-
 
282
 
-
 
283
    This routine calculates the length of the list p.
-
 
284
*/
-
 
285
 
-
 
286
unsigned
251
    PROTO_T ( c_class *p )
287
length_c_class_list(c_class *p)
252
{
288
{
253
    unsigned n = 0 ;
289
	unsigned n = 0;
254
    c_class *q = p ;
290
	c_class *q = p;
255
    while ( q ) {
291
	while (q) {
256
	n++ ;
292
		n++;
257
	q = TAIL_list ( q ) ;
293
		q = TAIL_list(q);
258
    }
294
	}
259
    return ( n ) ;
295
	return(n);
260
}
296
}
261
 
297
 
262
 
298
 
263
/*
299
/*
264
    REVERSE A LIST
300
    REVERSE A LIST
265
 
301
 
266
    This routine reverses the order of the list p.
302
    This routine reverses the order of the list p.
267
*/
303
*/
268
 
304
 
269
c_class *reverse_c_class_list
305
c_class *
270
    PROTO_N ( ( p ) )
-
 
271
    PROTO_T ( c_class *p )
306
reverse_c_class_list(c_class *p)
272
{
307
{
273
    c_class *r = NULL ;
308
	c_class *r = NULL;
274
    c_class *q = p ;
309
	c_class *q = p;
275
    while ( q ) {
310
	while (q) {
276
	c_class *nq = TAIL_list ( q ) ;
311
		c_class *nq = TAIL_list(q);
277
	TAIL_list ( q ) = r ;
312
		TAIL_list(q) = r;
278
	r = q ;
313
		r = q;
279
	q = nq ;
314
		q = nq;
280
    }
315
	}
281
    return ( r ) ;
316
	return(r);
282
}
317
}
283
 
318
 
284
 
319
 
285
/*
320
/*
286
    APPEND TWO LISTS
321
    APPEND TWO LISTS
287
 
322
 
288
    This routine appends the lists of c_class blocks p and q.
323
    This routine appends the lists of c_class blocks p and q.
289
*/
324
*/
290
 
325
 
291
c_class *append_c_class_list
326
c_class *
292
    PROTO_N ( ( p, q ) )
-
 
293
    PROTO_T ( c_class *p X c_class *q )
327
append_c_class_list(c_class *p, c_class *q)
294
{
328
{
295
    c_class *r = p ;
329
	c_class *r = p;
296
    if ( r == NULL ) return ( q ) ;
330
	if (r == NULL) {
-
 
331
		return(q);
-
 
332
	}
297
    while ( TAIL_list ( r ) ) r = TAIL_list ( r ) ;
333
	while (TAIL_list(r)) {
-
 
334
		r = TAIL_list(r);
-
 
335
	}
298
    TAIL_list ( r ) = q ;
336
	TAIL_list(r) = q;
299
    return ( p ) ;
337
	return(p);
300
}
338
}
301
 
339
 
302
 
340
 
303
/*
341
/*
304
    FIND THE LAST MEMBER OF A LIST
342
    FIND THE LAST MEMBER OF A LIST
305
 
343
 
306
    This routine returns the last member of the list of c_class blocks p.
344
    This routine returns the last member of the list of c_class blocks p.
307
*/
345
*/
308
 
346
 
309
c_class *end_c_class_list
347
c_class *
310
    PROTO_N ( ( p ) )
-
 
311
    PROTO_T ( c_class *p )
348
end_c_class_list(c_class *p)
312
{
349
{
313
    c_class *r = p ;
350
	c_class *r = p;
314
    if ( r == NULL ) return ( NULL ) ;
351
	if (r == NULL) {
-
 
352
		return(NULL);
-
 
353
	}
315
    while ( TAIL_list ( r ) ) r = TAIL_list ( r ) ;
354
	while (TAIL_list(r)) {
-
 
355
		r = TAIL_list(r);
-
 
356
	}
316
    return ( r ) ;
357
	return(r);
317
}
358
}
318
 
359
 
319
 
360
 
320
/*
361
/*
321
    GENERIC EMPTY VECTOR
362
   GENERIC EMPTY VECTOR
322
 
363
 
323
    This c_class represents the generic empty vector.  It is only defined
364
   This c_class represents the generic empty vector.  It is only defined
324
    if vector operations have been enabled.  Note that the element field
365
   if vector operations have been enabled.  Note that the element field
325
    of a vector is not be NULL, even if the vector is empty.
366
   of a vector is not be NULL, even if the vector is empty.
326
*/
367
 */
327
 
368
 
328
#ifdef VEC
369
#ifdef VEC
329
static c_class dummy_elem ;
370
static c_class dummy_elem;
330
c_class_VEC empty_c_class_vec = { 0, { &dummy_elem, &dummy_elem } } ;
371
c_class_VEC empty_c_class_vec = {0, {&dummy_elem, &dummy_elem}};
331
#endif
372
#endif
332
 
373
 
333
 
374
 
334
#ifdef c_class_IO_ROUTINES
375
#ifdef c_class_IO_ROUTINES
335
 
376
 
336
/*
377
/*
337
    ALIASING VARIABLES
378
   ALIASING VARIABLES
-
 
379
 
-
 
380
   These variables give respectively the current alias number and the
-
 
381
   list of all aliases.
-
 
382
 */
-
 
383
 
-
 
384
unsigned crt_c_class_alias = 0;
-
 
385
static c_class *crt_alias_list = NULL;
-
 
386
 
-
 
387
 
-
 
388
/*
-
 
389
   SET AN ALIAS
338
 
390
 
339
    These variables give respectively the current alias number and the
391
   This routine sets up an alias of p to n.
340
    list of all aliases.
-
 
341
*/
392
 */
342
 
393
 
343
unsigned crt_c_class_alias = 0 ;
-
 
344
static c_class *crt_alias_list = NULL ;
-
 
345
 
-
 
346
 
-
 
347
/*
394
void
348
    SET AN ALIAS
-
 
349
 
-
 
350
    This routine sets up an alias of p to n.
-
 
351
*/
-
 
352
 
-
 
353
void set_c_class_alias
-
 
354
    PROTO_N ( ( p, n ) )
-
 
355
    PROTO_T ( c_class *p X unsigned n )
395
set_c_class_alias(c_class *p, unsigned n)
356
{
396
{
357
    c_class *q = GEN_c_class ( 2, TYPEID_list ) ;
397
	c_class *q = GEN_c_class(2, TYPEID_list);
358
    TAIL_list ( q ) = crt_alias_list ;
398
	TAIL_list(q) = crt_alias_list;
359
    HEAD_list ( q )->ag_ptr = p ;
399
	HEAD_list(q) ->ag_ptr = p;
360
    ASSERT ( p != NULL ) ;
400
	ASSERT(p != NULL);
361
    p->ag_tag = n ;
401
	p->ag_tag = n;
362
    crt_alias_list = q ;
402
	crt_alias_list = q;
363
    return ;
403
	return;
364
}
404
}
365
 
405
 
366
 
406
 
367
/*
407
/*
368
    FIND AN ALIAS
408
    FIND AN ALIAS
369
 
409
 
370
    This routine searches for alias number n.
410
    This routine searches for alias number n.
371
*/
411
*/
372
 
412
 
373
c_class *find_c_class_alias
413
c_class *
374
    PROTO_N ( ( n ) )
-
 
375
    PROTO_T ( unsigned n )
414
find_c_class_alias(unsigned n)
376
{
415
{
377
    c_class *p = crt_alias_list ;
416
	c_class *p = crt_alias_list;
378
    while ( p ) {
417
	while (p) {
379
	c_class *q = HEAD_list ( p )->ag_ptr ;
418
		c_class *q = HEAD_list(p) ->ag_ptr;
380
	if ( q->ag_tag == n ) return ( q ) ;
419
		if (q->ag_tag == n) {
-
 
420
			return (q);
-
 
421
		}
381
	p = TAIL_list ( p ) ;
422
		p = TAIL_list(p);
382
    }
423
	}
383
    error ( ERROR_INTERNAL, "Can't find alias %u", n ) ;
424
	error(ERROR_INTERNAL, "Can't find alias %u", n);
384
    return ( NULL ) ;
425
	return (NULL);
385
}
426
}
386
 
427
 
387
 
428
 
388
/*
429
/*
389
    CLEAR ALL ALIASES
430
    CLEAR ALL ALIASES
390
 
431
 
391
    This routine clears all aliases.  Each alias in the list is reset to
432
    This routine clears all aliases.  Each alias in the list is reset to
392
    zero, and the list itself is freed.
433
    zero, and the list itself is freed.
393
*/
434
*/
394
 
435
 
-
 
436
void
395
void clear_c_class_alias
437
clear_c_class_alias(void)
396
    PROTO_Z ()
-
 
397
{
438
{
398
    c_class *p = crt_alias_list ;
439
	c_class *p = crt_alias_list;
399
    c_class *q = NULL ;
440
	c_class *q = NULL;
400
    while ( p ) {
441
	while (p) {
401
	HEAD_list ( p )->ag_ptr->ag_tag = 0 ;
442
		HEAD_list(p)->ag_ptr->ag_tag = 0;
402
	q = p ;
443
		q = p;
403
	p = TAIL_list ( p ) ;
444
		p = TAIL_list(p);
404
    }
445
	}
405
    if ( q ) {
446
	if (q) {
406
	TAIL_list ( q ) = free_c_class_array [2] ;
447
		TAIL_list(q) = free_c_class_array[2];
407
	free_c_class_array [2] = crt_alias_list ;
448
		free_c_class_array[2] = crt_alias_list;
408
    }
449
	}
409
    crt_c_class_alias = 0 ;
450
	crt_c_class_alias = 0;
410
    crt_alias_list = NULL ;
451
	crt_alias_list = NULL;
411
    return ;
452
	return;
412
}
453
}
413
 
454
 
414
#endif /* c_class_IO_ROUTINES */
455
#endif /* c_class_IO_ROUTINES */
415
 
456
 
416
 
457