Check for config.h (currently not generated).
[yaz-moved-to-github.git] / odr / odr_tag.c
1 /*
2  * Copyright (c) 1995-2000, Index Data
3  * See the file LICENSE for details.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: odr_tag.c,v $
7  * Revision 1.11  2000-02-29 13:44:55  adam
8  * Check for config.h (currently not generated).
9  *
10  * Revision 1.10  1999/11/30 13:47:11  adam
11  * Improved installation. Moved header files to include/yaz.
12  *
13  * Revision 1.9  1998/02/11 11:53:34  adam
14  * Changed code so that it compiles as C++.
15  *
16  * Revision 1.8  1997/05/14 06:53:59  adam
17  * C++ support.
18  *
19  * Revision 1.7  1996/02/20 12:52:54  quinn
20  * Added odr_peektag
21  *
22  * Revision 1.6  1995/12/14  16:28:26  quinn
23  * More explain stuff.
24  *
25  * Revision 1.5  1995/09/29  17:12:27  quinn
26  * Smallish
27  *
28  * Revision 1.4  1995/09/27  15:03:00  quinn
29  * Modified function heads & prototypes.
30  *
31  * Revision 1.3  1995/05/16  08:51:00  quinn
32  * License, documentation, and memory fixes
33  *
34  * Revision 1.2  1995/03/08  12:12:31  quinn
35  * Added better error checking.
36  *
37  * Revision 1.1  1995/02/02  16:21:54  quinn
38  * First kick.
39  *
40  */
41 #if HAVE_CONFIG_H
42 #include <config.h>
43 #endif
44
45 #include <yaz/odr.h>
46
47 int odr_peektag(ODR o, int *zclass, int *tag, int *cons)
48 {
49     if (o->direction != ODR_DECODE)
50     {
51         o->error = OOTHER;
52         return 0;
53     }
54     if (o->stackp > -1 && !odr_constructed_more(o))
55         return 0;
56     if (ber_dectag(o->bp, zclass, tag, cons) <= 0)
57     {
58         o->error = OREQUIRED;
59         return 0;
60     }
61     return 1;
62 }
63
64 int odr_implicit_settag(ODR o, int zclass, int tag)
65 {
66     if (o->error)
67         return 0;
68     if (o->t_class < 0)
69     {
70         o->t_class = zclass;
71         o->t_tag = tag;
72     }
73     return 1;
74 }
75
76 int odr_initmember(ODR o, void *p, int size)
77 {
78     char **pp = (char **) p;
79
80     if (o->error)
81         return 0;
82     if (o->direction == ODR_DECODE)
83         *pp = (char *)odr_malloc(o, size);
84     else if (!*pp)
85     {
86         o->t_class = -1;
87         return 0;
88     }
89     return 1;
90 }