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