Examples using Bib-1 use attributes
[idzebra-moved-to-github.git] / index / kinput.c
index de1d563..4d26181 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of the Zebra server.
-   Copyright (C) 1994-2009 Index Data
+   Copyright (C) Index Data
 
 Zebra is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free
@@ -16,7 +16,10 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 */
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
 #include <fcntl.h>
 #ifdef WIN32
 #include <io.h>
@@ -50,7 +53,12 @@ struct key_file {
     Res res;
 };
 
-#if 0
+
+#define PR_KEY_LOW 0
+#define PR_KEY_TOP 0
+
+#if PR_KEY_LOW || PR_KEY_TOP
+
 static void pkey(const char *b, int mode)
 {
     key_logdump_txt(YLOG_LOG, b, mode ? "i" : "d");
@@ -61,7 +69,7 @@ static void pkey(const char *b, int mode)
 void getFnameTmp(Res res, char *fname, int no)
 {
     const char *pre;
-    
+
     pre = res_get_def(res, "keyTmpDir", ".");
     sprintf(fname, "%s/key%d.tmp", pre, no);
 }
@@ -69,7 +77,7 @@ void getFnameTmp(Res res, char *fname, int no)
 void extract_get_fname_tmp(ZebraHandle zh, char *fname, int no)
 {
     const char *pre;
-    
+
     pre = res_get_def(zh->res, "keyTmpDir", ".");
     sprintf(fname, "%s/key%d.tmp", pre, no);
 }
@@ -305,7 +313,7 @@ static void key_heap_delete(struct heap_info *hi)
             child++;
         if ((*hi->cmp)(&hi->info.buf[hi->ptr[cur]],
                        &hi->info.buf[hi->ptr[child]]) > 0)
-        {            
+        {
             key_heap_swap(hi, cur, child);
             cur = child;
             child = 2*cur;
@@ -320,6 +328,8 @@ static void key_heap_insert(struct heap_info *hi, const char *buf, int nbytes,
 {
     int cur, parent;
 
+    assert(nbytes < INP_NAME_MAX);
+
     cur = ++(hi->heapnum);
     memcpy(hi->info.buf[hi->ptr[cur]], buf, nbytes);
     hi->info.file[hi->ptr[cur]] = kf;
@@ -354,8 +364,6 @@ static int heap_read_one(struct heap_info *hi, char *name, char *key)
     return 1;
 }
 
-#define PR_KEY_LOW 0
-#define PR_KEY_TOP 0
 
 /* for debugging only */
 void zebra_log_dict_entry(ZebraHandle zh, const char *s)
@@ -415,7 +423,7 @@ int heap_cread_item2(void *vp, char **dst, int *insertMode)
            p->look_level++;
        }
        memcpy(*dst, p->key_1, p->sz_1);
-#if 0
+#if PR_KEY_TOP
        yaz_log(YLOG_LOG, "DUP level=%d", p->look_level);
        pkey(*dst, *insertMode);
 #endif
@@ -490,13 +498,14 @@ int heap_cread_item2(void *vp, char **dst, int *insertMode)
     }
     p->look_level = level;
     memcpy(*dst, p->key_1, p->sz_1);
-#if 0
+#if PR_KEY_TOP
+    yaz_log(YLOG_LOG, "TOP");
     pkey(*dst, *insertMode);
 #endif
     (*dst) += p->sz_1;
     return 1;
 }
-      
+
 int heap_cread_item(void *vp, char **dst, int *insertMode)
 {
     struct heap_cread_info *p = (struct heap_cread_info *) vp;
@@ -559,14 +568,14 @@ int heap_inpc(struct heap_cread_info *hci, struct heap_info *hi)
                 if (!dict_delete(hi->reg->dict, this_name))
                     abort();
             }
-            else 
+            else
             {
                 hi->no_updates++;
                 if (isamc_p2 != isamc_p)
                     dict_insert(hi->reg->dict, this_name,
                                  sizeof(ISAM_P), &isamc_p2);
             }
-        } 
+        }
         else
         {
            isamc_p = 0;
@@ -579,7 +588,7 @@ int heap_inpc(struct heap_cread_info *hci, struct heap_info *hi)
     }
     xfree(isamc_i);
     return 0;
-} 
+}
 
 int heap_inpb(struct heap_cread_info *hci, struct heap_info *hi)
 {
@@ -613,14 +622,14 @@ int heap_inpb(struct heap_cread_info *hci, struct heap_info *hi)
                 if (!dict_delete(hi->reg->dict, this_name))
                     abort();
             }
-            else 
+            else
             {
                 hi->no_updates++;
                 if (isamc_p2 != isamc_p)
                     dict_insert(hi->reg->dict, this_name,
                                  sizeof(ISAM_P), &isamc_p2);
             }
-        } 
+        }
         else
         {
            isamc_p = 0;
@@ -633,7 +642,7 @@ int heap_inpb(struct heap_cread_info *hci, struct heap_info *hi)
     }
     xfree(isamc_i);
     return 0;
-} 
+}
 
 int heap_inps(struct heap_cread_info *hci, struct heap_info *hi)
 {
@@ -665,7 +674,7 @@ int heap_inps(struct heap_cread_info *hci, struct heap_info *hi)
     }
     xfree(isams_i);
     return 0;
-} 
+}
 
 struct progressInfo {
     time_t   startTime;
@@ -713,7 +722,7 @@ void zebra_index_merge(ZebraHandle zh)
 
     if (nkeys == 0)
         return;
-    
+
     if (nkeys < 0)
     {
         char fname[1024];
@@ -743,7 +752,7 @@ void zebra_index_merge(ZebraHandle zh)
     }
     hi = key_heap_init_file(zh, nkeys, key_qsort_compare);
     hi->reg = zh->reg;
-    
+
     for (i = 1; i<=nkeys; i++)
         if ((r = key_file_read(kf[i], rbuf)))
             key_heap_insert(hi, rbuf, r, kf[i]);
@@ -751,7 +760,7 @@ void zebra_index_merge(ZebraHandle zh)
     if (1)
     {
         struct heap_cread_info hci;
-        
+
         hci.key = (char *) xmalloc(KEY_SIZE);
        hci.key_1 = (char *) xmalloc(KEY_SIZE);
        hci.key_2 = (char *) xmalloc(KEY_SIZE);
@@ -759,20 +768,20 @@ void zebra_index_merge(ZebraHandle zh)
        hci.first_in_list = 1;
        hci.hi = hi;
        hci.look_level = 0;
-       hci.more = heap_read_one(hi, hci.cur_name, hci.key);    
-       
+       hci.more = heap_read_one(hi, hci.cur_name, hci.key);
+
        if (zh->reg->isams)
            heap_inps(&hci, hi);
        if (zh->reg->isamc)
            heap_inpc(&hci, hi);
        if (zh->reg->isamb)
            heap_inpb(&hci, hi);
-       
+
        xfree(hci.key);
        xfree(hci.key_1);
        xfree(hci.key_2);
     }
-       
+
     for (i = 1; i<=nkeys; i++)
     {
         extract_get_fname_tmp (zh, rbuf, i);
@@ -783,7 +792,7 @@ void zebra_index_merge(ZebraHandle zh)
     xfree(kf);
     if (hi->no_iterations)
     { /* do not log if nothing happened */
-        yaz_log(YLOG_LOG, "Iterations: isam/dict " 
+        yaz_log(YLOG_LOG, "Iterations: isam/dict "
                 ZINT_FORMAT "/" ZINT_FORMAT,
                 hi->no_iterations, hi->no_diffs);
         yaz_log(YLOG_LOG, "Dict: inserts/updates/deletions: "