2 * Copyright (c) 1995-1998, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.15 1998-10-13 16:09:49 adam
8 * Added support for arbitrary OID's for tagsets, schemas and attribute sets.
9 * Added support for multiple attribute set references and tagset references
10 * from an abstract syntax file.
11 * Fixed many bad logs-calls in routines that read the various
12 * specifications regarding data1 (*.abs,*.att,...) and made the messages
13 * consistent whenever possible.
14 * Added extra 'lineno' argument to function readconf_line.
16 * Revision 1.14 1998/02/11 11:53:35 adam
17 * Changed code so that it compiles as C++.
19 * Revision 1.13 1997/11/24 11:33:56 adam
20 * Using function odr_nullval() instead of global ODR_NULLVAL when
23 * Revision 1.12 1997/10/31 12:20:09 adam
24 * Improved memory debugging for xmalloc/nmem.c. References to NMEM
25 * instead of ODR in n ESPEC-1 handling in source d1_espec.c.
26 * Bug fix: missing fclose in data1_read_espec1.
28 * Revision 1.11 1997/09/29 13:18:59 adam
29 * Added function, oid_ent_to_oid, to replace the function
30 * oid_getoidbyent, which is not thread safe.
32 * Revision 1.10 1997/09/29 07:21:10 adam
33 * Added typecast to avoid warnings on MSVC.
35 * Revision 1.9 1997/09/17 12:10:35 adam
38 * Revision 1.8 1997/09/05 09:50:56 adam
39 * Removed global data1_tabpath - uses data1_get_tabpath() instead.
41 * Revision 1.7 1997/05/14 06:54:02 adam
44 * Revision 1.6 1996/07/06 19:58:34 quinn
45 * System headerfiles gathered in yconfig
47 * Revision 1.5 1996/01/02 08:57:44 quinn
48 * Changed enums in the ASN.1 .h files to #defines. Changed oident.class to oclass
50 * Revision 1.4 1995/12/05 11:16:10 quinn
53 * Revision 1.3 1995/11/13 09:27:34 quinn
54 * Fiddling with the variant stuff.
56 * Revision 1.2 1995/11/01 16:34:56 quinn
57 * Making data1 look for tables in data1_tabpath
59 * Revision 1.1 1995/11/01 11:56:07 quinn
60 * Added Retrieval (data management) functions en masse.
75 static Z_Variant *read_variant(int argc, char **argv, NMEM nmem,
76 const char *file, int lineno)
78 Z_Variant *r = (Z_Variant *)nmem_malloc(nmem, sizeof(*r));
83 var1.proto = PROTO_Z3950;
84 var1.oclass = CLASS_VARSET;
85 var1.value = VAL_VAR1;
86 r->globalVariantSetId = odr_oiddup_nmem(nmem, oid_ent_to_oid(&var1, oid));
89 r->triples = (Z_Triple **)nmem_malloc(nmem, sizeof(Z_Triple*) * argc);
92 r->num_triples = argc;
93 for (i = 0; i < argc; i++)
99 if (sscanf(argv[i], "(%d,%d,%[^)])", &zclass, &type, value) < 3)
101 logf(LOG_WARN, "%s:%d: Syntax error in variant component '%s'",
102 file, lineno, argv[i]);
105 t = r->triples[i] = (Z_Triple *)nmem_malloc(nmem, sizeof(Z_Triple));
107 t->zclass = (int *)nmem_malloc(nmem, sizeof(int));
109 t->type = (int *)nmem_malloc(nmem, sizeof(int));
112 * This is wrong.. we gotta look up the correct type for the
113 * variant, I guess... damn this stuff.
117 t->which = Z_Triple_null;
118 t->value.null = odr_nullval();
120 else if (isdigit(*value))
122 t->which = Z_Triple_integer;
123 t->value.integer = (int *)
124 nmem_malloc(nmem, sizeof(*t->value.integer));
125 *t->value.integer = atoi(value);
129 t->which = Z_Triple_internationalString;
130 t->value.internationalString = (char *)
131 nmem_malloc(nmem, strlen(value)+1);
132 strcpy(t->value.internationalString, value);
138 static Z_Occurrences *read_occurrences(char *occ, NMEM nmem,
139 const char *file, int lineno)
141 Z_Occurrences *op = (Z_Occurrences *)nmem_malloc(nmem, sizeof(*op));
146 op->which = Z_Occurrences_values;
147 op->u.values = (Z_OccurValues *)
148 nmem_malloc(nmem, sizeof(Z_OccurValues));
149 op->u.values->start = (int *)nmem_malloc(nmem, sizeof(int));
150 *op->u.values->start = 1;
151 op->u.values->howMany = 0;
153 else if (!strcmp(occ, "all"))
155 op->which = Z_Occurrences_all;
156 op->u.all = odr_nullval();
158 else if (!strcmp(occ, "last"))
160 op->which = Z_Occurrences_last;
161 op->u.all = odr_nullval();
165 Z_OccurValues *ov = (Z_OccurValues *)nmem_malloc(nmem, sizeof(*ov));
169 logf(LOG_WARN, "%s:%d: Bad occurrences-spec %s",
173 op->which = Z_Occurrences_values;
175 ov->start = (int *)nmem_malloc(nmem, sizeof(*ov->start));
176 *ov->start = atoi(occ);
177 if ((p = strchr(occ, '+')))
179 ov->howMany = (int *)nmem_malloc(nmem, sizeof(*ov->howMany));
180 *ov->howMany = atoi(p + 1);
189 static Z_ETagUnit *read_tagunit(char *buf, NMEM nmem,
190 const char *file, int lineno)
192 Z_ETagUnit *u = (Z_ETagUnit *)nmem_malloc(nmem, sizeof(*u));
195 char value[512], occ[512];
199 u->which = Z_ETagUnit_wildPath;
200 u->u.wildPath = odr_nullval();
202 else if (*buf == '?')
204 u->which = Z_ETagUnit_wildThing;
206 u->u.wildThing = read_occurrences(buf+2, nmem, file, lineno);
208 u->u.wildThing = read_occurrences(0, nmem, file, lineno);
210 else if ((terms = sscanf(buf, "(%d,%[^)]):%[a-z0-9+]", &type, value,
216 int force_string = 0;
223 u->which = Z_ETagUnit_specificTag;
224 u->u.specificTag = t = (Z_SpecificTag *)nmem_malloc(nmem, sizeof(*t));
225 t->tagType = (int *)nmem_malloc(nmem, sizeof(*t->tagType));
227 t->tagValue = (Z_StringOrNumeric *)
228 nmem_malloc(nmem, sizeof(*t->tagValue));
229 if (!force_string && (numval = atoi(valp)))
231 t->tagValue->which = Z_StringOrNumeric_numeric;
232 t->tagValue->u.numeric = (int *)nmem_malloc(nmem, sizeof(int));
233 *t->tagValue->u.numeric = numval;
237 t->tagValue->which = Z_StringOrNumeric_string;
238 t->tagValue->u.string = (char *)nmem_malloc(nmem, strlen(valp)+1);
239 strcpy(t->tagValue->u.string, valp);
241 if (terms > 2) /* an occurrences-spec exists */
242 t->occurrences = read_occurrences(occ, nmem, file, lineno);
250 * Read an element-set specification from a file.
251 * NOTE: If !o, memory is allocated directly from the heap by nmem_malloc().
253 Z_Espec1 *data1_read_espec1 (data1_handle dh, const char *file)
256 NMEM nmem = data1_nmem_get (dh);
258 int argc, size_esn = 0;
259 char *argv[50], line[512];
260 Z_Espec1 *res = (Z_Espec1 *)nmem_malloc(nmem, sizeof(*res));
262 if (!(f = yaz_path_fopen(data1_get_tabpath(dh), file, "r")))
264 logf(LOG_WARN|LOG_ERRNO, "%s", file);
268 res->num_elementSetNames = 0;
269 res->elementSetNames = 0;
270 res->defaultVariantSetId = 0;
271 res->defaultVariantRequest = 0;
272 res->defaultTagType = 0;
273 res->num_elements = 0;
276 while ((argc = readconf_line(f, &lineno, line, 512, argv, 50)))
277 if (!strcmp(argv[0], "elementsetnames"))
279 int nnames = argc-1, i;
283 logf(LOG_WARN, "%s:%d: Empty elementsetnames directive",
288 res->elementSetNames =
289 (char **)nmem_malloc(nmem, sizeof(char**)*nnames);
290 for (i = 0; i < nnames; i++)
292 res->elementSetNames[i] = (char *)
293 nmem_malloc(nmem, strlen(argv[i+1])+1);
294 strcpy(res->elementSetNames[i], argv[i+1]);
296 res->num_elementSetNames = nnames;
298 else if (!strcmp(argv[0], "defaultvariantsetid"))
302 logf(LOG_WARN, "%s:%d: Bad # of args for %s",
303 file, lineno, argv[0]);
306 if (!(res->defaultVariantSetId =
307 odr_getoidbystr_nmem(nmem, argv[1])))
309 logf(LOG_WARN, "%s:%d: Bad defaultvariantsetid",
314 else if (!strcmp(argv[0], "defaulttagtype"))
318 logf(LOG_WARN, "%s:%d: Bad # of args for %s",
319 file, lineno, argv[0]);
322 res->defaultTagType = (int *)nmem_malloc(nmem, sizeof(int));
323 *res->defaultTagType = atoi(argv[1]);
325 else if (!strcmp(argv[0], "defaultvariantrequest"))
327 if (!(res->defaultVariantRequest =
328 read_variant(argc-1, argv+1, nmem, file, lineno)))
330 logf(LOG_WARN, "%s:%d: Bad defaultvariantrequest",
335 else if (!strcmp(argv[0], "simpleelement"))
337 Z_ElementRequest *er;
340 char *path = argv[1];
345 res->elements = (Z_ElementRequest **)
346 nmem_malloc(nmem, size_esn = 24*sizeof(er));
347 else if (res->num_elements >= (int) (size_esn/sizeof(er)))
349 Z_ElementRequest **oe = res->elements;
351 res->elements = (Z_ElementRequest **)
352 nmem_malloc (nmem, size_esn*sizeof(er));
353 memcpy (res->elements, oe, size_esn/2);
357 logf(LOG_WARN, "%s:%d: Bad # of args for %s",
358 file, lineno, argv[0]);
362 res->elements[res->num_elements++] = er =
363 (Z_ElementRequest *)nmem_malloc(nmem, sizeof(*er));
364 er->which = Z_ERequest_simpleElement;
365 er->u.simpleElement = se = (Z_SimpleElement *)
366 nmem_malloc(nmem, sizeof(*se));
367 se->variantRequest = 0;
368 se->path = tp = (Z_ETagPath *)nmem_malloc(nmem, sizeof(*tp));
371 * Parse the element selector.
373 for (num = 1, ep = path; (ep = strchr(ep, '/')); num++, ep++)
375 tp->tags = (Z_ETagUnit **)
376 nmem_malloc(nmem, sizeof(Z_ETagUnit*)*num);
378 for ((ep = strchr(path, '/')) ; path ;
379 (void)((path = ep) && (ep = strchr(path, '/'))))
385 tp->tags[tp->num_tags++] =
386 read_tagunit(path, nmem, file, lineno);
389 if (argc > 2 && !strcmp(argv[2], "variant"))
391 read_variant(argc-3, argv+3, nmem, file, lineno);
394 logf(LOG_WARN, "%s:%d: Unknown directive '%s'",
395 file, lineno, argv[0]);