BSD 4_3_Net_2 release
[unix-history] / usr / src / contrib / isode / pepsy / pepsy_misc.c
CommitLineData
459ebbd7
C
1/* pepy_misc.c - PE parser (yacc-based) misc routines */
2
3#ifndef lint
4static char *rcsid = "$Header: /f/osi/pepsy/RCS/pepsy_misc.c,v 7.1 91/02/22 09:49:49 mrose Interim $";
5#endif
6
7/*
8 * $Header: /f/osi/pepsy/RCS/pepsy_misc.c,v 7.1 91/02/22 09:49:49 mrose Interim $
9 *
10 *
11 * $Log: pepsy_misc.c,v $
12 * Revision 7.1 91/02/22 09:49:49 mrose
13 * Interim 6.8
14 *
15 * Revision 7.0 90/07/01 19:54:27 mrose
16 * *** empty log message ***
17 *
18 * Revision 7.0 89/11/23 22:11:52 mrose
19 * Release 6.0
20 *
21 */
22
23/*
24 * NOTICE
25 *
26 * Acquisition, use, and distribution of this module and related
27 * materials are subject to the restrictions of a license agreement.
28 * Consult the Preface in the User's Manual for the full terms of
29 * this agreement.
30 *
31 */
32
33
34#include <ctype.h>
35#include <stdio.h>
36#include "pepsydefs.h"
37
38/* \f Oid manipulation */
39
40typedef struct oidlist {
41 OID op_oid;
42 char *op_name;
43 struct oidlist *op_next;
44} oidlist, *OP;
45#define NULLOP ((OP) 0)
46
47typedef struct symtable {
48 char *sym_name;
49 char *sym_module;
50 OID sym_oid;
51 int sym_type;
52 struct symtable *sym_next;
53} symtable, *SYM;
54#define NULLSYM ((SYM)0)
55
56
57static OP myoids;
58static SYM symtab[MAX_TBLS];
59
60
61OID addoid (o1, o2)
62OID o1, o2;
63{
64 OID noid;
65
66 if (o1 == NULLOID || o2 == NULLOID)
67 return NULLOID;
68
69 noid = (OID) calloc (1, sizeof(*noid));
70 if (noid == NULLOID)
71 myyerror ("out of memory (%d needed)", sizeof(*noid));
72
73 noid -> oid_nelem = o1->oid_nelem + o2->oid_nelem;
74 noid -> oid_elements = (unsigned int *) calloc ((unsigned)noid->oid_nelem,
75 sizeof(unsigned int));
76 if (noid -> oid_elements == NULL)
77 myyerror ("out of memory (%d needed)", noid->oid_nelem);
78
79 bcopy ((char *)o1->oid_elements, (char *)noid->oid_elements,
80 o1->oid_nelem * sizeof(unsigned int));
81 bcopy ((char *)o2 -> oid_elements,
82 (char *) &noid -> oid_elements[o1->oid_nelem],
83 o2 -> oid_nelem * sizeof(unsigned int));
84 return noid;
85}
86
87defineoid (name, oid)
88char *name;
89OID oid;
90{
91 register char *p;
92 register OP op;
93
94 if (oid == NULLOID) {
95 myyerror ("Warning Null oid in defineoid");
96 return;
97 }
98 for (op = myoids; op; op = op -> op_next)
99 if (strcmp (op -> op_name, name) == 0) {
100 if (oid_cmp(op->op_oid, oid) != 0) {
101 p = new_string(sprintoid (oid));
102 warning ("OID name clash %s => %s & %s",
103 name, p, sprintoid(op->op_oid));
104 free (p);
105 }
106 else
107 return;
108 }
109 op = (OP) calloc (1, sizeof *op);
110 if (op == NULLOP)
111 myyerror ("out of memory (%d needed)", sizeof(*op));
112 op -> op_oid = oid_cpy(oid);
113 op -> op_name = new_string (name);
114 op -> op_next = myoids;
115 myoids = op;
116}
117
118OID oidlookup (name)
119char *name;
120{
121 OP op;
122
123 for (op = myoids; op; op = op -> op_next)
124 if (strcmp ( name, op->op_name) == 0)
125 return oid_cpy(op -> op_oid);
126
127 warning ("unknown Object Identifier '%s'", name);
128 return NULLOID;
129}
130
131char *oidname (oid)
132OID oid;
133{
134 OP op;
135
136 for (op = myoids; op; op = op -> op_next)
137 if (oid_cmp (op->op_oid, oid) == 0)
138 return op -> op_name;
139
140 return NULLCP;
141}
142
143OID int2oid (n)
144int n;
145{
146 OID noid;
147
148 noid = (OID) calloc(1, sizeof(*noid));
149 if (noid == NULLOID)
150 myyerror ("out of memory (%d needed)", sizeof *noid);
151
152 noid -> oid_elements = (unsigned int *) calloc (1, sizeof(unsigned int));
153 if (noid -> oid_elements == NULL)
154 myyerror ("out of memory (%d needed)", sizeof(unsigned int));
155 noid -> oid_nelem = 1;
156 noid -> oid_elements[0] = n;
157 return noid;
158}
159
160/* \f */
161
162addtable (name, lt, typ)
163char *name;
164int lt;
165int typ; /* Does it allow implicit's to work or not */
166{
167 SYM sp;
168
169 sp = (SYM)calloc (1, sizeof *sp);
170 sp -> sym_name = new_string (name);
171 sp -> sym_next = symtab[lt];
172 sp -> sym_type = typ;
173 symtab[lt] = sp;
174}
175
176addtableref (name, id, lt)
177char *name;
178OID id;
179int lt;
180{
181 SYM sp;
182 char *nm;
183 OID oid;
184
185 nm = name ? new_string (name) : NULLCP;
186 oid = id ? oid_cpy (id) : NULLOID;
187
188 for (sp = symtab[lt]; sp; sp = sp -> sym_next)
189 if (sp -> sym_module == NULLCP && sp -> sym_oid == NULLOID)
190 {
191 sp -> sym_module = nm;
192 sp -> sym_oid = oid;
193 }
194}
195
196print_expimp ()
197{
198 SYM sp;
199 int ind;
200 OID oid;
201 char *p;
202
203 if (sp = symtab[TBL_EXPORT])
204 (void) printf ("\nEXPORTS\n");
205
206 for (ind = 0; sp; sp = sp->sym_next) {
207 if (ind == 0) {
208 (void) putchar('\t');
209 ind = 8;
210 }
211 (void) printf("%s", sp -> sym_name);
212 ind += strlen (sp -> sym_name);
213 if (sp -> sym_next){
214 (void) putchar (',');
215 ind ++;
216 }
217 else
218 (void) putchar (';');
219 if (ind > 72) {
220 (void) putchar ('\n');
221 ind = 0;
222 }
223 else {
224 (void) putchar (' ');
225 ind ++;
226 }
227 }
228 (void) putchar ('\n');
229
230 if (sp = symtab[TBL_IMPORT]) {
231 (void) printf ("\nIMPORTS\n");
232 p = sp -> sym_module;
233 oid = sp -> sym_oid;
234 }
235 for (ind = 0; sp; sp = sp -> sym_next) {
236 if (ind == 0) {
237 (void) putchar ('\t');
238 ind = 8;
239 }
240 (void) printf ("%s", sp -> sym_name);
241 ind += strlen (sp -> sym_name);
242 if (sp -> sym_next) {
243 if (strcmp (p, sp -> sym_next -> sym_module) == 0) {
244 (void) putchar (',');
245 ind ++;
246 if ( ind > 72) {
247 (void) putchar ('\n');
248 ind = 0;
249 }
250 else {
251 (void) putchar (' ');
252 ind ++;
253 }
254 }
255 else {
256 if (ind != 8)
257 (void) printf ("\n\t\t");
258 else
259 (void) putchar ('\t');
260 (void) printf ("FROM %s", p);
261 if (oid)
262 (void) printf (" %s", oidprint (oid));
263 (void) printf ("\n\t");
264 ind = 8;
265 p = sp -> sym_next -> sym_module;
266 oid = sp -> sym_next -> sym_oid;
267 }
268 }
269 else {
270 if (ind != 8)
271 (void) printf ("\n\t\t");
272 else
273 (void) putchar ('\t');
274 (void) printf ("FROM %s", p);
275 if (oid)
276 (void) printf (" %s", oidprint (oid));
277 (void) printf (";\n");
278 }
279 }
280}
281
282check_impexp (yp)
283YP yp;
284{
285 SYM sp;
286
287 for (sp = symtab[TBL_EXPORT]; sp; sp = sp->sym_next)
288 if (strcmp (sp -> sym_name, yp -> yp_identifier) == 0)
289 {
290 yp -> yp_flags |= YP_EXPORTED;
291 break;
292 }
293
294 for (sp = symtab[TBL_IMPORT]; sp; sp = sp -> sym_next)
295 if (strcmp (sp -> sym_name, yp -> yp_identifier) == 0) {
296 if (yp->yp_flags & YP_EXPORTED)
297 myyerror ("Warning: %s imported & exported!", yp->yp_identifier);
298 yp -> yp_module = sp -> sym_module;
299 yp -> yp_modid = sp -> sym_oid;
300/* yp -> yp_flags |= YP_IMPORTED; */
301 }
302}
303static struct oidtbl {
304 char *oid_name;
305 int oid_value;
306} oidtable[] = {
307 /* Top level OIDS */
308 "ccitt", 0,
309 "iso", 1,
310 "joint-iso-ccitt", 2,
311
312 NULL,
313};
314
315initoidtbl ()
316{
317 struct oidtbl *op;
318 OID oid;
319
320 for (op = oidtable; op -> oid_name; op++) {
321 defineoid (op->oid_name, oid = int2oid(op->oid_value));
322 oid_free (oid);
323 }
324}
325
326char *oidprint (oid)
327OID oid;
328{
329 static char buf[BUFSIZ];
330 char *cp;
331 char *p;
332 OID o2;
333 unsigned int *ip;
334 int i;
335
336 if (oid == NULLOID)
337 return "";
338
339 (void) strcpy (buf, "{ ");
340 cp = buf + strlen(buf);
341
342 i = oid->oid_nelem;
343 ip = oid->oid_elements;
344
345 p = oidname (o2 = int2oid((int)*ip));
346 oid_free (o2);
347 if (p) {
348 i --;
349 ip ++;
350 (void) sprintf (cp, "%s ", p);
351 cp += strlen(cp);
352 }
353
354 for (; i > 0; i--) {
355 (void) sprintf (cp, "%d ", *ip++);
356 cp += strlen (cp);
357 }
358
359 (void) strcat (cp, " }");
360 return buf;
361}
362
363/*
364 * look at import list and return any clue found as to handling implicit tags
365 * on that type
366 */
367chkil(id)
368char *id;
369{
370 SYM sy;
371
372 for (sy = symtab[TBL_IMPORT]; sy; sy = sy->sym_next)
373 if (strcmp(sy->sym_name, id) == 0)
374 break;
375 if (sy)
376 return (sy->sym_type);
377
378 return (ER_UNKNOWN);
379
380}