X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fodr_util.c;h=9a9f4452b6219b4fd27e659223a7e30f13794d0c;hp=bb1955c0f38f2b1fbc8226cd90b77e91f9700523;hb=db93359f0cbf9a1e9dc81ea05f7b8662f843ae3d;hpb=4fbc7c05a14d80187951b2fc690ba71374449124 diff --git a/src/odr_util.c b/src/odr_util.c index bb1955c..9a9f445 100644 --- a/src/odr_util.c +++ b/src/odr_util.c @@ -1,8 +1,12 @@ /* - * Copyright (c) 1995-2003, Index Data + * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: odr_util.c,v 1.2 2003-11-26 16:23:42 mike Exp $ + * $Id: odr_util.c,v 1.10 2007-03-19 21:08:13 adam Exp $ + */ +/** + * \file odr_util.c + * \brief Implements various ODR utilities */ #if HAVE_CONFIG_H #include @@ -17,24 +21,24 @@ void odr_prname(ODR o, const char *name) { if (name) - fprintf (o->print, "%*s%s ", o->indent*4, "", name); + odr_printf(o, "%*s%s ", o->op->indent*4, "", name); else - fprintf (o->print, "%*s", o->indent*4, ""); + odr_printf(o, "%*s", o->op->indent*4, ""); } int odp_more_chunks(ODR o, const unsigned char *base, int len) { if (!len) - return 0; + return 0; if (len < 0) /* indefinite length */ { - if (*o->bp == 0 && *(o->bp + 1) == 0) - { - o->bp += 2; - return 0; - } - else - return 1; + if (*o->bp == 0 && *(o->bp + 1) == 0) + { + o->bp += 2; + return 0; + } + else + return 1; } else return o->bp - base < len; @@ -45,15 +49,17 @@ Odr_oid *odr_oiddup_nmem(NMEM nmem, Odr_oid *o) Odr_oid *r; if (!o) - return 0; + return 0; if (!(r = (int *)nmem_malloc(nmem, (oid_oidlen(o) + 1) * sizeof(int)))) - return 0; + return 0; oid_oidcpy(r, o); return r; } Odr_oid *odr_oiddup(ODR odr, Odr_oid *o) { + if (!odr->mem) + odr->mem = nmem_create(); return odr_oiddup_nmem (odr->mem, o); } @@ -63,14 +69,14 @@ Odr_oid *odr_getoidbystr_nmem(NMEM nmem, const char *str) const char *p = str; Odr_oid *ret; - if (!isdigit(*str)) - return 0; + if (!isdigit(*(const unsigned char *) str)) + return 0; while ((p = strchr(p, '.'))) - num++, p++; + num++, p++; ret = (int *)nmem_malloc(nmem, sizeof(*ret)*(num + 1)); p = str; do - ret[i++] = atoi(p); + ret[i++] = atoi(p); while ((p = strchr(p, '.')) && *++p); ret[i] = -1; return ret; @@ -78,6 +84,8 @@ Odr_oid *odr_getoidbystr_nmem(NMEM nmem, const char *str) Odr_oid *odr_getoidbystr(ODR o, const char *str) { + if (!o->mem) + o->mem = nmem_create(); return odr_getoidbystr_nmem (o->mem, str); } @@ -99,8 +107,8 @@ int odr_missing(ODR o, int opt, const char *name) * any) and a separator character. Copy `prefix', a forward slash and * the old value into the new area and return its address. Can be * used as follows: - * initRequest->implementationName = odr_prepend(o, - * initRequest->implementationName, "ZOOM-C"); + * initRequest->implementationName = odr_prepend(o, + * initRequest->implementationName, "ZOOM-C"); */ char *odr_prepend(ODR o, const char *prefix, const char *old) { @@ -110,11 +118,19 @@ char *odr_prepend(ODR o, const char *prefix, const char *old) *res = '\0'; if (prefix != 0) - strcpy (res, prefix); + strcpy (res, prefix); if (prefix != 0 && old != 0) - strcat (res, "/"); + strcat (res, "/"); if (old !=0) - strcat (res, old); + strcat (res, old); return res; } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ +