-## $Id: Makefile.am,v 1.4 2004-12-08 12:23:08 adam Exp $ Copyright (C) 1994-1998, Index Data ApS
+## $Id: Makefile.am,v 1.5 2005-03-30 09:25:23 adam Exp $ Copyright (C) 1994-1998, Index Data ApS
lib_LTLIBRARIES = libidzebra-bfile.la
-AM_CPPFLAGS = -I$(srcdir)/../include $(YAZINC)
+check_PROGRAMS = tstbfile1
+
+TESTS = $(check_PROGRAMS)
+
+tstbfile1_SOURCES = tstbfile1.c
+
+AM_CPPFLAGS = -I$(top_srcdir)/include $(YAZINC)
libidzebra_bfile_la_SOURCES = bfile.c mfile.c cfile.c commit.c cfile.h mfile.h
+LDADD = libidzebra-bfile.la ../util/libidzebra-util.la $(YAZLALIB)
+
-/* $Id: bfile.c,v 1.39 2005-01-15 19:38:17 adam Exp $
+/* $Id: bfile.c,v 1.40 2005-03-30 09:25:23 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <unistd.h>
#endif
-#include <zebrautl.h>
+#include <idzebra/util.h>
#include <idzebra/bfile.h>
#include "mfile.h"
#include "cfile.h"
MFile mf;
Zebra_lock_rdwr rdwr_lock;
struct CFile_struct *cf;
+ char *alloc_buf;
+ int block_size;
+ int alloc_buf_size;
+ zint last_block;
+ zint free_list;
+ zint root_block;
+ char *magic;
+ int header_dirty;
};
struct BFiles_struct {
if (bf->cf)
cf_close (bf->cf);
mf_close (bf->mf);
- xfree (bf);
+ xfree(bf->alloc_buf);
+ xfree(bf->magic);
+ xfree(bf);
return 0;
}
+#define HEADER_SIZE 256
+
+BFile bf_xopen(BFiles bfs, const char *name, int block_size, int wrflag,
+ const char *magic, int *read_version,
+ const char **more_info)
+{
+ char read_magic[40];
+ int l = 0;
+ int i = 0;
+ char *hbuf;
+ zint pos = 0;
+ BFile bf = bf_open(bfs, name, block_size, wrflag);
+
+ if (!bf)
+ return 0;
+ /* HEADER_SIZE is considered enough for our header */
+ if (bf->alloc_buf_size < HEADER_SIZE)
+ bf->alloc_buf_size = HEADER_SIZE;
+ else
+ bf->alloc_buf_size = bf->block_size;
+
+ hbuf = bf->alloc_buf = xmalloc(bf->alloc_buf_size);
+
+ /* fill-in default values */
+ bf->free_list = 0;
+ bf->root_block = bf->last_block = HEADER_SIZE / bf->block_size + 1;
+ bf->magic = xstrdup(magic);
+
+ if (!bf_read(bf, pos, 0, 0, hbuf + pos * bf->block_size))
+ {
+ if (wrflag)
+ bf->header_dirty = 1;
+ return bf;
+ }
+ while(hbuf[pos * bf->block_size + i] != '\0')
+ {
+ if (i == bf->block_size)
+ { /* end of block at pos reached .. */
+ if (bf->alloc_buf_size < (pos+1) * bf->block_size)
+ {
+ /* not room for all in alloc_buf_size */
+ yaz_log(YLOG_WARN, "bad header for %s (3)", magic);
+ bf_close(bf);
+ return 0;
+ }
+ /* read next block in header */
+ pos++;
+ if (!bf_read(bf, pos, 0, 0, hbuf + pos * bf->block_size))
+ {
+ yaz_log(YLOG_WARN, "missing header block %s (4)", magic);
+ bf_close(bf);
+ return 0;
+ }
+ i = 0; /* pos within block is reset */
+ }
+ else
+ i++;
+ }
+ if (sscanf(hbuf, "%39s %d " ZINT_FORMAT " " ZINT_FORMAT "%n",
+ read_magic, read_version, &bf->last_block,
+ &bf->free_list, &l) < 4 && l) /* if %n is counted, it's 5 */
+ {
+ yaz_log(YLOG_WARN, "bad header for %s (1)", magic);
+ bf_close(bf);
+ return 0;
+ }
+ if (strcmp(read_magic, magic))
+ {
+ yaz_log(YLOG_WARN, "bad header for %s (2)", magic);
+ bf_close(bf);
+ return 0;
+ }
+ if (more_info)
+ *more_info = hbuf + l;
+ return bf;
+}
+
+int bf_xclose (BFile bf, int version, const char *more_info)
+{
+ if (bf->header_dirty)
+ {
+ assert(bf->alloc_buf);
+ zint pos = 0;
+ assert(bf->magic);
+ sprintf(bf->alloc_buf, "%s %d " ZINT_FORMAT " " ZINT_FORMAT " ",
+ bf->magic, version, bf->last_block, bf->free_list);
+ if (more_info)
+ strcat(bf->alloc_buf, more_info);
+ while (1)
+ {
+ bf_write(bf, pos, 0, 0, bf->alloc_buf + pos * bf->block_size);
+ pos++;
+ if (pos * bf->block_size > strlen(bf->alloc_buf))
+ break;
+ }
+ }
+ return bf_close(bf);
+}
+
BFile bf_open (BFiles bfs, const char *name, int block_size, int wflag)
{
- BFile tmp = (BFile) xmalloc(sizeof(struct BFile_struct));
+ BFile bf = (BFile) xmalloc(sizeof(struct BFile_struct));
+ bf->alloc_buf = 0;
+ bf->magic = 0;
+ bf->block_size = block_size;
+ bf->header_dirty = 0;
if (bfs->commit_area)
{
int first_time;
- tmp->mf = mf_open (bfs->register_area, name, block_size, 0);
- tmp->cf = cf_open (tmp->mf, bfs->commit_area, name, block_size,
+ bf->mf = mf_open (bfs->register_area, name, block_size, 0);
+ bf->cf = cf_open (bf->mf, bfs->commit_area, name, block_size,
wflag, &first_time);
if (first_time)
{
FILE *outf;
- outf = open_cache (bfs, "ab");
+ outf = open_cache(bfs, "ab");
if (!outf)
{
- yaz_log (YLOG_FATAL|YLOG_ERRNO, "open %s", bfs->cache_fname);
- exit (1);
+ yaz_log(YLOG_FATAL|YLOG_ERRNO, "open %s", bfs->cache_fname);
+ exit(1);
}
- fprintf (outf, "%s %d\n", name, block_size);
- fclose (outf);
+ fprintf(outf, "%s %d\n", name, block_size);
+ fclose(outf);
}
}
else
{
- tmp->mf = mf_open(bfs->register_area, name, block_size, wflag);
- tmp->cf = NULL;
+ bf->mf = mf_open(bfs->register_area, name, block_size, wflag);
+ bf->cf = NULL;
}
- if (!tmp->mf)
+ if (!bf->mf)
{
- yaz_log (YLOG_FATAL, "mf_open failed for %s", name);
- xfree (tmp);
+ yaz_log(YLOG_FATAL, "mf_open failed for %s", name);
+ xfree(bf);
return 0;
}
- zebra_lock_rdwr_init (&tmp->rdwr_lock);
- return(tmp);
+ zebra_lock_rdwr_init(&bf->rdwr_lock);
+ return bf;
}
int bf_read (BFile bf, zint no, int offset, int nbytes, void *buf)
if (mustDisable)
bf_cache (bfs, 0);
}
+
+int bf_alloc(BFile bf, int no, zint *blocks)
+{
+ int i;
+ assert(bf->alloc_buf);
+ bf->header_dirty = 1;
+ for (i = 0; i < no; i++)
+ {
+ if (!bf->free_list)
+ blocks[i] = bf->last_block++;
+ else
+ {
+ char buf[16];
+ const char *cp = buf;
+ memset(buf, '\0', sizeof(buf));
+
+ blocks[i] = bf->free_list;
+ if (!bf_read(bf, bf->free_list, 0, sizeof(buf), buf))
+ {
+ yaz_log(YLOG_WARN, "Bad freelist entry " ZINT_FORMAT,
+ bf->free_list);
+ exit(1);
+ }
+ zebra_zint_decode(&cp, &bf->free_list);
+ }
+ }
+ return 0;
+}
+
+int bf_free(BFile bf, int no, const zint *blocks)
+{
+ int i;
+ assert(bf->alloc_buf);
+ bf->header_dirty = 1;
+ for (i = 0; i < no; i++)
+ {
+ char buf[16];
+ char *cp = buf;
+ memset(buf, '\0', sizeof(buf));
+ zebra_zint_encode(&cp, bf->free_list);
+ bf->free_list = blocks[i];
+ bf_write(bf, bf->free_list, 0, sizeof(buf), buf);
+ }
+ return 0;
+}
-/* $Id: cfile.c,v 1.33 2005-01-15 19:38:17 adam Exp $
+/* $Id: cfile.c,v 1.34 2005-03-30 09:25:23 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <stdlib.h>
#include <string.h>
-#include <zebrautl.h>
+#include <idzebra/util.h>
#include "mfile.h"
#include "cfile.h"
-/* $Id: commit.c,v 1.23 2005-01-15 19:38:17 adam Exp $
+/* $Id: commit.c,v 1.24 2005-03-30 09:25:23 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <assert.h>
#include <stdlib.h>
-#include <zebrautl.h>
+#include <idzebra/util.h>
#include "mfile.h"
#include "cfile.h"
-/* $Id: mfile.c,v 1.58 2005-01-15 19:38:17 adam Exp $
+/* $Id: mfile.c,v 1.59 2005-03-30 09:25:23 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <errno.h>
#include <zebra-lock.h>
-#include <zebrautl.h>
+#include <idzebra/util.h>
#include "mfile.h"
static int scan_areadef(MFile_area ma, const char *ad, const char *base)
--- /dev/null
+/* $Id: tstbfile1.c,v 1.1 2005-03-30 09:25:23 adam Exp $
+ Copyright (C) 1995-2005
+ Index Data ApS
+
+This file is part of the Zebra server.
+
+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
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with Zebra; see the file LICENSE.zebra. If not, write to the
+Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA.
+*/
+
+#include <assert.h>
+#include <stdlib.h>
+#include <idzebra/bfile.h>
+
+void tst1(BFiles bfs)
+{
+ int version = 1;
+ BFile bf;
+
+ bf_reset(bfs);
+ bf = bf_xopen(bfs, "tst", /* block size */ 32,
+ /* wr */ 1, "tstmagic", &version, 0 /* more_info */);
+
+ bf_xclose(bf, version, 0 /* no more info */);
+
+ bf = bf_xopen(bfs, "tst", /* block size */ 32,
+ /* wr */ 1, "tstmagic", &version, 0 /* more_info */);
+
+ bf_xclose(bf, version, 0 /* no more info */);
+}
+
+void tst2(BFiles bfs)
+{
+ int version = 1;
+ int bno, i;
+ zint blocks[1000];
+ BFile bf;
+ bf_reset(bfs);
+
+ bf = bf_xopen(bfs, "tst", /* block size */ 32,
+ /* wr */ 1, "tstmagic", &version, 0 /* more_info */);
+
+ bno = 0;
+ for (i = 1; i<30; i++)
+ {
+ int j;
+ for (j = 0; j<i; j++)
+ blocks[bno + j] = 0;
+ if (bf_alloc(bf, i, blocks + bno))
+ {
+ fprintf(stderr, "bf_alloc failed i=%d bno=%d\n", i, bno);
+ exit(1);
+ }
+ for (j = 0; j < i; j++)
+ {
+ if (!blocks[bno + j])
+ {
+ fprintf(stderr, "zero block i=%d bno=%d j=%d\n", i, bno, j);
+ exit(1);
+ }
+ }
+ bno += i;
+ }
+ for (i = 0; i<bno; i++)
+ {
+ if (bf_free(bf, 1, blocks + i))
+ {
+ fprintf(stderr, "bf_freec failed i=%d\n", i);
+ exit(1);
+ }
+ }
+ bf_xclose(bf, version, 0);
+}
+
+#define BLOCKS 100
+
+void tst3(BFiles bfs)
+{
+ int version = 1;
+ int i;
+ zint blocks[BLOCKS];
+ BFile bf;
+ int no_in_use = 0;
+ int pass = 0;
+ bf_reset(bfs);
+
+ for(i = 0; i<BLOCKS; i++)
+ blocks[i] = 0;
+
+ bf = bf_xopen(bfs, "tst", /* block size */ 32,
+ /* wr */ 1, "tstmagic", &version, 0 /* more_info */);
+
+ no_in_use = 0;
+ for (pass = 0; pass < 100; pass++)
+ {
+ int r = random() % 9;
+
+ assert (no_in_use >= 0 && no_in_use <= BLOCKS);
+ if (r < 5 && (BLOCKS - no_in_use) > 0)
+ {
+ /* alloc phase */
+ int j = 0;
+ zint tblocks[BLOCKS];
+ int left = BLOCKS - no_in_use;
+ int to_alloc = 1 + (random() % left);
+
+ bf_alloc(bf, to_alloc, tblocks);
+ /* transfer from tblocks to blocks */
+ for (i = 0; i<BLOCKS; i++)
+ {
+ if (blocks[i] == 0)
+ {
+ blocks[i] = tblocks[j++];
+ no_in_use++;
+ if (j == to_alloc)
+ break;
+ }
+ }
+ }
+ else if (r < 8 && no_in_use > 0)
+ {
+ /* free phase */
+ zint tblocks[BLOCKS];
+ int to_free = 1 + (random() % no_in_use);
+ int start = random() % to_free;
+ int j = 0;
+ for (i = 0; i<BLOCKS; i++)
+ {
+ if (blocks[i])
+ {
+ if (j >= start && j < to_free)
+ {
+ tblocks[j-start] = blocks[i];
+ blocks[i] = 0;
+ no_in_use--;
+ }
+ j++;
+ }
+ }
+ assert(tblocks[to_free-start-1]);
+ bf_free(bf, to_free - start, tblocks);
+ }
+ else
+ {
+ bf_xclose(bf, version, 0);
+ bf = bf_xopen(bfs, "tst", /* block size */ 32,
+ /* wr */ 1, "tstmagic", &version, 0 /* more_info */);
+ }
+ }
+ bf_xclose(bf, version, 0);
+}
+
+int main(int argc, char **argv)
+{
+ BFiles bfs = bfs_create(0, /* register: current dir, no limit */
+ 0 /* base: current dir */
+ );
+ if (!bfs)
+ exit(1);
+
+ tst1(bfs);
+ tst2(bfs);
+ tst3(bfs);
+ bf_reset(bfs);
+ bfs_destroy(bfs);
+ exit(0);
+}
-/* $Id: agrep.c,v 1.14 2005-01-15 19:38:18 adam Exp $
+/* $Id: agrep.c,v 1.15 2005-03-30 09:25:23 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <unistd.h>
#endif
-#include <zebrautl.h>
+#include <idzebra/util.h>
#include <dfa.h>
#include "imalloc.h"
-/* $Id: bset.c,v 1.7 2005-01-15 19:38:18 adam Exp $
+/* $Id: bset.c,v 1.8 2005-03-30 09:25:23 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <stdlib.h>
#include <string.h>
-#include <zebrautl.h>
+#include <idzebra/util.h>
#include <bset.h>
#include "imalloc.h"
-/* $Id: dfa.c,v 1.33 2005-01-15 21:45:42 adam Exp $
+/* $Id: dfa.c,v 1.34 2005-03-30 09:25:23 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <string.h>
#include <ctype.h>
-#include <zebrautl.h>
+#include <idzebra/util.h>
#include "dfap.h"
#include "imalloc.h"
-/* $Id: grepper.c,v 1.12 2005-01-15 19:38:19 adam Exp $
+/* $Id: grepper.c,v 1.13 2005-03-30 09:25:23 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <ctype.h>
#include <assert.h>
-#include <zebrautl.h>
+#include <idzebra/util.h>
#include <dfa.h>
#include "imalloc.h"
-/* $Id: imalloc.c,v 1.11 2005-01-15 19:38:19 adam Exp $
+/* $Id: imalloc.c,v 1.12 2005-03-30 09:25:23 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <assert.h>
#include <stdlib.h>
-#include <zebrautl.h>
+#include <idzebra/util.h>
#include "imalloc.h"
#if MEMDEBUG
-/* $Id: lexer.c,v 1.13 2005-01-15 19:38:19 adam Exp $
+/* $Id: lexer.c,v 1.14 2005-03-30 09:25:23 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <string.h>
#include <stdarg.h>
-#include <zebrautl.h>
+#include <idzebra/util.h>
#include <dfa.h>
#include "imalloc.h"
#include "lexer.h"
-/* $Id: readfile.c,v 1.10 2005-01-15 19:38:19 adam Exp $
+/* $Id: readfile.c,v 1.11 2005-03-30 09:25:23 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <string.h>
#include <ctype.h>
-#include <zebrautl.h>
+#include <idzebra/util.h>
#include <dfa.h>
#include "lexer.h"
-/* $Id: dictext.c,v 1.11 2005-01-15 19:38:21 adam Exp $
+/* $Id: dictext.c,v 1.12 2005-03-30 09:25:23 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <assert.h>
#include <ctype.h>
-#include <zebrautl.h>
+#include <idzebra/util.h>
char *prog;
-/* $Id: dicttest.c,v 1.32 2005-01-15 19:38:21 adam Exp $
+/* $Id: dicttest.c,v 1.33 2005-03-30 09:25:23 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <ctype.h>
#include <idzebra/dict.h>
-#include <zebrautl.h>
+#include <idzebra/util.h>
+#include <idzebra/res.h>
char *prog;
static Dict dict;
-# $Id: Makefile.am,v 1.21 2005-01-15 21:45:42 adam Exp $
+# $Id: Makefile.am,v 1.22 2005-03-30 09:25:23 adam Exp $
noinst_HEADERS = bset.h charmap.h \
direntz.h passwddb.h dfa.h zebra_xpath.h d1_absyn.h \
-rset.h dfaset.h sortidx.h zebra-lock.h zebrautl.h
+rset.h dfaset.h sortidx.h zebra-lock.h
SUBDIRS = idzebra
-# $Id: Makefile.am,v 1.5 2004-12-08 14:02:36 adam Exp $
+# $Id: Makefile.am,v 1.6 2005-03-30 09:25:23 adam Exp $
pkginclude_HEADERS=api.h version.h res.h recctrl.h data1.h recgrs.h \
- zebramap.h bfile.h dict.h isam-codec.h isams.h isamc.h isamb.h
+ zebramap.h bfile.h dict.h isam-codec.h isams.h isamc.h isamb.h util.h
-/* $Id: bfile.h,v 1.3 2005-01-15 19:38:24 adam Exp $
+/* $Id: bfile.h,v 1.4 2005-03-30 09:25:23 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#define BFILE_H
#include <yaz/yconfig.h>
-#include <idzebra/version.h>
+#include <idzebra/util.h>
YAZ_BEGIN_CDECL
YAZ_EXPORT
int bf_close (BFile);
+YAZ_EXPORT
+int bf_xclose (BFile bf, int version, const char *more_info);
+
/* bf_open: opens bfile.
opens bfile with name 'name' and with 'block_size' as block size.
returns bfile handle is successful; NULL otherwise
YAZ_EXPORT
BFile bf_open (BFiles bfs, const char *name, int block_size, int wflag);
+YAZ_EXPORT
+BFile bf_xopen(BFiles bfs, const char *name, int block_size, int wrflag,
+ const char *magic, int *read_version,
+ const char **more_info);
+
/* bf_read: reads bytes from bfile 'bf'.
reads 'nbytes' bytes (or whole block if 0) from offset 'offset' from
block 'no'. stores contents in buffer 'buf'.
YAZ_EXPORT
void bf_reset (BFiles bfs);
+/* bf_alloc: allocate one or more blocks */
+YAZ_EXPORT
+int bf_alloc(BFile bf, int no, zint *blocks);
+
+/* bf_alloc: allocate one or more blocks */
+YAZ_EXPORT
+int bf_free(BFile bf, int no, const zint *blocks);
+
YAZ_END_CDECL
#endif
-/* $Id: data1.h,v 1.7 2005-01-15 19:38:24 adam Exp $
+/* $Id: data1.h,v 1.8 2005-03-30 09:25:23 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <yaz/nmem.h>
#include <yaz/oid.h>
#include <yaz/proto.h>
-
-#include <idzebra/version.h>
-
#include <yaz/yaz-util.h>
+#include <idzebra/util.h>
+
#define d1_isspace(c) strchr(" \r\n\t\f", c)
#define d1_isdigit(c) ((c) <= '9' && (c) >= '0')
-/* $Id: res.h,v 1.3 2005-01-15 19:38:24 adam Exp $
+/* $Id: res.h,v 1.4 2005-03-30 09:25:23 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
02111-1307, USA.
*/
-#ifndef RES_H
-#define RES_H
+#ifndef IDZEBRA_RES_H
+#define IDZEBRA_RES_H
-#include <yaz/yaz-version.h>
+#include <idzebra/util.h>
YAZ_BEGIN_CDECL
--- /dev/null
+/* $Id: util.h,v 1.1 2005-03-30 09:25:23 adam Exp $
+ Copyright (C) 1995-2005
+ Index Data ApS
+
+This file is part of the Zebra server.
+
+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
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with Zebra; see the file LICENSE.zebra. If not, write to the
+Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA.
+*/
+
+#ifndef ZEBRA_UTIL_H
+#define ZEBRA_UTIL_H
+
+#include <yaz/yaz-util.h>
+
+#include <idzebra/version.h>
+
+/* check that we don't have all too old yaz */
+#ifndef YLOG_ERRNO
+#error Need a modern yaz with YLOG_ defines
+#endif
+
+YAZ_BEGIN_CDECL
+
+#ifdef __GNUC__
+typedef long long int zint;
+#define ZINT_FORMAT "%lld"
+#define ZINT_FORMAT0 "lld"
+#else
+#ifdef WIN32
+typedef __int64 zint;
+#define ZINT_FORMAT "%I64d"
+#define ZINT_FORMAT0 "I64d"
+#else
+typedef long zint;
+#define ZINT_FORMAT "%ld"
+#define ZINT_FORMAT0 "ld"
+#endif
+#endif
+
+typedef zint SYSNO;
+
+YAZ_EXPORT
+zint atoi_zn (const char *buf, zint len);
+
+YAZ_EXPORT
+void zebra_zint_encode(char **dst, zint pos);
+
+YAZ_EXPORT
+void zebra_zint_decode(const char **src, zint *pos);
+
+YAZ_END_CDECL
+
+#define CAST_ZINT_TO_INT(x) (int)(x)
+#define CAST_ZINT_TO_DOUBLE(x) (double)(x)
+
+#endif
-/* $Id: version.h,v 1.2 2005-01-15 19:38:24 adam Exp $
+/* $Id: version.h,v 1.3 2005-03-30 09:25:23 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#define ZEBRAVER "1.4.0"
-#define ZEBRADATE "$Date: 2005-01-15 19:38:24 $"
-
-#ifdef __GNUC__
-typedef long long int zint;
-#define ZINT_FORMAT "%lld"
-#define ZINT_FORMAT0 "lld"
-#else
-#ifdef WIN32
-typedef __int64 zint;
-#define ZINT_FORMAT "%I64d"
-#define ZINT_FORMAT0 "I64d"
-#else
-typedef long zint;
-#define ZINT_FORMAT "%ld"
-#define ZINT_FORMAT0 "ld"
-#endif
-#endif
-
-typedef zint SYSNO;
+#define ZEBRADATE "$Date: 2005-03-30 09:25:23 $"
#endif
+++ /dev/null
-/* $Id: zebrautl.h,v 1.14 2005-03-08 14:02:08 adam Exp $
- Copyright (C) 1995-2005
- Index Data ApS
-
-This file is part of the Zebra server.
-
-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
-Software Foundation; either version 2, or (at your option) any later
-version.
-
-Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License
-along with Zebra; see the file LICENSE.zebra. If not, write to the
-Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.
-*/
-
-#ifndef ZEBRA_UTIL_H
-#define ZEBRA_UTIL_H
-
-#include <yaz/yaz-util.h>
-
-#include <idzebra/res.h>
-#include <idzebra/version.h>
-
-/* check that we don't have all too old yaz */
-#ifndef YLOG_ERRNO
-#error Need a modern yaz with YLOG_ defines
-#endif
-
-YAZ_BEGIN_CDECL
-zint atoi_zn (const char *buf, zint len);
-YAZ_END_CDECL
-
-#define CAST_ZINT_TO_INT(x) (int)(x)
-#define CAST_ZINT_TO_DOUBLE(x) (double)(x)
-
-#endif
-/* $Id: attribute.c,v 1.19 2005-01-15 19:38:24 adam Exp $
+/* $Id: attribute.c,v 1.20 2005-03-30 09:25:23 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
02111-1307, USA.
*/
-
-
#include <stdio.h>
#include <yaz/log.h>
#include <idzebra/res.h>
-#include <zebrautl.h>
+#include <idzebra/util.h>
#include "index.h"
static data1_att *getatt(data1_attset *p, int att, const char *sattr)
-/* $Id: index.h,v 1.130 2005-01-16 23:14:57 adam Exp $
+/* $Id: index.h,v 1.131 2005-03-30 09:25:23 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <time.h>
#include <stdlib.h>
#include <idzebra/version.h>
-#include <zebrautl.h>
+#include <idzebra/util.h>
#include <sortidx.h>
#if HAVE_SYS_TIMES_H
-/* $Id: recindex.h,v 1.23 2005-01-15 19:38:26 adam Exp $
+/* $Id: recindex.h,v 1.24 2005-03-30 09:25:23 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#ifndef RECINDEX_H
#define RECINDEX_H
-#include <zebrautl.h>
+#include <idzebra/util.h>
#include <zebra-lock.h>
#include <idzebra/bfile.h>
-/* $Id: recctrl.c,v 1.17 2005-01-15 19:38:32 adam Exp $
+/* $Id: recctrl.c,v 1.18 2005-03-30 09:25:24 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#endif
#include <direntz.h>
-#include <zebrautl.h>
+#include <idzebra/util.h>
#include <idzebra/recctrl.h>
struct recTypeClass {
-/* $Id: rectext.c,v 1.24 2005-03-05 09:19:16 adam Exp $
+/* $Id: rectext.c,v 1.25 2005-03-30 09:25:24 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <assert.h>
#include <ctype.h>
-#include <zebrautl.h>
+#include <idzebra/util.h>
#include <idzebra/recctrl.h>
struct text_info {
-/* $Id: regxread.c,v 1.57 2005-01-16 23:14:57 adam Exp $
+/* $Id: regxread.c,v 1.58 2005-03-30 09:25:24 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <ctype.h>
#include <yaz/tpath.h>
-#include <zebrautl.h>
+#include <idzebra/util.h>
#include <dfa.h>
#include <idzebra/recgrs.h>
-/* $Id: safari.c,v 1.5 2005-03-09 13:45:29 adam Exp $
+/* $Id: safari.c,v 1.6 2005-03-30 09:25:24 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <assert.h>
#include <ctype.h>
-#include <zebrautl.h>
+#include <idzebra/util.h>
#include <idzebra/recctrl.h>
struct safari_info {
-/* $Id: rsbetween.c,v 1.35 2005-01-15 20:47:16 adam Exp $
+/* $Id: rsbetween.c,v 1.36 2005-03-30 09:25:24 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <string.h>
#include <assert.h>
-#include <zebrautl.h>
+#include <idzebra/util.h>
#include <rset.h>
-/* $Id: rsbool.c,v 1.52 2005-01-15 19:38:33 adam Exp $
+/* $Id: rsbool.c,v 1.53 2005-03-30 09:25:24 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <string.h>
#include <assert.h>
-#include <zebrautl.h>
+#include <idzebra/util.h>
#include <rset.h>
#ifndef RSET_DEBUG
-/* $Id: rset.c,v 1.43 2005-01-17 01:21:44 adam Exp $
+/* $Id: rset.c,v 1.44 2005-03-30 09:25:24 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <stdio.h>
#include <string.h>
-#include <zebrautl.h>
+#include <idzebra/util.h>
#include <assert.h>
#include <yaz/nmem.h>
#include <rset.h>
-/* $Id: rsisamb.c,v 1.29 2005-01-15 19:38:34 adam Exp $
+/* $Id: rsisamb.c,v 1.30 2005-03-30 09:25:24 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <stdio.h>
#include <assert.h>
-#include <zebrautl.h>
+#include <idzebra/util.h>
#include <rset.h>
#include <string.h>
-/* $Id: rsisamc.c,v 1.35 2005-01-15 19:38:34 adam Exp $
+/* $Id: rsisamc.c,v 1.36 2005-03-30 09:25:24 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <stdio.h>
#include <assert.h>
#include <string.h>
-#include <zebrautl.h>
+#include <idzebra/util.h>
#include <rset.h>
static RSFD r_open (RSET ct, int flag);
-/* $Id: rsisams.c,v 1.18 2005-01-15 19:38:34 adam Exp $
+/* $Id: rsisams.c,v 1.19 2005-03-30 09:25:24 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <stdio.h>
#include <assert.h>
-#include <zebrautl.h>
+#include <idzebra/util.h>
#include <rset.h>
static RSFD r_open (RSET ct, int flag);
-/* $Id: rsmultiandor.c,v 1.14 2005-03-08 14:02:15 adam Exp $
+/* $Id: rsmultiandor.c,v 1.15 2005-03-30 09:25:24 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <stdlib.h>
#include <string.h>
-#include <zebrautl.h>
+#include <idzebra/util.h>
#include <idzebra/isamc.h>
#include <rset.h>
-/* $Id: rsnull.c,v 1.31 2005-01-15 19:38:35 adam Exp $
+/* $Id: rsnull.c,v 1.32 2005-03-30 09:25:24 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <stdio.h>
#include <assert.h>
-#include <zebrautl.h>
+#include <idzebra/util.h>
#include <rset.h>
-/* $Id: rsprox.c,v 1.25 2005-03-08 14:02:15 adam Exp $
+/* $Id: rsprox.c,v 1.26 2005-03-30 09:25:24 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <string.h>
#include <assert.h>
-#include <zebrautl.h>
+#include <idzebra/util.h>
#include <rset.h>
#ifndef RSET_DEBUG
-/* $Id: rstemp.c,v 1.60 2005-01-17 01:21:44 adam Exp $
+/* $Id: rstemp.c,v 1.61 2005-03-30 09:25:24 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#endif
#include <sys/types.h>
-#include <zebrautl.h>
+#include <idzebra/util.h>
#include <rset.h>
static RSFD r_open(RSET ct, int flag);
-# $Id: Makefile.am,v 1.4 2004-09-30 08:16:49 adam Exp $
+# $Id: Makefile.am,v 1.5 2005-03-30 09:25:25 adam Exp $
-TESTS = tstcodec
+check_PROGRAMS = tstcodec
+
+TESTS = $(check_PROGRAMS)
zebralibs = \
../../index/libidzebra-api.la \
tstcodec_SOURCES = tstcodec.c
-noinst_PROGRAMS = tstcodec
AM_CPPFLAGS = -I$(top_srcdir)/include $(YAZINC)
-## $Id: Makefile.am,v 1.12 2004-09-30 08:16:49 adam Exp $
+## $Id: Makefile.am,v 1.13 2005-03-30 09:25:25 adam Exp $
lib_LTLIBRARIES = libidzebra-util.la
AM_CPPFLAGS = -I$(srcdir)/../include $(YAZINC) -DDEFAULT_PROFILE_PATH=\"$(pkgdatadir)/tab\"
LDADD = libidzebra-util.la $(YAZLALIB)
-libidzebra_util_la_SOURCES = res.c charmap.c zebramap.c passwddb.c \
+libidzebra_util_la_SOURCES = zint.c res.c charmap.c zebramap.c passwddb.c \
zebra-lock.c dirent.c xpath.c atoi_zn.c
passtest_SOURCES = passtest.c
-/* $Id: atoi_zn.c,v 1.2 2005-01-15 19:38:40 adam Exp $
+/* $Id: atoi_zn.c,v 1.3 2005-03-30 09:25:25 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <string.h>
#include <ctype.h>
-#include <zebrautl.h>
+#include <idzebra/util.h>
zint atoi_zn (const char *buf, zint len)
{
-/* $Id: res.c,v 1.39 2005-01-15 19:38:42 adam Exp $
+/* $Id: res.c,v 1.40 2005-03-30 09:25:25 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
#include <unistd.h>
#endif
-#include <zebrautl.h>
-#include <yaz/yaz-util.h>
+#include <idzebra/res.h>
struct res_entry {
char *name;
--- /dev/null
+/* $Id: zint.c,v 1.1 2005-03-30 09:25:25 adam Exp $
+ Copyright (C) 1995-2005
+ Index Data ApS
+
+This file is part of the Zebra server.
+
+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
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with Zebra; see the file LICENSE.zebra. If not, write to the
+Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA.
+*/
+
+#include <idzebra/util.h>
+
+void zebra_zint_encode(char **dst, zint pos)
+{
+ unsigned char *bp = (unsigned char*) *dst;
+
+ while (pos > 127)
+ {
+ *bp++ = (unsigned char) (128 | (pos & 127));
+ pos = pos >> 7;
+ }
+ *bp++ = (unsigned char) pos;
+ *dst = (char *) bp;
+}
+
+void zebra_zint_decode(const char **src, zint *pos)
+{
+ const unsigned char **bp = (const unsigned char **) src;
+ zint d = 0;
+ unsigned char c;
+ unsigned r = 0;
+
+ while (((c = *(*bp)++) & 128))
+ {
+ d += ((zint) (c & 127) << r);
+ r += 7;
+ }
+ d += ((zint) c << r);
+ *pos = d;
+}
# Zebra makefile for MS NMAKE
-# $Id: makefile,v 1.33 2005-01-16 00:27:54 adam Exp $
+# $Id: makefile,v 1.34 2005-03-30 09:25:26 adam Exp $
###########################################################
############### Parameters
$(OBJDIR)\trunc.obj \
$(OBJDIR)\zebraapi.obj \
$(OBJDIR)\zebramap.obj \
+ $(OBJDIR)\zint.obj \
$(OBJDIR)\zinfo.obj \
$(OBJDIR)\zrpn.obj \
$(OBJDIR)\zsets.obj \