1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2011 Index Data
3 * See the file LICENSE for details.
7 * \brief Implements various ODR utilities
16 #include <yaz/oid_util.h>
18 void odr_prname(ODR o, const char *name)
21 odr_printf(o, "%*s%s ", o->op->indent*4, "", name);
23 odr_printf(o, "%*s", o->op->indent*4, "");
26 int odp_more_chunks(ODR o, const unsigned char *base, int len)
30 if (len < 0) /* indefinite length */
32 if (*o->bp == 0 && *(o->bp + 1) == 0)
41 return o->bp - base < len;
44 Odr_oid *odr_oiddup_nmem(NMEM nmem, const Odr_oid *o)
51 nmem_malloc(nmem, (oid_oidlen(o) + 1) * sizeof(Odr_oid))))
57 Odr_oid *odr_oiddup(ODR odr, const Odr_oid *o)
59 return odr_oiddup_nmem(odr_getmem(odr), o);
62 Odr_oid *odr_getoidbystr_nmem(NMEM nmem, const char *str)
64 Odr_oid oid[OID_SIZE];
67 if (oid_dotstring_to_oid(str, oid))
69 ret = (Odr_oid *)nmem_malloc(nmem, sizeof(*ret)*(oid_oidlen(oid) + 1));
74 Odr_oid *odr_getoidbystr(ODR o, const char *str)
76 return odr_getoidbystr_nmem(odr_getmem(o), str);
79 int odr_missing(ODR o, int opt, const char *name)
85 odr_seterror(o, OREQUIRED, 53);
86 odr_setelement(o, name);
92 * Reallocate the buffer `old', using the ODR memory pool `o' to be
93 * big enough to hold its existing value (if any) plus `prefix' (if
94 * any) and a separator character. Copy `prefix', a forward slash and
95 * the old value into the new area and return its address. Can be
97 * initRequest->implementationName = odr_prepend(o,
98 * initRequest->implementationName, "ZOOM-C");
100 char *odr_prepend(ODR o, const char *prefix, const char *old)
102 int plen = (prefix == 0) ? 0 : strlen(prefix);
103 int olen = (old == 0) ? 0 : strlen(old);
104 char *res = (char*) odr_malloc (o, olen + plen + 2);
108 strcpy (res, prefix);
109 if (prefix != 0 && old != 0)
119 * c-file-style: "Stroustrup"
120 * indent-tabs-mode: nil
122 * vim: shiftwidth=4 tabstop=8 expandtab