Subversion Repositories tendra.SVN

Rev

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

Rev Author Line No. Line
2 7u83 1
/*
6 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
6 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:-
6 7u83 42
 
2 7u83 43
        (1) Its Recipients shall ensure that this Notice is
44
        reproduced upon any copies or amended versions of it;
6 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;
6 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;
6 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.c --- Identifier table entry ADT.
62
 *
63
 ** Author: Steve Folkes <smf@hermes.mod.uk>
64
 *
65
 *** Commentary:
66
 *
67
 * This file implements the identifier table routines used by SID.
68
 *
69
 *** Change Log:
70
 * $Log: entry.c,v $
71
 * Revision 1.1.1.1  1998/01/17  15:57:45  release
72
 * First version to be checked into rolling release.
73
 *
74
 * Revision 1.2  1994/12/15  09:58:08  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:33  smf
79
 * Initial import of SID 1.8 non shared files.
80
 *
81
**/
82
 
83
/****************************************************************************/
84
 
85
#include "entry.h"
86
#include "action.h"
87
#include "basic.h"
88
#include "gen-errors.h"
89
#include "name.h"
90
#include "rule.h"
91
#include "type.h"
92
 
93
/*--------------------------------------------------------------------------*/
94
 
95
#ifdef FS_FAST
96
#undef entry_traced
97
#endif /* defined (FS_FAST) */
98
static void
6 7u83 99
entry_traced(EntryP entry)
2 7u83 100
{
101
    entry->traced = TRUE;
102
}
103
#ifdef FS_FAST
6 7u83 104
#define entry_traced(e)	((e)->traced = TRUE)
2 7u83 105
#endif /* defined (FS_FAST) */
106
 
107
/*--------------------------------------------------------------------------*/
108
 
109
EntryP
6 7u83 110
entry_create_from_string(NStringP key, unsigned number, EntryTypeT type)
2 7u83 111
{
6 7u83 112
    EntryP entry = ALLOCATE(EntryT);
2 7u83 113
 
6 7u83 114
    entry->next   = NIL(EntryP);
115
    key_init_from_string(entry_key(entry), key, number);
2 7u83 116
    entry->mapped = FALSE;
6 7u83 117
    nstring_init(&(entry->mapping));
2 7u83 118
    entry->type   = type;
6 7u83 119
    entry->name   = name_create();
2 7u83 120
    entry->traced = FALSE;
6 7u83 121
    return(entry);
2 7u83 122
}
123
 
124
EntryP
6 7u83 125
entry_create_from_number(unsigned key, EntryTypeT type, BoolT traced,
126
			 EntryP next)
2 7u83 127
{
6 7u83 128
    EntryP entry = ALLOCATE(EntryT);
2 7u83 129
 
130
    entry->next   = next;
6 7u83 131
    key_init_from_number(entry_key(entry), key);
2 7u83 132
    entry->mapped = FALSE;
6 7u83 133
    nstring_init(&(entry->mapping));
2 7u83 134
    entry->type   = type;
6 7u83 135
    entry->name   = name_create();
2 7u83 136
    entry->traced = traced;
6 7u83 137
    return(entry);
2 7u83 138
}
139
 
140
#ifdef FS_FAST
141
#undef entry_set_basic
142
#endif /* defined (FS_FAST) */
143
void
6 7u83 144
entry_set_basic(EntryP entry, BasicP basic)
2 7u83 145
{
6 7u83 146
    ASSERT(entry_is_basic(entry));
2 7u83 147
    entry->u.basic = basic;
148
}
149
#ifdef FS_FAST
6 7u83 150
#define entry_set_basic(e, b)	((e)->u.basic = (b))
2 7u83 151
#endif /* defined (FS_FAST) */
152
 
153
#ifdef FS_FAST
154
#undef entry_set_rule
155
#endif /* defined (FS_FAST) */
156
void
6 7u83 157
entry_set_rule(EntryP entry, RuleP rule)
2 7u83 158
{
6 7u83 159
    ASSERT(entry_is_rule(entry));
2 7u83 160
    entry->u.rule = rule;
161
}
162
#ifdef FS_FAST
6 7u83 163
#define entry_set_rule(e, r)	((e)->u.rule = (r))
2 7u83 164
#endif /* defined (FS_FAST) */
165
 
