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.9 1998-10-13 16:09:53 adam
8 * Added support for arbitrary OID's for tagsets, schemas and attribute sets.
9 * Added support for multiple attribute set references and tagset references
10 * from an abstract syntax file.
11 * Fixed many bad logs-calls in routines that read the various
12 * specifications regarding data1 (*.abs,*.att,...) and made the messages
13 * consistent whenever possible.
14 * Added extra 'lineno' argument to function readconf_line.
16 * Revision 1.8 1998/05/18 13:07:07 adam
17 * Changed the way attribute sets are handled by the retriaval module.
18 * Extended Explain conversion / schema.
19 * Modified server and client to work with ASN.1 compiled protocol handlers.
21 * Revision 1.7 1998/02/11 11:53:35 adam
22 * Changed code so that it compiles as C++.
24 * Revision 1.6 1997/09/17 12:10:38 adam
27 * Revision 1.5 1997/09/05 09:50:57 adam
28 * Removed global data1_tabpath - uses data1_get_tabpath() instead.
30 * Revision 1.4 1995/11/13 09:27:38 quinn
31 * Fiddling with the variant stuff.
33 * Revision 1.3 1995/11/01 16:34:58 quinn
34 * Making data1 look for tables in data1_tabpath
36 * Revision 1.2 1995/11/01 13:54:49 quinn
39 * Revision 1.1 1995/11/01 11:56:09 quinn
40 * Added Retrieval (data management) functions en masse.
54 * We'll probably want to add some sort of hashed index to these lookup-
55 * functions eventually.
58 data1_datatype data1_maptype (data1_handle dh, char *t)
66 {"structured", DATA1K_structured},
67 {"string", DATA1K_string},
68 {"numeric", DATA1K_numeric},
70 {"bool", DATA1K_bool},
71 {"generalizedtime", DATA1K_generalizedtime},
72 {"intunit", DATA1K_intunit},
74 {"octetstring", DATA1K_octetstring},
75 {"null", DATA1K_null},
76 {NULL, (data1_datatype) -1}
80 for (i = 0; types[i].tname; i++)
81 if (!data1_matchstr(types[i].tname, t))
86 data1_tag *data1_gettagbynum (data1_handle dh, data1_tagset *s,
91 for (; s; s = s->next)
95 for (r = s->tags; r; r = r->next)
96 if (r->which == DATA1T_numeric && r->value.numeric == value)
98 /* scan included sets */
99 if (s->children && (r = data1_gettagbynum (dh, s->children,
106 data1_tag *data1_gettagbyname (data1_handle dh, data1_tagset *s, char *name)
110 for (; s; s = s->next)
113 for (r = s->tags; r; r = r->next)
117 for (np = r->names; np; np = np->next)
118 if (!data1_matchstr(np->name, name))
121 /* scan included sets */
122 if (s->children && (r = data1_gettagbyname (dh, s->children, name)))
128 data1_tagset *data1_empty_tagset (data1_handle dh)
131 (data1_tagset *) nmem_malloc(data1_nmem_get (dh), sizeof(*res));
133 res->reference = VAL_NONE;
141 data1_tagset *data1_read_tagset (data1_handle dh, char *file)
143 NMEM mem = data1_nmem_get (dh);
144 data1_tagset *res = 0, **childp;
149 char *argv[50], line[512];
151 if (!(f = yaz_path_fopen(data1_get_tabpath(dh), file, "r")))
153 logf(LOG_WARN|LOG_ERRNO, "%s", file);
156 res = data1_empty_tagset (dh);
157 childp = &res->children;
160 while ((argc = readconf_line(f, &lineno, line, 512, argv, 50)))
163 if (!strcmp(cmd, "tag"))
166 char *names, *type, *nm;
172 logf(LOG_WARN, "%s:%d: Bad # args to tag", file, lineno);
175 value = atoi(argv[1]);
179 rr = *tagp = (data1_tag *)nmem_malloc(mem, sizeof(*rr));
182 rr->which = DATA1T_numeric;
183 rr->value.numeric = value;
185 * how to deal with local numeric tags?
188 if (!(rr->kind = data1_maptype(dh, type)))
190 logf(LOG_WARN, "%s:%d: Unknown datatype %s",
203 *npp = (data1_name *)nmem_malloc(mem, sizeof(**npp));
204 if ((e = strchr(nm, '/')))
206 (*npp)->name = nmem_strdup(mem, nm);
214 else if (!strcmp(cmd, "name"))
218 logf(LOG_WARN, "%s:%d: Bad # args to name", file, lineno);
221 res->name = nmem_strdup(mem, argv[1]);
223 else if (!strcmp(cmd, "reference"))
229 logf(LOG_WARN, "%s:%d: Bad # args to reference", file, lineno);
233 if ((res->reference = oid_getvalbyname(name)) == VAL_NONE)
235 logf(LOG_WARN, "%s:%d: Unknown tagset ref '%s'",
240 else if (!strcmp(cmd, "type"))
244 logf(LOG_WARN, "%s:%d: Bad # args to type", file, lineno);
247 res->type = atoi(argv[1]);
249 else if (!strcmp(cmd, "include"))
255 logf(LOG_WARN, "%s:%d: Bad # args to include",
260 if (!(*childp = data1_read_tagset (dh, name)))
262 logf(LOG_WARN, "%s:%d: Inclusion failed for tagset %s",
266 childp = &(*childp)->next;
270 logf(LOG_WARN, "%s:%d: Unknown directive '%s'",