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-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
*/
29
 
59
 
30
 
60
 
31
/*** name-key.c --- External name key ADT.
61
/*** name-key.c --- External name key ADT.
32
 *
62
 *
33
 ** Author: Steve Folkes <smf@hermes.mod.uk>
63
 ** Author: Steve Folkes <smf@hermes.mod.uk>
34
 *
64
 *
35
 *** Commentary:
65
 *** Commentary:
36
 *
66
 *
37
 * This file implements the external name key routines used by the TDF linker.
67
 * This file implements the external name key routines used by the TDF linker.
38
 *
68
 *
39
 *** Change Log:
69
 *** Change Log:
40
 * $Log: name-key.c,v $
70
 * $Log: name-key.c,v $
41
 * Revision 1.1.1.1  1998/01/17  15:57:19  release
71
 * Revision 1.1.1.1  1998/01/17  15:57:19  release
42
 * First version to be checked into rolling release.
72
 * First version to be checked into rolling release.
43
 *
73
 *
44
 * Revision 1.3  1995/09/22  08:39:28  smf
74
 * Revision 1.3  1995/09/22  08:39:28  smf
45
 * Fixed problems with incomplete structures (to shut "tcc" up).
75
 * Fixed problems with incomplete structures (to shut "tcc" up).
46
 * Fixed some problems in "name-key.c" (no real problems, but rewritten to
76
 * Fixed some problems in "name-key.c" (no real problems, but rewritten to
47
 * reduce the warnings that were output by "tcc" and "gcc").
77
 * reduce the warnings that were output by "tcc" and "gcc").
48
 * Fixed bug CR95_354.tld-common-id-problem (library capsules could be loaded
78
 * Fixed bug CR95_354.tld-common-id-problem (library capsules could be loaded
Line 65... Line 95...
65
#include "solve-cycles.h"
95
#include "solve-cycles.h"
66
 
96
 
67
/*--------------------------------------------------------------------------*/
97
/*--------------------------------------------------------------------------*/
68
 
98
 
69
static BoolT
99
static BoolT
70
name_key_parse_hex_char PROTO_N ((name, c_ref))
100
name_key_parse_hex_char(CStringP name,				 char    *c_ref)
71
			PROTO_T (CStringP name X
-
 
72
				 char    *c_ref)
-
 
73
{
101
{
74
    char result;
102
    char result;
75
    char c;
103
    char c;
76
    int  value;
104
    int  value;
77
 
105
 
78
    if ((c = name [0]), ((value = syntax_value (c)) != SYNTAX_NO_VALUE)) {
106
    if ((c = name[0]), ((value = syntax_value(c)) != SYNTAX_NO_VALUE)) {
79
	result = (char) ((unsigned) value << 4);
107
	result = (char)((unsigned)value << 4);
80
    } else {
108
    } else {
81
	return (FALSE);
109
	return(FALSE);
82
    }
110
    }
83
    if ((c = name [1]), ((value = syntax_value (c)) != SYNTAX_NO_VALUE)) {
111
    if ((c = name[1]), ((value = syntax_value(c)) != SYNTAX_NO_VALUE)) {
84
	result |= (char) value;
112
	result |= (char)value;
85
    } else {
113
    } else {
86
	return (FALSE);
114
	return(FALSE);
87
    }
115
    }
88
    *c_ref = result;
116
    *c_ref = result;
89
    return (TRUE);
117
    return(TRUE);
90
}
118
}
91
 
119
 
92
static BoolT
120
static BoolT
93
name_key_parse_escaped PROTO_N ((name_ref, c_ref))
121
name_key_parse_escaped(CStringP *name_ref,				char     *c_ref)
94
		       PROTO_T (CStringP *name_ref X
-
 
95
				char     *c_ref)
-
 
