2 * Copyright (c) 1995, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.9 1997-09-17 12:10:35 adam
10 * Revision 1.8 1997/09/05 09:50:56 adam
11 * Removed global data1_tabpath - uses data1_get_tabpath() instead.
13 * Revision 1.7 1997/05/14 06:54:02 adam
16 * Revision 1.6 1996/07/06 19:58:34 quinn
17 * System headerfiles gathered in yconfig
19 * Revision 1.5 1996/01/02 08:57:44 quinn
20 * Changed enums in the ASN.1 .h files to #defines. Changed oident.class to oclass
22 * Revision 1.4 1995/12/05 11:16:10 quinn
25 * Revision 1.3 1995/11/13 09:27:34 quinn
26 * Fiddling with the variant stuff.
28 * Revision 1.2 1995/11/01 16:34:56 quinn
29 * Making data1 look for tables in data1_tabpath
31 * Revision 1.1 1995/11/01 11:56:07 quinn
32 * Added Retrieval (data management) functions en masse.
50 static Z_Variant *read_variant(int argc, char **argv, ODR o)
52 Z_Variant *r = odr_malloc(o, sizeof(*r));
56 var1.proto = PROTO_Z3950;
57 var1.oclass = CLASS_VARSET;
58 var1.value = VAL_VAR1;
59 r->globalVariantSetId = odr_oiddup(o, oid_getoidbyent(&var1));
62 r->triples = odr_malloc(o, sizeof(Z_Triple*) * argc);
65 r->num_triples = argc;
66 for (i = 0; i < argc; i++)
72 if (sscanf(argv[i], "(%d,%d,%[^)])", &zclass, &type, value) < 3)
74 logf(LOG_WARN, "Syntax error in variant component '%s'",
78 t = r->triples[i] = odr_malloc(o, sizeof(Z_Triple));
80 t->zclass = odr_malloc(o, sizeof(int));
82 t->type = odr_malloc(o, sizeof(int));
85 * This is wrong.. we gotta look up the correct type for the
86 * variant, I guess... damn this stuff.
90 t->which = Z_Triple_null;
91 t->value.null = ODR_NULLVAL;
93 else if (isdigit(*value))
95 t->which = Z_Triple_integer;
96 t->value.integer = odr_malloc(o, sizeof(*t->value.integer));
97 *t->value.integer = atoi(value);
101 t->which = Z_Triple_internationalString;
102 t->value.internationalString = odr_malloc(o, strlen(value)+1);
103 strcpy(t->value.internationalString, value);
109 static Z_Occurrences *read_occurrences(char *occ, ODR o)
111 Z_Occurrences *op = odr_malloc(o, sizeof(*op));
116 op->which = Z_Occurrences_values;
117 op->u.values = odr_malloc(o, sizeof(Z_OccurValues));
118 op->u.values->start = odr_malloc(o, sizeof(int));
119 *op->u.values->start = 1;
120 op->u.values->howMany = 0;
122 else if (!strcmp(occ, "all"))
124 op->which = Z_Occurrences_all;
125 op->u.all = ODR_NULLVAL;
127 else if (!strcmp(occ, "last"))
129 op->which = Z_Occurrences_last;
130 op->u.all = ODR_NULLVAL;
134 Z_OccurValues *ov = odr_malloc(o, sizeof(*ov));
138 logf(LOG_WARN, "Bad occurrences-spec in %s", occ);
141 op->which = Z_Occurrences_values;
143 ov->start = odr_malloc(o, sizeof(*ov->start));
144 *ov->start = atoi(occ);
145 if ((p = strchr(occ, '+')))
147 ov->howMany = odr_malloc(o, sizeof(*ov->howMany));
148 *ov->howMany = atoi(p + 1);
157 static Z_ETagUnit *read_tagunit(char *buf, ODR o)
159 Z_ETagUnit *u = odr_malloc(o, sizeof(*u));
162 char value[512], occ[512];
166 u->which = Z_ETagUnit_wildPath;
167 u->u.wildPath = ODR_NULLVAL;
169 else if (*buf == '?')
171 u->which = Z_ETagUnit_wildThing;
173 u->u.wildThing = read_occurrences(buf+2, o);
175 u->u.wildThing = read_occurrences(0, o);
177 else if ((terms = sscanf(buf, "(%d,%[^)]):%[a-z0-9+]", &type, value,
183 int force_string = 0;
190 u->which = Z_ETagUnit_specificTag;
191 u->u.specificTag = t = odr_malloc(o, sizeof(*t));
192 t->tagType = odr_malloc(o, sizeof(*t->tagType));
194 t->tagValue = odr_malloc(o, sizeof(*t->tagValue));
195 if (!force_string && (numval = atoi(valp)))
197 t->tagValue->which = Z_StringOrNumeric_numeric;
198 t->tagValue->u.numeric = odr_malloc(o, sizeof(int));
199 *t->tagValue->u.numeric = numval;
203 t->tagValue->which = Z_StringOrNumeric_string;
204 t->tagValue->u.string = odr_malloc(o, strlen(valp)+1);
205 strcpy(t->tagValue->u.string, valp);
207 if (terms > 2) /* an occurrences-spec exists */
208 t->occurrences = read_occurrences(occ, o);
216 * Read an element-set specification from a file.
217 * NOTE: If !o, memory is allocated directly from the heap by odr_malloc().
219 Z_Espec1 *data1_read_espec1 (data1_handle dh, const char *file, ODR o)
222 int argc, size_esn = 0;
223 char *argv[50], line[512];
224 Z_Espec1 *res = odr_malloc(o, sizeof(*res));
226 if (!(f = yaz_path_fopen(data1_get_tabpath(dh), file, "r")))
228 logf(LOG_WARN|LOG_ERRNO, "%s", file);
232 res->num_elementSetNames = 0;
233 res->elementSetNames = 0;
234 res->defaultVariantSetId = 0;
235 res->defaultVariantRequest = 0;
236 res->defaultTagType = 0;
237 res->num_elements = 0;
240 while ((argc = readconf_line(f, line, 512, argv, 50)))
241 if (!strcmp(argv[0], "elementsetnames"))
243 int nnames = argc-1, i;
247 logf(LOG_WARN, "%s: Empty elementsetnames directive",
252 res->elementSetNames = odr_malloc(o, sizeof(char**)*nnames);
253 for (i = 0; i < nnames; i++)
255 res->elementSetNames[i] = odr_malloc(o, strlen(argv[i+1])+1);
256 strcpy(res->elementSetNames[i], argv[i+1]);
258 res->num_elementSetNames = nnames;
260 else if (!strcmp(argv[0], "defaultvariantsetid"))
262 if (argc != 2 || !(res->defaultVariantSetId =
263 odr_getoidbystr(o, argv[1])))
265 logf(LOG_WARN, "%s: Bad defaultvariantsetid directive", file);
269 else if (!strcmp(argv[0], "defaulttagtype"))
273 logf(LOG_WARN, "%s: Bad defaulttagtype directive", file);
276 res->defaultTagType = odr_malloc(o, sizeof(int));
277 *res->defaultTagType = atoi(argv[1]);
279 else if (!strcmp(argv[0], "defaultvariantrequest"))
281 if (!(res->defaultVariantRequest = read_variant(argc-1, argv+1, o)))
283 logf(LOG_WARN, "%s: Bad defaultvariantrequest", file);
287 else if (!strcmp(argv[0], "simpleelement"))
289 Z_ElementRequest *er;
292 char *path = argv[1];
297 res->elements = odr_malloc(o, size_esn = 24*sizeof(er));
298 else if (res->num_elements >= size_esn/sizeof(er))
303 Z_ElementRequest **oe = res->elements;
305 res->elements = odr_malloc (o, size_esn*sizeof(er));
306 memcpy (res->elements, oe, size_esn/2);
310 xrealloc(res->elements, size_esn*sizeof(er));
314 logf(LOG_WARN, "%s: Empty simpleelement directive", file);
318 res->elements[res->num_elements++] = er =
319 odr_malloc(o, sizeof(*er));
320 er->which = Z_ERequest_simpleElement;
321 er->u.simpleElement = se = odr_malloc(o, sizeof(*se));
322 se->variantRequest = 0;
323 se->path = tp = odr_malloc(o, sizeof(*tp));
326 * Parse the element selector.
328 for (num = 1, ep = path; (ep = strchr(ep, '/')); num++, ep++)
330 tp->tags = odr_malloc(o, sizeof(Z_ETagUnit*)*num);
332 for ((ep = strchr(path, '/')) ; path ;
333 (void)((path = ep) && (ep = strchr(path, '/'))))
339 tp->tags[tp->num_tags++] = read_tagunit(path, o);
342 if (argc > 2 && !strcmp(argv[2], "variant"))
343 se->variantRequest= read_variant(argc-3, argv+3, o);
347 logf(LOG_WARN, "%s: Unknown directive %s", file, argv[0]);