efdb9ad94d2fa99c76866839bf58419b085acc9f
[idzebra-moved-to-github.git] / index / attribute.c
1 /*
2  * Copyright (C) 1994-1999, Index Data
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: attribute.c,v $
7  * Revision 1.13  2002-04-04 14:14:13  adam
8  * Multiple registers (alpha early)
9  *
10  * Revision 1.12  2000/03/15 15:00:30  adam
11  * First work on threaded version.
12  *
13  * Revision 1.11  1999/11/30 13:48:03  adam
14  * Improved installation. Updated for inclusion of YAZ header files.
15  *
16  * Revision 1.10  1999/02/02 14:50:49  adam
17  * Updated WIN32 code specific sections. Changed header.
18  *
19  * Revision 1.9  1998/05/20 10:12:14  adam
20  * Implemented automatic EXPLAIN database maintenance.
21  * Modified Zebra to work with ASN.1 compiled version of YAZ.
22  *
23  * Revision 1.8  1998/03/05 08:45:11  adam
24  * New result set model and modular ranking system. Moved towards
25  * descent server API. System information stored as "SGML" records.
26  *
27  * Revision 1.7  1997/10/29 12:05:01  adam
28  * Server produces diagnostic "Unsupported Attribute Set" when appropriate.
29  *
30  * Revision 1.6  1997/09/17 12:19:11  adam
31  * Zebra version corresponds to YAZ version 1.4.
32  * Changed Zebra server so that it doesn't depend on global common_resource.
33  *
34  * Revision 1.5  1997/09/05 15:30:08  adam
35  * Changed prototype for chr_map_input - added const.
36  * Added support for C++, headers uses extern "C" for public definitions.
37  *
38  * Revision 1.4  1996/10/29 14:06:48  adam
39  * Include zebrautl.h instead of alexutil.h.
40  *
41  * Revision 1.3  1996/05/09 07:28:54  quinn
42  * Work towards phrases and multiple registers
43  *
44  * Revision 1.2  1995/11/15  19:13:07  adam
45  * Work on record management.
46  *
47  *
48  * This interface is used by other modules (the Z-server in particular)
49  * to normalize the attributes given in queries.
50  */
51
52 #include <stdio.h>
53
54 #include <yaz/log.h>
55 #include <res.h>
56 #include <zebrautl.h>
57 #include "index.h"
58
59 static data1_att *getatt(data1_attset *p, int att)
60 {
61     data1_att *a;
62     data1_attset_child *c;
63
64     /* scan local set */
65     for (a = p->atts; a; a = a->next)
66         if (a->value == att)
67             return a;
68     /* scan included sets */
69     for (c = p->children; c; c = c->next)
70         if ((a = getatt(c->child, att)))
71             return a;
72     return 0;
73 }
74
75 int att_getentbyatt(ZebraHandle zi, attent *res, oid_value set, int att)
76 {
77     data1_att *r;
78     data1_attset *p;
79
80     if (!(p = data1_attset_search_id (zi->reg->dh, set)))
81     {
82         zebraExplain_loadAttsets (zi->reg->dh, zi->res);
83         p = data1_attset_search_id (zi->reg->dh, set);
84     }
85     if (!p)
86         return -2;
87     if (!(r = getatt(p, att)))
88         return -1;
89     res->attset_ordinal = r->parent->reference;
90     res->local_attributes = r->locals;
91     return 0;
92 }