96
{
122
{
97
    CStringP name = (*name_ref);
123
    CStringP name = (*name_ref);
98
 
124
 
99
    switch ((*++ name)) {
125
    switch ((*++name)) {
100
      case 'x': case 'X':
126
      case 'x': case 'X':
101
	if (!name_key_parse_hex_char (name, c_ref)) {
127
	if (!name_key_parse_hex_char(name, c_ref)) {
102
	    return (FALSE);
128
	    return(FALSE);
103
	}
129
	}
104
	name += 3;
130
	name += 3;
105
	break;
131
	break;
106
      case 'n': case 'N':
132
      case 'n': case 'N':
107
	*c_ref = '\n';
133
	*c_ref = '\n';
108
	name ++;
134
	name++;
109
	break;
135
	break;
110
      case 'r': case 'R':
136
      case 'r': case 'R':
111
	*c_ref = '\r';
137
	*c_ref = '\r';
112
	name ++;
138
	name++;
113
	break;
139
	break;
114
      case 't': case 'T':
140
      case 't': case 'T':
115
	*c_ref= '\t';
141
	*c_ref= '\t';
116
	name ++;
142
	name++;
117
	break;
143
	break;
118
      case '0':
144
      case '0':
119
	*c_ref = '\0';
145
	*c_ref = '\0';
120
	name ++;
146
	name++;
121
	break;
147
	break;
122
      case '\\': case '.': case '[': case ']':
148
      case '\\': case '.': case '[': case ']':
123
	*c_ref = *name ++;
149
	*c_ref = *name++;
124
	break;
150
	break;
125
      default:
151
      default:
126
	return (FALSE);
152
	return(FALSE);
127
    }
153
    }
128
    *name_ref = name;
154
    *name_ref = name;
129
    return (TRUE);
155
    return(TRUE);
130
}
156
}
131
 
157
 
132
static BoolT
158
static BoolT
133
name_key_parse_cstring_unique PROTO_N ((key, name))
159
name_key_parse_cstring_unique(NameKeyP key,				       CStringP name)
134
			      PROTO_T (NameKeyP key X
-
 
135
				       CStringP name)
-
 
136
{
160
{
137
    unsigned length   = 1;
161
    unsigned length   = 1;
138
    CStringP tmp_name = name;
162
    CStringP tmp_name = name;
139
    NStringP components;
163
    NStringP components;
140
    unsigned i;
164
    unsigned i;
141
 
165
 
142
    while (*++ tmp_name) {
166
    while (*++tmp_name) {
143
	if (*tmp_name == '.') {
167
	if (*tmp_name == '.') {
144
	    length ++;
168
	    length++;
145
	}
169
	}
146
    }
170
    }
147
    components = ALLOCATE_VECTOR (NStringT, length);
171
    components = ALLOCATE_VECTOR(NStringT, length);
148
    length     = 0;
172
    length     = 0;
149
    for (;;) {
173
    for (;;) {
150
	DStringT dstring;
174
	DStringT dstring;
151
 
175
 
152
	name ++;
176
	name++;
153
	dstring_init (&dstring);
177
	dstring_init(&dstring);
154
	while ((*name != '.') && (*name != ']')) {
178
	while ((*name != '.') && (*name != ']')) {
155
	    if ((*name == '\0') || (*name == '[')) {
179
	    if ((*name == '\0') || (*name == '[')) {
156
		dstring_destroy (&dstring);
180
		dstring_destroy(&dstring);
157
		goto fail;
181
		goto fail;
158
	    } else if (*name == '\\') {
182
	    } else if (*name == '\\') {
159
		char c;
183
		char c;
160
 
184
 
161
		if (name_key_parse_escaped (&name, &c)) {
185
		if (name_key_parse_escaped(&name, &c)) {
162
		    dstring_append_char (&dstring, c);
186
		    dstring_append_char(&dstring, c);
163
		} else {
187
		} else {
164
		    dstring_destroy (&dstring);
188
		    dstring_destroy(&dstring);
165
		    goto fail;
189
		    goto fail;
166
		}
190
		}
167
	    } else {
191
	    } else {
168
		dstring_append_char (&dstring, *name ++);
192
		dstring_append_char(&dstring, *name++);
169
	    }
193
	    }
170
	}
194
	}
171
	dstring_to_nstring (&dstring, &(components [length ++]));
195
	dstring_to_nstring(&dstring, & (components[length++]));
172
	if (*name == ']') {
196
	if (*name == ']') {
173
	    break;
197
	    break;
174
	}
198
	}
175
    }
199
    }
176
    if (*name) {
200
    if (*name) {
177
      fail:
201
      fail:
178
	for (i = 0; i < length ; i ++) {
202
	for (i = 0; i < length; i++) {
179
	    nstring_destroy (&(components [i]));
203
	    nstring_destroy(& (components[i]));
180
	}
204
	}
181
	DEALLOCATE (components);
205
	DEALLOCATE(components);
182
	return (FALSE);
206
	return(FALSE);
183
    }
207
    }
184
    name_key_init_unique (key, length);
208
    name_key_init_unique(key, length);
185
    for (i = 0; i < length; i ++) {
209
    for (i = 0; i < length; i++) {
186
	name_key_set_component (key, i, &(components [i]));
210
	name_key_set_component(key, i, & (components[i]));
187
    }
211
    }
188
    DEALLOCATE (components);
212
    DEALLOCATE(components);
189
    return (TRUE);
213
    return(TRUE);
190
}
214
}
191
 
