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