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-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 67... Line 97...
67
} EntrySortListT, *EntrySortListP;
97
} EntrySortListT, *EntrySortListP;
68
 
98
 
69
/*--------------------------------------------------------------------------*/
99
/*--------------------------------------------------------------------------*/
70
 
100
 
71
static EntryListEntryP
101
static EntryListEntryP
72
entry_list_find PROTO_N ((list, entry))
102
entry_list_find(EntryListP list, EntryP entry)
73
		PROTO_T (EntryListP list X
-
 
74
			 EntryP     entry)
-
 
75
{
103
{
76
    EntryListEntryP link = list->head;
104
    EntryListEntryP link = list->head;
77
 
105
 
78
    while (link) {
106
    while (link) {
79
	if (link->entry == entry) {
107
	if (link->entry == entry) {
80
	    return (link);
108
	    return(link);
81
	}
109
	}
82
	link = link->next;
110
	link = link->next;
83
    }
111
    }
84
    return (NIL (EntryListEntryP));
112
    return(NIL(EntryListEntryP));
85
}
113
}
86
 
114
 
87
/*--------------------------------------------------------------------------*/
115
/*--------------------------------------------------------------------------*/
88
 
116
 
89
void
117
void
90
entry_list_init PROTO_N ((list))
118
entry_list_init(EntryListP list)
91
		PROTO_T (EntryListP list)
-
 
92
{
119
{
93
    list->head = NIL (EntryListEntryP);
120
    list->head = NIL(EntryListEntryP);
94
    list->tail = &(list->head);
121
    list->tail = &(list->head);
95
}
122
}
96
 
123
 
97
void
124
void
98
entry_list_copy PROTO_N ((to, from))
125
entry_list_copy(EntryListP to, EntryListP from)
99
		PROTO_T (EntryListP to X
-
 
100
			 EntryListP from)
-
 
101
{
126
{
102
    EntryListEntryP ptr;
127
    EntryListEntryP ptr;
103
 
128
 
104
    to->head = NIL (EntryListEntryP);
129
    to->head = NIL(EntryListEntryP);
105
    to->tail = &(to->head);
130
    to->tail = &(to->head);
106
    for (ptr = from->head; ptr; ptr = ptr->next) {
131
    for (ptr = from->head; ptr; ptr = ptr->next) {
107
	entry_list_add (to, ptr->entry);
132
	entry_list_add(to, ptr->entry);
108
    }
133
    }
109
}
134
}
110
 
135
 
111
void
136
void
112
entry_list_add PROTO_N ((list, entry))
137
entry_list_add(EntryListP list, EntryP entry)
113
	       PROTO_T (EntryListP list X
-
 
114
			EntryP     entry)
-
 
115
{
138
{
116
    EntryListEntryP link = ALLOCATE (EntryListEntryT);
139
    EntryListEntryP link = ALLOCATE(EntryListEntryT);
117
 
140
 
118
    link->next    = NIL (EntryListEntryP);
141
    link->next    = NIL(EntryListEntryP);
119
    link->entry   = entry;
142
    link->entry   = entry;
120
    *(list->tail) = link;
143
    *(list->tail) = link;
121
    list->tail    = &(link->next);
144
    list->tail    = &(link->next);
122
}
145
}
123
 
146
 
124
void
147
void
125
entry_list_add_if_missing PROTO_N ((list, entry))
148
entry_list_add_if_missing(EntryListP list, EntryP entry)
126
			  PROTO_T (EntryListP list X
-
 
127
				   EntryP     entry)
-
 
128
{
149
{
129
    if (entry_list_find (list, entry) == NIL (EntryListEntryP)) {
150
    if (entry_list_find(list, entry) == NIL(EntryListEntryP)) {
130
	entry_list_add (list, entry);
151
	entry_list_add(list, entry);
131
    }
152
    }
132
}
153
}
133
 
154
 
134
BoolT
155
BoolT
135
entry_list_contains PROTO_N ((list, entry))
156
entry_list_contains(EntryListP list, EntryP entry)
136
		    PROTO_T (EntryListP list X
-
 
137
			     EntryP     entry)
-
 
138
{
157
{
139
    return (entry_list_find (list, entry) != NIL (EntryListEntryP));
158
    return(entry_list_find(list, entry) != NIL(EntryListEntryP));
140
}
159
}
141
 
160
 
142
BoolT
161
BoolT
143
entry_list_includes PROTO_N ((list1, list2))
162
entry_list_includes(EntryListP list1, EntryListP list2)
144
		    PROTO_T (EntryListP list1 X
-
 
145
			     EntryListP list2)
-
 
