1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2009 Index Data
3 * See the file LICENSE for details.
8 * \brief Implements ODR CHOICE codec
17 int odr_choice(ODR o, Odr_arm arm[], void *p, void *whichp,
20 int i, cl = -1, tg, cn, *which = (int *)whichp, bias = o->op->choice_bias;
24 if (o->direction != ODR_DECODE && !*(char**)p)
27 if (o->direction == ODR_DECODE)
32 o->op->choice_bias = -1;
34 if (o->direction == ODR_PRINT)
39 odr_printf(o, "choice\n");
42 for (i = 0; arm[i].fun; i++)
44 if (o->direction == ODR_DECODE)
46 if (bias >= 0 && bias != arm[i].which)
48 *which = arm[i].which;
50 else if (*which != arm[i].which)
53 if (arm[i].tagmode != ODR_NONE)
55 if (o->direction == ODR_DECODE && cl < 0)
57 if (o->op->stack_top && !odr_constructed_more(o))
59 if (ber_dectag(o->bp, &cl, &tg, &cn, odr_max(o)) <= 0)
62 else if (o->direction != ODR_DECODE)
67 if (tg == arm[i].tag && cl == arm[i].zclass)
69 if (arm[i].tagmode == ODR_IMPLICIT)
71 odr_implicit_settag(o, cl, tg);
72 return (*arm[i].fun)(o, (char **)p, 0, arm[i].name);
75 if (!odr_constructed_begin(o, p, cl, tg, 0))
77 return (*arm[i].fun)(o, (char **)p, 0, arm[i].name) &&
78 odr_constructed_end(o);
81 else /* no tagging. Have to poll type */
83 if ((*arm[i].fun)(o, (char **)p, 1, arm[i].name) && *(char**)p)
90 void odr_choice_bias(ODR o, int what)
92 if (o->op->enable_bias)
93 o->op->choice_bias = what;
96 void odr_choice_enable_bias (ODR o, int mode)
98 o->op->enable_bias = mode;
103 * c-file-style: "Stroustrup"
104 * indent-tabs-mode: nil
106 * vim: shiftwidth=4 tabstop=8 expandtab