More gils CCL field mappings.
[yaz-moved-to-github.git] / ccl / ccltoken.c
index 1521c90..1c45b55 100644 (file)
  * Europagate, 1995
  *
  * $Log: ccltoken.c,v $
- * Revision 1.11  1999-11-30 13:47:11  adam
+ * 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
  *
  */
 
-#include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
-#include <assert.h>
 
 #include <yaz/ccl.h>
 
@@ -167,13 +180,13 @@ struct ccl_token *ccl_token_simple (const char *command)
        if (!first)
        {
            first = last = (struct ccl_token *)malloc (sizeof (*first));
-           assert (first);
+           ccl_assert (first);
            last->prev = NULL;
        }
        else
        {
            last->next = (struct ccl_token *)malloc (sizeof(*first));
-           assert (last->next);
+           ccl_assert (last->next);
            last->next->prev = last;
            last = last->next;
        }
@@ -230,13 +243,13 @@ struct ccl_token *ccl_parser_tokenize (CCL_parser cclp, const char *command)
        if (!first)
        {
            first = last = (struct ccl_token *)malloc (sizeof (*first));
-           assert (first);
+           ccl_assert (first);
            last->prev = NULL;
        }
        else
        {
            last->next = (struct ccl_token *)malloc (sizeof(*first));
-           assert (last->next);
+           ccl_assert (last->next);
            last->next->prev = last;
            last = last->next;
        }
@@ -280,9 +293,6 @@ struct ccl_token *ccl_parser_tokenize (CCL_parser cclp, const char *command)
            else
                last->kind = CCL_TOK_REL;
            break;
-       case '-':
-           last->kind = CCL_TOK_MINUS;
-           break;
        case '\"':
            last->kind = CCL_TOK_TERM;
            last->name = cp;
@@ -342,6 +352,14 @@ void ccl_token_del (struct ccl_token *list)
     }
 }
 
+static char *ccl_strdup (const char *str)
+{
+    int len = strlen(str);
+    char *p = (char*) malloc (len+1);
+    strcpy (p, str);
+    return p;
+}
+
 CCL_parser ccl_parser_create (void)
 {
     CCL_parser p = (CCL_parser)malloc (sizeof(*p));
@@ -352,10 +370,10 @@ CCL_parser ccl_parser_create (void)
     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_token_and = ccl_strdup("and");
+    p->ccl_token_or = ccl_strdup("or");
+    p->ccl_token_not = ccl_strdup("not andnot");
+    p->ccl_token_set = ccl_strdup("set");
     p->ccl_case_sensitive = 1;
 
     return p;
@@ -365,6 +383,37 @@ 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);
 }
 
+void ccl_parser_set_op_and (CCL_parser p, const char *op)
+{
+    if (p && op)
+       p->ccl_token_and = ccl_strdup (op);
+}
+
+void ccl_parser_set_op_or (CCL_parser p, const char *op)
+{
+    if (p && op)
+       p->ccl_token_or = ccl_strdup (op);
+}
+void ccl_parser_set_op_not (CCL_parser p, const char *op)
+{
+    if (p && op)
+       p->ccl_token_not = ccl_strdup (op);
+}
+void ccl_parser_set_op_set (CCL_parser p, const char *op)
+{
+    if (p && op)
+       p->ccl_token_set = ccl_strdup (op);
+}
+
+void ccl_parser_set_case (CCL_parser p, int case_sensitivity_flag)
+{
+    if (p)
+       p->ccl_case_sensitive = case_sensitivity_flag;
+}