The constructions 'qualifier rel term ...' implemented.
[egate.git] / ccl / cclqual.c
1 /* CCL qualifiers
2  * Europagate, 1995
3  *
4  * $Log: cclqual.c,v $
5  * Revision 1.2  1995/02/14 10:25:56  adam
6  * The constructions 'qualifier rel term ...' implemented.
7  *
8  * Revision 1.1  1995/02/13  15:15:07  adam
9  * Added handling of qualifiers. Not finished yet.
10  *
11  */
12
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <assert.h>
16 #include <string.h>
17
18 #include "cclp.h"
19
20 struct ccl_qualifiers {
21     struct ccl_qualifier *list;
22 };
23
24 void ccl_qual_add (CCL_bibset b, const char *name, int no, int *pairs)
25 {
26     struct ccl_qualifier *new_qual;
27     struct ccl_rpn_attr **attrp;
28     
29     assert (b);
30     new_qual = malloc (sizeof(*new_qual));
31     assert (new_qual);
32
33     new_qual->next = b->list;
34     b->list = new_qual;
35
36     new_qual->name = malloc (strlen(name)+1);
37     assert (new_qual->name);
38     strcpy (new_qual->name, name);
39     attrp = &new_qual->attr_list;
40
41     while (--no >= 0)
42     {
43         struct ccl_rpn_attr *attr;
44
45         attr = malloc (sizeof(*attr));
46         assert (attr);
47         attr->type = *pairs++;
48         attr->value = *pairs++;
49         *attrp = attr;
50         attrp = &attr->next;
51     }
52     *attrp = NULL;
53 }
54
55 CCL_bibset ccl_qual_mk (void)
56 {
57     CCL_bibset b = malloc (sizeof(*b));
58     assert (b);
59     b->list = NULL;     
60     return b;
61 }
62
63 void ccl_qual_rm (CCL_bibset *b)
64 {
65     assert (*b);
66     *b = NULL;
67 }
68
69 struct ccl_rpn_attr *ccl_qual_search (CCL_bibset b, const char *name, int len)
70 {
71     struct ccl_qualifier *q;
72
73     assert (b);
74     for (q = b->list; q; q = q->next)
75         if (strlen(q->name) == len && !memcmp (name, q->name, len))
76             return q->attr_list;
77     return NULL;
78 }