comparison src/lzfu.c @ 73:3cb02cb1e6cd stable-0-6-10

Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them). More changes for Fedora packaging (#434727) Fixes for const correctness.
author Carl Byington <carl@five-ten-sg.com>
date Thu, 29 May 2008 18:51:02 -0700
parents f66078abed38
children 535075b4d261
comparison
equal deleted inserted replaced
72:c21e9c001256 73:3cb02cb1e6cd
38 uint32_t dwMagic; 38 uint32_t dwMagic;
39 uint32_t dwCRC; 39 uint32_t dwCRC;
40 } lzfuheader; 40 } lzfuheader;
41 41
42 42
43 unsigned char* lzfu_decompress (unsigned char* rtfcomp, uint32_t compsize, size_t *size) { 43 char* lzfu_decompress (char* rtfcomp, uint32_t compsize, size_t *size) {
44 // the dictionary buffer 44 // the dictionary buffer
45 unsigned char dict[4096]; 45 unsigned char dict[4096];
46 // the dictionary pointer 46 // the dictionary pointer
47 unsigned int dict_length=0; 47 unsigned int dict_length=0;
48 // the header of the lzfu block 48 // the header of the lzfu block
50 // container for the data blocks 50 // container for the data blocks
51 unsigned char flags; 51 unsigned char flags;
52 // temp value for determining the bits in the flag 52 // temp value for determining the bits in the flag
53 unsigned char flag_mask; 53 unsigned char flag_mask;
54 uint32_t i; 54 uint32_t i;
55 unsigned char *out_buf; 55 char *out_buf;
56 uint32_t out_ptr = 0; 56 uint32_t out_ptr = 0;
57 uint32_t out_size; 57 uint32_t out_size;
58 uint32_t in_ptr; 58 uint32_t in_ptr;
59 uint32_t in_size; 59 uint32_t in_size;
60 60
69 //printf("raw size : %d\n", lzfuhdr.cbRawSize); 69 //printf("raw size : %d\n", lzfuhdr.cbRawSize);
70 //printf("compressed: %s\n", (lzfuhdr.dwMagic == LZFU_COMPRESSED ? "yes" : "no")); 70 //printf("compressed: %s\n", (lzfuhdr.dwMagic == LZFU_COMPRESSED ? "yes" : "no"));
71 //printf("CRC : %#x\n", lzfuhdr.dwCRC); 71 //printf("CRC : %#x\n", lzfuhdr.dwCRC);
72 //printf("\n"); 72 //printf("\n");
73 out_size = lzfuhdr.cbRawSize + 3; // two braces and a null terminator 73 out_size = lzfuhdr.cbRawSize + 3; // two braces and a null terminator
74 out_buf = (unsigned char*)xmalloc(out_size); 74 out_buf = (char*)xmalloc(out_size);
75 in_ptr = sizeof(lzfuhdr); 75 in_ptr = sizeof(lzfuhdr);
76 in_size = (lzfuhdr.cbSize < compsize) ? lzfuhdr.cbSize : compsize; 76 in_size = (lzfuhdr.cbSize < compsize) ? lzfuhdr.cbSize : compsize;
77 while (in_ptr < in_size) { 77 while (in_ptr < in_size) {
78 flags = rtfcomp[in_ptr++]; 78 flags = (unsigned char)(rtfcomp[in_ptr++]);
79 flag_mask = 1; 79 flag_mask = 1;
80 while (flag_mask) { 80 while (flag_mask) {
81 if (flag_mask & flags) { 81 if (flag_mask & flags) {
82 // two bytes available? 82 // two bytes available?
83 if (in_ptr+1 < in_size) { 83 if (in_ptr+1 < in_size) {
97 for (i=0; i < length; i++) { 97 for (i=0; i < length; i++) {
98 unsigned char c1; 98 unsigned char c1;
99 c1 = dict[(offset+i)%4096]; 99 c1 = dict[(offset+i)%4096];
100 dict[dict_length]=c1; 100 dict[dict_length]=c1;
101 dict_length = (dict_length+1) % 4096; 101 dict_length = (dict_length+1) % 4096;
102 if (out_ptr < out_size) out_buf[out_ptr++] = c1; 102 if (out_ptr < out_size) out_buf[out_ptr++] = (char)c1;
103 } 103 }
104 } 104 }
105 } else { 105 } else {
106 // one byte available? 106 // one byte available?
107 if (in_ptr < in_size) { 107 if (in_ptr < in_size) {
108 // uncompressed chunk (single byte) 108 // uncompressed chunk (single byte)
109 char c1 = rtfcomp[in_ptr++]; 109 char c1 = rtfcomp[in_ptr++];
110 dict[dict_length] = c1; 110 dict[dict_length] = c1;
111 dict_length = (dict_length+1)%4096; 111 dict_length = (dict_length+1)%4096;
112 if (out_ptr < out_size) out_buf[out_ptr++] = c1; 112 if (out_ptr < out_size) out_buf[out_ptr++] = (char)c1;
113 } 113 }
114 } 114 }
115 flag_mask <<= 1; 115 flag_mask <<= 1;
116 } 116 }
117 } 117 }