Directive s=pw sets structure to phrase if term includes blank(s).
[yaz-moved-to-github.git] / asn / prt-esp.c
1 /*
2  * Copyright (c) 1995-1999, Index Data.
3  * See the file LICENSE for details.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: prt-esp.c,v $
7  * Revision 1.5  1999-11-30 13:47:11  adam
8  * Improved installation. Moved header files to include/yaz.
9  *
10  * Revision 1.4  1999/04/20 09:56:47  adam
11  * Added 'name' paramter to encoder/decoder routines (typedef Odr_fun).
12  * Modified all encoders/decoders to reflect this change.
13  *
14  * Revision 1.3  1998/02/11 11:53:32  adam
15  * Changed code so that it compiles as C++.
16  *
17  * Revision 1.2  1998/02/10 15:31:46  adam
18  * Implemented date and time structure. Changed the Update Extended
19  * Service.
20  *
21  * Revision 1.1  1995/10/12 10:34:37  quinn
22  * Added Espec-1.
23  *
24  *
25  */
26
27 #include <yaz/proto.h>
28
29 int z_OccurValues(ODR o, Z_OccurValues **p, int opt, const char *name)
30 {
31     if (!odr_sequence_begin(o, p, sizeof(**p), 0))
32         return opt && odr_ok(o);
33     return
34         odr_implicit(o, odr_integer, &(*p)->start, ODR_CONTEXT, 1, 0) &&
35         odr_implicit(o, odr_integer, &(*p)->howMany, ODR_CONTEXT, 2, 1) &&
36         odr_sequence_end(o);
37 }
38
39 int z_Occurrences(ODR o, Z_Occurrences **p, int opt, const char *name)
40 {
41     static Odr_arm arm[] =
42     {
43         {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_Occurrences_all,
44          (Odr_fun)odr_null, 0},
45         {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_Occurrences_last,
46          (Odr_fun)odr_null, 0},
47         {ODR_IMPLICIT, ODR_CONTEXT, 3, Z_Occurrences_values,
48          (Odr_fun)z_OccurValues, 0},
49         {-1, -1, -1, -1, 0, 0}
50     };
51     
52     if (o->direction == ODR_DECODE)
53         *p = (Z_Occurrences *)odr_malloc(o, sizeof(**p));
54     else if (!*p)
55         return opt;
56     if (odr_choice(o, arm, &(*p)->u, &(*p)->which, 0))
57         return 1;
58     *p = 0;
59     return opt && odr_ok(o);
60 }
61
62 int z_SpecificTag(ODR o, Z_SpecificTag **p, int opt, const char *name)
63 {
64     if (!odr_sequence_begin(o, p, sizeof(**p), 0))
65         return opt && odr_ok(o);
66     return
67         odr_implicit(o, odr_oid, &(*p)->schemaId, ODR_CONTEXT, 0, 1) &&
68         odr_implicit(o, odr_integer, &(*p)->tagType, ODR_CONTEXT, 1, 1) &&
69         odr_explicit(o, z_StringOrNumeric, &(*p)->tagValue, ODR_CONTEXT,
70                      2, 0) &&
71         odr_explicit(o, z_Occurrences, &(*p)->occurrences,
72                      ODR_CONTEXT, 3, 1) &&
73         odr_sequence_end(o);
74 }
75
76 int z_ETagUnit(ODR o, Z_ETagUnit **p, int opt, const char *name)
77 {
78     static Odr_arm arm[] =
79     {
80         {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_ETagUnit_specificTag,
81          (Odr_fun)z_SpecificTag, 0},
82         {ODR_EXPLICIT, ODR_CONTEXT, 2, Z_ETagUnit_wildThing,
83          (Odr_fun)z_Occurrences, 0},
84         {ODR_IMPLICIT, ODR_CONTEXT, 3, Z_ETagUnit_wildPath,
85          (Odr_fun)odr_null, 0},
86         {-1, -1, -1 -1, 0, 0}
87     };
88     
89     if (o->direction == ODR_DECODE)
90         *p = (Z_ETagUnit *)odr_malloc(o, sizeof(**p));
91     else if (!*p)
92         return opt;
93     if (odr_choice(o, arm, &(*p)->u, &(*p)->which, 0))
94         return 1;
95     *p = 0;
96     return opt && odr_ok(o);
97 }
98
99 int z_ETagPath(ODR o, Z_ETagPath **p, int opt, const char *name)
100 {
101     if (o->direction == ODR_DECODE)
102         *p = (Z_ETagPath *)odr_malloc(o, sizeof(**p));
103     else if (!*p)
104         return opt;
105     if (odr_sequence_of(o, (Odr_fun)z_ETagUnit, &(*p)->tags,
106                         &(*p)->num_tags, 0))
107         return 1;
108     *p = 0;
109     return opt && odr_ok(o);
110 }
111
112 int z_SimpleElement(ODR o, Z_SimpleElement **p, int opt, const char *name)
113 {
114     if (!odr_sequence_begin(o, p, sizeof(**p), 0))
115         return opt && odr_ok(o);
116     return
117         odr_implicit(o, z_ETagPath, &(*p)->path, ODR_CONTEXT, 1, 0) &&
118         odr_implicit(o, z_Variant, &(*p)->variantRequest,
119                      ODR_CONTEXT, 2, 1) &&
120         odr_sequence_end(o);
121 }
122
123 int z_CompoPrimitives(ODR o, Z_CompoPrimitives **p, int opt, const char *name)
124 {
125     if (o->direction == ODR_DECODE)
126         *p = (Z_CompoPrimitives *)odr_malloc(o, sizeof(**p));
127     else if (!*p)
128         return opt;
129     if (odr_sequence_of(o, z_InternationalString, &(*p)->primitives,
130                         &(*p)->num_primitives, 0))
131         return 1;
132     *p = 0;
133     return opt && odr_ok(o);
134 }
135
136 int z_CompoSpecs(ODR o, Z_CompoSpecs **p, int opt, const char *name)
137 {
138     if (o->direction == ODR_DECODE)
139         *p = (Z_CompoSpecs *)odr_malloc(o, sizeof(**p));
140     else if (!*p)
141         return opt;
142     if (odr_sequence_of(o, (Odr_fun)z_SimpleElement, &(*p)->specs,
143                         &(*p)->num_specs, 0))
144         return 1;
145     *p = 0;
146     return opt && odr_ok(o);
147 }
148
149 int z_CompositeElement(ODR o, Z_CompositeElement **p, int opt,
150                        const char *name)
151 {
152     static Odr_arm arm[] =
153     {
154         {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_CompoElement_primitives,
155          (Odr_fun)z_CompoPrimitives, 0},
156         {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_CompoElement_specs,
157          (Odr_fun)z_CompoSpecs, 0},
158         {-1, -1, -1, -1, 0, 0}
159     };
160     
161     if (!odr_sequence_begin(o, p, sizeof(**p), 0))
162         return opt && odr_ok(o);
163     return
164         odr_constructed_begin(o, &(*p)->elementList, ODR_CONTEXT, 1, 0) &&
165         odr_choice(o, arm, &(*p)->elementList, &(*p)->which, 0) &&
166         odr_constructed_end(o) &&
167         odr_implicit(o, z_ETagPath, &(*p)->deliveryTag, ODR_CONTEXT, 2, 0) &&
168         odr_implicit(o, z_Variant, &(*p)->variantRequest, ODR_CONTEXT, 3, 1) &&
169         odr_sequence_end(o);
170 }
171
172 int z_ElementRequest(ODR o, Z_ElementRequest **p, int opt, const char *name)
173 {
174     static Odr_arm arm[] =
175     {
176         {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_ERequest_simpleElement,
177          (Odr_fun)z_SimpleElement, 0},
178         {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_ERequest_compositeElement,
179          (Odr_fun)z_CompositeElement, 0},
180         {-1, -1, -1 -1, 0, 0}
181     };
182     
183     if (o->direction == ODR_DECODE)
184         *p = (Z_ElementRequest *)odr_malloc(o, sizeof(**p));
185     else if (!*p)
186         return opt;
187     if (odr_choice(o, arm, &(*p)->u, &(*p)->which, 0))
188         return 1;
189     *p = 0;
190     return opt && odr_ok(o);
191 }
192
193 int z_Espec1(ODR o, Z_Espec1 **p, int opt, const char *name)
194 {
195     if (!odr_sequence_begin(o, p, sizeof(**p), 0))
196         return opt && odr_ok(o);
197     return
198         odr_implicit_settag(o, ODR_CONTEXT, 1) &&
199         (odr_sequence_of(o, z_InternationalString, &(*p)->elementSetNames,
200                          &(*p)->num_elementSetNames, 0) || odr_ok(o)) &&
201         odr_implicit(o, odr_oid, &(*p)->defaultVariantSetId,
202                      ODR_CONTEXT, 2, 1) &&
203         odr_implicit(o, z_Variant, &(*p)->defaultVariantRequest,
204                      ODR_CONTEXT, 3, 1) &&
205         odr_implicit(o, odr_integer, &(*p)->defaultTagType,
206                      ODR_CONTEXT, 4, 1) &&
207         odr_implicit_settag(o, ODR_CONTEXT, 5) &&
208         (odr_sequence_of(o, (Odr_fun)z_ElementRequest, &(*p)->elements,
209                          &(*p)->num_elements, 0) || odr_ok(o)) &&
210         odr_sequence_end(o);
211 }