Changed prototype for chr_map_input - added const.
[idzebra-moved-to-github.git] / index / zrpn.c
index 2a45b7d..f196a52 100644 (file)
@@ -1,10 +1,20 @@
 /*
- * Copyright (C) 1994-1996, Index Data I/S 
+ * Copyright (C) 1994-1997, Index Data I/S 
  * All rights reserved.
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: zrpn.c,v $
- * Revision 1.59  1997-01-17 11:31:46  adam
+ * Revision 1.62  1997-09-05 15:30:09  adam
+ * Changed prototype for chr_map_input - added const.
+ * Added support for C++, headers uses extern "C" for public definitions.
+ *
+ * Revision 1.61  1997/02/10 10:21:14  adam
+ * Bug fix: in search terms character (^) wasn't observed.
+ *
+ * Revision 1.60  1997/01/31 11:10:34  adam
+ * Bug fix: Leading and trailing white space weren't removed in scan tokens.
+ *
+ * Revision 1.59  1997/01/17 11:31:46  adam
  * Bug fix: complete phrase search didn't work.
  *
  * Revision 1.58  1996/12/23 15:30:45  adam
@@ -333,10 +343,10 @@ static int grep_handle (char *name, const char *info, void *p)
     return 0;
 }
 
-static int term_pre (char **src, const char *ct1, const char *ct2)
+static int term_pre (const char **src, const char *ct1, const char *ct2)
 {
-    char *s1, *s0 = *src;
-    char **map;
+    const char *s1, *s0 = *src;
+    const char **map;
 
     /* skip white space */
     while (*s0)
@@ -355,9 +365,10 @@ static int term_pre (char **src, const char *ct1, const char *ct2)
     return *s0;
 }
 
-static int term_100 (char **src, char *dst, int space_split)
+static int term_100 (const char **src, char *dst, int space_split)
 {
-    char *s0, *s1, **map;
+    const char *s0, *s1;
+    const char **map;
     int i = 0;
 
     if (!term_pre (src, NULL, NULL))
@@ -381,9 +392,10 @@ static int term_100 (char **src, char *dst, int space_split)
     return i;
 }
 
-static int term_101 (char **src, char *dst, int space_split)
+static int term_101 (const char **src, char *dst, int space_split)
 {
-    char *s0, *s1, **map;
+    const char *s0, *s1;
+    const char **map;
     int i = 0;
 
     if (!term_pre (src, "#", "#"))
@@ -417,12 +429,13 @@ static int term_101 (char **src, char *dst, int space_split)
 }
 
 
