2 * Copyright (c) 1995, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.3 1995-11-13 09:27:34 quinn
8 * Fiddling with the variant stuff.
10 * Revision 1.2 1995/11/01 16:34:56 quinn
11 * Making data1 look for tables in data1_tabpath
13 * Revision 1.1 1995/11/01 11:56:07 quinn
14 * Added Retrieval (data management) functions en masse.
32 static Z_Variant *read_variant(int argc, char **argv, ODR o)
34 Z_Variant *r = odr_malloc(o, sizeof(*r));
38 var1.proto = PROTO_Z3950;
39 var1.class = CLASS_VARSET;
40 var1.value = VAL_VAR1;
41 r->globalVariantSetId = odr_oiddup(o, oid_getoidbyent(&var1));
43 r->triples = odr_malloc(o, sizeof(Z_Triple*) * argc);
44 r->num_triples = argc;
45 for (i = 0; i < argc; i++)
51 if (sscanf(argv[i], "(%d,%d,%[^)])", &class, &type, value) < 3)
53 logf(LOG_WARN, "Syntax error in variant component '%s'",
57 t = r->triples[i] = odr_malloc(o, sizeof(Z_Triple));
59 t->class = odr_malloc(o, sizeof(int));
61 t->type = odr_malloc(o, sizeof(int));
64 * This is wrong.. we gotta look up the correct type for the
65 * variant, I guess... damn this stuff.
69 t->which = Z_Triple_null;
70 t->value.null = ODR_NULLVAL;
74 t->which = Z_Triple_internationalString;
75 t->value.internationalString = odr_malloc(o, strlen(value)+1);
76 strcpy(t->value.internationalString, value);
82 static Z_Occurrences *read_occurrences(char *occ, ODR o)
84 Z_Occurrences *op = odr_malloc(o, sizeof(*op));
89 op->which = Z_Occurrences_values;
90 op->u.values = odr_malloc(o, sizeof(Z_OccurValues));
91 op->u.values->start = odr_malloc(o, sizeof(int));
92 *op->u.values->start = 1;
93 op->u.values->howMany = 0;
95 else if (!strcmp(occ, "all"))
97 op->which = Z_Occurrences_all;
98 op->u.all = ODR_NULLVAL;
100 else if (!strcmp(occ, "last"))
102 op->which = Z_Occurrences_last;
103 op->u.all = ODR_NULLVAL;
107 Z_OccurValues *ov = odr_malloc(o, sizeof(*ov));
111 logf(LOG_WARN, "Bad occurrences-spec in %s", occ);
114 op->which = Z_Occurrences_values;
116 ov->start = odr_malloc(o, sizeof(*ov->start));
117 *ov->start = atoi(occ);
118 if ((p = strchr(occ, '+')))
120 ov->howMany = odr_malloc(o, sizeof(*ov->howMany));
121 *ov->howMany = atoi(p + 1);
130 static Z_ETagUnit *read_tagunit(char *buf, ODR o)
132 Z_ETagUnit *u = odr_malloc(o, sizeof(*u));
135 char value[512], occ[512];
139 u->which = Z_ETagUnit_wildPath;
140 u->u.wildPath = ODR_NULLVAL;
142 else if (*buf == '?')
144 u->which = Z_ETagUnit_wildThing;
146 u->u.wildThing = read_occurrences(buf+2, o);
148 u->u.wildThing = read_occurrences(0, o);
150 else if ((terms = sscanf(buf, "(%d,%[^)]):%[a-z0-9+]", &type, value,
156 int force_string = 0;
163 u->which = Z_ETagUnit_specificTag;
164 u->u.specificTag = t = odr_malloc(o, sizeof(*t));
165 t->tagType = odr_malloc(o, sizeof(*t->tagType));
167 t->tagValue = odr_malloc(o, sizeof(*t->tagValue));
168 if (!force_string && (numval = atoi(valp)))
170 t->tagValue->which = Z_StringOrNumeric_numeric;
171 t->tagValue->u.numeric = odr_malloc(o, sizeof(int));
172 *t->tagValue->u.numeric = numval;
176 t->tagValue->which = Z_StringOrNumeric_string;
177 t->tagValue->u.string = odr_malloc(o, strlen(valp)+1);
178 strcpy(t->tagValue->u.string, valp);
180 if (terms > 2) /* an occurrences-spec exists */
181 t->occurrences = read_occurrences(occ, o);
189 * Read an element-set specification from a file.
190 * NOTE: If !o, memory is allocated directly from the heap by odr_malloc().
192 Z_Espec1 *data1_read_espec1(char *file, ODR o)
195 int argc, size_esn = 0;
196 char *argv[50], line[512];
197 Z_Espec1 *res = odr_malloc(o, sizeof(*res));
199 if (!(f = yaz_path_fopen(data1_tabpath, file, "r")))
201 logf(LOG_WARN|LOG_ERRNO, "%s", file);
205 res->num_elementSetNames = 0;
206 res->elementSetNames = 0;
207 res->defaultVariantSetId = 0;
208 res->defaultVariantRequest = 0;
209 res->defaultTagType = 0;
210 res->num_elements = 0;
213 while ((argc = readconf_line(f, line, 512, argv, 50)))
214 if (!strcmp(argv[0], "elementsetnames"))
216 int nnames = argc-1, i;
220 logf(LOG_WARN, "%s: Empty elementsetnames directive",
225 res->elementSetNames = odr_malloc(o, sizeof(char*)*nnames);
226 for (i = 0; i < nnames; i++)
228 res->elementSetNames[i] = odr_malloc(o, strlen(argv[i+1])+1);
229 strcpy(res->elementSetNames[i], argv[i+1]);
231 res->num_elementSetNames = nnames;
233 else if (!strcmp(argv[0], "defaultvariantsetid"))
235 if (argc != 2 || !(res->defaultVariantSetId =
236 odr_getoidbystr(o, argv[1])))
238 logf(LOG_WARN, "%s: Bad defaultvariantsetid directive", file);
242 else if (!strcmp(argv[0], "defaulttagtype"))
246 logf(LOG_WARN, "%s: Bad defaulttagtype directive", file);
249 res->defaultTagType = odr_malloc(o, sizeof(int));
250 *res->defaultTagType = atoi(argv[1]);
252 else if (!strcmp(argv[0], "defaultvariantrequest"))
254 if (!(res->defaultVariantRequest = read_variant(argc-1, argv+1, o)))
256 logf(LOG_WARN, "%s: Bad defaultvariantrequest", file);
260 else if (!strcmp(argv[0], "simpleelement"))
262 Z_ElementRequest *er;
265 char *path = argv[1];
270 res->elements = odr_malloc(o, size_esn = 24*sizeof(*er));
271 else if (res->num_elements >= size_esn)
274 res->elements = o ? odr_malloc(o, size_esn) :
275 xrealloc(res->elements, size_esn);
279 logf(LOG_WARN, "%s: Empty simpleelement directive", file);
283 res->elements[res->num_elements++] = er =
284 odr_malloc(o, sizeof(*er));
285 er->which = Z_ERequest_simpleElement;
286 er->u.simpleElement = se = odr_malloc(o, sizeof(*se));
287 se->variantRequest = 0;
288 se->path = tp = odr_malloc(o, sizeof(*tp));
291 * Parse the element selector.
293 for (num = 1, ep = path; (ep = strchr(ep, '/')); num++, ep++);
294 tp->tags = odr_malloc(o, sizeof(Z_ETagUnit*)*num);
296 for ((ep = strchr(path, '/')) ; path ; (void)((path = ep) &&
297 (ep = strchr(path, '/'))))
303 tp->tags[tp->num_tags++] = read_tagunit(path, o);
306 if (argc > 2 && !strcmp(argv[2], "variant"))
307 se->variantRequest= read_variant(argc-3, argv+3, o);
311 logf(LOG_WARN, "%s: Unknown directive %s", file, argv[0]);