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