source: trunk/gsdl/packages/yaz/odr/odr_choice.c@ 1343

Last change on this file since 1343 was 1343, checked in by johnmcp, 24 years ago

Added the YAZ toolkit source to the packages directory (for z39.50 stuff)

  • Property svn:keywords set to Author Date Id Revision
File size: 3.6 KB
Line 
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:19 johnmcp
8 * Added the YAZ toolkit source to the packages directory (for z39.50 stuff)
9 *
10 * Revision 1.18 2000/02/29 13:44:55 adam
11 * Check for config.h (currently not generated).
12 *
13 * Revision 1.17 1999/11/30 13:47:11 adam
14 * Improved installation. Moved header files to include/yaz.
15 *
16 * Revision 1.16 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.15 1998/02/11 11:53:34 adam
21 * Changed code so that it compiles as C++.
22 *
23 * Revision 1.14 1997/05/14 06:53:57 adam
24 * C++ support.
25 *
26 * Revision 1.13 1997/04/30 08:52:10 quinn
27 * Null
28 *
29 * Revision 1.12 1996/10/08 12:58:17 adam
30 * New ODR function, odr_choice_enable_bias, to control behaviour of
31 * odr_choice_bias.
32 *
33 * Revision 1.11 1995/09/29 17:12:23 quinn
34 * Smallish
35 *
36 * Revision 1.10 1995/09/27 15:02:58 quinn
37 * Modified function heads & prototypes.
38 *
39 * Revision 1.9 1995/08/15 12:00:23 quinn
40 * Updated External
41 *
42 * Revision 1.8 1995/06/19 17:01:51 quinn
43 * This should bring us in sync with the version distributed as 1.0b
44 *
45 * Revision 1.7 1995/06/19 13:06:50 quinn
46 * Fixed simple bug in the code to handle untagged choice elements.
47 *
48 * Revision 1.6 1995/05/16 08:50:53 quinn
49 * License, documentation, and memory fixes
50 *
51 * Revision 1.5 1995/03/18 12:16:31 quinn
52 * Minor changes.
53 *
54 * Revision 1.4 1995/03/14 16:59:38 quinn
55 * Added odr_constructed_more check
56 *
57 * Revision 1.3 1995/03/08 12:12:22 quinn
58 * Added better error checking.
59 *
60 * Revision 1.2 1995/02/09 15:51:48 quinn
61 * Works better now.
62 *
63 * Revision 1.1 1995/02/07 17:52:59 quinn
64 * A damn mess, but now things work, I think.
65 *
66 */
67#if HAVE_CONFIG_H
68#include <config.h>
69#endif
70
71#include <yaz/odr.h>
72
73int odr_choice(ODR o, Odr_arm arm[], void *p, void *whichp,
74 const char *name)
75{
76 int i, cl = -1, tg, cn, *which = (int *)whichp, bias = o->choice_bias;
77
78 if (o->error)
79 return 0;
80 if (o->direction != ODR_DECODE && !*(char**)p)
81 return 0;
82 o->choice_bias = -1;
83
84 if (o->direction == ODR_PRINT)
85 {
86 if (name)
87 {
88 odr_prname(o, name);
89 fprintf (o->print, "choice\n");
90 }
91 }
92 for (i = 0; arm[i].fun; i++)
93 {
94 if (o->direction == ODR_DECODE)
95 {
96 if (bias >= 0 && bias != arm[i].which)
97 continue;
98 *which = arm[i].which;
99 }
100 else if (*which != arm[i].which)
101 continue;
102
103 if (arm[i].tagmode != ODR_NONE)
104 {
105 if (o->direction == ODR_DECODE && cl < 0)
106 {
107 if (o->stackp > -1 && !odr_constructed_more(o))
108 return 0;
109 if (ber_dectag(o->bp, &cl, &tg, &cn) <= 0)
110 return 0;
111 }
112 else if (o->direction != ODR_DECODE)
113 {
114 cl = arm[i].zclass;
115 tg = arm[i].tag;
116 }
117 if (tg == arm[i].tag && cl == arm[i].zclass)
118 {
119 if (arm[i].tagmode == ODR_IMPLICIT)
120 {
121 odr_implicit_settag(o, cl, tg);
122 return (*arm[i].fun)(o, (char **)p, 0, arm[i].name);
123 }
124 /* explicit */
125 if (!odr_constructed_begin(o, p, cl, tg, 0))
126 return 0;
127 return (*arm[i].fun)(o, (char **)p, 0, arm[i].name) &&
128 odr_constructed_end(o);
129 }
130 }
131 else /* no tagging. Have to poll type */
132 {
133 if ((*arm[i].fun)(o, (char **)p, 1, arm[i].name) && *(char**)p)
134 return 1;
135 }
136 }
137 *which = -1;
138 *(char*)p = 0;
139 return 0;
140}
141
142void odr_choice_bias(ODR o, int what)
143{
144 if (o->enable_bias)
145 o->choice_bias = what;
146}
147
148void odr_choice_enable_bias (ODR o, int mode)
149{
150 o->enable_bias = mode;
151}
Note: See TracBrowser for help on using the repository browser.