More type casts. Modify CQL tree - bool is C++ reserved name.
[yaz-moved-to-github.git] / ccl / ccltoken.c
index b0e1b81..31a18d8 100644 (file)
 /* CCL - lexical analysis
  * Europagate, 1995
  *
- * $Log: ccltoken.c,v $
- * Revision 1.16  2001-03-07 13:24:40  adam
- * Member and_not in Z_Operator is kept for backwards compatibility.
- * Added support for definition of CCL operators in field spec file.
+ * $Id: ccltoken.c,v 1.22 2003-02-14 18:49:23 adam Exp $
  *
- * 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.
- *
- * 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
 
 #include <string.h>
 #include <stdlib.h>
+#include <ctype.h>
 
 #include <yaz/ccl.h>
 
@@ -189,13 +150,13 @@ struct ccl_token *ccl_token_simple (const char *command)
        }
        if (!first)
        {
-           first = last = (struct ccl_token *)malloc (sizeof (*first));
+           first = last = (struct ccl_token *)xmalloc (sizeof (*first));
            ccl_assert (first);
            last->prev = NULL;
        }
        else
        {
-           last->next = (struct ccl_token *)malloc (sizeof(*first));
+           last->next = (struct ccl_token *)xmalloc (sizeof(*first));
            ccl_assert (last->next);
            last->next->prev = last;
            last = last->next;
@@ -253,13 +214,13 @@ struct ccl_token *ccl_parser_tokenize (CCL_parser cclp, const char *command)
        }
        if (!first)
        {
-           first = last = (struct ccl_token *)malloc (sizeof (*first));
+           first = last = (struct ccl_token *)xmalloc (sizeof (*first));
            ccl_assert (first);
            last->prev = NULL;
        }
        else
        {
-           last->next = (struct ccl_token *)malloc (sizeof(*first));
+           last->next = (struct ccl_token *)xmalloc (sizeof(*first));
            ccl_assert (last->next);
            last->next->prev = last;
            last = last->next;
@@ -284,7 +245,7 @@ struct ccl_token *ccl_parser_tokenize (CCL_parser cclp, const char *command)
        case '%':
        case '!':
            last->kind = CCL_TOK_PROX;
-           while (*cp == '%' || *cp == '!')
+            while (isdigit(*cp))
            {
                ++ last->len;
                cp++;
@@ -317,10 +278,13 @@ 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;
+               }
            }
            last->kind = CCL_TOK_TERM;
 
@@ -374,7 +338,7 @@ void ccl_token_del (struct ccl_token *list)
     while (list) 
     {
         list1 = list->next;
-        free (list);
+        xfree (list);
         list = list1;
     }
 }
@@ -382,14 +346,14 @@ void ccl_token_del (struct ccl_token *list)
 char *ccl_strdup (const char *str)
 {
     int len = strlen(str);
-    char *p = (char*) malloc (len+1);
+    char *p = (char*) xmalloc (len+1);
     strcpy (p, str);
     return p;
 }
 
 CCL_parser ccl_parser_create (void)
 {
-    CCL_parser p = (CCL_parser)malloc (sizeof(*p));
+    CCL_parser p = (CCL_parser)xmalloc (sizeof(*p));
     if (!p)
        return p;
     p->look_token = NULL;
@@ -410,11 +374,11 @@ void ccl_parser_destroy (CCL_parser p)
 {
     if (!p)
        return;
-    free (p->ccl_token_and);
-    free (p->ccl_token_or);
-    free (p->ccl_token_not);
-    free (p->ccl_token_set);
-    free (p);
+    xfree (p->ccl_token_and);
+    xfree (p->ccl_token_or);
+    xfree (p->ccl_token_not);
+    xfree (p->ccl_token_set);
+    xfree (p);
 }
 
 void ccl_parser_set_op_and (CCL_parser p, const char *op)
@@ -422,7 +386,7 @@ 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);
+           xfree (p->ccl_token_and);
        p->ccl_token_and = ccl_strdup (op);
     }
 }
@@ -432,7 +396,7 @@ 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);
+           xfree (p->ccl_token_or);
        p->ccl_token_or = ccl_strdup (op);
     }
 }
@@ -441,7 +405,7 @@ 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);
+           xfree (p->ccl_token_not);
        p->ccl_token_not = ccl_strdup (op);
     }
 }
@@ -450,7 +414,7 @@ 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);
+           xfree (p->ccl_token_set);
        p->ccl_token_set = ccl_strdup (op);
     }
 }