YAZ  4.2.57
odr-priv.h
Go to the documentation of this file.
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2013 Index Data.
3  * All rights reserved.
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of Index Data nor the names of its contributors
13  * may be used to endorse or promote products derived from this
14  * software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
32 #ifndef ODR_PRIV_H
33 
34 #define ODR_PRIV_H
35 
36 #include <yaz/odr.h>
37 #include <yaz/yaz-util.h>
38 
40 struct Odr_ber_tag {
41  int lclass;
42  int ltag;
43  int br;
44  int lcons;
45 };
46 
47 #define odr_max(o) ((o)->size - ((o)->bp - (o)->buf))
48 #define odr_offset(o) ((o)->bp - (o)->buf)
49 
65 {
66  const unsigned char *base;
68  int len;
70  const unsigned char *lenb;
72  int lenlen;
73  const char *name;
75  struct odr_constack *prev;
76  struct odr_constack *next;
77 };
78 
79 #define ODR_MAX_STACK 2000
80 
84 struct Odr_private {
85  /* stack for constructed types (we above) */
89  const char **tmp_names_buf;
95  int error_id;
96  char element[80];
97  void (*stream_write)(ODR o, void *handle, int type,
98  const char *buf, int len);
99  void (*stream_close)(void *handle);
100 
101  int can_grow; /* are we allowed to reallocate */
102  int t_class; /* implicit tagging (-1==default tag) */
103  int t_tag;
104 
105  int enable_bias; /* force choice enable flag */
106  int choice_bias; /* force choice */
107  int lenlen; /* force length-of-lenght (odr_setlen()) */
108  FILE *print; /* output file handler for direction print */
109  int indent; /* current indent level for printing */
110 };
111 
112 #define ODR_STACK_POP(x) (x)->op->stack_top = (x)->op->stack_top->prev
113 #define ODR_STACK_EMPTY(x) (!(x)->op->stack_top)
114 #define ODR_STACK_NOT_EMPTY(x) ((x)->op->stack_top)
115 
116 /* Private macro.
117  * write a single character at the current position - grow buffer if
118  * necessary.
119  * (no, we're not usually this anal about our macros, but this baby is
120  * next to unreadable without some indentation :)
121  */
122 #define odr_putc(o, c) \
123 ( \
124  ( \
125  (o)->pos < (o)->size ? \
126  ( \
127  (o)->buf[(o)->pos++] = (c), \
128  0 \
129  ) : \
130  ( \
131  odr_grow_block((o), 1) == 0 ? \
132  ( \
133  (o)->buf[(o)->pos++] = (c), \
134  0 \
135  ) : \
136  ( \
137  (o)->error = OSPACE, \
138  -1 \
139  ) \
140  ) \
141  ) == 0 ? \
142  ( \
143  (o)->pos > (o)->top ? \
144  ( \
145  (o)->top = (o)->pos, \
146  0 \
147  ) : \
148  0 \
149  ) : \
150  -1 \
151 )
152 
153 #endif
154 /*
155  * Local variables:
156  * c-basic-offset: 4
157  * c-file-style: "Stroustrup"
158  * indent-tabs-mode: nil
159  * End:
160  * vim: shiftwidth=4 tabstop=8 expandtab
161  */
162