2 * Copyright (c) 1995, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
6 * $Log: d1_tagset.c,v $
7 * Revision 1.5 1997-09-05 09:50:57 adam
8 * Removed global data1_tabpath - uses data1_get_tabpath() instead.
10 * Revision 1.4 1995/11/13 09:27:38 quinn
11 * Fiddling with the variant stuff.
13 * Revision 1.3 1995/11/01 16:34:58 quinn
14 * Making data1 look for tables in data1_tabpath
16 * Revision 1.2 1995/11/01 13:54:49 quinn
19 * Revision 1.1 1995/11/01 11:56:09 quinn
20 * Added Retrieval (data management) functions en masse.
37 * We'll probably want to add some sort of hashed index to these lookup-
38 * functions eventually.
41 data1_datatype data1_maptype(char *t)
49 {"structured", DATA1K_structured},
50 {"string", DATA1K_string},
51 {"numeric", DATA1K_numeric},
53 {"bool", DATA1K_bool},
54 {"generalizedtime", DATA1K_generalizedtime},
55 {"intunit", DATA1K_intunit},
57 {"octetstring", DATA1K_octetstring},
58 {"null", DATA1K_null},
63 for (i = 0; types[i].tname; i++)
64 if (!data1_matchstr(types[i].tname, t))
69 data1_tag *data1_gettagbynum(data1_tagset *s, int type, int value)
73 for (; s; s = s->next)
77 for (r = s->tags; r; r = r->next)
78 if (r->which == DATA1T_numeric && r->value.numeric == value)
80 /* scan included sets */
81 if (s->children && (r = data1_gettagbynum(s->children, type, value)))
87 data1_tag *data1_gettagbyname(data1_tagset *s, char *name)
91 for (; s; s = s->next)
94 for (r = s->tags; r; r = r->next)
98 for (np = r->names; np; np = np->next)
99 if (!data1_matchstr(np->name, name))
102 /* scan included sets */
103 if (s->children && (r = data1_gettagbyname(s->children, name)))
109 data1_tagset *data1_read_tagset(char *file)
111 char line[512], *r, cmd[512], args[512];
112 data1_tagset *res = 0, **childp;
116 if (!(f = yaz_path_fopen(data1_get_tabpath(), file, "r")))
118 logf(LOG_WARN|LOG_ERRNO, "%s", file);
122 if (!(res = xmalloc(sizeof(*res))))
129 childp = &res->children;
134 while ((r = fgets(line, 512, f)))
136 while (*r && isspace(*r))
146 if (sscanf(r, "%s %[^\n]", cmd, args) < 2)
148 if (!strcmp(cmd, "tag"))
151 char names[512], type[512], *nm;
155 if (sscanf(args, "%d %s %s", &value, names, type) < 3)
157 logf(LOG_WARN, "Bad number of parms in '%s' in %s",
162 if (!(rr = *tagp = xmalloc(sizeof(*rr))))
167 rr->which = DATA1T_numeric;
168 rr->value.numeric = value;
170 * how to deal with local numeric tags?
173 if (!(rr->kind = data1_maptype(type)))
175 logf(LOG_WARN, "Unknown datatype %s in %s", type, file);
187 if (!(*npp = xmalloc(sizeof(**npp))))
189 if ((e = strchr(nm, '/')))
191 if (!((*npp)->name = xmalloc(strlen(nm)+1)))
193 strcpy((*npp)->name, nm);
201 else if (!strcmp(cmd, "name"))
205 if (!sscanf(args, "%s", name))
207 logf(LOG_WARN, "%s malformed name directive in %s", file);
211 if (!(res->name = xmalloc(strlen(args)+1)))
213 strcpy(res->name, name);
215 else if (!strcmp(cmd, "reference"))
219 if (!sscanf(args, "%s", name))
221 logf(LOG_WARN, "%s malformed reference directive in %s", file);
225 if ((res->reference = oid_getvalbyname(name)) == VAL_NONE)
227 logf(LOG_WARN, "Unknown tagset ref '%s' in %s", name, file);
232 else if (!strcmp(cmd, "type"))
234 if (!sscanf(args, "%d", &res->type))
236 logf(LOG_WARN, "%s malformed type directive in %s", file);
241 else if (!strcmp(cmd, "include"))
245 if (!sscanf(args, "%s", name))
247 logf(LOG_WARN, "%s malformed reference directive in %s", file);
251 if (!(*childp = data1_read_tagset(name)))
253 logf(LOG_WARN, "Inclusion failed in %s", file);
257 childp = &(*childp)->next;
261 logf(LOG_WARN, "Unknown directive '%s' in %s", cmd, file);