Updated WIN32 code specific sections. Changed header.
[idzebra-moved-to-github.git] / isam / isam.c
index 91ad2cb..e2205b1 100644 (file)
@@ -1,10 +1,23 @@
 /*
- * Copyright (C) 1994, Index Data I/S 
+ * Copyright (C) 1994-1999, Index Data
  * All rights reserved.
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: isam.c,v $
- * Revision 1.21  1996-03-29 14:11:47  quinn
+ * Revision 1.25  1999-02-02 14:51:16  adam
+ * Updated WIN32 code specific sections. Changed header.
+ *
+ * Revision 1.24  1997/10/27 14:25:39  adam
+ * Fixed memory leaks.
+ *
+ * Revision 1.23  1997/09/17 12:19:20  adam
+ * Zebra version corresponds to YAZ version 1.4.
+ * Changed Zebra server so that it doesn't depend on global common_resource.
+ *
+ * Revision 1.22  1996/10/29 13:56:53  adam
+ * Include of zebrautl.h instead of alexutil.h.
+ *
+ * Revision 1.21  1996/03/29 14:11:47  quinn
  * Change to is_merge
  *
  * Revision 1.20  1996/03/19  13:14:57  quinn
 #include <string.h>
 #include <ctype.h>
 
-#include <alexutil.h>
+#include <zebrautl.h>
 #include <bfile.h>
 #include <isam.h>
-#include <common.h>
 #include "isutil.h"
 #include "rootblk.h"
 #include "keyops.h"
@@ -146,8 +158,9 @@ static int splitargs(const char *s, char *bf[], int max)
  * Open isam file.
  * Process resources.
  */
-ISAM is_open(const char *name, int (*cmp)(const void *p1, const void *p2),
-    int writeflag, int keysize)
+ISAM is_open(BFiles bfs, const char *name,
+            int (*cmp)(const void *p1, const void *p2),
+            int writeflag, int keysize, Res res)
 {
     ISAM new;
     char *nm, *r, *pp[IS_MAX_BLOCKTYPES+1], m[2];
@@ -178,8 +191,9 @@ ISAM is_open(const char *name, int (*cmp)(const void *p1, const void *p2),
        new->types[i].index = 0;                        /* dummy */
 
     /* determine number and size of blocktypes */
-    if (!(r = res_get_def(common_resource, nm = strconcat(name, ".",
-       "blocktypes", 0), "64 512 4K 32K")) ||
+    if (!(r = res_get_def(res,
+                         nm = strconcat(name, ".",
+                                        "blocktypes", 0), "64 512 4K 32K")) ||
        !(num = splitargs(r, pp, IS_MAX_BLOCKTYPES)))
     {
        logf (LOG_FATAL, "Failed to locate resource %s", nm);
@@ -210,7 +224,7 @@ ISAM is_open(const char *name, int (*cmp)(const void *p1, const void *p2),
        new->types[i].dbuf = xmalloc(new->types[i].blocksize);
        m[0] = 'A' + i;
        m[1] = '\0';
-       if (!(new->types[i].bf = bf_open(strconcat(name, m, 0), 
+       if (!(new->types[i].bf = bf_open(bfs, strconcat(name, m, 0), 
            new->types[i].blocksize, writeflag)))
        {
            logf (LOG_FATAL, "bf_open failed");
@@ -242,9 +256,8 @@ ISAM is_open(const char *name, int (*cmp)(const void *p1, const void *p2),
         new->keysize = keysize;
     else
     {
-        if (!(r = res_get_def(common_resource, nm = strconcat(name, ".",
-                                                              "keysize",
-                                                              0), "4")))
+        if (!(r = res_get_def(res, nm = strconcat(name, ".",
+                                                 "keysize", 0), "4")))
         {
             logf (LOG_FATAL, "Failed to locate resource %s", nm);
             return 0;
@@ -257,8 +270,8 @@ ISAM is_open(const char *name, int (*cmp)(const void *p1, const void *p2),
     }
 
     /* determine repack percent */
-    if (!(r = res_get_def(common_resource, nm = strconcat(name, ".", "repack",
-       0), IS_DEF_REPACK_PERCENT)))
+    if (!(r = res_get_def(res, nm = strconcat(name, ".", "repack",
+                                             0), IS_DEF_REPACK_PERCENT)))
     {
        logf (LOG_FATAL, "Failed to locate resource %s", nm);
        return 0;
@@ -266,9 +279,10 @@ ISAM is_open(const char *name, int (*cmp)(const void *p1, const void *p2),
     new->repack = atoi(r);
 
     /* determine max keys/blocksize */
-    if (!(r = res_get_def(common_resource, nm = strconcat(name, ".",
-       "maxkeys", 0), "50 640 10000")) || !(num = splitargs(r, pp,
-       IS_MAX_BLOCKTYPES)))
+    if (!(r = res_get_def(res,
+                         nm = strconcat(name, ".",
+                                        "maxkeys", 0), "50 640 10000")) ||
+       !(num = splitargs(r, pp, IS_MAX_BLOCKTYPES)))
     {
        logf (LOG_FATAL, "Failed to locate resource %s", nm);
        return 0;
@@ -309,9 +323,10 @@ ISAM is_open(const char *name, int (*cmp)(const void *p1, const void *p2),
     }
 
     /* determine nice fill rates */
-    if (!(r = res_get_def(common_resource, nm = strconcat(name, ".",
-       "nicefill", 0), "90 90 90 95")) || !(num = splitargs(r, pp,
-       IS_MAX_BLOCKTYPES)))
+    if (!(r = res_get_def(res,
+                         nm = strconcat(name, ".",
+                                        "nicefill", 0), "90 90 90 95")) ||
+       !(num = splitargs(r, pp, IS_MAX_BLOCKTYPES)))
     {
        logf (LOG_FATAL, "Failed to locate resource %s", nm);
        return 0;
@@ -366,6 +381,9 @@ int is_close(ISAM is)
            bf_close(is->types[i].bf);
        }
     }
+    for (i = 0; i < is->num_types; i++)
+       xfree (is->types[i].dbuf);
+
     if (is->writeflag)
     {
        logf(LOG_LOG, "ISAM statistics:");