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