1 /* $Id: d1_varset.c,v 1.2 2002-10-22 13:19:50 adam Exp $
2 Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
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 Zebra; see the file LICENSE.zebra. If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
30 data1_vartype *data1_getvartypebyct (data1_handle dh, data1_varset *set,
31 char *zclass, 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(LOG_WARN, "Unknown variant type %s in class %s",
46 yaz_log(LOG_WARN, "Unknown variant class %s", zclass);
50 data1_varset *data1_read_varset (data1_handle dh, const char *file)
52 NMEM mem = data1_nmem_get (dh);
53 data1_varset *res = (data1_varset *)nmem_malloc(mem, sizeof(*res));
54 data1_varclass **classp = &res->classes, *zclass = 0;
55 data1_vartype **typep = 0;
59 char *argv[50],line[512];
62 res->reference = VAL_NONE;
65 if (!(f = data1_path_fopen(dh, file, "r")))
67 yaz_log(LOG_WARN|LOG_ERRNO, "%s", file);
70 while ((argc = readconf_line(f, &lineno, line, 512, argv, 50)))
71 if (!strcmp(argv[0], "class"))
77 yaz_log(LOG_WARN, "%s:%d: Bad # or args to class",
81 *classp = r = zclass = (data1_varclass *)
82 nmem_malloc(mem, sizeof(*r));
84 r->zclass = atoi(argv[1]);
85 r->name = nmem_strdup(mem, argv[2]);
91 else if (!strcmp(argv[0], "type"))
97 yaz_log(LOG_WARN, "%s:%d: Directive class must precede type",
103 yaz_log(LOG_WARN, "%s:%d: Bad # or args to type",
107 *typep = r = (data1_vartype *)nmem_malloc(mem, sizeof(*r));
108 r->name = nmem_strdup(mem, argv[2]);
110 r->type = atoi(argv[1]);
111 if (!(r->datatype = data1_maptype (dh, argv[3])))
113 yaz_log(LOG_WARN, "%s:%d: Unknown datatype '%s'",
114 file, lineno, argv[3]);
121 else if (!strcmp(argv[0], "name"))
125 yaz_log(LOG_WARN, "%s:%d: Bad # args for name",
129 res->name = nmem_strdup(mem, argv[1]);
131 else if (!strcmp(argv[0], "reference"))
135 yaz_log(LOG_WARN, "%s:%d: Bad # args for reference",
139 if ((res->reference = oid_getvalbyname(argv[1])) == VAL_NONE)
141 yaz_log(LOG_WARN, "%s:%d: Unknown reference '%s'",
142 file, lineno, argv[1]);
147 yaz_log(LOG_WARN, "%s:%d: Unknown directive '%s'",
148 file, lineno, argv[0]);