215
 
192
static BoolT
216
static BoolT
193
name_key_parse_cstring_string PROTO_N ((key, name))
217
name_key_parse_cstring_string(NameKeyP key,				       CStringP name)
194
			      PROTO_T (NameKeyP key X
-
 
195
				       CStringP name)
-
 
196
{
218
{
197
    DStringT dstring;
219
    DStringT dstring;
198
    NStringT nstring;
220
    NStringT nstring;
199
 
221
 
200
    dstring_init (&dstring);
222
    dstring_init(&dstring);
201
    while (*name) {
223
    while (*name) {
202
	if ((*name == '[') || (*name == ']') || (*name == '.')) {
224
	if ((*name == '[') || (*name == ']') || (*name == '.')) {
203
	    dstring_destroy (&dstring);
225
	    dstring_destroy(&dstring);
204
	    return (FALSE);
226
	    return(FALSE);
205
	} else if (*name == '\\') {
227
	} else if (*name == '\\') {
206
	    char c;
228
	    char c;
207
 
229
 
208
	    if (name_key_parse_escaped (&name, &c)) {
230
	    if (name_key_parse_escaped(&name, &c)) {
209
		dstring_append_char (&dstring, c);
231
		dstring_append_char(&dstring, c);
210
	    } else {
232
	    } else {
211
		dstring_destroy (&dstring);
233
		dstring_destroy(&dstring);
212
		return (FALSE);
234
		return(FALSE);
213
	    }
235
	    }
214
	} else {
236
	} else {
215
	    dstring_append_char (&dstring, *name ++);
237
	    dstring_append_char(&dstring, *name++);
216
	}
238
	}
217
    }
239
    }
218
    dstring_to_nstring (&dstring, &nstring);
240
    dstring_to_nstring(&dstring, &nstring);
219
    name_key_init_string (key, &nstring);
241
    name_key_init_string(key, &nstring);
220
    return (TRUE);
242
    return(TRUE);
221
}
243
}
222
 
244
 
223
static void
245
static void
224
write_name_key_1 PROTO_N ((ostream, nstring))
246
write_name_key_1(OStreamP ostream,			  NStringP nstring)
225
		 PROTO_T (OStreamP ostream X
-
 
226
			  NStringP nstring)
-
 
227
{
247
{
228
    unsigned length = nstring_length (nstring);
248
    unsigned length = nstring_length(nstring);
229
    CStringP bytes  = nstring_contents (nstring);
249
    CStringP bytes  = nstring_contents(nstring);
230
 
250
 
231
    while (length --) {
251
    while (length--) {
232
	switch (*bytes) {
252
	switch (*bytes) {
233
	  case '[': case ']': case '.': case '\\':
253
	  case '[': case ']': case '.': case '\\':
234
	    write_char (ostream, '\\');
254
	    write_char(ostream, '\\');
235
	    FALL_THROUGH;
255
	    FALL_THROUGH;
236
	  default:
256
	  default:
237
	    write_char (ostream, *bytes);
257
	    write_char(ostream, *bytes);
238
	}
258
	}
239
	bytes ++;
259
	bytes++;
240
    }
260
    }
241
}
261
}
242
 
