33 #include <QtCore/QIODevice>
35 #include <sys/types.h>
42 #define LZFU_COMPRESSED 0x75465a4c
43 #define LZFU_UNCOMPRESSED 0x414c454d
45 #define LZFU_INITDICT "{\\rtf1\\ansi\\mac\\deff0\\deftab720{\\fonttbl;}" \
46 "{\\f0\\fnil \\froman \\fswiss \\fmodern \\fscrip" \
47 "t \\fdecor MS Sans SerifSymbolArialTimes Ne" \
48 "w RomanCourier{\\colortbl\\red0\\green0\\blue0" \
49 "\r\n\\par \\pard\\plain\\f0\\fs20\\b\\i\\u\\tab" \
51 #define LZFU_INITLENGTH 207
55 typedef struct _lzfuheader
65 #define FLAG(f,n) (f>>n)&0x1
72 #define OFFSET(b) (b>>4)&0xFFF
73 #define LENGTH(b) ((b&0xF)+2)
78 unsigned char window[4096];
79 unsigned int wlength = 0, cursor = 0, ocursor = 0;
86 memcpy( window, LZFU_INITDICT, LZFU_INITLENGTH );
87 wlength = LZFU_INITLENGTH;
88 if ( input->read( (
char *)&lzfuhdr,
sizeof(lzfuhdr) ) !=
sizeof(lzfuhdr) ) {
89 fprintf( stderr,
"unexpected eof, cannot read LZFU header\n" );
92 cursor +=
sizeof( lzfuhdr );
94 fprintf( stdout,
"total size : %d\n", lzfuhdr.cbSize+4 );
95 fprintf( stdout,
"raw size : %d\n", lzfuhdr.cbRawSize );
96 fprintf( stdout,
"compressed : %s\n", ( lzfuhdr.dwMagic == LZFU_COMPRESSED ?
"yes" :
"no" ) );
97 fprintf( stdout,
"CRC : %x\n", lzfuhdr.dwCRC );
98 fprintf( stdout,
"\n" );
101 while ( cursor < lzfuhdr.cbSize+4 && ocursor < lzfuhdr.cbRawSize && !input->atEnd() ) {
102 if ( input->read( &bFlags, 1 ) != 1 ) {
103 fprintf( stderr,
"unexpected eof, cannot read chunk flag\n" );
109 fprintf( stdout,
"Flags : " );
110 for (
int i=nFlags-1; i>=0; i-- ) {
111 fprintf( stdout,
"%d", FLAG( bFlags, i ) );
113 fprintf( stdout,
"\n" );
115 for (
int i=0; i<nFlags && ocursor<lzfuhdr.cbRawSize && cursor<lzfuhdr.cbSize+4; i++ ) {
116 if ( FLAG( bFlags, i ) ) {
119 if ( input->read( &c1, 1 ) != 1 || input->read( &c2, 1 ) != 1 ) {
120 fprintf( stderr,
"unexpected eof, cannot read block header\n" );
125 blkhdr |= ( 0xFF & c2 );
126 unsigned int offset = OFFSET( blkhdr ), length = LENGTH( blkhdr );
129 fprintf( stdout,
"block : offset=%.4d [%d], length=%.2d (0x%04X)\n",
130 OFFSET( blkhdr ), wlength, LENGTH( blkhdr ), blkhdr );
136 fprintf( stdout,
"block : " );
138 for (
unsigned int i=0; i<length; i++ ) {
139 c1 = window[( offset + i ) % 4096];
141 window[wlength] = c1;
142 wlength = ( wlength + 1 ) % 4096;
146 fprintf( stdout,
"\nblock : " );
148 fprintf( stdout,
"%c", c1 );
151 output->putChar( c1 );
155 fprintf( stdout,
"\n" );
160 if ( !input->getChar( &c ) ) {
161 if ( !input->atEnd() ) {
162 fprintf( stderr,
"unexpected eof, cannot read character\n" );
168 fprintf( stdout,
"char : %c\n", c );
173 wlength = ( wlength+1 ) % 4096;
175 output->putChar( c );
This file is part of the API for handling TNEF data and provides the LZFU decompression functionality...
int lzfu_decompress(QIODevice *input, QIODevice *output)
LZFU decompress data in compressed Rich Text Format (RTF).