1 /* $Id: d1_attset.c,v 1.7 2005-01-15 19:38:18 adam Exp $
2 Copyright (C) 1995-2005
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
28 #include <idzebra/data1.h>
30 data1_att *data1_getattbyname(data1_handle dh, data1_attset *s, char *name)
33 data1_attset_child *c;
36 for (r = s->atts; r; r = r->next)
37 if (!data1_matchstr(r->name, name))
39 for (c = s->children; c; c = c->next)
42 /* scan included sets */
43 if ((r = data1_getattbyname (dh, c->child, name)))
49 data1_attset *data1_empty_attset(data1_handle dh)
51 NMEM mem = data1_nmem_get (dh);
52 data1_attset *res = (data1_attset*) nmem_malloc(mem,sizeof(*res));
55 res->reference = VAL_NONE;
62 data1_attset *data1_read_attset(data1_handle dh, const char *file)
64 data1_attset *res = 0;
65 data1_attset_child **childp;
68 NMEM mem = data1_nmem_get (dh);
71 char *argv[50], line[512];
73 if (!(f = data1_path_fopen(dh, file, "r")))
75 res = data1_empty_attset (dh);
77 childp = &res->children;
80 while ((argc = readconf_line(f, &lineno, line, 512, argv, 50)))
83 if (!strcmp(cmd, "att"))
88 data1_local_attribute *locals;
92 yaz_log(YLOG_WARN, "%s:%d: Bad # of args to att", file, lineno);
98 if (argc == 3) /* no local attributes given */
100 locals = (data1_local_attribute *)
101 nmem_malloc(mem, sizeof(*locals));
105 else /* parse the string "local{,local}" */
108 data1_local_attribute **ap = &locals;
111 *ap = (data1_local_attribute *)
112 nmem_malloc(mem, sizeof(**ap));
113 (*ap)->local = atoi(p);
117 while ((p = strchr(p, ',')) && *(++p));
119 t = *attp = (data1_att *)nmem_malloc(mem, sizeof(*t));
121 t->name = nmem_strdup(mem, name);
127 else if (!strcmp(cmd, "name"))
131 yaz_log(YLOG_WARN, "%s:%d: Bad # of args to name", file, lineno);
135 else if (!strcmp(cmd, "reference"))
141 yaz_log(YLOG_WARN, "%s:%d: Bad # of args to reference",
146 if ((res->reference = oid_getvalbyname(name)) == VAL_NONE)
148 yaz_log(YLOG_WARN, "%s:%d: Unknown reference oid '%s'",
154 else if (!strcmp(cmd, "ordinal"))
156 yaz_log (YLOG_WARN, "%s:%d: Directive ordinal ignored",
159 else if (!strcmp(cmd, "include"))
162 data1_attset *attset;
166 yaz_log(YLOG_WARN, "%s:%d: Bad # of args to include",
172 if (!(attset = data1_get_attset (dh, name)))
174 yaz_log(YLOG_WARN, "%s:%d: Include of attset %s failed",
179 *childp = (data1_attset_child *)
180 nmem_malloc (mem, sizeof(**childp));
181 (*childp)->child = attset;
183 childp = &(*childp)->next;
187 yaz_log(YLOG_WARN, "%s:%d: Unknown directive '%s'",