7c9279eabb506aedb33b02738e438091a0789750
[yaz-moved-to-github.git] / src / odr_bool.c
1 /*
2  * Copyright (C) 1995-2007, Index Data ApS
3  * See the file LICENSE for details.
4  *
5  * $Id: odr_bool.c,v 1.7 2007-03-19 21:08:13 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->op->t_class < 0)
30     {
31         o->op->t_class = ODR_UNIVERSAL;
32         o->op->t_tag = ODR_BOOLEAN;
33     }
34     res = ber_tag(o, p, o->op->t_class, o->op->t_tag, &cons, opt, name);
35     if (res < 0)
36         return 0;
37     if (!res)
38         return odr_missing(o, opt, name);
39     if (o->direction == ODR_PRINT)
40     {
41         odr_prname(o, name);
42         odr_printf(o, "%s\n", (**p ? "TRUE" : "FALSE"));
43         return 1;
44     }
45     if (cons)
46         return 0;
47     if (o->direction == ODR_DECODE)
48         *p = (int *)odr_malloc(o, sizeof(int));
49     return ber_boolean(o, *p);
50 }
51 /*
52  * Local variables:
53  * c-basic-offset: 4
54  * indent-tabs-mode: nil
55  * End:
56  * vim: shiftwidth=4 tabstop=8 expandtab
57  */
58