2 * Copyright (c) 1995, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.2 1995-11-01 16:34:56 quinn
8 * Making data1 look for tables in data1_tabpath
10 * Revision 1.1 1995/11/01 11:56:07 quinn
11 * Added Retrieval (data management) functions en masse.
30 * Read an element-set specification from a file. If !o, use xmalloc for
33 Z_Espec1 *data1_read_espec1(char *file, ODR o)
36 int argc, size_esn = 0;
37 char *argv[50], line[512];
38 Z_Espec1 *res = odr_malloc(o, sizeof(*res));
40 if (!(f = yaz_path_fopen(data1_tabpath, file, "r")))
42 logf(LOG_WARN|LOG_ERRNO, "%s", file);
46 res->num_elementSetNames = 0;
47 res->elementSetNames = 0;
48 res->defaultVariantSetId = 0;
49 res->defaultVariantRequest = 0;
50 res->defaultTagType = 0;
51 res->num_elements = 0;
54 while ((argc = readconf_line(f, line, 512, argv, 50)))
55 if (!strcmp(argv[0], "elementsetnames"))
57 int nnames = argc-1, i;
61 logf(LOG_WARN, "%s: Empty elementsetnames directive",
66 res->elementSetNames = odr_malloc(o, sizeof(char*)*nnames);
67 for (i = 0; i < nnames; i++)
69 res->elementSetNames[i] = odr_malloc(o, strlen(argv[i+1])+1);
70 strcpy(res->elementSetNames[i], argv[i+1]);
72 res->num_elementSetNames = nnames;
74 else if (!strcmp(argv[0], "defaultvariantsetid"))
76 if (argc != 2 || !(res->defaultVariantSetId =
77 odr_getoidbystr(o, argv[1])))
79 logf(LOG_WARN, "%s: Bad defaultvariantsetid directive", file);
83 else if (!strcmp(argv[0], "defaulttagtype"))
87 logf(LOG_WARN, "%s: Bad defaulttagtype directive", file);
90 res->defaultTagType = odr_malloc(o, sizeof(int));
91 *res->defaultTagType = atoi(argv[1]);
93 else if (!strcmp(argv[0], "defaultvariantrequest"))
97 else if (!strcmp(argv[0], "simpleelement"))
102 char *path = argv[1];
107 res->elements = odr_malloc(o, size_esn = 24*sizeof(*er));
108 else if (res->num_elements >= size_esn)
111 res->elements = o ? odr_malloc(o, size_esn) :
112 xrealloc(res->elements, size_esn);
116 logf(LOG_WARN, "%s: Empty simpleelement directive", file);
119 res->elements[res->num_elements++] = er =
120 odr_malloc(o, sizeof(*er));
121 er->which = Z_ERequest_simpleElement;
122 er->u.simpleElement = se = odr_malloc(o, sizeof(*se));
123 se->variantRequest = 0;
124 se->path = tp = odr_malloc(o, sizeof(*tp));
126 for (num = 1, ep = path; (ep = strchr(ep, '/')); num++, ep++);
127 tp->tags = odr_malloc(o, sizeof(Z_ETagUnit*)*num);
129 for ((ep = strchr(path, '/')) ; path ; (void)((path = ep) &&
130 (ep = strchr(path, '/'))))
140 tp->tags[tp->num_tags++] = u = odr_malloc(o, sizeof(*u));
141 if (sscanf(path, "(%d,%[^)])", &type, value) == 2)
146 int force_string = 0;
153 u->which = Z_ETagUnit_specificTag;
154 u->u.specificTag = t = odr_malloc(o, sizeof(*t));
155 t->tagType = odr_malloc(o, sizeof(*t->tagType));
157 t->tagValue = odr_malloc(o, sizeof(*t->tagValue));
158 if (!force_string && (numval = atoi(valp)))
160 t->tagValue->which = Z_StringOrNumeric_numeric;
161 t->tagValue->u.numeric = odr_malloc(o, sizeof(int));
162 *t->tagValue->u.numeric = numval;
166 t->tagValue->which = Z_StringOrNumeric_string;
167 t->tagValue->u.string = odr_malloc(o, strlen(valp)+1);
168 strcpy(t->tagValue->u.string, valp);
170 t->occurrences = 0; /* for later */
176 logf(LOG_WARN, "%s: Unknown directive %s", file, argv[0]);