1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2012 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)
20 if (o->op->indent < 16)
21 odr_printf(o, "%*s", o->op->indent * 2, "");
23 odr_printf(o, "level=%-7d%*s", o->op->indent,
24 2 * (o->op->indent % 8) , "");
26 odr_printf(o, "%s ", name);
29 int odp_more_chunks(ODR o, const unsigned char *base, int len)
33 if (len < 0) /* indefinite length */
35 if (*o->bp == 0 && *(o->bp + 1) == 0)
44 return o->bp - base < len;
47 Odr_oid *odr_oiddup_nmem(NMEM nmem, const Odr_oid *o)
54 nmem_malloc(nmem, (oid_oidlen(o) + 1) * sizeof(Odr_oid))))
60 Odr_oid *odr_oiddup(ODR odr, const Odr_oid *o)
62 return odr_oiddup_nmem(odr_getmem(odr), o);
65 Odr_oid *odr_getoidbystr_nmem(NMEM nmem, const char *str)
67 Odr_oid oid[OID_SIZE];
70 if (oid_dotstring_to_oid(str, oid))
72 ret = (Odr_oid *)nmem_malloc(nmem, sizeof(*ret)*(oid_oidlen(oid) + 1));
77 Odr_oid *odr_getoidbystr(ODR o, const char *str)
79 return odr_getoidbystr_nmem(odr_getmem(o), str);
82 int odr_missing(ODR o, int opt, const char *name)
88 odr_seterror(o, OREQUIRED, 53);
89 odr_setelement(o, name);
95 * Reallocate the buffer `old', using the ODR memory pool `o' to be
96 * big enough to hold its existing value (if any) plus `prefix' (if
97 * any) and a separator character. Copy `prefix', a forward slash and
98 * the old value into the new area and return its address. Can be
100 * initRequest->implementationName = odr_prepend(o,
101 * initRequest->implementationName, "ZOOM-C");
103 char *odr_prepend(ODR o, const char *prefix, const char *old)
105 int plen = (prefix == 0) ? 0 : strlen(prefix);
106 int olen = (old == 0) ? 0 : strlen(old);
107 char *res = (char*) odr_malloc (o, olen + plen + 2);
111 strcpy (res, prefix);
112 if (prefix != 0 && old != 0)
122 * c-file-style: "Stroustrup"
123 * indent-tabs-mode: nil
125 * vim: shiftwidth=4 tabstop=8 expandtab