2 * Copyright (c) 1995, the EUROPAGATE consortium (see below).
4 * The EUROPAGATE consortium members are:
6 * University College Dublin
7 * Danmarks Teknologiske Videnscenter
8 * An Chomhairle Leabharlanna
9 * Consejo Superior de Investigaciones Cientificas
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,
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.
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.
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.
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.
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.
46 * \brief Implements CCL qualifier utilities
51 * $Id: cclqual.c,v 1.6 2007-04-26 21:41:57 adam Exp $
55 * Revision 1.9 1995/05/16 09:39:27 adam
58 * Revision 1.8 1995/05/11 14:03:57 adam
59 * Changes in the reading of qualifier(s). New function: ccl_qual_fitem.
60 * New variable ccl_case_sensitive, which controls whether reserved
61 * words and field names are case sensitive or not.
63 * Revision 1.7 1995/04/17 09:31:46 adam
64 * Improved handling of qualifiers. Aliases or reserved words.
66 * Revision 1.6 1995/02/23 08:32:00 adam
69 * Revision 1.4 1995/02/14 19:55:12 adam
70 * Header files ccl.h/cclp.h are gone! They have been merged an
71 * moved to ../include/ccl.h.
72 * Node kind(s) in ccl_rpn_node have changed names.
74 * Revision 1.3 1995/02/14 16:20:56 adam
75 * Qualifiers are read from a file now.
77 * Revision 1.2 1995/02/14 10:25:56 adam
78 * The constructions 'qualifier rel term ...' implemented.
80 * Revision 1.1 1995/02/13 15:15:07 adam
81 * Added handling of qualifiers. Not finished yet.
92 struct ccl_qualifier {
95 struct ccl_qualifier **sub;
96 struct ccl_rpn_attr *attr_list;
97 struct ccl_qualifier *next;
101 /** Definition of CCL_bibset pointer */
102 struct ccl_qualifiers {
103 struct ccl_qualifier *list;
104 struct ccl_qualifier_special *special;
108 /** CCL Qualifier special */
109 struct ccl_qualifier_special {
112 struct ccl_qualifier_special *next;
116 static struct ccl_qualifier *ccl_qual_lookup (CCL_bibset b,
117 const char *n, size_t len)
119 struct ccl_qualifier *q;
120 for (q = b->list; q; q = q->next)
121 if (len == strlen(q->name) && !memcmp (q->name, n, len))
127 void ccl_qual_add_special (CCL_bibset bibset, const char *n, const char *v)
129 struct ccl_qualifier_special *p;
132 for (p = bibset->special; p && strcmp(p->name, n); p = p->next)
138 p = (struct ccl_qualifier_special *) xmalloc (sizeof(*p));
139 p->name = xstrdup(n);
141 p->next = bibset->special;
144 while (strchr(" \t", *v))
146 for (pe = v + strlen(v); pe != v; --pe)
147 if (!strchr(" \n\r\t", pe[-1]))
149 p->value = (char*) xmalloc (pe - v + 1);
151 memcpy (p->value, v, pe - v);
152 p->value[pe - v] = '\0';
155 static int next_token(const char **cpp, const char **dst)
158 const char *cp = *cpp;
159 while (*cp && strchr(" \r\n\t\f", *cp))
164 while (*cp && !strchr(" \r\n\t\f", *cp))
173 void ccl_qual_add_combi (CCL_bibset b, const char *n, const char *names)
175 const char *cp, *cp1;
177 struct ccl_qualifier *q;
178 for (q = b->list; q && strcmp(q->name, n); q = q->next)
182 q = (struct ccl_qualifier *) xmalloc (sizeof(*q));
183 q->name = xstrdup(n);
189 for (i = 0; next_token(&cp, 0); i++)
192 q->sub = (struct ccl_qualifier **) xmalloc (sizeof(*q->sub) *
195 for (i = 0; (len = next_token(&cp, &cp1)); i++)
197 q->sub[i] = ccl_qual_lookup (b, cp1, len);
202 * ccl_qual_add: Add qualifier to Bibset. If qualifier already
203 * exists, then attributes are appendend to old
205 * name: name of qualifier
206 * no: No of attribute type/value pairs.
207 * pairs: Attributes. pairs[0] first type, pair[1] first value,
208 * ... pair[2*no-2] last type, pair[2*no-1] last value.
211 void ccl_qual_add_set (CCL_bibset b, const char *name, int no,
212 int *type_ar, int *value_ar, char **svalue_ar,
215 struct ccl_qualifier *q;
216 struct ccl_rpn_attr **attrp;
219 for (q = b->list; q; q = q->next)
220 if (!strcmp (name, q->name))
224 struct ccl_qualifier *new_qual =
225 (struct ccl_qualifier *)xmalloc (sizeof(*new_qual));
226 ccl_assert (new_qual);
228 new_qual->next = b->list;
231 new_qual->name = xstrdup(name);
232 attrp = &new_qual->attr_list;
234 new_qual->no_sub = 0;
239 attrp = &q->attr_list;
241 attrp = &(*attrp)->next;
245 struct ccl_rpn_attr *attr;
247 attr = (struct ccl_rpn_attr *)xmalloc (sizeof(*attr));
249 attr->set = *attsets++;
250 attr->type = *type_ar++;
253 attr->kind = CCL_RPN_ATTR_STRING;
254 attr->value.str = *svalue_ar;
258 attr->kind = CCL_RPN_ATTR_NUMERIC;
259 attr->value.numeric = *value_ar;
270 * ccl_qual_mk: Make new (empty) bibset.
271 * return: empty bibset.
273 CCL_bibset ccl_qual_mk (void)
275 CCL_bibset b = (CCL_bibset)xmalloc (sizeof(*b));
283 * ccl_qual_rm: Delete bibset.
284 * b: pointer to bibset
286 void ccl_qual_rm (CCL_bibset *b)
288 struct ccl_qualifier *q, *q1;
289 struct ccl_qualifier_special *sp, *sp1;
293 for (q = (*b)->list; q; q = q1)
295 struct ccl_rpn_attr *attr, *attr1;
297 for (attr = q->attr_list; attr; attr = attr1)
302 if (attr->kind == CCL_RPN_ATTR_STRING)
303 xfree(attr->value.str);
312 for (sp = (*b)->special; sp; sp = sp1)
324 * ccl_qual_search: Search for qualifier in bibset.
326 * name: Name of qualifier to search for (need no null-termination)
327 * len: Length of name.
328 * return: Attribute info. NULL if not found.
330 struct ccl_rpn_attr *ccl_qual_search (CCL_parser cclp,
331 const char *name, size_t len,
334 struct ccl_qualifier *q;
336 int case_sensitive = cclp->ccl_case_sensitive;
342 aliases = ccl_qual_search_special(cclp->bibset, "case");
344 case_sensitive = atoi(aliases);
346 for (q = cclp->bibset->list; q; q = q->next)
347 if (strlen(q->name) == len)
351 if (!memcmp (name, q->name, len))
356 if (!ccl_memicmp (name, q->name, len))
362 if (q->attr_list && seq == 0)
364 if (seq < q->no_sub && q->sub[seq])
366 return q->sub[seq]->attr_list;
372 const char *ccl_qual_search_special (CCL_bibset b,
375 struct ccl_qualifier_special *q;
378 for (q = b->special; q && strcmp(q->name, name); q = q->next)
387 * indent-tabs-mode: nil
389 * vim: shiftwidth=4 tabstop=8 expandtab