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