1 /* lzo_mchw.ch -- matching functions using a window
3 This file is part of the LZO real-time data compression library.
5 Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer
6 Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer
7 Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer
8 Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer
9 Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer
10 Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer
11 Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
12 Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
13 Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
14 Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer
15 Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer
16 Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
17 Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
20 The LZO library is free software; you can redistribute it and/or
21 modify it under the terms of the GNU General Public License as
22 published by the Free Software Foundation; either version 2 of
23 the License, or (at your option) any later version.
25 The LZO library is distributed in the hope that it will be useful,
26 but WITHOUT ANY WARRANTY; without even the implied warranty of
27 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 GNU General Public License for more details.
30 You should have received a copy of the GNU General Public License
31 along with the LZO library; see the file COPYING.
32 If not, write to the Free Software Foundation, Inc.,
33 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
35 Markus F.X.J. Oberhumer
36 <markus@oberhumer.com>
37 http://www.oberhumer.com/opensource/lzo/
41 /***********************************************************************
43 ************************************************************************/
49 lzo_uint look; /* bytes in lookahead buffer */
60 const lzo_bytep in_end;
65 lzo_uint textsize; /* text size counter */
66 lzo_uint codesize; /* code size counter */
67 lzo_uint printcount; /* counter for reporting progress every 1K bytes */
70 unsigned long lit_bytes;
71 unsigned long match_bytes;
72 unsigned long rep_bytes;
79 unsigned long r1_r, m3_r, m2_m, m3_m;
87 unsigned long r1_r, m3_r, m2_m, m3_m;
95 unsigned long r1_r, m2_m, m3_m;
98 #if defined(LZO1X) || defined(LZO1Y) || defined(LZO1Z)
103 unsigned long m1a_m, m1b_m, m2_m, m3_m, m4_m;
104 unsigned long lit1_r, lit2_r, lit3_r;
109 unsigned long m1, m2, m3, m4;
115 #if (LZO_CC_BORLANDC && LZO_ARCH_I086) && (__BORLANDC__ < 0x0450)
116 /* work around a Borland C 3.1 bug */
117 # define getbyte(c) ((c).ip < (c).in_end ? (c).ip +=1, (c).ip[-1] : (-1))
118 #elif defined(__TURBOC__) && defined(__TOS__)
119 /* work around a bug in Turbo C / Pure C (Atari ST) */
120 # define getbyte(c) ((c).ip < (c).in_end ? (int)(unsigned) *((c).ip)++ : (-1))
122 # define getbyte(c) ((c).ip < (c).in_end ? *((c).ip)++ : (-1))
125 #include "lzo_swd.ch"
128 /***********************************************************************
130 ************************************************************************/
133 init_match ( LZO_COMPRESS_T *c, lzo_swd_p s,
134 const lzo_bytep dict, lzo_uint dict_len,
144 c->last_m_len = c->last_m_off = 0;
146 c->textsize = c->codesize = c->printcount = 0;
147 c->lit_bytes = c->match_bytes = c->rep_bytes = 0;
150 r = swd_init(s,dict,dict_len);
154 s->use_best_off = (flags & 1) ? 1 : 0;
159 /***********************************************************************
161 ************************************************************************/
164 find_match ( LZO_COMPRESS_T *c, lzo_swd_p s,
165 lzo_uint this_len, lzo_uint skip )
171 assert(this_len >= skip);
172 swd_accept(s, this_len - skip);
173 c->textsize += this_len - skip + 1;
177 assert(this_len <= 1);
178 c->textsize += this_len - skip;
182 s->m_len = THRESHOLD;
185 lzo_memset(s->best_pos,0,sizeof(s->best_pos));
201 c->look = s->look + 1;
203 c->bp = c->ip - c->look;
206 /* brute force match search */
207 if (c->m_len > THRESHOLD && c->m_len + 1 <= c->look)
209 const lzo_bytep ip = c->bp;
210 const lzo_bytep m = c->bp - c->m_off;
211 const lzo_bytep in = c->in;
222 if (lzo_memcmp(in,ip,c->m_len+1) == 0)
223 printf("%p %p %p %5d\n",in,ip,m,c->m_len);
229 if (c->cb && c->cb->nprogress && c->textsize > c->printcount)
231 (*c->cb->nprogress)(c->cb, c->textsize, c->codesize, 0);
232 c->printcount += 1024;