c076de9490da5c727fa6c63c57bd7dc7b19ce890
[idzebra-moved-to-github.git] / index / attribute.c
1 /* $Id: attribute.c,v 1.16 2004-08-25 09:23:36 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 <idzebra/res.h>
29 #include <zebrautl.h>
30 #include "index.h"
31
32 static data1_att *getatt(data1_attset *p, int att, const char *sattr)
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 (sattr && !yaz_matchstr(sattr, a->name))
40             return a;
41         else if (a->value == att)
42             return a;
43     /* scan included sets */
44     for (c = p->children; c; c = c->next)
45         if ((a = getatt(c->child, att, sattr)))
46             return a;
47     return 0;
48 }
49
50 int att_getentbyatt(ZebraHandle zi, attent *res, oid_value set, int att,
51                 const char *sattr)
52 {
53     data1_att *r;
54     data1_attset *p;
55
56     if (!(p = data1_attset_search_id (zi->reg->dh, set)))
57     {
58         zebraExplain_loadAttsets (zi->reg->dh, zi->res);
59         p = data1_attset_search_id (zi->reg->dh, set);
60     }
61     if (!p)
62         return -2;
63     if (!(r = getatt(p, att, sattr)))
64         return -1;
65     res->attset_ordinal = r->parent->reference;
66     res->local_attributes = r->locals;
67     return 0;
68 }