X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fodr.c;h=1e31f29cca1bb26ecff8534f074df0b70c1c2b88;hb=9a32992b1041bf622fdc4825262f5f7110494cce;hp=7a0dab1696c4559f6a0aad3c3ae9f93d984eef2f;hpb=0a7d4354288c747883261e9f430a7e0069225a5b;p=yaz-moved-to-github.git diff --git a/src/odr.c b/src/odr.c index 7a0dab1..1e31f29 100644 --- a/src/odr.c +++ b/src/odr.c @@ -2,9 +2,15 @@ * Copyright (c) 1995-2004, Index Data * See the file LICENSE for details. * - * $Id: odr.c,v 1.2 2004-08-11 12:15:38 adam Exp $ + * $Id: odr.c,v 1.8 2004-10-15 00:19:00 adam Exp $ * */ + +/** + * \file odr.c + * \brief Implements fundamental ODR functionality + */ + #if HAVE_CONFIG_H #include #endif @@ -69,11 +75,16 @@ int odr_geterrorx(ODR o, int *x) return o->error; } -char *odr_getelement(ODR o) +const char *odr_getelement(ODR o) { return o->op->element; } +const char **odr_get_element_path(ODR o) +{ + return o->op->stack_names; +} + void odr_seterror(ODR o, int error, int id) { o->error = error; @@ -90,9 +101,36 @@ void odr_setelement(ODR o, const char *element) } } -void odr_FILE_puts(void *handle, const char *strz) +void odr_FILE_write(ODR o, void *handle, int type, + const char *buf, int len) { - fputs(strz, (FILE*) handle); + 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); + } +#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); + } + } } void odr_FILE_close(void *handle) @@ -104,15 +142,17 @@ void odr_FILE_close(void *handle) void odr_setprint(ODR o, FILE *file) { - odr_set_stream(o, file, odr_FILE_puts, odr_FILE_close); + odr_set_stream(o, file, odr_FILE_write, odr_FILE_close); } void odr_set_stream(ODR o, void *handle, - void (*stream_puts)(void *handle, const char *strz), + void (*stream_write)(ODR o, + void *handle, int type, + const char *buf, int len), void (*stream_close)(void *handle)) { - o->print = handle; - o->op->stream_puts = stream_puts; + o->print = (FILE*) handle; + o->op->stream_write = stream_write; o->op->stream_close = stream_close; } @@ -187,6 +227,7 @@ void odr_destroy(ODR 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; @@ -218,6 +259,6 @@ void odr_printf(ODR o, const char *fmt, ...) vsprintf(buf, fmt, ap); #endif #endif - o->op->stream_puts(o->print, buf); + o->op->stream_write(o, o->print, ODR_VISIBLESTRING, buf, strlen(buf)); va_end(ap); }