Subversion Repositories tendra.SVN

Rev

Rev 2 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
2
    		 Crown Copyright (c) 1997
3
 
4
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
12
 
13
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
15
 
16
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
19
 
20
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
22
        these conditions;
23
 
24
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
27
        it may be put.
28
*/
29
 
30
 
31
/*** entry-list.c --- Identifier table entry list ADT.
32
 *
33
 ** Author: Steve Folkes <smf@hermes.mod.uk>
34
 *
35
 *** Commentary:
36
 *
37
 * This file implements the SID table entry list routines.
38
 *
39
 *** Change Log:
40
 * $Log: entry-list.c,v $
41
 * Revision 1.1.1.1  1998/01/17  15:57:46  release
42
 * First version to be checked into rolling release.
43
 *
44
 * Revision 1.2  1994/12/15  09:58:04  smf
45
 * Brought into line with OSSG C Coding Standards Document, as per
46
 * "CR94_178.sid+tld-update".
47
 *
48
 * Revision 1.1.1.1  1994/07/25  16:04:32  smf
49
 * Initial import of SID 1.8 non shared files.
50
 *
51
**/
52
 
53
/****************************************************************************/
54
 
55
#include "entry-list.h"
56
#include "action.h"
57
#include "basic.h"
58
#include "name.h"
59
#include "rule.h"
60
#include "type.h"
61
 
62
/*--------------------------------------------------------------------------*/
63
 
64
typedef struct EntrySortListT {
65
    EntryListEntryP		head;
66
    EntryListEntryP	       *tail;
67
} EntrySortListT, *EntrySortListP;
68
 
69
/*--------------------------------------------------------------------------*/
70
 
71
static EntryListEntryP
72
entry_list_find PROTO_N ((list, entry))
73
		PROTO_T (EntryListP list X
74
			 EntryP     entry)
75
{
76
    EntryListEntryP link = list->head;
77
 
78
    while (link) {
79
	if (link->entry == entry) {
80
	    return (link);
81
	}
82
	link = link->next;
83
    }
84
    return (NIL (EntryListEntryP));
85
}
86
 
87
/*--------------------------------------------------------------------------*/
88
 
89
void
90
entry_list_init PROTO_N ((list))
91
		PROTO_T (EntryListP list)
92
{
93
    list->head = NIL (EntryListEntryP);
94
    list->tail = &(list->head);
95
}
96
 
97
void
98
entry_list_copy PROTO_N ((to, from))
99
		PROTO_T (EntryListP to X
100
			 EntryListP from)
101
{
102
    EntryListEntryP ptr;
103
 
104
    to->head = NIL (EntryListEntryP);
105
    to->tail = &(to->head);
106
    for (ptr = from->head; ptr; ptr = ptr->next) {
107
	entry_list_add (to, ptr->entry);
108
    }
109
}
110
 
111
void
112
entry_list_add PROTO_N ((list, entry))
113
	       PROTO_T (EntryListP list X
114
			EntryP     entry)
115
{
116
    EntryListEntryP link = ALLOCATE (EntryListEntryT);
117
 
118
    link->next    = NIL (EntryListEntryP);
119
    link->entry   = entry;
120
    *(list->tail) = link;
121
    list->tail    = &(link->next);
122
}
123
 
124
void
125
entry_list_add_if_missing PROTO_N ((list, entry))
126
			  PROTO_T (EntryListP list X
127
				   EntryP     entry)
128
{
129
    if (entry_list_find (list, entry) == NIL (EntryListEntryP)) {
130
	entry_list_add (list, entry);
131
    }
132
}
133
 
134
BoolT
135
entry_list_contains PROTO_N ((list, entry))
136
		    PROTO_T (EntryListP list X
137
			     EntryP     entry)
138
{
139
    return (entry_list_find (list, entry) != NIL (EntryListEntryP));
140
}
141
 
142
BoolT
143
entry_list_includes PROTO_N ((list1, list2))
144
		    PROTO_T (EntryListP list1 X
145
			     EntryListP list2)
146
{
147
    EntryListEntryP ptr;
148
 
149
    for (ptr = list2->head; ptr; ptr = ptr->next) {
150
	if (entry_list_find (list1, ptr->entry) == NIL (EntryListEntryP)) {
151
	    return (FALSE);
152
	}
153
    }
154
    return (TRUE);
155
}
156
 
157
void
158
entry_list_intersection PROTO_N ((to, list1, list2))
159
			PROTO_T (EntryListP to X
160
				 EntryListP list1 X
161
				 EntryListP list2)
