Extra generic handle for the character mapping routines.
[idzebra-moved-to-github.git] / index / zrpn.c
index f3b0479..cc13551 100644 (file)
@@ -1,10 +1,21 @@
 /*
- * 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.61  1997-02-10 10:21:14  adam
+ * Revision 1.64  1997-09-18 08:59:20  adam
+ * Extra generic handle for the character mapping routines.
+ *
+ * Revision 1.63  1997/09/17 12:19:18  adam
+ * Zebra version corresponds to YAZ version 1.4.
+ * Changed Zebra server so that it doesn't depend on global common_resource.
+ *
+ * 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
 #include <ctype.h>
 
 #include "zserver.h"
-#include "attribute.h"
 
 #include <charmap.h>
 #include <rstemp.h>
@@ -339,10 +349,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)
@@ -352,7 +362,7 @@ static int term_pre (char **src, const char *ct1, const char *ct2)
         if (ct2 && strchr (ct2, *s0))
             break;
         s1 = s0;
-        map = map_chrs_input (&s1, strlen(s1));
+        map = map_chrs_input (0, &s1, strlen(s1));
         if (**map != *CHR_SPACE)
             break;
         s0 = s1;
@@ -361,9 +371,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))
@@ -372,7 +383,7 @@ static int term_100 (char **src, char *dst, int space_split)
     while (*s0)
     {
         s1 = s0;
-        map = map_chrs_input (&s0, strlen(s0));
+        map = map_chrs_input (0, &s0, strlen(s0));
         if (space_split && **map == *CHR_SPACE)
             break;
         while (s1 < s0)
@@ -387,9 +398,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, "#", "#"))
@@ -406,7 +418,7 @@ static int term_101 (char **src, char *dst, int space_split)
         else
         {
             s1 = s0;
-            map = map_chrs_input (&s0, strlen(s0));
+            map = map_chrs_input (0, &s0, strlen(s0));
             if (space_split && **map == *CHR_SPACE)
                 break;
             while (s1 < s0)
@@ -423,10 +435,11 @@ 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, "^\\()[].*+?|", "("))
         return 0;
@@ -446,7 +459,7 @@ static int term_103 (char **src, char *dst, int *errors, int space_split)
         else
         {
             s1 = s0;
-            map = map_chrs_input (&s0, strlen(s0));
+            map = map_chrs_input (0, &s0, strlen(s0));
             if (**map == *CHR_SPACE)
                 break;
             while (s1 < s0)
@@ -462,7 +475,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);
 }
@@ -577,7 +590,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,
@@ -642,7 +655,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)
 {
@@ -653,7 +666,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);
@@ -667,13 +680,12 @@ static int field_term (ZServerInfo *zi, Z_AttributesPlusTerm *zapt,
 
     for (base_no = 0; base_no < num_bases; base_no++)
     {
-        attent *attp;
+        attent attp;
         data1_local_attribute *local_attr;
         int max_pos, prefix_len = 0;
 
         termp = *term_sub;
-        attp = att_getentbyatt (curAttributeSet, use_value);
-        if (!attp)
+        if (!att_getentbyatt (zi, &attp, curAttributeSet, use_value))
         {
             logf (LOG_DEBUG, "att_getentbyatt fail. set=%d use=%d",
                   curAttributeSet, use_value);
@@ -686,12 +698,12 @@ static int field_term (ZServerInfo *zi, Z_AttributesPlusTerm *zapt,
             zi->errString = basenames[base_no];
             return -1;
         }
-        for (local_attr = attp->local_attributes; local_attr;
+        for (local_attr = attp.local_attributes; local_attr;
              local_attr = local_attr->next)
         {
             int ord;
 
-            ord = zebTargetInfo_lookupSU (zi->zti, attp->attset_ordinal,
+            ord = zebTargetInfo_lookupSU (zi->zti, attp.attset_ordinal,
                                           local_attr->local);
             if (ord < 0)
                 continue;
@@ -800,8 +812,8 @@ 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;
@@ -810,7 +822,7 @@ static void trans_scan_term (ZServerInfo *zi, Z_AttributesPlusTerm *zapt,
     
     while ((len = (cp_end - cp)) > 0)
     {
-        map = map_chrs_input (&cp, len);
+        map = map_chrs_input (0, &cp, len);
         if (**map == *CHR_SPACE)
             space_map = *map;
         else
@@ -833,7 +845,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;
@@ -893,7 +905,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)
@@ -920,7 +932,8 @@ static RSET rpn_search_APT_cphrase (ZServerInfo *zi,
     return result;
 }
 
-static RSET rpn_proximity (RSET rset1, RSET rset2, int ordered,
+static RSET rpn_proximity (ZServerInfo *zi, RSET rset1, RSET rset2,
+                          int ordered,
                            int exclusion, int relation, int distance)
 {
     int i;
@@ -938,6 +951,7 @@ static RSET rpn_proximity (RSET rset1, RSET rset2, int ordered,
     more2 = rset_read (rset2, rsfd2, &buf2);
 
     parms.key_size = sizeof (struct it_key);
+    parms.temp_path = res_get (zi->res, "setTmpDir");
     result = rset_create (rset_kind_temp, &parms);
     rsfd_result = rset_open (result, RSETF_WRITE|RSETF_SORT_SYSNO);
    
@@ -1009,7 +1023,7 @@ static RSET rpn_proximity (RSET rset1, RSET rset2, int ordered,
     return result;
 }
 
-static RSET rpn_prox (RSET *rset, int rset_no)
+static RSET rpn_prox (ZServerInfo *zi, RSET *rset, int rset_no)
 {
     int i;
     RSFD *rsfd;
@@ -1042,6 +1056,7 @@ static RSET rpn_prox (RSET *rset, int rset_no)
         }
     }
     parms.key_size = sizeof (struct it_key);
+    parms.temp_path = res_get (zi->res, "setTmpDir");
     result = rset_create (rset_kind_temp, &parms);
     rsfd_result = rset_open (result, RSETF_WRITE|RSETF_SORT_SYSNO);
     
@@ -1101,7 +1116,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;
@@ -1140,7 +1155,7 @@ static RSET rpn_search_APT_phrase (ZServerInfo *zi,
         return rset_create (rset_kind_null, NULL);
     else if (rset_no == 1)
         return (rset[0]);
-    result = rpn_prox (rset, rset_no);
+    result = rpn_prox (zi, rset, rset_no);
     for (i = 0; i<rset_no; i++)
         rset_delete (rset[i]);
     return result;
@@ -1161,6 +1176,7 @@ static RSET rpn_search_APT_local (ZServerInfo *zi, Z_AttributesPlusTerm *zapt,
         return NULL;
     }
     parms.key_size = sizeof (struct it_key);
+    parms.temp_path = res_get (zi->res, "setTmpDir");
     result = rset_create (rset_kind_temp, &parms);
     rsfd = rset_open (result, RSETF_WRITE|RSETF_SORT_SYSNO);
 
@@ -1323,7 +1339,7 @@ static RSET rpn_search_structure (ZServerInfo *zi, Z_RPNStructure *zs,
                 sprintf (val, "%d", *zop->u.prox->proximityUnitCode);
                 return NULL;
             }
-            r = rpn_proximity (bool_parms.rset_l, bool_parms.rset_r,
+            r = rpn_proximity (zi, bool_parms.rset_l, bool_parms.rset_r,
                                *zop->u.prox->ordered,
                                (!zop->u.prox->exclusion ? 0 :
                                          *zop->u.prox->exclusion),
@@ -1362,7 +1378,7 @@ static RSET rpn_search_structure (ZServerInfo *zi, Z_RPNStructure *zs,
     return r;
 }
 
-void count_set_save (RSET *r, int *count)
+void count_set_save (ZServerInfo *zi, RSET *r, int *count)
 {
     int psysno = 0;
     int kno = 0;
@@ -1370,11 +1386,12 @@ 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,
+    int maxResultSetSize = atoi (res_get_def (zi->res,
                                         "maxResultSetSize", "400"));
     logf (LOG_DEBUG, "count_set_save");
     *count = 0;
     parms.key_size = sizeof(struct it_key);
+    parms.temp_path = res_get (zi->res, "setTmpDir");
     w = rset_create (rset_kind_temp, &parms);
     wfd = rset_open (w, RSETF_WRITE|RSETF_SORT_SYSNO);
     rfd = rset_open (*r, RSETF_READ|RSETF_SORT_SYSNO);
@@ -1427,7 +1444,7 @@ int rpn_search (ZServerInfo *zi,
     oident *attrset;
     oid_value attributeSet;
 
-    dict_grep_cmap (zi->dict, map_chrs_input);
+    dict_grep_cmap (zi->dict, 0, map_chrs_input);
     zlog_rpn (rpn);
 
     zi->errCode = 0;
@@ -1440,7 +1457,7 @@ int rpn_search (ZServerInfo *zi,
     if (!rset)
         return zi->errCode;
     if (rset_is_volatile(rset))
-        count_set_save(&rset,hits);
+        count_set_save(zi, &rset,hits);
     else
         count_set (rset, hits);
     resultSetAdd (zi, setname, 1, rset);
@@ -1535,11 +1552,10 @@ int rpn_scan (ZServerInfo *zi, Z_AttributesPlusTerm *zapt,
         use_value = 1016;
     for (base_no = 0; base_no < num_bases && ord_no < 32; base_no++)
     {
-        attent *attp;
+        attent attp;
         data1_local_attribute *local_attr;
 
-        attp = att_getentbyatt (attributeset, use_value);
-        if (!attp)
+        if (!att_getentbyatt (zi, &attp, attributeset, use_value))
         {
             logf (LOG_DEBUG, "att_getentbyatt fail. set=%d use=%d",
                   attributeset, use_value);
@@ -1550,12 +1566,12 @@ int rpn_scan (ZServerInfo *zi, Z_AttributesPlusTerm *zapt,
             zi->errString = basenames[base_no];
             return zi->errCode = 109; /* Database unavailable */
         }
-        for (local_attr = attp->local_attributes; local_attr && ord_no < 32;
+        for (local_attr = attp.local_attributes; local_attr && ord_no < 32;
              local_attr = local_attr->next)
         {
             int ord;
 
-            ord = zebTargetInfo_lookupSU (zi->zti, attp->attset_ordinal,
+            ord = zebTargetInfo_lookupSU (zi->zti, attp.attset_ordinal,
                                           local_attr->local);
             if (ord > 0)
                 ords[ord_no++] = ord;