166
#ifdef FS_FAST
167
#undef entry_set_action
168
#endif /* defined (FS_FAST) */
169
void
6 7u83 170
entry_set_action(EntryP entry, ActionP action)
2 7u83 171
{
6 7u83 172
    ASSERT(entry_is_action(entry));
2 7u83 173
    entry->u.action = action;
174
}
175
#ifdef FS_FAST
6 7u83 176
#define entry_set_action(e, a)	((e)->u.action = (a))
2 7u83 177
#endif /* defined (FS_FAST) */
178
 
179
#ifdef FS_FAST
180
#undef entry_set_type
181
#endif /* defined (FS_FAST) */
182
void
6 7u83 183
entry_set_type(EntryP entry, TypeP type)
2 7u83 184
{
6 7u83 185
    ASSERT(entry_is_type(entry));
2 7u83 186
    entry->u.type = type;
187
}
188
#ifdef FS_FAST
6 7u83 189
#define entry_set_type(e, t)	((e)->u.type = (t))
2 7u83 190
#endif /* defined (FS_FAST) */
191
 
192
#ifdef FS_FAST
193
#undef entry_set_non_local
194
#endif /* defined (FS_FAST) */
195
void
6 7u83 196
entry_set_non_local(EntryP entry, EntryP type)
2 7u83 197
{
6 7u83 198
    ASSERT(entry_is_non_local(entry));
2 7u83 199
    entry->u.non_local = type;
200
}
201
#ifdef FS_FAST
6 7u83 202
#define entry_set_non_local(e, t)	((e)->u.non_local = (t))
2 7u83 203
#endif /* defined (FS_FAST) */
204
 
205
#ifdef FS_FAST
206
#undef entry_next
207
#endif /* defined (FS_FAST) */
208
EntryP
6 7u83 209
entry_next(EntryP entry)
2 7u83 210
{
6 7u83 211
    return(entry->next);
2 7u83 212
}
213
#ifdef FS_FAST
6 7u83 214
#define entry_next(e)	((e)->next)
2 7u83 215
#endif /* defined (FS_FAST) */
216
 
217
#ifdef FS_FAST
218
#undef entry_next_ref
219
#endif /* defined (FS_FAST) */
220
EntryP *
6 7u83 221
entry_next_ref(EntryP entry)
2 7u83 222
{
6 7u83 223
    return(&(entry->next));
2 7u83 224
}
225
#ifdef FS_FAST
6 7u83 226
#define entry_next_ref(e)	(&((e)->next))
2 7u83 227
#endif /* defined (FS_FAST) */
228
 
229
#ifdef FS_FAST
230
#undef entry_key
231
#endif /* defined (FS_FAST) */
232
KeyP
6 7u83 233
entry_key(EntryP entry)
2 7u83 234
{
6 7u83 235
    return(&(entry->key));
2 7u83 236
}
237
#ifdef FS_FAST
6 7u83 238
#define entry_key(e)	(&((e)->key))
2 7u83 239
#endif /* defined (FS_FAST) */
240
 
241
#ifdef FS_FAST
242
#undef entry_type
243
#endif /* defined (FS_FAST) */
244
EntryTypeT
6 7u83 245
entry_type(EntryP entry)
2 7u83 246
{
6 7u83 247
    return(entry->type);
2 7u83 248
}
249
#ifdef FS_FAST
6 7u83 250
#define entry_type(e)	((e)->type)
2 7u83 251
#endif /* defined (FS_FAST) */
252
 
253
#ifdef FS_FAST
254
#undef entry_change_type
255
#endif /* defined (FS_FAST) */
256
void
6 7u83 257
entry_change_type(EntryP entry, EntryTypeT type)
2 7u83 258
{
259
    entry->type = type;
260
}
261
#ifdef FS_FAST
6 7u83 262
#define entry_change_type(e, t)	((e)->type = (t))
2 7u83 263
#endif /* defined (FS_FAST) */
264
 
265
#ifdef FS_FAST
266
#undef entry_is_basic
267
#endif /* defined (FS_FAST) */
268
BoolT
6 7u83 269
entry_is_basic(EntryP entry)
2 7u83 270
{
6 7u83 271
    return(entry->type == ET_BASIC);
2 7u83 272
}
273
#ifdef FS_FAST
6 7u83 274
#define entry_is_basic(e)	((e)->type == ET_BASIC)
2 7u83 275
#endif /* defined (FS_FAST) */
276
 
