X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=odr%2Fodr.c;h=2691c65ec0c1f94b028fa4fb02ba7796e9c364c4;hb=7d093cf64e6045cf14dbf199f8cdf6b808dd3b65;hp=2347ef353aa1c882ec7e4c527b1a9bb2e47860c9;hpb=398d5857516b707c1697721ec92bb0ec15619252;p=yaz-moved-to-github.git diff --git a/odr/odr.c b/odr/odr.c index 2347ef3..2691c65 100644 --- a/odr/odr.c +++ b/odr/odr.c @@ -4,7 +4,31 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: odr.c,v $ - * Revision 1.1 1995-03-07 09:23:15 quinn + * Revision 1.9 1995-04-10 10:23:11 quinn + * Smallish changes. + * + * Revision 1.8 1995/03/17 10:17:43 quinn + * Added memory management. + * + * Revision 1.7 1995/03/10 11:44:41 quinn + * Fixed serious stack-bug in odr_cons_begin + * + * Revision 1.6 1995/03/08 12:12:15 quinn + * Added better error checking. + * + * Revision 1.5 1995/03/07 13:28:57 quinn + * *** empty log message *** + * + * Revision 1.4 1995/03/07 13:16:13 quinn + * Fixed bug in odr_reset + * + * Revision 1.3 1995/03/07 10:21:31 quinn + * odr_errno-->odr_error + * + * Revision 1.2 1995/03/07 10:19:05 quinn + * Addded some method functions to the ODR type. + * + * Revision 1.1 1995/03/07 09:23:15 quinn * Installing top-level API and documentation. * * @@ -18,12 +42,15 @@ char *odr_errlist[] = { "No (unknown) error", - "Memoy allocation failed", + "Memory allocation failed", "System error", "No space in buffer", "Required data element missing", "Unexpected tag", - "Other error" + "Other error", + "Protocol error", + "Malformed data", + "Stack overflow" }; void odr_perror(ODR o, char *message) @@ -31,6 +58,11 @@ void odr_perror(ODR o, char *message) fprintf(stderr, "%s: %s\n", message, odr_errlist[o->error]); } +int odr_geterror(ODR o) +{ + return o->error; +} + void odr_setprint(ODR o, FILE *file) { o->print = file; @@ -43,9 +75,10 @@ ODR odr_createmem(int direction) if (!(r = malloc(sizeof(*r)))) return 0; r->direction = direction; - r->print = stdout; + r->print = stderr; r->buf = 0; r->buflen = 0; + r->mem = 0; odr_reset(r); return r; } @@ -53,15 +86,32 @@ ODR odr_createmem(int direction) void odr_reset(ODR o) { o->error = ONONE; - o->bp = 0; + o->bp = o->buf; o->left = o->buflen; o->t_class = -1; o->t_tag = -1; o->indent = 0; - o->stackp = 0; + o->stackp = -1; + odr_release_mem(o->mem); + o->mem = 0; } void odr_destroy(ODR o) { + odr_release_mem(o->mem); + if (o->print != stderr) + fclose(o->print); free(o); } + +void odr_setbuf(ODR o, char *buf, int len) +{ + o->buf = o->bp = (unsigned char *) buf; + o->buflen = o->left = len; +} + +char *odr_getbuf(ODR o, int *len) +{ + *len = o->bp - o->buf; + return (char *) o->buf; +}