X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=odr%2Fodr_cons.c;h=917e154fd0efc85e01a012824fe02b8aa9ad3161;hb=52463063061a631f9cb086e938bc4494efec0bb5;hp=a2435b46727dab90f2c1afa6a524407ac01e32a8;hpb=99268f722648e84bf5c54eb685a1434e100f38a1;p=yaz-moved-to-github.git diff --git a/odr/odr_cons.c b/odr/odr_cons.c index a2435b4..917e154 100644 --- a/odr/odr_cons.c +++ b/odr/odr_cons.c @@ -4,7 +4,24 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: odr_cons.c,v $ - * Revision 1.11 1995-05-16 08:50:53 quinn + * Revision 1.16 1996-07-26 13:38:20 quinn + * Various smaller things. Gathered header-files. + * + * Revision 1.15 1995/09/29 17:12:23 quinn + * Smallish + * + * Revision 1.14 1995/09/27 15:02:58 quinn + * Modified function heads & prototypes. + * + * Revision 1.13 1995/08/15 11:16:39 quinn + * Fixed pretty-printers. + * CV:e ---------------------------------------------------------------------- + * CV:e ---------------------------------------------------------------------- + * + * Revision 1.12 1995/06/19 12:38:47 quinn + * Added BER dumper. + * + * Revision 1.11 1995/05/16 08:50:53 quinn * License, documentation, and memory fixes * * Revision 1.10 1995/04/18 08:15:21 quinn @@ -41,14 +58,22 @@ */ #include +#include + +void odr_setlenlen(ODR o, int len) +{ + o->lenlen = len; +} int odr_constructed_begin(ODR o, void *p, int class, int tag) { int res; int cons = 1; + int lenlen = o->lenlen; if (o->error) return 0; + o->lenlen = 1; /* reset lenlen */ if (o->t_class < 0) { o->t_class = class; @@ -69,10 +94,13 @@ int odr_constructed_begin(ODR o, void *p, int class, int tag) #ifdef ODR_DEBUG fprintf(stderr, "[cons_begin(%d)]", o->stackp); #endif - if (o->direction == ODR_ENCODE || o->direction == ODR_PRINT) + if (o->direction == ODR_ENCODE) { - o->stack[o->stackp].lenlen = 1; - if (odr_putc(o, 0) < 0) /* dummy */ + unsigned char dummy[sizeof(int)+1]; + + o->stack[o->stackp].lenlen = lenlen; + + if (odr_write(o, dummy, lenlen) < 0) /* dummy */ return 0; } else if (o->direction == ODR_DECODE) @@ -83,8 +111,16 @@ int odr_constructed_begin(ODR o, void *p, int class, int tag) o->bp += res; o->left -= res; } - else return 0; - + else if (o->direction == ODR_PRINT) + { + fprintf(o->print, "%s{\n", odr_indent(o)); + o->indent++; + } + else + { + o->error = OOTHER; + return 0; + } o->stack[o->stackp].base = o->bp; o->stack[o->stackp].base_offset = odr_tell(o); return 1; @@ -134,7 +170,7 @@ int odr_constructed_end(ODR o) else if (o->bp - o->stack[o->stackp].base != o->stack[o->stackp].len) { - o->error = OOTHER; + o->error = OCONLEN; return 0; } o->stackp--; @@ -144,7 +180,10 @@ int odr_constructed_end(ODR o) odr_seek(o, ODR_S_SET, o->stack[o->stackp].len_offset); if ((res = ber_enclen(o, pos - o->stack[o->stackp].base_offset, o->stack[o->stackp].lenlen, 1)) < 0) + { + o->error = OLENOV; return 0; + } odr_seek(o, ODR_S_END, 0); if (res == 0) /* indefinite encoding */ { @@ -162,7 +201,12 @@ int odr_constructed_end(ODR o) #endif o->stackp--; return 1; - case ODR_PRINT: o->stackp--; return 1; + case ODR_PRINT: + assert(o->indent > 0); + o->stackp--; + o->indent--; + fprintf(o->print, "%s}\n", odr_indent(o)); + return 1; default: o->error = OOTHER; return 0;