X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fodr.c;h=8d4cff84730d292a04589754037196583d2b6600;hp=4cf86adba8c0dbe66c2f329c306a3e95511bf8b5;hb=fb6d99a0c7e07d9cc4a315c447deaf6564a85505;hpb=388a09802a50b37d3b3679949ac91b13594d3260 diff --git a/src/odr.c b/src/odr.c index 4cf86ad..8d4cff8 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.5 2004-08-24 08:44:10 adam Exp $ + * $Id: odr.c,v 1.12 2005-06-25 15:46:04 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) @@ -96,34 +106,34 @@ void odr_setelement(ODR o, const char *element) } void odr_FILE_write(ODR o, void *handle, int type, - const char *buf, int len) + const char *buf, int len) { int i; #if 0 if (type == ODR_OCTETSTRING) { - const char **stack_names = odr_get_element_path(o); - for (i = 0; stack_names[i]; i++) - fprintf((FILE*) handle, "[%s]", stack_names[i]); - fputs("\n", (FILE*) handle); + const char **stack_names = odr_get_element_path(o); + for (i = 0; stack_names[i]; i++) + fprintf((FILE*) handle, "[%s]", stack_names[i]); + fputs("\n", (FILE*) handle); } #endif for (i = 0; i 3100) - { - fputs(" ..... ", (FILE*) handle); - i = len - 1000; - } - if (strchr("\r\n\f\t", c) || c >= ' ' && c <= 126) - putc(c, (FILE*) handle); - else - { - char x[5]; - sprintf(x, "\\X%02X", c); - fputs(x, (FILE*) handle); - } + unsigned c = ((const unsigned char *) buf)[i]; + if (i == 2000 && len > 3100) + { + fputs(" ..... ", (FILE*) handle); + i = len - 1000; + } + if (strchr("\r\n\f\t", c) || (c >= ' ' && c <= 126)) + putc(c, (FILE*) handle); + else + { + char x[5]; + sprintf(x, "\\X%02X", c); + fputs(x, (FILE*) handle); + } } } @@ -131,7 +141,7 @@ void odr_FILE_close(void *handle) { FILE *f = (FILE *) handle; if (f && f != stderr && f != stdout) - fclose(f); + fclose(f); } void odr_setprint(ODR o, FILE *file) @@ -140,12 +150,12 @@ void odr_setprint(ODR o, FILE *file) } void odr_set_stream(ODR o, void *handle, - void (*stream_write)(ODR o, - void *handle, int type, - const char *buf, int len), - void (*stream_close)(void *handle)) + void (*stream_write)(ODR o, + void *handle, int type, + 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) @@ -211,12 +231,12 @@ void odr_destroy(ODR o) if (o->buf && o->can_grow) xfree(o->buf); if (o->op->stream_close) - o->op->stream_close(o->print); + o->op->stream_close(o->print); if (o->op->iconv_handle != 0) 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) @@ -256,3 +276,11 @@ void odr_printf(ODR o, const char *fmt, ...) o->op->stream_write(o, o->print, ODR_VISIBLESTRING, buf, strlen(buf)); va_end(ap); } +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ +