Various minor text tweaks.
[yaz-moved-to-github.git] / src / ccltoken.c
index 538cd56..a572ce2 100644 (file)
@@ -1,8 +1,8 @@
 /* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2011 Index Data
+ * Copyright (C) Index Data
  * See the file LICENSE for details.
  */
-/** 
+/**
  * \file ccltoken.c
  * \brief Implements CCL lexical analyzer (scanner)
  */
@@ -81,7 +81,6 @@ struct ccl_token *ccl_parser_tokenize(CCL_parser cclp, const char *command)
             last->next->prev = last;
             last = last->next;
         }
-        last->left_trunc = last->right_trunc = 0;
         last->ws_prefix_buf = (const char *) cp0;
         last->ws_prefix_len = cp - cp0;
         last->next = NULL;
@@ -127,63 +126,60 @@ struct ccl_token *ccl_parser_tokenize(CCL_parser cclp, const char *command)
         default:
             --cp;
             --last->len;
-            if (*cp == '?')
-            {
-                last->left_trunc = 1;
-                cp++;
-            }
-            if (*cp == '"')
+
+            last->kind = CCL_TOK_TERM;
+            last->name = (const char *) cp;
+            while (*cp && !strchr("(),%!><= \t\n\r", *cp))
             {
-                cp++;
-                last->kind = CCL_TOK_TERM;
-                last->name = (const char *) cp;
-                while (*cp && *cp != '"')
+                if (*cp == '\\' && cp[1])
                 {
                     cp++;
                     ++ last->len;
                 }
-                if (*cp)
-                    cp++;
-            }
-            else
-            {
-                last->kind = CCL_TOK_TERM;
-                last->name = (const char *) cp;
-                while (*cp && !strchr("(),%!><=? \t\n\r", *cp))
+                else if (*cp == '"')
                 {
-                    ++ last->len;
-                    cp++;
+                    while (*cp)
+                    {
+                        cp++;
+                        ++ last->len;
+                        if (*cp == '\\' && cp[1])
+                        {
+                            cp++;
+                            ++ last->len;
+                        }
+                        else if (*cp == '"')
+                            break;
+                    }
                 }
-                aliases = ccl_qual_search_special(cclp->bibset, "and");
-                if (!aliases)
-                    aliases = cclp->ccl_token_and;
-                if (token_cmp(cclp, aliases, last))
-                    last->kind = CCL_TOK_AND;
-                
-                aliases = ccl_qual_search_special(cclp->bibset, "or");
-                if (!aliases)
-                    aliases = cclp->ccl_token_or;
-                if (token_cmp(cclp, aliases, last))
-                    last->kind = CCL_TOK_OR;
-                
-                aliases = ccl_qual_search_special(cclp->bibset, "not");
-                if (!aliases)
-                    aliases = cclp->ccl_token_not;
-                if (token_cmp(cclp, aliases, last))
-                    last->kind = CCL_TOK_NOT;
-                
-                aliases = ccl_qual_search_special(cclp->bibset, "set");
-                if (!aliases)
-                    aliases = cclp->ccl_token_set;
-                
-                if (token_cmp(cclp, aliases, last))
-                    last->kind = CCL_TOK_SET;
-            }
-            if (*cp == '?')
-            {
-                last->right_trunc = 1;
+                if (!*cp)
+                    break;
                 cp++;
+                ++ last->len;
             }
+            aliases = ccl_qual_search_special(cclp->bibset, "and");
+            if (!aliases)
+                aliases = cclp->ccl_token_and;
+            if (token_cmp(cclp, aliases, last))
+                last->kind = CCL_TOK_AND;
+
+            aliases = ccl_qual_search_special(cclp->bibset, "or");
+            if (!aliases)
+                aliases = cclp->ccl_token_or;
+            if (token_cmp(cclp, aliases, last))
+                last->kind = CCL_TOK_OR;
+
+            aliases = ccl_qual_search_special(cclp->bibset, "not");
+            if (!aliases)
+                aliases = cclp->ccl_token_not;
+            if (token_cmp(cclp, aliases, last))
+                last->kind = CCL_TOK_NOT;
+
+            aliases = ccl_qual_search_special(cclp->bibset, "set");
+            if (!aliases)
+                aliases = cclp->ccl_token_set;
+
+            if (token_cmp(cclp, aliases, last))
+                last->kind = CCL_TOK_SET;
         }
     }
     return first;
@@ -200,14 +196,13 @@ struct ccl_token *ccl_token_add(struct ccl_token *at)
         n->next->prev = n;
 
     n->kind = CCL_TOK_TERM;
-    n->left_trunc = n->right_trunc = 0;
     n->name = 0;
     n->len = 0;
     n->ws_prefix_buf = 0;
     n->ws_prefix_len = 0;
     return n;
 }
-    
+
 /*
  * ccl_token_del: delete CCL tokens
  */
@@ -215,7 +210,7 @@ void ccl_token_del(struct ccl_token *list)
 {
     struct ccl_token *list1;
 
-    while (list) 
+    while (list)
     {
         list1 = list->next;
         xfree(list);