YAZ  5.34.0
odr_enum.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  */
9 #if HAVE_CONFIG_H
10 #include <config.h>
11 #endif
12 
13 #include "odr-priv.h"
14 
15 /*
16  * Top level enum en/decoder.
17  * Returns 1 on success, 0 on error.
18  */
19 int odr_enum(ODR o, Odr_int **p, int opt, const char *name)
20 {
21  int res, cons = 0;
22 
23  if (o->error)
24  return 0;
25  if (o->op->t_class < 0)
26  {
27  o->op->t_class = ODR_UNIVERSAL;
28  o->op->t_tag = ODR_ENUM;
29  }
30  res = ber_tag(o, p, o->op->t_class, o->op->t_tag, &cons, opt, name);
31  if (res < 0)
32  return 0;
33  if (!res)
34  return odr_missing(o, opt, name);
35  if (o->direction == ODR_PRINT)
36  {
37  odr_prname(o, name);
38  odr_printf(o, "%d\n", **p);
39  return 1;
40  }
41  if (cons)
42  {
43  odr_seterror(o, OPROTO, 54);
44  return 0;
45  }
46  if (o->direction == ODR_DECODE)
47  *p = (Odr_int *)odr_malloc(o, sizeof(**p));
48  return ber_integer(o, *p);
49 }
50 /*
51  * Local variables:
52  * c-basic-offset: 4
53  * c-file-style: "Stroustrup"
54  * indent-tabs-mode: nil
55  * End:
56  * vim: shiftwidth=4 tabstop=8 expandtab
57  */
58 
int ber_integer(ODR o, Odr_int *val)
Definition: ber_int.c:33
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
int opt
Definition: initopt.c:19
char * name
Definition: initopt.c:18
Internal ODR definitions.
void odr_seterror(ODR o, int error, int id)
Definition: odr.c:118
void odr_printf(ODR o, const char *fmt,...)
Definition: odr.c:290
#define ODR_DECODE
Definition: odr.h:95
#define ODR_UNIVERSAL
Definition: odr.h:65
nmem_int_t Odr_int
Definition: odr.h:47
#define ODR_PRINT
Definition: odr.h:97
#define ODR_ENUM
Definition: odr.h:82
#define OPROTO
Definition: odr.h:157
int odr_enum(ODR o, Odr_int **p, int opt, const char *name)
Definition: odr_enum.c:19
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
int odr_missing(ODR o, int opt, const char *name)
Definition: odr_util.c:82
int t_class
Definition: odr-priv.h:107
Definition: odr.h:125
struct Odr_private * op
Definition: odr.h:132
int error
Definition: odr.h:128
int direction
Definition: odr.h:126