2 * Copyright (c) 1995, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.4 1995-12-05 11:16:10 quinn
10 * Revision 1.3 1995/11/13 09:27:34 quinn
11 * Fiddling with the variant stuff.
13 * Revision 1.2 1995/11/01 16:34:56 quinn
14 * Making data1 look for tables in data1_tabpath
16 * Revision 1.1 1995/11/01 11:56:07 quinn
17 * Added Retrieval (data management) functions en masse.
35 static Z_Variant *read_variant(int argc, char **argv, ODR o)
37 Z_Variant *r = odr_malloc(o, sizeof(*r));
41 var1.proto = PROTO_Z3950;
42 var1.class = CLASS_VARSET;
43 var1.value = VAL_VAR1;
44 r->globalVariantSetId = odr_oiddup(o, oid_getoidbyent(&var1));
47 r->triples = odr_malloc(o, sizeof(Z_Triple*) * argc);
50 r->num_triples = argc;
51 for (i = 0; i < argc; i++)
57 if (sscanf(argv[i], "(%d,%d,%[^)])", &class, &type, value) < 3)
59 logf(LOG_WARN, "Syntax error in variant component '%s'",
63 t = r->triples[i] = odr_malloc(o, sizeof(Z_Triple));
65 t->class = odr_malloc(o, sizeof(int));
67 t->type = odr_malloc(o, sizeof(int));
70 * This is wrong.. we gotta look up the correct type for the
71 * variant, I guess... damn this stuff.
75 t->which = Z_Triple_null;
76 t->value.null = ODR_NULLVAL;
80 t->which = Z_Triple_internationalString;
81 t->value.internationalString = odr_malloc(o, strlen(value)+1);
82 strcpy(t->value.internationalString, value);
88 static Z_Occurrences *read_occurrences(char *occ, ODR o)
90 Z_Occurrences *op = odr_malloc(o, sizeof(*op));
95 op->which = Z_Occurrences_values;
96 op->u.values = odr_malloc(o, sizeof(Z_OccurValues));
97 op->u.values->start = odr_malloc(o, sizeof(int));
98 *op->u.values->start = 1;
99 op->u.values->howMany = 0;
101 else if (!strcmp(occ, "all"))
103 op->which = Z_Occurrences_all;
104 op->u.all = ODR_NULLVAL;
106 else if (!strcmp(occ, "last"))
108 op->which = Z_Occurrences_last;
109 op->u.all = ODR_NULLVAL;
113 Z_OccurValues *ov = odr_malloc(o, sizeof(*ov));
117 logf(LOG_WARN, "Bad occurrences-spec in %s", occ);
120 op->which = Z_Occurrences_values;
122 ov->start = odr_malloc(o, sizeof(*ov->start));
123 *ov->start = atoi(occ);
124 if ((p = strchr(occ, '+')))
126 ov->howMany = odr_malloc(o, sizeof(*ov->howMany));
127 *ov->howMany = atoi(p + 1);
136 static Z_ETagUnit *read_tagunit(char *buf, ODR o)
138 Z_ETagUnit *u = odr_malloc(o, sizeof(*u));
141 char value[512], occ[512];
145 u->which = Z_ETagUnit_wildPath;
146 u->u.wildPath = ODR_NULLVAL;
148 else if (*buf == '?')
150 u->which = Z_ETagUnit_wildThing;
152 u->u.wildThing = read_occurrences(buf+2, o);
154 u->u.wildThing = read_occurrences(0, o);
156 else if ((terms = sscanf(buf, "(%d,%[^)]):%[a-z0-9+]", &type, value,
162 int force_string = 0;
169 u->which = Z_ETagUnit_specificTag;
170 u->u.specificTag = t = odr_malloc(o, sizeof(*t));
171 t->tagType = odr_malloc(o, sizeof(*t->tagType));
173 t->tagValue = odr_malloc(o, sizeof(*t->tagValue));
174 if (!force_string && (numval = atoi(valp)))
176 t->tagValue->which = Z_StringOrNumeric_numeric;
177 t->tagValue->u.numeric = odr_malloc(o, sizeof(int));
178 *t->tagValue->u.numeric = numval;
182 t->tagValue->which = Z_StringOrNumeric_string;
183 t->tagValue->u.string = odr_malloc(o, strlen(valp)+1);
184 strcpy(t->tagValue->u.string, valp);
186 if (terms > 2) /* an occurrences-spec exists */
187 t->occurrences = read_occurrences(occ, o);
195 * Read an element-set specification from a file.
196 * NOTE: If !o, memory is allocated directly from the heap by odr_malloc().
198 Z_Espec1 *data1_read_espec1(char *file, ODR o)
201 int argc, size_esn = 0;
202 char *argv[50], line[512];
203 Z_Espec1 *res = odr_malloc(o, sizeof(*res));
205 if (!(f = yaz_path_fopen(data1_tabpath, file, "r")))
207 logf(LOG_WARN|LOG_ERRNO, "%s", file);
211 res->num_elementSetNames = 0;
212 res->elementSetNames = 0;
213 res->defaultVariantSetId = 0;
214 res->defaultVariantRequest = 0;
215 res->defaultTagType = 0;
216 res->num_elements = 0;
219 while ((argc = readconf_line(f, line, 512, argv, 50)))
220 if (!strcmp(argv[0], "elementsetnames"))
222 int nnames = argc-1, i;
226 logf(LOG_WARN, "%s: Empty elementsetnames directive",
231 res->elementSetNames = odr_malloc(o, sizeof(char*)*nnames);
232 for (i = 0; i < nnames; i++)
234 res->elementSetNames[i] = odr_malloc(o, strlen(argv[i+1])+1);
235 strcpy(res->elementSetNames[i], argv[i+1]);
237 res->num_elementSetNames = nnames;
239 else if (!strcmp(argv[0], "defaultvariantsetid"))
241 if (argc != 2 || !(res->defaultVariantSetId =
242 odr_getoidbystr(o, argv[1])))
244 logf(LOG_WARN, "%s: Bad defaultvariantsetid directive", file);
248 else if (!strcmp(argv[0], "defaulttagtype"))
252 logf(LOG_WARN, "%s: Bad defaulttagtype directive", file);
255 res->defaultTagType = odr_malloc(o, sizeof(int));
256 *res->defaultTagType = atoi(argv[1]);
258 else if (!strcmp(argv[0], "defaultvariantrequest"))
260 if (!(res->defaultVariantRequest = read_variant(argc-1, argv+1, o)))
262 logf(LOG_WARN, "%s: Bad defaultvariantrequest", file);
266 else if (!strcmp(argv[0], "simpleelement"))
268 Z_ElementRequest *er;
271 char *path = argv[1];
276 res->elements = odr_malloc(o, size_esn = 24*sizeof(*er));
277 else if (res->num_elements >= size_esn)
280 res->elements = o ? odr_malloc(o, size_esn) :
281 xrealloc(res->elements, size_esn);
285 logf(LOG_WARN, "%s: Empty simpleelement directive", file);
289 res->elements[res->num_elements++] = er =
290 odr_malloc(o, sizeof(*er));
291 er->which = Z_ERequest_simpleElement;
292 er->u.simpleElement = se = odr_malloc(o, sizeof(*se));
293 se->variantRequest = 0;
294 se->path = tp = odr_malloc(o, sizeof(*tp));
297 * Parse the element selector.
299 for (num = 1, ep = path; (ep = strchr(ep, '/')); num++, ep++);
300 tp->tags = odr_malloc(o, sizeof(Z_ETagUnit*)*num);
302 for ((ep = strchr(path, '/')) ; path ; (void)((path = ep) &&
303 (ep = strchr(path, '/'))))
309 tp->tags[tp->num_tags++] = read_tagunit(path, o);
312 if (argc > 2 && !strcmp(argv[2], "variant"))
313 se->variantRequest= read_variant(argc-3, argv+3, o);
317 logf(LOG_WARN, "%s: Unknown directive %s", file, argv[0]);