146
{
163
{
147
    EntryListEntryP ptr;
164
    EntryListEntryP ptr;
148
 
165
 
149
    for (ptr = list2->head; ptr; ptr = ptr->next) {
166
    for (ptr = list2->head; ptr; ptr = ptr->next) {
150
	if (entry_list_find (list1, ptr->entry) == NIL (EntryListEntryP)) {
167
	if (entry_list_find(list1, ptr->entry) == NIL(EntryListEntryP)) {
151
	    return (FALSE);
168
	    return(FALSE);
152
	}
169
	}
153
    }
170
    }
154
    return (TRUE);
171
    return(TRUE);
155
}
172
}
156
 
173
 
157
void
174
void
158
entry_list_intersection PROTO_N ((to, list1, list2))
175
entry_list_intersection(EntryListP to, EntryListP list1, EntryListP list2)
159
			PROTO_T (EntryListP to X
-
 
160
				 EntryListP list1 X
-
 
161
				 EntryListP list2)
-
 
162
{
176
{
163
    EntryListEntryP ptr;
177
    EntryListEntryP ptr;
164
 
178
 
165
    entry_list_init (to);
179
    entry_list_init(to);
166
    for (ptr = list1->head; ptr; ptr = ptr->next) {
180
    for (ptr = list1->head; ptr; ptr = ptr->next) {
167
	if (entry_list_find (list2, ptr->entry) != NIL (EntryListEntryP)) {
181
	if (entry_list_find(list2, ptr->entry) != NIL(EntryListEntryP)) {
168
	    entry_list_add_if_missing (to, ptr->entry);
182
	    entry_list_add_if_missing(to, ptr->entry);
169
	}
183
	}
170
    }
184
    }
171
}
185
}
172
 
186
 
173
void
187
void
174
entry_list_unlink_used PROTO_N ((to, from))
188
entry_list_unlink_used(EntryListP to, EntryListP from)
175
		       PROTO_T (EntryListP to X
-
 
176
				EntryListP from)
-
 
177
{
189
{
178
    EntryListEntryP ptr;
190
    EntryListEntryP ptr;
179
 
191
 
180
    to->tail = &(to->head);
192
    to->tail = &(to->head);
181
    while ((ptr = *(to->tail)) != NIL (EntryListEntryP)) {
193
    while ((ptr = *(to->tail)) != NIL(EntryListEntryP)) {
182
	if (entry_list_find (from, ptr->entry) != NIL (EntryListEntryP)) {
194
	if (entry_list_find(from, ptr->entry) != NIL(EntryListEntryP)) {
183
	    *(to->tail) = ptr->next;
195
	    *(to->tail) = ptr->next;
184
	    DEALLOCATE (ptr);
196
	    DEALLOCATE(ptr);
185
	} else {
197
	} else {
186
	    to->tail = &(ptr->next);
198
	    to->tail = &(ptr->next);
187
	}
199
	}
188
    }
200
    }
189
}
201
}
190
 
202
 
191
void
203
void
192
entry_list_append PROTO_N ((to, from))
204
entry_list_append(EntryListP to, EntryListP from)
193
		  PROTO_T (EntryListP to X
-
 
194
			   EntryListP from)
-
 
195
{
205
{
196
    EntryListEntryP ptr;
206
    EntryListEntryP ptr;
197
 
207
 
198
    for (ptr = from->head; ptr; ptr = ptr->next) {
208
    for (ptr = from->head; ptr; ptr = ptr->next) {
199
	entry_list_add_if_missing (to, ptr->entry);
209
	entry_list_add_if_missing(to, ptr->entry);
200
    }
210
    }
201
}
211
}
202
 
212
 
203
#ifdef FS_FAST
213
#ifdef FS_FAST
204
#undef entry_list_is_empty
214
#undef entry_list_is_empty
205
#endif /* defined (FS_FAST) */
215
#endif /* defined (FS_FAST) */
206
BoolT
216
BoolT
207
entry_list_is_empty PROTO_N ((list))
217
entry_list_is_empty(EntryListP list)
208
		    PROTO_T (EntryListP list)
-
 
209
{
218
{
210
    return (list->head == NIL (EntryListEntryP));
219
    return(list->head == NIL(EntryListEntryP));
211
}
220
}
212
#ifdef FS_FAST
221
#ifdef FS_FAST
213
#define entry_list_is_empty(e) ((e)->head == NIL (EntryListEntryP))
222
#define entry_list_is_empty(e)	((e)->head == NIL(EntryListEntryP))
214
#endif /* defined (FS_FAST) */
223
#endif /* defined (FS_FAST) */
215
 
224
 
216
void
225
void
217
entry_list_save_state PROTO_N ((list, state))
226
entry_list_save_state(EntryListP list, SaveListP state)
218
		      PROTO_T (EntryListP list X
-
 
219
			       SaveListP  state)
-
 
