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.11 2007-05-01 12:54:44 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.
88 #include <yaz/snprintf.h>
89 #include <yaz/tokenizer.h>
93 struct ccl_qualifier {
96 struct ccl_qualifier **sub;
97 struct ccl_rpn_attr *attr_list;
98 struct ccl_qualifier *next;
102 /** Definition of CCL_bibset pointer */
103 struct ccl_qualifiers {
104 struct ccl_qualifier *list;
105 struct ccl_qualifier_special *special;
109 /** CCL Qualifier special */
110 struct ccl_qualifier_special {
113 struct ccl_qualifier_special *next;
117 static struct ccl_qualifier *ccl_qual_lookup(CCL_bibset b,
118 const char *n, size_t len)
120 struct ccl_qualifier *q;
121 for (q = b->list; q; q = q->next)
122 if (len == strlen(q->name) && !memcmp(q->name, n, len))
127 void ccl_qual_add_special_ar(CCL_bibset bibset, const char *n,
130 struct ccl_qualifier_special *p;
131 for (p = bibset->special; p && strcmp(p->name, n); p = p->next)
138 for (i = 0; p->values[i]; i++)
139 xfree((char *) p->values[i]);
140 xfree((char **)p->values);
145 p = (struct ccl_qualifier_special *) xmalloc(sizeof(*p));
146 p->name = xstrdup(n);
147 p->next = bibset->special;
153 void ccl_qual_add_special(CCL_bibset bibset, const char *n, const char *cp)
156 char **vlist = xmalloc(no * sizeof(*vlist));
157 yaz_tok_cfg_t yt = yaz_tok_cfg_create();
161 yaz_tok_parse_t tp = yaz_tok_parse_buf(yt, cp);
163 yaz_tok_cfg_destroy(yt);
165 t = yaz_tok_move(tp);
166 while (t == YAZ_TOK_STRING)
169 vlist = xrealloc(vlist, (no = no * 2) * sizeof(*vlist));
170 vlist[i++] = xstrdup(yaz_tok_parse_string(tp));
171 t = yaz_tok_move(tp);
174 ccl_qual_add_special_ar(bibset, n, (const char **) vlist);
176 yaz_tok_parse_destroy(tp);
180 /** \brief adds specifies qualifier aliases
183 \param n qualifier name
184 \param names list of qualifier aliases
186 void ccl_qual_add_combi(CCL_bibset b, const char *n, const char **names)
189 struct ccl_qualifier *q;
190 for (q = b->list; q && strcmp(q->name, n); q = q->next)
194 q = (struct ccl_qualifier *) xmalloc(sizeof(*q));
195 q->name = xstrdup(n);
200 for (i = 0; names[i]; i++)
203 q->sub = (struct ccl_qualifier **)
204 xmalloc(sizeof(*q->sub) * (1+q->no_sub));
205 for (i = 0; names[i]; i++)
206 q->sub[i] = ccl_qual_lookup(b, names[i], strlen(names[i]));
209 /** \brief adds specifies attributes for qualifier
212 \param name qualifier name
213 \param no number of attribute type+value pairs
214 \param type_ar attributes type of size no
215 \param value_ar attribute value of size no
216 \param svalue_ar attribute string values ([i] only used if != NULL)
217 \param attsets attribute sets of size no
220 void ccl_qual_add_set(CCL_bibset b, const char *name, int no,
221 int *type_ar, int *value_ar, char **svalue_ar,
224 struct ccl_qualifier *q;
225 struct ccl_rpn_attr **attrp;
228 for (q = b->list; q; q = q->next)
229 if (!strcmp(name, q->name))
233 q = (struct ccl_qualifier *)xmalloc(sizeof(*q));
239 q->name = xstrdup(name);
245 attrp = &q->attr_list;
247 attrp = &(*attrp)->next;
250 struct ccl_rpn_attr *attr;
252 attr = (struct ccl_rpn_attr *)xmalloc(sizeof(*attr));
254 attr->set = *attsets++;
255 attr->type = *type_ar++;
258 attr->kind = CCL_RPN_ATTR_STRING;
259 attr->value.str = *svalue_ar;
263 attr->kind = CCL_RPN_ATTR_NUMERIC;
264 attr->value.numeric = *value_ar;
274 /** \brief creates Bibset
277 CCL_bibset ccl_qual_mk(void)
279 CCL_bibset b = (CCL_bibset)xmalloc(sizeof(*b));
286 /** \brief destroys Bibset
287 \param b pointer to Bibset
289 *b will be set to NULL.
291 void ccl_qual_rm(CCL_bibset *b)
293 struct ccl_qualifier *q, *q1;
294 struct ccl_qualifier_special *sp, *sp1;
298 for (q = (*b)->list; q; q = q1)
300 struct ccl_rpn_attr *attr, *attr1;
302 for (attr = q->attr_list; attr; attr = attr1)
307 if (attr->kind == CCL_RPN_ATTR_STRING)
308 xfree(attr->value.str);
317 for (sp = (*b)->special; sp; sp = sp1)
324 for (i = 0; sp->values[i]; i++)
325 xfree((char*) sp->values[i]);
326 xfree((char **)sp->values);
334 ccl_qualifier_t ccl_qual_search(CCL_parser cclp, const char *name,
335 size_t name_len, int seq)
337 struct ccl_qualifier *q = 0;
338 const char **aliases;
339 int case_sensitive = cclp->ccl_case_sensitive;
345 aliases = ccl_qual_search_special(cclp->bibset, "case");
347 case_sensitive = atoi(aliases[0]);
349 for (q = cclp->bibset->list; q; q = q->next)
350 if (strlen(q->name) == name_len)
354 if (!memcmp(name, q->name, name_len))
359 if (!ccl_memicmp(name, q->name, name_len))
378 struct ccl_rpn_attr *ccl_qual_get_attr(ccl_qualifier_t q)
383 const char *ccl_qual_get_name(ccl_qualifier_t q)
388 const char **ccl_qual_search_special(CCL_bibset b, const char *name)
390 struct ccl_qualifier_special *q;
393 for (q = b->special; q && strcmp(q->name, name); q = q->next)
400 int ccl_search_stop(CCL_bibset bibset, const char *qname,
401 const char *src_str, size_t src_len)
403 const char **slist = 0;
407 yaz_snprintf(qname_buf, sizeof(qname_buf)-1, "stop.%s",
409 slist = ccl_qual_search_special(bibset, qname_buf);
412 slist = ccl_qual_search_special(bibset, "stop.*");
416 for (i = 0; slist[i]; i++)
417 if (src_len == strlen(slist[i])
418 && ccl_memicmp(slist[i], src_str, src_len) == 0)
427 * indent-tabs-mode: nil
429 * vim: shiftwidth=4 tabstop=8 expandtab