5279ae240a26f3929706926615212b12b4c64324
[yaz-moved-to-github.git] / odr / odr_bool.c
1 /*
2  * Copyright (C) 1994, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: odr_bool.c,v $
7  * Revision 1.5  1995-03-17 10:17:49  quinn
8  * Added memory management.
9  *
10  * Revision 1.4  1995/03/08  12:12:20  quinn
11  * Added better error checking.
12  *
13  * Revision 1.3  1995/02/10  18:57:25  quinn
14  * More in the way of error-checking.
15  *
16  * Revision 1.2  1995/02/09  15:51:47  quinn
17  * Works better now.
18  *
19  * Revision 1.1  1995/02/02  16:21:53  quinn
20  * First kick.
21  *
22  */
23
24 #include <stdio.h>
25 #include <odr.h>
26
27 /*
28  * Top level boolean en/decoder.
29  * Returns 1 on success, 0 on error.
30  */
31 int odr_bool(ODR o, int **p, int opt)
32 {
33     int res, cons = 0;
34
35     if (o->error)
36         return 0;
37     if (o->t_class < 0)
38     {
39         o->t_class = ODR_UNIVERSAL;
40         o->t_tag = ODR_BOOLEAN;
41     }
42     if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt)) < 0)
43         return 0;
44     if (!res)
45         return opt;
46     if (o->direction == ODR_PRINT)
47     {
48         fprintf(o->print, "%s%s\n", odr_indent(o), (**p ? "TRUE" : "FALSE"));
49         return 1;
50     }
51     if (cons)
52         return 0;
53     if (o->direction == ODR_DECODE)
54         *p = odr_malloc(o, sizeof(int));
55     return ber_boolean(o, *p);
56 }