--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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;
+}