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.
47 * \brief Implements parsing of a CCL FIND query.
49 * This source file implements parsing of a CCL Query (ISO8777).
50 * The parser uses predictive parsing, but it does several tokens
51 * of lookahead in the handling of relational operations.. So
52 * it's not really pure.
56 /* CCL find (to rpn conversion)
59 * $Id: cclfind.c,v 1.6 2004-10-15 00:18:59 adam Exp $
63 * Revision 1.16 1996/01/08 08:41:13 adam
64 * Removed unused function.
66 * Revision 1.15 1995/07/20 08:14:34 adam
67 * Qualifiers were observed too often. Instead tokens are treated as
68 * qualifiers only when separated by comma.
70 * Revision 1.14 1995/05/16 09:39:26 adam
73 * Revision 1.13 1995/04/17 09:31:42 adam
74 * Improved handling of qualifiers. Aliases or reserved words.
76 * Revision 1.12 1995/03/20 15:27:43 adam
79 * Revision 1.11 1995/02/23 08:31:59 adam
82 * Revision 1.9 1995/02/16 13:20:06 adam
85 * Revision 1.8 1995/02/14 19:59:42 adam
86 * Removed a syntax error.
88 * Revision 1.7 1995/02/14 19:55:10 adam
89 * Header files ccl.h/cclp.h are gone! They have been merged an
90 * moved to ../include/ccl.h.
91 * Node kind(s) in ccl_rpn_node have changed names.
93 * Revision 1.6 1995/02/14 16:20:55 adam
94 * Qualifiers are read from a file now.
96 * Revision 1.5 1995/02/14 14:12:41 adam
97 * Ranges for ordered qualfiers implemented (e.g. pd=1980-1990).
99 * Revision 1.4 1995/02/14 13:16:29 adam
100 * Left and/or right truncation implemented.
102 * Revision 1.3 1995/02/14 10:25:56 adam
103 * The constructions 'qualifier rel term ...' implemented.
105 * Revision 1.2 1995/02/13 15:15:07 adam
106 * Added handling of qualifiers. Not finished yet.
108 * Revision 1.1 1995/02/13 12:35:20 adam
109 * First version of CCL. Qualifiers aren't handled yet.
118 /* returns type of current lookahead */
119 #define KIND (cclp->look_token->kind)
121 /* move one token forward */
122 #define ADVANCE cclp->look_token = cclp->look_token->next
125 * qual_val_type: test for existance of attribute type/value pair.
126 * qa: Attribute array
127 * type: Type of attribute to search for
128 * value: Value of attribute to seach for
129 * return: 1 if found; 0 otherwise.
131 static int qual_val_type (struct ccl_rpn_attr **qa, int type, int value,
135 struct ccl_rpn_attr *q;
139 for (i = 0; (q=qa[i]); i++)
142 if (q->type == type && q->kind == CCL_RPN_ATTR_NUMERIC &&
143 q->value.numeric == value)
155 * strxcat: concatenate strings.
156 * n: Null-terminated Destination string
157 * src: Source string to be appended (not null-terminated)
158 * len: Length of source string.
160 static void strxcat (char *n, const char *src, int len)
170 * copy_token_name: Return copy of CCL token name
171 * tp: Pointer to token info.
172 * return: malloc(3) allocated copy of token name.
174 static char *copy_token_name (struct ccl_token *tp)
176 char *str = (char *)xmalloc (tp->len + 1);
178 memcpy (str, tp->name, tp->len);
184 * mk_node: Create RPN node.
185 * kind: Type of node.
186 * return: pointer to allocated node.
188 static struct ccl_rpn_node *mk_node (int kind)
190 struct ccl_rpn_node *p;
191 p = (struct ccl_rpn_node *)xmalloc (sizeof(*p));
198 * ccl_rpn_delete: Delete RPN tree.
199 * rpn: Pointer to tree.
201 void ccl_rpn_delete (struct ccl_rpn_node *rpn)
203 struct ccl_rpn_attr *attr, *attr1;
211 ccl_rpn_delete (rpn->u.p[0]);
212 ccl_rpn_delete (rpn->u.p[1]);
215 xfree (rpn->u.t.term);
216 for (attr = rpn->u.t.attr_list; attr; attr = attr1)
219 if (attr->kind == CCL_RPN_ATTR_STRING)
220 xfree(attr->value.str);
227 xfree (rpn->u.setname);
230 ccl_rpn_delete (rpn->u.p[0]);
231 ccl_rpn_delete (rpn->u.p[1]);
232 ccl_rpn_delete (rpn->u.p[2]);
238 static struct ccl_rpn_node *find_spec (CCL_parser cclp,
239 struct ccl_rpn_attr **qa);
241 static int is_term_ok (int look, int *list)
243 for (;*list >= 0; list++)
249 static struct ccl_rpn_node *search_terms (CCL_parser cclp,
250 struct ccl_rpn_attr **qa);
252 static struct ccl_rpn_attr *add_attr_node (struct ccl_rpn_node *p,
253 const char *set, int type)
255 struct ccl_rpn_attr *n;
257 n = (struct ccl_rpn_attr *)xmalloc (sizeof(*n));
261 n->set = (char*) xmalloc (strlen(set)+1);
262 strcpy (n->set, set);
267 n->next = p->u.t.attr_list;
268 p->u.t.attr_list = n;
270 n->kind = CCL_RPN_ATTR_NUMERIC;
271 n->value.numeric = 0;
276 * add_attr_numeric: Add attribute (type/value) to RPN term node.
277 * p: RPN node of type term.
278 * type: Type of attribute
279 * value: Value of attribute
280 * set: Attribute set name
282 static void add_attr_numeric (struct ccl_rpn_node *p, const char *set,
285 struct ccl_rpn_attr *n;
287 n = add_attr_node(p, set, type);
288 n->kind = CCL_RPN_ATTR_NUMERIC;
289 n->value.numeric = value;
292 static void add_attr_string (struct ccl_rpn_node *p, const char *set,
293 int type, char *value)
295 struct ccl_rpn_attr *n;
297 n = add_attr_node(p, set, type);
298 n->kind = CCL_RPN_ATTR_STRING;
299 n->value.str = xstrdup(value);
304 * search_term: Parse CCL search term.
306 * qa: Qualifier attributes already applied.
307 * term_list: tokens we accept as terms in context
308 * multi: whether we accept "multiple" tokens
309 * return: pointer to node(s); NULL on error.
311 static struct ccl_rpn_node *search_term_x (CCL_parser cclp,
312 struct ccl_rpn_attr **qa,
313 int *term_list, int multi)
315 struct ccl_rpn_node *p_top = 0;
316 struct ccl_token *lookahead = cclp->look_token;
320 const char *truncation_aliases;
323 ccl_qual_search_special(cclp->bibset, "truncation");
324 if (!truncation_aliases)
325 truncation_aliases = "?";
327 if (qual_val_type (qa, CCL_BIB1_STR, CCL_BIB1_STR_AND_LIST, 0))
329 if (qual_val_type (qa, CCL_BIB1_STR, CCL_BIB1_STR_OR_LIST, 0))
333 struct ccl_rpn_node *p;
339 int relation_value = -1;
340 int position_value = -1;
341 int structure_value = -1;
342 int truncation_value = -1;
343 int completeness_value = -1;
346 if (and_list || or_list || !multi)
349 /* ignore commas when dealing with and-lists .. */
350 if (and_list && lookahead && lookahead->kind == CCL_TOK_COMMA)
352 lookahead = lookahead->next;
356 /* go through each TERM token. If no truncation attribute is yet
357 met, then look for left/right truncation markers (?) and
358 set left_trunc/right_trunc/mid_trunc accordingly */
359 for (no = 0; no < max && is_term_ok(lookahead->kind, term_list); no++)
361 for (i = 0; i<lookahead->len; i++)
362 if (lookahead->name[i] == ' ')
364 else if (strchr(truncation_aliases, lookahead->name[i]))
366 if (no == 0 && i == 0 && lookahead->len >= 1)
368 else if (!is_term_ok(lookahead->next->kind, term_list) &&
369 i == lookahead->len-1 && i >= 1)
374 len += 1+lookahead->len;
375 lookahead = lookahead->next;
379 break; /* no more terms . stop . */
385 p = mk_node (CCL_RPN_OR);
387 p = mk_node (CCL_RPN_AND);
389 p = mk_node (CCL_RPN_AND);
394 /* create the term node, but wait a moment before adding the term */
395 p = mk_node (CCL_RPN_TERM);
396 p->u.t.attr_list = NULL;
399 /* make the top node point to us.. */
406 /* go through all attributes and add them to the attribute list */
407 for (i=0; qa && qa[i]; i++)
409 struct ccl_rpn_attr *attr;
411 for (attr = qa[i]; attr; attr = attr->next)
414 case CCL_RPN_ATTR_STRING:
415 add_attr_string(p, attr->set, attr->type,
418 case CCL_RPN_ATTR_NUMERIC:
419 if (attr->value.numeric > 0)
420 { /* deal only with REAL attributes (positive) */
424 if (relation_value != -1)
426 relation_value = attr->value.numeric;
429 if (position_value != -1)
431 position_value = attr->value.numeric;
434 if (structure_value != -1)
436 structure_value = attr->value.numeric;
439 if (truncation_value != -1)
441 truncation_value = attr->value.numeric;
442 left_trunc = right_trunc = mid_trunc = 0;
445 if (completeness_value != -1)
447 completeness_value = attr->value.numeric;
450 add_attr_numeric(p, attr->set, attr->type,
451 attr->value.numeric);
455 /* len now holds the number of characters in the RPN term */
456 /* no holds the number of CCL tokens (1 or more) */
458 if (structure_value == -1 &&
459 qual_val_type (qa, CCL_BIB1_STR, CCL_BIB1_STR_WP, &attset))
460 { /* no structure attribute met. Apply either structure attribute
461 WORD or PHRASE depending on number of CCL tokens */
462 if (no == 1 && no_spaces == 0)
463 add_attr_numeric (p, attset, CCL_BIB1_STR, 2);
465 add_attr_numeric (p, attset, CCL_BIB1_STR, 1);
468 /* make the RPN token */
469 p->u.t.term = (char *)xmalloc (len);
470 ccl_assert (p->u.t.term);
471 p->u.t.term[0] = '\0';
472 for (i = 0; i<no; i++)
474 const char *src_str = cclp->look_token->name;
475 int src_len = cclp->look_token->len;
477 if (i == 0 && left_trunc)
482 if (i == no-1 && right_trunc)
486 int len = strlen(p->u.t.term);
488 !strchr("-+", *src_str) &&
489 !strchr("-+", p->u.t.term[len-1]))
491 strcat (p->u.t.term, " ");
494 strxcat (p->u.t.term, src_str, src_len);
497 if (left_trunc && right_trunc)
499 if (!qual_val_type (qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_BOTH,
502 cclp->error_code = CCL_ERR_TRUNC_NOT_BOTH;
506 add_attr_numeric (p, attset, CCL_BIB1_TRU, 3);
508 else if (right_trunc)
510 if (!qual_val_type (qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_RIGHT,
513 cclp->error_code = CCL_ERR_TRUNC_NOT_RIGHT;
517 add_attr_numeric (p, attset, CCL_BIB1_TRU, 1);
521 if (!qual_val_type (qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_LEFT,
524 cclp->error_code = CCL_ERR_TRUNC_NOT_LEFT;
528 add_attr_numeric (p, attset, CCL_BIB1_TRU, 2);
532 if (qual_val_type (qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_NONE,
534 add_attr_numeric (p, attset, CCL_BIB1_TRU, 100);
540 cclp->error_code = CCL_ERR_TERM_EXPECTED;
544 static struct ccl_rpn_node *search_term (CCL_parser cclp,
545 struct ccl_rpn_attr **qa)
547 static int list[] = {CCL_TOK_TERM, CCL_TOK_COMMA, -1};
548 return search_term_x(cclp, qa, list, 0);
552 struct ccl_rpn_node *qualifiers_order (CCL_parser cclp,
553 struct ccl_rpn_attr **ap, char *attset)
556 struct ccl_rpn_node *p;
558 if (cclp->look_token->len == 1)
560 if (cclp->look_token->name[0] == '<')
562 else if (cclp->look_token->name[0] == '=')
564 else if (cclp->look_token->name[0] == '>')
567 else if (cclp->look_token->len == 2)
569 if (!memcmp (cclp->look_token->name, "<=", 2))
571 else if (!memcmp (cclp->look_token->name, ">=", 2))
573 else if (!memcmp (cclp->look_token->name, "<>", 2))
578 cclp->error_code = CCL_ERR_BAD_RELATION;
581 ADVANCE; /* skip relation */
583 qual_val_type(ap, CCL_BIB1_REL, CCL_BIB1_REL_PORDER, 0))
585 /* allow - inside term and treat it as range _always_ */
586 /* relation is =. Extract "embedded" - to separate terms */
587 if (KIND == CCL_TOK_TERM)
590 for (i = 0; i<cclp->look_token->len; i++)
592 if (cclp->look_token->name[i] == '-')
596 if (cclp->look_token->len > 1 && i == 0)
598 struct ccl_token *ntoken = ccl_token_add (cclp->look_token);
600 ntoken->kind = CCL_TOK_TERM;
601 ntoken->name = cclp->look_token->name + 1;
602 ntoken->len = cclp->look_token->len - 1;
604 cclp->look_token->len = 1;
605 cclp->look_token->name = "-";
607 else if (cclp->look_token->len > 1 && i == cclp->look_token->len-1)
609 struct ccl_token *ntoken = ccl_token_add (cclp->look_token);
611 ntoken->kind = CCL_TOK_TERM;
615 (cclp->look_token->len)--;
617 else if (cclp->look_token->len > 2 && i < cclp->look_token->len)
619 struct ccl_token *ntoken1 = ccl_token_add (cclp->look_token);
620 struct ccl_token *ntoken2 = ccl_token_add (ntoken1);
622 ntoken1->kind = CCL_TOK_TERM; /* generate - */
626 ntoken2->kind = CCL_TOK_TERM; /* generate yy */
627 ntoken2->name = cclp->look_token->name + (i+1);
628 ntoken2->len = cclp->look_token->len - (i+1);
630 cclp->look_token->len = i; /* adjust xx */
632 else if (i == cclp->look_token->len &&
633 cclp->look_token->next &&
634 cclp->look_token->next->kind == CCL_TOK_TERM &&
635 cclp->look_token->next->len > 1 &&
636 cclp->look_token->next->name[0] == '-')
639 /* we _know_ that xx does not have - in it */
640 struct ccl_token *ntoken = ccl_token_add (cclp->look_token);
642 ntoken->kind = CCL_TOK_TERM; /* generate - */
646 (ntoken->next->name)++; /* adjust yy */
647 (ntoken->next->len)--;
653 KIND == CCL_TOK_TERM &&
654 cclp->look_token->next && cclp->look_token->next->len == 1 &&
655 cclp->look_token->next->name[0] == '-')
657 struct ccl_rpn_node *p1;
658 if (!(p1 = search_term (cclp, ap)))
660 ADVANCE; /* skip '-' */
661 if (KIND == CCL_TOK_TERM) /* = term - term ? */
663 struct ccl_rpn_node *p2;
665 if (!(p2 = search_term (cclp, ap)))
670 p = mk_node (CCL_RPN_AND);
672 add_attr_numeric (p1, attset, CCL_BIB1_REL, 4);
674 add_attr_numeric (p2, attset, CCL_BIB1_REL, 2);
679 add_attr_numeric (p1, attset, CCL_BIB1_REL, 4);
684 cclp->look_token->len == 1 &&
685 cclp->look_token->name[0] == '-') /* = - term ? */
688 if (!(p = search_term (cclp, ap)))
690 add_attr_numeric (p, attset, CCL_BIB1_REL, 2);
693 else if (KIND == CCL_TOK_LP)
696 if (!(p = find_spec (cclp, ap)))
698 if (KIND != CCL_TOK_RP)
700 cclp->error_code = CCL_ERR_RP_EXPECTED;
709 if (!(p = search_terms (cclp, ap)))
711 add_attr_numeric (p, attset, CCL_BIB1_REL, rel);
714 cclp->error_code = CCL_ERR_TERM_EXPECTED;
719 struct ccl_rpn_node *qualifiers2 (CCL_parser cclp, struct ccl_rpn_attr **ap)
722 struct ccl_rpn_node *p;
724 if (qual_val_type(ap, CCL_BIB1_REL, CCL_BIB1_REL_ORDER, &attset)
725 || qual_val_type(ap, CCL_BIB1_REL, CCL_BIB1_REL_PORDER, &attset))
726 return qualifiers_order(cclp, ap, attset);
728 /* unordered relation */
729 if (KIND != CCL_TOK_EQ)
731 cclp->error_code = CCL_ERR_EQ_EXPECTED;
735 if (KIND == CCL_TOK_LP)
738 if (!(p = find_spec (cclp, ap)))
742 if (KIND != CCL_TOK_RP)
744 cclp->error_code = CCL_ERR_RP_EXPECTED;
751 p = search_terms (cclp, ap);
756 * qualifiers1: Parse CCL qualifiers and search terms.
758 * la: Token pointer to RELATION token.
759 * qa: Qualifier attributes already applied.
760 * return: pointer to node(s); NULL on error.
762 static struct ccl_rpn_node *qualifiers1 (CCL_parser cclp, struct ccl_token *la,
763 struct ccl_rpn_attr **qa)
765 struct ccl_token *lookahead = cclp->look_token;
766 struct ccl_token *look_start = cclp->look_token;
767 struct ccl_rpn_attr **ap;
768 struct ccl_rpn_node *node = 0;
769 const char *field_str;
777 cclp->error_code = CCL_ERR_DOUBLE_QUAL;
781 for (lookahead = cclp->look_token; lookahead != la;
782 lookahead=lookahead->next)
785 for (i=0; qa[i]; i++)
787 ap = (struct ccl_rpn_attr **)xmalloc ((no ? (no+1) : 2) * sizeof(*ap));
790 field_str = ccl_qual_search_special(cclp->bibset, "field");
793 if (!strcmp (field_str, "or"))
795 else if (!strcmp (field_str, "merge"))
800 /* consider each field separately and OR */
801 lookahead = look_start;
802 while (lookahead != la)
806 while ((ap[0] = ccl_qual_search (cclp, lookahead->name,
807 lookahead->len, seq)) != 0)
809 struct ccl_rpn_node *node_sub;
810 cclp->look_token = la;
812 node_sub = qualifiers2(cclp, ap);
815 ccl_rpn_delete (node);
821 struct ccl_rpn_node *node_this = mk_node(CCL_RPN_OR);
822 node_this->u.p[0] = node;
823 node_this->u.p[1] = node_sub;
832 cclp->look_token = lookahead;
833 cclp->error_code = CCL_ERR_UNKNOWN_QUAL;
837 lookahead = lookahead->next;
838 if (lookahead->kind == CCL_TOK_COMMA)
839 lookahead = lookahead->next;
844 /* merge attributes from ALL fields - including inherited ones */
847 struct ccl_rpn_node *node_sub;
849 lookahead = look_start;
850 for (i = 0; lookahead != la; i++)
852 ap[i] = ccl_qual_search (cclp, lookahead->name,
853 lookahead->len, seq);
856 if (!ap[i] && seq > 0)
857 ap[i] = ccl_qual_search (cclp, lookahead->name,
861 cclp->look_token = lookahead;
862 cclp->error_code = CCL_ERR_UNKNOWN_QUAL;
866 lookahead = lookahead->next;
867 if (lookahead->kind == CCL_TOK_COMMA)
868 lookahead = lookahead->next;
872 struct ccl_rpn_attr **qa0 = qa;
882 cclp->look_token = lookahead;
884 node_sub = qualifiers2(cclp, ap);
887 ccl_rpn_delete (node);
892 struct ccl_rpn_node *node_this = mk_node(CCL_RPN_OR);
893 node_this->u.p[0] = node;
894 node_this->u.p[1] = node_sub;
908 * search_terms: Parse CCL search terms - including proximity.
910 * qa: Qualifier attributes already applied.
911 * return: pointer to node(s); NULL on error.
913 static struct ccl_rpn_node *search_terms (CCL_parser cclp,
914 struct ccl_rpn_attr **qa)
916 static int list[] = {
917 CCL_TOK_TERM, CCL_TOK_COMMA,CCL_TOK_EQ, CCL_TOK_REL, CCL_TOK_SET, -1};
918 struct ccl_rpn_node *p1, *p2, *pn;
919 p1 = search_term_x (cclp, qa, list, 1);
924 if (KIND == CCL_TOK_PROX)
926 struct ccl_rpn_node *p_prox = 0;
927 /* ! word order specified */
928 /* % word order not specified */
929 p_prox = mk_node(CCL_RPN_TERM);
930 p_prox->u.t.term = (char *) xmalloc(1 + cclp->look_token->len);
931 memcpy(p_prox->u.t.term, cclp->look_token->name,
932 cclp->look_token->len);
933 p_prox->u.t.term[cclp->look_token->len] = 0;
934 p_prox->u.t.attr_list = 0;
937 p2 = search_term_x (cclp, qa, list, 1);
943 pn = mk_node (CCL_RPN_PROX);
949 else if (is_term_ok(KIND, list))
951 p2 = search_term_x (cclp, qa, list, 1);
957 pn = mk_node (CCL_RPN_PROX);
970 * search_elements: Parse CCL search elements
972 * qa: Qualifier attributes already applied.
973 * return: pointer to node(s); NULL on error.
975 static struct ccl_rpn_node *search_elements (CCL_parser cclp,
976 struct ccl_rpn_attr **qa)
978 struct ccl_rpn_node *p1;
979 struct ccl_token *lookahead;
980 if (KIND == CCL_TOK_LP)
983 p1 = find_spec (cclp, qa);
986 if (KIND != CCL_TOK_RP)
988 cclp->error_code = CCL_ERR_RP_EXPECTED;
995 else if (KIND == CCL_TOK_SET)
998 if (KIND == CCL_TOK_EQ)
1000 if (KIND != CCL_TOK_TERM)
1002 cclp->error_code = CCL_ERR_SETNAME_EXPECTED;
1005 p1 = mk_node (CCL_RPN_SET);
1006 p1->u.setname = copy_token_name (cclp->look_token);
1010 lookahead = cclp->look_token;
1012 while (lookahead->kind==CCL_TOK_TERM)
1014 lookahead = lookahead->next;
1015 if (lookahead->kind == CCL_TOK_REL || lookahead->kind == CCL_TOK_EQ)
1016 return qualifiers1 (cclp, lookahead, qa);
1017 if (lookahead->kind != CCL_TOK_COMMA)
1019 lookahead = lookahead->next;
1022 return search_terms (cclp, qa);
1025 struct ccl_rpn_attr *qa[2];
1026 struct ccl_rpn_node *node = 0;
1028 lookahead = cclp->look_token;
1031 for(seq = 0; ;seq++)
1033 struct ccl_rpn_node *node_sub;
1034 qa[0] = ccl_qual_search(cclp, "term", 4, seq);
1038 cclp->look_token = lookahead;
1040 node_sub = search_terms (cclp, qa);
1043 ccl_rpn_delete (node);
1048 struct ccl_rpn_node *node_this = mk_node(CCL_RPN_OR);
1049 node_this->u.p[0] = node;
1050 node_this->u.p[1] = node_sub;
1051 node_this->u.p[2] = 0;
1058 node = search_terms (cclp, 0);
1064 * find_spec: Parse CCL find specification
1066 * qa: Qualifier attributes already applied.
1067 * return: pointer to node(s); NULL on error.
1069 static struct ccl_rpn_node *find_spec (CCL_parser cclp,
1070 struct ccl_rpn_attr **qa)
1072 struct ccl_rpn_node *p1, *p2, *pn;
1073 if (!(p1 = search_elements (cclp, qa)))
1081 p2 = search_elements (cclp, qa);
1084 ccl_rpn_delete (p1);
1087 pn = mk_node (CCL_RPN_AND);
1095 p2 = search_elements (cclp, qa);
1098 ccl_rpn_delete (p1);
1101 pn = mk_node (CCL_RPN_OR);
1109 p2 = search_elements (cclp, qa);
1112 ccl_rpn_delete (p1);
1115 pn = mk_node (CCL_RPN_NOT);
1127 struct ccl_rpn_node *ccl_parser_find (CCL_parser cclp, struct ccl_token *list)
1129 struct ccl_rpn_node *p;
1131 cclp->look_token = list;
1132 p = find_spec (cclp, NULL);
1133 if (p && KIND != CCL_TOK_EOL)
1135 if (KIND == CCL_TOK_RP)
1136 cclp->error_code = CCL_ERR_BAD_RP;
1138 cclp->error_code = CCL_ERR_OP_EXPECTED;
1142 cclp->error_pos = cclp->look_token->name;
1144 cclp->error_code = CCL_ERR_OK;
1146 cclp->error_code = cclp->error_code;
1151 * ccl_find: Parse CCL find - token representation
1152 * bibset: Bibset to be used for the parsing
1153 * list: List of tokens
1154 * error: Pointer to integer. Holds error no. on completion.
1155 * pos: Pointer to char position. Holds approximate error position.
1156 * return: RPN tree on successful completion; NULL otherwise.
1158 struct ccl_rpn_node *ccl_find (CCL_bibset bibset, struct ccl_token *list,
1159 int *error, const char **pos)
1161 struct ccl_rpn_node *p;
1162 CCL_parser cclp = ccl_parser_create ();
1164 cclp->bibset = bibset;
1166 p = ccl_parser_find (cclp, list);
1168 *error = cclp->error_code;
1169 *pos = cclp->error_pos;
1171 ccl_parser_destroy (cclp);
1177 * ccl_find_str: Parse CCL find - string representation
1178 * bibset: Bibset to be used for the parsing
1179 * str: String to be parsed
1180 * error: Pointer to integer. Holds error no. on completion.
1181 * pos: Pointer to char position. Holds approximate error position.
1182 * return: RPN tree on successful completion; NULL otherwise.
1184 struct ccl_rpn_node *ccl_find_str (CCL_bibset bibset, const char *str,
1185 int *error, int *pos)
1187 CCL_parser cclp = ccl_parser_create ();
1188 struct ccl_token *list;
1189 struct ccl_rpn_node *p;
1191 cclp->bibset = bibset;
1193 list = ccl_parser_tokenize (cclp, str);
1194 p = ccl_parser_find (cclp, list);
1196 *error = cclp->error_code;
1198 *pos = cclp->error_pos - str;
1199 ccl_parser_destroy (cclp);
1200 ccl_token_del (list);