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.12 1999-08-27 09:40:32 adam
8 * Renamed logf function to yaz_log. Removed VC++ project files.
10 * Revision 1.11 1998/10/19 14:16:36 adam
11 * Fixed data1_gettagbyname. Bug introduced by previous revision.
13 * Revision 1.10 1998/10/15 08:29:17 adam
14 * Tag set type may be specified in reference to it using "tagset"
15 * directive in .abs-files and "include" directive in .tag-files.
17 * Revision 1.9 1998/10/13 16:09:53 adam
18 * Added support for arbitrary OID's for tagsets, schemas and attribute sets.
19 * Added support for multiple attribute set references and tagset references
20 * from an abstract syntax file.
21 * Fixed many bad logs-calls in routines that read the various
22 * specifications regarding data1 (*.abs,*.att,...) and made the messages
23 * consistent whenever possible.
24 * Added extra 'lineno' argument to function readconf_line.
26 * Revision 1.8 1998/05/18 13:07:07 adam
27 * Changed the way attribute sets are handled by the retriaval module.
28 * Extended Explain conversion / schema.
29 * Modified server and client to work with ASN.1 compiled protocol handlers.
31 * Revision 1.7 1998/02/11 11:53:35 adam
32 * Changed code so that it compiles as C++.
34 * Revision 1.6 1997/09/17 12:10:38 adam
37 * Revision 1.5 1997/09/05 09:50:57 adam
38 * Removed global data1_tabpath - uses data1_get_tabpath() instead.
40 * Revision 1.4 1995/11/13 09:27:38 quinn
41 * Fiddling with the variant stuff.
43 * Revision 1.3 1995/11/01 16:34:58 quinn
44 * Making data1 look for tables in data1_tabpath
46 * Revision 1.2 1995/11/01 13:54:49 quinn
49 * Revision 1.1 1995/11/01 11:56:09 quinn
50 * Added Retrieval (data management) functions en masse.
64 * We'll probably want to add some sort of hashed index to these lookup-
65 * functions eventually.
68 data1_datatype data1_maptype (data1_handle dh, char *t)
76 {"structured", DATA1K_structured},
77 {"string", DATA1K_string},
78 {"numeric", DATA1K_numeric},
80 {"bool", DATA1K_bool},
81 {"generalizedtime", DATA1K_generalizedtime},
82 {"intunit", DATA1K_intunit},
84 {"octetstring", DATA1K_octetstring},
85 {"null", DATA1K_null},
86 {NULL, (data1_datatype) -1}
90 for (i = 0; types[i].tname; i++)
91 if (!data1_matchstr(types[i].tname, t))
93 return DATA1K_unknown;
96 data1_tag *data1_gettagbynum (data1_handle dh, data1_tagset *s,
101 for (; s; s = s->next)
105 for (r = s->tags; r; r = r->next)
106 if (r->which == DATA1T_numeric && r->value.numeric == value)
108 /* scan included sets */
110 (r = data1_gettagbynum (dh, s->children, type, value)))
116 data1_tag *data1_gettagbyname (data1_handle dh, data1_tagset *s,
121 for (; s; s = s->next)
124 for (r = s->tags; r; r = r->next)
128 for (np = r->names; np; np = np->next)
129 if (!data1_matchstr(np->name, name))
132 /* scan included sets */
133 if (s->children && (r = data1_gettagbyname (dh, s->children, name)))
139 data1_tagset *data1_empty_tagset (data1_handle dh)
142 (data1_tagset *) nmem_malloc(data1_nmem_get (dh), sizeof(*res));
144 res->reference = VAL_NONE;
152 data1_tagset *data1_read_tagset (data1_handle dh, const char *file, int type)
154 NMEM mem = data1_nmem_get (dh);
155 data1_tagset *res = 0;
156 data1_tagset **childp;
161 char *argv[50], line[512];
163 if (!(f = yaz_path_fopen(data1_get_tabpath(dh), file, "r")))
165 yaz_log(LOG_WARN|LOG_ERRNO, "%s", file);
168 res = data1_empty_tagset (dh);
170 childp = &res->children;
173 while ((argc = readconf_line(f, &lineno, line, 512, argv, 50)))
176 if (!strcmp(cmd, "tag"))
179 char *names, *type, *nm;
185 yaz_log(LOG_WARN, "%s:%d: Bad # args to tag", file, lineno);
188 value = atoi(argv[1]);
192 rr = *tagp = (data1_tag *)nmem_malloc(mem, sizeof(*rr));
195 rr->which = DATA1T_numeric;
196 rr->value.numeric = value;
198 * how to deal with local numeric tags?
201 if (!(rr->kind = data1_maptype(dh, type)))
203 yaz_log(LOG_WARN, "%s:%d: Unknown datatype %s",
216 *npp = (data1_name *)nmem_malloc(mem, sizeof(**npp));
217 if ((e = strchr(nm, '/')))
219 (*npp)->name = nmem_strdup(mem, nm);
227 else if (!strcmp(cmd, "name"))
231 yaz_log(LOG_WARN, "%s:%d: Bad # args to name", file, lineno);
234 res->name = nmem_strdup(mem, argv[1]);
236 else if (!strcmp(cmd, "reference"))
242 yaz_log(LOG_WARN, "%s:%d: Bad # args to reference",
247 if ((res->reference = oid_getvalbyname(name)) == VAL_NONE)
249 yaz_log(LOG_WARN, "%s:%d: Unknown tagset ref '%s'",
254 else if (!strcmp(cmd, "type"))
258 yaz_log (LOG_WARN, "%s:%d: Bad # args to type", file, lineno);
262 res->type = atoi(argv[1]);
264 else if (!strcmp(cmd, "include"))
271 yaz_log(LOG_WARN, "%s:%d: Bad # args to include",
277 type = atoi(argv[2]);
278 *childp = data1_read_tagset (dh, name, type);
281 yaz_log(LOG_WARN, "%s:%d: Inclusion failed for tagset %s",
285 childp = &(*childp)->next;
289 yaz_log(LOG_WARN, "%s:%d: Unknown directive '%s'",