1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2010 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 <yaz/oid_db.h>
26 #include <idzebra/data1.h>
28 data1_att *data1_getattbyname(data1_handle dh, data1_attset *s, const char *name)
31 data1_attset_child *c;
34 for (r = s->atts; r; r = r->next)
35 if (!data1_matchstr(r->name, name))
37 for (c = s->children; c; c = c->next)
40 /* scan included sets */
41 if ((r = data1_getattbyname (dh, c->child, name)))
47 data1_attset *data1_empty_attset(data1_handle dh)
49 NMEM mem = data1_nmem_get (dh);
50 data1_attset *res = (data1_attset*) nmem_malloc(mem,sizeof(*res));
60 data1_attset *data1_read_attset(data1_handle dh, const char *file)
62 data1_attset *res = 0;
63 data1_attset_child **childp;
66 NMEM mem = data1_nmem_get (dh);
69 char *argv[50], line[512];
71 if (!(f = data1_path_fopen(dh, file, "r")))
73 res = data1_empty_attset (dh);
75 childp = &res->children;
78 while ((argc = readconf_line(f, &lineno, line, 512, argv, 50)))
81 if (!strcmp(cmd, "att"))
90 yaz_log(YLOG_WARN, "%s:%d: Bad # of args to att", file, lineno);
95 yaz_log(YLOG_WARN, "%s:%d: Local attributes not supported",
98 num = strtol(argv[1], &endptr, 10);
101 yaz_log(YLOG_WARN, "%s:%d: Bad attribute integer %s",
102 file, lineno, argv[1]);
107 t = *attp = (data1_att *)nmem_malloc(mem, sizeof(*t));
109 t->name = nmem_strdup(mem, name);
114 else if (!strcmp(cmd, "name"))
118 yaz_log(YLOG_WARN, "%s:%d: Bad # of args to name", file, lineno);
122 else if (!strcmp(cmd, "reference"))
128 yaz_log(YLOG_WARN, "%s:%d: Bad # of args to reference",
134 res->oid = yaz_string_to_oid_nmem(yaz_oid_std(),
135 CLASS_ATTSET, name, mem);
138 yaz_log(YLOG_WARN, "%s:%d: Unknown reference oid '%s'",
144 else if (!strcmp(cmd, "ordinal"))
146 yaz_log (YLOG_WARN, "%s:%d: Directive ordinal ignored",
149 else if (!strcmp(cmd, "include"))
152 data1_attset *attset;
156 yaz_log(YLOG_WARN, "%s:%d: Bad # of args to include",
162 if (!(attset = data1_get_attset (dh, name)))
164 yaz_log(YLOG_WARN, "%s:%d: Include of attset %s failed",
169 *childp = (data1_attset_child *)
170 nmem_malloc (mem, sizeof(**childp));
171 (*childp)->child = attset;
173 childp = &(*childp)->next;
177 yaz_log(YLOG_WARN, "%s:%d: Unknown directive '%s'",
187 * c-file-style: "Stroustrup"
188 * indent-tabs-mode: nil
190 * vim: shiftwidth=4 tabstop=8 expandtab