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