Not functional yet
authorSebastian Hammer <quinn@indexdata.com>
Mon, 12 Sep 1994 08:02:07 +0000 (08:02 +0000)
committerSebastian Hammer <quinn@indexdata.com>
Mon, 12 Sep 1994 08:02:07 +0000 (08:02 +0000)
include/isam.h [new file with mode: 0644]
isam/Makefile [new file with mode: 0644]
isam/isam.c [new file with mode: 0644]
isam/isutil.c [new file with mode: 0644]
isam/isutil.h [new file with mode: 0644]

diff --git a/include/isam.h b/include/isam.h
new file mode 100644 (file)
index 0000000..126270e
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 1994, Index Data I/S 
+ * All rights reserved.
+ * Sebastian Hammer, Adam Dickmeiss
+ *
+ * $Log: isam.h,v $
+ * Revision 1.1  1994-09-12 08:02:07  quinn
+ * Not functional yet
+ *
+ */
+
+#ifndef ISAM_H
+#define ISAM_H
+
+#include <bfile.h>
+#include <isam.h>
+
+#define IS_MAX_BLOCKTYPES 4
+
+typedef unsigned int SYSNO; /* should be somewhere else */
+typedef unsigned int ISAM_P;
+
+/*
+ * Description of a blocktype (part of an isam file)
+ */
+typedef struct isam_blocktype
+{
+    BFile bf;                    /* blocked file */
+    int blocksize;
+    int max_keys_block;          /* max num of keys per block */
+    int nice_keys_block;         /* nice number of keys per block */
+    int max_keys;                /* max number of keys per table */
+} isam_blocktype;
+
+/*
+ * Handle to an open isam complex.
+ */
+typedef struct isam_struct
+{
+    isam_blocktype types[IS_MAX_BLOCKTYPES]; /* block_types used in this file */
+    int num_types;                /* number of block types used */
+    int writeflag;
+    int keysize;                  /* size of the keys (records) used */
+    int (*cmp)(const void *k1, const void *k2); /* compare function */
+} isam_struct, *ISAM;
+
+typedef struct ispt_struct
+{
+    ISAM is;                       /* which file do we belong to? */
+    int ptr;                       /* current key offset */
+
+    struct ispt_struct *next;      /* freelist */
+} ispt_struct, *ISPT; 
+
+#define IS_TYPE(x) ((x) & 3))      /* type part of position */
+#define IS_BLOCK(x) ((x >> 2))     /* block # part of position */
+
+/*
+ * Public Prototypes.
+ *******************************************************************
+ */
+
+/*
+ * Open isam file.
+ */
+ISAM is_open(const char *name, int writeflag);
+
+/*
+ * Close isam file.
+ */
+int is_close(ISAM is);
+
+/*
+ * Locate a table of keys in an isam file. The ISPT is an individual
+ * position marker for that table.
+ */
+ISPT is_position(ISAM is, ISAM_P pos);
+
+/*
+ * Release ISPT.
+ */
+void is_pt_free(ISPT ip);
+
+/*
+ * Read a key from a table.
+ */
+int is_readkey(ISPT ip, void *buf);
+
+#endif
diff --git a/isam/Makefile b/isam/Makefile
new file mode 100644 (file)
index 0000000..da4830e
--- /dev/null
@@ -0,0 +1,34 @@
+SHELL=/bin/sh
+INCLUDE=-I../include
+CFLAGS=-g -Wall -pedantic
+DEFS=$(INCLUDE)
+LIB=../lib/isam.a
+PO = isutil.o isam.o
+CPP=cc -E
+
+all: $(LIB)
+
+isam-test: isam-test.c $(LIB)
+       $(CC) -g -o isam-test -I../include isam-test.c \
+       ../lib/isam.a ../lib/bfile.a ../lib/util.a
+
+#$(TPROG): $(TPROG).o $(LIB) 
+#      $(CC) -o $(TPROG) $(TPROG).o $(LIB)
+
+$(LIB): $(PO)
+       rm -f $(LIB)
+       ar qc $(LIB) $(PO)
+       ranlib $(LIB)
+
+.c.o:
+       $(CC) -c $(DEFS) $(CFLAGS) $<
+
+clean:
+       rm -f *.[oa] $(TPROG) core mon.out gmon.out errlist isam-test
+
+dep depend:
+       $(CPP) $(INCLUDE) -M *.c >.depend
+
+#ifeq (.depend,$(wildcard .depend))
+include .depend
+#endif
diff --git a/isam/isam.c b/isam/isam.c
new file mode 100644 (file)
index 0000000..7794ede
--- /dev/null
@@ -0,0 +1,152 @@
+/*
+ * Copyright (C) 1994, Index Data I/S 
+ * All rights reserved.
+ * Sebastian Hammer, Adam Dickmeiss
+ *
+ * $Log: isam.c,v $
+ * Revision 1.1  1994-09-12 08:02:13  quinn
+ * Not functional yet
+ *
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#include <util.h>
+#include "isutil.h"
+#include <bfile.h>
+#include <isam.h>
+#include <common.h>
+
+static int splitargs(const char *s, char *bf[], int max)
+{
+    int ct = 0;
+    for (;;)
+    {
+       while (*s && isspace(*s))
+           s++;
+       bf[ct] = (char *) s;
+       if (!*s)
+               return ct;
+       ct++;
+       if (ct > max)
+       {
+           log(LOG_WARN, "Ignoring extra args to is resource");
+           bf[ct] = '\0';
+           return(ct - 1);
+       }
+       while (*s && !isspace(*s))
+           s++;
+    }
+}
+
+/*
+ * Open isam file.
+ * Process resources.
+ */
+ISAM is_open(const char *name, int writeflag)
+{
+    ISAM new;
+    char *nm, *r, *pp[IS_MAX_BLOCKTYPES+1], m[2];
+    int num, size, rs, tmp, i;
+
+    log(LOG_DEBUG, "is_open(%s, %s)", name, writeflag ? "RW" : "RDONLY");
+    new = xmalloc(sizeof(*new));
+    new->writeflag = writeflag;
+
+    /* determine number and size of blocktypes */
+    if (!(r = res_get(common_resource, nm = strconcat(name, ".",
+       "blocktypes", 0))) || !(num = splitargs(r, pp, IS_MAX_BLOCKTYPES)))
+    {
+       log(LOG_FATAL, "Failed to locate resource %s", nm);
+       return 0;
+    }
+    new->num_types = num;
+    for (i = 0; i < num; i++)
+    {
+       if ((rs = sscanf(pp[i], "%d%1[bBkKmM]", &size, m)) < 1)
+       {
+           log(LOG_FATAL, "Error in resource %s: %s", r, pp[i]);
+           return 0;
+       }
+       if (rs == 1)
+               *m = 'b';
+       switch (*m)
+       {
+               case 'b': case 'B':
+                   new->types[i].blocksize = size; break;
+               case 'k': case 'K':
+                   new->types[i].blocksize = size * 1024; break;
+               case 'm': case 'M':
+                   new->types[i].blocksize = size * 1048576; break;
+               default:
+                   log(LOG_FATAL, "Illegal size suffix: %c", *m);
+                   return 0;
+       }
+       m[0] = 'A' + i;
+       m[1] = '\0';
+       if (!(new->types[i].bf = bf_open(strconcat(name, m, 0), 
+           new->types[i].blocksize, writeflag)))
+       {
+           log(LOG_FATAL, "bf_open failed");
+           return 0;
+       }
+    }
+
+    /* determine nice fill rates */
+    if (!(r = res_get(common_resource, nm = strconcat(name, ".",
+       "nicefill", 0))) || !(num = splitargs(r, pp, IS_MAX_BLOCKTYPES)))
+    {
+       log(LOG_FATAL, "Failed to locate resource %s", nm);
+       return 0;
+    }
+    if (num < new->num_types)
+    {
+       log(LOG_FATAL, "Not enough elements in %s", nm);
+       return 0;
+    }
+    for (i = 0; i < num; i++)
+    {
+       if ((rs = sscanf(pp[i], "%d", &tmp)) < 1)
+       {
+           log(LOG_FATAL, "Error in resource %s: %s", r, pp[i]);
+           return 0;
+       }
+       new->types[i].nice_keys_block = tmp;
+    }
+
+    /* determine max keys/blocksize */
+    if (!(r = res_get(common_resource, nm = strconcat(name, ".",
+       "maxkeys", 0))) || !(num = splitargs(r, pp, IS_MAX_BLOCKTYPES)))
+    {
+       log(LOG_FATAL, "Failed to locate resource %s", nm);
+       return 0;
+    }
+    if (num < new->num_types -1)
+    {
+       log(LOG_FATAL, "Not enough elements in %s", nm);
+       return 0;
+    }
+    for (i = 0; i < num; i++)
+    {
+       if ((rs = sscanf(pp[i], "%d", &tmp)) < 1)
+       {
+           log(LOG_FATAL, "Error in resource %s: %s", r, pp[i]);
+           return 0;
+       }
+       new->types[i].max_keys = tmp;
+    }
+    return new;
+}
+
+/*
+ * Close isam file.
+ */
+int is_close(ISAM is)
+{
+    log(LOG_DEBUG, "is_close()");
+    log(LOG_LOG, "is_close needs to close individual files.");
+    xfree(is);
+    return 0;
+}
diff --git a/isam/isutil.c b/isam/isutil.c
new file mode 100644 (file)
index 0000000..aae8c3e
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 1994, Index Data I/S 
+ * All rights reserved.
+ * Sebastian Hammer, Adam Dickmeiss
+ *
+ * $Log: isutil.c,v $
+ * Revision 1.1  1994-09-12 08:02:13  quinn
+ * Not functional yet
+ *
+ */
+
+/*
+ * Small utilities needed by the isam system. Some or all of these
+ * may move to util/ along the way.
+ */
+
+#include <string.h>
+#include <stdarg.h>
+
+#include <isam.h>
+#include "isutil.h"
+
+char *strconcat(const char *s1, ...)
+{
+    va_list ap;
+    static char buf[512];
+    char *p;
+
+    va_start(ap, s1);
+    strcpy(buf, s1);
+    while ((p = va_arg(ap, char *)))
+       strcat(buf, p);
+    va_end(ap);
+    
+    return buf;
+}
+
+int is_default_cmp(const void *k1, const void *k2)
+{
+    SYSNO b1, b2;
+
+    memcpy(&b1, k1, sizeof(b1));
+    memcpy(&b2, k2, sizeof(b2));
+    return b1 - b2;
+}
diff --git a/isam/isutil.h b/isam/isutil.h
new file mode 100644 (file)
index 0000000..50bbb62
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 1994, Index Data I/S 
+ * All rights reserved.
+ * Sebastian Hammer, Adam Dickmeiss
+ *
+ * $Log: isutil.h,v $
+ * Revision 1.1  1994-09-12 08:02:14  quinn
+ * Not functional yet
+ *
+ */
+
+/*
+ * Small utilities needed by the isam system. Some or all of these
+ * may move to util/ along the way.
+ */
+
+#ifndef ISUTIL_H
+#define ISUTIL_H
+
+char *strconcat(const char *s1, ...);
+
+int is_default_cmp(const void *k1, const void *k2); /* compare function */
+
+#endif