X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=ccl%2Fccltoken.c;h=1521c90e6602531fc45aa5c811a2699d0bb3288b;hp=64a82793120ef972197f987403b7044985ba5448;hb=30cfc59b71c25923e2e9cfb63c310c095bb3b6c1;hpb=a00dfa73d5d3796f8048f2134fec2685b62e2658 diff --git a/ccl/ccltoken.c b/ccl/ccltoken.c index 64a8279..1521c90 100644 --- a/ccl/ccltoken.c +++ b/ccl/ccltoken.c @@ -45,7 +45,21 @@ * Europagate, 1995 * * $Log: ccltoken.c,v $ - * Revision 1.7 1997-09-01 08:48:12 adam + * 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. * @@ -95,13 +109,7 @@ #include #include -#include - -const char *ccl_token_and = "and"; -const char *ccl_token_or = "or"; -const char *ccl_token_not = "not andnot"; -const char *ccl_token_set = "set"; -int ccl_case_sensitive = 1; +#include /* * token_cmp: Compare token with keyword(s) @@ -110,7 +118,7 @@ int ccl_case_sensitive = 1; * return: 1 if token string matches one of the keywords in list; * 0 otherwise. */ -static int token_cmp (const char *kw, struct ccl_token *token) +static int token_cmp (CCL_parser cclp, const char *kw, struct ccl_token *token) { const char *cp1 = kw; const char *cp2; @@ -119,7 +127,8 @@ static int token_cmp (const char *kw, struct ccl_token *token) while ((cp2 = strchr (cp1, ' '))) { if (token->len == (size_t) (cp2-cp1)) - if (ccl_case_sensitive) + { + if (cclp->ccl_case_sensitive) { if (!memcmp (cp1, token->name, token->len)) return 1; @@ -129,9 +138,10 @@ static int token_cmp (const char *kw, struct ccl_token *token) if (!ccl_memicmp (cp1, token->name, token->len)) return 1; } + } cp1 = cp2+1; } - if (ccl_case_sensitive) + if (cclp->ccl_case_sensitive) return token->len == strlen(cp1) && !memcmp (cp1, token->name, token->len); return token->len == strlen(cp1) && @@ -156,13 +166,13 @@ struct ccl_token *ccl_token_simple (const char *command) } if (!first) { - first = last = malloc (sizeof (*first)); + first = last = (struct ccl_token *)malloc (sizeof (*first)); assert (first); last->prev = NULL; } else { - last->next = malloc (sizeof(*first)); + last->next = (struct ccl_token *)malloc (sizeof(*first)); assert (last->next); last->next->prev = last; last = last->next; @@ -199,11 +209,12 @@ struct ccl_token *ccl_token_simple (const char *command) return first; } + /* * ccl_tokenize: tokenize CCL command string. * return: CCL token list. */ -struct ccl_token *ccl_tokenize (const char *command) +struct ccl_token *ccl_parser_tokenize (CCL_parser cclp, const char *command) { const char *cp = command; struct ccl_token *first = NULL; @@ -218,13 +229,13 @@ struct ccl_token *ccl_tokenize (const char *command) } if (!first) { - first = last = malloc (sizeof (*first)); + first = last = (struct ccl_token *)malloc (sizeof (*first)); assert (first); last->prev = NULL; } else { - last->next = malloc (sizeof(*first)); + last->next = (struct ccl_token *)malloc (sizeof(*first)); assert (last->next); last->next->prev = last; last = last->next; @@ -290,13 +301,13 @@ struct ccl_token *ccl_tokenize (const char *command) cp++; ++ last->len; } - if (token_cmp (ccl_token_and, last)) + if (token_cmp (cclp, cclp->ccl_token_and, last)) last->kind = CCL_TOK_AND; - else if (token_cmp (ccl_token_or, last)) + else if (token_cmp (cclp, cclp->ccl_token_or, last)) last->kind = CCL_TOK_OR; - else if (token_cmp (ccl_token_not, last)) + else if (token_cmp (cclp, cclp->ccl_token_not, last)) last->kind = CCL_TOK_NOT; - else if (token_cmp (ccl_token_set, last)) + else if (token_cmp (cclp, cclp->ccl_token_set, last)) last->kind = CCL_TOK_SET; else last->kind = CCL_TOK_TERM; @@ -305,6 +316,17 @@ struct ccl_token *ccl_tokenize (const char *command) return first; } +struct ccl_token *ccl_tokenize (const char *command) +{ + CCL_parser cclp = ccl_parser_create (); + struct ccl_token *list; + + list = ccl_parser_tokenize (cclp, command); + + ccl_parser_destroy (cclp); + return list; +} + /* * ccl_token_del: delete CCL tokens */ @@ -319,3 +341,30 @@ void ccl_token_del (struct ccl_token *list) list = list1; } } + +CCL_parser ccl_parser_create (void) +{ + CCL_parser p = (CCL_parser)malloc (sizeof(*p)); + if (!p) + return p; + p->look_token = NULL; + p->error_code = 0; + p->error_pos = NULL; + p->bibset = NULL; + + p->ccl_token_and = "and"; + p->ccl_token_or = "or"; + p->ccl_token_not = "not andnot"; + p->ccl_token_set = "set"; + p->ccl_case_sensitive = 1; + + return p; +} + +void ccl_parser_destroy (CCL_parser p) +{ + if (!p) + return; + free (p); +} +