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