]>
Commit | Line | Data |
---|---|---|
bac41a7b A |
1 | /* |
2 | * compiler/core/define.c - keeps a list of things that have been defined | |
3 | * and provided means for checking if something has been | |
4 | * defined | |
5 | * | |
6 | * MS 92 | |
7 | * Copyright (C) 1991, 1992 Michael Sample | |
8 | * and the University of British Columbia | |
9 | * | |
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. | |
14 | * | |
5a719ac8 | 15 | * $Header: /cvs/Darwin/src/live/Security/SecuritySNACCRuntime/compiler/core/define.c,v 1.1 2001/06/20 21:27:56 dmitch Exp $ |
bac41a7b A |
16 | * $Log: define.c,v $ |
17 | * Revision 1.1 2001/06/20 21:27:56 dmitch | |
18 | * Adding missing snacc compiler files. | |
19 | * | |
20 | * Revision 1.1.1.1 1999/03/16 18:06:46 aram | |
21 | * Originals from SMIME Free Library. | |
22 | * | |
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) | |
28 | * | |
29 | * Revision 1.3 1995/07/25 19:41:21 rj | |
30 | * changed `_' to `-' in file names. | |
31 | * | |
32 | * Revision 1.2 1994/09/01 00:27:38 rj | |
33 | * snacc_config.h removed. | |
34 | * | |
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. | |
37 | * | |
38 | */ | |
39 | ||
40 | #include "asn-incl.h" | |
41 | #include "mem.h" | |
42 | #include "define.h" | |
43 | ||
44 | /* for CompareOids from snacc_util.c*/ | |
45 | int CompareOids PROTO ((OID *oid1, OID *oid2)); | |
46 | ||
47 | ||
48 | /* cmp routine for a null terminated string object type */ | |
49 | int | |
50 | StrObjCmp PARAMS ((s1, s2), | |
51 | void *s1 _AND_ | |
52 | void *s2) | |
53 | { | |
54 | if (strcmp ((char*)s1, (char*) s2) == 0) | |
55 | return TRUE; | |
56 | else | |
57 | return FALSE; | |
58 | } | |
59 | ||
60 | /* cmp routine for a integer object type */ | |
61 | int | |
62 | IntObjCmp PARAMS ((s1, s2), | |
63 | void *s1 _AND_ | |
64 | void *s2) | |
65 | { | |
66 | if (*((int*) s1) == *((int*) s2)) | |
67 | return TRUE; | |
68 | else | |
69 | return FALSE; | |
70 | } | |
71 | ||
72 | ||
73 | /* cmp routine for a OID object type */ | |
74 | int | |
75 | OidObjCmp PARAMS ((o1, o2), | |
76 | void *o1 _AND_ | |
77 | void *o2) | |
78 | { | |
79 | return CompareOids ((OID*)o1, (OID*)o2); | |
80 | } | |
81 | ||
82 | /* special cmp routine - compares the pointers themselves */ | |
83 | int | |
84 | ObjPtrCmp PARAMS ((s1, s2), | |
85 | void *s1 _AND_ | |
86 | void *s2) | |
87 | { | |
88 | if (s1 == s2) | |
89 | return TRUE; | |
90 | else | |
91 | return FALSE; | |
92 | } | |
93 | ||
94 | ||
95 | DefinedObj* | |
96 | NewObjList() | |
97 | { | |
98 | return NULL; | |
99 | } | |
100 | ||
101 | /* | |
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. | |
105 | */ | |
106 | void | |
107 | DefineObj PARAMS ((objListHndl, obj), | |
108 | DefinedObj **objListHndl _AND_ | |
109 | void *obj) | |
110 | { | |
111 | DefinedObj *new; | |
112 | ||
113 | new = MT (DefinedObj); | |
114 | new->obj = obj; | |
115 | ||
116 | /* insert new one at head */ | |
117 | new->next = *objListHndl; | |
118 | *objListHndl = new; | |
119 | ||
120 | } /* DefineObj */ | |
121 | ||
122 | ||
123 | /* | |
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. | |
128 | */ | |
129 | void | |
130 | UndefineObj PARAMS ((objListHndl, obj, cmpRoutine), | |
131 | DefinedObj **objListHndl _AND_ | |
132 | void *obj _AND_ | |
133 | CmpObjsRoutine cmpRoutine) | |
134 | { | |
135 | DefinedObj *objListPtr; | |
136 | DefinedObj **prevHndl; | |
137 | ||
138 | objListPtr = *objListHndl; | |
139 | ||
140 | prevHndl = objListHndl; | |
141 | for ( ; objListPtr != NULL; objListPtr = *prevHndl) | |
142 | { | |
143 | if (cmpRoutine (objListPtr->obj, obj)) | |
144 | { | |
145 | /* found object, now remove it */ | |
146 | *prevHndl = objListPtr->next; | |
147 | Free (objListPtr); | |
148 | } | |
149 | else | |
150 | prevHndl = &objListPtr->next; | |
151 | } | |
152 | ||
153 | } /* UndefineObj */ | |
154 | ||
155 | ||
156 | /* | |
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 | |
161 | */ | |
162 | int | |
163 | ObjIsDefined PARAMS ((objListPtr, obj, cmpRoutine), | |
164 | DefinedObj *objListPtr _AND_ | |
165 | void *obj _AND_ | |
166 | CmpObjsRoutine cmpRoutine) | |
167 | { | |
168 | for ( ; objListPtr != NULL; objListPtr = objListPtr->next) | |
169 | { | |
170 | if (cmpRoutine (objListPtr->obj, obj)) | |
171 | return TRUE; | |
172 | } | |
173 | return FALSE; | |
174 | ||
175 | } /* ObjIsDefined */ | |
176 | ||
177 | /* | |
178 | * Frees the list holding the defined objects. | |
179 | * Does not free the objects. | |
180 | */ | |
181 | void | |
182 | FreeDefinedObjs PARAMS ((objListHndl), | |
183 | DefinedObj **objListHndl) | |
184 | { | |
185 | DefinedObj *dO; | |
186 | DefinedObj *tmpDO; | |
187 | ||
188 | for (dO = *objListHndl; dO != NULL; ) | |
189 | { | |
190 | tmpDO = dO->next; | |
191 | Free (dO); | |
192 | dO = tmpDO; | |
193 | } | |
194 | *objListHndl = NULL; | |
195 | ||
196 | } /* FreeDefinedObjs */ | |
197 | ||
198 | ||
199 | ||
200 | /* | |
201 | * Frees the list holding the defined objects. | |
202 | * Does free the objects. | |
203 | */ | |
204 | void | |
205 | FreeDefinedObjsAndContent PARAMS ((objListHndl), | |
206 | DefinedObj **objListHndl) | |
207 | { | |
208 | DefinedObj *dO; | |
209 | DefinedObj *tmpDO; | |
210 | ||
211 | for (dO = *objListHndl; dO != NULL; ) | |
212 | { | |
213 | tmpDO = dO->next; | |
214 | Free (dO->obj); | |
215 | Free (dO); | |
216 | dO = tmpDO; | |
217 | } | |
218 | *objListHndl = NULL; | |
219 | ||
220 | } /* FreeDefinedObjs */ |