Added const modifier to some of the BER/ODR encoding routines.
[yaz-moved-to-github.git] / odr / odr_enum.c
1 /*
2  * Copyright (c) 1995-1999, Index Data
3  * See the file LICENSE for details.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: odr_enum.c,v $
7  * Revision 1.2  1999-01-08 11:23:27  adam
8  * Added const modifier to some of the BER/ODR encoding routines.
9  *
10  * Revision 1.1  1998/03/20 14:45:01  adam
11  * Implemented odr_enum and odr_set_of.
12  *
13  */
14
15 #include <odr.h>
16
17 /*
18  * Top level enum en/decoder.
19  * Returns 1 on success, 0 on error.
20  */
21 int odr_enum(ODR o, int **p, int opt)
22 {
23     int res, cons = 0;
24
25     if (o->error)
26         return 0;
27     if (o->t_class < 0)
28     {
29         o->t_class = ODR_UNIVERSAL;
30         o->t_tag = ODR_ENUM;
31     }
32     if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt)) < 0)
33         return 0;
34     if (!res)
35         return opt;
36     if (o->direction == ODR_PRINT)
37     {
38         fprintf(o->print, "%s%d\n", odr_indent(o), **p);
39         return 1;
40     }
41     if (cons)
42     {
43         o->error = OPROTO;
44         return 0;
45     }
46     if (o->direction == ODR_DECODE)
47         *p = (int *)odr_malloc(o, sizeof(int));
48     return ber_integer(o, *p);
49 }