1 /* Catacomb Armageddon Source Code
\r
2 * Copyright (C) 1993-2014 Flat Rock Software
\r
4 * This program is free software; you can redistribute it and/or modify
\r
5 * it under the terms of the GNU General Public License as published by
\r
6 * the Free Software Foundation; either version 2 of the License, or
\r
7 * (at your option) any later version.
\r
9 * This program is distributed in the hope that it will be useful,
\r
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
12 * GNU General Public License for more details.
\r
14 * You should have received a copy of the GNU General Public License along
\r
15 * with this program; if not, write to the Free Software Foundation, Inc.,
\r
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\r
19 //===========================================================================
\r
21 // LZHUFF COMPRESSION ROUTINES
\r
24 // Compression algrythim by Haruhiko OKUMURA
\r
25 // Implementation by Jim T. Row
\r
28 // Copyright (c) 1992 - Softdisk Publishing inc. - All rights reserved
\r
30 //===========================================================================
\r
32 // Compiler #ifdef switches
\r
34 // LZHUFF_COMPRESSION & LZHUFF_DECOMPRESSION - not yet functional!
\r
36 // Usage Explanition :
\r
38 // if LZHUFF_COMPRESSION is defined then the compression code & data is
\r
39 // compiled and so-forth for the decompression code.
\r
41 //---------------------------------------------------------------------------
\r
59 //===========================================================================
\r
63 // NOTE : Make sure the appropriate switches are set in SOFT.c for Softlib
\r
66 //===========================================================================
\r
69 #define INCLUDE_LZH_COMP 0
\r
70 #define INCLUDE_LZH_DECOMP 1
\r
76 //===========================================================================
\r
80 //===========================================================================
\r
84 #define EXIT_FAILED -1
\r
86 /* LZSS Parameters */
\r
88 #define N 4096 /* Size of string buffer */
\r
89 #define F 30 /* Size of look-ahead buffer */
\r
91 #define NIL N /* End of tree's node */
\r
93 /* Huffman coding parameters */
\r
95 #define N_CHAR (256 - THRESHOLD + F) /* character code (= 0..N_CHAR-1) */
\r
96 #define T (N_CHAR * 2 - 1) /* Size of table */
\r
97 #define R (T - 1) /* root position */
\r
98 #define MAX_FREQ 0x8000 /* update when cumulative frequency */
\r
99 /* reaches to this value */
\r
102 //==========================================================================
\r
104 // LOCAL PROTOTYPES
\r
106 //==========================================================================
\r
109 static void StartHuff();
\r
110 static void reconst();
\r
111 static void update(int c);
\r
114 static void DeleteNode(int p); /* Deleting node from the tree */
\r
115 static void InsertNode(int r); /* Inserting node to the tree */
\r
116 static void InitTree(void); /* Initializing tree */
\r
117 static void Putcode(long outfile_ptr, int l, unsigned c,unsigned PtrTypes); /* output c bits */
\r
118 static void EncodeChar(long outfile_ptr, unsigned c, unsigned PtrTypes);
\r
119 static void EncodePosition(long outfile_ptr, unsigned c, unsigned PtrTypes);
\r
120 static void EncodeEnd(long outfile_ptr,unsigned PtrTypes);
\r
123 static int GetByte(long infile_ptr, unsigned long *CompressLength, unsigned PtrTypes);
\r
124 static int GetBit(long infile_ptr, unsigned long *CompressLength, unsigned PtrTypes); /* get one bit */
\r
125 static int DecodeChar(long infile_ptr, unsigned long *CompressLength, unsigned PtrTypes);
\r
126 static int DecodePosition(long infile_ptr,unsigned long *CompressLength, unsigned PtrTypes);
\r
131 //==========================================================================
\r
133 // USER AVAILABLE VECTORS
\r
135 //==========================================================================
\r
140 //---------------------------------------------------------------------------
\r
142 // LZHUFF DISPLAY VECTORS
\r
144 // These vectors allow you to hook up any form of display you desire for
\r
145 // displaying the compression/decompression status.
\r
147 // These routines are called inside of the compression/decompression routines
\r
148 // and pass the orginal size of data and current position within that
\r
149 // data. This allows for any kind of "% Done" messages.
\r
151 // Your functions MUST have the following parameters in this order...
\r
153 // void VectorRoutine(unsigned long OrginalSize,unsigned long CurPosition)
\r
157 #if INCLUDE_LZH_COMP
\r
158 void (*LZH_CompressDisplayVector)() = NULL;
\r
161 #if INCLUDE_LZH_DECOMP
\r
162 void (*LZH_DecompressDisplayVector)() = NULL;
\r
168 //===========================================================================
\r
170 // GLOBAL VARIABLES
\r
172 //===========================================================================
\r
173 /* pointing children nodes (son[], son[] + 1)*/
\r
176 unsigned code, len;
\r
179 // pointing parent nodes.
\r
180 // area [T..(T + N_CHAR - 1)] are pointers for leaves
\r
183 int far prnt[T + N_CHAR];
\r
185 unsigned far freq[T + 1]; /* cumulative freq table */
\r
187 unsigned long textsize = 0, codesize = 0, printcount = 0,datasize;
\r
188 unsigned char far text_buf[N + F - 1];
\r
193 // COMPRESSION VARIABLES
\r
196 #if INCLUDE_LZH_COMP
\r
198 static int match_position,match_length, lson[N + 1], rson[N + 257], dad[N + 1];
\r
199 unsigned putbuf = 0;
\r
200 unsigned char putlen = 0;
\r
203 // Tables for encoding/decoding upper 6 bits of
\r
204 // sliding dictionary pointer
\r
211 unsigned char far p_len[64] = {
\r
212 0x03, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x05,
\r
213 0x05, 0x05, 0x05, 0x05, 0x06, 0x06, 0x06, 0x06,
\r
214 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
\r
215 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
\r
216 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
\r
217 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
\r
218 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
\r
219 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08
\r
222 unsigned char far p_code[64] = {
\r
223 0x00, 0x20, 0x30, 0x40, 0x50, 0x58, 0x60, 0x68,
\r
224 0x70, 0x78, 0x80, 0x88, 0x90, 0x94, 0x98, 0x9C,
\r
225 0xA0, 0xA4, 0xA8, 0xAC, 0xB0, 0xB4, 0xB8, 0xBC,
\r
226 0xC0, 0xC2, 0xC4, 0xC6, 0xC8, 0xCA, 0xCC, 0xCE,
\r
227 0xD0, 0xD2, 0xD4, 0xD6, 0xD8, 0xDA, 0xDC, 0xDE,
\r
228 0xE0, 0xE2, 0xE4, 0xE6, 0xE8, 0xEA, 0xEC, 0xEE,
\r
229 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
\r
230 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF
\r
236 // DECOMPRESSION VARIABLES
\r
244 #if INCLUDE_LZH_DECOMP
\r
246 unsigned char far d_code[256] = {
\r
247 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
\r
248 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
\r
249 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
\r
250 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
\r
251 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
\r
252 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
\r
253 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
\r
254 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
\r
255 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
\r
256 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
\r
257 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
\r
258 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
\r
259 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
\r
260 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
\r
261 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
\r
262 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,
\r
263 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A,
\r
264 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B,
\r
265 0x0C, 0x0C, 0x0C, 0x0C, 0x0D, 0x0D, 0x0D, 0x0D,
\r
266 0x0E, 0x0E, 0x0E, 0x0E, 0x0F, 0x0F, 0x0F, 0x0F,
\r
267 0x10, 0x10, 0x10, 0x10, 0x11, 0x11, 0x11, 0x11,
\r
268 0x12, 0x12, 0x12, 0x12, 0x13, 0x13, 0x13, 0x13,
\r
269 0x14, 0x14, 0x14, 0x14, 0x15, 0x15, 0x15, 0x15,
\r
270 0x16, 0x16, 0x16, 0x16, 0x17, 0x17, 0x17, 0x17,
\r
271 0x18, 0x18, 0x19, 0x19, 0x1A, 0x1A, 0x1B, 0x1B,
\r
272 0x1C, 0x1C, 0x1D, 0x1D, 0x1E, 0x1E, 0x1F, 0x1F,
\r
273 0x20, 0x20, 0x21, 0x21, 0x22, 0x22, 0x23, 0x23,
\r
274 0x24, 0x24, 0x25, 0x25, 0x26, 0x26, 0x27, 0x27,
\r
275 0x28, 0x28, 0x29, 0x29, 0x2A, 0x2A, 0x2B, 0x2B,
\r
276 0x2C, 0x2C, 0x2D, 0x2D, 0x2E, 0x2E, 0x2F, 0x2F,
\r
277 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
\r
278 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
\r
281 unsigned char far d_len[256] = {
\r
282 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
\r
283 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
\r
284 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
\r
285 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
\r
286 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
\r
287 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
\r
288 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
\r
289 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
\r
290 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
\r
291 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
\r
292 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
\r
293 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
\r
294 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
\r
295 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
\r
296 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
\r
297 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
\r
298 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
\r
299 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
\r
300 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
\r
301 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
\r
302 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
\r
303 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
\r
304 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
\r
305 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
\r
306 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
\r
307 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
\r
308 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
\r
309 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
\r
310 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
\r
311 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
\r
312 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
\r
313 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
\r
316 unsigned getbuf = 0;
\r
317 unsigned char getlen = 0;
\r
323 //===========================================================================
\r
325 // COMPRESSION & DECOMPRESSION ROUTINES
\r
327 //===========================================================================
\r
335 //---------------------------------------------------------------------------
\r
336 // StartHuff /* initialize freq tree */
\r
337 //---------------------------------------------------------------------------
\r
338 static void StartHuff()
\r
342 for (i = 0; i < N_CHAR; i++) {
\r
349 freq[j] = freq[i] + freq[i + 1];
\r
351 prnt[i] = prnt[i + 1] = j;
\r
363 //---------------------------------------------------------------------------
\r
364 // reconst /* reconstruct freq tree */
\r
365 //---------------------------------------------------------------------------
\r
366 static void reconst()
\r
371 /* halven cumulative freq for leaf nodes */
\r
375 for (i = 0; i < T; i++)
\r
379 freq[j] = (freq[i] + 1) / 2;
\r
385 /* make a tree : first, connect children nodes */
\r
387 for (i = 0, j = N_CHAR; j < T; i += 2, j++)
\r
390 f = freq[j] = freq[i] + freq[k];
\r
392 for (k = j - 1;f < freq[k]; k--);
\r
397 (void)memmove(&freq[k + 1], &freq[k], l);
\r
400 (void)memmove(&son[k + 1], &son[k], l);
\r
404 /* connect parent nodes */
\r
406 for (i = 0; i < T; i++)
\r
408 if ((k = son[i]) >= T)
\r
414 prnt[k] = prnt[k + 1] = i;
\r
424 //---------------------------------------------------------------------------
\r
425 // update() update freq tree
\r
426 //---------------------------------------------------------------------------
\r
427 static void update(int c)
\r
431 if (freq[R] == MAX_FREQ)
\r
442 // swap nodes to keep the tree freq-ordered
\r
445 if (k > freq[l = c + 1])
\r
447 while (k > freq[++l]);
\r
469 } while ((c = prnt[c]) != 0); /* do it until reaching the root */
\r
475 //===========================================================================
\r
477 // COMPRESSION ROUTINES
\r
479 //===========================================================================
\r
486 #if INCLUDE_LZH_COMP
\r
489 //---------------------------------------------------------------------------
\r
491 //---------------------------------------------------------------------------
\r
492 static void DeleteNode(int p) /* Deleting node from the tree */
\r
497 return; /* unregistered */
\r
499 if (rson[p] == NIL)
\r
502 if (lson[p] == NIL)
\r
507 if (rson[q] != NIL)
\r
511 } while (rson[q] != NIL);
\r
513 rson[dad[q]] = lson[q];
\r
514 dad[lson[q]] = dad[q];
\r
525 if (rson[dad[p]] == p)
\r
538 //---------------------------------------------------------------------------
\r
540 //---------------------------------------------------------------------------
\r
541 static void InsertNode(int r) /* Inserting node to the tree */
\r
544 unsigned char *key;
\r
548 key = &text_buf[r];
\r
549 p = N + 1 + key[0];
\r
550 rson[r] = lson[r] = NIL;
\r
556 if (rson[p] != NIL)
\r
567 if (lson[p] != NIL)
\r
578 for (i = 1; i < F; i++)
\r
579 if ((cmp = key[i] - text_buf[p + i]) != 0)
\r
584 if (i > match_length)
\r
586 match_position = ((r - p) & (N - 1)) - 1;
\r
587 if ((match_length = i) >= F)
\r
591 if (i == match_length)
\r
593 if ((c = ((r - p) & (N - 1)) - 1) < match_position)
\r
595 match_position = c;
\r
607 if (rson[dad[p]] == p)
\r
612 dad[p] = NIL; /* remove p */
\r
619 //---------------------------------------------------------------------------
\r
621 //---------------------------------------------------------------------------
\r
622 static void InitTree(void) /* Initializing tree */
\r
626 for (i = N + 1; i <= N + 256; i++)
\r
627 rson[i] = NIL; /* root */
\r
629 for (i = 0; i < N; i++)
\r
630 dad[i] = NIL; /* node */
\r
638 //---------------------------------------------------------------------------
\r
640 //---------------------------------------------------------------------------
\r
641 static void Putcode(long outfile_ptr, int l, unsigned c,unsigned PtrTypes) /* output c bits */
\r
643 putbuf |= c >> putlen;
\r
645 if ((putlen += l) >= 8)
\r
647 WritePtr(outfile_ptr, putbuf >> 8, PtrTypes);
\r
650 if ((putlen -= 8) >= 8)
\r
652 WritePtr(outfile_ptr, putbuf, PtrTypes);
\r
656 putbuf = c << (l - putlen);
\r
670 //---------------------------------------------------------------------------
\r
672 //---------------------------------------------------------------------------
\r
673 static void EncodeChar(long outfile_ptr, unsigned c, unsigned PtrTypes)
\r
682 /* search connections from leaf node to the root */
\r
688 // if node's address is odd, output 1 else output 0
\r
695 } while ((k = prnt[k]) != R);
\r
697 Putcode(outfile_ptr, j, i, PtrTypes);
\r
707 //---------------------------------------------------------------------------
\r
709 //---------------------------------------------------------------------------
\r
710 static void EncodePosition(long outfile_ptr, unsigned c, unsigned PtrTypes)
\r
715 // output upper 6 bits with encoding
\r
719 Putcode(outfile_ptr, p_len[i], (unsigned)p_code[i] << 8,PtrTypes);
\r
722 // output lower 6 bits directly
\r
725 Putcode(outfile_ptr, 6, (c & 0x3f) << 10,PtrTypes);
\r
731 //---------------------------------------------------------------------------
\r
733 //---------------------------------------------------------------------------
\r
734 static void EncodeEnd(long outfile_ptr,unsigned PtrTypes)
\r
738 WritePtr(outfile_ptr,(putbuf >> 8),PtrTypes);
\r
749 //===========================================================================
\r
751 // DECOMPRESSION ROUTINES
\r
753 //===========================================================================
\r
757 #if INCLUDE_LZH_DECOMP
\r
759 //---------------------------------------------------------------------------
\r
761 //---------------------------------------------------------------------------
\r
762 static int GetByte(long infile_ptr, unsigned long *CompressLength, unsigned PtrTypes)
\r
766 while (getlen <= 8)
\r
768 if (*CompressLength)
\r
770 i = ReadPtr(infile_ptr,PtrTypes);
\r
771 (*CompressLength)--;
\r
776 getbuf |= i << (8 - getlen);
\r
791 //---------------------------------------------------------------------------
\r
793 //---------------------------------------------------------------------------
\r
794 static int GetBit(long infile_ptr, unsigned long *CompressLength, unsigned PtrTypes) /* get one bit */
\r
798 while (getlen <= 8)
\r
800 if (*CompressLength)
\r
802 i = ReadPtr(infile_ptr,PtrTypes);
\r
803 (*CompressLength)--;
\r
808 getbuf |= i << (8 - getlen);
\r
822 //---------------------------------------------------------------------------
\r
824 //---------------------------------------------------------------------------
\r
825 static int DecodeChar(long infile_ptr, unsigned long *CompressLength, unsigned PtrTypes)
\r
832 * start searching tree from the root to leaves.
\r
833 * choose node #(son[]) if input bit == 0
\r
834 * else choose #(son[]+1) (input bit == 1)
\r
839 c += GetBit(infile_ptr,CompressLength,PtrTypes);
\r
852 //---------------------------------------------------------------------------
\r
854 //---------------------------------------------------------------------------
\r
855 static int DecodePosition(long infile_ptr,unsigned long *CompressLength, unsigned PtrTypes)
\r
860 // decode upper 6 bits from given table
\r
863 i = GetByte(infile_ptr, CompressLength, PtrTypes);
\r
864 c = (unsigned)d_code[i] << 6;
\r
868 // input lower 6 bits directly
\r
874 i = (i << 1) + GetBit(infile_ptr, CompressLength, PtrTypes);
\r
877 return c | i & 0x3f;
\r
886 //===========================================================================
\r
888 // EXTERNAL REFERENCED
\r
889 // COMPRESSION & DECOMPRESSION
\r
892 //===========================================================================
\r
897 #if INCLUDE_LZH_DECOMP
\r
899 //---------------------------------------------------------------------------
\r
901 //---------------------------------------------------------------------------
\r
902 long lzhDecompress(void far *infile, void far *outfile, unsigned long OrginalLength, unsigned long CompressLength, unsigned PtrTypes)
\r
907 datasize = textsize = OrginalLength;
\r
915 for (i = 0; i < N - F; i++)
\r
920 for (count = 0; count < textsize; )
\r
922 c = DecodeChar((long)&infile,&CompressLength,PtrTypes);
\r
926 WritePtr((long)&outfile,c,PtrTypes);
\r
927 datasize--; // Dec # of bytes to write
\r
931 count++; // inc count of bytes written
\r
935 i = (r - DecodePosition((long)&infile,&CompressLength,PtrTypes) - 1) & (N - 1);
\r
936 j = c - 255 + THRESHOLD;
\r
938 for (k = 0; k < j; k++)
\r
940 c = text_buf[(i + k) & (N - 1)];
\r
942 WritePtr((long)&outfile,c,PtrTypes);
\r
943 datasize--; // dec count of bytes to write
\r
947 count++; // inc count of bytes written
\r
951 if (LZH_DecompressDisplayVector && (count > printcount))
\r
953 LZH_DecompressDisplayVector(OrginalLength,OrginalLength-datasize);
\r
954 printcount += 1024;
\r
958 // printf("%12ld\n", count);
\r
969 #if INCLUDE_LZH_COMP
\r
971 //---------------------------------------------------------------------------
\r
973 //---------------------------------------------------------------------------
\r
974 long lzhCompress(void far *infile, void far *outfile,unsigned long DataLength,unsigned PtrTypes)
\r
976 int i, c, len, r, s, last_match_length;
\r
978 textsize = DataLength;
\r
985 textsize = 0; /* rewind and rescan */
\r
987 datasize = 0; // Init our counter of ReadData...
\r
994 for (i = s; i < r; i++)
\r
997 for (len = 0; len < F && (DataLength > datasize); len++)
\r
999 c = ReadPtr((long)&infile,PtrTypes);
\r
1000 datasize++; // Dec num of bytes to compress
\r
1001 text_buf[r + len] = c;
\r
1006 for (i = 1; i <= F; i++)
\r
1007 InsertNode(r - i);
\r
1012 if (match_length > len)
\r
1013 match_length = len;
\r
1015 if (match_length <= THRESHOLD)
\r
1018 EncodeChar((long)&outfile,text_buf[r],PtrTypes);
\r
1022 EncodeChar((long)&outfile, 255 - THRESHOLD + match_length,PtrTypes);
\r
1023 EncodePosition((long)&outfile, match_position,PtrTypes);
\r
1026 last_match_length = match_length;
\r
1028 for (i = 0; i < last_match_length && (DataLength > datasize); i++)
\r
1030 c = ReadPtr((long)&infile,PtrTypes);
\r
1037 text_buf[s + N] = c;
\r
1039 s = (s + 1) & (N - 1);
\r
1040 r = (r + 1) & (N - 1);
\r
1044 if (LZH_CompressDisplayVector && ((textsize += i) > printcount))
\r
1046 LZH_CompressDisplayVector(DataLength,datasize);
\r
1047 printcount += 1024;
\r
1051 while (i++ < last_match_length)
\r
1054 s = (s + 1) & (N - 1);
\r
1055 r = (r + 1) & (N - 1);
\r
1060 } while (len > 0);
\r
1062 EncodeEnd((long)&outfile,PtrTypes);
\r