Moved isam headers to include/idzebra.
[idzebra-moved-to-github.git] / rset / rsmultiandor.c
index 4f4bdcd..1d06c37 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: rsmultiandor.c,v 1.7 2004-10-22 10:12:52 heikki Exp $
+/* $Id: rsmultiandor.c,v 1.11 2004-12-08 14:02:37 adam Exp $
    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
    Index Data Aps
 
@@ -40,7 +40,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include <string.h>
 
 #include <zebrautl.h>
-#include <isamc.h>
+#include <idzebra/isamc.h>
 #include <rset.h>
 
 static RSFD r_open_and (RSET ct, int flag);
@@ -125,6 +125,10 @@ struct rset_multiandor_rfd {
     char *tailbits;
 };
 
+static int log_level=0;
+static int log_level_initialized=0;
+
+
 /* Heap functions ***********************/
 
 #if 0
@@ -133,13 +137,13 @@ static void heap_dump_item( HEAP h, int i, int level) {
     if (i>h->heapnum)
         return;
     (void)rset_pos(h->heap[i]->rset,h->heap[i]->fd, &cur, &tot);
-    logf(LOG_LOG," %d %*s i=%p buf=%p %0.1f/%0.1f",i, level, "",  
+    yaz_log(log_level," %d %*s i=%p buf=%p %0.1f/%0.1f",i, level, "",  
                     &(h->heap[i]), h->heap[i]->buf, cur,tot );
     heap_dump_item(h, 2*i, level+1);
     heap_dump_item(h, 2*i+1, level+1);
 }
 static void heap_dump( HEAP h,char *msg) {
-    logf(LOG_LOG, "heap dump: %s num=%d max=%d",msg, h->heapnum, h->heapmax);
+    yaz_log(log_level, "heap dump: %s num=%d max=%d",msg, h->heapnum, h->heapmax);
     heap_dump_item(h,1,1);
 }
 #endif
@@ -264,6 +268,11 @@ static RSET rsmulti_andor_create( NMEM nmem, const struct key_control *kcontrol,
 {
     RSET rnew=rset_create_base(ctrl, nmem,kcontrol, scope,0);
     struct rset_multiandor_info *info;
+    if (!log_level_initialized)
+    {
+        log_level=yaz_log_module_level("rsmultiandor");
+        log_level_initialized=1;
+    }
     info = (struct rset_multiandor_info *) nmem_malloc(rnew->nmem,sizeof(*info));
     info->no_rsets=no_rsets;
     info->rsets=(RSET*)nmem_malloc(rnew->nmem, no_rsets*sizeof(*rsets));
@@ -307,7 +316,7 @@ static RSFD r_open_andor (RSET ct, int flag, int is_and)
 
     if (flag & RSETF_WRITE)
     {
-        logf (LOG_FATAL, "multiandor set type is read-only");
+        yaz_log (YLOG_FATAL, "multiandor set type is read-only");
         return NULL;
     }
     rfd=rfd_create_base(ct);
@@ -562,24 +571,26 @@ static void r_pos (RSFD rfd, double *current, double *total)
     int i;
     for (i=0; i<info->no_rsets; i++){
         rset_pos(mrfd->items[i].fd, &cur, &tot);
-        logf(LOG_DEBUG, "r_pos: %d %0.1f %0.1f", i, cur,tot);
+        yaz_log(log_level, "r_pos: %d %0.1f %0.1f", i, cur,tot); 
         scur += cur;
         stot += tot;
     }
     if (stot <1.0) { /* nothing there */
         *current=0;
         *total=0;
+        yaz_log(log_level, "r_pos: NULL  %0.1f %0.1f",  *current, *total);
         return;
     }
     *current=mrfd->hits;
     *total=*current*stot/scur;
+    yaz_log(log_level, "r_pos: =  %0.1f %0.1f",  *current, *total);
 }
 
 
 
 static int r_write (RSFD rfd, const void *buf)
 {
-    logf (LOG_FATAL, "multior set type is read-only");
+    yaz_log (YLOG_FATAL, "multior set type is read-only");
     return -1;
 }
 
@@ -595,12 +606,10 @@ static void r_get_terms(RSET ct, TERMID *terms, int maxterms, int *curterm)
     for (i=0;i<info->no_rsets;i++)
     {
         rset_getterms(info->rsets[i], terms, maxterms, curterm);
-        yaz_log(LOG_DEBUG,"rsmulti: getterms: i=%d *cur=%d",i,*curterm);
-        /* FIXME - remove this log once we know it works */
         if ( ( (*curterm) > firstterm+1 ) &&
              ( (*curterm) <= maxterms ) &&
              ( terms[(*curterm)-1] == terms[firstterm] ) )
-            *curterm--; /* forget the term, seen that before */
+            (*curterm)--; /* forget the term, seen that before */
     }
 }