3 * \brief Internal ODR definitions
11 #include <yaz/yaz-util.h>
13 /** \brief Utility structure used by ber_tag */
21 #define odr_max(o) ((o)->size - ((o)->bp - (o)->buf))
22 #define odr_offset(o) ((o)->bp - (o)->buf)
25 * \brief stack for BER constructed items
27 * data structure for con stack.. a little peculiar. Since we can't
28 * deallocate memory we reuse stack items (popped items gets reused)
31 * +---+ +---+ +---+ +---+
32 * NULL -|p n|-----|p n|-----|p n|-----|p n|-- NULL
33 * +---+ +---+ +---+ +---+
35 * stack_first stack_top reused item
40 const unsigned char *base; /** starting point of data */
42 int len; /** length of data, if known, else -1
44 const unsigned char *lenb; /** where to encode length */
46 int lenlen; /** length of length-field */
47 const char *name; /** name of stack entry */
49 struct odr_constack *prev; /** pointer back in stack */
50 struct odr_constack *next; /** pointer forward */
53 #define ODR_MAX_STACK 2000
56 * \brief ODR private data
59 /* stack for constructed types (we above) */
60 struct odr_constack *stack_first; /** first member of allocated stack */
61 struct odr_constack *stack_top; /** top of stack */
63 const char **tmp_names_buf; /** array returned by odr_get_element_path */
64 int tmp_names_sz; /** size of tmp_names_buf */
66 struct Odr_ber_tag odr_ber_tag; /** used by ber_tag */
68 yaz_iconv_t iconv_handle;
71 void (*stream_write)(ODR o, void *handle, int type,
72 const char *buf, int len);
73 void (*stream_close)(void *handle);
75 int can_grow; /* are we allowed to reallocate */
76 int t_class; /* implicit tagging (-1==default tag) */
79 int enable_bias; /* force choice enable flag */
80 int choice_bias; /* force choice */
81 int lenlen; /* force length-of-lenght (odr_setlen()) */
82 FILE *print; /* output file handler for direction print */
83 int indent; /* current indent level for printing */
86 #define ODR_STACK_POP(x) (x)->op->stack_top = (x)->op->stack_top->prev
87 #define ODR_STACK_EMPTY(x) (!(x)->op->stack_top)
88 #define ODR_STACK_NOT_EMPTY(x) ((x)->op->stack_top)
91 * write a single character at the current position - grow buffer if
93 * (no, we're not usually this anal about our macros, but this baby is
94 * next to unreadable without some indentation :)
96 #define odr_putc(o, c) \
99 (o)->pos < (o)->size ? \
101 (o)->buf[(o)->pos++] = (c), \
105 odr_grow_block((o), 1) == 0 ? \
107 (o)->buf[(o)->pos++] = (c), \
111 (o)->error = OSPACE, \
117 (o)->pos > (o)->top ? \
119 (o)->top = (o)->pos, \
131 * indent-tabs-mode: nil
133 * vim: shiftwidth=4 tabstop=8 expandtab