|
|
1.1 ! root 1: /* pepy_misc.c - PE parser (yacc-based) misc routines */ ! 2: ! 3: #ifndef lint ! 4: static char *rcsid = "$Header: /f/osi/pepsy/RCS/pepsy_misc.c,v 7.0 90/07/01 19:54:27 mrose Exp $"; ! 5: #endif ! 6: ! 7: /* ! 8: * $Header: /f/osi/pepsy/RCS/pepsy_misc.c,v 7.0 90/07/01 19:54:27 mrose Exp $ ! 9: * ! 10: * ! 11: * $Log: pepsy_misc.c,v $ ! 12: * Revision 7.0 90/07/01 19:54:27 mrose ! 13: * *** empty log message *** ! 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 "pepsydefs.h" ! 34: ! 35: /* Oid manipulation */ ! 36: ! 37: typedef struct oidlist { ! 38: OID op_oid; ! 39: char *op_name; ! 40: struct oidlist *op_next; ! 41: } oidlist, *OP; ! 42: #define NULLOP ((OP) 0) ! 43: ! 44: typedef 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: ! 53: static OP myoids; ! 54: static SYM symtab[MAX_TBLS]; ! 55: ! 56: ! 57: OID addoid (o1, o2) ! 58: OID 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: ! 83: defineoid (name, oid) ! 84: char *name; ! 85: OID 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: ! 114: OID oidlookup (name) ! 115: char *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: ! 127: char *oidname (oid) ! 128: OID 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: ! 139: OID int2oid (n) ! 140: int 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: /* */ ! 157: ! 158: addtable (name, lt) ! 159: char *name; ! 160: int 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: ! 170: addtableref (name, id, lt) ! 171: char *name; ! 172: OID id; ! 173: int 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: ! 190: print_expimp () ! 191: { ! 192: SYM sp; ! 193: int ind; ! 194: OID oid; ! 195: char *p; ! 196: ! 197: if (sp = symtab[TBL_EXPORT]) ! 198: (void) printf ("\nEXPORTS\n"); ! 199: ! 200: for (ind = 0; sp; sp = sp->sym_next) { ! 201: if (ind == 0) { ! 202: (void) putchar('\t'); ! 203: ind = 8; ! 204: } ! 205: (void) printf("%s", sp -> sym_name); ! 206: ind += strlen (sp -> sym_name); ! 207: if (sp -> sym_next){ ! 208: (void) putchar (','); ! 209: ind ++; ! 210: } ! 211: else ! 212: (void) putchar (';'); ! 213: if (ind > 72) { ! 214: (void) putchar ('\n'); ! 215: ind = 0; ! 216: } ! 217: else { ! 218: (void) putchar (' '); ! 219: ind ++; ! 220: } ! 221: } ! 222: (void) putchar ('\n'); ! 223: ! 224: if (sp = symtab[TBL_IMPORT]) { ! 225: (void) 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: (void) putchar ('\t'); ! 232: ind = 8; ! 233: } ! 234: (void) 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: (void) putchar (','); ! 239: ind ++; ! 240: if ( ind > 72) { ! 241: (void) putchar ('\n'); ! 242: ind = 0; ! 243: } ! 244: else { ! 245: (void) putchar (' '); ! 246: ind ++; ! 247: } ! 248: } ! 249: else { ! 250: if (ind != 8) ! 251: (void) printf ("\n\t\t"); ! 252: else ! 253: (void) putchar ('\t'); ! 254: (void) printf ("FROM %s", p); ! 255: if (oid) ! 256: (void) printf (" %s", oidprint (oid)); ! 257: (void) printf ("\n\t"); ! 258: ind = 8; ! 259: p = sp -> sym_next -> sym_module; ! 260: oid = sp -> sym_next -> sym_oid; ! 261: } ! 262: } ! 263: else { ! 264: if (ind != 8) ! 265: (void) printf ("\n\t\t"); ! 266: else ! 267: (void) putchar ('\t'); ! 268: (void) printf ("FROM %s", p); ! 269: if (oid) ! 270: (void) printf (" %s", oidprint (oid)); ! 271: (void) printf (";\n"); ! 272: } ! 273: } ! 274: } ! 275: ! 276: check_impexp (yp) ! 277: YP yp; ! 278: { ! 279: SYM sp; ! 280: ! 281: for (sp = symtab[TBL_EXPORT]; sp; sp = sp->sym_next) ! 282: if (strcmp (sp -> sym_name, yp -> yp_identifier) == 0) ! 283: { ! 284: yp -> yp_flags |= YP_EXPORTED; ! 285: break; ! 286: } ! 287: ! 288: for (sp = symtab[TBL_IMPORT]; sp; sp = sp -> sym_next) ! 289: if (strcmp (sp -> sym_name, yp -> yp_identifier) == 0) { ! 290: if (yp->yp_flags & YP_EXPORTED) ! 291: myyerror ("Warning: %s imported & exported!", yp->yp_identifier); ! 292: yp -> yp_module = sp -> sym_module; ! 293: yp -> yp_modid = sp -> sym_oid; ! 294: /* yp -> yp_flags |= YP_IMPORTED; */ ! 295: } ! 296: } ! 297: static struct oidtbl { ! 298: char *oid_name; ! 299: int oid_value; ! 300: } oidtable[] = { ! 301: /* Top level OIDS */ ! 302: "ccitt", 0, ! 303: "iso", 1, ! 304: "joint-iso-ccitt", 2, ! 305: ! 306: NULL, ! 307: }; ! 308: ! 309: initoidtbl () ! 310: { ! 311: struct oidtbl *op; ! 312: OID oid; ! 313: ! 314: for (op = oidtable; op -> oid_name; op++) { ! 315: defineoid (op->oid_name, oid = int2oid(op->oid_value)); ! 316: oid_free (oid); ! 317: } ! 318: } ! 319: ! 320: char *oidprint (oid) ! 321: OID oid; ! 322: { ! 323: static char buf[BUFSIZ]; ! 324: char *cp; ! 325: char *p; ! 326: OID o2; ! 327: unsigned int *ip; ! 328: int i; ! 329: ! 330: if (oid == NULLOID) ! 331: return ""; ! 332: ! 333: (void) strcpy (buf, "{ "); ! 334: cp = buf + strlen(buf); ! 335: ! 336: i = oid->oid_nelem; ! 337: ip = oid->oid_elements; ! 338: ! 339: p = oidname (o2 = int2oid((int)*ip)); ! 340: oid_free (o2); ! 341: if (p) { ! 342: i --; ! 343: ip ++; ! 344: (void) sprintf (cp, "%s ", p); ! 345: cp += strlen(cp); ! 346: } ! 347: ! 348: for (; i > 0; i--) { ! 349: (void) sprintf (cp, "%d ", *ip++); ! 350: cp += strlen (cp); ! 351: } ! 352: ! 353: (void) strcat (cp, " }"); ! 354: return buf; ! 355: } ! 356: ! 357:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.