Work on dict_compact routine.
[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.1  1999-03-09 13:07:06  adam
8  * Work on dict_compact routine.
9  *
10  */
11
12 #include <stdlib.h>
13 #include <string.h>
14 #include <stdio.h>
15
16 #include <log.h>
17 #include <dict.h>
18
19 int dict_compact (BFiles bfs, const char *from_name, const char *to_name)
20 {
21     int no_dir = 0;
22     Dict from, to;
23     int *map, i;
24     map = xmalloc (100);
25     from = dict_open (bfs, from_name, 0, 0);
26     if (!from)
27         return -1;
28     map = xmalloc ((from->head.last+1) * sizeof(*map));
29     for (i = 0; i <= from->head.last; i++)
30         map[i] = -1;
31     to = dict_open (bfs, to_name, 0, 1);
32     if (!to)
33         return -1;
34     map[0] = 0;
35     map[1] = DICT_pagesize(from);
36     
37     for (i = 1; i < from->head.last; i++)
38     {
39         void *buf;
40         logf (LOG_LOG, "map[%d] = %d", i, map[i]);
41         dict_bf_readp (from->dbf, i, &buf);
42         map[i+1] = map[i] + DICT_size(buf);
43         no_dir += DICT_nodir(buf);
44     }
45     logf (LOG_LOG, "map[%d] = %d", i, map[i]);
46     logf (LOG_LOG, "nodir = %d", no_dir);
47     dict_close (from);
48     dict_close (to);
49     return 0;
50 }