30 #include <yaz/proto.h>
32 #include <yaz/oid_db.h>
35 const char *file,
int lineno)
37 Z_Variant *r = (Z_Variant *)nmem_malloc(nmem,
sizeof(*r));
40 r->globalVariantSetId = odr_oiddup_nmem(nmem, yaz_oid_varset_variant_1);
42 r->triples = (Z_Triple **)nmem_malloc(nmem,
sizeof(Z_Triple*) * argc);
45 r->num_triples = argc;
46 for (i = 0; i < argc; i++)
52 if (sscanf(argv[i],
"(%d,%d,%511[^)])", &zclass, &type, value) < 3)
54 yaz_log(YLOG_WARN,
"%s:%d: Syntax error in variant component '%s'",
55 file, lineno, argv[i]);
58 t = r->triples[i] = (Z_Triple *)nmem_malloc(nmem,
sizeof(Z_Triple));
60 t->zclass = nmem_intdup(nmem, zclass);
61 t->type = nmem_intdup(nmem, type);
68 t->which = Z_Triple_null;
69 t->value.null = odr_nullval();
73 t->which = Z_Triple_integer;
74 t->value.integer = nmem_intdup(nmem, atoi(value));
78 t->which = Z_Triple_internationalString;
79 t->value.internationalString = nmem_strdup(nmem, value);
86 const char *file,
int lineno)
88 Z_Occurrences *op = (Z_Occurrences *)nmem_malloc(nmem,
sizeof(*op));
93 op->which = Z_Occurrences_values;
94 op->u.values = (Z_OccurValues *)
95 nmem_malloc(nmem,
sizeof(Z_OccurValues));
96 op->u.values->start = nmem_intdup(nmem, 1);
97 op->u.values->howMany = 0;
99 else if (!strcmp(occ,
"all"))
101 op->which = Z_Occurrences_all;
102 op->u.all = odr_nullval();
104 else if (!strcmp(occ,
"last"))
106 op->which = Z_Occurrences_last;
107 op->u.all = odr_nullval();
111 Z_OccurValues *ov = (Z_OccurValues *)nmem_malloc(nmem,
sizeof(*ov));
115 yaz_log(YLOG_WARN,
"%s:%d: Bad occurrences-spec %s",
119 op->which = Z_Occurrences_values;
121 ov->start = nmem_intdup(nmem, atoi(occ));
122 if ((p = strchr(occ,
'+')))
123 ov->howMany = nmem_intdup(nmem, atoi(p + 1));
132 const char *file,
int lineno)
134 Z_ETagUnit *u = (Z_ETagUnit *)nmem_malloc(nmem,
sizeof(*u));
137 char value[512], occ[512];
141 u->which = Z_ETagUnit_wildPath;
142 u->u.wildPath = odr_nullval();
144 else if (*buf ==
'?')
146 u->which = Z_ETagUnit_wildThing;
152 else if ((terms = sscanf(buf,
"(%d,%511[^)]):%511[a-zA-Z0-9+]",
153 &type, value, occ)) >= 2)
158 int force_string = 0;
164 if (*valp && valp[strlen(valp)-1] ==
'\'')
167 u->which = Z_ETagUnit_specificTag;
168 u->u.specificTag = t = (Z_SpecificTag *)nmem_malloc(nmem,
sizeof(*t));
169 t->tagType = nmem_intdup(nmem, type);
170 t->tagValue = (Z_StringOrNumeric *)
171 nmem_malloc(nmem,
sizeof(*t->tagValue));
172 if (!force_string && isdigit(*(
unsigned char *)valp))
175 t->tagValue->which = Z_StringOrNumeric_numeric;
176 t->tagValue->u.numeric = nmem_intdup(nmem, numval);
180 t->tagValue->which = Z_StringOrNumeric_string;
181 t->tagValue->u.string = nmem_strdup(nmem, valp);
188 else if ((terms = sscanf(buf,
"%511[^)]", value)) >= 1)
193 u->which = Z_ETagUnit_specificTag;
194 u->u.specificTag = t = (Z_SpecificTag *)nmem_malloc(nmem,
sizeof(*t));
195 t->tagType = nmem_intdup(nmem, 3);
196 t->tagValue = (Z_StringOrNumeric *)
197 nmem_malloc(nmem,
sizeof(*t->tagValue));
198 t->tagValue->which = Z_StringOrNumeric_string;
199 t->tagValue->u.string = nmem_strdup(nmem, valp);
218 int argc, size_esn = 0;
219 char *argv[50], line[512];
220 Z_Espec1 *res = (Z_Espec1 *)nmem_malloc(nmem,
sizeof(*res));
225 res->num_elementSetNames = 0;
226 res->elementSetNames = 0;
227 res->defaultVariantSetId = 0;
228 res->defaultVariantRequest = 0;
229 res->defaultTagType = 0;
230 res->num_elements = 0;
233 while ((argc = readconf_line(f, &lineno, line, 512, argv, 50)))
234 if (!strcmp(argv[0],
"elementsetnames"))
236 int nnames = argc-1, i;
240 yaz_log(YLOG_WARN,
"%s:%d: Empty elementsetnames directive",
245 res->elementSetNames =
246 (
char **)nmem_malloc(nmem,
sizeof(
char**)*nnames);
247 for (i = 0; i < nnames; i++)
249 res->elementSetNames[i] = nmem_strdup(nmem, argv[i+1]);
251 res->num_elementSetNames = nnames;
253 else if (!strcmp(argv[0],
"defaultvariantsetid"))
257 yaz_log(YLOG_WARN,
"%s:%d: Bad # of args for %s",
258 file, lineno, argv[0]);
261 if (!(res->defaultVariantSetId =
262 odr_getoidbystr_nmem(nmem, argv[1])))
264 yaz_log(YLOG_WARN,
"%s:%d: Bad defaultvariantsetid",
269 else if (!strcmp(argv[0],
"defaulttagtype"))
273 yaz_log(YLOG_WARN,
"%s:%d: Bad # of args for %s",
274 file, lineno, argv[0]);
277 res->defaultTagType = nmem_intdup(nmem, atoi(argv[1]));
279 else if (!strcmp(argv[0],
"defaultvariantrequest"))
281 if (!(res->defaultVariantRequest =
284 yaz_log(YLOG_WARN,
"%s:%d: Bad defaultvariantrequest",
289 else if (!strcmp(argv[0],
"simpleelement"))
291 Z_ElementRequest *er;
294 char *path = argv[1];
299 res->elements = (Z_ElementRequest **)
300 nmem_malloc(nmem, size_esn = 24*
sizeof(er));
301 else if (res->num_elements >= (
int) (size_esn/
sizeof(er)))
303 Z_ElementRequest **oe = res->elements;
305 res->elements = (Z_ElementRequest **)
306 nmem_malloc (nmem, size_esn*
sizeof(er));
307 memcpy (res->elements, oe, size_esn/2);
311 yaz_log(YLOG_WARN,
"%s:%d: Bad # of args for %s",
312 file, lineno, argv[0]);
316 res->elements[res->num_elements++] = er =
317 (Z_ElementRequest *)nmem_malloc(nmem,
sizeof(*er));
318 er->which = Z_ERequest_simpleElement;
319 er->u.simpleElement = se = (Z_SimpleElement *)
320 nmem_malloc(nmem,
sizeof(*se));
321 se->variantRequest = 0;
322 se->path = tp = (Z_ETagPath *)nmem_malloc(nmem,
sizeof(*tp));
327 for (num = 1, ep = path; (ep = strchr(ep,
'/')); num++, ep++)
329 tp->tags = (Z_ETagUnit **)
330 nmem_malloc(nmem,
sizeof(Z_ETagUnit*)*num);
332 for ((ep = strchr(path,
'/')) ; path ;
333 (void)((path = ep) && (ep = strchr(path,
'/'))))
343 yaz_log (YLOG_WARN,
"%s%d: Bad tag unit at %s",
347 tp->tags[tp->num_tags++] = tagunit;
350 if (argc > 2 && !strcmp(argv[2],
"variant"))
355 yaz_log(YLOG_WARN,
"%s:%d: Unknown directive '%s'",
356 file, lineno, argv[0]);
static Z_ETagUnit * read_tagunit(char *buf, NMEM nmem, const char *file, int lineno)
Z_Espec1 * data1_read_espec1(data1_handle dh, const char *file)
static Z_Occurrences * read_occurrences(char *occ, NMEM nmem, const char *file, int lineno)
static Z_Variant * read_variant(int argc, char **argv, NMEM nmem, const char *file, int lineno)
FILE * data1_path_fopen(data1_handle dh, const char *file, const char *mode)
NMEM data1_nmem_get(data1_handle dh)