1 | /*
|
---|
2 | * Copyright (c) 1995-2000, Index Data
|
---|
3 | * See the file LICENSE for details.
|
---|
4 | * Sebastian Hammer, Adam Dickmeiss
|
---|
5 | *
|
---|
6 | * $Log$
|
---|
7 | * Revision 1.1 2000/08/03 03:11:21 johnmcp
|
---|
8 | * Added the YAZ toolkit source to the packages directory (for z39.50 stuff)
|
---|
9 | *
|
---|
10 | * Revision 1.5 2000/02/29 13:44:55 adam
|
---|
11 | * Check for config.h (currently not generated).
|
---|
12 | *
|
---|
13 | * Revision 1.4 1999/11/30 13:47:11 adam
|
---|
14 | * Improved installation. Moved header files to include/yaz.
|
---|
15 | *
|
---|
16 | * Revision 1.3 1999/04/20 09:56:48 adam
|
---|
17 | * Added 'name' paramter to encoder/decoder routines (typedef Odr_fun).
|
---|
18 | * Modified all encoders/decoders to reflect this change.
|
---|
19 | *
|
---|
20 | * Revision 1.2 1999/01/08 11:23:27 adam
|
---|
21 | * Added const modifier to some of the BER/ODR encoding routines.
|
---|
22 | *
|
---|
23 | * Revision 1.1 1998/03/20 14:45:01 adam
|
---|
24 | * Implemented odr_enum and odr_set_of.
|
---|
25 | *
|
---|
26 | */
|
---|
27 | #if HAVE_CONFIG_H
|
---|
28 | #include <config.h>
|
---|
29 | #endif
|
---|
30 |
|
---|
31 | #include <yaz/odr.h>
|
---|
32 |
|
---|
33 | /*
|
---|
34 | * Top level enum en/decoder.
|
---|
35 | * Returns 1 on success, 0 on error.
|
---|
36 | */
|
---|
37 | int odr_enum(ODR o, int **p, int opt, const char *name)
|
---|
38 | {
|
---|
39 | int res, cons = 0;
|
---|
40 |
|
---|
41 | if (o->error)
|
---|
42 | return 0;
|
---|
43 | if (o->t_class < 0)
|
---|
44 | {
|
---|
45 | o->t_class = ODR_UNIVERSAL;
|
---|
46 | o->t_tag = ODR_ENUM;
|
---|
47 | }
|
---|
48 | if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt)) < 0)
|
---|
49 | return 0;
|
---|
50 | if (!res)
|
---|
51 | return opt;
|
---|
52 | if (o->direction == ODR_PRINT)
|
---|
53 | {
|
---|
54 | odr_prname(o, name);
|
---|
55 | fprintf(o->print, "%d\n", **p);
|
---|
56 | return 1;
|
---|
57 | }
|
---|
58 | if (cons)
|
---|
59 | {
|
---|
60 | o->error = OPROTO;
|
---|
61 | return 0;
|
---|
62 | }
|
---|
63 | if (o->direction == ODR_DECODE)
|
---|
64 | *p = (int *)odr_malloc(o, sizeof(int));
|
---|
65 | return ber_integer(o, *p);
|
---|
66 | }
|
---|