2 * compiler/core/define.c - keeps a list of things that have been defined
3 * and provided means for checking if something has been
7 * Copyright (C) 1991, 1992 Michael Sample
8 * and the University of British Columbia
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * $Header: /cvs/Darwin/Security/SecuritySNACCRuntime/compiler/core/define.c,v 1.1 2001/06/20 21:27:56 dmitch Exp $
17 * Revision 1.1 2001/06/20 21:27:56 dmitch
18 * Adding missing snacc compiler files.
20 * Revision 1.1.1.1 1999/03/16 18:06:46 aram
21 * Originals from SMIME Free Library.
23 * Revision 1.4 1997/10/10 13:43:15 wan
24 * Corrected bug in generic table decoder wrt. indefinite length elements
25 * Corrected compiler access to freed memory (bug reported by Markku Savela)
26 * Broke asnwish.c into two pieces so that one can build ones on wish
27 * Added beredit tool (based on asnwish, allowes to edit BER messages)
29 * Revision 1.3 1995/07/25 19:41:21 rj
30 * changed `_' to `-' in file names.
32 * Revision 1.2 1994/09/01 00:27:38 rj
33 * snacc_config.h removed.
35 * Revision 1.1 1994/08/28 09:48:58 rj
36 * first check-in. for a list of changes to the snacc-1.1 distribution please refer to the ChangeLog.
44 /* for CompareOids from snacc_util.c*/
45 int CompareOids
PROTO ((OID
*oid1
, OID
*oid2
));
48 /* cmp routine for a null terminated string object type */
50 StrObjCmp
PARAMS ((s1
, s2
),
54 if (strcmp ((char*)s1
, (char*) s2
) == 0)
60 /* cmp routine for a integer object type */
62 IntObjCmp
PARAMS ((s1
, s2
),
66 if (*((int*) s1
) == *((int*) s2
))
73 /* cmp routine for a OID object type */
75 OidObjCmp
PARAMS ((o1
, o2
),
79 return CompareOids ((OID
*)o1
, (OID
*)o2
);
82 /* special cmp routine - compares the pointers themselves */
84 ObjPtrCmp
PARAMS ((s1
, s2
),
102 * puts the given object into the give object list
103 * does not check for duplicates - you should do that
104 * before calling this - if you care.
107 DefineObj
PARAMS ((objListHndl
, obj
),
108 DefinedObj
**objListHndl _AND_
113 new = MT (DefinedObj
);
116 /* insert new one at head */
117 new->next
= *objListHndl
;
124 * removes the first identical object from the list
125 * - if you are allowing duplicates use another routine.
126 * this only removes the first for efficiency reasons - all
127 * current usage of the DefineObj stuff does not allow duplicates.
130 UndefineObj
PARAMS ((objListHndl
, obj
, cmpRoutine
),
131 DefinedObj
**objListHndl _AND_
133 CmpObjsRoutine cmpRoutine
)
135 DefinedObj
*objListPtr
;
136 DefinedObj
**prevHndl
;
138 objListPtr
= *objListHndl
;
140 prevHndl
= objListHndl
;
141 for ( ; objListPtr
!= NULL
; objListPtr
= *prevHndl
)
143 if (cmpRoutine (objListPtr
->obj
, obj
))
145 /* found object, now remove it */
146 *prevHndl
= objListPtr
->next
;
150 prevHndl
= &objListPtr
->next
;
157 * given an object list, an object and an object comparison routine,
158 * ObjIsDefined returns non-zero if the given object is already in
159 * the object list. The comparison routine should take two objects and
160 * return non-zero if the objects are equivalent
163 ObjIsDefined
PARAMS ((objListPtr
, obj
, cmpRoutine
),
164 DefinedObj
*objListPtr _AND_
166 CmpObjsRoutine cmpRoutine
)
168 for ( ; objListPtr
!= NULL
; objListPtr
= objListPtr
->next
)
170 if (cmpRoutine (objListPtr
->obj
, obj
))
178 * Frees the list holding the defined objects.
179 * Does not free the objects.
182 FreeDefinedObjs
PARAMS ((objListHndl
),
183 DefinedObj
**objListHndl
)
188 for (dO
= *objListHndl
; dO
!= NULL
; )
196 } /* FreeDefinedObjs */
201 * Frees the list holding the defined objects.
202 * Does free the objects.
205 FreeDefinedObjsAndContent
PARAMS ((objListHndl
),
206 DefinedObj
**objListHndl
)
211 for (dO
= *objListHndl
; dO
!= NULL
; )
220 } /* FreeDefinedObjs */