Changed prototype for chr_map_input - added const.
[idzebra-moved-to-github.git] / index / attribute.c
1 /*
2  * Copyright (C) 1994-1995, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: attribute.c,v $
7  * Revision 1.5  1997-09-05 15:30:08  adam
8  * Changed prototype for chr_map_input - added const.
9  * Added support for C++, headers uses extern "C" for public definitions.
10  *
11  * Revision 1.4  1996/10/29 14:06:48  adam
12  * Include zebrautl.h instead of alexutil.h.
13  *
14  * Revision 1.3  1996/05/09 07:28:54  quinn
15  * Work towards phrases and multiple registers
16  *
17  * Revision 1.2  1995/11/15  19:13:07  adam
18  * Work on record management.
19  *
20  *
21  * This interface is used by other modules (the Z-server in particular)
22  * to normalize the attributes given in queries.
23  */
24
25 #include <stdio.h>
26
27 #include <log.h>
28 #include <res.h>
29 #include <d1_attset.h>
30 #include <zebrautl.h>
31 #include "attribute.h"
32
33 static int initialized = 0;
34
35 static data1_attset *registered_sets = 0;
36
37 static void att_loadset(const char *n, const char *name)
38 {
39     data1_attset *cnew;
40
41     if (!(cnew = data1_read_attset((char*) name)))
42     {
43         logf(LOG_WARN|LOG_ERRNO, "%s", name);
44         return;
45     }
46     cnew->next = registered_sets;
47     registered_sets = cnew;
48 }
49
50 static void load_atts()
51 {
52     res_trav(common_resource, "attset", att_loadset);
53 }
54
55 static data1_att *getatt(data1_attset *p, int att)
56 {
57     data1_att *a;
58
59     for (; p; p = p->next)
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         if (p->children && (a = getatt(p->children, att)))
67             return a;
68     }
69     return 0;
70 }
71
72 attent *att_getentbyatt(oid_value set, int att)
73 {
74     static attent res;
75     data1_att *r;
76     data1_attset *p;
77
78     if (!initialized)
79     {
80         initialized = 1;
81         load_atts();
82     }
83     for (p = registered_sets; p; p = p->next)
84         if (p->reference == set && (r = getatt(p, att)))
85             break;;
86     if (!p)
87         return 0;
88     res.attset_ordinal = r->parent->ordinal;
89     res.local_attributes = r->locals;
90     return &res;
91 }