-static int term_103 (char **src, char *dst, int *errors, int space_split)
+static int term_103 (const char **src, char *dst, int *errors, int space_split)
 {
     int i = 0;
-    char *s0, *s1, **map;
+    const char *s0, *s1;
+    const char **map;
 
-    if (!term_pre (src, "\\()[].*+?|", "("))
+    if (!term_pre (src, "^\\()[].*+?|", "("))
         return 0;
     s0 = *src;
     if (errors && *s0 == '+' && s0[1] && s0[2] == '+' && s0[3] &&
@@ -435,7 +448,7 @@ static int term_103 (char **src, char *dst, int *errors, int space_split)
     }
     while (*s0)
     {
-        if (strchr ("\\()[].*+?|-", *s0))
+        if (strchr ("^\\()[].*+?|-", *s0))
             dst[i++] = *s0++;
         else
         {
@@ -456,7 +469,7 @@ static int term_103 (char **src, char *dst, int *errors, int space_split)
     return i;
 }
 
-static int term_102 (char **src, char *dst, int space_split)
+static int term_102 (const char **src, char *dst, int space_split)
 {
     return term_103 (src, dst, NULL, space_split);
 }
@@ -571,7 +584,7 @@ static void gen_regular_rel (char *dst, int val, int islt)
 }
 
 static int relational_term (ZServerInfo *zi, Z_AttributesPlusTerm *zapt,
-                            char **term_sub,
+                            const char **term_sub,
                             char *term_dict,
                             oid_value attributeSet,
                             struct grep_info *grep_info,
@@ -636,7 +649,7 @@ static int relational_term (ZServerInfo *zi, Z_AttributesPlusTerm *zapt,
 }
 
 static int field_term (ZServerInfo *zi, Z_AttributesPlusTerm *zapt,
-                       char **term_sub, int regType,
+                       const char **term_sub, int regType,
                        oid_value attributeSet, struct grep_info *grep_info,
                        int num_bases, char **basenames, int space_split)
 {
@@ -647,7 +660,7 @@ static int field_term (ZServerInfo *zi, Z_AttributesPlusTerm *zapt,
     AttrType use;
     int use_value;
     oid_value curAttributeSet = attributeSet;
-    char *termp;
+    const char *termp;
 
     attr_init (&use, zapt, 1);
     use_value = attr_find (&use, &curAttributeSet);
@@ -709,18 +722,13 @@ static int field_term (ZServerInfo *zi, Z_AttributesPlusTerm *zapt,
                               attributeSet, grep_info, &max_pos))
         {
             j = prefix_len;
-            logf (LOG_LOG, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
             switch (truncation_value)
             {
             case -1:         /* not specified */
             case 100:        /* do not truncate */
                 term_dict[j++] = '(';   
-                logf (LOG_LOG, "termp=%s", termp);
                 if (!term_100 (&termp, term_dict + j, space_split))
-                {
-                    logf (LOG_LOG, "aaaaaaaaaaaaargh");
                     return 0;
-                }
                 strcat (term_dict, ")");
                 r = dict_lookup_grep (zi->dict, term_dict, 0, grep_info,
                                       &max_pos, 0, grep_handle);
@@ -799,27 +807,28 @@ static void trans_scan_term (ZServerInfo *zi, Z_AttributesPlusTerm *zapt,
                              char *termz)
 {
     Z_Term *term = zapt->term;
-    char **map;
-    char *cp = (char*) term->u.general->buf;
+    const char **map;
+    const char *cp = (const char *) term->u.general->buf;
     const char *cp_end = cp + term->u.general->len;
     const char *src;
     int i = 0;
-    int prev_space = 0;
+    const char *space_map = NULL;
     int len;
     
     while ((len = (cp_end - cp)) > 0)
     {
         map = map_chrs_input (&cp, len);
         if (**map == *CHR_SPACE)
-        {
-            if (prev_space)
-                continue;
-            prev_space = 1;
-        } 
+            space_map = *map;
         else
-            prev_space = 0;
-        for (src = *map; *src; src++)
-            termz[i++] = *src;
+        {
+            if (i && space_map)
+                for (src = space_map; *src; src++)
+                    termz[i++] = *src;
+            space_map = NULL;
+            for (src = *map; *src; src++)
+                termz[i++] = *src;
+        }
     }
     termz[i] = '\0';
 }
@@ -831,7 +840,7 @@ static RSET rpn_search_APT_relevance (ZServerInfo *zi,
 {
     rset_relevance_parms parms;
     char termz[IT_MAX_WORD+1];
-    char *termp = termz;
+    const char *termp = termz;
     struct grep_info grep_info;
     RSET result;
     int term_index = 0;
@@ -891,7 +900,7 @@ static RSET rpn_search_APT_cphrase (ZServerInfo *zi,
     char termz[IT_MAX_WORD+1];
     struct grep_info grep_info;
     RSET result;
-    char *termp = termz;
+    const char *termp = termz;
     int r;
 
     if (zapt->term->which != Z_Term_general)
@@ -1099,7 +1108,7 @@ static RSET rpn_search_APT_phrase (ZServerInfo *zi,
                                    int num_bases, char **basenames)
 {
     char termz[IT_MAX_WORD+1];
-    char *termp = termz;
+    const char *termp = termz;
     RSET rset[60], result;
     int i, r, rset_no = 0;
     struct grep_info grep_info;
@@ -1368,7 +1377,8 @@ void count_set_save (RSET *r, int *count)
     RSFD rfd, wfd;
     RSET w;
     rset_temp_parms parms;
-
+    int maxResultSetSize = atoi (res_get_def (common_resource,
+                                        "maxResultSetSize", "400"));
     logf (LOG_DEBUG, "count_set_save");
     *count = 0;
     parms.key_size = sizeof(struct it_key);
@@ -1379,7 +1389,7 @@ void count_set_save (RSET *r, int *count)
     {
         if (key.sysno != psysno)
         {
-            if (*count < 400)
+            if (*count < maxResultSetSize)
                 rset_write (w, wfd, &key);
             (*count)++;
             psysno = key.sysno;