X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fodr.c;h=e424b20e17a00fa09d0d766506bc871f2ecccb94;hp=7e376c114282449986f0fb8dd34c80bbc74880f7;hb=69b1d8e7b437179163fe97b7cbead51a56835f2a;hpb=88d3bedf772316f87e1996f655ccf8d1e2589755 diff --git a/src/odr.c b/src/odr.c index 7e376c1..e424b20 100644 --- a/src/odr.c +++ b/src/odr.c @@ -1,5 +1,5 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2010 Index Data + * Copyright (C) 1995-2013 Index Data * See the file LICENSE for details. */ @@ -22,12 +22,12 @@ #include #include "odr-priv.h" -static int log_level=0; -static int log_level_initialized=0; +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) +Odr_null *odr_nullval(void) { return ODR_NULLVAL; } @@ -64,7 +64,7 @@ void odr_perror(ODR o, const char *message) fprintf(stderr, "%s: %s (code %d:%d)", message, odr_errlist[err], err, x); if (e && *e) fprintf(stderr, " element %s", e); - + fprintf(stderr, "\n"); if (element_path) { @@ -144,10 +144,10 @@ void odr_FILE_write(ODR o, void *handle, int type, fputs("\n", (FILE*) handle); } #endif - for (i = 0; i 3100) + if (i == 20000 && len > 31000) { fputs(" ..... ", (FILE*) handle); i = len - 1000; @@ -175,8 +175,9 @@ void odr_setprint(ODR o, FILE *file) odr_set_stream(o, file, odr_FILE_write, odr_FILE_close); } + void odr_set_stream(ODR o, void *handle, - void (*stream_write)(ODR o, + void (*stream_write)(ODR o, void *handle, int type, const char *buf, int len), void (*stream_close)(void *handle)) @@ -193,7 +194,7 @@ int odr_set_charset(ODR o, const char *to, const char *from) o->op->iconv_handle = 0; if (to && from) { - o->op->iconv_handle = yaz_iconv_open (to, from); + o->op->iconv_handle = yaz_iconv_open(to, from); if (o->op->iconv_handle == 0) return -1; } @@ -206,13 +207,13 @@ ODR odr_createmem(int direction) ODR o; if (!log_level_initialized) { - log_level=yaz_log_module_level("odr"); - log_level_initialized=1; + log_level = yaz_log_module_level("odr"); + log_level_initialized = 1; } - if (!(o = (ODR)xmalloc(sizeof(*o)))) + if (!(o = (ODR) xmalloc(sizeof(*o)))) return 0; - o->op = (struct Odr_private *) xmalloc (sizeof(*o->op)); + o->op = (struct Odr_private *) xmalloc(sizeof(*o->op)); o->direction = direction; o->buf = 0; o->size = o->pos = o->top = 0; @@ -223,7 +224,7 @@ ODR odr_createmem(int direction) o->op->iconv_handle = 0; odr_setprint(o, stderr); odr_reset(o); - yaz_log (log_level, "odr_createmem dir=%d o=%p", direction, o); + yaz_log(log_level, "odr_createmem dir=%d o=%p", direction, o); return o; } @@ -231,8 +232,8 @@ void odr_reset(ODR o) { if (!log_level_initialized) { - log_level=yaz_log_module_level("odr"); - log_level_initialized=1; + log_level = yaz_log_module_level("odr"); + log_level_initialized = 1; } odr_seterror(o, ONONE, 0); @@ -251,9 +252,9 @@ void odr_reset(ODR o) o->op->lenlen = 1; if (o->op->iconv_handle != 0) yaz_iconv(o->op->iconv_handle, 0, 0, 0, 0); - yaz_log (log_level, "odr_reset o=%p", o); + yaz_log(log_level, "odr_reset o=%p", o); } - + void odr_destroy(ODR o) { nmem_destroy(o->mem); @@ -262,18 +263,17 @@ void odr_destroy(ODR o) if (o->op->stream_close) o->op->stream_close(o->op->print); if (o->op->iconv_handle != 0) - yaz_iconv_close (o->op->iconv_handle); + yaz_iconv_close(o->op->iconv_handle); xfree(o->op); xfree(o); - yaz_log (log_level, "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; + o->bp = buf; + o->buf = buf; o->op->can_grow = can_grow; o->top = o->pos = 0; o->size = len;