Expanded tabs in all source files. Added vim/emacs local variables
[yaz-moved-to-github.git] / src / ber_bool.c
1 /*
2  * Copyright (C) 1995-2005, Index Data ApS
3  * See the file LICENSE for details.
4  *
5  * $Id: ber_bool.c,v 1.4 2005-06-25 15:46:03 adam Exp $
6  */
7
8 /** 
9  * \file ber_bool.c
10  * \brief Implements BER BOOLEAN encoding and decoding
11  *
12  * This source file implements BER encoding and decoding of
13  * the BOOLEAN type.
14  */
15
16 #if HAVE_CONFIG_H
17 #include <config.h>
18 #endif
19
20 #include <stdio.h>
21 #include "odr-priv.h"
22
23 int ber_boolean(ODR o, int *val)
24 {
25     int res, len;
26
27     switch (o->direction)
28     {
29     case ODR_ENCODE:
30         if (ber_enclen(o, 1, 1, 1) != 1)
31             return 0;
32         if (odr_putc(o, *val) < 0)
33             return 0;
34 #ifdef ODR_DEBUG
35         fprintf(stderr, "[val=%d]\n", *val);
36 #endif
37         return 1;
38     case ODR_DECODE:
39         if ((res = ber_declen(o->bp, &len, odr_max(o))) < 0)
40         {
41             odr_seterror(o, OPROTO, 9);
42             return 0;
43         }
44         o->bp+= res;
45         if (len != 1 || odr_max(o) < len)
46         {
47             odr_seterror(o, OPROTO, 10);
48             return 0;
49         }
50         *val = *o->bp;
51         o->bp++;
52 #ifdef ODR_DEBUG
53         fprintf(stderr, "[val=%d]\n", *val);
54 #endif
55         return 1;
56     case ODR_PRINT:
57         return 1;
58     default: odr_seterror(o, OOTHER, 11); return 0;
59     }
60 }
61 /*
62  * Local variables:
63  * c-basic-offset: 4
64  * indent-tabs-mode: nil
65  * End:
66  * vim: shiftwidth=4 tabstop=8 expandtab
67  */
68