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.10 1998-10-15 08:29:17 adam
8 * Tag set type may be specified in reference to it using "tagset"
9 * directive in .abs-files and "include" directive in .tag-files.
11 * Revision 1.9 1998/10/13 16:09:53 adam
12 * Added support for arbitrary OID's for tagsets, schemas and attribute sets.
13 * Added support for multiple attribute set references and tagset references
14 * from an abstract syntax file.
15 * Fixed many bad logs-calls in routines that read the various
16 * specifications regarding data1 (*.abs,*.att,...) and made the messages
17 * consistent whenever possible.
18 * Added extra 'lineno' argument to function readconf_line.
20 * Revision 1.8 1998/05/18 13:07:07 adam
21 * Changed the way attribute sets are handled by the retriaval module.
22 * Extended Explain conversion / schema.
23 * Modified server and client to work with ASN.1 compiled protocol handlers.
25 * Revision 1.7 1998/02/11 11:53:35 adam
26 * Changed code so that it compiles as C++.
28 * Revision 1.6 1997/09/17 12:10:38 adam
31 * Revision 1.5 1997/09/05 09:50:57 adam
32 * Removed global data1_tabpath - uses data1_get_tabpath() instead.
34 * Revision 1.4 1995/11/13 09:27:38 quinn
35 * Fiddling with the variant stuff.
37 * Revision 1.3 1995/11/01 16:34:58 quinn
38 * Making data1 look for tables in data1_tabpath
40 * Revision 1.2 1995/11/01 13:54:49 quinn
43 * Revision 1.1 1995/11/01 11:56:09 quinn
44 * Added Retrieval (data management) functions en masse.
58 * We'll probably want to add some sort of hashed index to these lookup-
59 * functions eventually.
62 data1_datatype data1_maptype (data1_handle dh, char *t)
70 {"structured", DATA1K_structured},
71 {"string", DATA1K_string},
72 {"numeric", DATA1K_numeric},
74 {"bool", DATA1K_bool},
75 {"generalizedtime", DATA1K_generalizedtime},
76 {"intunit", DATA1K_intunit},
78 {"octetstring", DATA1K_octetstring},
79 {"null", DATA1K_null},
80 {NULL, (data1_datatype) -1}
84 for (i = 0; types[i].tname; i++)
85 if (!data1_matchstr(types[i].tname, t))
87 return DATA1K_unknown;
90 data1_tag *data1_gettagbynum (data1_handle dh, data1_tagset *s,
95 for (; s; s = s->next)
99 for (r = s->tags; r; r = r->next)
100 if (r->which == DATA1T_numeric && r->value.numeric == value)
102 /* scan included sets */
104 (r = data1_gettagbynum (dh, s->children, type, value)))
110 data1_tag *data1_gettagbyname (data1_handle dh, data1_tagset *s,
115 for (; s; s = s->next)
118 for (r = s->children->tags; r; r = r->next)
122 for (np = r->names; np; np = np->next)
123 if (!data1_matchstr(np->name, name))
126 /* scan included sets */
127 if (s->children && (r = data1_gettagbyname (dh, s->children, name)))
133 data1_tagset *data1_empty_tagset (data1_handle dh)
136 (data1_tagset *) nmem_malloc(data1_nmem_get (dh), sizeof(*res));
138 res->reference = VAL_NONE;
146 data1_tagset *data1_read_tagset (data1_handle dh, const char *file, int type)
148 NMEM mem = data1_nmem_get (dh);
149 data1_tagset *res = 0;
150 data1_tagset **childp;
155 char *argv[50], line[512];
157 if (!(f = yaz_path_fopen(data1_get_tabpath(dh), file, "r")))
159 logf(LOG_WARN|LOG_ERRNO, "%s", file);
162 res = data1_empty_tagset (dh);
164 childp = &res->children;
167 while ((argc = readconf_line(f, &lineno, line, 512, argv, 50)))
170 if (!strcmp(cmd, "tag"))
173 char *names, *type, *nm;
179 logf(LOG_WARN, "%s:%d: Bad # args to tag", file, lineno);
182 value = atoi(argv[1]);
186 rr = *tagp = (data1_tag *)nmem_malloc(mem, sizeof(*rr));
189 rr->which = DATA1T_numeric;
190 rr->value.numeric = value;
192 * how to deal with local numeric tags?
195 if (!(rr->kind = data1_maptype(dh, type)))
197 logf(LOG_WARN, "%s:%d: Unknown datatype %s",
210 *npp = (data1_name *)nmem_malloc(mem, sizeof(**npp));
211 if ((e = strchr(nm, '/')))
213 (*npp)->name = nmem_strdup(mem, nm);
221 else if (!strcmp(cmd, "name"))
225 logf(LOG_WARN, "%s:%d: Bad # args to name", file, lineno);
228 res->name = nmem_strdup(mem, argv[1]);
230 else if (!strcmp(cmd, "reference"))
236 logf(LOG_WARN, "%s:%d: Bad # args to reference", file, lineno);
240 if ((res->reference = oid_getvalbyname(name)) == VAL_NONE)
242 logf(LOG_WARN, "%s:%d: Unknown tagset ref '%s'",
247 else if (!strcmp(cmd, "type"))
251 logf (LOG_WARN, "%s:%d: Bad # args to type", file, lineno);
255 res->type = atoi(argv[1]);
257 else if (!strcmp(cmd, "include"))
264 logf(LOG_WARN, "%s:%d: Bad # args to include",
270 type = atoi(argv[2]);
271 *childp = data1_read_tagset (dh, name, type);
274 logf(LOG_WARN, "%s:%d: Inclusion failed for tagset %s",
278 childp = &(*childp)->next;
282 logf(LOG_WARN, "%s:%d: Unknown directive '%s'",