2 * Copyright (c) 1995-1999, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
6 * $Log: d1_tagset.c,v $
7 * Revision 1.14 1999-11-30 13:47:12 adam
8 * Improved installation. Moved header files to include/yaz.
10 * Revision 1.13 1999/10/21 12:06:29 adam
11 * Retrieval module no longer uses ctype.h - functions.
13 * Revision 1.12 1999/08/27 09:40:32 adam
14 * Renamed logf function to yaz_log. Removed VC++ project files.
16 * Revision 1.11 1998/10/19 14:16:36 adam
17 * Fixed data1_gettagbyname. Bug introduced by previous revision.
19 * Revision 1.10 1998/10/15 08:29:17 adam
20 * Tag set type may be specified in reference to it using "tagset"
21 * directive in .abs-files and "include" directive in .tag-files.
23 * Revision 1.9 1998/10/13 16:09:53 adam
24 * Added support for arbitrary OID's for tagsets, schemas and attribute sets.
25 * Added support for multiple attribute set references and tagset references
26 * from an abstract syntax file.
27 * Fixed many bad logs-calls in routines that read the various
28 * specifications regarding data1 (*.abs,*.att,...) and made the messages
29 * consistent whenever possible.
30 * Added extra 'lineno' argument to function readconf_line.
32 * Revision 1.8 1998/05/18 13:07:07 adam
33 * Changed the way attribute sets are handled by the retriaval module.
34 * Extended Explain conversion / schema.
35 * Modified server and client to work with ASN.1 compiled protocol handlers.
37 * Revision 1.7 1998/02/11 11:53:35 adam
38 * Changed code so that it compiles as C++.
40 * Revision 1.6 1997/09/17 12:10:38 adam
43 * Revision 1.5 1997/09/05 09:50:57 adam
44 * Removed global data1_tabpath - uses data1_get_tabpath() instead.
46 * Revision 1.4 1995/11/13 09:27:38 quinn
47 * Fiddling with the variant stuff.
49 * Revision 1.3 1995/11/01 16:34:58 quinn
50 * Making data1 look for tables in data1_tabpath
52 * Revision 1.2 1995/11/01 13:54:49 quinn
55 * Revision 1.1 1995/11/01 11:56:09 quinn
56 * Added Retrieval (data management) functions en masse.
66 #include <yaz/data1.h>
69 * We'll probably want to add some sort of hashed index to these lookup-
70 * functions eventually.
73 data1_datatype data1_maptype (data1_handle dh, char *t)
81 {"structured", DATA1K_structured},
82 {"string", DATA1K_string},
83 {"numeric", DATA1K_numeric},
85 {"bool", DATA1K_bool},
86 {"generalizedtime", DATA1K_generalizedtime},
87 {"intunit", DATA1K_intunit},
89 {"octetstring", DATA1K_octetstring},
90 {"null", DATA1K_null},
91 {NULL, (data1_datatype) -1}
95 for (i = 0; types[i].tname; i++)
96 if (!data1_matchstr(types[i].tname, t))
98 return DATA1K_unknown;
101 data1_tag *data1_gettagbynum (data1_handle dh, data1_tagset *s,
106 for (; s; s = s->next)
110 for (r = s->tags; r; r = r->next)
111 if (r->which == DATA1T_numeric && r->value.numeric == value)
113 /* scan included sets */
115 (r = data1_gettagbynum (dh, s->children, type, value)))
121 data1_tag *data1_gettagbyname (data1_handle dh, data1_tagset *s,
126 for (; s; s = s->next)
129 for (r = s->tags; r; r = r->next)
133 for (np = r->names; np; np = np->next)
134 if (!data1_matchstr(np->name, name))
137 /* scan included sets */
138 if (s->children && (r = data1_gettagbyname (dh, s->children, name)))
144 data1_tagset *data1_empty_tagset (data1_handle dh)
147 (data1_tagset *) nmem_malloc(data1_nmem_get (dh), sizeof(*res));
149 res->reference = VAL_NONE;
157 data1_tagset *data1_read_tagset (data1_handle dh, const char *file, int type)
159 NMEM mem = data1_nmem_get (dh);
160 data1_tagset *res = 0;
161 data1_tagset **childp;
166 char *argv[50], line[512];
168 if (!(f = yaz_path_fopen(data1_get_tabpath(dh), file, "r")))
170 yaz_log(LOG_WARN|LOG_ERRNO, "%s", file);
173 res = data1_empty_tagset (dh);
175 childp = &res->children;
178 while ((argc = readconf_line(f, &lineno, line, 512, argv, 50)))
181 if (!strcmp(cmd, "tag"))
184 char *names, *type, *nm;
190 yaz_log(LOG_WARN, "%s:%d: Bad # args to tag", file, lineno);
193 value = atoi(argv[1]);
197 rr = *tagp = (data1_tag *)nmem_malloc(mem, sizeof(*rr));
200 rr->which = DATA1T_numeric;
201 rr->value.numeric = value;
203 * how to deal with local numeric tags?
206 if (!(rr->kind = data1_maptype(dh, type)))
208 yaz_log(LOG_WARN, "%s:%d: Unknown datatype %s",
221 *npp = (data1_name *)nmem_malloc(mem, sizeof(**npp));
222 if ((e = strchr(nm, '/')))
224 (*npp)->name = nmem_strdup(mem, nm);
232 else if (!strcmp(cmd, "name"))
236 yaz_log(LOG_WARN, "%s:%d: Bad # args to name", file, lineno);
239 res->name = nmem_strdup(mem, argv[1]);
241 else if (!strcmp(cmd, "reference"))
247 yaz_log(LOG_WARN, "%s:%d: Bad # args to reference",
252 if ((res->reference = oid_getvalbyname(name)) == VAL_NONE)
254 yaz_log(LOG_WARN, "%s:%d: Unknown tagset ref '%s'",
259 else if (!strcmp(cmd, "type"))
263 yaz_log (LOG_WARN, "%s:%d: Bad # args to type", file, lineno);
267 res->type = atoi(argv[1]);
269 else if (!strcmp(cmd, "include"))
276 yaz_log(LOG_WARN, "%s:%d: Bad # args to include",
282 type = atoi(argv[2]);
283 *childp = data1_read_tagset (dh, name, type);
286 yaz_log(LOG_WARN, "%s:%d: Inclusion failed for tagset %s",
290 childp = &(*childp)->next;
294 yaz_log(LOG_WARN, "%s:%d: Unknown directive '%s'",