X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fodr.c;h=e3709294730e170ff125cb45d466159adf7d9ce0;hb=60a702f390f7e2addfdab79f2328db3ba2897c8b;hp=54ff61361e74f80731ca60df7956e54bb918dd3c;hpb=3cef72d7093afaa8b106e4160ef0885b2ac50335;p=yaz-moved-to-github.git diff --git a/src/odr.c b/src/odr.c index 54ff613..e370929 100644 --- a/src/odr.c +++ b/src/odr.c @@ -1,10 +1,16 @@ /* - * Copyright (c) 1995-2004, Index Data + * Copyright (C) 1995-2005, Index Data ApS * See the file LICENSE for details. * - * $Id: odr.c,v 1.3 2004-08-13 07:30:06 adam Exp $ + * $Id: odr.c,v 1.11 2005-01-15 19:47:14 adam Exp $ * */ + +/** + * \file odr.c + * \brief Implements fundamental ODR functionality + */ + #if HAVE_CONFIG_H #include #endif @@ -14,8 +20,12 @@ #include #include +#include #include "odr-priv.h" +static int log_level=0; +static int log_level_initialized=0; + Odr_null *ODR_NULLVAL = (Odr_null *) "NULL"; /* the presence of a null value */ Odr_null *odr_nullval (void) @@ -110,13 +120,13 @@ void odr_FILE_write(ODR o, void *handle, int type, #endif for (i = 0; i 3100) { fputs(" ..... ", (FILE*) handle); i = len - 1000; } - unsigned c = ((const unsigned char *) buf)[i]; - if (strchr("\r\n\f\t", c) || c >= ' ' && c <= 126) + if (strchr("\r\n\f\t", c) || (c >= ' ' && c <= 126)) putc(c, (FILE*) handle); else { @@ -145,7 +155,7 @@ void odr_set_stream(ODR o, void *handle, const char *buf, int len), void (*stream_close)(void *handle)) { - o->print = handle; + o->print = (FILE*) handle; o->op->stream_write = stream_write; o->op->stream_close = stream_close; } @@ -164,11 +174,15 @@ int odr_set_charset(ODR o, const char *to, const char *from) return 0; } -#include ODR odr_createmem(int direction) { ODR o; + if (!log_level_initialized) + { + log_level=yaz_log_module_level("odr"); + log_level_initialized=1; + } if (!(o = (ODR)xmalloc(sizeof(*o)))) return 0; @@ -183,12 +197,18 @@ ODR odr_createmem(int direction) o->op->iconv_handle = 0; odr_setprint(o, stderr); odr_reset(o); - yaz_log (LOG_DEBUG, "odr_createmem dir=%d o=%p", direction, o); + yaz_log (log_level, "odr_createmem dir=%d o=%p", direction, o); return o; } void odr_reset(ODR o) { + if (!log_level_initialized) + { + log_level=yaz_log_module_level("odr"); + log_level_initialized=1; + } + odr_seterror(o, ONONE, 0); o->bp = o->buf; odr_seek(o, ODR_S_SET, 0); @@ -202,7 +222,7 @@ void odr_reset(ODR o) o->lenlen = 1; if (o->op->iconv_handle != 0) yaz_iconv(o->op->iconv_handle, 0, 0, 0, 0); - yaz_log (LOG_DEBUG, "odr_reset o=%p", o); + yaz_log (log_level, "odr_reset o=%p", o); } void odr_destroy(ODR o) @@ -216,11 +236,12 @@ void odr_destroy(ODR o) yaz_iconv_close (o->op->iconv_handle); xfree(o->op); xfree(o); - yaz_log (LOG_DEBUG, "odr_destroy o=%p", o); + yaz_log (log_level, "odr_destroy o=%p", o); } void odr_setbuf(ODR o, char *buf, int len, int can_grow) { + odr_seterror(o, ONONE, 0); o->bp = (unsigned char *) buf; o->buf = (unsigned char *) buf;