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