262
 
243
/*--------------------------------------------------------------------------*/
263
/*--------------------------------------------------------------------------*/
244
 
264
 
245
void
265
void
246
name_key_init_string PROTO_N ((key, string))
266
name_key_init_string(NameKeyP key,			      NStringP string)
247
		     PROTO_T (NameKeyP key X
-
 
248
			      NStringP string)
-
 
249
{
267
{
250
    key->type = KT_STRING;
268
    key->type = KT_STRING;
251
    nstring_assign (&(key->u.string), string);
269
    nstring_assign(& (key->u.string), string);
252
}
270
}
253
 
271
 
254
void
272
void
255
name_key_init_unique PROTO_N ((key, components))
273
name_key_init_unique(NameKeyP key,			      unsigned components)
256
		     PROTO_T (NameKeyP key X
-
 
257
			      unsigned components)
-
 
258
{
274
{
259
    key->type                = KT_UNIQUE;
275
    key->type                = KT_UNIQUE;
260
    key->u.unique.length     = components;
276
    key->u.unique.length     = components;
261
    key->u.unique.components = ALLOCATE_VECTOR (NStringT, components);
277
    key->u.unique.components = ALLOCATE_VECTOR(NStringT, components);
262
}
278
}
263
 
279
 
264
BoolT
280
BoolT
265
name_key_parse_cstring PROTO_N ((key, name))
281
name_key_parse_cstring(NameKeyP key,				CStringP name)
266
		       PROTO_T (NameKeyP key X
-
 
267
				CStringP name)
-
 
268
{
282
{
269
    if (*name == '[') {
283
    if (*name == '[') {
270
	return (name_key_parse_cstring_unique (key, name));
284
	return(name_key_parse_cstring_unique(key, name));
271
    } else {
285
    } else {
272
	return (name_key_parse_cstring_string (key, name));
286
	return(name_key_parse_cstring_string(key, name));
273
    }
287
    }
274
}
288
}
275
 
289
 
276
void
290
void
277
name_key_set_component PROTO_N ((key, component, string))
291
name_key_set_component(NameKeyP key,				unsigned component, 
278
		       PROTO_T (NameKeyP key X
-
 
279
				unsigned component X
-
 
280
				NStringP string)
292
				NStringP string)
281
{
293
{
282
    ASSERT ((key->type == KT_UNIQUE) && (component < key->u.unique.length));
294
    ASSERT((key->type == KT_UNIQUE) && (component < key->u.unique.length));
283
    nstring_assign (&(key->u.unique.components [component]), string);
295
    nstring_assign(& (key->u.unique.components[component]), string);
284
}
296
}
285
 
297
 
286
NameKeyTypeT
298
NameKeyTypeT
287
name_key_type PROTO_N ((key))
299
name_key_type(NameKeyP key)
288
	      PROTO_T (NameKeyP key)
-
 
289
{
300
{
290
    return (key->type);
301
    return(key->type);
291
}
302
}
292
 
303
 
293
NStringP
304
NStringP
294
name_key_string PROTO_N ((key))
305
name_key_string(NameKeyP key)
295
		PROTO_T (NameKeyP key)
-
 
296
{
306
{
297
    ASSERT (key->type == KT_STRING);
307
    ASSERT(key->type == KT_STRING);
298
    return (&(key->u.string));
308
    return(& (key->u.string));
299
}
309
}
300
 
310
 
301
unsigned
311
unsigned
302
name_key_components PROTO_N ((key))
312
name_key_components(NameKeyP key)
303
		    PROTO_T (NameKeyP key)
-
 
304
{
313
{
305
    ASSERT (key->type == KT_UNIQUE);
314
    ASSERT(key->type == KT_UNIQUE);
306
    return (key->u.unique.length);
315
    return(key->u.unique.length);
307
}
316
}
308
 
317
 
309
NStringP
318
NStringP
310
name_key_get_component PROTO_N ((key, component))
319
name_key_get_component(NameKeyP key,				unsigned component)
311
		       PROTO_T (NameKeyP key X
-
 
312
				unsigned component)
