Subversion Repositories tendra.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

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