From a4e93d62564084d6d1b6670d4fe75dd70a6ed139 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 9 Mar 1999 13:07:05 +0000 Subject: [PATCH] Work on dict_compact routine. --- dict/Makefile.in | 4 ++-- dict/dcompact.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ dict/open.c | 7 ++++++- include/dict.h | 6 +++++- 4 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 dict/dcompact.c diff --git a/dict/Makefile.in b/dict/Makefile.in index 6cc7efe..620863d 100644 --- a/dict/Makefile.in +++ b/dict/Makefile.in @@ -1,7 +1,7 @@ # Copyright (C) 1994-1998, Index Data # All rights reserved. # Sebastian Hammer, Adam Dickmeiss -# $Id: Makefile.in,v 1.2 1998-10-28 15:20:46 adam Exp $ +# $Id: Makefile.in,v 1.3 1999-03-09 13:07:05 adam Exp $ SHELL=/bin/sh @@ -20,7 +20,7 @@ TPROG2=dictext DEFS=$(CDEFS) $(INCLUDE) LIB=../lib/dict.a PO = scan.o dopen.o dclose.o drdwr.o open.o close.o insert.o lookup.o \ - lookupec.o lookgrep.o delete.o + lookupec.o lookgrep.o delete.o dcompact.o all: $(LIB) diff --git a/dict/dcompact.c b/dict/dcompact.c new file mode 100644 index 0000000..6dd4165 --- /dev/null +++ b/dict/dcompact.c @@ -0,0 +1,50 @@ +/* + * Copyright (C) 1994-1999, Index Data + * All rights reserved. + * Sebastian Hammer, Adam Dickmeiss + * + * $Log: dcompact.c,v $ + * Revision 1.1 1999-03-09 13:07:06 adam + * Work on dict_compact routine. + * + */ + +#include +#include +#include + +#include +#include + +int dict_compact (BFiles bfs, const char *from_name, const char *to_name) +{ + int no_dir = 0; + Dict from, to; + int *map, i; + map = xmalloc (100); + from = dict_open (bfs, from_name, 0, 0); + if (!from) + return -1; + map = xmalloc ((from->head.last+1) * sizeof(*map)); + for (i = 0; i <= from->head.last; i++) + map[i] = -1; + to = dict_open (bfs, to_name, 0, 1); + if (!to) + return -1; + map[0] = 0; + map[1] = DICT_pagesize(from); + + for (i = 1; i < from->head.last; i++) + { + void *buf; + logf (LOG_LOG, "map[%d] = %d", i, map[i]); + dict_bf_readp (from->dbf, i, &buf); + map[i+1] = map[i] + DICT_size(buf); + no_dir += DICT_nodir(buf); + } + logf (LOG_LOG, "map[%d] = %d", i, map[i]); + logf (LOG_LOG, "nodir = %d", no_dir); + dict_close (from); + dict_close (to); + return 0; +} diff --git a/dict/open.c b/dict/open.c index ad42795..a38076b 100644 --- a/dict/open.c +++ b/dict/open.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: open.c,v $ - * Revision 1.13 1999-02-02 14:50:27 adam + * Revision 1.14 1999-03-09 13:07:06 adam + * Work on dict_compact routine. + * + * Revision 1.13 1999/02/02 14:50:27 adam * Updated WIN32 code specific sections. Changed header. * * Revision 1.12 1997/09/17 12:19:07 adam @@ -64,6 +67,8 @@ Dict dict_open (BFiles bfs, const char *name, int cache, int rw) dict = xmalloc (sizeof(*dict)); + if (cache < 5) + cache = 5; sprintf (resource_str, "dict.%s.pagesize", name); dict->grep_cmap = NULL; diff --git a/include/dict.h b/include/dict.h index 6e4daf5..4b75eea 100644 --- a/include/dict.h +++ b/include/dict.h @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: dict.h,v $ - * Revision 1.27 1999-02-02 14:50:32 adam + * Revision 1.28 1999-03-09 13:07:06 adam + * Work on dict_compact routine. + * + * Revision 1.27 1999/02/02 14:50:32 adam * Updated WIN32 code specific sections. Changed header. * * Revision 1.26 1997/09/18 08:59:18 adam @@ -184,6 +187,7 @@ int dict_scan (Dict dict, char *str, void dict_grep_cmap (Dict dict, void *vp, const char **(*cmap)(void *vp, const char **from, int len)); +int dict_compact (BFiles bfs, const char *from, const char *to); #define DICT_EOS 0 -- 1.7.10.4