1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2011 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
26 #include <yaz/oid_db.h>
30 data1_vartype *data1_getvartypebyct (data1_handle dh, data1_varset *set,
31 const char *zclass, const char *type)
36 for (c = set->classes; c; c = c->next)
37 if (!data1_matchstr(c->name, zclass))
39 for (t = c->types; t; t = t->next)
40 if (!data1_matchstr(t->name, type))
42 yaz_log(YLOG_WARN, "Unknown variant type %s in class %s",
46 yaz_log(YLOG_WARN, "Unknown variant class %s", zclass);
50 data1_vartype *data1_getvartypeby_absyn (data1_handle dh, data1_absyn *absyn,
51 char *zclass, char *type)
53 return data1_getvartypebyct(dh, absyn->varset, zclass, type);
56 data1_varset *data1_read_varset (data1_handle dh, const char *file)
58 NMEM mem = data1_nmem_get (dh);
59 data1_varset *res = (data1_varset *)nmem_malloc(mem, sizeof(*res));
60 data1_varclass **classp = &res->classes, *zclass = 0;
61 data1_vartype **typep = 0;
65 char *argv[50],line[512];
71 if (!(f = data1_path_fopen(dh, file, "r")))
73 yaz_log(YLOG_WARN|YLOG_ERRNO, "%s", file);
76 while ((argc = readconf_line(f, &lineno, line, 512, argv, 50)))
77 if (!strcmp(argv[0], "class"))
83 yaz_log(YLOG_WARN, "%s:%d: Bad # or args to class",
87 *classp = r = zclass = (data1_varclass *)
88 nmem_malloc(mem, sizeof(*r));
90 r->zclass = atoi(argv[1]);
91 r->name = nmem_strdup(mem, argv[2]);
97 else if (!strcmp(argv[0], "type"))
103 yaz_log(YLOG_WARN, "%s:%d: Directive class must precede type",
109 yaz_log(YLOG_WARN, "%s:%d: Bad # or args to type",
113 *typep = r = (data1_vartype *)nmem_malloc(mem, sizeof(*r));
114 r->name = nmem_strdup(mem, argv[2]);
116 r->type = atoi(argv[1]);
117 if (!(r->datatype = data1_maptype (dh, argv[3])))
119 yaz_log(YLOG_WARN, "%s:%d: Unknown datatype '%s'",
120 file, lineno, argv[3]);
127 else if (!strcmp(argv[0], "name"))
131 yaz_log(YLOG_WARN, "%s:%d: Bad # args for name",
135 res->name = nmem_strdup(mem, argv[1]);
137 else if (!strcmp(argv[0], "reference"))
141 yaz_log(YLOG_WARN, "%s:%d: Bad # args for reference",
145 res->oid = yaz_string_to_oid_nmem(yaz_oid_std(),
146 CLASS_VARSET, argv[1], mem);
149 yaz_log(YLOG_WARN, "%s:%d: Unknown reference '%s'",
150 file, lineno, argv[1]);
155 yaz_log(YLOG_WARN, "%s:%d: Unknown directive '%s'",
156 file, lineno, argv[0]);
164 * c-file-style: "Stroustrup"
165 * indent-tabs-mode: nil
167 * vim: shiftwidth=4 tabstop=8 expandtab