source: trunk/gsdl/packages/mg-1.3d/src/text/mg_fast_comp_dict.c@ 30

Last change on this file since 30 was 13, checked in by rjmcnab, 26 years ago

* empty log message *

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 19.7 KB
Line 
1/**************************************************************************
2 *
3 * mg_fast_comp_dict.c -- Program to generate a fast compression dictionary
4 * Copyright (C) 1994 Neil Sharman
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 * $Id: mg_fast_comp_dict.c 13 1998-11-17 09:36:00Z rjmcnab $
21 *
22 **************************************************************************/
23
24
25/*
26 $Log$
27 Revision 1.1 1998/11/17 09:34:57 rjmcnab
28 *** empty log message ***
29
30 * Revision 1.3 1994/10/20 03:56:55 tes
31 * I have rewritten the boolean query optimiser and abstracted out the
32 * components of the boolean query.
33 *
34 * Revision 1.2 1994/09/20 04:41:47 tes
35 * For version 1.1
36 *
37 */
38
39static char *RCSID = "$Id: mg_fast_comp_dict.c 13 1998-11-17 09:36:00Z rjmcnab $";
40
41#include "sysfuncs.h"
42
43#include "filestats.h"
44#include "huffman.h"
45#include "timing.h"
46#include "messages.h"
47#include "memlib.h"
48#include "netorder.h" /* [RPAP - Jan 97: Endian Ordering] */
49
50#include "local_strings.h"
51#include "mg.h"
52#include "text.h"
53#include "invf.h"
54#include "lists.h"
55#include "backend.h"
56#include "mg_files.h"
57#include "locallib.h"
58#include "words.h"
59
60
61
62#define ALIGN_SIZE(p,t) (((p) + (sizeof(t)-1)) & (~(sizeof(t)-1)))
63
64#define WORDNO(p, base) ((((char*)(p))-((char*)(base)))/sizeof(u_char*))
65#define FIXUP(p) (fixup[WORDNO(p,buffer)/8] |= (1<<(WORDNO(p, buffer) & 7)))
66
67#define IS_FIXUP(p) ((fixup[WORDNO(p,buffer)/8] & (1<<(WORDNO(p, buffer) & 7))) != 0)
68
69#define FIXUP_VALS(vals) do { \
70 int i; \
71 for (i=0; i < MAX_HUFFCODE_LEN+1; i++) \
72 FIXUP(&vals[i]); \
73 } while(0)
74
75
76
77static u_long mem_for_comp_dict (char *filename);
78static void load_comp_dict (char *filename);
79static void save_fast_dict (char *filename);
80static void unfixup_buffer (void);
81
82
83static void *buffer;
84static void *cur;
85static u_char *fixup;
86static u_long mem, fixup_mem;
87
88void
89main (int argc, char **argv)
90{
91 ProgTime StartTime;
92 int ch;
93 char *filename = "";
94 opterr = 0;
95 msg_prefix = argv[0];
96 while ((ch = getopt (argc, argv, "f:d:h")) != -1)
97 switch (ch)
98 {
99 case 'f': /* input file */
100 filename = optarg;
101 break;
102 case 'd':
103 set_basepath (optarg);
104 break;
105 case 'h':
106 case '?':
107 fprintf (stderr, "usage: %s [-f input_file] [-d data directory] [-h]\n",
108 argv[0]);
109 exit (1);
110 }
111 GetTime (&StartTime);
112
113 mem = mem_for_comp_dict (filename);
114
115 fixup_mem = (ALIGN_SIZE (mem, u_char *) / sizeof (u_char *) + 7) / 8;
116
117 cur = buffer = Xmalloc (mem);
118 bzero (buffer, mem);
119 fixup = Xmalloc (fixup_mem);
120 bzero (fixup, fixup_mem);
121
122 Message ("Estimated memory for fast_dict %u", mem);
123 Message ("Estimated memory for fixups %u", fixup_mem);
124
125 load_comp_dict (filename);
126
127 Message ("Actual memory for fast_dict %u", (char *) cur - (char *) buffer);
128
129 if ((u_long) cur > (u_long) buffer + mem)
130 FatalError (1, "The buffer was not big enough for the dictionary");
131
132 {
133 /* [RPAP - Jan 97: Endian Ordering] */
134 compression_dict *cd = (compression_dict *) buffer;
135 int i, which;
136
137 /* cfh */
138 for (which = 0; which <= 1; which++)
139 {
140 int j;
141
142 HTONSI(cd->cfh[which]->hd.num_codes);
143 HTONSI(cd->cfh[which]->hd.mincodelen);
144 HTONSI(cd->cfh[which]->hd.maxcodelen);
145 for (j = 0; j < MAX_HUFFCODE_LEN + 1; j++)
146 {
147 HTONSI(cd->cfh[which]->hd.lencount[j]);
148 HTONUL(cd->cfh[which]->hd.min_code[j]);
149 }
150 HTONUL(cd->cfh[which]->uncompressed_size);
151 for (j = 0; j < MAX_HUFFCODE_LEN + 1; j++)
152 HTONUL(cd->cfh[which]->huff_words_size[j]);
153 }
154 HTONUL(cd->MemForCompDict);
155 /* ad */
156 if (cd->cdh.novel_method == MG_NOVEL_BINARY ||
157 cd->cdh.novel_method == MG_NOVEL_DELTA ||
158 cd->cdh.novel_method == MG_NOVEL_HYBRID ||
159 cd->cdh.novel_method == MG_NOVEL_HYBRID_MTF)
160 for (which = 0; which <= 1; which++)
161 {
162 int j;
163
164 HTONUL(cd->ad->afh[which].num_frags);
165 HTONUL(cd->ad->afh[which].mem_for_frags);
166 for (j = 0; j < 33; j++)
167 {
168 HTONSI(cd->ad->blk_start[which][j]);
169 HTONSI(cd->ad->blk_end[which][j]);
170 }
171 }
172 /* cdh */
173 HTONUL(cd->cdh.dict_type);
174 HTONUL(cd->cdh.novel_method);
175 for (i = 0; i < TEXT_PARAMS; i++)
176 HTONUL(cd->cdh.params[which]);
177 HTONUL(cd->cdh.num_words[0]);
178 HTONUL(cd->cdh.num_words[1]);
179 HTONUL(cd->cdh.num_word_chars[0]);
180 HTONUL(cd->cdh.num_word_chars[1]);
181 HTONUL(cd->cdh.lookback);
182 HTONSI(cd->fast_loaded);
183 }
184
185 unfixup_buffer ();
186
187 save_fast_dict (filename);
188
189 Message ("%s", ElapsedTime (&StartTime, NULL));
190 exit (0);
191}
192
193
194
195static void
196unfixup_buffer ()
197{
198 u_long *p;
199 for (p = buffer; (u_long) p < (u_long) cur; p++)
200 {
201 if (IS_FIXUP (p))
202 *p = *p - (u_long) buffer;
203 }
204}
205
206
207
208
209static u_long
210mem_for_aux_dict (compression_dict_header * cdh, char *filename)
211{
212 int i;
213 u_long mem = sizeof (auxiliary_dict);
214 FILE *aux;
215
216 aux = open_file (filename, TEXT_DICT_AUX_SUFFIX, "rb",
217 MAGIC_AUX_DICT, MG_ABORT); /* [RPAP - Feb 97: WIN32 Port] */
218
219 for (i = 0; i <= 1; i++)
220 {
221 aux_frags_header afh;
222 fread (&afh, sizeof (afh), 1, aux);
223 NTOHUL(afh.num_frags); /* [RPAP - Jan 97: Endian Ordering] */
224 NTOHUL(afh.mem_for_frags); /* [RPAP - Jan 97: Endian Ordering] */
225 mem += afh.num_frags * sizeof (u_char *);
226 mem = ALIGN_SIZE (mem + afh.mem_for_frags, u_char *);
227 fseek (aux, afh.mem_for_frags, SEEK_CUR);
228 }
229 fclose (aux);
230
231 return mem;
232}
233
234
235
236static u_long
237mem_for_words (FILE * dict, compression_dict_header * cdh,
238 comp_frags_header * cfh)
239{
240 u_long mem = 0;
241 u_long i, lookback;
242 int ptrs_reqd = 0;
243 int mem_reqd = 0;
244
245 lookback = cdh->lookback;
246
247 for (i = cfh->hd.mincodelen; i <= cfh->hd.maxcodelen; i++)
248 {
249 ptrs_reqd += (cfh->hd.lencount[i] + ((1 << lookback) - 1)) >> lookback;
250 mem_reqd += cfh->huff_words_size[i];
251 }
252
253 mem += ptrs_reqd * sizeof (u_char *);
254 mem += (MAX_HUFFCODE_LEN + 1) * sizeof (u_char **);
255 mem += mem_reqd;
256
257 for (i = 0; i < cfh->hd.num_codes; i++)
258 {
259 register int val;
260 for (val = getc (dict) & 0xf; val; val--)
261 getc (dict);
262 }
263 return ALIGN_SIZE (mem, u_char *);
264}
265
266
267
268
269static u_long
270mem_for_comp_dict (char *filename)
271{
272 u_long mem = sizeof (compression_dict);
273 compression_dict_header cdh;
274 comp_frags_header cfh;
275 FILE *dict;
276 int which;
277 int i; /* [RPAP - Jan 97: Endian Ordering] */
278
279 dict = open_file (filename, TEXT_DICT_SUFFIX, "rb",
280 MAGIC_DICT, MG_ABORT); /* [RPAP - Feb 97: WIN32 Port] */
281
282 fread (&cdh, sizeof (cdh), 1, dict);
283 /* [RPAP - Jan 97: Endian Ordering] */
284 NTOHUL(cdh.dict_type);
285 NTOHUL(cdh.novel_method);
286 for (i = 0; i < TEXT_PARAMS; i++)
287 NTOHUL(cdh.params[i]);
288 NTOHUL(cdh.num_words[0]);
289 NTOHUL(cdh.num_words[1]);
290 NTOHUL(cdh.num_word_chars[0]);
291 NTOHUL(cdh.num_word_chars[1]);
292 NTOHUL(cdh.lookback);
293
294 for (which = 0; which < 2; which++)
295 switch (cdh.dict_type)
296 {
297 case MG_COMPLETE_DICTIONARY:
298 {
299 mem += sizeof (comp_frags_header);
300 Read_cfh (dict, &cfh, NULL, NULL);
301
302 /* Don't need to count the space for the clens of the huffman data */
303
304 mem += mem_for_words (dict, &cdh, &cfh);
305 if (cfh.hd.clens)
306 Xfree (cfh.hd.clens);
307 }
308 break;
309 case MG_PARTIAL_DICTIONARY:
310 {
311 huff_data hd;
312 if (cdh.num_words[which])
313 {
314 mem += sizeof (comp_frags_header);
315 Read_cfh (dict, &cfh, NULL, NULL);
316
317 /* Don't need to count the space for the clens of the
318 huffman data */
319
320 mem += mem_for_words (dict, &cdh, &cfh);
321 if (cfh.hd.clens)
322 Xfree (cfh.hd.clens);
323
324 }
325
326 mem += sizeof (hd);
327 Read_Huffman_Data (dict, &hd, NULL, NULL);
328 if (hd.clens)
329 Xfree (hd.clens);
330 mem += hd.num_codes * sizeof (unsigned long);
331 mem += (MAX_HUFFCODE_LEN + 1) * sizeof (unsigned long *);
332
333 mem += sizeof (hd);
334 Read_Huffman_Data (dict, &hd, NULL, NULL);
335 if (hd.clens)
336 Xfree (hd.clens);
337 mem += hd.num_codes * sizeof (unsigned long);
338 mem += (MAX_HUFFCODE_LEN + 1) * sizeof (unsigned long *);
339 }
340 break;
341 case MG_SEED_DICTIONARY:
342 {
343 huff_data hd;
344 if (cdh.num_words[which])
345 {
346 mem += sizeof (comp_frags_header);
347 Read_cfh (dict, &cfh, NULL, NULL);
348
349 /* Don't need to count the space for the clens of the
350 huffman data */
351
352 mem += mem_for_words (dict, &cdh, &cfh);
353 if (cfh.hd.clens)
354 Xfree (cfh.hd.clens);
355
356 }
357 switch (cdh.novel_method)
358 {
359 case MG_NOVEL_HUFFMAN_CHARS:
360 mem += sizeof (hd);
361 Read_Huffman_Data (dict, &hd, NULL, NULL);
362 if (hd.clens)
363 Xfree (hd.clens);
364 mem += hd.num_codes * sizeof (unsigned long);
365 mem += (MAX_HUFFCODE_LEN + 1) * sizeof (unsigned long *);
366
367 mem += sizeof (hd);
368 Read_Huffman_Data (dict, &hd, NULL, NULL);
369 if (hd.clens)
370 Xfree (hd.clens);
371 mem += hd.num_codes * sizeof (unsigned long);
372 mem += (MAX_HUFFCODE_LEN + 1) * sizeof (unsigned long *);
373 break;
374 case MG_NOVEL_BINARY:
375 break;
376 case MG_NOVEL_DELTA:
377 break;
378 case MG_NOVEL_HYBRID:
379 break;
380 case MG_NOVEL_HYBRID_MTF:
381 break;
382 }
383 break;
384 }
385 }
386 fclose (dict);
387
388 if (cdh.novel_method == MG_NOVEL_BINARY ||
389 cdh.novel_method == MG_NOVEL_DELTA ||
390 cdh.novel_method == MG_NOVEL_HYBRID ||
391 cdh.novel_method == MG_NOVEL_HYBRID_MTF)
392 mem += mem_for_aux_dict (&cdh, filename);
393
394 return ALIGN_SIZE (mem, u_char *);
395}
396
397
398
399void *
400getmem (u_long size, int align)
401{
402 void *res;
403 cur = (void *) (((u_long) cur + (align - 1)) & (~(align - 1)));
404 res = cur;
405 cur = (char *) cur + size;
406 if ((long) cur > (long) buffer + mem)
407 FatalError (1, "The buffer was not big enough for the dictionary");
408 return res;
409}
410
411
412
413
414
415
416
417
418
419
420
421static auxiliary_dict *
422LoadAuxDict (compression_dict_header * cdh,
423 char *filename)
424{
425 auxiliary_dict *ad;
426 int i;
427 FILE *aux;
428
429 aux = open_file (filename, TEXT_DICT_AUX_SUFFIX, "rb",
430 MAGIC_AUX_DICT, MG_ABORT); /* [RPAP - Feb 97: WIN32 Port] */
431
432 ad = getmem (sizeof (auxiliary_dict), sizeof (u_char *));
433
434 for (i = 0; i <= 1; i++)
435 {
436 int j;
437 u_char *pos;
438
439 fread (&ad->afh[i], sizeof (aux_frags_header), 1, aux);
440
441 /* [RPAP - Jan 97: Endian Ordering] */
442 NTOHUL(ad->afh[i].num_frags);
443 NTOHUL(ad->afh[i].mem_for_frags);
444
445 ad->word_data[i] = getmem (ad->afh[i].mem_for_frags, 1);
446 FIXUP (&ad->word_data[i]);
447
448 ad->words[i] = getmem (ad->afh[i].num_frags * sizeof (u_char *),
449 sizeof (u_char *));
450 FIXUP (&ad->words[i]);
451
452 fread (ad->word_data[i], ad->afh[i].mem_for_frags, sizeof (u_char), aux);
453
454 pos = ad->word_data[i];
455 for (j = 0; j < ad->afh[i].num_frags; j++)
456 {
457 ad->words[i][j] = pos;
458 FIXUP (&ad->words[i][j]);
459 pos += *pos + 1;
460 }
461 if (cdh->novel_method == MG_NOVEL_HYBRID ||
462 cdh->novel_method == MG_NOVEL_HYBRID_MTF)
463 {
464 int num;
465 num = 1;
466 ad->blk_start[i][0] = 0;
467 ad->blk_end[i][0] = cdh->num_words[i] - 1;
468 while (num < 33)
469 {
470 ad->blk_start[i][num] = ad->blk_end[i][num - 1] + 1;
471 ad->blk_end[i][num] = ad->blk_start[i][num] +
472 (ad->blk_end[i][num - 1] - ad->blk_start[i][num - 1]) * 2;
473 num++;
474 }
475 }
476 }
477 fclose (aux);
478 return (ad);
479}
480
481
482
483
484
485static u_char ***
486ReadInWords (FILE * dict, compression_dict * cd,
487 comp_frags_header * cfh, u_char ** escape)
488{
489 int i, lookback;
490 int ptrs_reqd = 0;
491 int mem_reqd = 0;
492 int num_set[MAX_HUFFCODE_LEN + 1];
493 u_char *next_word[MAX_HUFFCODE_LEN + 1];
494 u_char **vals;
495 u_char ***values;
496 u_char word[MAXWORDLEN + 1];
497 u_char last_word[MAX_HUFFCODE_LEN + 1][MAXWORDLEN + 1];
498
499 lookback = cd->cdh.lookback;
500
501 for (i = cfh->hd.mincodelen; i <= cfh->hd.maxcodelen; i++)
502 {
503 ptrs_reqd += (cfh->hd.lencount[i] + ((1 << lookback) - 1)) >> lookback;
504 mem_reqd += cfh->huff_words_size[i];
505 }
506
507 vals = getmem (ptrs_reqd * sizeof (*vals), sizeof (u_char *));
508
509 values = getmem ((MAX_HUFFCODE_LEN + 1) * sizeof (u_char **), sizeof (u_char **));
510
511 next_word[0] = getmem (mem_reqd, sizeof (char));
512
513 cd->MemForCompDict += ptrs_reqd * sizeof (*vals) +
514 (MAX_HUFFCODE_LEN + 1) * sizeof (u_char **) +
515 mem_reqd;
516
517 values[0] = vals;
518 FIXUP (&values[0]);
519 values[0][0] = next_word[0];
520 FIXUP (&values[0][0]);
521 for (i = 1; i <= cfh->hd.maxcodelen; i++)
522 {
523 int next_start = (values[i - 1] - vals) +
524 ((cfh->hd.lencount[i - 1] + ((1 << lookback) - 1)) >> lookback);
525 values[i] = &vals[next_start];
526 FIXUP (&values[i]);
527 next_word[i] = next_word[i - 1] + cfh->huff_words_size[i - 1];
528 values[i][0] = next_word[i];
529 FIXUP (&values[i][0]);
530 }
531
532 bzero ((char *) num_set, sizeof (num_set));
533
534 for (i = 0; i < cfh->hd.num_codes; i++)
535 {
536 register int val, copy;
537 register int len = cfh->hd.clens[i];
538 val = getc (dict);
539 copy = (val >> 4) & 0xf;
540 val &= 0xf;
541
542 fread (word + copy + 1, sizeof (u_char), val, dict);
543 *word = val + copy;
544
545 if ((num_set[len] & ((1 << lookback) - 1)) == 0)
546 {
547 values[len][num_set[len] >> lookback] = next_word[len];
548 FIXUP (&values[len][num_set[len] >> lookback]);
549 memcpy (next_word[len], word, *word + 1);
550 if (escape && i == cfh->hd.num_codes - 1)
551 {
552 *escape = next_word[len];
553 FIXUP (escape);
554 }
555 next_word[len] += *word + 1;
556 }
557 else
558 {
559 copy = prefixlen (last_word[len], word);
560 memcpy (next_word[len] + 1, word + copy + 1, *word - copy);
561 *next_word[len] = (copy << 4) + (*word - copy);
562 if (escape && i == cfh->hd.num_codes - 1)
563 {
564 *escape = next_word[len];
565 FIXUP (escape);
566 }
567 next_word[len] += (*word - copy) + 1;
568 }
569 memcpy (last_word[len], word, *word + 1);
570 num_set[len]++;
571 }
572 if (cfh->hd.clens)
573 Xfree (cfh->hd.clens);
574 cfh->hd.clens = NULL;
575 return values;
576}
577
578
579static unsigned long **
580Generate_Fast_Huffman_Vals (huff_data * data, u_long * mem)
581{
582 int i;
583 unsigned long *fcode[MAX_HUFFCODE_LEN + 1];
584 unsigned long **values;
585 unsigned long *vals;
586
587 if (!data)
588 return (NULL);
589 vals = getmem (data->num_codes * sizeof (*vals), sizeof (long *));
590 values = getmem ((MAX_HUFFCODE_LEN + 1) * sizeof (unsigned long *),
591 sizeof (long *));
592
593 bzero ((char *) values, (MAX_HUFFCODE_LEN + 1) * sizeof (unsigned long *));
594
595 if (mem)
596 *mem += data->num_codes * sizeof (*vals) +
597 (MAX_HUFFCODE_LEN + 1) * sizeof (unsigned long *);
598
599 fcode[0] = values[0] = &vals[0];
600 FIXUP (&values[0]);
601 for (i = 1; i <= data->maxcodelen; i++)
602 {
603 fcode[i] = values[i] = &vals[(values[i - 1] - vals) + data->lencount[i - 1]];
604 FIXUP (&values[i]);
605 }
606
607 for (i = 0; i < data->num_codes; i++)
608 if (data->clens[i])
609 *fcode[(int) (data->clens[i])]++ = i;
610 return (values);
611}
612
613
614
615static void
616load_comp_dict (char *filename)
617{
618 FILE *dict;
619 int which;
620 compression_dict *cd;
621
622 cd = getmem (sizeof (compression_dict), sizeof (u_char *));
623 cd->fast_loaded = 1;
624
625 dict = open_file (filename, TEXT_DICT_SUFFIX, "rb",
626 MAGIC_DICT, MG_ABORT); /* [RPAP - Feb 97: WIN32 Port] */
627
628 Read_cdh (dict, &cd->cdh, NULL, NULL);
629
630 for (which = 0; which < 2; which++)
631 switch (cd->cdh.dict_type)
632 {
633 case MG_COMPLETE_DICTIONARY:
634 {
635 cd->cfh[which] = getmem (sizeof (*cd->cfh[which]), sizeof (u_char *));
636 cd->MemForCompDict += sizeof (*cd->cfh[which]);
637 Read_cfh (dict, cd->cfh[which], &cd->MemForCompDict, NULL);
638
639 cd->values[which] = ReadInWords (dict, cd, cd->cfh[which], NULL);
640 FIXUP (&cd->cfh[which]);
641 FIXUP (&cd->values[which]);
642 cd->escape[which] = NULL;
643 }
644 break;
645 case MG_PARTIAL_DICTIONARY:
646 {
647 huff_data *hd;
648 u_long **vals;
649 if (cd->cdh.num_words[which])
650 {
651 cd->cfh[which] = getmem (sizeof (*cd->cfh[which]), sizeof (u_char *));
652 cd->MemForCompDict += sizeof (*cd->cfh[which]);
653 Read_cfh (dict, cd->cfh[which], &cd->MemForCompDict, NULL);
654 cd->values[which] = ReadInWords (dict, cd, cd->cfh[which],
655 &cd->escape[which]);
656 FIXUP (&cd->cfh[which]);
657 FIXUP (&cd->values[which]);
658 FIXUP (&cd->escape[which]);
659 }
660
661 hd = getmem (sizeof (huff_data), sizeof (char *));
662 cd->MemForCompDict += sizeof (huff_data);
663 Read_Huffman_Data (dict, hd, &cd->MemForCompDict, NULL);
664 vals = Generate_Fast_Huffman_Vals (hd, &cd->MemForCompDict);
665 cd->chars_huff[which] = hd;
666 FIXUP (&cd->chars_huff[which]);
667 cd->chars_vals[which] = vals;
668 FIXUP (&cd->chars_vals[which]);
669 if (hd->clens)
670 Xfree (hd->clens);
671 hd->clens = NULL;
672
673 hd = getmem (sizeof (huff_data), sizeof (char *));
674 cd->MemForCompDict += sizeof (huff_data);
675 Read_Huffman_Data (dict, hd, &cd->MemForCompDict, NULL);
676 vals = Generate_Fast_Huffman_Vals (hd, &cd->MemForCompDict);
677 cd->lens_huff[which] = hd;
678 FIXUP (&cd->lens_huff[which]);
679 cd->lens_vals[which] = vals;
680 FIXUP (&cd->lens_vals[which]);
681 if (hd->clens)
682 Xfree (hd->clens);
683 hd->clens = NULL;
684 }
685 break;
686 case MG_SEED_DICTIONARY:
687 {
688 huff_data *hd;
689 u_long **vals;
690 if (cd->cdh.num_words[which])
691 {
692 cd->cfh[which] = getmem (sizeof (*cd->cfh[which]), sizeof (u_char *));
693 cd->MemForCompDict += sizeof (*cd->cfh[which]);
694 Read_cfh (dict, cd->cfh[which], &cd->MemForCompDict, NULL);
695 cd->values[which] = ReadInWords (dict, cd, cd->cfh[which],
696 &cd->escape[which]);
697 FIXUP (&cd->cfh[which]);
698 FIXUP (&cd->values[which]);
699 FIXUP (&cd->escape[which]);
700 }
701 switch (cd->cdh.novel_method)
702 {
703 case MG_NOVEL_HUFFMAN_CHARS:
704 hd = getmem (sizeof (huff_data), sizeof (char *));
705 cd->MemForCompDict += sizeof (huff_data);
706 Read_Huffman_Data (dict, hd, &cd->MemForCompDict, NULL);
707 vals = Generate_Fast_Huffman_Vals (hd, &cd->MemForCompDict);
708 cd->chars_huff[which] = hd;
709 FIXUP (&cd->chars_huff[which]);
710 cd->chars_vals[which] = vals;
711 FIXUP (&cd->chars_vals[which]);
712 if (hd->clens)
713 Xfree (hd->clens);
714 hd->clens = NULL;
715
716 hd = getmem (sizeof (huff_data), sizeof (char *));
717 cd->MemForCompDict += sizeof (huff_data);
718 Read_Huffman_Data (dict, hd, &cd->MemForCompDict, NULL);
719 vals = Generate_Fast_Huffman_Vals (hd, &cd->MemForCompDict);
720 cd->lens_huff[which] = hd;
721 FIXUP (&cd->lens_huff[which]);
722 cd->lens_vals[which] = vals;
723 FIXUP (&cd->lens_vals[which]);
724 if (hd->clens)
725 Xfree (hd->clens);
726 hd->clens = NULL;
727 break;
728 case MG_NOVEL_BINARY:
729 break;
730 case MG_NOVEL_DELTA:
731 break;
732 case MG_NOVEL_HYBRID:
733 break;
734 case MG_NOVEL_HYBRID_MTF:
735 break;
736 }
737 break;
738 }
739 }
740 fclose (dict);
741
742
743 if (cd->cdh.novel_method == MG_NOVEL_BINARY ||
744 cd->cdh.novel_method == MG_NOVEL_DELTA ||
745 cd->cdh.novel_method == MG_NOVEL_HYBRID ||
746 cd->cdh.novel_method == MG_NOVEL_HYBRID_MTF)
747 {
748 cd->ad = LoadAuxDict (&cd->cdh, filename);
749 FIXUP (&cd->ad);
750 }
751}
752
753
754static void
755save_fast_dict (char *filename)
756{
757 FILE *fdict;
758
759 fdict = create_file (filename, TEXT_DICT_FAST_SUFFIX, "wb",
760 MAGIC_FAST_DICT, MG_ABORT); /* [RPAP - Feb 97: WIN32 Port] */
761
762 {
763 u_long *p;
764 for (p = buffer; (u_long) p < (u_long) cur; p++)
765 {
766 if (IS_FIXUP (p))
767 HTONUL(*p);
768 }
769 }
770
771 /* [RPAP - Jan 97: Endian Ordering] */
772 HTONUL(mem);
773 HTONUL(fixup_mem);
774
775 fwrite (&mem, sizeof (mem), 1, fdict);
776 fwrite (&fixup_mem, sizeof (fixup_mem), 1, fdict);
777
778 /* [RPAP - Jan 97: Endian Ordering] */
779 NTOHUL(mem);
780 NTOHUL(fixup_mem);
781
782 fwrite (buffer, sizeof (u_char), mem, fdict);
783 fwrite (fixup, sizeof (u_char), fixup_mem, fdict);
784
785 fclose (fdict);
786}
Note: See TracBrowser for help on using the repository browser.