1 /* $Id: d1_tagset.c,v 1.8 2006-08-14 10:40:06 adam Exp $
2 Copyright (C) 1995-2006
5 This file is part of the Zebra server.
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 #include <idzebra/data1.h>
31 * We'll probably want to add some sort of hashed index to these lookup-
32 * functions eventually.
35 data1_datatype data1_maptype (data1_handle dh, char *t)
43 {"structured", DATA1K_structured},
44 {"string", DATA1K_string},
45 {"numeric", DATA1K_numeric},
47 {"bool", DATA1K_bool},
48 {"generalizedtime", DATA1K_generalizedtime},
49 {"intunit", DATA1K_intunit},
51 {"octetstring", DATA1K_octetstring},
52 {"null", DATA1K_null},
53 {NULL, (data1_datatype) -1}
57 for (i = 0; types[i].tname; i++)
58 if (!data1_matchstr(types[i].tname, t))
60 return DATA1K_unknown;
63 data1_tag *data1_gettagbynum (data1_handle dh, data1_tagset *s,
68 for (; s; s = s->next)
72 for (r = s->tags; r; r = r->next)
73 if (r->which == DATA1T_numeric && r->value.numeric == value)
75 /* scan included sets */
77 (r = data1_gettagbynum (dh, s->children, type, value)))
83 data1_tag *data1_gettagbyname (data1_handle dh, data1_tagset *s,
88 for (; s; s = s->next)
91 for (r = s->tags; r; r = r->next)
95 for (np = r->names; np; np = np->next)
96 if (!data1_matchstr(np->name, name))
99 /* scan included sets */
100 if (s->children && (r = data1_gettagbyname (dh, s->children, name)))
106 data1_tagset *data1_empty_tagset (data1_handle dh)
109 (data1_tagset *) nmem_malloc(data1_nmem_get (dh), sizeof(*res));
111 res->reference = VAL_NONE;
119 data1_tagset *data1_read_tagset (data1_handle dh, const char *file, int type)
121 NMEM mem = data1_nmem_get (dh);
122 data1_tagset *res = 0;
123 data1_tagset **childp;
128 char *argv[50], line[512];
130 if (!(f = data1_path_fopen(dh, file, "r")))
132 yaz_log(YLOG_WARN|YLOG_ERRNO, "%s", file);
135 res = data1_empty_tagset (dh);
137 childp = &res->children;
140 while ((argc = readconf_line(f, &lineno, line, 512, argv, 50)))
143 if (!strcmp(cmd, "tag"))
146 char *names, *type, *nm;
152 yaz_log(YLOG_WARN, "%s:%d: Bad # args to tag", file, lineno);
155 value = atoi(argv[1]);
159 rr = *tagp = (data1_tag *)nmem_malloc(mem, sizeof(*rr));
162 rr->which = DATA1T_numeric;
163 rr->value.numeric = value;
165 * how to deal with local numeric tags?
168 if (!(rr->kind = data1_maptype(dh, type)))
170 yaz_log(YLOG_WARN, "%s:%d: Unknown datatype %s",
183 *npp = (data1_name *)nmem_malloc(mem, sizeof(**npp));
184 if ((e = strchr(nm, '/')))
186 (*npp)->name = nmem_strdup(mem, nm);
194 else if (!strcmp(cmd, "name"))
198 yaz_log(YLOG_WARN, "%s:%d: Bad # args to name", file, lineno);
201 res->name = nmem_strdup(mem, argv[1]);
203 else if (!strcmp(cmd, "reference"))
209 yaz_log(YLOG_WARN, "%s:%d: Bad # args to reference",
214 if ((res->reference = oid_getvalbyname(name)) == VAL_NONE)
216 yaz_log(YLOG_WARN, "%s:%d: Unknown tagset ref '%s'",
221 else if (!strcmp(cmd, "type"))
225 yaz_log (YLOG_WARN, "%s:%d: Bad # args to type", file, lineno);
229 res->type = atoi(argv[1]);
231 else if (!strcmp(cmd, "include"))
238 yaz_log(YLOG_WARN, "%s:%d: Bad # args to include",
244 type = atoi(argv[2]);
245 *childp = data1_read_tagset (dh, name, type);
248 yaz_log(YLOG_WARN, "%s:%d: Inclusion failed for tagset %s",
252 childp = &(*childp)->next;
256 yaz_log(YLOG_WARN, "%s:%d: Unknown directive '%s'",
266 * indent-tabs-mode: nil
268 * vim: shiftwidth=4 tabstop=8 expandtab