277
#ifdef FS_FAST
278
#undef entry_is_action
279
#endif /* defined (FS_FAST) */
280
BoolT
6 7u83 281
entry_is_action(EntryP entry)
2 7u83 282
{
6 7u83 283
    return(entry->type == ET_ACTION);
2 7u83 284
}
285
#ifdef FS_FAST
6 7u83 286
#define entry_is_action(e)	((e)->type == ET_ACTION)
2 7u83 287
#endif /* defined (FS_FAST) */
288
 
289
#ifdef FS_FAST
290
#undef entry_is_rule
291
#endif /* defined (FS_FAST) */
292
BoolT
6 7u83 293
entry_is_rule(EntryP entry)
2 7u83 294
{
6 7u83 295
    return(entry->type == ET_RULE);
2 7u83 296
}
297
#ifdef FS_FAST
6 7u83 298
#define entry_is_rule(e)	((e)->type == ET_RULE)
2 7u83 299
#endif /* defined (FS_FAST) */
300
 
301
#ifdef FS_FAST
302
#undef entry_is_type
303
#endif /* defined (FS_FAST) */
304
BoolT
6 7u83 305
entry_is_type(EntryP entry)
2 7u83 306
{
6 7u83 307
    return(entry->type == ET_TYPE);
2 7u83 308
}
309
#ifdef FS_FAST
6 7u83 310
#define entry_is_type(e)	((e)->type == ET_TYPE)
2 7u83 311
#endif /* defined (FS_FAST) */
312
 
313
#ifdef FS_FAST
314
#undef entry_is_non_local
315
#endif /* defined (FS_FAST) */
316
BoolT
6 7u83 317
entry_is_non_local(EntryP entry)
2 7u83 318
{
6 7u83 319
    return(entry->type == ET_NON_LOCAL);
2 7u83 320
}
321
#ifdef FS_FAST
6 7u83 322
#define entry_is_non_local(e)	((e)->type == ET_NON_LOCAL)
2 7u83 323
#endif /* defined (FS_FAST) */
324
 
325
#ifdef FS_FAST
326
#undef entry_get_basic
327
#endif /* defined (FS_FAST) */
328
BasicP
6 7u83 329
entry_get_basic(EntryP entry)
2 7u83 330
{
6 7u83 331
    ASSERT(entry_is_basic(entry));
332
    return(entry->u.basic);
2 7u83 333
}
334
#ifdef FS_FAST
6 7u83 335
#define entry_get_basic(e)	((e)->u.basic)
2 7u83 336
#endif /* defined (FS_FAST) */
337
 
338
#ifdef FS_FAST
339
#undef entry_get_action
340
#endif /* defined (FS_FAST) */
341
ActionP
6 7u83 342
entry_get_action(EntryP entry)
2 7u83 343
{
6 7u83 344
    ASSERT(entry_is_action(entry));
345
    return(entry->u.action);
2 7u83 346
}
347
#ifdef FS_FAST
6 7u83 348
#define entry_get_action(e)	((e)->u.action)
2 7u83 349
#endif /* defined (FS_FAST) */
350
 
351
#ifdef FS_FAST
352
#undef entry_get_rule
353
#endif /* defined (FS_FAST) */
354
RuleP
6 7u83 355
entry_get_rule(EntryP entry)
2 7u83 356
{
6 7u83 357
    ASSERT(entry_is_rule(entry));
358
    return(entry->u.rule);
2 7u83 359
}
360
#ifdef FS_FAST
6 7u83 361
#define entry_get_rule(e)	((e)->u.rule)
2 7u83 362
#endif /* defined (FS_FAST) */
363
 
364
#ifdef FS_FAST
365
#undef entry_get_name
366
#endif /* defined (FS_FAST) */
367
NameP
6 7u83 368
entry_get_name(EntryP entry)
2 7u83 369
{
6 7u83 370
    return(entry->name);
2 7u83 371
}
372
#ifdef FS_FAST
6 7u83 373
#define entry_get_name(e)	((e)->name)
2 7u83 374
#endif /* defined (FS_FAST) */
375
 
376
#ifdef FS_FAST
377
#undef entry_get_type
378
#endif /* defined (FS_FAST) */
379
TypeP
6 7u83 380
entry_get_type(EntryP entry)
2 7u83 381
{
6 7u83 382
    ASSERT(entry_is_type(entry));
383
    return(entry->u.type);
2 7u83 384
}
385
#ifdef FS_FAST
6 7u83 386
#define entry_get_type(e)	((e)->u.type)
2 7u83 387
#endif /* defined (FS_FAST) */
388
 
