1 /* $Id: d1_tagset.c,v 1.10 2007-04-16 08:44:31 adam Exp $
2 Copyright (C) 1995-2007
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>
29 #include <yaz/oid_db.h>
32 * We'll probably want to add some sort of hashed index to these lookup-
33 * functions eventually.
36 data1_datatype data1_maptype (data1_handle dh, char *t)
44 {"structured", DATA1K_structured},
45 {"string", DATA1K_string},
46 {"numeric", DATA1K_numeric},
48 {"bool", DATA1K_bool},
49 {"generalizedtime", DATA1K_generalizedtime},
50 {"intunit", DATA1K_intunit},
52 {"octetstring", DATA1K_octetstring},
53 {"null", DATA1K_null},
54 {NULL, (data1_datatype) -1}
58 for (i = 0; types[i].tname; i++)
59 if (!data1_matchstr(types[i].tname, t))
61 return DATA1K_unknown;
64 data1_tag *data1_gettagbynum (data1_handle dh, data1_tagset *s,
69 for (; s; s = s->next)
73 for (r = s->tags; r; r = r->next)
74 if (r->which == DATA1T_numeric && r->value.numeric == value)
76 /* scan included sets */
78 (r = data1_gettagbynum (dh, s->children, type, value)))
84 data1_tag *data1_gettagbyname (data1_handle dh, data1_tagset *s,
89 for (; s; s = s->next)
92 for (r = s->tags; r; r = r->next)
96 for (np = r->names; np; np = np->next)
97 if (!data1_matchstr(np->name, name))
100 /* scan included sets */
101 if (s->children && (r = data1_gettagbyname (dh, s->children, name)))
107 data1_tagset *data1_empty_tagset (data1_handle dh)
110 (data1_tagset *) nmem_malloc(data1_nmem_get (dh), sizeof(*res));
120 data1_tagset *data1_read_tagset (data1_handle dh, const char *file, int type)
122 NMEM mem = data1_nmem_get (dh);
123 data1_tagset *res = 0;
124 data1_tagset **childp;
129 char *argv[50], line[512];
131 if (!(f = data1_path_fopen(dh, file, "r")))
133 yaz_log(YLOG_WARN|YLOG_ERRNO, "%s", file);
136 res = data1_empty_tagset (dh);
138 childp = &res->children;
141 while ((argc = readconf_line(f, &lineno, line, 512, argv, 50)))
144 if (!strcmp(cmd, "tag"))
147 char *names, *type, *nm;
153 yaz_log(YLOG_WARN, "%s:%d: Bad # args to tag", file, lineno);
156 value = atoi(argv[1]);
160 rr = *tagp = (data1_tag *)nmem_malloc(mem, sizeof(*rr));
163 rr->which = DATA1T_numeric;
164 rr->value.numeric = value;
166 * how to deal with local numeric tags?
169 if (!(rr->kind = data1_maptype(dh, type)))
171 yaz_log(YLOG_WARN, "%s:%d: Unknown datatype %s",
184 *npp = (data1_name *)nmem_malloc(mem, sizeof(**npp));
185 if ((e = strchr(nm, '/')))
187 (*npp)->name = nmem_strdup(mem, nm);
195 else if (!strcmp(cmd, "name"))
199 yaz_log(YLOG_WARN, "%s:%d: Bad # args to name", file, lineno);
202 res->name = nmem_strdup(mem, argv[1]);
204 else if (!strcmp(cmd, "reference"))
210 yaz_log(YLOG_WARN, "%s:%d: Bad # args to reference",
215 res->oid = yaz_string_to_oid_nmem(yaz_oid_std(),
216 CLASS_TAGSET, name, mem);
219 yaz_log(YLOG_WARN, "%s:%d: Unknown tagset ref '%s'",
224 else if (!strcmp(cmd, "type"))
228 yaz_log (YLOG_WARN, "%s:%d: Bad # args to type", file, lineno);
232 res->type = atoi(argv[1]);
234 else if (!strcmp(cmd, "include"))
241 yaz_log(YLOG_WARN, "%s:%d: Bad # args to include",
247 type = atoi(argv[2]);
248 *childp = data1_read_tagset (dh, name, type);
251 yaz_log(YLOG_WARN, "%s:%d: Inclusion failed for tagset %s",
255 childp = &(*childp)->next;
259 yaz_log(YLOG_WARN, "%s:%d: Unknown directive '%s'",
269 * indent-tabs-mode: nil
271 * vim: shiftwidth=4 tabstop=8 expandtab