162
{
163
    EntryListEntryP ptr;
164
 
165
    entry_list_init (to);
166
    for (ptr = list1->head; ptr; ptr = ptr->next) {
167
	if (entry_list_find (list2, ptr->entry) != NIL (EntryListEntryP)) {
168
	    entry_list_add_if_missing (to, ptr->entry);
169
	}
170
    }
171
}
172
 
173
void
174
entry_list_unlink_used PROTO_N ((to, from))
175
		       PROTO_T (EntryListP to X
176
				EntryListP from)
177
{
178
    EntryListEntryP ptr;
179
 
180
    to->tail = &(to->head);
181
    while ((ptr = *(to->tail)) != NIL (EntryListEntryP)) {
182
	if (entry_list_find (from, ptr->entry) != NIL (EntryListEntryP)) {
183
	    *(to->tail) = ptr->next;
184
	    DEALLOCATE (ptr);
185
	} else {
186
	    to->tail = &(ptr->next);
187
	}
188
    }
189
}
190
 
191
void
192
entry_list_append PROTO_N ((to, from))
193
		  PROTO_T (EntryListP to X
194
			   EntryListP from)
195
{
196
    EntryListEntryP ptr;
197
 
198
    for (ptr = from->head; ptr; ptr = ptr->next) {
199
	entry_list_add_if_missing (to, ptr->entry);
200
    }
201
}
202
 
203
#ifdef FS_FAST
204
#undef entry_list_is_empty
205
#endif /* defined (FS_FAST) */
206
BoolT
207
entry_list_is_empty PROTO_N ((list))
208
		    PROTO_T (EntryListP list)
209
{
210
    return (list->head == NIL (EntryListEntryP));
211
}
212
#ifdef FS_FAST
213
#define entry_list_is_empty(e) ((e)->head == NIL (EntryListEntryP))
214
#endif /* defined (FS_FAST) */
215
 
216
void
217
entry_list_save_state PROTO_N ((list, state))
218
		      PROTO_T (EntryListP list X
219
			       SaveListP  state)
220
{
221
    state->last_ref = list->tail;
222
}
223
 
224
void
225
entry_list_restore_state PROTO_N ((list, state))
226
			 PROTO_T (EntryListP list X
227
				  SaveListP  state)
228
{
229
    EntryListEntryP ptr = *(state->last_ref);
230
 
231
    *(state->last_ref) = NIL (EntryListEntryP);
232
    list->tail         = state->last_ref;
233
    while (ptr) {
234
	EntryListEntryP tmp = ptr;
235
 
236
	ptr = ptr->next;
237
	DEALLOCATE (tmp);
238
    }
239
}
240
 
241
void
242
entry_list_iter PROTO_N ((list, proc, closure))
243
		PROTO_T (EntryListP list X
244
			 void     (*proc) PROTO_S ((EntryP, GenericP)) X
245
			 GenericP   closure)
246
{
247
    EntryListEntryP ptr;
248
 
249
    for (ptr = list->head; ptr; ptr = ptr->next) {
250
	(*proc) (ptr->entry, closure);
251
    }
252
}
253
 
254
void
255
entry_list_iter_table PROTO_N ((list, full, proc, closure))
256
		      PROTO_T (EntryListP list X
257
			       BoolT      full X
258
			       void     (*proc) PROTO_S ((EntryP, GenericP)) X
259
			       GenericP   closure)
260
{
261
    EntryListEntryP ptr;
262
 
263
    for (ptr = list->head; ptr; ptr = ptr->next) {
264
	entry_iter (ptr->entry, full, proc, closure);
265
    }
266
}
267
 
268
void
269
entry_list_destroy PROTO_N ((list))
270
		   PROTO_T (EntryListP list)
271
{
272
    EntryListEntryP ptr = list->head;
273
 
274
    while (ptr) {
275
	EntryListEntryP tmp = ptr;
276
 
277
	ptr = ptr->next;
278
	DEALLOCATE (tmp);
279
    }
280
}
281
 
282
void
283
write_entry_list PROTO_N ((ostream, list))
284
		 PROTO_T (OStreamP   ostream X
285
			  EntryListP list)
286
{
287
    EntryListEntryP ptr = list->head;
288
    CStringP        sep = "";
289
 
290
    while (ptr) {
291
	write_cstring (ostream, sep);
292
	write_char (ostream, '\'');
293
	write_key (ostream, entry_key (ptr->entry));
294
	write_char (ostream, '\'');
295
	if ((ptr = ptr->next) && (ptr->next)) {
296
	    sep = " & ";
297
	} else {
298
	    sep = ", ";
299
	}
300
    }
301
}
302
 
303
/*
304
 * Local variables(smf):
305
 * eval: (include::add-path-entry "../os-interface" "../library")
306
 * eval: (include::add-path-entry "../generated")
307
 * end:
308
**/