-
 
313
{
320
{
314
    ASSERT ((key->type == KT_UNIQUE) && (component < key->u.unique.length));
321
    ASSERT((key->type == KT_UNIQUE) && (component < key->u.unique.length));
315
    return (&(key->u.unique.components [component]));
322
    return(& (key->u.unique.components[component]));
316
}
323
}
317
 
324
 
318
unsigned
325
unsigned
319
name_key_hash_value PROTO_N ((key))
326
name_key_hash_value(NameKeyP key)
320
		    PROTO_T (NameKeyP key)
-
 
321
{
327
{
322
#ifdef __TenDRA__
328
#ifdef __TenDRA__
323
    unsigned hash_value; /* "tcc" complains if this is initialised */
329
    unsigned hash_value; /* "tcc" complains if this is initialised */
324
#else
330
#else
325
    unsigned hash_value = 0; /* "gcc" complains if this is not initialised */
331
    unsigned hash_value = 0; /* "gcc" complains if this is not initialised */
326
#endif /* defined (__TenDRA__) */
332
#endif /* defined (__TenDRA__) */
327
    unsigned components;
333
    unsigned components;
328
    unsigned i;
334
    unsigned i;
329
 
335
 
330
    switch (key->type) EXHAUSTIVE {
336
    switch (key->type)EXHAUSTIVE {
331
      case KT_STRING:
337
      case KT_STRING:
332
	hash_value = nstring_hash_value (&(key->u.string));
338
	hash_value = nstring_hash_value(& (key->u.string));
333
	break;
339
	break;
334
      case KT_UNIQUE:
340
      case KT_UNIQUE:
335
	components = key->u.unique.length;
341
	components = key->u.unique.length;
336
	hash_value = components;
342
	hash_value = components;
337
	for (i = 0; i < components; i ++) {
343
	for (i = 0; i < components; i++) {
338
	    hash_value += nstring_hash_value (&(key->u.unique.components [i]));
344
	    hash_value += nstring_hash_value(& (key->u.unique.components[i]));
339
	}
345
	}
340
	break;
346
	break;
341
    }
347
    }
342
    return (hash_value);
348
    return(hash_value);
343
}
349
}
344
 
350
 
345
BoolT
351
BoolT
346
name_key_equal PROTO_N ((key1, key2))
352
name_key_equal(NameKeyP key1,			NameKeyP key2)
347
	       PROTO_T (NameKeyP key1 X
-
 
348
			NameKeyP key2)
-
 
349
{
353
{
350
    unsigned components;
354
    unsigned components;
351
    unsigned i;
355
    unsigned i;
352
 
356
 
353
    if (key1->type != key2->type) {
357
    if (key1->type != key2->type) {
354
	return (FALSE);
358
	return(FALSE);
355
    }
359
    }
356
    switch (key1->type) EXHAUSTIVE {
360
    switch (key1->type)EXHAUSTIVE {
357
      case KT_STRING:
361
      case KT_STRING:
358
	return (nstring_equal (&(key1->u.string), &(key2->u.string)));
362
	return(nstring_equal(& (key1->u.string), & (key2->u.string)));
359
      case KT_UNIQUE:
363
      case KT_UNIQUE:
360
	if ((components = key1->u.unique.length) != key2->u.unique.length) {
364
	if ((components = key1->u.unique.length) != key2->u.unique.length) {
361
	    return (FALSE);
365
	    return(FALSE);
362
	}
366
	}
363
	for (i = 0; i < components; i ++) {
367
	for (i = 0; i < components; i++) {
364
	    if (!nstring_equal (&(key1->u.unique.components [i]),
368
	    if (!nstring_equal(& (key1->u.unique.components[i]),
365
				&(key2->u.unique.components [i]))) {
369
				& (key2->u.unique.components[i]))) {
366
		return (FALSE);
370
		return(FALSE);
367
	    }
371
	    }
368
	}
372
	}
369
	break;
373
	break;
370
    }
374
    }
371
    return (TRUE);
375
    return(TRUE);
372
}
376
}
373
 
