X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fccltoken.c;h=d7b0d5f37d83eec9952a100493fb7db7cc27ac68;hb=dc068db61c02117e4e7e4aa3136f055965ec063c;hp=ae8b4c0ddf8ceadb5d5c0f462c04dfb99f1d55f7;hpb=8fa3d0c0967fd6db5c7a2b2ffc504cb48407a586;p=yaz-moved-to-github.git diff --git a/src/ccltoken.c b/src/ccltoken.c index ae8b4c0..d7b0d5f 100644 --- a/src/ccltoken.c +++ b/src/ccltoken.c @@ -41,10 +41,14 @@ * USE OR PERFORMANCE OF THIS SOFTWARE. * */ +/** + * \file ccltoken.c + * \brief Implements CCL lexical analyzer (scanner) + */ /* CCL - lexical analysis * Europagate, 1995 * - * $Id: ccltoken.c,v 1.2 2004-08-11 11:44:30 adam Exp $ + * $Id: ccltoken.c,v 1.7 2005-04-15 21:47:56 adam Exp $ * * Old Europagate Log: * @@ -133,85 +137,21 @@ static int token_cmp (CCL_parser cclp, const char *kw, struct ccl_token *token) } /* - * ccl_token_simple: tokenize CCL raw tokens - */ -struct ccl_token *ccl_token_simple (const char *command) -{ - const char *cp = command; - struct ccl_token *first = NULL; - struct ccl_token *last = NULL; - - while (1) - { - while (*cp && strchr (" \t\r\n", *cp)) - { - cp++; - continue; - } - if (!first) - { - first = last = (struct ccl_token *)xmalloc (sizeof (*first)); - ccl_assert (first); - last->prev = NULL; - } - else - { - last->next = (struct ccl_token *)xmalloc (sizeof(*first)); - ccl_assert (last->next); - last->next->prev = last; - last = last->next; - } - last->next = NULL; - last->name = cp; - last->len = 1; - switch (*cp++) - { - case '\0': - last->kind = CCL_TOK_EOL; - return first; - case '\"': - last->kind = CCL_TOK_TERM; - last->name = cp; - last->len = 0; - while (*cp && *cp != '\"') - { - cp++; - ++ last->len; - } - if (*cp == '\"') - cp++; - break; - default: - while (*cp && !strchr (" \t\n\r", *cp)) - { - cp++; - ++ last->len; - } - last->kind = CCL_TOK_TERM; - } - } - return first; -} - - -/* * ccl_tokenize: tokenize CCL command string. * return: CCL token list. */ struct ccl_token *ccl_parser_tokenize (CCL_parser cclp, const char *command) { const char *aliases; - const unsigned char *cp = command; + const unsigned char *cp = (const unsigned char *) command; struct ccl_token *first = NULL; struct ccl_token *last = NULL; while (1) { + const unsigned char *cp0 = cp; while (*cp && strchr (" \t\r\n", *cp)) - { cp++; - continue; - } if (!first) { first = last = (struct ccl_token *)xmalloc (sizeof (*first)); @@ -225,8 +165,10 @@ struct ccl_token *ccl_parser_tokenize (CCL_parser cclp, const char *command) last->next->prev = last; last = last->next; } + last->ws_prefix_buf = cp0; + last->ws_prefix_len = cp - cp0; last->next = NULL; - last->name = cp; + last->name = (const char *) cp; last->len = 1; switch (*cp++) { @@ -267,7 +209,7 @@ struct ccl_token *ccl_parser_tokenize (CCL_parser cclp, const char *command) break; case '\"': last->kind = CCL_TOK_TERM; - last->name = cp; + last->name = (const char *) cp; last->len = 0; while (*cp && *cp != '\"') { @@ -317,6 +259,24 @@ struct ccl_token *ccl_parser_tokenize (CCL_parser cclp, const char *command) return first; } +struct ccl_token *ccl_token_add (struct ccl_token *at) +{ + struct ccl_token *n = (struct ccl_token *)xmalloc (sizeof(*n)); + ccl_assert(n); + n->next = at->next; + n->prev = at; + at->next = n; + if (n->next) + n->next->prev = n; + + n->kind = CCL_TOK_TERM; + n->name = 0; + n->len = 0; + n->ws_prefix_buf = 0; + n->ws_prefix_len = 0; + return n; +} + struct ccl_token *ccl_tokenize (const char *command) { CCL_parser cclp = ccl_parser_create ();