2 * Copyright (C) 1994-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.5 1999-05-26 07:49:12 adam
10 * Revision 1.4 1999/05/15 14:36:37 adam
11 * Updated dictionary. Implemented "compression" of dictionary.
13 * Revision 1.3 1999/05/12 13:08:06 adam
14 * First version of ISAMS.
16 * Revision 1.2 1999/03/09 16:27:49 adam
17 * More work on SDRKit integration.
19 * Revision 1.1 1999/03/09 13:07:06 adam
20 * Work on dict_compact routine.
32 static void dict_copy_page(Dict dict, char *to_p, char *from_p, int *map)
35 short *from_indxp, *to_indxp;
36 char *from_info, *to_info;
38 from_indxp = (short*) ((char*) from_p+DICT_bsize(from_p));
39 to_indxp = (short*) ((char*) to_p+DICT_bsize(to_p));
40 to_info = (char*) to_p + DICT_infoffset;
41 for (i = DICT_nodir (from_p); --i >= 0; )
43 if (*--from_indxp > 0) /* tail string here! */
45 /* string (Dict_char *) DICT_EOS terminated */
46 /* unsigned char length of information */
47 /* char * information */
49 from_info = (char*) from_p + *from_indxp;
50 *--to_indxp = to_info - to_p;
51 slen = (dict_strlen((Dict_char*) from_info)+1)*sizeof(Dict_char);
52 memcpy (to_info, from_info, slen);
61 /* Dict_char sub char */
62 /* unsigned char length of information */
63 /* char * information */
65 *--to_indxp = -(to_info - to_p);
66 from_info = (char*) from_p - *from_indxp;
68 memcpy (&subptr, from_info, sizeof(subptr));
70 from_info += sizeof(Dict_ptr);
71 memcpy (&subchar, from_info, sizeof(subchar));
72 from_info += sizeof(Dict_char);
74 memcpy (to_info, &subptr, sizeof(Dict_ptr));
75 to_info += sizeof(Dict_ptr);
76 memcpy (to_info, &subchar, sizeof(Dict_char));
77 to_info += sizeof(Dict_char);
79 assert (to_info < (char*) to_indxp);
81 memcpy (to_info, from_info, slen);
85 DICT_size(to_p) = to_info - to_p;
87 DICT_nodir(to_p) = no;
90 int dict_copy_compact (BFiles bfs, const char *from_name, const char *to_name)
93 Dict dict_from, dict_to;
95 dict_from = dict_open (bfs, from_name, 0, 0, 0);
98 map = (int *) xmalloc ((dict_from->head.last+1) * sizeof(*map));
99 for (i = 0; i <= (int) (dict_from->head.last); i++)
101 dict_to = dict_open (bfs, to_name, 0, 1, 1);
105 map[1] = dict_from->head.page_size;
107 for (i = 1; i < (int) (dict_from->head.last); i++)
112 logf (LOG_LOG, "map[%d] = %d", i, map[i]);
114 dict_bf_readp (dict_from->dbf, i, &buf);
115 size = ((DICT_size(buf)+sizeof(short)-1)/sizeof(short) +
116 DICT_nodir(buf))*sizeof(short);
117 map[i+1] = map[i] + size;
118 no_dir += DICT_nodir(buf);
120 logf (LOG_LOG, "map[%d] = %d", i, map[i]);
121 logf (LOG_LOG, "nodir = %d", no_dir);
122 dict_to->head.root = map[1];
123 dict_to->head.last = map[i];
124 for (i = 1; i< (int) (dict_from->head.last); i++)
127 dict_bf_readp (dict_from->dbf, i, &old_p);
129 logf (LOG_LOG, "dict_bf_newp no=%d size=%d", map[i],
131 dict_bf_newp (dict_to->dbf, map[i], &new_p, map[i+1] - map[i]);
133 DICT_type(new_p) = 0;
134 DICT_backptr(new_p) = map[i-1];
135 DICT_bsize(new_p) = map[i+1] - map[i];
137 dict_copy_page(dict_from, (char*) new_p, (char*) old_p, map);
139 dict_close (dict_from);
140 dict_close (dict_to);