More work on SDRKit integration.
[idzebra-moved-to-github.git] / dict / dcompact.c
1 /*
2  * Copyright (C) 1994-1999, Index Data
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: dcompact.c,v $
7  * Revision 1.2  1999-03-09 16:27:49  adam
8  * More work on SDRKit integration.
9  *
10  * Revision 1.1  1999/03/09 13:07:06  adam
11  * Work on dict_compact routine.
12  *
13  */
14
15 #include <stdlib.h>
16 #include <string.h>
17 #include <stdio.h>
18
19 #include <log.h>
20 #include <dict.h>
21
22 int dict_compact (BFiles bfs, const char *from_name, const char *to_name)
23 {
24     int no_dir = 0;
25     Dict from, to;
26     int *map, i;
27     map = xmalloc (100);
28     from = dict_open (bfs, from_name, 0, 0);
29     if (!from)
30         return -1;
31     map = xmalloc ((from->head.last+1) * sizeof(*map));
32     for (i = 0; i <= (int) (from->head.last); i++)
33         map[i] = -1;
34     to = dict_open (bfs, to_name, 0, 1);
35     if (!to)
36         return -1;
37     map[0] = 0;
38     map[1] = DICT_pagesize(from);
39     
40     for (i = 1; i < (int) (from->head.last); i++)
41     {
42         void *buf;
43         logf (LOG_LOG, "map[%d] = %d", i, map[i]);
44         dict_bf_readp (from->dbf, i, &buf);
45         map[i+1] = map[i] + DICT_size(buf);
46         no_dir += DICT_nodir(buf);
47     }
48     logf (LOG_LOG, "map[%d] = %d", i, map[i]);
49     logf (LOG_LOG, "nodir = %d", no_dir);
50     dict_close (from);
51     dict_close (to);
52     return 0;
53 }