2 * Copyright (c) 1995-1997, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
6 * $Log: d1_tagset.c,v $
7 * Revision 1.7 1998-02-11 11:53:35 adam
8 * Changed code so that it compiles as C++.
10 * Revision 1.6 1997/09/17 12:10:38 adam
13 * Revision 1.5 1997/09/05 09:50:57 adam
14 * Removed global data1_tabpath - uses data1_get_tabpath() instead.
16 * Revision 1.4 1995/11/13 09:27:38 quinn
17 * Fiddling with the variant stuff.
19 * Revision 1.3 1995/11/01 16:34:58 quinn
20 * Making data1 look for tables in data1_tabpath
22 * Revision 1.2 1995/11/01 13:54:49 quinn
25 * Revision 1.1 1995/11/01 11:56:09 quinn
26 * Added Retrieval (data management) functions en masse.
42 * We'll probably want to add some sort of hashed index to these lookup-
43 * functions eventually.
46 data1_datatype data1_maptype (data1_handle dh, char *t)
54 {"structured", DATA1K_structured},
55 {"string", DATA1K_string},
56 {"numeric", DATA1K_numeric},
58 {"bool", DATA1K_bool},
59 {"generalizedtime", DATA1K_generalizedtime},
60 {"intunit", DATA1K_intunit},
62 {"octetstring", DATA1K_octetstring},
63 {"null", DATA1K_null},
68 for (i = 0; types[i].tname; i++)
69 if (!data1_matchstr(types[i].tname, t))
74 data1_tag *data1_gettagbynum (data1_handle dh, data1_tagset *s,
79 for (; s; s = s->next)
83 for (r = s->tags; r; r = r->next)
84 if (r->which == DATA1T_numeric && r->value.numeric == value)
86 /* scan included sets */
87 if (s->children && (r = data1_gettagbynum (dh, s->children,
94 data1_tag *data1_gettagbyname (data1_handle dh, data1_tagset *s, char *name)
98 for (; s; s = s->next)
101 for (r = s->tags; r; r = r->next)
105 for (np = r->names; np; np = np->next)
106 if (!data1_matchstr(np->name, name))
109 /* scan included sets */
110 if (s->children && (r = data1_gettagbyname (dh, s->children, name)))
116 data1_tagset *data1_read_tagset (data1_handle dh, char *file)
118 NMEM mem = data1_nmem_get (dh);
119 char line[512], *r, cmd[512], args[512];
120 data1_tagset *res = 0, **childp;
124 if (!(f = yaz_path_fopen(data1_get_tabpath(dh), file, "r")))
126 logf(LOG_WARN|LOG_ERRNO, "%s", file);
130 res = (data1_tagset *)nmem_malloc(mem, sizeof(*res));
136 childp = &res->children;
141 while ((r = fgets(line, 512, f)))
143 while (*r && isspace(*r))
153 if (sscanf(r, "%s %[^\n]", cmd, args) < 2)
155 if (!strcmp(cmd, "tag"))
158 char names[512], type[512], *nm;
162 if (sscanf(args, "%d %s %s", &value, names, type) < 3)
164 logf(LOG_WARN, "Bad number of parms in '%s' in %s",
169 rr = *tagp = (data1_tag *)nmem_malloc(mem, sizeof(*rr));
172 rr->which = DATA1T_numeric;
173 rr->value.numeric = value;
175 * how to deal with local numeric tags?
178 if (!(rr->kind = data1_maptype(dh, type)))
180 logf(LOG_WARN, "Unknown datatype %s in %s", type, file);
192 *npp = (data1_name *)nmem_malloc(mem, sizeof(**npp));
193 if ((e = strchr(nm, '/')))
195 (*npp)->name = nmem_strdup(mem, nm);
203 else if (!strcmp(cmd, "name"))
207 if (!sscanf(args, "%s", name))
209 logf(LOG_WARN, "%s malformed name directive in %s", file);
213 res->name = nmem_strdup(mem, args);
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 (dh, 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);