377
 
374
void
378
void
375
name_key_assign PROTO_N ((to, from))
379
name_key_assign(NameKeyP to,			 NameKeyP from)
376
		PROTO_T (NameKeyP to X
-
 
377
			 NameKeyP from)
-
 
378
{
380
{
379
    switch (to->type = from->type) EXHAUSTIVE {
381
    switch (to->type = from->type)EXHAUSTIVE {
380
      case KT_STRING:
382
      case KT_STRING:
381
	nstring_assign (&(to->u.string), &(from->u.string));
383
	nstring_assign(& (to->u.string), & (from->u.string));
382
	break;
384
	break;
383
      case KT_UNIQUE:
385
      case KT_UNIQUE:
384
	to->u.unique.length     = from->u.unique.length;
386
	to->u.unique.length     = from->u.unique.length;
385
	to->u.unique.components = from->u.unique.components;
387
	to->u.unique.components = from->u.unique.components;
386
	break;
388
	break;
387
    }
389
    }
388
}
390
}
389
 
391
 
390
void
392
void
391
name_key_copy PROTO_N ((to, from))
393
name_key_copy(NameKeyP to,		       NameKeyP from)
392
	      PROTO_T (NameKeyP to X
-
 
393
		       NameKeyP from)
-
 
394
{
394
{
395
    unsigned components;
395
    unsigned components;
396
    unsigned i;
396
    unsigned i;
397
 
397
 
398
    switch (to->type = from->type) EXHAUSTIVE {
398
    switch (to->type = from->type)EXHAUSTIVE {
399
      case KT_STRING:
399
      case KT_STRING:
400
	nstring_copy (&(to->u.string), &(from->u.string));
400
	nstring_copy(& (to->u.string), & (from->u.string));
401
	break;
401
	break;
402
      case KT_UNIQUE:
402
      case KT_UNIQUE:
403
	components = to->u.unique.length = from->u.unique.length;
403
	components = to->u.unique.length = from->u.unique.length;
404
	to->u.unique.components = ALLOCATE_VECTOR (NStringT, components);
404
	to->u.unique.components = ALLOCATE_VECTOR(NStringT, components);
405
	for (i = 0; i < components; i ++) {
405
	for (i = 0; i < components; i++) {
406
	    nstring_copy (&(to->u.unique.components [i]),
406
	    nstring_copy(& (to->u.unique.components[i]),
407
			  &(from->u.unique.components [i]));
407
			  & (from->u.unique.components[i]));
408
	}
408
	}
409
	break;
409
	break;
410
    }
410
    }
411
}
411
}
412
 
412
 
413
void
413
void
414
name_key_destroy PROTO_N ((key))
414
name_key_destroy(NameKeyP key)
415
		 PROTO_T (NameKeyP key)
-
 
416
{
415
{
417
    unsigned components;
416
    unsigned components;
418
    unsigned i;
417
    unsigned i;
419
 
418
 
420
    switch (key->type) EXHAUSTIVE {
419
    switch (key->type)EXHAUSTIVE {
421
      case KT_STRING:
420
      case KT_STRING:
422
	nstring_destroy (&(key->u.string));
421
	nstring_destroy(& (key->u.string));
423
	break;
422
	break;
424
      case KT_UNIQUE:
423
      case KT_UNIQUE:
425
	components = key->u.unique.length;
424
	components = key->u.unique.length;
426
	for (i = 0; i < components; i ++) {
425
	for (i = 0; i < components; i++) {
427
	    nstring_destroy (&(key->u.unique.components [i]));
426
	    nstring_destroy(& (key->u.unique.components[i]));
428
	}
427
	}
429
	DEALLOCATE (key->u.unique.components);
428
	DEALLOCATE(key->u.unique.components);
430
	break;
429
	break;
431
    }
430
    }
432
}
431
}
433
 
432
 
434
void
433
void
435
write_name_key PROTO_N ((ostream, key))
434
write_name_key(OStreamP ostream,			NameKeyP key)
436
	       PROTO_T (OStreamP ostream X
-
 
437
			NameKeyP key)
