IDZEBRA 2.2.8
d1_varset.c
Go to the documentation of this file.
1/* This file is part of the Zebra server.
2 Copyright (C) Index Data
3
4Zebra is free software; you can redistribute it and/or modify it under
5the terms of the GNU General Public License as published by the Free
6Software Foundation; either version 2, or (at your option) any later
7version.
8
9Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10WARRANTY; without even the implied warranty of MERCHANTABILITY or
11FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program; if not, write to the Free Software
16Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
18*/
19
20#if HAVE_CONFIG_H
21#include <config.h>
22#endif
23#include <string.h>
24#include <stdlib.h>
25
26#include <yaz/oid_db.h>
27#include <yaz/log.h>
28#include <d1_absyn.h>
29
31 const char *zclass, const char *type)
32{
35
36 for (c = set->classes; c; c = c->next)
37 if (!data1_matchstr(c->name, zclass))
38 {
39 for (t = c->types; t; t = t->next)
40 if (!data1_matchstr(t->name, type))
41 return t;
42 yaz_log(YLOG_WARN, "Unknown variant type %s in class %s",
43 type, zclass);
44 return 0;
45 }
46 yaz_log(YLOG_WARN, "Unknown variant class %s", zclass);
47 return 0;
48}
49
51 char *zclass, char *type)
52{
53 return data1_getvartypebyct(dh, absyn->varset, zclass, type);
54}
55
57{
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;
62 FILE *f;
63 int lineno = 0;
64 int argc;
65 char *argv[50],line[512];
66
67 res->name = 0;
68 res->oid = 0;
69 res->classes = 0;
70
71 if (!(f = data1_path_fopen(dh, file, "r")))
72 {
73 yaz_log(YLOG_WARN|YLOG_ERRNO, "%s", file);
74 return 0;
75 }
76 while ((argc = readconf_line(f, &lineno, line, 512, argv, 50)))
77 if (!strcmp(argv[0], "class"))
78 {
80
81 if (argc != 3)
82 {
83 yaz_log(YLOG_WARN, "%s:%d: Bad # or args to class",
84 file, lineno);
85 continue;
86 }
87 *classp = r = zclass = (data1_varclass *)
88 nmem_malloc(mem, sizeof(*r));
89 r->set = res;
90 r->zclass = atoi(argv[1]);
91 r->name = nmem_strdup(mem, argv[2]);
92 r->types = 0;
93 typep = &r->types;
94 r->next = 0;
95 classp = &r->next;
96 }
97 else if (!strcmp(argv[0], "type"))
98 {
100
101 if (!typep)
102 {
103 yaz_log(YLOG_WARN, "%s:%d: Directive class must precede type",
104 file, lineno);
105 continue;
106 }
107 if (argc != 4)
108 {
109 yaz_log(YLOG_WARN, "%s:%d: Bad # or args to type",
110 file, lineno);
111 continue;
112 }
113 *typep = r = (data1_vartype *)nmem_malloc(mem, sizeof(*r));
114 r->name = nmem_strdup(mem, argv[2]);
115 r->zclass = zclass;
116 r->type = atoi(argv[1]);
117 if (!(r->datatype = data1_maptype (dh, argv[3])))
118 {
119 yaz_log(YLOG_WARN, "%s:%d: Unknown datatype '%s'",
120 file, lineno, argv[3]);
121 fclose(f);
122 return 0;
123 }
124 r->next = 0;
125 typep = &r->next;
126 }
127 else if (!strcmp(argv[0], "name"))
128 {
129 if (argc != 2)
130 {
131 yaz_log(YLOG_WARN, "%s:%d: Bad # args for name",
132 file, lineno);
133 continue;
134 }
135 res->name = nmem_strdup(mem, argv[1]);
136 }
137 else if (!strcmp(argv[0], "reference"))
138 {
139 if (argc != 2)
140 {
141 yaz_log(YLOG_WARN, "%s:%d: Bad # args for reference",
142 file, lineno);
143 continue;
144 }
145 res->oid = yaz_string_to_oid_nmem(yaz_oid_std(),
146 CLASS_VARSET, argv[1], mem);
147 if (!res->oid)
148 {
149 yaz_log(YLOG_WARN, "%s:%d: Unknown reference '%s'",
150 file, lineno, argv[1]);
151 continue;
152 }
153 }
154 else
155 yaz_log(YLOG_WARN, "%s:%d: Unknown directive '%s'",
156 file, lineno, argv[0]);
157
158 fclose(f);
159 return res;
160}
161/*
162 * Local variables:
163 * c-basic-offset: 4
164 * c-file-style: "Stroustrup"
165 * indent-tabs-mode: nil
166 * End:
167 * vim: shiftwidth=4 tabstop=8 expandtab
168 */
169
data1_vartype * data1_getvartypebyct(data1_handle dh, data1_varset *set, const char *zclass, const char *type)
Definition d1_varset.c:30
data1_varset * data1_read_varset(data1_handle dh, const char *file)
Definition d1_varset.c:56
data1_vartype * data1_getvartypeby_absyn(data1_handle dh, data1_absyn *absyn, char *zclass, char *type)
Definition d1_varset.c:50
data1_datatype data1_maptype(data1_handle dh, char *t)
Definition d1_tagset.c:36
NMEM data1_nmem_get(data1_handle dh)
Definition d1_handle.c:66
#define data1_matchstr(s1, s2)
Definition data1.h:36
FILE * data1_path_fopen(data1_handle dh, const char *file, const char *mode)
Definition d1_handle.c:147
data1_varset * varset
Definition d1_absyn.h:52
struct data1_varset * set
Definition data1.h:182
data1_vartype * types
Definition data1.h:184
struct data1_varclass * next
Definition data1.h:185
char * name
Definition data1.h:181
Odr_oid * oid
Definition data1.h:191
data1_varclass * classes
Definition data1.h:192
char * name
Definition data1.h:190
data1_datatype datatype
Definition data1.h:175
char * name
Definition data1.h:172
struct data1_vartype * next
Definition data1.h:176
struct data1_varclass * zclass
Definition data1.h:173