YAZ  5.23.1
odr_bool.c
Go to the documentation of this file.
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) Index Data
3  * See the file LICENSE for details.
4  */
5 
10 #if HAVE_CONFIG_H
11 #include <config.h>
12 #endif
13 
14 #include <stdio.h>
15 #include "odr-priv.h"
16 
17 /*
18  * Top level boolean en/decoder.
19  * Returns 1 on success, 0 on error.
20  */
21 int odr_bool(ODR o, Odr_bool **p, int opt, const char *name)
22 {
23  int res, cons = 0;
24 
25  if (o->error)
26  return 0;
27  if (o->op->t_class < 0)
28  {
29  o->op->t_class = ODR_UNIVERSAL;
30  o->op->t_tag = ODR_BOOLEAN;
31  }
32  res = ber_tag(o, p, o->op->t_class, o->op->t_tag, &cons, opt, name);
33  if (res < 0)
34  return 0;
35  if (!res)
36  return odr_missing(o, opt, name);
37  if (o->direction == ODR_PRINT)
38  {
39  odr_prname(o, name);
40  odr_printf(o, "%s\n", (**p ? "TRUE" : "FALSE"));
41  return 1;
42  }
43  if (cons)
44  return 0;
45  if (o->direction == ODR_DECODE)
46  *p = (int *)odr_malloc(o, sizeof(int));
47  return ber_boolean(o, *p);
48 }
49 /*
50  * Local variables:
51  * c-basic-offset: 4
52  * c-file-style: "Stroustrup"
53  * indent-tabs-mode: nil
54  * End:
55  * vim: shiftwidth=4 tabstop=8 expandtab
56  */
57 
int t_class
Definition: odr-priv.h:107
#define ODR_UNIVERSAL
Definition: odr.h:65
#define ODR_PRINT
Definition: odr.h:97
int error
Definition: odr.h:128
char * name
Definition: initopt.c:18
int ber_tag(ODR o, void *p, int zclass, int tag, int *constructed, int opt, const char *name)
Encode/decode BER tags.
Definition: ber_tag.c:34
void * odr_malloc(ODR o, size_t size)
Definition: odr_mem.c:31
void odr_prname(ODR o, const char *name)
Definition: odr_util.c:18
Internal ODR definitions.
int ber_boolean(ODR o, int *val)
Definition: ber_bool.c:21
int direction
Definition: odr.h:126
int odr_bool(ODR o, Odr_bool **p, int opt, const char *name)
Definition: odr_bool.c:21
nmem_bool_t Odr_bool
Definition: odr.h:48
struct Odr_private * op
Definition: odr.h:132
int odr_missing(ODR o, int opt, const char *name)
Definition: odr_util.c:82
Definition: odr.h:124
int opt
Definition: initopt.c:19
#define ODR_BOOLEAN
Definition: odr.h:73
void odr_printf(ODR o, const char *fmt,...)
Definition: odr.c:290
#define ODR_DECODE
Definition: odr.h:95