2 * Copyright (c) 1995, Index Data
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.13 1995-08-15 11:16:39 quinn
8 * Fixed pretty-printers.
9 * CV:e ----------------------------------------------------------------------
10 * CV:e ----------------------------------------------------------------------
12 * Revision 1.12 1995/06/19 12:38:47 quinn
15 * Revision 1.11 1995/05/16 08:50:53 quinn
16 * License, documentation, and memory fixes
18 * Revision 1.10 1995/04/18 08:15:21 quinn
19 * Added dynamic memory allocation on encoding (whew). Code is now somewhat
20 * neater. We'll make the same change for decoding one day.
22 * Revision 1.9 1995/03/28 09:15:49 quinn
23 * Fixed bug in the printing mode
25 * Revision 1.8 1995/03/15 11:18:04 quinn
26 * Fixed serious bug in odr_cons
28 * Revision 1.7 1995/03/10 11:44:41 quinn
29 * Fixed serious stack-bug in odr_cons_begin
31 * Revision 1.6 1995/03/08 12:12:23 quinn
32 * Added better error checking.
34 * Revision 1.5 1995/02/10 18:57:25 quinn
35 * More in the way of error-checking.
37 * Revision 1.4 1995/02/10 15:55:29 quinn
40 * Revision 1.3 1995/02/09 15:51:48 quinn
43 * Revision 1.2 1995/02/07 17:52:59 quinn
44 * A damn mess, but now things work, I think.
46 * Revision 1.1 1995/02/02 16:21:53 quinn
54 int odr_constructed_begin(ODR o, void *p, int class, int tag)
66 if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, 1)) < 0)
71 if (o->stackp == ODR_MAX_STACK - 1)
76 o->stack[++(o->stackp)].lenb = o->bp;
77 o->stack[o->stackp].len_offset = odr_tell(o);
79 fprintf(stderr, "[cons_begin(%d)]", o->stackp);
81 if (o->direction == ODR_ENCODE)
83 o->stack[o->stackp].lenlen = 1;
84 if (odr_putc(o, 0) < 0) /* dummy */
87 else if (o->direction == ODR_DECODE)
89 if ((res = ber_declen(o->bp, &o->stack[o->stackp].len)) < 0)
91 o->stack[o->stackp].lenlen = res;
95 else if (o->direction == ODR_PRINT)
97 fprintf(o->print, "%s{\n", odr_indent(o));
105 o->stack[o->stackp].base = o->bp;
106 o->stack[o->stackp].base_offset = odr_tell(o);
110 int odr_constructed_more(ODR o)
116 if (o->stack[o->stackp].len >= 0)
117 return o->bp - o->stack[o->stackp].base < o->stack[o->stackp].len;
119 return (!(*o->bp == 0 && *(o->bp + 1) == 0));
122 int odr_constructed_end(ODR o)
134 switch (o->direction)
137 if (o->stack[o->stackp].len < 0)
139 if (*o->bp++ == 0 && *(o->bp++) == 0)
151 else if (o->bp - o->stack[o->stackp].base !=
152 o->stack[o->stackp].len)
161 odr_seek(o, ODR_S_SET, o->stack[o->stackp].len_offset);
162 if ((res = ber_enclen(o, pos - o->stack[o->stackp].base_offset,
163 o->stack[o->stackp].lenlen, 1)) < 0)
165 odr_seek(o, ODR_S_END, 0);
166 if (res == 0) /* indefinite encoding */
169 fprintf(stderr, "[cons_end(%d): indefinite]", o->stackp);
171 if (odr_putc(o, 0) < 0 || odr_putc(o, 0) < 0)
177 fprintf(stderr, "[cons_end(%d): definite]", o->stackp);
183 assert(o->indent > 0);
186 fprintf(o->print, "%s}\n", odr_indent(o));