|
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 u
Length: 5042 (0x13b2) Types: TextFile Names: »util.c«
└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0 └─⟦041b9c0f8⟧ »EurOpenD22/isode/pepsy.system-6.0.Z« └─⟦d49939f05⟧ └─⟦6a28ec38e⟧ »pepsy.tar« └─⟦this⟧ »pepsy/util.c«
/* Copyright 1989 CSIRO Division of Information Technology * May be given away but not sold for profit - See Copyright file for details */ #include <stdio.h> #include "../h/psap.h" #include "pep.h" #include "pepdefs.h" #define PEPYPATH int _pverbose = 0; /* * Useful little routines */ /* * print out the message and if the arguement is greater than 0 terminate */ ferr(n, mesg) char *mesg; { printf(mesg); if (n > 0) exit (n); } /* * print out the message and number and if the arguement is greater than 0 terminate */ ferrd(n, mesg, d) char *mesg; int d; { printf(mesg, d); if (n > 0) exit (n); } /* * 0 = Encoding table, 1 = Decoding table, 2 = Printing table */ #define TYP_ENC 0 #define TYP_DEC 1 #define TYP_PRINT 2 #define TYP_LAST 2 /* Bound on size of a tpe array to stop endless loops */ #define MAXTPE 500 dmp_tpe(s, p, mod) char *s; modtyp *mod; /* Module it is from */ tpe *p; { int typ, i, j; tpe **par, **prev; char *name; printf("%s: (%s)", s, mod->md_name); /* * Calculate what table it is in - we assume they are in order * of increasing address */ par = NULL; for (typ = 0; typ <= TYP_LAST; typ++) { switch (typ) { case TYP_ENC: if (mod->md_etab != NULL && mod->md_etab[0] < p) { par = mod->md_etab; name = "Encoding:"; } break; case TYP_DEC: if (mod->md_dtab != NULL && mod->md_dtab[0] < p) { par = mod->md_dtab; name = "Decoding:"; } break; case TYP_PRINT: if (mod->md_ptab != NULL && mod->md_ptab[0] < (ptpe *) p) { (ptpe **) par = mod->md_ptab; name = "Printing:"; } break; default: ferrd(1, "dmp_tpe:typ = %d internal error\n", typ); } } if (par == NULL) { printf("can't find entry 0x%x\n", p); return; } prev = par; for (i = mod->md_nentries; i > 0; i--) { if (*par > p) break; par++; } if (par == prev) ferrd(1, "dmp_tpe:par == prev == 0x%x internal error\n", (int )par); par--; j = p - *par; printf("%s type %d + %d ", name, par - prev, j); pr_entry(p); } dmp_ptpe(s, p, mod) char *s; modtyp *mod; /* Module it is from */ ptpe *p; { int typ, i, j; ptpe **par, **prev; char *name; printf("%s:(%s)", s, mod->md_name); /* * Calculate what table it is in - we assume they are in order * of increasing address */ par = NULL; if (mod->md_ptab != NULL && mod->md_ptab[0] < p) { par = mod->md_ptab; name = "Printing:"; } if (par == NULL) { printf("can't find entry 0x%x\n", p); return; } prev = par; for (i = mod->md_nentries; i > 0; i--) { if (*par > p) break; par++; } if (par == prev) ferrd(1, "dmp_tpe:par == prev == 0x%x internal error\n", (int )par); par--; j = p - *par; printf("%s type %d + %d ", name, par - prev, j); pr_entry(p); } #define NENTRY(x) ((sizeof (x)/sizeof (x[0]))) /* * Print out a tpe entry */ static char *ntypes[] = { "PE_START", "PE_END", "illegal 1", "illegal 2", "XOBJECT", "illegal 4", "illegal 5", "UCODE", "MALLOC", "SCTRL", "CH_ACT", }, *otypes[] = { "ANY", "INTEGER", "BOOLEAN", "OBJECT", "BITSTRING", "OCTETSTRING", "SET_START", "SEQ_START", "SEQOF_START", "SETOF_START", "CHOICE_START", "CONS_ANY", "T_NULL", "T_OID", "ETAG", "IMP_OBJ", }; pr_entry(p) tpe *p; { if (p->pe_type >= PE_START && p->pe_type < NENTRY(ntypes) - 1) printf("{%s, ", ntypes[p->pe_type + 1]); else if (p->pe_type >= TYPE_DATA && p->pe_type < NENTRY(otypes) + TYPE_DATA) printf("{%s, ", otypes[p->pe_type - TYPE_DATA]); else printf("{%d, ", p->pe_type); printf("%d, %d, %d}\n", p->pe_ucode, p->pe_tag, p->pe_flags); } pr_pe(pe) PE pe; { #if 0 print_pe(pe, 1); #endif } /* * null function for what evr purposes */ f_null() {} /* * compare a given number of bits pointed to by the two character pointers * return 0 if they are the same non zero otherwise */ bitscmp(p1, p2, len) register char *p1, *p2; int len; { register int i; register unsigned int mask; if (len >= 8 && bcmp(p1, p2, len/8)) return (1); if (len % 8 == 0) return (0); /* Check those last few bits */ i = len/8; mask = (0xff00 >> len % 8) & 0xff; if (p1[i] & mask != p2[i] & mask) return (1); return (0); } #define MIN(a, b) (a < b ? a : b) /* * compare an octet string and a qb and return 0 if they are the same and * non zero otherwise */ ostrcmp(p, len, qb) register char *p; register int len; register struct qbuf *qb; { register struct qbuf *qp; if (len < 0 || qb == NULL || p == NULL) return (1); qp = qb; do { if (qp->qb_data != NULL) { if (qp->qb_len < 0) ferrd(1, "ostrcmp:qb_len %d < 0", qp->qb_len); if (qp->qb_len > len) return (1); if (bcmp(qp->qb_data, p, qp->qb_len)) return (1); if ((len -= qp->qb_len) == 0) return (0); p += qp->qb_len; } qp = qp->qb_forw; } while (qp != qb); return (len); }