Header files moved to include (used to be z39.50).
[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.3  1999-04-20 09:56:48  adam
8  * Added 'name' paramter to encoder/decoder routines (typedef Odr_fun).
9  * Modified all encoders/decoders to reflect this change.
10  *
11  * Revision 1.2  1999/01/08 11:23:27  adam
12  * Added const modifier to some of the BER/ODR encoding routines.
13  *
14  * Revision 1.1  1998/03/20 14:45:01  adam
15  * Implemented odr_enum and odr_set_of.
16  *
17  */
18
19 #include <odr.h>
20
21 /*
22  * Top level enum en/decoder.
23  * Returns 1 on success, 0 on error.
24  */
25 int odr_enum(ODR o, int **p, int opt, const char *name)
26 {
27     int res, cons = 0;
28
29     if (o->error)
30         return 0;
31     if (o->t_class < 0)
32     {
33         o->t_class = ODR_UNIVERSAL;
34         o->t_tag = ODR_ENUM;
35     }
36     if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt)) < 0)
37         return 0;
38     if (!res)
39         return opt;
40     if (o->direction == ODR_PRINT)
41     {
42         odr_prname(o, name);
43         fprintf(o->print, "%d\n", **p);
44         return 1;
45     }
46     if (cons)
47     {
48         o->error = OPROTO;
49         return 0;
50     }
51     if (o->direction == ODR_DECODE)
52         *p = (int *)odr_malloc(o, sizeof(int));
53     return ber_integer(o, *p);
54 }