|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T r
Length: 5616 (0x15f0) Types: TextFile Names: »readobjects.c«
└─⟦3d0c2be1b⟧ Bits:30001254 ISODE-5.0 Tape └─⟦eba4602b1⟧ »./isode-5.0.tar.Z« └─⟦d3ac74d73⟧ └─⟦this⟧ »isode-5.0/others/mosy/readobjects.c«
/* readobjects.c - managed objects database */ #ifndef lint static char *rcsid = "$Header: /f/osi/others/mosy/RCS/readobjects.c,v 6.0 89/03/18 23:36:09 mrose Rel $"; #endif /* * $Header: /f/osi/others/mosy/RCS/readobjects.c,v 6.0 89/03/18 23:36:09 mrose Rel $ * * * $Log: readobjects.c,v $ * Revision 6.0 89/03/18 23:36:09 mrose * Release 5.0 * */ /* * NOTICE * * Acquisition, use, and distribution of this module and related * materials are subject to the restrictions of a license agreement. * Consult the Preface in the User's Manual for the full terms of * this agreement. * */ /* LINTLIBRARY */ #include <ctype.h> #include <stdio.h> #include "mosy.h" /* \f DATA */ /* hash buckets for text2obj */ #define TBUCKETS 128 #define THASH(nm) (((((nm)[0]) - ((nm)[1])) & 0x1f) + (((nm)[2]) & 0x5f)) static int once_only = 0; static OT Tbuckets[TBUCKETS]; OID resolve (); /* \f */ int readobjects (types, names) register OT types; register struct object_name *names; { register int i; int again, hit; register OT ot; if (once_only == 0) { bzero ((char *) Tbuckets, sizeof Tbuckets); if (!read_name ("iso", "1") || !read_name ("ccitt", "2") || !read_name ("joint-iso-ccitt", "3")) return 0; once_only = 1; } if (names) for (; names -> on_name; names++) if (!read_name (names -> on_name, names -> on_value)) return 0; if (types) for (; types -> ot_text; types++) if (!(read_type (types))) return 0; hit = 1; do { if (!hit) return 0; again = hit = 0; for (i = 0; i < TBUCKETS; i++) for (ot = Tbuckets[i]; ot && ot -> ot_text; ot = ot -> ot_chain) if (ot -> ot_name == NULLOID) if (ot -> ot_name = resolve (ot)) hit = 1; else again = 1; } while (again); #ifdef notdef { for (i = 0; i < TBUCKETS; i++) { hit = 0; for (ot = Tbuckets[i]; ot && ot -> ot_text; ot = ot -> ot_chain) { if (!hit) printf ("Bucket %d:\n", i), hit = 1; printf (" %s %s %s\n", ot -> ot_text, ot -> ot_id, sprintoid (ot -> ot_name)); } } } #endif return 1; } /* \f */ static int read_name (name, value) char *name, *value; { int i; register OT ot; if (text2obj (name)) { fprintf (stderr, "duplicate object \"%s\"\n", name); return 0; } if ((ot = (OT) calloc (1, sizeof *ot)) == NULL) return 0; ot -> ot_text = name; ot -> ot_id = value; ot -> ot_chain = Tbuckets[i = THASH (name)]; Tbuckets[i] = ot; return 1; } /* \f */ static int read_type (ot) register OT ot; { int i; if (text2obj (ot -> ot_text)) { fprintf (stderr, "duplicate object \"%s\"\n", ot -> ot_text); return 0; } ot -> ot_chain = Tbuckets[i = THASH (ot -> ot_text)]; Tbuckets[i] = ot; return 1; } /* \f */ static OID resolve (ot) register OT ot; { int i; char *id; unsigned int elements[NELEM + 1]; register char *cp; register OT ot2; struct OIDentifier oids; register OID oid = &oids; oid -> oid_elements = elements; if (cp = index (id = ot -> ot_id, '.')) *cp = NULL; if (isdigit (*id)) { ot2 = NULLOT; oid -> oid_nelem = 1; oid -> oid_elements[0] = atoi (id); if (cp) *cp = '.'; } else { ot2 = text2obj (id); if (cp) *cp = '.'; if (ot2 == NULLOT || ot2 -> ot_name == NULLOID) return NULLOID; oid -> oid_nelem = ot2 -> ot_name -> oid_nelem; bcopy ((char *) ot2 -> ot_name -> oid_elements, (char *) oid -> oid_elements, sizeof elements); } if (cp) { if ((i = str2elem (++cp, oid -> oid_elements + oid -> oid_nelem)) < 1) return NULLOID; oid -> oid_nelem += i; if (ot2) { /* XXX: not normalized... */ ot -> ot_sibling = ot2 -> ot_children; ot2 -> ot_children = ot; } } return oid_cpy (oid); } /* \f */ /* Partial matches are made only on leaf nodes... */ static char *roots[] = { NULL, "iso", "ccitt", "joint-iso-ccitt" }; OT name2obj (oid) OID oid; { register int i, j; register unsigned *ip; register OID nm; register OT ot; if (oid == NULLOID || oid -> oid_nelem < 1 || (i = (ip = oid -> oid_elements)[0]) >= (sizeof roots / sizeof roots[0]) || (ot = text2obj (roots[i])) == NULL) return NULLOT; i = 0; while (ot) { if ((j = (nm = ot -> ot_name) -> oid_nelem) > oid -> oid_nelem) return NULLOT; if (bcmp ((char *) ip, (char *) (nm -> oid_elements + i), (j - i) * sizeof *ip)) ot = ot -> ot_sibling; else if (oid -> oid_nelem == j || ot -> ot_children == NULLOT) break; else { ot = ot -> ot_children; ip = oid -> oid_elements + j, i = j; } } return ot; } /* \f */ OT text2obj (text) char *text; { register OT ot; if (text == NULL || once_only == 0) return NULLOT; for (ot = Tbuckets[THASH (text)]; ot && strcmp (ot -> ot_text, text); ot = ot -> ot_chain) continue; return ot; } /* \f */ char *oid2ode (oid) OID oid; { register int i; register char *bp; register unsigned int *ip; register OID oid2; register OT ot; static char buffer[BUFSIZ]; if ((ot = name2obj (oid)) == NULLOT) return sprintoid (oid); (void) strcpy (bp = buffer, ot -> ot_text); bp += strlen (bp); for (ip = oid -> oid_elements + (oid2 = ot -> ot_name) -> oid_nelem, i = oid -> oid_nelem - oid2 -> oid_nelem; i-- > 0; ip++) { (void) sprintf (bp, ".%d", *ip); bp += strlen (bp); } return buffer; }