-
 
438
{
435
{
439
    char     sep = '[';
436
    char     sep = '[';
440
    unsigned components;
437
    unsigned components;
441
    unsigned i;
438
    unsigned i;
442
        
439
 
443
    switch (key->type) EXHAUSTIVE {
440
    switch (key->type)EXHAUSTIVE {
444
      case KT_STRING:
441
      case KT_STRING:
445
	write_name_key_1 (ostream, &(key->u.string));
442
	write_name_key_1(ostream, & (key->u.string));
446
	break;
443
	break;
447
      case KT_UNIQUE:
444
      case KT_UNIQUE:
448
	components = key->u.unique.length;
445
	components = key->u.unique.length;
449
	for (i = 0; i < components; i ++) {
446
	for (i = 0; i < components; i++) {
450
	    NStringP nstring = &(key->u.unique.components [i]);
447
	    NStringP nstring = & (key->u.unique.components[i]);
451
 
448
 
452
	    write_char (ostream, sep);
449
	    write_char(ostream, sep);
453
	    write_name_key_1 (ostream, nstring);
450
	    write_name_key_1(ostream, nstring);
454
	    sep = '.';
451
	    sep = '.';
455
	}
452
	}
456
	write_char (ostream, ']');
453
	write_char(ostream, ']');
457
	break;
454
	break;
458
    }
455
    }
459
}
456
}
460
 
457
 
461
/*--------------------------------------------------------------------------*/
458
/*--------------------------------------------------------------------------*/
462
 
459
 
463
void
460
void
464
name_key_list_init PROTO_N ((list))
461
name_key_list_init(NameKeyListP list)
465
		   PROTO_T (NameKeyListP list)
-
 
466
{
462
{
467
    list->head = NIL (NameKeyListEntryP);
463
    list->head = NIL(NameKeyListEntryP);
468
}
464
}
469
 
465
 
470
void
466
void
471
name_key_list_add PROTO_N ((list, key))
467
name_key_list_add(NameKeyListP list,			   NameKeyP     key)
472
		  PROTO_T (NameKeyListP list X
-
 
473
			   NameKeyP     key)
-
 
474
{
468
{
475
    NameKeyListEntryP entry;
469
    NameKeyListEntryP entry;
476
 
470
 
477
    for (entry = name_key_list_head (list); entry;
471
    for (entry = name_key_list_head(list); entry;
478
	 entry = name_key_list_entry_next (entry)) {
472
	 entry = name_key_list_entry_next(entry)) {
479
	if (name_key_equal (key, &(entry->key))) {
473
	if (name_key_equal(key, & (entry->key))) {
480
	    name_key_destroy (key);
474
	    name_key_destroy(key);
481
	    return;
475
	    return;
482
	}
476
	}
483
    }
477
    }
484
    entry       = ALLOCATE (NameKeyListEntryT);
478
    entry       = ALLOCATE(NameKeyListEntryT);
485
    entry->next = list->head;
479
    entry->next = list->head;
486
    name_key_assign (&(entry->key), key);
480
    name_key_assign(& (entry->key), key);
487
    list->head  = entry;
481
    list->head  = entry;
488
}
482
}
489
 
483
 
490
NameKeyListEntryP
484
NameKeyListEntryP
491
name_key_list_head PROTO_N ((list))
485
name_key_list_head(NameKeyListP list)
492
		   PROTO_T (NameKeyListP list)
-
 
493
{
486
{
494
    return (list->head);
487
    return(list->head);
495
}
488
}
496
 
489
 
497
NameKeyP
490
NameKeyP
498
name_key_list_entry_key PROTO_N ((entry))
491
name_key_list_entry_key(NameKeyListEntryP entry)
499
			PROTO_T (NameKeyListEntryP entry)
-
 
500
{
492
{
501
    return (&(entry->key));
493
    return(& (entry->key));
502
}
494
}
503
 
495
 
504
NameKeyListEntryP
496
NameKeyListEntryP
505
name_key_list_entry_next PROTO_N ((entry))
497
name_key_list_entry_next(NameKeyListEntryP entry)
506
			 PROTO_T (NameKeyListEntryP entry)
