2 * Copyright (c) 1995-2003, Index Data
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
6 * $Id: odr_seq.c,v 1.29 2003-01-06 08:20:28 adam Exp $
15 int odr_sequence_begin(ODR o, void *p, int size, const char *name)
17 char **pp = (char**) p;
23 o->t_class = ODR_UNIVERSAL;
24 o->t_tag = ODR_SEQUENCE;
26 if (o->direction == ODR_DECODE)
28 if (odr_constructed_begin(o, p, o->t_class, o->t_tag, name))
30 if (o->direction == ODR_DECODE && size)
31 *pp = (char *)odr_malloc(o, size);
38 int odr_set_begin(ODR o, void *p, int size, const char *name)
40 char **pp = (char**) p;
46 o->t_class = ODR_UNIVERSAL;
49 if (o->direction == ODR_DECODE)
51 if (odr_constructed_begin(o, p, o->t_class, o->t_tag, name))
53 if (o->direction == ODR_DECODE && size)
54 *pp = (char *)odr_malloc(o, size);
61 int odr_sequence_end(ODR o)
63 return odr_constructed_end(o);
66 int odr_set_end(ODR o)
68 return odr_constructed_end(o);
71 static int odr_sequence_more(ODR o)
73 return odr_constructed_more(o);
76 static int odr_sequence_x (ODR o, Odr_fun type, void *p, int *num)
78 char ***pp = (char***) p; /* for dereferencing */
86 *pp = (char **)odr_nullval();
87 while (odr_sequence_more(o))
90 if (*num * (int) sizeof(void*) >= size)
92 /* double the buffer size */
93 tmp = (char **)odr_malloc(o, sizeof(void*) *
94 (size += size ? size : 128));
97 memcpy(tmp, *pp, *num * sizeof(void*));
99 * For now, we just throw the old *p away, since we use
100 * nibble memory anyway (disgusting, isn't it?).
105 if (!(*type)(o, (*pp) + *num, 0, 0))
110 case ODR_ENCODE: case ODR_PRINT:
112 fprintf(stderr, "[seqof: num=%d]", *num);
114 for (i = 0; i < *num; i++)
117 fprintf(stderr, "[seqof: elem #%d]", i);
119 if (!(*type)(o, *pp + i, 0, 0))
127 return odr_sequence_end(o);
130 int odr_set_of(ODR o, Odr_fun type, void *p, int *num, const char *name)
132 if (!odr_set_begin(o, p, 0, name)) {
133 if (o->direction == ODR_DECODE)
137 return odr_sequence_x (o, type, p, num);
140 int odr_sequence_of(ODR o, Odr_fun type, void *p, int *num,
143 if (!odr_sequence_begin(o, p, 0, name)) {
144 if (o->direction == ODR_DECODE)
148 return odr_sequence_x (o, type, p, num);