From: Adam Dickmeiss Date: Wed, 15 Nov 1995 14:46:17 +0000 (+0000) Subject: Started work on better record management system. X-Git-Tag: ZEBRA.1.0~682 X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=commitdiff_plain;h=5214040d316f7b5228e46e1749505e3c0c8869d4 Started work on better record management system. --- diff --git a/index/Makefile b/index/Makefile index 5968ac4..7cd9467 100644 --- a/index/Makefile +++ b/index/Makefile @@ -1,13 +1,13 @@ # Copyright (C) 1995, Index Data I/S # All rights reserved. # Sebastian Hammer, Adam Dickmeiss -# $Id: Makefile,v 1.16 1995-11-01 13:58:27 quinn Exp $ +# $Id: Makefile,v 1.17 1995-11-15 14:46:17 adam Exp $ SHELL=/bin/sh RANLIB=ranlib YAZ=../../yaz YAZLIB=$(YAZ)/lib/libyaz.a -#OSILIB=../../xtimosi/src/libmosi.a $(YAZ)/lib/librfc.a +OSILIB=../../xtimosi/src/libmosi.a $(YAZ)/lib/librfc.a #NETLIB=-lnsl -lsocket INCLUDE=-I../include -I$(YAZ)/include TPROG1=index @@ -15,10 +15,10 @@ TPROG2=kdump TPROG3=zserver DEFS=$(INCLUDE) O1 = main.o dir.o trav.o extract.o kinput.o kcompare.o \ - symtab.o text.o recctrl.o structrec.o + symtab.o text.o recctrl.o structrec.o recindex.o O2 = kdump.o O3 = zserver.o kcompare.o zrpn.o zsets.o text.o recctrl.o structrec.o \ - attribute.o + attribute.o recindex.o CPP=$(CC) -E all: $(TPROG1) $(TPROG2) $(TPROG3) diff --git a/index/index.h b/index/index.h index 9c92696..f9e4825 100644 --- a/index/index.h +++ b/index/index.h @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: index.h,v $ - * Revision 1.19 1995-10-27 14:00:11 adam + * Revision 1.20 1995-11-15 14:46:18 adam + * Started work on better record management system. + * + * Revision 1.19 1995/10/27 14:00:11 adam * Implemented detection of database availability. * * Revision 1.18 1995/10/17 18:02:08 adam @@ -117,3 +120,4 @@ void strtab_del (struct strtab *t, int index_char_cvt (int c); int index_word_prefix (char *string, int attset_ordinal, int local_attribute, char *databaseName); + diff --git a/index/recindex.c b/index/recindex.c new file mode 100644 index 0000000..f64816c --- /dev/null +++ b/index/recindex.c @@ -0,0 +1,114 @@ +/* + * Copyright (C) 1994-1995, Index Data I/S + * All rights reserved. + * Sebastian Hammer, Adam Dickmeiss + * + * $Log: recindex.c,v $ + * Revision 1.1 1995-11-15 14:46:20 adam + * Started work on better record management system. + * + */ +#include +#include +#include +#include +#include +#include +#include + +#include "recindex.h" + +#define REC_HEAD_MAGIC "rechead" + +static void rec_write_head (Records p) +{ + int r; + + assert (p); + assert (p->fd != -1); + if (lseek (p->fd, (off_t) 0, SEEK_SET) == -1) + { + logf (LOG_FATAL|LOG_ERRNO, "lseek to 0 in %s", p->fname); + exit (1); + } + r = write (p->fd, &p->head, sizeof(p->head)); + switch (r) + { + case -1: + logf (LOG_FATAL|LOG_ERRNO, "write head of %s", p->fname); + exit (1); + case sizeof(p->head): + break; + default: + logf (LOG_FATAL, "write head of %s. wrote %d", p->fname, r); + exit (1); + } +} + +Records rec_open (int rw) +{ + Records p; + int r; + + if (!(p = malloc (sizeof(*p)))) + { + logf (LOG_FATAL|LOG_ERRNO, "malloc"); + exit (1); + } + p->fname = "recindex"; + p->fd = open (p->fname, rw ? (O_RDWR|O_CREAT) : O_RDONLY, 0666); + if (p->fd == -1) + { + logf (LOG_FATAL|LOG_ERRNO, "open %s", p->fname); + exit (1); + } + r = read (p->fd, &p->head, sizeof(p->head)); + switch (r) + { + case -1: + logf (LOG_FATAL|LOG_ERRNO, "read %s", p->fname); + exit (1); + case 0: + p->head.no_records = 0; + p->head.freelist = 0; + if (rw) + rec_write_head (p); + break; + case sizeof(p->head): + if (memcmp (p->head.magic, REC_HEAD_MAGIC, sizeof(p->head.magic))) + { + logf (LOG_FATAL, "read %s. bad header", p->fname); + exit (1); + } + break; + default: + logf (LOG_FATAL, "read head of %s. expected %d. got %d", + p->fname, sizeof(p->head), r); + exit (1); + } + return p; +} + +void rec_close (Records p) +{ + if (p->fd != -1) + close (p->fd); + free (p); +} + +Record rec_get (Records p, int sysno) +{ + assert (p); + return NULL; +} + +Record rec_new (Records p) +{ + assert (p); + return NULL; +} + +void rec_put (Records p, Record rec) +{ + assert (p); +} diff --git a/index/recindex.h b/index/recindex.h new file mode 100644 index 0000000..6d0b23c --- /dev/null +++ b/index/recindex.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 1994-1995, Index Data I/S + * All rights reserved. + * Sebastian Hammer, Adam Dickmeiss + * + * $Log: recindex.h,v $ + * Revision 1.1 1995-11-15 14:46:21 adam + * Started work on better record management system. + * + */ + +#include + +typedef struct records_info { + int fd; + char *fname; + struct records_head { + char magic[8]; + int no_records; + int freelist; + } head; +} *Records; + +typedef struct record_info { + int sysno; + char *type; + char *fname; + char *kinfo; +} *Record; +