Fixed bug #2068: pkg-config trouble.
[yaz-moved-to-github.git] / src / odr-priv.h
1 /**
2  * \file odr-priv.h
3  * \brief Internal ODR definitions
4  */
5
6 #ifndef ODR_PRIV_H
7
8 #define ODR_PRIV_H
9
10 #include <yaz/odr.h>
11 #include <yaz/yaz-util.h>
12
13 /** \brief Utility structure used by ber_tag */
14 struct Odr_ber_tag {
15     int lclass;
16     int ltag;
17     int br;
18     int lcons;
19 };
20
21 #define odr_max(o) ((o)->size - ((o)->bp - (o)->buf))
22 #define odr_offset(o) ((o)->bp - (o)->buf)
23
24 /**
25  * \brief stack for BER constructed items
26  *
27  * data structure for con stack.. a little peculiar. Since we can't
28  * deallocate memory we reuse stack items (popped items gets reused)
29  *
30  *\verbatim
31  *       +---+     +---+     +---+     +---+
32  * NULL -|p n|-----|p n|-----|p n|-----|p n|-- NULL
33  *       +---+     +---+     +---+     +---+
34  *         |                   |
35  *     stack_first         stack_top   reused item
36  *\endverbatim
37  */
38 struct odr_constack
39 {
40     const unsigned char *base;   /** starting point of data */
41     int base_offset;
42     int len;                     /** length of data, if known, else -1
43                                         (decoding only) */
44     const unsigned char *lenb;   /** where to encode length */
45     int len_offset;
46     int lenlen;                  /** length of length-field */
47     const char *name;            /** name of stack entry */
48
49     struct odr_constack *prev;   /** pointer back in stack */
50     struct odr_constack *next;   /** pointer forward */
51 };
52
53 #define ODR_MAX_STACK 2000
54
55 /**
56  * \brief ODR private data
57  */
58 struct Odr_private {
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 */
62
63     const char **tmp_names_buf;   /** array returned by odr_get_element_path */
64     int tmp_names_sz;                 /** size of tmp_names_buf */
65
66     struct Odr_ber_tag odr_ber_tag;   /** used by ber_tag */
67
68     yaz_iconv_t iconv_handle;
69     int error_id;
70     char element[80];
71     void (*stream_write)(ODR o, void *handle, int type,
72                          const char *buf, int len);
73     void (*stream_close)(void *handle);
74
75     int can_grow;        /* are we allowed to reallocate */
76     int t_class;         /* implicit tagging (-1==default tag) */
77     int t_tag;
78
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 */
84 };
85
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)
89
90 /* Private macro.
91  * write a single character at the current position - grow buffer if
92  * necessary.
93  * (no, we're not usually this anal about our macros, but this baby is
94  *  next to unreadable without some indentation  :)
95  */
96 #define odr_putc(o, c) \
97 ( \
98     ( \
99         (o)->pos < (o)->size ? \
100         ( \
101             (o)->buf[(o)->pos++] = (c), \
102             0 \
103         ) : \
104         ( \
105             odr_grow_block((o), 1) == 0 ? \
106             ( \
107                 (o)->buf[(o)->pos++] = (c), \
108                 0 \
109             ) : \
110             ( \
111                 (o)->error = OSPACE, \
112                 -1 \
113             ) \
114         ) \
115     ) == 0 ? \
116     ( \
117         (o)->pos > (o)->top ? \
118         ( \
119             (o)->top = (o)->pos, \
120             0 \
121         ) : \
122         0 \
123     ) : \
124         -1 \
125 )
126
127 #endif
128 /*
129  * Local variables:
130  * c-basic-offset: 4
131  * indent-tabs-mode: nil
132  * End:
133  * vim: shiftwidth=4 tabstop=8 expandtab
134  */
135