1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2009 Index Data
3 * See the file LICENSE for details.
7 * \brief Implements various ODR utilities
17 #include <yaz/oid_util.h>
19 void odr_prname(ODR o, const char *name)
22 odr_printf(o, "%*s%s ", o->op->indent*4, "", name);
24 odr_printf(o, "%*s", o->op->indent*4, "");
27 int odp_more_chunks(ODR o, const unsigned char *base, int len)
31 if (len < 0) /* indefinite length */
33 if (*o->bp == 0 && *(o->bp + 1) == 0)
42 return o->bp - base < len;
45 Odr_oid *odr_oiddup_nmem(NMEM nmem, const Odr_oid *o)
52 nmem_malloc(nmem, (oid_oidlen(o) + 1) * sizeof(Odr_oid))))
58 Odr_oid *odr_oiddup(ODR odr, const Odr_oid *o)
60 return odr_oiddup_nmem(odr_getmem(odr), o);
63 Odr_oid *odr_getoidbystr_nmem(NMEM nmem, const char *str)
65 Odr_oid oid[OID_SIZE];
68 if (oid_dotstring_to_oid(str, oid))
70 ret = (Odr_oid *)nmem_malloc(nmem, sizeof(*ret)*(oid_oidlen(oid) + 1));
75 Odr_oid *odr_getoidbystr(ODR o, const char *str)
77 return odr_getoidbystr_nmem(odr_getmem(o), str);
80 int odr_missing(ODR o, int opt, const char *name)
86 odr_seterror(o, OREQUIRED, 53);
87 odr_setelement(o, name);
93 * Reallocate the buffer `old', using the ODR memory pool `o' to be
94 * big enough to hold its existing value (if any) plus `prefix' (if
95 * any) and a separator character. Copy `prefix', a forward slash and
96 * the old value into the new area and return its address. Can be
98 * initRequest->implementationName = odr_prepend(o,
99 * initRequest->implementationName, "ZOOM-C");
101 char *odr_prepend(ODR o, const char *prefix, const char *old)
103 int plen = (prefix == 0) ? 0 : strlen(prefix);
104 int olen = (old == 0) ? 0 : strlen(old);
105 char *res = (char*) odr_malloc (o, olen + plen + 2);
109 strcpy (res, prefix);
110 if (prefix != 0 && old != 0)
120 * indent-tabs-mode: nil
122 * vim: shiftwidth=4 tabstop=8 expandtab