389
#ifdef FS_FAST
390
#undef entry_get_non_local
391
#endif /* defined (FS_FAST) */
392
EntryP
6 7u83 393
entry_get_non_local(EntryP entry)
2 7u83 394
{
6 7u83 395
    ASSERT(entry_is_non_local(entry));
396
    return(entry->u.non_local);
2 7u83 397
}
398
#ifdef FS_FAST
6 7u83 399
#define entry_get_non_local(e)	((e)->u.non_local)
2 7u83 400
#endif /* defined (FS_FAST) */
401
 
402
void
6 7u83 403
entry_set_mapping(EntryP entry, NStringP mapping)
2 7u83 404
{
405
    if (entry->mapped) {
6 7u83 406
	nstring_destroy(&(entry->mapping));
2 7u83 407
    }
6 7u83 408
    nstring_assign(&(entry->mapping), mapping);
2 7u83 409
    entry->mapped = TRUE;
410
}
411
 
412
NStringP
6 7u83 413
entry_get_mapping(EntryP entry)
2 7u83 414
{
415
    if (entry->mapped) {
6 7u83 416
	return(&(entry->mapping));
2 7u83 417
    }
6 7u83 418
    return(NIL(NStringP));
2 7u83 419
}
420
 
421
void
6 7u83 422
entry_iter(EntryP entry, BoolT full, void (*proc)(EntryP, GenericP),
423
	   GenericP closure)
2 7u83 424
{
6 7u83 425
    if (!entry_is_traced(entry)) {
426
	entry_traced(entry);
2 7u83 427
	if (proc) {
6 7u83 428
	   (*proc)(entry, closure);
2 7u83 429
	}
6 7u83 430
	switch (entry_type(entry))EXHAUSTIVE {
2 7u83 431
	  case ET_RULE: {
6 7u83 432
	      RuleP rule = entry_get_rule(entry);
2 7u83 433
 
6 7u83 434
	      rule_iter_for_table(rule, full, proc, closure);
2 7u83 435
	  }
436
	    break;
437
	  case ET_ACTION: {
6 7u83 438
	      ActionP action = entry_get_action(entry);
2 7u83 439
 
6 7u83 440
	      action_iter_for_table(action, full, proc, closure);
2 7u83 441
	  }
442
	    break;
443
	  case ET_BASIC: {
6 7u83 444
	      BasicP basic = entry_get_basic(entry);
2 7u83 445
 
6 7u83 446
	      basic_iter_for_table(basic, full, proc, closure);
2 7u83 447
	  }
448
	    break;
449
	  case ET_NON_LOCAL:
450
	    if (full) {
6 7u83 451
		entry_iter(entry_get_non_local(entry), TRUE, proc, closure);
2 7u83 452
	    }
453
	    break;
454
	  case ET_NAME:
455
	  case ET_TYPE:
456
	  case ET_RENAME:
457
	    /*NOTHING*/
458
	    break;
459
	  case ET_PREDICATE:
460
	    UNREACHED;
461
	}
462
    }
463
}
464
 
465
#ifdef FS_FAST
466
#undef entry_not_traced
467
#endif /* defined (FS_FAST) */
468
void
6 7u83 469
entry_not_traced(EntryP entry)
2 7u83 470
{
471
    entry->traced = FALSE;
472
}
473
#ifdef FS_FAST
6 7u83 474
#define entry_not_traced(e)	((e)->traced = FALSE)
2 7u83 475
#endif /* defined (FS_FAST) */
476
 
477
#ifdef FS_FAST
478
#undef entry_is_traced
479
#endif /* defined (FS_FAST) */
480
BoolT
6 7u83 481
entry_is_traced(EntryP entry)
2 7u83 482
{
6 7u83 483
    return(entry->traced);
2 7u83 484
}
485
#ifdef FS_FAST
6 7u83 486
#define entry_is_traced(e)	((e)->traced)
2 7u83 487
#endif /* defined (FS_FAST) */
488
 
489
/*
490
 * Local variables(smf):
491
 * eval: (include::add-path-entry "../os-interface" "../library")
492
 * eval: (include::add-path-entry "../generated")
493
 * end:
494
**/