1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2009 Index Data
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #include <idzebra/data1.h>
26 #include <yaz/oid_db.h>
29 * We'll probably want to add some sort of hashed index to these lookup-
30 * functions eventually.
33 data1_datatype data1_maptype (data1_handle dh, char *t)
41 {"structured", DATA1K_structured},
42 {"string", DATA1K_string},
43 {"numeric", DATA1K_numeric},
45 {"bool", DATA1K_bool},
46 {"generalizedtime", DATA1K_generalizedtime},
47 {"intunit", DATA1K_intunit},
49 {"octetstring", DATA1K_octetstring},
50 {"null", DATA1K_null},
51 {NULL, (data1_datatype) -1}
55 for (i = 0; types[i].tname; i++)
56 if (!data1_matchstr(types[i].tname, t))
58 return DATA1K_unknown;
61 data1_tag *data1_gettagbynum (data1_handle dh, data1_tagset *s,
66 for (; s; s = s->next)
70 for (r = s->tags; r; r = r->next)
71 if (r->which == DATA1T_numeric && r->value.numeric == value)
73 /* scan included sets */
75 (r = data1_gettagbynum (dh, s->children, type, value)))
81 data1_tag *data1_gettagbyname (data1_handle dh, data1_tagset *s,
86 for (; s; s = s->next)
89 for (r = s->tags; r; r = r->next)
93 for (np = r->names; np; np = np->next)
94 if (!data1_matchstr(np->name, name))
97 /* scan included sets */
98 if (s->children && (r = data1_gettagbyname (dh, s->children, name)))
104 data1_tagset *data1_empty_tagset (data1_handle dh)
107 (data1_tagset *) nmem_malloc(data1_nmem_get (dh), sizeof(*res));
117 data1_tagset *data1_read_tagset (data1_handle dh, const char *file, int type)
119 NMEM mem = data1_nmem_get (dh);
120 data1_tagset *res = 0;
121 data1_tagset **childp;
126 char *argv[50], line[512];
128 if (!(f = data1_path_fopen(dh, file, "r")))
130 yaz_log(YLOG_WARN|YLOG_ERRNO, "%s", file);
133 res = data1_empty_tagset (dh);
135 childp = &res->children;
138 while ((argc = readconf_line(f, &lineno, line, 512, argv, 50)))
141 if (!strcmp(cmd, "tag"))
144 char *names, *type, *nm;
150 yaz_log(YLOG_WARN, "%s:%d: Bad # args to tag", file, lineno);
153 value = atoi(argv[1]);
157 rr = *tagp = (data1_tag *)nmem_malloc(mem, sizeof(*rr));
160 rr->which = DATA1T_numeric;
161 rr->value.numeric = value;
163 * how to deal with local numeric tags?
166 if (!(rr->kind = data1_maptype(dh, type)))
168 yaz_log(YLOG_WARN, "%s:%d: Unknown datatype %s",
181 *npp = (data1_name *)nmem_malloc(mem, sizeof(**npp));
182 if ((e = strchr(nm, '/')))
184 (*npp)->name = nmem_strdup(mem, nm);
192 else if (!strcmp(cmd, "name"))
196 yaz_log(YLOG_WARN, "%s:%d: Bad # args to name", file, lineno);
199 res->name = nmem_strdup(mem, argv[1]);
201 else if (!strcmp(cmd, "reference"))
207 yaz_log(YLOG_WARN, "%s:%d: Bad # args to reference",
212 res->oid = yaz_string_to_oid_nmem(yaz_oid_std(),
213 CLASS_TAGSET, name, mem);
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 * c-file-style: "Stroustrup"
267 * indent-tabs-mode: nil
269 * vim: shiftwidth=4 tabstop=8 expandtab