Towards GPL
[idzebra-moved-to-github.git] / index / attribute.c
1 /* $Id: attribute.c,v 1.14 2002-08-02 19:26:55 adam Exp $
2    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
3    Index Data Aps
4
5 This file is part of the Zebra server.
6
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
10 version.
11
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
15 for more details.
16
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
20 02111-1307, USA.
21 */
22
23
24
25 #include <stdio.h>
26
27 #include <yaz/log.h>
28 #include <res.h>
29 #include <zebrautl.h>
30 #include "index.h"
31
32 static data1_att *getatt(data1_attset *p, int att)
33 {
34     data1_att *a;
35     data1_attset_child *c;
36
37     /* scan local set */
38     for (a = p->atts; a; a = a->next)
39         if (a->value == att)
40             return a;
41     /* scan included sets */
42     for (c = p->children; c; c = c->next)
43         if ((a = getatt(c->child, att)))
44             return a;
45     return 0;
46 }
47
48 int att_getentbyatt(ZebraHandle zi, attent *res, oid_value set, int att)
49 {
50     data1_att *r;
51     data1_attset *p;
52
53     if (!(p = data1_attset_search_id (zi->reg->dh, set)))
54     {
55         zebraExplain_loadAttsets (zi->reg->dh, zi->res);
56         p = data1_attset_search_id (zi->reg->dh, set);
57     }
58     if (!p)
59         return -2;
60     if (!(r = getatt(p, att)))
61         return -1;
62     res->attset_ordinal = r->parent->reference;
63     res->local_attributes = r->locals;
64     return 0;
65 }