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.6 1997-09-17 12:10:38 adam
10 * Revision 1.5 1997/09/05 09:50:57 adam
11 * Removed global data1_tabpath - uses data1_get_tabpath() instead.
13 * Revision 1.4 1995/11/13 09:27:38 quinn
14 * Fiddling with the variant stuff.
16 * Revision 1.3 1995/11/01 16:34:58 quinn
17 * Making data1 look for tables in data1_tabpath
19 * Revision 1.2 1995/11/01 13:54:49 quinn
22 * Revision 1.1 1995/11/01 11:56:09 quinn
23 * Added Retrieval (data management) functions en masse.
39 * We'll probably want to add some sort of hashed index to these lookup-
40 * functions eventually.
43 data1_datatype data1_maptype (data1_handle dh, char *t)
51 {"structured", DATA1K_structured},
52 {"string", DATA1K_string},
53 {"numeric", DATA1K_numeric},
55 {"bool", DATA1K_bool},
56 {"generalizedtime", DATA1K_generalizedtime},
57 {"intunit", DATA1K_intunit},
59 {"octetstring", DATA1K_octetstring},
60 {"null", DATA1K_null},
65 for (i = 0; types[i].tname; i++)
66 if (!data1_matchstr(types[i].tname, t))
71 data1_tag *data1_gettagbynum (data1_handle dh, data1_tagset *s,
76 for (; s; s = s->next)
80 for (r = s->tags; r; r = r->next)
81 if (r->which == DATA1T_numeric && r->value.numeric == value)
83 /* scan included sets */
84 if (s->children && (r = data1_gettagbynum (dh, s->children,
91 data1_tag *data1_gettagbyname (data1_handle dh, data1_tagset *s, char *name)
95 for (; s; s = s->next)
98 for (r = s->tags; r; r = r->next)
102 for (np = r->names; np; np = np->next)
103 if (!data1_matchstr(np->name, name))
106 /* scan included sets */
107 if (s->children && (r = data1_gettagbyname (dh, s->children, name)))
113 data1_tagset *data1_read_tagset (data1_handle dh, char *file)
115 NMEM mem = data1_nmem_get (dh);
116 char line[512], *r, cmd[512], args[512];
117 data1_tagset *res = 0, **childp;
121 if (!(f = yaz_path_fopen(data1_get_tabpath(dh), file, "r")))
123 logf(LOG_WARN|LOG_ERRNO, "%s", file);
127 res = nmem_malloc(mem, sizeof(*res));
133 childp = &res->children;
138 while ((r = fgets(line, 512, f)))
140 while (*r && isspace(*r))
150 if (sscanf(r, "%s %[^\n]", cmd, args) < 2)
152 if (!strcmp(cmd, "tag"))
155 char names[512], type[512], *nm;
159 if (sscanf(args, "%d %s %s", &value, names, type) < 3)
161 logf(LOG_WARN, "Bad number of parms in '%s' in %s",
166 rr = *tagp = nmem_malloc(mem, sizeof(*rr));
169 rr->which = DATA1T_numeric;
170 rr->value.numeric = value;
172 * how to deal with local numeric tags?
175 if (!(rr->kind = data1_maptype(dh, type)))
177 logf(LOG_WARN, "Unknown datatype %s in %s", type, file);
189 *npp = nmem_malloc(mem, sizeof(**npp));
190 if ((e = strchr(nm, '/')))
192 (*npp)->name = nmem_strdup(mem, nm);
200 else if (!strcmp(cmd, "name"))
204 if (!sscanf(args, "%s", name))
206 logf(LOG_WARN, "%s malformed name directive in %s", file);
210 res->name = nmem_strdup(mem, args);
212 else if (!strcmp(cmd, "reference"))
216 if (!sscanf(args, "%s", name))
218 logf(LOG_WARN, "%s malformed reference directive in %s", file);
222 if ((res->reference = oid_getvalbyname(name)) == VAL_NONE)
224 logf(LOG_WARN, "Unknown tagset ref '%s' in %s", name, file);
229 else if (!strcmp(cmd, "type"))
231 if (!sscanf(args, "%d", &res->type))
233 logf(LOG_WARN, "%s malformed type directive in %s", file);
238 else if (!strcmp(cmd, "include"))
242 if (!sscanf(args, "%s", name))
244 logf(LOG_WARN, "%s malformed reference directive in %s", file);
248 if (!(*childp = data1_read_tagset (dh, name)))
250 logf(LOG_WARN, "Inclusion failed in %s", file);
254 childp = &(*childp)->next;
258 logf(LOG_WARN, "Unknown directive '%s' in %s", cmd, file);