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