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.15 2002-04-04 20:49:46 adam
8 * New functions yaz_is_abspath, yaz_path_fopen_base
10 * Revision 1.14 1999/11/30 13:47:12 adam
11 * Improved installation. Moved header files to include/yaz.
13 * Revision 1.13 1999/10/21 12:06:29 adam
14 * Retrieval module no longer uses ctype.h - functions.
16 * Revision 1.12 1999/08/27 09:40:32 adam
17 * Renamed logf function to yaz_log. Removed VC++ project files.
19 * Revision 1.11 1998/10/19 14:16:36 adam
20 * Fixed data1_gettagbyname. Bug introduced by previous revision.
22 * Revision 1.10 1998/10/15 08:29:17 adam
23 * Tag set type may be specified in reference to it using "tagset"
24 * directive in .abs-files and "include" directive in .tag-files.
26 * Revision 1.9 1998/10/13 16:09:53 adam
27 * Added support for arbitrary OID's for tagsets, schemas and attribute sets.
28 * Added support for multiple attribute set references and tagset references
29 * from an abstract syntax file.
30 * Fixed many bad logs-calls in routines that read the various
31 * specifications regarding data1 (*.abs,*.att,...) and made the messages
32 * consistent whenever possible.
33 * Added extra 'lineno' argument to function readconf_line.
35 * Revision 1.8 1998/05/18 13:07:07 adam
36 * Changed the way attribute sets are handled by the retriaval module.
37 * Extended Explain conversion / schema.
38 * Modified server and client to work with ASN.1 compiled protocol handlers.
40 * Revision 1.7 1998/02/11 11:53:35 adam
41 * Changed code so that it compiles as C++.
43 * Revision 1.6 1997/09/17 12:10:38 adam
46 * Revision 1.5 1997/09/05 09:50:57 adam
47 * Removed global data1_tabpath - uses data1_get_tabpath() instead.
49 * Revision 1.4 1995/11/13 09:27:38 quinn
50 * Fiddling with the variant stuff.
52 * Revision 1.3 1995/11/01 16:34:58 quinn
53 * Making data1 look for tables in data1_tabpath
55 * Revision 1.2 1995/11/01 13:54:49 quinn
58 * Revision 1.1 1995/11/01 11:56:09 quinn
59 * Added Retrieval (data management) functions en masse.
69 #include <yaz/data1.h>
72 * We'll probably want to add some sort of hashed index to these lookup-
73 * functions eventually.
76 data1_datatype data1_maptype (data1_handle dh, char *t)
84 {"structured", DATA1K_structured},
85 {"string", DATA1K_string},
86 {"numeric", DATA1K_numeric},
88 {"bool", DATA1K_bool},
89 {"generalizedtime", DATA1K_generalizedtime},
90 {"intunit", DATA1K_intunit},
92 {"octetstring", DATA1K_octetstring},
93 {"null", DATA1K_null},
94 {NULL, (data1_datatype) -1}
98 for (i = 0; types[i].tname; i++)
99 if (!data1_matchstr(types[i].tname, t))
100 return types[i].type;
101 return DATA1K_unknown;
104 data1_tag *data1_gettagbynum (data1_handle dh, data1_tagset *s,
109 for (; s; s = s->next)
113 for (r = s->tags; r; r = r->next)
114 if (r->which == DATA1T_numeric && r->value.numeric == value)
116 /* scan included sets */
118 (r = data1_gettagbynum (dh, s->children, type, value)))
124 data1_tag *data1_gettagbyname (data1_handle dh, data1_tagset *s,
129 for (; s; s = s->next)
132 for (r = s->tags; r; r = r->next)
136 for (np = r->names; np; np = np->next)
137 if (!data1_matchstr(np->name, name))
140 /* scan included sets */
141 if (s->children && (r = data1_gettagbyname (dh, s->children, name)))
147 data1_tagset *data1_empty_tagset (data1_handle dh)
150 (data1_tagset *) nmem_malloc(data1_nmem_get (dh), sizeof(*res));
152 res->reference = VAL_NONE;
160 data1_tagset *data1_read_tagset (data1_handle dh, const char *file, int type)
162 NMEM mem = data1_nmem_get (dh);
163 data1_tagset *res = 0;
164 data1_tagset **childp;
169 char *argv[50], line[512];
171 if (!(f = data1_path_fopen(dh, file, "r")))
173 yaz_log(LOG_WARN|LOG_ERRNO, "%s", file);
176 res = data1_empty_tagset (dh);
178 childp = &res->children;
181 while ((argc = readconf_line(f, &lineno, line, 512, argv, 50)))
184 if (!strcmp(cmd, "tag"))
187 char *names, *type, *nm;
193 yaz_log(LOG_WARN, "%s:%d: Bad # args to tag", file, lineno);
196 value = atoi(argv[1]);
200 rr = *tagp = (data1_tag *)nmem_malloc(mem, sizeof(*rr));
203 rr->which = DATA1T_numeric;
204 rr->value.numeric = value;
206 * how to deal with local numeric tags?
209 if (!(rr->kind = data1_maptype(dh, type)))
211 yaz_log(LOG_WARN, "%s:%d: Unknown datatype %s",
224 *npp = (data1_name *)nmem_malloc(mem, sizeof(**npp));
225 if ((e = strchr(nm, '/')))
227 (*npp)->name = nmem_strdup(mem, nm);
235 else if (!strcmp(cmd, "name"))
239 yaz_log(LOG_WARN, "%s:%d: Bad # args to name", file, lineno);
242 res->name = nmem_strdup(mem, argv[1]);
244 else if (!strcmp(cmd, "reference"))
250 yaz_log(LOG_WARN, "%s:%d: Bad # args to reference",
255 if ((res->reference = oid_getvalbyname(name)) == VAL_NONE)
257 yaz_log(LOG_WARN, "%s:%d: Unknown tagset ref '%s'",
262 else if (!strcmp(cmd, "type"))
266 yaz_log (LOG_WARN, "%s:%d: Bad # args to type", file, lineno);
270 res->type = atoi(argv[1]);
272 else if (!strcmp(cmd, "include"))
279 yaz_log(LOG_WARN, "%s:%d: Bad # args to include",
285 type = atoi(argv[2]);
286 *childp = data1_read_tagset (dh, name, type);
289 yaz_log(LOG_WARN, "%s:%d: Inclusion failed for tagset %s",
293 childp = &(*childp)->next;
297 yaz_log(LOG_WARN, "%s:%d: Unknown directive '%s'",