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.13 1999-10-21 12:06:29 adam
8 * Retrieval module no longer uses ctype.h - functions.
10 * Revision 1.12 1999/08/27 09:40:32 adam
11 * Renamed logf function to yaz_log. Removed VC++ project files.
13 * Revision 1.11 1998/10/19 14:16:36 adam
14 * Fixed data1_gettagbyname. Bug introduced by previous revision.
16 * Revision 1.10 1998/10/15 08:29:17 adam
17 * Tag set type may be specified in reference to it using "tagset"
18 * directive in .abs-files and "include" directive in .tag-files.
20 * Revision 1.9 1998/10/13 16:09:53 adam
21 * Added support for arbitrary OID's for tagsets, schemas and attribute sets.
22 * Added support for multiple attribute set references and tagset references
23 * from an abstract syntax file.
24 * Fixed many bad logs-calls in routines that read the various
25 * specifications regarding data1 (*.abs,*.att,...) and made the messages
26 * consistent whenever possible.
27 * Added extra 'lineno' argument to function readconf_line.
29 * Revision 1.8 1998/05/18 13:07:07 adam
30 * Changed the way attribute sets are handled by the retriaval module.
31 * Extended Explain conversion / schema.
32 * Modified server and client to work with ASN.1 compiled protocol handlers.
34 * Revision 1.7 1998/02/11 11:53:35 adam
35 * Changed code so that it compiles as C++.
37 * Revision 1.6 1997/09/17 12:10:38 adam
40 * Revision 1.5 1997/09/05 09:50:57 adam
41 * Removed global data1_tabpath - uses data1_get_tabpath() instead.
43 * Revision 1.4 1995/11/13 09:27:38 quinn
44 * Fiddling with the variant stuff.
46 * Revision 1.3 1995/11/01 16:34:58 quinn
47 * Making data1 look for tables in data1_tabpath
49 * Revision 1.2 1995/11/01 13:54:49 quinn
52 * Revision 1.1 1995/11/01 11:56:09 quinn
53 * Added Retrieval (data management) functions en masse.
66 * We'll probably want to add some sort of hashed index to these lookup-
67 * functions eventually.
70 data1_datatype data1_maptype (data1_handle dh, char *t)
78 {"structured", DATA1K_structured},
79 {"string", DATA1K_string},
80 {"numeric", DATA1K_numeric},
82 {"bool", DATA1K_bool},
83 {"generalizedtime", DATA1K_generalizedtime},
84 {"intunit", DATA1K_intunit},
86 {"octetstring", DATA1K_octetstring},
87 {"null", DATA1K_null},
88 {NULL, (data1_datatype) -1}
92 for (i = 0; types[i].tname; i++)
93 if (!data1_matchstr(types[i].tname, t))
95 return DATA1K_unknown;
98 data1_tag *data1_gettagbynum (data1_handle dh, data1_tagset *s,
103 for (; s; s = s->next)
107 for (r = s->tags; r; r = r->next)
108 if (r->which == DATA1T_numeric && r->value.numeric == value)
110 /* scan included sets */
112 (r = data1_gettagbynum (dh, s->children, type, value)))
118 data1_tag *data1_gettagbyname (data1_handle dh, data1_tagset *s,
123 for (; s; s = s->next)
126 for (r = s->tags; r; r = r->next)
130 for (np = r->names; np; np = np->next)
131 if (!data1_matchstr(np->name, name))
134 /* scan included sets */
135 if (s->children && (r = data1_gettagbyname (dh, s->children, name)))
141 data1_tagset *data1_empty_tagset (data1_handle dh)
144 (data1_tagset *) nmem_malloc(data1_nmem_get (dh), sizeof(*res));
146 res->reference = VAL_NONE;
154 data1_tagset *data1_read_tagset (data1_handle dh, const char *file, int type)
156 NMEM mem = data1_nmem_get (dh);
157 data1_tagset *res = 0;
158 data1_tagset **childp;
163 char *argv[50], line[512];
165 if (!(f = yaz_path_fopen(data1_get_tabpath(dh), file, "r")))
167 yaz_log(LOG_WARN|LOG_ERRNO, "%s", file);
170 res = data1_empty_tagset (dh);
172 childp = &res->children;
175 while ((argc = readconf_line(f, &lineno, line, 512, argv, 50)))
178 if (!strcmp(cmd, "tag"))
181 char *names, *type, *nm;
187 yaz_log(LOG_WARN, "%s:%d: Bad # args to tag", file, lineno);
190 value = atoi(argv[1]);
194 rr = *tagp = (data1_tag *)nmem_malloc(mem, sizeof(*rr));
197 rr->which = DATA1T_numeric;
198 rr->value.numeric = value;
200 * how to deal with local numeric tags?
203 if (!(rr->kind = data1_maptype(dh, type)))
205 yaz_log(LOG_WARN, "%s:%d: Unknown datatype %s",
218 *npp = (data1_name *)nmem_malloc(mem, sizeof(**npp));
219 if ((e = strchr(nm, '/')))
221 (*npp)->name = nmem_strdup(mem, nm);
229 else if (!strcmp(cmd, "name"))
233 yaz_log(LOG_WARN, "%s:%d: Bad # args to name", file, lineno);
236 res->name = nmem_strdup(mem, argv[1]);
238 else if (!strcmp(cmd, "reference"))
244 yaz_log(LOG_WARN, "%s:%d: Bad # args to reference",
249 if ((res->reference = oid_getvalbyname(name)) == VAL_NONE)
251 yaz_log(LOG_WARN, "%s:%d: Unknown tagset ref '%s'",
256 else if (!strcmp(cmd, "type"))
260 yaz_log (LOG_WARN, "%s:%d: Bad # args to type", file, lineno);
264 res->type = atoi(argv[1]);
266 else if (!strcmp(cmd, "include"))
273 yaz_log(LOG_WARN, "%s:%d: Bad # args to include",
279 type = atoi(argv[2]);
280 *childp = data1_read_tagset (dh, name, type);
283 yaz_log(LOG_WARN, "%s:%d: Inclusion failed for tagset %s",
287 childp = &(*childp)->next;
291 yaz_log(LOG_WARN, "%s:%d: Unknown directive '%s'",