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.
44 /* CCL find (to rpn conversion)
47 * $Id: cclfind.c,v 1.4 2004-09-29 20:37:50 adam Exp $
51 * Revision 1.16 1996/01/08 08:41:13 adam
52 * Removed unused function.
54 * Revision 1.15 1995/07/20 08:14:34 adam
55 * Qualifiers were observed too often. Instead tokens are treated as
56 * qualifiers only when separated by comma.
58 * Revision 1.14 1995/05/16 09:39:26 adam
61 * Revision 1.13 1995/04/17 09:31:42 adam
62 * Improved handling of qualifiers. Aliases or reserved words.
64 * Revision 1.12 1995/03/20 15:27:43 adam
67 * Revision 1.11 1995/02/23 08:31:59 adam
70 * Revision 1.9 1995/02/16 13:20:06 adam
73 * Revision 1.8 1995/02/14 19:59:42 adam
74 * Removed a syntax error.
76 * Revision 1.7 1995/02/14 19:55:10 adam
77 * Header files ccl.h/cclp.h are gone! They have been merged an
78 * moved to ../include/ccl.h.
79 * Node kind(s) in ccl_rpn_node have changed names.
81 * Revision 1.6 1995/02/14 16:20:55 adam
82 * Qualifiers are read from a file now.
84 * Revision 1.5 1995/02/14 14:12:41 adam
85 * Ranges for ordered qualfiers implemented (e.g. pd=1980-1990).
87 * Revision 1.4 1995/02/14 13:16:29 adam
88 * Left and/or right truncation implemented.
90 * Revision 1.3 1995/02/14 10:25:56 adam
91 * The constructions 'qualifier rel term ...' implemented.
93 * Revision 1.2 1995/02/13 15:15:07 adam
94 * Added handling of qualifiers. Not finished yet.
96 * Revision 1.1 1995/02/13 12:35:20 adam
97 * First version of CCL. Qualifiers aren't handled yet.
106 /* returns type of current lookahead */
107 #define KIND (cclp->look_token->kind)
109 /* move one token forward */
110 #define ADVANCE cclp->look_token = cclp->look_token->next
113 * qual_val_type: test for existance of attribute type/value pair.
114 * qa: Attribute array
115 * type: Type of attribute to search for
116 * value: Value of attribute to seach for
117 * return: 1 if found; 0 otherwise.
119 static int qual_val_type (struct ccl_rpn_attr **qa, int type, int value,
123 struct ccl_rpn_attr *q;
127 for (i = 0; (q=qa[i]); i++)
130 if (q->type == type && q->kind == CCL_RPN_ATTR_NUMERIC &&
131 q->value.numeric == value)
143 * strxcat: concatenate strings.
144 * n: Null-terminated Destination string
145 * src: Source string to be appended (not null-terminated)
146 * len: Length of source string.
148 static void strxcat (char *n, const char *src, int len)
158 * copy_token_name: Return copy of CCL token name
159 * tp: Pointer to token info.
160 * return: malloc(3) allocated copy of token name.
162 static char *copy_token_name (struct ccl_token *tp)
164 char *str = (char *)xmalloc (tp->len + 1);
166 memcpy (str, tp->name, tp->len);
172 * mk_node: Create RPN node.
173 * kind: Type of node.
174 * return: pointer to allocated node.
176 static struct ccl_rpn_node *mk_node (int kind)
178 struct ccl_rpn_node *p;
179 p = (struct ccl_rpn_node *)xmalloc (sizeof(*p));
186 * ccl_rpn_delete: Delete RPN tree.
187 * rpn: Pointer to tree.
189 void ccl_rpn_delete (struct ccl_rpn_node *rpn)
191 struct ccl_rpn_attr *attr, *attr1;
199 ccl_rpn_delete (rpn->u.p[0]);
200 ccl_rpn_delete (rpn->u.p[1]);
203 xfree (rpn->u.t.term);
204 for (attr = rpn->u.t.attr_list; attr; attr = attr1)
207 if (attr->kind == CCL_RPN_ATTR_STRING)
208 xfree(attr->value.str);
215 xfree (rpn->u.setname);
218 ccl_rpn_delete (rpn->u.p[0]);
219 ccl_rpn_delete (rpn->u.p[1]);
220 ccl_rpn_delete (rpn->u.p[2]);
226 static struct ccl_rpn_node *find_spec (CCL_parser cclp,
227 struct ccl_rpn_attr **qa);
229 static int is_term_ok (int look, int *list)
231 for (;*list >= 0; list++)
237 static struct ccl_rpn_node *search_terms (CCL_parser cclp,
238 struct ccl_rpn_attr **qa);
240 static struct ccl_rpn_attr *add_attr_node (struct ccl_rpn_node *p,
241 const char *set, int type)
243 struct ccl_rpn_attr *n;
245 n = (struct ccl_rpn_attr *)xmalloc (sizeof(*n));
249 n->set = (char*) xmalloc (strlen(set)+1);
250 strcpy (n->set, set);
255 n->next = p->u.t.attr_list;
256 p->u.t.attr_list = n;
258 n->kind = CCL_RPN_ATTR_NUMERIC;
259 n->value.numeric = 0;
264 * add_attr_numeric: Add attribute (type/value) to RPN term node.
265 * p: RPN node of type term.
266 * type: Type of attribute
267 * value: Value of attribute
268 * set: Attribute set name
270 static void add_attr_numeric (struct ccl_rpn_node *p, const char *set,
273 struct ccl_rpn_attr *n;
275 n = add_attr_node(p, set, type);
276 n->kind = CCL_RPN_ATTR_NUMERIC;
277 n->value.numeric = value;
280 static void add_attr_string (struct ccl_rpn_node *p, const char *set,
281 int type, char *value)
283 struct ccl_rpn_attr *n;
285 n = add_attr_node(p, set, type);
286 n->kind = CCL_RPN_ATTR_STRING;
287 n->value.str = xstrdup(value);
292 * search_term: Parse CCL search term.
294 * qa: Qualifier attributes already applied.
295 * term_list: tokens we accept as terms in context
296 * multi: whether we accept "multiple" tokens
297 * return: pointer to node(s); NULL on error.
299 static struct ccl_rpn_node *search_term_x (CCL_parser cclp,
300 struct ccl_rpn_attr **qa,
301 int *term_list, int multi)
303 struct ccl_rpn_node *p_top = 0;
304 struct ccl_token *lookahead = cclp->look_token;
308 const char *truncation_aliases;
311 ccl_qual_search_special(cclp->bibset, "truncation");
312 if (!truncation_aliases)
313 truncation_aliases = "?";
315 if (qual_val_type (qa, CCL_BIB1_STR, CCL_BIB1_STR_AND_LIST, 0))
317 if (qual_val_type (qa, CCL_BIB1_STR, CCL_BIB1_STR_OR_LIST, 0))
321 struct ccl_rpn_node *p;
327 int relation_value = -1;
328 int position_value = -1;
329 int structure_value = -1;
330 int truncation_value = -1;
331 int completeness_value = -1;
334 if (and_list || or_list || !multi)
337 /* ignore commas when dealing with and-lists .. */
338 if (and_list && lookahead && lookahead->kind == CCL_TOK_COMMA)
340 lookahead = lookahead->next;
344 /* go through each TERM token. If no truncation attribute is yet
345 met, then look for left/right truncation markers (?) and
346 set left_trunc/right_trunc/mid_trunc accordingly */
347 for (no = 0; no < max && is_term_ok(lookahead->kind, term_list); no++)
349 for (i = 0; i<lookahead->len; i++)
350 if (lookahead->name[i] == ' ')
352 else if (strchr(truncation_aliases, lookahead->name[i]))
354 if (no == 0 && i == 0 && lookahead->len >= 1)
356 else if (!is_term_ok(lookahead->next->kind, term_list) &&
357 i == lookahead->len-1 && i >= 1)
362 len += 1+lookahead->len;
363 lookahead = lookahead->next;
367 break; /* no more terms . stop . */
373 p = mk_node (CCL_RPN_OR);
375 p = mk_node (CCL_RPN_AND);
377 p = mk_node (CCL_RPN_AND);
382 /* create the term node, but wait a moment before adding the term */
383 p = mk_node (CCL_RPN_TERM);
384 p->u.t.attr_list = NULL;
387 /* make the top node point to us.. */
394 /* go through all attributes and add them to the attribute list */
395 for (i=0; qa && qa[i]; i++)
397 struct ccl_rpn_attr *attr;
399 for (attr = qa[i]; attr; attr = attr->next)
402 case CCL_RPN_ATTR_STRING:
403 add_attr_string(p, attr->set, attr->type,
406 case CCL_RPN_ATTR_NUMERIC:
407 if (attr->value.numeric > 0)
408 { /* deal only with REAL attributes (positive) */
412 if (relation_value != -1)
414 relation_value = attr->value.numeric;
417 if (position_value != -1)
419 position_value = attr->value.numeric;
422 if (structure_value != -1)
424 structure_value = attr->value.numeric;
427 if (truncation_value != -1)
429 truncation_value = attr->value.numeric;
430 left_trunc = right_trunc = mid_trunc = 0;
433 if (completeness_value != -1)
435 completeness_value = attr->value.numeric;
438 add_attr_numeric(p, attr->set, attr->type,
439 attr->value.numeric);
443 /* len now holds the number of characters in the RPN term */
444 /* no holds the number of CCL tokens (1 or more) */
446 if (structure_value == -1 &&
447 qual_val_type (qa, CCL_BIB1_STR, CCL_BIB1_STR_WP, &attset))
448 { /* no structure attribute met. Apply either structure attribute
449 WORD or PHRASE depending on number of CCL tokens */
450 if (no == 1 && no_spaces == 0)
451 add_attr_numeric (p, attset, CCL_BIB1_STR, 2);
453 add_attr_numeric (p, attset, CCL_BIB1_STR, 1);
456 /* make the RPN token */
457 p->u.t.term = (char *)xmalloc (len);
458 ccl_assert (p->u.t.term);
459 p->u.t.term[0] = '\0';
460 for (i = 0; i<no; i++)
462 const char *src_str = cclp->look_token->name;
463 int src_len = cclp->look_token->len;
465 if (i == 0 && left_trunc)
470 if (i == no-1 && right_trunc)
474 int len = strlen(p->u.t.term);
476 !strchr("-+", *src_str) &&
477 !strchr("-+", p->u.t.term[len-1]))
479 strcat (p->u.t.term, " ");
482 strxcat (p->u.t.term, src_str, src_len);
485 if (left_trunc && right_trunc)
487 if (!qual_val_type (qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_BOTH,
490 cclp->error_code = CCL_ERR_TRUNC_NOT_BOTH;
494 add_attr_numeric (p, attset, CCL_BIB1_TRU, 3);
496 else if (right_trunc)
498 if (!qual_val_type (qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_RIGHT,
501 cclp->error_code = CCL_ERR_TRUNC_NOT_RIGHT;
505 add_attr_numeric (p, attset, CCL_BIB1_TRU, 1);
509 if (!qual_val_type (qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_LEFT,
512 cclp->error_code = CCL_ERR_TRUNC_NOT_LEFT;
516 add_attr_numeric (p, attset, CCL_BIB1_TRU, 2);
520 if (qual_val_type (qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_NONE,
522 add_attr_numeric (p, attset, CCL_BIB1_TRU, 100);
528 cclp->error_code = CCL_ERR_TERM_EXPECTED;
532 static struct ccl_rpn_node *search_term (CCL_parser cclp,
533 struct ccl_rpn_attr **qa)
535 static int list[] = {CCL_TOK_TERM, CCL_TOK_COMMA, -1};
536 return search_term_x(cclp, qa, list, 0);
540 struct ccl_rpn_node *qualifiers_order (CCL_parser cclp,
541 struct ccl_rpn_attr **ap, char *attset)
544 struct ccl_rpn_node *p;
546 if (cclp->look_token->len == 1)
548 if (cclp->look_token->name[0] == '<')
550 else if (cclp->look_token->name[0] == '=')
552 else if (cclp->look_token->name[0] == '>')
555 else if (cclp->look_token->len == 2)
557 if (!memcmp (cclp->look_token->name, "<=", 2))
559 else if (!memcmp (cclp->look_token->name, ">=", 2))
561 else if (!memcmp (cclp->look_token->name, "<>", 2))
566 cclp->error_code = CCL_ERR_BAD_RELATION;
569 ADVANCE; /* skip relation */
571 qual_val_type(ap, CCL_BIB1_REL, CCL_BIB1_REL_PORDER, 0))
573 /* allow - inside term and treat it as range _always_ */
574 /* relation is =. Extract "embedded" - to separate terms */
575 if (KIND == CCL_TOK_TERM)
578 for (i = 0; i<cclp->look_token->len; i++)
580 if (cclp->look_token->name[i] == '-')
584 if (cclp->look_token->len > 1 && i == 0)
586 struct ccl_token *ntoken = ccl_token_add (cclp->look_token);
588 ntoken->kind = CCL_TOK_TERM;
589 ntoken->name = cclp->look_token->name + 1;
590 ntoken->len = cclp->look_token->len - 1;
592 cclp->look_token->len = 1;
593 cclp->look_token->name = "-";
595 else if (cclp->look_token->len > 1 && i == cclp->look_token->len-1)
597 struct ccl_token *ntoken = ccl_token_add (cclp->look_token);
599 ntoken->kind = CCL_TOK_TERM;
603 (cclp->look_token->len)--;
605 else if (cclp->look_token->len > 2 && i < cclp->look_token->len)
607 struct ccl_token *ntoken1 = ccl_token_add (cclp->look_token);
608 struct ccl_token *ntoken2 = ccl_token_add (ntoken1);
610 ntoken1->kind = CCL_TOK_TERM; /* generate - */
614 ntoken2->kind = CCL_TOK_TERM; /* generate yy */
615 ntoken2->name = cclp->look_token->name + (i+1);
616 ntoken2->len = cclp->look_token->len - (i+1);
618 cclp->look_token->len = i; /* adjust xx */
620 else if (i == cclp->look_token->len &&
621 cclp->look_token->next &&
622 cclp->look_token->next->kind == CCL_TOK_TERM &&
623 cclp->look_token->next->len > 1 &&
624 cclp->look_token->next->name[0] == '-')
627 /* we _know_ that xx does not have - in it */
628 struct ccl_token *ntoken = ccl_token_add (cclp->look_token);
630 ntoken->kind = CCL_TOK_TERM; /* generate - */
634 (ntoken->next->name)++; /* adjust yy */
635 (ntoken->next->len)--;
641 KIND == CCL_TOK_TERM &&
642 cclp->look_token->next && cclp->look_token->next->len == 1 &&
643 cclp->look_token->next->name[0] == '-')
645 struct ccl_rpn_node *p1;
646 if (!(p1 = search_term (cclp, ap)))
648 ADVANCE; /* skip '-' */
649 if (KIND == CCL_TOK_TERM) /* = term - term ? */
651 struct ccl_rpn_node *p2;
653 if (!(p2 = search_term (cclp, ap)))
658 p = mk_node (CCL_RPN_AND);
660 add_attr_numeric (p1, attset, CCL_BIB1_REL, 4);
662 add_attr_numeric (p2, attset, CCL_BIB1_REL, 2);
667 add_attr_numeric (p1, attset, CCL_BIB1_REL, 4);
672 cclp->look_token->len == 1 &&
673 cclp->look_token->name[0] == '-') /* = - term ? */
676 if (!(p = search_term (cclp, ap)))
678 add_attr_numeric (p, attset, CCL_BIB1_REL, 2);
681 else if (KIND == CCL_TOK_LP)
684 if (!(p = find_spec (cclp, ap)))
686 if (KIND != CCL_TOK_RP)
688 cclp->error_code = CCL_ERR_RP_EXPECTED;
697 if (!(p = search_terms (cclp, ap)))
699 add_attr_numeric (p, attset, CCL_BIB1_REL, rel);
702 cclp->error_code = CCL_ERR_TERM_EXPECTED;
707 struct ccl_rpn_node *qualifiers2 (CCL_parser cclp, struct ccl_rpn_attr **ap)
710 struct ccl_rpn_node *p;
712 if (qual_val_type(ap, CCL_BIB1_REL, CCL_BIB1_REL_ORDER, &attset)
713 || qual_val_type(ap, CCL_BIB1_REL, CCL_BIB1_REL_PORDER, &attset))
714 return qualifiers_order(cclp, ap, attset);
716 /* unordered relation */
717 if (KIND != CCL_TOK_EQ)
719 cclp->error_code = CCL_ERR_EQ_EXPECTED;
723 if (KIND == CCL_TOK_LP)
726 if (!(p = find_spec (cclp, ap)))
730 if (KIND != CCL_TOK_RP)
732 cclp->error_code = CCL_ERR_RP_EXPECTED;
739 p = search_terms (cclp, ap);
744 * qualifiers1: Parse CCL qualifiers and search terms.
746 * la: Token pointer to RELATION token.
747 * qa: Qualifier attributes already applied.
748 * return: pointer to node(s); NULL on error.
750 static struct ccl_rpn_node *qualifiers1 (CCL_parser cclp, struct ccl_token *la,
751 struct ccl_rpn_attr **qa)
753 struct ccl_token *lookahead = cclp->look_token;
754 struct ccl_token *look_start = cclp->look_token;
755 struct ccl_rpn_attr **ap;
756 struct ccl_rpn_node *node = 0;
757 const char *field_str;
765 cclp->error_code = CCL_ERR_DOUBLE_QUAL;
769 for (lookahead = cclp->look_token; lookahead != la;
770 lookahead=lookahead->next)
773 for (i=0; qa[i]; i++)
775 ap = (struct ccl_rpn_attr **)xmalloc ((no ? (no+1) : 2) * sizeof(*ap));
778 field_str = ccl_qual_search_special(cclp->bibset, "field");
781 if (!strcmp (field_str, "or"))
783 else if (!strcmp (field_str, "merge"))
788 /* consider each field separately and OR */
789 lookahead = look_start;
790 while (lookahead != la)
794 while ((ap[0] = ccl_qual_search (cclp, lookahead->name,
795 lookahead->len, seq)) != 0)
797 struct ccl_rpn_node *node_sub;
798 cclp->look_token = la;
800 node_sub = qualifiers2(cclp, ap);
803 ccl_rpn_delete (node);
809 struct ccl_rpn_node *node_this = mk_node(CCL_RPN_OR);
810 node_this->u.p[0] = node;
811 node_this->u.p[1] = node_sub;
820 cclp->look_token = lookahead;
821 cclp->error_code = CCL_ERR_UNKNOWN_QUAL;
825 lookahead = lookahead->next;
826 if (lookahead->kind == CCL_TOK_COMMA)
827 lookahead = lookahead->next;
832 /* merge attributes from ALL fields - including inherited ones */
835 struct ccl_rpn_node *node_sub;
837 lookahead = look_start;
838 for (i = 0; lookahead != la; i++)
840 ap[i] = ccl_qual_search (cclp, lookahead->name,
841 lookahead->len, seq);
844 if (!ap[i] && seq > 0)
845 ap[i] = ccl_qual_search (cclp, lookahead->name,
849 cclp->look_token = lookahead;
850 cclp->error_code = CCL_ERR_UNKNOWN_QUAL;
854 lookahead = lookahead->next;
855 if (lookahead->kind == CCL_TOK_COMMA)
856 lookahead = lookahead->next;
860 struct ccl_rpn_attr **qa0 = qa;
870 cclp->look_token = lookahead;
872 node_sub = qualifiers2(cclp, ap);
875 ccl_rpn_delete (node);
880 struct ccl_rpn_node *node_this = mk_node(CCL_RPN_OR);
881 node_this->u.p[0] = node;
882 node_this->u.p[1] = node_sub;
896 * search_terms: Parse CCL search terms - including proximity.
898 * qa: Qualifier attributes already applied.
899 * return: pointer to node(s); NULL on error.
901 static struct ccl_rpn_node *search_terms (CCL_parser cclp,
902 struct ccl_rpn_attr **qa)
904 static int list[] = {
905 CCL_TOK_TERM, CCL_TOK_COMMA,CCL_TOK_EQ, CCL_TOK_REL, CCL_TOK_SET, -1};
906 struct ccl_rpn_node *p1, *p2, *pn;
907 p1 = search_term_x (cclp, qa, list, 1);
912 if (KIND == CCL_TOK_PROX)
914 struct ccl_rpn_node *p_prox = 0;
915 /* ! word order specified */
916 /* % word order not specified */
917 p_prox = mk_node(CCL_RPN_TERM);
918 p_prox->u.t.term = (char *) xmalloc(1 + cclp->look_token->len);
919 memcpy(p_prox->u.t.term, cclp->look_token->name,
920 cclp->look_token->len);
921 p_prox->u.t.term[cclp->look_token->len] = 0;
922 p_prox->u.t.attr_list = 0;
925 p2 = search_term_x (cclp, qa, list, 1);
931 pn = mk_node (CCL_RPN_PROX);
937 else if (is_term_ok(KIND, list))
939 p2 = search_term_x (cclp, qa, list, 1);
945 pn = mk_node (CCL_RPN_PROX);
958 * search_elements: Parse CCL search elements
960 * qa: Qualifier attributes already applied.
961 * return: pointer to node(s); NULL on error.
963 static struct ccl_rpn_node *search_elements (CCL_parser cclp,
964 struct ccl_rpn_attr **qa)
966 struct ccl_rpn_node *p1;
967 struct ccl_token *lookahead;
968 if (KIND == CCL_TOK_LP)
971 p1 = find_spec (cclp, qa);
974 if (KIND != CCL_TOK_RP)
976 cclp->error_code = CCL_ERR_RP_EXPECTED;
983 else if (KIND == CCL_TOK_SET)
986 if (KIND == CCL_TOK_EQ)
988 if (KIND != CCL_TOK_TERM)
990 cclp->error_code = CCL_ERR_SETNAME_EXPECTED;
993 p1 = mk_node (CCL_RPN_SET);
994 p1->u.setname = copy_token_name (cclp->look_token);
998 lookahead = cclp->look_token;
1000 while (lookahead->kind==CCL_TOK_TERM)
1002 lookahead = lookahead->next;
1003 if (lookahead->kind == CCL_TOK_REL || lookahead->kind == CCL_TOK_EQ)
1004 return qualifiers1 (cclp, lookahead, qa);
1005 if (lookahead->kind != CCL_TOK_COMMA)
1007 lookahead = lookahead->next;
1010 return search_terms (cclp, qa);
1013 struct ccl_rpn_attr *qa[2];
1014 struct ccl_rpn_node *node = 0;
1016 lookahead = cclp->look_token;
1019 for(seq = 0; ;seq++)
1021 struct ccl_rpn_node *node_sub;
1022 qa[0] = ccl_qual_search(cclp, "term", 4, seq);
1026 cclp->look_token = lookahead;
1028 node_sub = search_terms (cclp, qa);
1031 ccl_rpn_delete (node);
1036 struct ccl_rpn_node *node_this = mk_node(CCL_RPN_OR);
1037 node_this->u.p[0] = node;
1038 node_this->u.p[1] = node_sub;
1039 node_this->u.p[2] = 0;
1046 node = search_terms (cclp, 0);
1052 * find_spec: Parse CCL find specification
1054 * qa: Qualifier attributes already applied.
1055 * return: pointer to node(s); NULL on error.
1057 static struct ccl_rpn_node *find_spec (CCL_parser cclp,
1058 struct ccl_rpn_attr **qa)
1060 struct ccl_rpn_node *p1, *p2, *pn;
1061 if (!(p1 = search_elements (cclp, qa)))
1069 p2 = search_elements (cclp, qa);
1072 ccl_rpn_delete (p1);
1075 pn = mk_node (CCL_RPN_AND);
1083 p2 = search_elements (cclp, qa);
1086 ccl_rpn_delete (p1);
1089 pn = mk_node (CCL_RPN_OR);
1097 p2 = search_elements (cclp, qa);
1100 ccl_rpn_delete (p1);
1103 pn = mk_node (CCL_RPN_NOT);
1115 struct ccl_rpn_node *ccl_parser_find (CCL_parser cclp, struct ccl_token *list)
1117 struct ccl_rpn_node *p;
1119 cclp->look_token = list;
1120 p = find_spec (cclp, NULL);
1121 if (p && KIND != CCL_TOK_EOL)
1123 if (KIND == CCL_TOK_RP)
1124 cclp->error_code = CCL_ERR_BAD_RP;
1126 cclp->error_code = CCL_ERR_OP_EXPECTED;
1130 cclp->error_pos = cclp->look_token->name;
1132 cclp->error_code = CCL_ERR_OK;
1134 cclp->error_code = cclp->error_code;
1139 * ccl_find: Parse CCL find - token representation
1140 * bibset: Bibset to be used for the parsing
1141 * list: List of tokens
1142 * error: Pointer to integer. Holds error no. on completion.
1143 * pos: Pointer to char position. Holds approximate error position.
1144 * return: RPN tree on successful completion; NULL otherwise.
1146 struct ccl_rpn_node *ccl_find (CCL_bibset bibset, struct ccl_token *list,
1147 int *error, const char **pos)
1149 struct ccl_rpn_node *p;
1150 CCL_parser cclp = ccl_parser_create ();
1152 cclp->bibset = bibset;
1154 p = ccl_parser_find (cclp, list);
1156 *error = cclp->error_code;
1157 *pos = cclp->error_pos;
1159 ccl_parser_destroy (cclp);
1165 * ccl_find_str: Parse CCL find - string representation
1166 * bibset: Bibset to be used for the parsing
1167 * str: String to be parsed
1168 * error: Pointer to integer. Holds error no. on completion.
1169 * pos: Pointer to char position. Holds approximate error position.
1170 * return: RPN tree on successful completion; NULL otherwise.
1172 struct ccl_rpn_node *ccl_find_str (CCL_bibset bibset, const char *str,
1173 int *error, int *pos)
1175 CCL_parser cclp = ccl_parser_create ();
1176 struct ccl_token *list;
1177 struct ccl_rpn_node *p;
1179 cclp->bibset = bibset;
1181 list = ccl_parser_tokenize (cclp, str);
1182 p = ccl_parser_find (cclp, list);
1184 *error = cclp->error_code;
1186 *pos = cclp->error_pos - str;
1187 ccl_parser_destroy (cclp);
1188 ccl_token_del (list);