686aa63df5ad25cb23847cb6886d1174f32bea9f
[yaz-moved-to-github.git] / odr / odr_int.c
1 /*
2  * Copyright (C) 1994, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: odr_int.c,v $
7  * Revision 1.5  1995-03-08 12:12:25  quinn
8  * Added better error checking.
9  *
10  * Revision 1.4  1995/02/10  18:57:25  quinn
11  * More in the way of error-checking.
12  *
13  * Revision 1.3  1995/02/09  15:51:48  quinn
14  * Works better now.
15  *
16  * Revision 1.2  1995/02/07  14:13:45  quinn
17  * Bug fixes.
18  *
19  * Revision 1.1  1995/02/02  16:21:53  quinn
20  * First kick.
21  *
22  */
23
24 #include <odr.h>
25
26 /*
27  * Top level integer en/decoder.
28  * Returns 1 on success, 0 on error.
29  */
30 int odr_integer(ODR o, int **p, int opt)
31 {
32     int res, cons = 0;
33
34     if (o->error)
35         return 0;
36     if (o->t_class < 0)
37     {
38         o->t_class = ODR_UNIVERSAL;
39         o->t_tag = ODR_INTEGER;
40     }
41     if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt)) < 0)
42         return 0;
43     if (!res)
44         return opt;
45     if (o->direction == ODR_PRINT)
46     {
47         fprintf(o->print, "%s%d\n", odr_indent(o), **p);
48         return 1;
49     }
50     if (cons)
51     {
52         o->error = OPROTO;
53         return 0;
54     }
55     if (o->direction == ODR_DECODE)
56         *p = nalloc(o, sizeof(int));
57     return ber_integer(o, *p);
58 }