Works better now.
[yaz-moved-to-github.git] / odr / odr_bit.c
1 /*
2  * Copyright (C) 1994, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: odr_bit.c,v $
7  * Revision 1.4  1995-02-09 15:51:47  quinn
8  * Works better now.
9  *
10  * Revision 1.3  1995/02/07  14:13:45  quinn
11  * Bug fixes.
12  *
13  * Revision 1.2  1995/02/03  17:04:37  quinn
14  * *** empty log message ***
15  *
16  * Revision 1.1  1995/02/02  20:38:50  quinn
17  * Updates.
18  *
19  *
20  */
21
22 #include <odr.h>
23 #include <string.h>
24
25 /*
26  * Top level bitstring string en/decoder.
27  * Returns 1 on success, 0 on error.
28  */
29 int odr_bitstring(ODR o, Odr_bitmask **p, int opt)
30 {
31     int res, cons = 0;
32
33     if (o->t_class < 0)
34     {
35         o->t_class = ODR_UNIVERSAL;
36         o->t_tag = ODR_BITSTRING;
37     }
38     if (o->direction == ODR_DECODE)
39         *p = 0;
40     if ((res = ber_tag(o, *p, o->t_class, o->t_tag, &cons)) < 0)
41         return 0;
42     if (!res)
43     {
44         *p = 0;
45         return opt;
46     }
47     if (o->direction == ODR_PRINT)
48     {
49         fprintf(o->print, "%sBITSTRING(len=%d)\n", odr_indent(o), (*p)->top + 1);
50         return 1;
51     }
52     if (o->direction == ODR_DECODE)
53     {
54         *p = nalloc(o, sizeof(Odr_bitmask));
55         memset((*p)->bits, 0, ODR_BITMASK_SIZE);
56         (*p)->top = -1;
57     }
58     return ber_bitstring(o, *p, cons);
59 }