Updates.
[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.1  1995-02-02 20:38:50  quinn
8  * Updates.
9  *
10  *
11  */
12
13 #include <odr.h>
14 #include <string.h>
15
16 /*
17  * Top level bitstring string en/decoder.
18  * Returns 1 on success, 0 on error.
19  */
20 int odr_bitstring(ODR o, ODR_BITMASK **p, int opt)
21 {
22     int res, cons = 0;
23
24     if (o->t_class < 0)
25     {
26         o->t_class = ODR_UNIVERSAL;
27         o->t_tag = ODR_BITSTRING;
28     }
29     if ((res = ber_tag(o, *p, o->t_class, o->t_tag, &cons)) < 0)
30         return 0;
31     if (!res)
32     {
33         *p = 0;
34         return opt;
35     }
36     if (o->direction == ODR_PRINT)
37     {
38         fprintf(o->print, "BITSTRING(len=%d)\n", (*p)->top + 1);
39         return 1;
40     }
41     if (o->direction == ODR_DECODE && !*p)
42     {
43         *p = nalloc(o, sizeof(ODR_BITMASK));
44         memset((*p)->bits, 0, ODR_BITMASK_SIZE);
45         (*p)->top = -1;
46     }
47     return ber_bitstring(o, *p, cons);
48 }