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.8 1998-05-18 13:07:07 adam
8 * Changed the way attribute sets are handled by the retriaval module.
9 * Extended Explain conversion / schema.
10 * Modified server and client to work with ASN.1 compiled protocol handlers.
12 * Revision 1.7 1998/02/11 11:53:35 adam
13 * Changed code so that it compiles as C++.
15 * Revision 1.6 1997/09/17 12:10:38 adam
18 * Revision 1.5 1997/09/05 09:50:57 adam
19 * Removed global data1_tabpath - uses data1_get_tabpath() instead.
21 * Revision 1.4 1995/11/13 09:27:38 quinn
22 * Fiddling with the variant stuff.
24 * Revision 1.3 1995/11/01 16:34:58 quinn
25 * Making data1 look for tables in data1_tabpath
27 * Revision 1.2 1995/11/01 13:54:49 quinn
30 * Revision 1.1 1995/11/01 11:56:09 quinn
31 * Added Retrieval (data management) functions en masse.
47 * We'll probably want to add some sort of hashed index to these lookup-
48 * functions eventually.
51 data1_datatype data1_maptype (data1_handle dh, char *t)
59 {"structured", DATA1K_structured},
60 {"string", DATA1K_string},
61 {"numeric", DATA1K_numeric},
63 {"bool", DATA1K_bool},
64 {"generalizedtime", DATA1K_generalizedtime},
65 {"intunit", DATA1K_intunit},
67 {"octetstring", DATA1K_octetstring},
68 {"null", DATA1K_null},
69 {NULL, (data1_datatype) -1}
73 for (i = 0; types[i].tname; i++)
74 if (!data1_matchstr(types[i].tname, t))
79 data1_tag *data1_gettagbynum (data1_handle dh, data1_tagset *s,
84 for (; s; s = s->next)
88 for (r = s->tags; r; r = r->next)
89 if (r->which == DATA1T_numeric && r->value.numeric == value)
91 /* scan included sets */
92 if (s->children && (r = data1_gettagbynum (dh, s->children,
99 data1_tag *data1_gettagbyname (data1_handle dh, data1_tagset *s, char *name)
103 for (; s; s = s->next)
106 for (r = s->tags; r; r = r->next)
110 for (np = r->names; np; np = np->next)
111 if (!data1_matchstr(np->name, name))
114 /* scan included sets */
115 if (s->children && (r = data1_gettagbyname (dh, s->children, name)))
121 data1_tagset *data1_read_tagset (data1_handle dh, char *file)
123 NMEM mem = data1_nmem_get (dh);
124 char line[512], *r, cmd[512], args[512];
125 data1_tagset *res = 0, **childp;
129 if (!(f = yaz_path_fopen(data1_get_tabpath(dh), file, "r")))
131 logf(LOG_WARN|LOG_ERRNO, "%s", file);
135 res = (data1_tagset *)nmem_malloc(mem, sizeof(*res));
141 childp = &res->children;
146 while ((r = fgets(line, 512, f)))
148 while (*r && isspace(*r))
158 if (sscanf(r, "%s %[^\n]", cmd, args) < 2)
160 if (!strcmp(cmd, "tag"))
163 char names[512], type[512], *nm;
167 if (sscanf(args, "%d %s %s", &value, names, type) < 3)
169 logf(LOG_WARN, "Bad number of parms in '%s' in %s",
174 rr = *tagp = (data1_tag *)nmem_malloc(mem, sizeof(*rr));
177 rr->which = DATA1T_numeric;
178 rr->value.numeric = value;
180 * how to deal with local numeric tags?
183 if (!(rr->kind = data1_maptype(dh, type)))
185 logf(LOG_WARN, "Unknown datatype %s in %s", type, file);
197 *npp = (data1_name *)nmem_malloc(mem, sizeof(**npp));
198 if ((e = strchr(nm, '/')))
200 (*npp)->name = nmem_strdup(mem, nm);
208 else if (!strcmp(cmd, "name"))
212 if (!sscanf(args, "%s", name))
214 logf(LOG_WARN, "%s malformed name directive in %s", file);
218 res->name = nmem_strdup(mem, args);
220 else if (!strcmp(cmd, "reference"))
224 if (!sscanf(args, "%s", name))
226 logf(LOG_WARN, "%s malformed reference directive in %s", file);
230 if ((res->reference = oid_getvalbyname(name)) == VAL_NONE)
232 logf(LOG_WARN, "Unknown tagset ref '%s' in %s", name, file);
237 else if (!strcmp(cmd, "type"))
239 if (!sscanf(args, "%d", &res->type))
241 logf(LOG_WARN, "%s malformed type directive in %s", file);
246 else if (!strcmp(cmd, "include"))
250 if (!sscanf(args, "%s", name))
252 logf(LOG_WARN, "%s malformed reference directive in %s", file);
256 if (!(*childp = data1_read_tagset (dh, name)))
258 logf(LOG_WARN, "Inclusion failed in %s", file);
262 childp = &(*childp)->next;
266 logf(LOG_WARN, "Unknown directive '%s' in %s", cmd, file);