-
 
507
{
498
{
508
    return (entry->next);
499
    return(entry->next);
509
}
500
}
510
 
501
 
511
/*--------------------------------------------------------------------------*/
502
/*--------------------------------------------------------------------------*/
512
 
503
 
513
void
504
void
514
name_key_pair_list_init PROTO_N ((list))
505
name_key_pair_list_init(NameKeyPairListP list)
515
			PROTO_T (NameKeyPairListP list)
-
 
516
{
506
{
517
    list->head = NIL (NameKeyPairListEntryP);
507
    list->head = NIL(NameKeyPairListEntryP);
518
}
508
}
519
 
509
 
520
BoolT
510
BoolT
521
name_key_pair_list_add PROTO_N ((list, from, to))
511
name_key_pair_list_add(NameKeyPairListP list,				NameKeyP         from, 
522
		       PROTO_T (NameKeyPairListP list X
-
 
523
				NameKeyP         from X
-
 
524
				NameKeyP         to)
512
				NameKeyP         to)
525
{
513
{
526
    NameKeyPairListEntryP entry;
514
    NameKeyPairListEntryP entry;
527
 
515
 
528
    for (entry = name_key_pair_list_head (list); entry;
516
    for (entry = name_key_pair_list_head(list); entry;
529
	 entry = name_key_pair_list_entry_next (entry)) {
517
	 entry = name_key_pair_list_entry_next(entry)) {
530
	if (name_key_equal (from, &(entry->from))) {
518
	if (name_key_equal(from, & (entry->from))) {
531
	    return (FALSE);
519
	    return(FALSE);
532
	}
520
	}
533
    }
521
    }
534
    entry       = ALLOCATE (NameKeyPairListEntryT);
522
    entry       = ALLOCATE(NameKeyPairListEntryT);
535
    entry->next = list->head;
523
    entry->next = list->head;
536
    name_key_assign (&(entry->from), from);
524
    name_key_assign(& (entry->from), from);
537
    name_key_assign (&(entry->to), to);
525
    name_key_assign(& (entry->to), to);
538
    list->head  = entry;
526
    list->head  = entry;
539
    return (TRUE);
527
    return(TRUE);
540
}
528
}
541
 
529
 
542
NameKeyPairListEntryP
530
NameKeyPairListEntryP
543
name_key_pair_list_head PROTO_N ((list))
531
name_key_pair_list_head(NameKeyPairListP list)
544
			PROTO_T (NameKeyPairListP list)
-
 
545
{
532
{
546
    return (list->head);
533
    return(list->head);
547
}
534
}
548
 
535
 
549
NameKeyP
536
NameKeyP
550
name_key_pair_list_entry_from PROTO_N ((entry))
537
name_key_pair_list_entry_from(NameKeyPairListEntryP entry)
551
			      PROTO_T (NameKeyPairListEntryP entry)
-
 
552
{
538
{
553
    return (&(entry->from));
539
    return(& (entry->from));
554
}
540
}
555
 
541
 
556
NameKeyP
542
NameKeyP
557
name_key_pair_list_entry_to PROTO_N ((entry))
543
name_key_pair_list_entry_to(NameKeyPairListEntryP entry)
558
			    PROTO_T (NameKeyPairListEntryP entry)
-
 
559
{
544
{
560
    return (&(entry->to));
545
    return(& (entry->to));
561
}
546
}
562
 
547
 
563
NameKeyPairListEntryP
548
NameKeyPairListEntryP
564
name_key_pair_list_entry_next PROTO_N ((entry))
549
name_key_pair_list_entry_next(NameKeyPairListEntryP entry)
565
			      PROTO_T (NameKeyPairListEntryP entry)
-
 
566
{
550
{
567
    return (entry->next);
551
    return(entry->next);
568
}
552
}
569

553

570
/*
554
/*
571
 * Local variables(smf):
555
 * Local variables(smf):
572
 * eval: (include::add-path-entry "../os-interface" "../library")
556
 * eval: (include::add-path-entry "../os-interface" "../library")