d1582f580366770a3290925a58dd24b4df95c7a3
[yaz-moved-to-github.git] / src / odr_bool.c
1 /*
2  * Copyright (C) 1995-2005, Index Data ApS
3  * See the file LICENSE for details.
4  *
5  * $Id: odr_bool.c,v 1.4 2005-01-15 19:47:14 adam Exp $
6  */
7
8 /**
9  * \file odr_bool.c
10  * \brief Implements ODR BOOLEAN codec
11  */
12 #if HAVE_CONFIG_H
13 #include <config.h>
14 #endif
15
16 #include <stdio.h>
17 #include "odr-priv.h"
18
19 /*
20  * Top level boolean en/decoder.
21  * Returns 1 on success, 0 on error.
22  */
23 int odr_bool(ODR o, int **p, int opt, const char *name)
24 {
25     int res, cons = 0;
26
27     if (o->error)
28         return 0;
29     if (o->t_class < 0)
30     {
31         o->t_class = ODR_UNIVERSAL;
32         o->t_tag = ODR_BOOLEAN;
33     }
34     if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt, name)) < 0)
35         return 0;
36     if (!res)
37         return odr_missing(o, opt, name);
38     if (o->direction == ODR_PRINT)
39     {
40         odr_prname(o, name);
41         odr_printf(o, "%s\n", (**p ? "TRUE" : "FALSE"));
42         return 1;
43     }
44     if (cons)
45         return 0;
46     if (o->direction == ODR_DECODE)
47         *p = (int *)odr_malloc(o, sizeof(int));
48     return ber_boolean(o, *p);
49 }