2 * Copyright (c) 1995-1998, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
6 * $Log: d1_tagset.c,v $
7 * Revision 1.11 1998-10-19 14:16:36 adam
8 * Fixed data1_gettagbyname. Bug introduced by previous revision.
10 * Revision 1.10 1998/10/15 08:29:17 adam
11 * Tag set type may be specified in reference to it using "tagset"
12 * directive in .abs-files and "include" directive in .tag-files.
14 * Revision 1.9 1998/10/13 16:09:53 adam
15 * Added support for arbitrary OID's for tagsets, schemas and attribute sets.
16 * Added support for multiple attribute set references and tagset references
17 * from an abstract syntax file.
18 * Fixed many bad logs-calls in routines that read the various
19 * specifications regarding data1 (*.abs,*.att,...) and made the messages
20 * consistent whenever possible.
21 * Added extra 'lineno' argument to function readconf_line.
23 * Revision 1.8 1998/05/18 13:07:07 adam
24 * Changed the way attribute sets are handled by the retriaval module.
25 * Extended Explain conversion / schema.
26 * Modified server and client to work with ASN.1 compiled protocol handlers.
28 * Revision 1.7 1998/02/11 11:53:35 adam
29 * Changed code so that it compiles as C++.
31 * Revision 1.6 1997/09/17 12:10:38 adam
34 * Revision 1.5 1997/09/05 09:50:57 adam
35 * Removed global data1_tabpath - uses data1_get_tabpath() instead.
37 * Revision 1.4 1995/11/13 09:27:38 quinn
38 * Fiddling with the variant stuff.
40 * Revision 1.3 1995/11/01 16:34:58 quinn
41 * Making data1 look for tables in data1_tabpath
43 * Revision 1.2 1995/11/01 13:54:49 quinn
46 * Revision 1.1 1995/11/01 11:56:09 quinn
47 * Added Retrieval (data management) functions en masse.
61 * We'll probably want to add some sort of hashed index to these lookup-
62 * functions eventually.
65 data1_datatype data1_maptype (data1_handle dh, char *t)
73 {"structured", DATA1K_structured},
74 {"string", DATA1K_string},
75 {"numeric", DATA1K_numeric},
77 {"bool", DATA1K_bool},
78 {"generalizedtime", DATA1K_generalizedtime},
79 {"intunit", DATA1K_intunit},
81 {"octetstring", DATA1K_octetstring},
82 {"null", DATA1K_null},
83 {NULL, (data1_datatype) -1}
87 for (i = 0; types[i].tname; i++)
88 if (!data1_matchstr(types[i].tname, t))
90 return DATA1K_unknown;
93 data1_tag *data1_gettagbynum (data1_handle dh, data1_tagset *s,
98 for (; s; s = s->next)
102 for (r = s->tags; r; r = r->next)
103 if (r->which == DATA1T_numeric && r->value.numeric == value)
105 /* scan included sets */
107 (r = data1_gettagbynum (dh, s->children, type, value)))
113 data1_tag *data1_gettagbyname (data1_handle dh, data1_tagset *s,
118 for (; s; s = s->next)
121 for (r = s->tags; r; r = r->next)
125 for (np = r->names; np; np = np->next)
126 if (!data1_matchstr(np->name, name))
129 /* scan included sets */
130 if (s->children && (r = data1_gettagbyname (dh, s->children, name)))
136 data1_tagset *data1_empty_tagset (data1_handle dh)
139 (data1_tagset *) nmem_malloc(data1_nmem_get (dh), sizeof(*res));
141 res->reference = VAL_NONE;
149 data1_tagset *data1_read_tagset (data1_handle dh, const char *file, int type)
151 NMEM mem = data1_nmem_get (dh);
152 data1_tagset *res = 0;
153 data1_tagset **childp;
158 char *argv[50], line[512];
160 if (!(f = yaz_path_fopen(data1_get_tabpath(dh), file, "r")))
162 logf(LOG_WARN|LOG_ERRNO, "%s", file);
165 res = data1_empty_tagset (dh);
167 childp = &res->children;
170 while ((argc = readconf_line(f, &lineno, line, 512, argv, 50)))
173 if (!strcmp(cmd, "tag"))
176 char *names, *type, *nm;
182 logf(LOG_WARN, "%s:%d: Bad # args to tag", file, lineno);
185 value = atoi(argv[1]);
189 rr = *tagp = (data1_tag *)nmem_malloc(mem, sizeof(*rr));
192 rr->which = DATA1T_numeric;
193 rr->value.numeric = value;
195 * how to deal with local numeric tags?
198 if (!(rr->kind = data1_maptype(dh, type)))
200 logf(LOG_WARN, "%s:%d: Unknown datatype %s",
213 *npp = (data1_name *)nmem_malloc(mem, sizeof(**npp));
214 if ((e = strchr(nm, '/')))
216 (*npp)->name = nmem_strdup(mem, nm);
224 else if (!strcmp(cmd, "name"))
228 logf(LOG_WARN, "%s:%d: Bad # args to name", file, lineno);
231 res->name = nmem_strdup(mem, argv[1]);
233 else if (!strcmp(cmd, "reference"))
239 logf(LOG_WARN, "%s:%d: Bad # args to reference", file, lineno);
243 if ((res->reference = oid_getvalbyname(name)) == VAL_NONE)
245 logf(LOG_WARN, "%s:%d: Unknown tagset ref '%s'",
250 else if (!strcmp(cmd, "type"))
254 logf (LOG_WARN, "%s:%d: Bad # args to type", file, lineno);
258 res->type = atoi(argv[1]);
260 else if (!strcmp(cmd, "include"))
267 logf(LOG_WARN, "%s:%d: Bad # args to include",
273 type = atoi(argv[2]);
274 *childp = data1_read_tagset (dh, name, type);
277 logf(LOG_WARN, "%s:%d: Inclusion failed for tagset %s",
281 childp = &(*childp)->next;
285 logf(LOG_WARN, "%s:%d: Unknown directive '%s'",