X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=ccl%2Fccltoken.c;h=12111b1726b2ecc9e214ec60b7fca951e1c0e9a9;hb=fde978ee5097a46b9a162dcff3b4b15d24c8c82f;hp=1c45b55d9bfbe417ccf6abcce7ef92a2f5f2ca18;hpb=95043c4abd87486b64ef44a575313cf4153c1445;p=yaz-moved-to-github.git diff --git a/ccl/ccltoken.c b/ccl/ccltoken.c index 1c45b55..12111b1 100644 --- a/ccl/ccltoken.c +++ b/ccl/ccltoken.c @@ -44,45 +44,9 @@ /* CCL - lexical analysis * Europagate, 1995 * - * $Log: ccltoken.c,v $ - * Revision 1.15 2000-05-01 09:36:50 adam - * Range operator only treated in ordered ranges so that minus (-) can be - * used for, say, the and-not operator. + * $Id: ccltoken.c,v 1.18 2001-11-27 22:38:50 adam Exp $ * - * Revision 1.14 2000/03/14 09:06:11 adam - * Added POSIX threads support for frontend server. - * - * Revision 1.13 2000/02/08 10:39:53 adam - * Added a few functions to set name of operands, etc. - * - * Revision 1.12 2000/01/31 13:15:21 adam - * Removed uses of assert(3). Cleanup of ODR. CCL parser update so - * that some characters are not surrounded by spaces in resulting term. - * ILL-code updates. - * - * Revision 1.11 1999/11/30 13:47:11 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.10 1998/07/07 15:49:41 adam - * Added braces to avoid warning. - * - * Revision 1.9 1998/02/11 11:53:33 adam - * Changed code so that it compiles as C++. - * - * Revision 1.8 1997/09/29 08:56:38 adam - * Changed CCL parser to be thread safe. New type, CCL_parser, declared - * and a create/destructers ccl_parser_create/ccl_parser/destory has - * been added. - * - * Revision 1.7 1997/09/01 08:48:12 adam - * New windows NT/95 port using MSV5.0. Only a few changes made - * to avoid warnings. - * - * Revision 1.6 1997/04/30 08:52:07 quinn - * Null - * - * Revision 1.5 1996/10/11 15:00:26 adam - * CCL parser from Europagate Email gateway 1.0. + * Old Europagate Log: * * Revision 1.10 1995/07/11 12:28:31 adam * New function: ccl_token_simple (split into simple tokens) and @@ -135,13 +99,19 @@ static int token_cmp (CCL_parser cclp, const char *kw, struct ccl_token *token) { const char *cp1 = kw; const char *cp2; + const char *aliases; + int case_sensitive = cclp->ccl_case_sensitive; + + aliases = ccl_qual_search_special(cclp->bibset, "case"); + if (aliases) + case_sensitive = atoi(aliases); if (!kw) return 0; while ((cp2 = strchr (cp1, ' '))) { if (token->len == (size_t) (cp2-cp1)) { - if (cclp->ccl_case_sensitive) + if (case_sensitive) { if (!memcmp (cp1, token->name, token->len)) return 1; @@ -154,7 +124,7 @@ static int token_cmp (CCL_parser cclp, const char *kw, struct ccl_token *token) } cp1 = cp2+1; } - if (cclp->ccl_case_sensitive) + if (case_sensitive) return token->len == strlen(cp1) && !memcmp (cp1, token->name, token->len); return token->len == strlen(cp1) && @@ -229,6 +199,7 @@ struct ccl_token *ccl_token_simple (const char *command) */ struct ccl_token *ccl_parser_tokenize (CCL_parser cclp, const char *command) { + const char *aliases; const char *cp = command; struct ccl_token *first = NULL; struct ccl_token *last = NULL; @@ -306,21 +277,40 @@ struct ccl_token *ccl_parser_tokenize (CCL_parser cclp, const char *command) cp++; break; default: - while (*cp && !strchr ("(),%!><=- \t\n\r", *cp)) + if (!strchr ("(),%!><=- \t\n\r", cp[-1])) { - cp++; - ++ last->len; + while (*cp && !strchr ("(),%!><=- \t\n\r", *cp)) + { + cp++; + ++ last->len; + } } - if (token_cmp (cclp, cclp->ccl_token_and, last)) + last->kind = CCL_TOK_TERM; + + aliases = ccl_qual_search_special(cclp->bibset, "and"); + if (!aliases) + aliases = cclp->ccl_token_and; + if (token_cmp (cclp, aliases, last)) last->kind = CCL_TOK_AND; - else if (token_cmp (cclp, cclp->ccl_token_or, last)) + + aliases = ccl_qual_search_special(cclp->bibset, "or"); + if (!aliases) + aliases = cclp->ccl_token_or; + if (token_cmp (cclp, aliases, last)) last->kind = CCL_TOK_OR; - else if (token_cmp (cclp, cclp->ccl_token_not, last)) + + aliases = ccl_qual_search_special(cclp->bibset, "not"); + if (!aliases) + aliases = cclp->ccl_token_not; + if (token_cmp (cclp, aliases, last)) last->kind = CCL_TOK_NOT; - else if (token_cmp (cclp, cclp->ccl_token_set, last)) + + aliases = ccl_qual_search_special(cclp->bibset, "set"); + if (!aliases) + aliases = cclp->ccl_token_set; + + if (token_cmp (cclp, aliases, last)) last->kind = CCL_TOK_SET; - else - last->kind = CCL_TOK_TERM; } } return first; @@ -352,7 +342,7 @@ void ccl_token_del (struct ccl_token *list) } } -static char *ccl_strdup (const char *str) +char *ccl_strdup (const char *str) { int len = strlen(str); char *p = (char*) malloc (len+1); @@ -393,23 +383,39 @@ void ccl_parser_destroy (CCL_parser p) void ccl_parser_set_op_and (CCL_parser p, const char *op) { if (p && op) + { + if (p->ccl_token_and) + free (p->ccl_token_and); p->ccl_token_and = ccl_strdup (op); + } } void ccl_parser_set_op_or (CCL_parser p, const char *op) { if (p && op) + { + if (p->ccl_token_or) + free (p->ccl_token_or); p->ccl_token_or = ccl_strdup (op); + } } void ccl_parser_set_op_not (CCL_parser p, const char *op) { if (p && op) + { + if (p->ccl_token_not) + free (p->ccl_token_not); p->ccl_token_not = ccl_strdup (op); + } } void ccl_parser_set_op_set (CCL_parser p, const char *op) { if (p && op) + { + if (p->ccl_token_set) + free (p->ccl_token_set); p->ccl_token_set = ccl_strdup (op); + } } void ccl_parser_set_case (CCL_parser p, int case_sensitivity_flag)