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