IDZEBRA 2.2.8
d1_attset.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 <stdio.h>
24#include <assert.h>
25#include <stdlib.h>
26
27#include <yaz/log.h>
28#include <yaz/oid_db.h>
29#include <idzebra/data1.h>
30
32{
33 data1_att *r;
35
36 /* scan local set */
37 for (r = s->atts; r; r = r->next)
38 if (!data1_matchstr(r->name, name))
39 return r;
40 for (c = s->children; c; c = c->next)
41 {
42 assert (c->child);
43 /* scan included sets */
44 if ((r = data1_getattbyname(dh, c->child, name)))
45 return r;
46 }
47 return 0;
48}
49
51{
52 NMEM mem = data1_nmem_get(dh);
53 data1_attset *res = (data1_attset*) nmem_malloc(mem,sizeof(*res));
54
55 res->name = 0;
56 res->oid = 0;
57 res->atts = 0;
58 res->children = 0;
59 res->next = 0;
60 return res;
61}
62
64{
65 data1_attset *res = 0;
66 data1_attset_child **childp;
67 data1_att **attp;
68 FILE *f;
69 NMEM mem = data1_nmem_get(dh);
70 int lineno = 0;
71 int argc;
72 char *argv[50], line[512];
73
74 if (!(f = data1_path_fopen(dh, file, "r")))
75 return NULL;
76 res = data1_empty_attset(dh);
77
78 childp = &res->children;
79 attp = &res->atts;
80
81 while ((argc = readconf_line(f, &lineno, line, 512, argv, 50)))
82 {
83 char *cmd = argv[0];
84 if (!strcmp(cmd, "att"))
85 {
86 int num;
87 char *name;
88 char *endptr;
89 data1_att *t;
90
91 if (argc < 3)
92 {
93 yaz_log(YLOG_WARN, "%s:%d: Bad # of args to att", file, lineno);
94 continue;
95 }
96 if (argc > 3)
97 {
98 yaz_log(YLOG_WARN, "%s:%d: Local attributes not supported",
99 file, lineno);
100 }
101 num = strtol(argv[1], &endptr, 10);
102 if (*endptr != '\0')
103 {
104 yaz_log(YLOG_WARN, "%s:%d: Bad attribute integer %s",
105 file, lineno, argv[1]);
106 continue;
107 }
108 name = argv[2];
109
110 t = *attp = (data1_att *)nmem_malloc(mem, sizeof(*t));
111 t->parent = res;
112 t->name = nmem_strdup(mem, name);
113 t->value = num;
114 t->next = 0;
115 attp = &t->next;
116 }
117 else if (!strcmp(cmd, "name"))
118 {
119 if (argc != 2)
120 {
121 yaz_log(YLOG_WARN, "%s:%d: Bad # of args to name", file, lineno);
122 continue;
123 }
124 }
125 else if (!strcmp(cmd, "reference"))
126 {
127 char *name;
128
129 if (argc != 2)
130 {
131 yaz_log(YLOG_WARN, "%s:%d: Bad # of args to reference",
132 file, lineno);
133 continue;
134 }
135 name = argv[1];
136
137 res->oid = yaz_string_to_oid_nmem(yaz_oid_std(),
138 CLASS_ATTSET, name, mem);
139 if (!res->oid)
140 {
141 yaz_log(YLOG_WARN, "%s:%d: Unknown reference oid '%s'",
142 file, lineno, name);
143 fclose(f);
144 return 0;
145 }
146 }
147 else if (!strcmp(cmd, "ordinal"))
148 {
149 yaz_log (YLOG_WARN, "%s:%d: Directive ordinal ignored",
150 file, lineno);
151 }
152 else if (!strcmp(cmd, "include"))
153 {
154 char *name;
155 data1_attset *attset;
156
157 if (argc != 2)
158 {
159 yaz_log(YLOG_WARN, "%s:%d: Bad # of args to include",
160 file, lineno);
161 continue;
162 }
163 name = argv[1];
164
165 if (!(attset = data1_get_attset(dh, name)))
166 {
167 yaz_log(YLOG_WARN, "%s:%d: Include of attset %s failed",
168 file, lineno, name);
169 continue;
170
171 }
172 *childp = (data1_attset_child *)
173 nmem_malloc(mem, sizeof(**childp));
174 (*childp)->child = attset;
175 (*childp)->next = 0;
176 childp = &(*childp)->next;
177 }
178 else
179 {
180 yaz_log(YLOG_WARN, "%s:%d: Unknown directive '%s'",
181 file, lineno, cmd);
182 }
183 }
184 fclose(f);
185 return res;
186}
187/*
188 * Local variables:
189 * c-basic-offset: 4
190 * c-file-style: "Stroustrup"
191 * indent-tabs-mode: nil
192 * End:
193 * vim: shiftwidth=4 tabstop=8 expandtab
194 */
195
data1_att * data1_getattbyname(data1_handle dh, data1_attset *s, const char *name)
Definition d1_attset.c:31
data1_attset * data1_read_attset(data1_handle dh, const char *file)
Definition d1_attset.c:63
data1_attset * data1_empty_attset(data1_handle dh)
Definition d1_attset.c:50
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_attset * data1_get_attset(data1_handle dh, const char *name)
Definition d1_absyn.c:289
char * name
Definition data1.h:58
data1_att * next
Definition data1.h:60
int value
Definition data1.h:59
data1_attset * parent
Definition data1.h:57
data1_attset * child
Definition data1.h:64
data1_attset_child * next
Definition data1.h:65
char * name
Definition data1.h:70
data1_attset_child * children
Definition data1.h:73
data1_attset * next
Definition data1.h:74
Odr_oid * oid
Definition data1.h:71
data1_att * atts
Definition data1.h:72