From: Adam Dickmeiss Date: Wed, 30 Mar 2005 09:25:23 +0000 (+0000) Subject: Moved zebrautl.h to idzebra/util.h. X-Git-Tag: snippet.version.1~109 X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=commitdiff_plain;h=deff57cfa9d9b39c4a4f1c9b82a64c6e61d821a4 Moved zebrautl.h to idzebra/util.h. Implemented bf_xpen, bf_xclose that opens/closes a BFile with magic header and managed block free list handling. bf_alloc/bf_free performs the block allocation. --- diff --git a/bfile/Makefile.am b/bfile/Makefile.am index 05db97f..38d05f3 100644 --- a/bfile/Makefile.am +++ b/bfile/Makefile.am @@ -1,7 +1,15 @@ -## $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) + diff --git a/bfile/bfile.c b/bfile/bfile.c index 41b8a62..facec01 100644 --- a/bfile/bfile.c +++ b/bfile/bfile.c @@ -1,4 +1,4 @@ -/* $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 @@ -30,7 +30,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #endif -#include +#include #include #include "mfile.h" #include "cfile.h" @@ -40,6 +40,14 @@ struct BFile_struct 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 { @@ -116,48 +124,153 @@ int bf_close (BFile bf) 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) @@ -268,3 +381,48 @@ void bf_commitClean (BFiles bfs, const char *spec) 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; +} diff --git a/bfile/cfile.c b/bfile/cfile.c index 63465d5..d2d1add 100644 --- a/bfile/cfile.c +++ b/bfile/cfile.c @@ -1,4 +1,4 @@ -/* $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 @@ -24,7 +24,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include -#include +#include #include "mfile.h" #include "cfile.h" diff --git a/bfile/commit.c b/bfile/commit.c index 1715913..2461834 100644 --- a/bfile/commit.c +++ b/bfile/commit.c @@ -1,4 +1,4 @@ -/* $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 @@ -24,7 +24,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include -#include +#include #include "mfile.h" #include "cfile.h" diff --git a/bfile/mfile.c b/bfile/mfile.c index 189f202..69a062a 100644 --- a/bfile/mfile.c +++ b/bfile/mfile.c @@ -1,4 +1,4 @@ -/* $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 @@ -43,7 +43,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include -#include +#include #include "mfile.h" static int scan_areadef(MFile_area ma, const char *ad, const char *base) diff --git a/bfile/tstbfile1.c b/bfile/tstbfile1.c new file mode 100644 index 0000000..f2a4903 --- /dev/null +++ b/bfile/tstbfile1.c @@ -0,0 +1,179 @@ +/* $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 +#include +#include + +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= 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 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= 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); +} diff --git a/dfa/agrep.c b/dfa/agrep.c index 9409baa..179a495 100644 --- a/dfa/agrep.c +++ b/dfa/agrep.c @@ -1,4 +1,4 @@ -/* $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 @@ -39,7 +39,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #endif -#include +#include #include #include "imalloc.h" diff --git a/dfa/bset.c b/dfa/bset.c index 8fef050..3634774 100644 --- a/dfa/bset.c +++ b/dfa/bset.c @@ -1,4 +1,4 @@ -/* $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 @@ -27,7 +27,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include -#include +#include #include #include "imalloc.h" diff --git a/dfa/dfa.c b/dfa/dfa.c index d58b303..5c3d376 100644 --- a/dfa/dfa.c +++ b/dfa/dfa.c @@ -1,4 +1,4 @@ -/* $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 @@ -28,7 +28,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include -#include +#include #include "dfap.h" #include "imalloc.h" diff --git a/dfa/grepper.c b/dfa/grepper.c index 48fa465..03553a6 100644 --- a/dfa/grepper.c +++ b/dfa/grepper.c @@ -1,4 +1,4 @@ -/* $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 @@ -27,7 +27,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include -#include +#include #include #include "imalloc.h" diff --git a/dfa/imalloc.c b/dfa/imalloc.c index b88967f..0561d89 100644 --- a/dfa/imalloc.c +++ b/dfa/imalloc.c @@ -1,4 +1,4 @@ -/* $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 @@ -25,7 +25,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include -#include +#include #include "imalloc.h" #if MEMDEBUG diff --git a/dfa/lexer.c b/dfa/lexer.c index e5bbc36..c6e1d85 100644 --- a/dfa/lexer.c +++ b/dfa/lexer.c @@ -1,4 +1,4 @@ -/* $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 @@ -28,7 +28,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include -#include +#include #include #include "imalloc.h" #include "lexer.h" diff --git a/dfa/readfile.c b/dfa/readfile.c index 40b0bf3..7682ea5 100644 --- a/dfa/readfile.c +++ b/dfa/readfile.c @@ -1,4 +1,4 @@ -/* $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 @@ -28,7 +28,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include -#include +#include #include #include "lexer.h" diff --git a/dict/dictext.c b/dict/dictext.c index b72e83a..124e461 100644 --- a/dict/dictext.c +++ b/dict/dictext.c @@ -1,4 +1,4 @@ -/* $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 @@ -28,7 +28,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include -#include +#include char *prog; diff --git a/dict/dicttest.c b/dict/dicttest.c index 2dce332..e923565 100644 --- a/dict/dicttest.c +++ b/dict/dicttest.c @@ -1,4 +1,4 @@ -/* $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 @@ -26,7 +26,8 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include -#include +#include +#include char *prog; static Dict dict; diff --git a/include/Makefile.am b/include/Makefile.am index f06e009..6bb6f49 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1,6 +1,6 @@ -# $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 diff --git a/include/idzebra/Makefile.am b/include/idzebra/Makefile.am index 52efdff..0c6f616 100644 --- a/include/idzebra/Makefile.am +++ b/include/idzebra/Makefile.am @@ -1,5 +1,5 @@ -# $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 diff --git a/include/idzebra/bfile.h b/include/idzebra/bfile.h index 4ec3923..d1b25c1 100644 --- a/include/idzebra/bfile.h +++ b/include/idzebra/bfile.h @@ -1,4 +1,4 @@ -/* $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 @@ -24,7 +24,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #define BFILE_H #include -#include +#include YAZ_BEGIN_CDECL @@ -40,6 +40,9 @@ void bfs_destroy (BFiles bfiles); 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 @@ -47,6 +50,11 @@ int bf_close (BFile); 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'. @@ -83,6 +91,14 @@ void bf_commitClean (BFiles bfs, const char *spec); 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 diff --git a/include/idzebra/data1.h b/include/idzebra/data1.h index dc7c975..705b9e9 100644 --- a/include/idzebra/data1.h +++ b/include/idzebra/data1.h @@ -1,4 +1,4 @@ -/* $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 @@ -28,11 +28,10 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include #include - -#include - #include +#include + #define d1_isspace(c) strchr(" \r\n\t\f", c) #define d1_isdigit(c) ((c) <= '9' && (c) >= '0') diff --git a/include/idzebra/res.h b/include/idzebra/res.h index 357801e..2a7c296 100644 --- a/include/idzebra/res.h +++ b/include/idzebra/res.h @@ -1,4 +1,4 @@ -/* $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 @@ -20,10 +20,10 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef RES_H -#define RES_H +#ifndef IDZEBRA_RES_H +#define IDZEBRA_RES_H -#include +#include YAZ_BEGIN_CDECL diff --git a/include/idzebra/util.h b/include/idzebra/util.h new file mode 100644 index 0000000..41f356e --- /dev/null +++ b/include/idzebra/util.h @@ -0,0 +1,69 @@ +/* $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 + +#include + +/* 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 diff --git a/include/idzebra/version.h b/include/idzebra/version.h index 4053fac..fe80f34 100644 --- a/include/idzebra/version.h +++ b/include/idzebra/version.h @@ -1,4 +1,4 @@ -/* $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 @@ -24,24 +24,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #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 diff --git a/include/zebrautl.h b/include/zebrautl.h deleted file mode 100644 index ecc5d42..0000000 --- a/include/zebrautl.h +++ /dev/null @@ -1,43 +0,0 @@ -/* $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 - -#include -#include - -/* 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 diff --git a/index/attribute.c b/index/attribute.c index 4ea12f7..51a5be0 100644 --- a/index/attribute.c +++ b/index/attribute.c @@ -1,4 +1,4 @@ -/* $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 @@ -20,13 +20,11 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - - #include #include #include -#include +#include #include "index.h" static data1_att *getatt(data1_attset *p, int att, const char *sattr) diff --git a/index/index.h b/index/index.h index 36b1c57..5fdc519 100644 --- a/index/index.h +++ b/index/index.h @@ -1,4 +1,4 @@ -/* $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 @@ -26,7 +26,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include #include -#include +#include #include #if HAVE_SYS_TIMES_H diff --git a/index/recindex.h b/index/recindex.h index d8b5e30..403795d 100644 --- a/index/recindex.h +++ b/index/recindex.h @@ -1,4 +1,4 @@ -/* $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 @@ -23,7 +23,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #ifndef RECINDEX_H #define RECINDEX_H -#include +#include #include #include diff --git a/recctrl/recctrl.c b/recctrl/recctrl.c index d4f6f2b..0acba7d 100644 --- a/recctrl/recctrl.c +++ b/recctrl/recctrl.c @@ -1,4 +1,4 @@ -/* $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 @@ -29,7 +29,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #endif #include -#include +#include #include struct recTypeClass { diff --git a/recctrl/rectext.c b/recctrl/rectext.c index 3b14203..48460d5 100644 --- a/recctrl/rectext.c +++ b/recctrl/rectext.c @@ -1,4 +1,4 @@ -/* $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 @@ -25,7 +25,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include -#include +#include #include struct text_info { diff --git a/recctrl/regxread.c b/recctrl/regxread.c index 3d074a8..db605ad 100644 --- a/recctrl/regxread.c +++ b/recctrl/regxread.c @@ -1,4 +1,4 @@ -/* $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 @@ -27,7 +27,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include -#include +#include #include #include diff --git a/recctrl/safari.c b/recctrl/safari.c index 6a1c585..a3a98cb 100644 --- a/recctrl/safari.c +++ b/recctrl/safari.c @@ -1,4 +1,4 @@ -/* $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 @@ -25,7 +25,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include -#include +#include #include struct safari_info { diff --git a/rset/rsbetween.c b/rset/rsbetween.c index 486954b..56cc894 100644 --- a/rset/rsbetween.c +++ b/rset/rsbetween.c @@ -1,4 +1,4 @@ -/* $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 @@ -36,7 +36,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include -#include +#include #include diff --git a/rset/rsbool.c b/rset/rsbool.c index 8dab557..04afa12 100644 --- a/rset/rsbool.c +++ b/rset/rsbool.c @@ -1,4 +1,4 @@ -/* $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 @@ -25,7 +25,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include -#include +#include #include #ifndef RSET_DEBUG diff --git a/rset/rset.c b/rset/rset.c index 41d39a7..26ba709 100644 --- a/rset/rset.c +++ b/rset/rset.c @@ -1,4 +1,4 @@ -/* $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 @@ -22,7 +22,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include -#include +#include #include #include #include diff --git a/rset/rsisamb.c b/rset/rsisamb.c index 305a3d8..c07c5a5 100644 --- a/rset/rsisamb.c +++ b/rset/rsisamb.c @@ -1,4 +1,4 @@ -/* $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 @@ -22,7 +22,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include -#include +#include #include #include diff --git a/rset/rsisamc.c b/rset/rsisamc.c index 09a0c29..7eafe1d 100644 --- a/rset/rsisamc.c +++ b/rset/rsisamc.c @@ -1,4 +1,4 @@ -/* $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 @@ -26,7 +26,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include #include -#include +#include #include static RSFD r_open (RSET ct, int flag); diff --git a/rset/rsisams.c b/rset/rsisams.c index 046d2c4..28bb5e5 100644 --- a/rset/rsisams.c +++ b/rset/rsisams.c @@ -1,4 +1,4 @@ -/* $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 @@ -24,7 +24,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include -#include +#include #include static RSFD r_open (RSET ct, int flag); diff --git a/rset/rsmultiandor.c b/rset/rsmultiandor.c index 0204cac..aeaffc0 100644 --- a/rset/rsmultiandor.c +++ b/rset/rsmultiandor.c @@ -1,4 +1,4 @@ -/* $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 @@ -39,7 +39,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include -#include +#include #include #include diff --git a/rset/rsnull.c b/rset/rsnull.c index f073744..754f771 100644 --- a/rset/rsnull.c +++ b/rset/rsnull.c @@ -1,4 +1,4 @@ -/* $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 @@ -24,7 +24,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include -#include +#include #include diff --git a/rset/rsprox.c b/rset/rsprox.c index d0746dd..129e521 100644 --- a/rset/rsprox.c +++ b/rset/rsprox.c @@ -1,4 +1,4 @@ -/* $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 @@ -25,7 +25,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include -#include +#include #include #ifndef RSET_DEBUG diff --git a/rset/rstemp.c b/rset/rstemp.c index 57e1beb..fa239f3 100644 --- a/rset/rstemp.c +++ b/rset/rstemp.c @@ -1,4 +1,4 @@ -/* $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 @@ -32,7 +32,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #endif #include -#include +#include #include static RSFD r_open(RSET ct, int flag); diff --git a/test/codec/Makefile.am b/test/codec/Makefile.am index a74c841..f7ab8e5 100644 --- a/test/codec/Makefile.am +++ b/test/codec/Makefile.am @@ -1,6 +1,8 @@ -# $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 \ @@ -17,7 +19,6 @@ zebralibs = \ tstcodec_SOURCES = tstcodec.c -noinst_PROGRAMS = tstcodec AM_CPPFLAGS = -I$(top_srcdir)/include $(YAZINC) diff --git a/util/Makefile.am b/util/Makefile.am index 7ba1fee..8c9783c 100644 --- a/util/Makefile.am +++ b/util/Makefile.am @@ -1,4 +1,4 @@ -## $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 @@ -13,7 +13,7 @@ DISTCLEANFILES = idzebra-config 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 diff --git a/util/atoi_zn.c b/util/atoi_zn.c index f9561ba..535327e 100644 --- a/util/atoi_zn.c +++ b/util/atoi_zn.c @@ -1,4 +1,4 @@ -/* $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 @@ -22,7 +22,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include -#include +#include zint atoi_zn (const char *buf, zint len) { diff --git a/util/res.c b/util/res.c index 6db1086..952b900 100644 --- a/util/res.c +++ b/util/res.c @@ -1,4 +1,4 @@ -/* $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 @@ -30,8 +30,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #endif -#include -#include +#include struct res_entry { char *name; diff --git a/util/zint.c b/util/zint.c new file mode 100644 index 0000000..b183a53 --- /dev/null +++ b/util/zint.c @@ -0,0 +1,52 @@ +/* $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 + +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; +} diff --git a/win/makefile b/win/makefile index 382212d..2fe6dcb 100644 --- a/win/makefile +++ b/win/makefile @@ -1,5 +1,5 @@ # 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 @@ -292,6 +292,7 @@ ZEBRALIB_OBJS= \ $(OBJDIR)\trunc.obj \ $(OBJDIR)\zebraapi.obj \ $(OBJDIR)\zebramap.obj \ + $(OBJDIR)\zint.obj \ $(OBJDIR)\zinfo.obj \ $(OBJDIR)\zrpn.obj \ $(OBJDIR)\zsets.obj \