220
{
227
{
221
    state->last_ref = list->tail;
228
    state->last_ref = list->tail;
222
}
229
}
223
 
230
 
224
void
231
void
225
entry_list_restore_state PROTO_N ((list, state))
232
entry_list_restore_state(EntryListP list, SaveListP state)
226
			 PROTO_T (EntryListP list X
-
 
227
				  SaveListP  state)
-
 
228
{
233
{
229
    EntryListEntryP ptr = *(state->last_ref);
234
    EntryListEntryP ptr = *(state->last_ref);
230
 
235
 
231
    *(state->last_ref) = NIL (EntryListEntryP);
236
    *(state->last_ref) = NIL(EntryListEntryP);
232
    list->tail         = state->last_ref;
237
    list->tail         = state->last_ref;
233
    while (ptr) {
238
    while (ptr) {
234
	EntryListEntryP tmp = ptr;
239
	EntryListEntryP tmp = ptr;
235
 
240
 
236
	ptr = ptr->next;
241
	ptr = ptr->next;
237
	DEALLOCATE (tmp);
242
	DEALLOCATE(tmp);
238
    }
243
    }
239
}
244
}
240
 
245
 
241
void
246
void
242
entry_list_iter PROTO_N ((list, proc, closure))
247
entry_list_iter(EntryListP list, void (*proc)(EntryP, GenericP),
243
		PROTO_T (EntryListP list X
-
 
244
			 void     (*proc) PROTO_S ((EntryP, GenericP)) X
-
 
245
			 GenericP   closure)
248
		GenericP closure)
246
{
249
{
247
    EntryListEntryP ptr;
250
    EntryListEntryP ptr;
248
 
251
 
249
    for (ptr = list->head; ptr; ptr = ptr->next) {
252
    for (ptr = list->head; ptr; ptr = ptr->next) {
250
	(*proc) (ptr->entry, closure);
253
	(*proc)(ptr->entry, closure);
251
    }
254
    }
252
}
255
}
253
 
256
 
254
void
257
void
255
entry_list_iter_table PROTO_N ((list, full, proc, closure))
258
entry_list_iter_table(EntryListP list, BoolT full,
256
		      PROTO_T (EntryListP list X
-
 
257
			       BoolT      full X
-
 
258
			       void     (*proc) PROTO_S ((EntryP, GenericP)) X
259
		      void (*proc)(EntryP, GenericP), GenericP closure)
259
			       GenericP   closure)
-
 
260
{
260
{
261
    EntryListEntryP ptr;
261
    EntryListEntryP ptr;
262
 
262
 
263
    for (ptr = list->head; ptr; ptr = ptr->next) {
263
    for (ptr = list->head; ptr; ptr = ptr->next) {
264
	entry_iter (ptr->entry, full, proc, closure);
264
	entry_iter(ptr->entry, full, proc, closure);
265
    }
265
    }
266
}
266
}
267
 
267
 
268
void
268
void
269
entry_list_destroy PROTO_N ((list))
269
entry_list_destroy(EntryListP list)
270
		   PROTO_T (EntryListP list)
-
 
271
{
270
{
272
    EntryListEntryP ptr = list->head;
271
    EntryListEntryP ptr = list->head;
273
 
272
 
274
    while (ptr) {
273
    while (ptr) {
275
	EntryListEntryP tmp = ptr;
274
	EntryListEntryP tmp = ptr;
276
 
275
 
277
	ptr = ptr->next;
276
	ptr = ptr->next;
278
	DEALLOCATE (tmp);
277
	DEALLOCATE(tmp);
279
    }
278
    }
280
}
279
}
281
 
280
 
282
void
281
void
283
write_entry_list PROTO_N ((ostream, list))
282
write_entry_list(OStreamP ostream, EntryListP list)
284
		 PROTO_T (OStreamP   ostream X
-
 
285
			  EntryListP list)
-
 
286
{
283
{
287
    EntryListEntryP ptr = list->head;
284
    EntryListEntryP ptr = list->head;
288
    CStringP        sep = "";
285
    CStringP        sep = "";
289
 
286
 
290
    while (ptr) {
287
    while (ptr) {
291
	write_cstring (ostream, sep);
288
	write_cstring(ostream, sep);
292
	write_char (ostream, '\'');
289
	write_char(ostream, '\'');
293
	write_key (ostream, entry_key (ptr->entry));
290
	write_key(ostream, entry_key(ptr->entry));
294
	write_char (ostream, '\'');
291
	write_char(ostream, '\'');
295
	if ((ptr = ptr->next) && (ptr->next)) {
292
	if ((ptr = ptr->next) && (ptr->next)) {
296
	    sep = " & ";
293
	    sep = " & ";
297
	} else {
294
	} else {
298
	    sep = ", ";
295
	    sep = ", ";
299
	}
296
	}