Include zebrautl.h instead of alexutil.h.
[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.4  1996-10-29 14:06:48  adam
8  * Include zebrautl.h instead of alexutil.h.
9  *
10  * Revision 1.3  1996/05/09 07:28:54  quinn
11  * Work towards phrases and multiple registers
12  *
13  * Revision 1.2  1995/11/15  19:13:07  adam
14  * Work on record management.
15  *
16  *
17  * This interface is used by other modules (the Z-server in particular)
18  * to normalize the attributes given in queries.
19  */
20
21 #include <stdio.h>
22
23 #include <log.h>
24 #include <res.h>
25 #include <d1_attset.h>
26 #include <zebrautl.h>
27 #include "attribute.h"
28
29 static int initialized = 0;
30
31 static data1_attset *registered_sets = 0;
32
33 static void att_loadset(const char *n, const char *name)
34 {
35     data1_attset *new;
36
37     if (!(new = data1_read_attset((char*) name)))
38     {
39         logf(LOG_WARN|LOG_ERRNO, "%s", name);
40         return;
41     }
42     new->next = registered_sets;
43     registered_sets = new;
44     return;
45 }
46
47 static void load_atts()
48 {
49     res_trav(common_resource, "attset", att_loadset);
50 }
51
52 static data1_att *getatt(data1_attset *p, int att)
53 {
54     data1_att *a;
55
56     for (; p; p = p->next)
57     {
58         /* scan local set */
59         for (a = p->atts; a; a = a->next)
60             if (a->value == att)
61                 return a;
62         /* scan included sets */
63         if (p->children && (a = getatt(p->children, att)))
64             return a;
65     }
66     return 0;
67 }
68
69 attent *att_getentbyatt(oid_value set, int att)
70 {
71     static attent res;
72     data1_att *r;
73     data1_attset *p;
74
75     if (!initialized)
76     {
77         initialized = 1;
78         load_atts();
79     }
80     for (p = registered_sets; p; p = p->next)
81         if (p->reference == set && (r = getatt(p, att)))
82             break;;
83     if (!p)
84         return 0;
85     res.attset_ordinal = r->parent->ordinal;
86     res.local_attributes = r->locals;
87     return &res;
88 }