14 #include <QDataStream>
28 # include <sys/utime.h>
29 # include <sys/stat.h>
30 # include <qdatetime.h>
38 # define utimbuf _utimbuf
41 # include <sys/stat.h>
52 # define bzero(p, size) (void)memset((p), 0, (size))
60 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
61 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
62 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
63 0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
64 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
65 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
66 0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
67 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
68 0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
69 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
70 0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
71 0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
72 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
73 0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
74 0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
75 0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
76 0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
77 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
78 0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
79 0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
80 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
81 0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
82 0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
83 0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
84 0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
85 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
86 0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
87 0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
88 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
89 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
90 0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
91 0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
92 0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
93 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
94 0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
95 0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
96 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
97 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
98 0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
99 0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
100 0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
101 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
102 0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
103 0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
104 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
105 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
106 0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
107 0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
108 0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
109 0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
110 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
117 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
122 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
123 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
129 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
130 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99
135 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
136 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
137 8193, 12289, 16385, 24577
142 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
143 7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
150 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
151 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
165 {32, 128, 258, 1024},
171 0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0
176 0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13
181 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7
186 16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15
194 using namespace gzip_data;
198 static_dtree[ 0 ].Len = 0;
204 return treat_file( filename, FALSE );
210 return treat_file( filename, TRUE );
217 QFileInfo filename( iname );
226 QDateTime lastRead = filename.lastRead();
227 QDateTime lastMod = filename.lastModified();
229 filetime = lastMod.toTime_t();
231 ifd = open( iname.toAscii().constData(), O_RDONLY |
O_BINARY );
235 QString oname = make_ofname( iname, decompress );
246 count = read( ifd, signature, 2 );
254 if ( signature[0] != (
char) 0x1f ||
255 signature[1] != (
char) 0x8b )
return GZIP_NOTGZ;
259 count = read( ifd, &method, 1 );
272 count = read( ifd, &flags, 1 );
283 count = read( ifd, (
char*) &filetime, 4 );
294 int stringCount = sprintf( timestring,
"%s", ctime( &filetime ) );
296 ctime_r( &filetime, timestring );
307 count = read( ifd, &extra, 1 );
318 count = read( ifd, &OS, 1 );
328 QString embedded_name(
"" );
335 count = read( ifd, &c, 1 );
344 embedded_name.append( c );
347 oname = embedded_name;
351 QFileInfo output_file( oname );
355 ofd = open( oname.toAscii().constData(),
356 O_CREAT | O_WRONLY |
O_BINARY , 0664 );
366 catch (
int inflate_error )
370 unlink( oname.toAscii().constData() );
371 return inflate_error;
375 #define GETBYTE() (inptr < insize ? inbuf[inptr++] : (wp = w, fill_inbuf(0)))
379 unsigned char buf[ 4 ];
381 for (
int i = 0; i < 4; i++ ) buf[ i ] =
GETBYTE();
383 crc = buf[ 3 ] << 24 | buf[ 2 ] << 16 | buf[ 1 ] << 8 | buf[ 0 ];
386 if ( crc != updcrc(outbuf, 0) )
390 unlink( oname.toAscii().constData() );
396 for (
int i = 0; i < 4; i++ ) buf[ i ] =
GETBYTE();
398 ulg size = buf[ 3 ] << 24 | buf[ 2 ] << 16 | buf[ 1 ] << 8 | buf[ 0 ];
400 if ( size != (
unsigned int) bytes_out )
404 unlink( oname.toAscii().constData() );
412 QFileInfo filename( oname );
415 ofd = open( oname.toAscii().constData(),
416 O_CREAT | O_WRONLY |
O_BINARY, 0664 );
422 #define flush_output(w) (wp=(w),flush_window())
424 #define put_byte(c) \
426 outbuf[ outcnt++ ] = (uch)(c); \
427 if ( outcnt == OUTBUFSIZ ) flush_outbuf();\
431 #define put_short(w) \
433 if ( outcnt < OUTBUFSIZ-2 ) \
435 outbuf[ outcnt++ ] = (uch) ((w) & 0xff); \
436 outbuf[ outcnt++ ] = (uch) ((ush)(w) >> 8); \
440 put_byte( (uch) ( (w) & 0xff) ); \
441 put_byte( (uch) ( (ush) (w) >> 8 ) ); \
446 #define put_long(n) \
448 put_short( (n) & 0xffff ); \
449 put_short( ( (ulg) (n) ) >> 16) ; \
452 #define GZIP_MAGIC "\037\213"
454 #define ORIG_NAME 0x08
467 time_t time_stamp = lastMod.toTime_t();
468 put_long( (
ulg) time_stamp == ( time_stamp & 0xffffffff ) ?
469 (
ulg) time_stamp : (
ulg) 0);
477 # define OS_CODE 0x0b
479 # define OS_CODE 0x03
484 if ( strlen( iname.toAscii().constData() ) > 255 )
488 strcpy( f, iname.toAscii().constData() );
489 char*
p = base_name( f );
490 do {
put_byte( *p ); }
while ( *p++ );
492 crc = updcrc( 0, 0 );
515 fstat( ifd, &ifstat );
522 chmod( oname.toAscii().constData(), ifstat.st_mode & 07777 );
526 chown( oname.toAscii().constData(), ifstat.st_uid, ifstat.st_gid );
531 struct utimbuf timep;
533 timep.actime = ifstat.st_atime;
534 timep.modtime = filetime;
535 utime( oname.toAscii().constData(), &timep );
538 unlink( iname.toAscii().constData() );
549 QString ofile = filename;
553 if ( filename.endsWith(
".gz" ) )
554 return ofile.section(
".", 0, 2 );
555 else if ( filename.endsWith(
".svgz" ) )
556 return ofile.section(
".", 0, 2 ) +
".svg";
558 return QString(
"" );
562 if ( filename.endsWith(
".svg" ) )
563 return ofile.section(
".", 0, -2 ) +
".svgz";
565 return ofile +
".gz";
724 # define NEXTBYTE() (uch)GETBYTE()
727 #define NEEDBITS(n) {while(k<(n)){b|=((ulg)NEXTBYTE())<<k;k+=8;}}
755 #define DUMPBITS(n) {b>>=(n);k-=(n);}
812 #define memzero(s, n) bzero((s), (n))
838 register unsigned*
p;
839 register struct huft* q;
865 *t = (
struct huft*) NULL;
874 for ( j = 1; j <=
BMAX; j++ )
881 if ( (
unsigned)l < j ) l = j;
883 for ( i =
BMAX; i; i-- )
890 if ((
unsigned)l > i) l = i;
896 for (y = 1 << j; j < i; j++, y <<= 1)
898 if ( (y -= c[j]) < 0 )
return 2;
901 if ( ( y -= c[i] ) < 0 )
return 2;
923 if ( (j = *p++) != 0 ) v[x[j]++] = i;
936 u[0] = (
struct huft*) NULL;
937 q = (
struct huft*) NULL;
941 for ( ; k <= g; k++ )
954 z = (z = g - w) > (
unsigned)l ? l : z;
956 if ( (f = 1 << (j = k - w)) > a + 1 )
964 if ( (f <<= 1) <= *++xp )
977 if ( (q = (
struct huft*) malloc( (z + 1) *
sizeof(
struct huft)) ) ==
978 (
struct huft *) NULL )
980 if ( h ) huft_free( u[0] );
986 *(t = &(q->
v.
t)) = (
struct huft *)NULL;
1010 r.
e = (
uch)(*p < 256 ? 16 : 15);
1016 r.
e = (
uch) e[*p - s];
1017 r.
v.
n = d[*p++ - s];
1023 for ( j = i >> w; j < z; j += f )
1029 for ( j = 1 << (k - 1); i & j; j >>= 1 )
1037 while ( (i & ((1 << w) - 1)) != x[
h] )
1046 return y != 0 && g != 1;
1054 register struct huft*
p;
1055 register struct huft* q;
1060 while ( p != (
struct huft*) NULL )
1080 register unsigned e;
1088 register unsigned k;
1103 if ((e = (t = tl + ((
unsigned)b & ml))->e) > 16)
1107 if (e == 99)
return 1;
1111 }
while ( (e = (t = t->
v.
t + ((
unsigned)b &
mask_bits[e]))->e) > 16 );
1140 if ( (e = (t = td + ((
unsigned)b & md))->e) > 16 )
1144 if ( e == 99 )
return 1;
1148 }
while ( (e = (t = t->
v.
t + ((
unsigned)b &
mask_bits[e]))->e) > 16 );
1160 n -= (e = (e =
WSIZE - ((d &=
WSIZE-1) > w ? d : w)) > n ? n : e);
1204 register unsigned k;
1220 n = ( (unsigned) b & 0xffff );
1224 if ( n != (
unsigned)( (~b) & 0xffff ) )
1267 for ( i = 0; i < 144; i++ ) l [ i ] = 8;
1268 for ( ; i < 256; i++ ) l [ i ] = 9;
1269 for ( ; i < 280; i++ ) l [ i ] = 7;
1272 for ( ; i < 288; i++ ) l [ i ] = 8;
1276 if ( ( i = huft_build(l, 288, 257,
cplens,
cplext, &tl, &bl ) ) != 0 )
1283 for ( i = 0; i < 30; i++ ) l [ i ] = 5;
1287 if ( ( i = huft_build( l, 30, 0,
cpdist,
cpdext, &td, &bd ) ) > 1 )
1295 if ( inflate_codes( tl, td, bl, bd ) )
1324 unsigned ll[286+30];
1326 register unsigned k;
1328 static unsigned border[] = {
1329 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
1339 nl = 257 + ( (unsigned) b & 0x1f );
1343 nd = 1 + ((unsigned) b & 0x1f );
1347 nb = 4 + ( (unsigned) b & 0xf );
1350 if ( nl > 286 || nd > 30 )
return 1;
1354 for ( j = 0; j < nb; j++ )
1357 ll [ border[j] ] = (unsigned) b & 7;
1361 for ( ; j < 19; j++ ) ll[ border[j] ] = 0;
1366 if ( ( i = huft_build( ll, 19, 19, NULL, NULL, &tl, &bl ) ) != 0 )
1382 while ( (
unsigned) i < n )
1385 j = ( td = tl + ( (unsigned) b & m ) ) -> b;
1396 j = 3 + ((unsigned)b & 3);
1399 if ( (
unsigned) i + j > n)
return 1;
1401 while ( j-- ) ll [ i++ ] = l;
1406 j = 3 + ( (unsigned) b & 7 );
1409 if ( (
unsigned) i + j > n )
return 1;
1411 while ( j-- ) ll[ i++ ] = 0;
1417 j = 11 + ( (unsigned) b & 0x7f );
1420 if ( (
unsigned) i + j > n )
return 1;
1422 while ( j-- ) ll[i++] = 0;
1439 if ( ( i = huft_build( ll, nl, 257,
cplens,
cplext, &tl, &bl ) ) != 0 )
1450 if ( ( i = huft_build( ll + nl, nd, 0,
cpdist,
cpdext, &td, &bd ) ) != 0 )
1463 if ( inflate_codes( tl, td, bl, bd ) )
return 1;
1481 register unsigned k;
1497 t = (unsigned) b & 3;
1506 if ( t == 2 )
return inflate_dynamic();
1507 if ( t == 0 )
return inflate_stored();
1508 if ( t == 1 )
return inflate_fixed();
1534 if ( (r = inflate_block( &e ) ) != 0 )
return r;
1535 if ( hufts > h ) h = hufts;
1567 len = read ( ifd, (
char*) inbuf + insize,
INBUFSIZ - insize );
1568 if ( len == 0 )
break;
1580 if ( eof_ok )
return EOF;
1585 bytes_in += (off_t) insize;
1596 if ( outcnt == 0 )
return;
1598 updcrc( window, outcnt );
1599 write_buf( ofd, (
char *) window, outcnt );
1601 bytes_out += (off_t) outcnt;
1616 static ulg crc_internal = (
ulg) 0xffffffffL;
1627 c =
crc_32_tab[ ( (int) c ^ ( *s++ ) ) & 0xff ] ^ ( c >> 8 );
1632 return c ^ 0xffffffffL;
1648 while ( ( n = write( fd, buf, cnt) ) != cnt)
1650 if ( n == (
unsigned) (-1) )
1656 buf = (
void*) ( (
char*) buf + n );
1666 #define PATH_SEP '/'
1669 # define PATH_SEP2 '\\'
1670 # define PATH_SEP3 ':'
1678 if ( ( p = strrchr( f,
PATH_SEP ) ) != NULL ) f = p + 1;
1681 if ( ( p = strrchr( f, PATH_SEP2 ) ) != NULL ) f = p + 1;
1685 if ( ( p = strrchr( f, PATH_SEP3 ) ) != NULL ) f = p + 1;
1697 if ( outcnt == 0)
return;
1699 write_buf( ofd, (
char *) outbuf, outcnt );
1700 bytes_out += (off_t) outcnt;
1708 #define HASH_BITS 15
1711 #define MIN_LOOKAHEAD ( MAX_MATCH + MIN_MATCH + 1 )
1715 #define MAX_DIST ( WSIZE - MIN_LOOKAHEAD )
1719 #define HASH_SIZE (unsigned) ( 1 << HASH_BITS )
1720 #define HASH_MASK ( HASH_SIZE - 1 )
1721 #define WMASK ( WSIZE - 1 )
1726 #define H_SHIFT ( (HASH_BITS + MIN_MATCH - 1) / MIN_MATCH )
1739 #define UPDATE_HASH(h,c) ( h = ( ( (h) << H_SHIFT ) ^ (c)) & HASH_MASK )
1750 #define INSERT_STRING(s, match_head) \
1751 ( UPDATE_HASH( ins_h, window[ (s) + MIN_MATCH - 1 ] ), \
1752 prev[ (s) & WMASK ] = match_head = head[ ins_h ], \
1753 head[ ins_h ] = (s) )
1759 #define FLUSH_BLOCK(eof) \
1760 flush_block( block_start >= 0L ? (char*) &window[ (unsigned) block_start ] : \
1761 (char*) NULL, (long) strstart - block_start, (eof) )
1769 int match_available = 0;
1770 register unsigned match_length =
MIN_MATCH - 1;
1773 while ( lookahead != 0 )
1782 prev_length = match_length, prev_match = match_start;
1785 if ( hash_head != (
ush) 0 &&
1786 prev_length < max_lazy_match &&
1793 match_length = longest_match( hash_head );
1797 if ( match_length > lookahead ) match_length = lookahead;
1801 #define TOO_FAR 4096
1814 if ( prev_length >=
MIN_MATCH && match_length <= prev_length )
1816 flush = ct_tally( strstart - 1 - prev_match, prev_length -
MIN_MATCH );
1821 lookahead -= prev_length - 1;
1833 }
while ( --prev_length != 0 );
1835 match_available = 0;
1839 if ( flush )
FLUSH_BLOCK(0), block_start = strstart;
1842 else if ( match_available )
1848 if ( ct_tally ( 0, window[ strstart - 1 ] ) )
1861 match_available = 1;
1870 }
while ( lookahead <
MIN_LOOKAHEAD && ! eofile ) fill_window();
1873 if ( match_available ) ct_tally ( 0, window[strstart -1 ] );
1896 l_desc.dyn_tree = dyn_ltree;
1897 l_desc.static_tree = static_ltree;
1902 l_desc.max_code = 0;
1909 d_desc.dyn_tree = dyn_dtree;
1910 d_desc.static_tree = static_dtree;
1912 d_desc.extra_base = 0;
1915 d_desc.max_code = 0;
1922 bl_desc.dyn_tree = bl_tree;
1923 bl_desc.static_tree = 0;
1925 bl_desc.extra_base = 0;
1928 bl_desc.max_code = 0;
1931 #define pack_level 9
1948 lookahead = file_read( (
char*) window, 2 *
WSIZE );
1950 if ( lookahead == 0 )
1962 while ( lookahead <
MIN_LOOKAHEAD && ! eofile ) fill_window();
1966 register unsigned j;
1981 len = read( ifd, buf, size );
1982 if ( len == 0 )
return (
int) len;
1984 if ( len == (
unsigned) -1 )
1989 crc = updcrc( (
uch*)buf, len );
1990 bytes_in += (off_t)len;
2005 register unsigned n;
2006 register unsigned m;
2008 unsigned more = (unsigned) ( 2L *
WSIZE - (
ulg) lookahead - (
ulg) strstart );
2014 if ( more == (
unsigned) EOF )
2027 memcpy( (
char*) window, (
char*) window +
WSIZE, (
unsigned)
WSIZE );
2029 match_start -=
WSIZE;
2032 block_start -= (long) WSIZE;
2037 head[n] = (
Pos)(m >= WSIZE ? m - WSIZE : 0 );
2040 for ( n = 0; n <
WSIZE; n++ )
2043 prev[n] = (
Pos)(m >= WSIZE ? m - WSIZE : 0 );
2055 n = file_read( (
char*) window + strstart + lookahead, more );
2056 if ( n == 0 || n == (
unsigned) EOF)
2070 unsigned chain_length = max_chain_length;
2071 register uch* scan = window + strstart;
2072 register uch* match;
2074 int best_len = prev_length;
2088 register uch* strend = window + strstart +
MAX_MATCH - 1;
2089 register ush scan_start = *(
ush*) scan;
2090 register ush scan_end = *(
ush*) (scan + best_len - 1 );
2093 register uch scan_end1 = scan[ best_len - 1 ];
2094 register uch scan_end = scan[ best_len ];
2099 if ( prev_length >= good_match )
2106 match = window + cur_match;
2111 #if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
2115 if ( *(
ush*)( match + best_len - 1 ) != scan_end ||
2116 *(
ush*) match != scan_start)
continue;
2132 }
while ( *(
ush*) ( scan += 2 ) == *(
ush*) ( match += 2 ) &&
2133 *(
ush*) ( scan += 2 ) == *(
ush*) ( match += 2 ) &&
2134 *(
ush*) ( scan += 2 ) == *(
ush*) ( match += 2 ) &&
2135 *(
ush*) ( scan += 2 ) == *(
ush*) ( match += 2 ) &&
2141 if ( *scan == *match ) scan++;
2143 len = ( MAX_MATCH - 1 ) - (
int) ( strend - scan );
2144 scan = strend - ( MAX_MATCH - 1 );
2147 if ( match[ best_len ] != scan_end ||
2148 match[ best_len - 1 ] != scan_end1 ||
2150 * ++match != scan[ 1 ] )
continue;
2165 }
while ( * ++scan == * ++match && * ++scan == * ++match &&
2166 * ++scan == * ++match && * ++scan == * ++match &&
2167 * ++scan == * ++match && * ++scan == * ++match &&
2168 * ++scan == * ++match && * ++scan == * ++match &&
2171 len = MAX_MATCH - (int)( strend - scan );
2176 if ( len > best_len )
2178 match_start = cur_match;
2180 if ( len >= nice_match )
break;
2182 scan_end = *(
ush*) ( scan + best_len - 1 );
2184 scan_end1 = scan[ best_len - 1 ];
2185 scan_end = scan[ best_len ];
2188 }
while ( ( cur_match = prev[ cur_match &
WMASK ] ) > limit
2189 && --chain_length != 0 );
2207 #define d_code(dist) \
2208 ( (dist) < 256 ? dist_code[ dist ] : dist_code[ 256 + ( ( dist ) >> 7 ) ] )
2213 #define STORED_BLOCK 0
2214 #define STORED STORED_BLOCK
2215 #define STATIC_TREES 1
2219 #ifndef DIST_BUFSIZE
2220 # define DIST_BUFSIZE LIT_BUFSIZE
2256 compressed_len = 0L;
2258 if ( static_dtree[ 0 ].
Len != 0 )
return;
2264 base_length[code] = length;
2265 for ( n = 0; n < ( 1 <<
extra_lbits[ code ] ); n++ )
2267 length_code[length++] = (
uch)code;
2275 length_code[ length - 1 ] = (
uch)code;
2279 for ( code = 0 ; code < 16; code++ )
2281 base_dist[ code ] = dist;
2282 for ( n = 0; n < ( 1 <<
extra_dbits[ code ] ); n++ )
2284 dist_code[ dist++ ] = (
uch) code;
2289 for ( ; code <
D_CODES; code++ )
2291 base_dist[ code ] = dist << 7;
2292 for ( n = 0; n < ( 1 << (
extra_dbits[ code ] - 7 ) ); n++ )
2294 dist_code[256 + dist++] = (
uch)code;
2299 for ( bits = 0; bits <=
MAX_BITS; bits++ ) bl_count[ bits ] = 0;
2302 while ( n <= 143 ) static_ltree[ n++ ].Len = 8, bl_count[ 8 ]++;
2303 while ( n <= 255 ) static_ltree[ n++ ].Len = 9, bl_count[ 9 ]++;
2304 while ( n <= 279 ) static_ltree[ n++ ].Len = 7, bl_count[ 7 ]++;
2305 while ( n <= 287 ) static_ltree[ n++ ].Len = 8, bl_count[ 8 ]++;
2314 for ( n = 0; n <
D_CODES; n++ )
2316 static_dtree[ n ].Len = 5;
2317 static_dtree[ n ].Code = bi_reverse( n, 5 );
2332 inbuf[ last_lit++ ] = (
uch) lc;
2337 dyn_ltree[ lc ].Freq++;
2344 dyn_ltree[ length_code[ lc ] +
LITERALS + 1 ].Freq++;
2345 dyn_dtree[
d_code( dist ) ].Freq++;
2347 d_buf[ last_dist++ ] = (
ush) dist;
2354 if ( ( last_lit & 7 ) == 0 )
2356 flag_buf[ last_flags++ ] = flags;
2363 if (
level > 2 && ( last_lit & 0xfff ) == 0)
2366 ulg out_length = (
ulg) last_lit * 8L;
2367 ulg in_length = (
ulg) strstart - block_start;
2370 for ( dcode = 0; dcode <
D_CODES; dcode++ )
2376 if ( last_dist < last_lit / 2 && out_length < in_length / 2)
return 1;
2395 ulg opt_lenb, static_lenb;
2398 flag_buf[ last_flags ] = flags;
2414 max_blindex = build_bl_tree();
2417 opt_lenb = ( opt_len + 3 + 7 ) >> 3;
2418 static_lenb = ( static_len + 3 + 7 ) >> 3;
2421 if ( static_lenb <= opt_lenb ) opt_lenb = static_lenb;
2427 #define seekable() 0
2430 if (
level == 1 && eof && compressed_len == 0L) {
2432 if ( stored_len <= opt_lenb && eof && compressed_len == 0L &&
seekable() )
2439 copy_block( buf, (
unsigned) stored_len, 0 );
2440 compressed_len = stored_len << 3;
2446 if (
level == 2 && buf != (
char*)0)
2451 if ( stored_len + 4 <= opt_lenb && buf != (
char*) 0 )
2462 compressed_len = ( compressed_len + 3 + 7 ) & ~7L;
2463 compressed_len += ( stored_len + 4 ) << 3;
2465 copy_block( buf, (
unsigned) stored_len, 1 );
2474 if ( static_lenb == opt_lenb )
2478 compress_block( (
ct_data*) static_ltree, (
ct_data*) static_dtree );
2479 compressed_len += 3 + static_len;
2482 send_bits( (
DYN_TREES << 1 ) + eof, 3 );
2483 send_all_trees( l_desc.max_code + 1, d_desc.max_code + 1, max_blindex + 1 );
2485 compressed_len += 3 + opt_len;
2493 compressed_len += 7;
2496 return compressed_len >> 3;
2507 for ( n = 0; n <
L_CODES; n++ ) dyn_ltree[ n ].
Freq = 0;
2508 for ( n = 0; n <
D_CODES; n++ ) dyn_dtree[ n ].
Freq = 0;
2509 for ( n = 0; n <
BL_CODES; n++ ) bl_tree [ n ].
Freq = 0;
2512 opt_len = static_len = 0L;
2513 last_lit = last_dist = last_flags = 0;
2514 flags = 0; flag_bit = 1;
2517 #define send_code(c, tree) send_bits( tree[ c ].Code, tree[ c ].Len )
2538 if ( last_lit != 0 )
2541 if ( ( lx & 7 ) == 0 ) flag = flag_buf[ fx++ ];
2544 if ( ( flag & 1 ) == 0 )
2551 code = length_code[ lc ];
2557 lc -= base_length[ code ];
2558 send_bits( lc, extra );
2561 dist = d_buf[ dx++ ];
2571 dist -= base_dist[ code ];
2572 send_bits( dist, extra );
2578 }
while ( lx < last_lit );
2595 if ( bi_valid > (
int)
Buf_size - length )
2597 bi_buf |= (value << bi_valid);
2604 bi_buf |= value << bi_valid;
2618 register unsigned res = 0;
2625 }
while ( --len > 0 );
2638 else if ( bi_valid > 0 )
2676 #define pqremove(tree, top) \
2678 top = heap[ SMALLEST ]; \
2679 heap[ SMALLEST ] = heap[ heap_len--] ; \
2680 pqdownheap( tree, SMALLEST ); \
2683 #define MAX(a,b) ( a >= b ? a : b )
2699 int elems = desc->
elems;
2711 for ( n = 0; n < elems; n++ )
2713 if ( tree[ n ].
Freq != 0 )
2715 heap[ ++heap_len ] = max_code = n;
2729 while ( heap_len < 2 )
2731 int new1 = heap[ ++heap_len ] = ( max_code < 2 ? ++max_code : 0 );
2733 tree [ new1 ].Freq = 1;
2736 if ( stree ) static_len -= stree[ new1 ].Len;
2745 for ( n = heap_len / 2; n >= 1; n-- ) pqdownheap( tree, n );
2755 heap[ --heap_max ] = n;
2756 heap[ --heap_max ] = m;
2759 tree [ node ].Freq = tree[ n ].Freq + tree[ m ].Freq;
2760 depth[ node ] = (
uch) (
MAX( depth[ n ], depth[ m ] ) + 1 );
2761 tree [ n ].Dad = tree[ m ].Dad = (
ush) node;
2767 }
while ( heap_len >= 2 );
2769 heap[ --heap_max ] = heap[
SMALLEST ];
2777 gen_codes ( (
ct_data*) tree, max_code );
2790 scan_tree( (
ct_data*) dyn_ltree, l_desc.max_code );
2791 scan_tree( (
ct_data*) dyn_dtree, d_desc.max_code );
2794 build_tree( (
tree_desc*) ( &bl_desc ) );
2803 for ( max_blindex =
BL_CODES - 1; max_blindex >= 3; max_blindex-- )
2805 if ( bl_tree[
bl_order[ max_blindex ] ].
Len != 0 )
break;
2809 opt_len += 3 * ( max_blindex + 1 ) + 5 + 5 + 4;
2840 for ( bits = 0; bits <=
MAX_BITS; bits++ ) bl_count[ bits ] = 0;
2845 tree[ heap[ heap_max ] ].Len = 0;
2847 for ( h = heap_max + 1; h <
HEAP_SIZE; h++ )
2850 bits = tree[ tree[ n ].Dad ].Len + 1;
2852 if ( bits > max_length)
2858 tree[ n ].Len = (
ush) bits;
2861 if ( n > max_code )
continue;
2866 if ( n >= base ) xbits = extra[ n - base ];
2869 opt_len += (
ulg) f * ( bits + xbits );
2871 if ( stree ) static_len += (
ulg) f * ( stree[ n ].
Len + xbits );
2874 if ( overflow == 0)
return;
2879 bits = max_length-1;
2881 while ( bl_count[ bits ] == 0 ) bits--;
2884 bl_count[ bits + 1 ] += 2;
2885 bl_count[ max_length ]--;
2892 }
while ( overflow > 0 );
2899 for ( bits = max_length; bits != 0; bits-- )
2907 if ( m > max_code )
continue;
2909 if ( tree[ m ].
Len != (
unsigned) bits )
2911 opt_len += ( (long) bits - (
long) tree[ m ].Len ) * (
long) tree[ m ].Freq;
2912 tree[ m ].Len = (
ush) bits;
2939 for ( bits = 1; bits <=
MAX_BITS; bits++ )
2941 next_code[ bits ] = code = ( code + bl_count[ bits - 1 ] ) << 1;
2947 for ( n = 0; n <= max_code; n++ )
2949 int len = tree[ n ].Len;
2951 if ( len == 0 )
continue;
2954 tree[ n ].Code = bi_reverse( next_code[ len ]++, len );
2962 #define smaller( tree, n, m ) \
2963 ( tree[ n ].Freq < tree[ m ].Freq || \
2964 ( tree[ n ].Freq == tree[ m ].Freq && depth[ n ] <= depth[ m ] ) )
2979 while ( j <= heap_len )
2982 if ( j < heap_len &&
smaller( tree, heap[ j + 1 ], heap[ j ] ) ) j++;
2985 if (
smaller( tree, v, heap[ j ] ) )
break;
2988 heap[ k ] = heap[ j ];
3007 send_bits( lcodes - 257, 5 );
3008 send_bits( dcodes - 1, 5 );
3009 send_bits( blcodes - 4, 4 );
3011 for ( rank = 0; rank < blcodes; rank++ )
3016 send_tree( (
ct_data*) dyn_ltree, lcodes - 1 );
3017 send_tree((
ct_data*) dyn_dtree, dcodes - 1 );
3023 #define REPZ_3_10 17
3026 #define REPZ_11_138 18
3042 int nextlen = tree[0].Len;
3053 tree[ max_code + 1 ].Len = (
ush) 0xffff;
3055 for ( n = 0; n <= max_code; n++ )
3058 nextlen = tree[ n + 1 ].Len;
3060 if ( ++count < max_count && curlen == nextlen )
3064 else if ( count < min_count )
3066 bl_tree[ curlen ].Freq += count;
3068 else if ( curlen != 0 )
3070 if ( curlen != prevlen ) bl_tree[ curlen ].Freq++;
3073 else if ( count <= 10 )
3090 else if ( curlen == nextlen )
3114 int nextlen = tree[0].Len;
3127 for ( n = 0; n <= max_code; n++ )
3130 nextlen = tree[ n + 1 ].Len;
3132 if ( ++count < max_count && curlen == nextlen )
3136 else if ( count < min_count )
3141 }
while ( --count != 0 );
3143 else if ( curlen != 0 )
3145 if ( curlen != prevlen )
3152 send_bits( count - 3, 2 );
3154 else if ( count <= 10 )
3157 send_bits( count - 3, 3 );
3162 send_bits( count - 11, 7 );
3173 else if ( curlen == nextlen )
3189 QString explanation;
3193 explanation =
"The g(un)zip operation was succesful.";
3197 explanation =
"Could not find the input file." ;
3201 explanation =
"The input file name is not a regular file." ;
3205 explanation =
"The input file is not readable by the user." ;
3209 explanation =
"An unsupported option is included in the compressed file.";
3213 explanation =
"The output file already exists." ;
3217 explanation =
"The compressed file failed an internal validation." ;
3221 explanation =
"Could not read the input file." ;
3225 explanation =
"Could not write the output file." ;
3229 explanation =
"The output data does not match the internal file size." ;
3233 explanation =
"The file/path name is too long." ;
3237 explanation =
"In internal gzip error occured." ;
3241 explanation =
"Unknown return code: " + error;