X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fcclfind.c;h=9037887eaf1e4d31bf16627ab2aef73753b9f55b;hb=58e7306c9f23189e136c52b21e39692392824ea7;hp=0883235617aea7dd7cf7cdf6822ba97f8a02f514;hpb=e4baade57ba02d625ecd6452b0f4383b24c25f2d;p=yaz-moved-to-github.git diff --git a/src/cclfind.c b/src/cclfind.c index 0883235..9037887 100644 --- a/src/cclfind.c +++ b/src/cclfind.c @@ -41,10 +41,22 @@ * USE OR PERFORMANCE OF THIS SOFTWARE. * */ + +/** + * \file cclfind.c + * \brief Implements parsing of a CCL FIND query. + * + * This source file implements parsing of a CCL Query (ISO8777). + * The parser uses predictive parsing, but it does several tokens + * of lookahead in the handling of relational operations.. So + * it's not really pure. + */ + + /* CCL find (to rpn conversion) * Europagate, 1995 * - * $Id: cclfind.c,v 1.4 2004-09-29 20:37:50 adam Exp $ + * $Id: cclfind.c,v 1.7 2005-03-15 16:32:52 adam Exp $ * * Old Europagate log: * @@ -109,7 +121,7 @@ /* move one token forward */ #define ADVANCE cclp->look_token = cclp->look_token->next -/* +/** * qual_val_type: test for existance of attribute type/value pair. * qa: Attribute array * type: Type of attribute to search for @@ -139,7 +151,7 @@ static int qual_val_type (struct ccl_rpn_attr **qa, int type, int value, return 0; } -/* +/** * strxcat: concatenate strings. * n: Null-terminated Destination string * src: Source string to be appended (not null-terminated) @@ -154,7 +166,7 @@ static void strxcat (char *n, const char *src, int len) *n = '\0'; } -/* +/** * copy_token_name: Return copy of CCL token name * tp: Pointer to token info. * return: malloc(3) allocated copy of token name. @@ -168,7 +180,7 @@ static char *copy_token_name (struct ccl_token *tp) return str; } -/* +/** * mk_node: Create RPN node. * kind: Type of node. * return: pointer to allocated node. @@ -182,7 +194,7 @@ static struct ccl_rpn_node *mk_node (int kind) return p; } -/* +/** * ccl_rpn_delete: Delete RPN tree. * rpn: Pointer to tree. */ @@ -260,7 +272,7 @@ static struct ccl_rpn_attr *add_attr_node (struct ccl_rpn_node *p, return n; } -/* +/** * add_attr_numeric: Add attribute (type/value) to RPN term node. * p: RPN node of type term. * type: Type of attribute @@ -288,7 +300,7 @@ static void add_attr_string (struct ccl_rpn_node *p, const char *set, } -/* +/** * search_term: Parse CCL search term. * cclp: CCL Parser * qa: Qualifier attributes already applied. @@ -359,7 +371,7 @@ static struct ccl_rpn_node *search_term_x (CCL_parser cclp, else mid_trunc = 1; } - len += 1+lookahead->len; + len += 1+lookahead->len+lookahead->ws_prefix_len; lookahead = lookahead->next; } @@ -469,15 +481,12 @@ static struct ccl_rpn_node *search_term_x (CCL_parser cclp, } if (i == no-1 && right_trunc) src_len--; - if (src_len) - { - int len = strlen(p->u.t.term); - if (len && - !strchr("-+", *src_str) && - !strchr("-+", p->u.t.term[len-1])) - { - strcat (p->u.t.term, " "); - } + if (i && cclp->look_token->ws_prefix_len) + { + size_t len = strlen(p->u.t.term); + memcpy(p->u.t.term + len, cclp->look_token->ws_prefix_buf, + cclp->look_token->ws_prefix_len); + p->u.t.term[len + cclp->look_token->ws_prefix_len] = '\0'; } strxcat (p->u.t.term, src_str, src_len); ADVANCE; @@ -574,7 +583,7 @@ struct ccl_rpn_node *qualifiers_order (CCL_parser cclp, /* relation is =. Extract "embedded" - to separate terms */ if (KIND == CCL_TOK_TERM) { - int i; + size_t i; for (i = 0; ilook_token->len; i++) { if (cclp->look_token->name[i] == '-') @@ -740,7 +749,7 @@ struct ccl_rpn_node *qualifiers2 (CCL_parser cclp, struct ccl_rpn_attr **ap) return p; } -/* +/** * qualifiers1: Parse CCL qualifiers and search terms. * cclp: CCL Parser * la: Token pointer to RELATION token. @@ -892,7 +901,7 @@ static struct ccl_rpn_node *qualifiers1 (CCL_parser cclp, struct ccl_token *la, } -/* +/** * search_terms: Parse CCL search terms - including proximity. * cclp: CCL Parser * qa: Qualifier attributes already applied. @@ -954,7 +963,7 @@ static struct ccl_rpn_node *search_terms (CCL_parser cclp, return p1; } -/* +/** * search_elements: Parse CCL search elements * cclp: CCL Parser * qa: Qualifier attributes already applied. @@ -1048,7 +1057,7 @@ static struct ccl_rpn_node *search_elements (CCL_parser cclp, } } -/* +/** * find_spec: Parse CCL find specification * cclp: CCL Parser * qa: Qualifier attributes already applied. @@ -1135,7 +1144,7 @@ struct ccl_rpn_node *ccl_parser_find (CCL_parser cclp, struct ccl_token *list) return p; } -/* +/** * ccl_find: Parse CCL find - token representation * bibset: Bibset to be used for the parsing * list: List of tokens @@ -1161,7 +1170,7 @@ struct ccl_rpn_node *ccl_find (CCL_bibset bibset, struct ccl_token *list, return p; } -/* +/** * ccl_find_str: Parse CCL find - string representation * bibset: Bibset to be used for the parsing * str: String to be parsed