2 * Copyright (c) 1995, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.1 1995-11-01 11:56:07 quinn
8 * Added Retrieval (data management) functions en masse.
25 * Read an element-set specification from a file. If !o, use xmalloc for
28 Z_Espec1 *data1_read_espec1(char *file, ODR o)
31 int argc, size_esn = 0;
32 char *argv[50], line[512];
33 Z_Espec1 *res = odr_malloc(o, sizeof(*res));
35 if (!(f = fopen(file, "r")))
37 logf(LOG_WARN|LOG_ERRNO, "%s", file);
41 res->num_elementSetNames = 0;
42 res->elementSetNames = 0;
43 res->defaultVariantSetId = 0;
44 res->defaultVariantRequest = 0;
45 res->defaultTagType = 0;
46 res->num_elements = 0;
49 while ((argc = readconf_line(f, line, 512, argv, 50)))
50 if (!strcmp(argv[0], "elementsetnames"))
52 int nnames = argc-1, i;
56 logf(LOG_WARN, "%s: Empty elementsetnames directive",
61 res->elementSetNames = odr_malloc(o, sizeof(char*)*nnames);
62 for (i = 0; i < nnames; i++)
64 res->elementSetNames[i] = odr_malloc(o, strlen(argv[i+1])+1);
65 strcpy(res->elementSetNames[i], argv[i+1]);
67 res->num_elementSetNames = nnames;
69 else if (!strcmp(argv[0], "defaultvariantsetid"))
71 if (argc != 2 || !(res->defaultVariantSetId =
72 odr_getoidbystr(o, argv[1])))
74 logf(LOG_WARN, "%s: Bad defaultvariantsetid directive", file);
78 else if (!strcmp(argv[0], "defaulttagtype"))
82 logf(LOG_WARN, "%s: Bad defaulttagtype directive", file);
85 res->defaultTagType = odr_malloc(o, sizeof(int));
86 *res->defaultTagType = atoi(argv[1]);
88 else if (!strcmp(argv[0], "defaultvariantrequest"))
92 else if (!strcmp(argv[0], "simpleelement"))
102 res->elements = odr_malloc(o, size_esn = 24*sizeof(*er));
103 else if (res->num_elements >= size_esn)
106 res->elements = o ? odr_malloc(o, size_esn) :
107 xrealloc(res->elements, size_esn);
111 logf(LOG_WARN, "%s: Empty simpleelement directive", file);
114 res->elements[res->num_elements++] = er =
115 odr_malloc(o, sizeof(*er));
116 er->which = Z_ERequest_simpleElement;
117 er->u.simpleElement = se = odr_malloc(o, sizeof(*se));
118 se->variantRequest = 0;
119 se->path = tp = odr_malloc(o, sizeof(*tp));
121 for (num = 1, ep = path; (ep = strchr(ep, '/')); num++, ep++);
122 tp->tags = odr_malloc(o, sizeof(Z_ETagUnit*)*num);
124 for ((ep = strchr(path, '/')) ; path ; (void)((path = ep) &&
125 (ep = strchr(path, '/'))))
135 tp->tags[tp->num_tags++] = u = odr_malloc(o, sizeof(*u));
136 if (sscanf(path, "(%d,%[^)])", &type, value) == 2)
141 int force_string = 0;
148 u->which = Z_ETagUnit_specificTag;
149 u->u.specificTag = t = odr_malloc(o, sizeof(*t));
150 t->tagType = odr_malloc(o, sizeof(*t->tagType));
152 t->tagValue = odr_malloc(o, sizeof(*t->tagValue));
153 if (!force_string && (numval = atoi(valp)))
155 t->tagValue->which = Z_StringOrNumeric_numeric;
156 t->tagValue->u.numeric = odr_malloc(o, sizeof(int));
157 *t->tagValue->u.numeric = numval;
161 t->tagValue->which = Z_StringOrNumeric_string;
162 t->tagValue->u.string = odr_malloc(o, strlen(valp)+1);
163 strcpy(t->tagValue->u.string, valp);
165 t->occurrences = 0; /* for later */
171 logf(LOG_WARN, "%s: Unknown directive %s", file, argv[0]);