* Europagate, 1995
*
* $Log: ccltoken.c,v $
- * Revision 1.7 1997-09-01 08:48:12 adam
+ * 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.
*
#include <ccl.h>
-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;
-
/*
* token_cmp: Compare token with keyword(s)
* kw: Keyword list. Each keyword is separated by space.
* 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;
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;
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) &&
}
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;
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;
}
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;
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;
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
*/
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);
+}
+