Run latex
[egate.git] / ccl / cclqual.c
1 /*
2  * Copyright (c) 1995, the EUROPAGATE consortium (see below).
3  *
4  * The EUROPAGATE consortium members are:
5  *
6  *    University College Dublin
7  *    Danmarks Teknologiske Videnscenter
8  *    An Chomhairle Leabharlanna
9  *    Consejo Superior de Investigaciones Cientificas
10  *
11  * Permission to use, copy, modify, distribute, and sell this software and
12  * its documentation, in whole or in part, for any purpose, is hereby granted,
13  * provided that:
14  *
15  * 1. This copyright and permission notice appear in all copies of the
16  * software and its documentation. Notices of copyright or attribution
17  * which appear at the beginning of any file must remain unchanged.
18  *
19  * 2. The names of EUROPAGATE or the project partners may not be used to
20  * endorse or promote products derived from this software without specific
21  * prior written permission.
22  *
23  * 3. Users of this software (implementors and gateway operators) agree to
24  * inform the EUROPAGATE consortium of their use of the software. This
25  * information will be used to evaluate the EUROPAGATE project and the
26  * software, and to plan further developments. The consortium may use
27  * the information in later publications.
28  * 
29  * 4. Users of this software agree to make their best efforts, when
30  * documenting their use of the software, to acknowledge the EUROPAGATE
31  * consortium, and the role played by the software in their work.
32  *
33  * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
34  * EXPRESS, IMPLIED, OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
35  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
36  * IN NO EVENT SHALL THE EUROPAGATE CONSORTIUM OR ITS MEMBERS BE LIABLE
37  * FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF
38  * ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
39  * OR PROFITS, WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND
40  * ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
41  * USE OR PERFORMANCE OF THIS SOFTWARE.
42  *
43  */
44 /* CCL qualifiers
45  * Europagate, 1995
46  *
47  * $Log: cclqual.c,v $
48  * Revision 1.9  1995/05/16 09:39:27  adam
49  * LICENSE.
50  *
51  * Revision 1.8  1995/05/11  14:03:57  adam
52  * Changes in the reading of qualifier(s). New function: ccl_qual_fitem.
53  * New variable ccl_case_sensitive, which controls whether reserved
54  * words and field names are case sensitive or not.
55  *
56  * Revision 1.7  1995/04/17  09:31:46  adam
57  * Improved handling of qualifiers. Aliases or reserved words.
58  *
59  * Revision 1.6  1995/02/23  08:32:00  adam
60  * Changed header.
61  *
62  * Revision 1.4  1995/02/14  19:55:12  adam
63  * Header files ccl.h/cclp.h are gone! They have been merged an
64  * moved to ../include/ccl.h.
65  * Node kind(s) in ccl_rpn_node have changed names.
66  *
67  * Revision 1.3  1995/02/14  16:20:56  adam
68  * Qualifiers are read from a file now.
69  *
70  * Revision 1.2  1995/02/14  10:25:56  adam
71  * The constructions 'qualifier rel term ...' implemented.
72  *
73  * Revision 1.1  1995/02/13  15:15:07  adam
74  * Added handling of qualifiers. Not finished yet.
75  *
76  */
77
78 #include <stdio.h>
79 #include <stdlib.h>
80 #include <assert.h>
81 #include <string.h>
82
83 #include <ccl.h>
84
85 /* Definition of CCL_bibset pointer */
86 struct ccl_qualifiers {
87     struct ccl_qualifier *list;
88 };
89
90 /*
91  * ccl_qual_add: Add qualifier to Bibset. If qualifier already
92  *               exists, then attributes are appendend to old
93  *               definition.
94  * name:    name of qualifier
95  * no:      No of attribute type/value pairs.
96  * pairs:   Attributes. pairs[0] first type, pair[1] first value,
97  *          ... pair[2*no-2] last type, pair[2*no-1] last value.
98  */
99 void ccl_qual_add (CCL_bibset b, const char *name, int no, int *pairs)
100 {
101     struct ccl_qualifier *q;
102     struct ccl_rpn_attr **attrp;
103
104     assert (b);
105     for (q = b->list; q; q = q->next)
106         if (!strcmp (name, q->name))
107             break;
108     if (!q)
109     {
110         struct ccl_qualifier *new_qual = malloc (sizeof(*new_qual));
111         assert (new_qual);
112         
113         new_qual->next = b->list;
114         b->list = new_qual;
115         
116         new_qual->name = malloc (strlen(name)+1);
117         assert (new_qual->name);
118         strcpy (new_qual->name, name);
119         attrp = &new_qual->attr_list;
120     }
121     else
122     {
123         attrp = &q->attr_list;
124         while (*attrp)
125             attrp = &(*attrp)->next;
126     }
127     while (--no >= 0)
128     {
129         struct ccl_rpn_attr *attr;
130
131         attr = malloc (sizeof(*attr));
132         assert (attr);
133         attr->type = *pairs++;
134         attr->value = *pairs++;
135         *attrp = attr;
136         attrp = &attr->next;
137     }
138     *attrp = NULL;
139 }
140
141 /*
142  * ccl_qual_mk: Make new (empty) bibset.
143  * return:   empty bibset.
144  */
145 CCL_bibset ccl_qual_mk (void)
146 {
147     CCL_bibset b = malloc (sizeof(*b));
148     assert (b);
149     b->list = NULL;     
150     return b;
151 }
152
153 /*
154  * ccl_qual_rm: Delete bibset.
155  * b:        pointer to bibset
156  */
157 void ccl_qual_rm (CCL_bibset *b)
158 {
159     struct ccl_qualifier *q, *q1;
160
161     if (!*b)
162         return;
163     for (q = (*b)->list; q; q = q1)
164     {
165         struct ccl_rpn_attr *attr, *attr1;
166
167         for (attr = q->attr_list; attr; attr = attr1)
168         {
169             attr1 = attr->next;
170             free (attr);
171         }
172         q1 = q->next;
173         free (q);
174     }
175     free (*b);
176     *b = NULL;
177 }
178
179 /*
180  * ccl_qual_search: Search for qualifier in bibset.
181  * b:      Bibset
182  * name:   Name of qualifier to search for (need no null-termination)
183  * len:    Length of name.
184  * return: Attribute info. NULL if not found.
185  */
186 struct ccl_rpn_attr *ccl_qual_search (CCL_bibset b, const char *name, int len)
187 {
188     struct ccl_qualifier *q;
189
190     assert (b);
191     for (q = b->list; q; q = q->next)
192         if (strlen(q->name) == len)
193             if (ccl_case_sensitive)
194             {
195                 if (!memcmp (name, q->name, len))
196                     return q->attr_list;
197             }
198             else
199             {
200                 if (!ccl_memicmp (name, q->name, len))
201                     return q->attr_list;
202             }
203     return NULL;
204 }
205