Changeset 12893 for lang/perl/Archive-Lha
- Timestamp:
- 05/31/08 11:46:39 (6 months ago)
- Location:
- lang/perl/Archive-Lha/trunk
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/Archive-Lha/trunk/Lha.h
r3588 r12893 33 33 hash_store(self, key, newSVpv(n, 0)) 34 34 35 #define create_mask(n) \ 36 (1 << (USHORT_BIT - 1 - n)) 35 #define char_bit 8 36 #define uchar_bit 8 37 #define ushort_bit 16 37 38 38 #define CHAR_BIT 8 39 #define UCHAR_BIT 8 40 #define USHORT_BIT 16 39 #define uchar_max (1 << uchar_bit) - 1 40 #define ushort_max (1 << ushort_bit) - 1 41 41 42 #ifndef USHORT_MAX 43 #define USHORT_MAX (1 << USHORT_BIT) - 1 42 #define uchar_center (1 << (uchar_bit - 1)) 43 #define ushort_center (1 << (ushort_bit - 1)) 44 45 #ifndef min 46 #define min(a,b) ((a) <= (b) ? (a) : (b)) 44 47 #endif 45 48 46 #define UCHAR_CENTER (1 << (UCHAR_BIT - 1)) 47 #define USHORT_CENTER (1 << (USHORT_BIT - 1)) 48 #define MIN(a,b) ((a) <= (b) ? (a) : (b)) 49 #define create_mask(n) \ 50 (1 << (ushort_bit - 1 - n)) 49 51 50 #define READBUF_SIZE409652 #define readbuf_size 4096 51 53 52 54 typedef struct LhaTree { … … 68 70 unsigned char pos; 69 71 unsigned short blocksize; 70 unsigned char readbuf[ READBUF_SIZE];72 unsigned char readbuf[readbuf_size]; 71 73 unsigned short readpos; 72 74 } LhaBitstream; -
lang/perl/Archive-Lha/trunk/Lha.xs
r3588 r12893 33 33 34 34 void 35 safe_croak(LhaStash * stash, unsignedchar * dying_message)35 safe_croak(LhaStash * stash, char * dying_message) 36 36 { 37 37 destroy_stash(stash); … … 40 40 41 41 void 42 output(LhaStash * stash, unsigned char * queue, unsignedint len)42 output(LhaStash * stash, unsigned char * queue, int len) 43 43 { 44 44 dSP; … … 56 56 57 57 void 58 input(LhaStash * stash, unsignedint len)58 input(LhaStash * stash, int len) 59 59 { 60 60 int n; … … 86 86 { 87 87 return (bit->value << n) 88 + (bit->buf >> ( CHAR_BIT- n));88 + (bit->buf >> (char_bit - n)); 89 89 } 90 90 … … 99 99 if (stash->encoded_size > 0) { 100 100 if (bit->readpos == 0) { 101 if (stash->encoded_size > READBUF_SIZE)102 len = READBUF_SIZE;101 if (stash->encoded_size > readbuf_size) 102 len = readbuf_size; 103 103 else 104 104 len = stash->encoded_size; … … 106 106 } 107 107 bit->buf = bit->readbuf[bit->readpos++]; 108 if (bit->readpos == READBUF_SIZE)108 if (bit->readpos == readbuf_size) 109 109 bit->readpos = 0; 110 110 stash->encoded_size--; … … 112 112 else 113 113 bit->buf = 0; 114 bit->pos = CHAR_BIT;114 bit->pos = char_bit; 115 115 } 116 116 bit->pos -= n; … … 122 122 peekbits(LhaStash * stash, unsigned char n) 123 123 { 124 return (stash->bit->value >> ( USHORT_BIT- n));124 return (stash->bit->value >> (ushort_bit - n)); 125 125 } 126 126 … … 146 146 stash->bit->buf = 0; 147 147 stash->bit->pos = 0; 148 fillbuf(stash, USHORT_BIT);148 fillbuf(stash, ushort_bit); 149 149 } 150 150 … … 158 158 make_table(LhaStash * stash, LhaTable * table, unsigned short nchar) 159 159 { 160 unsigned short count[ USHORT_BIT+ 1];161 unsigned short weight[ USHORT_BIT+ 1];162 unsigned short start[ USHORT_BIT+ 1];160 unsigned short count[ushort_bit + 1]; 161 unsigned short weight[ushort_bit + 1]; 162 unsigned short start[ushort_bit + 1]; 163 163 unsigned short total, avail; 164 164 unsigned short from, to; … … 168 168 unsigned short *p; 169 169 170 if (table->bit > USHORT_BIT) {170 if (table->bit > ushort_bit) { 171 171 safe_croak(stash, "Table is broken: table bit is too large"); 172 172 } 173 173 174 for(i = 1; i <= USHORT_BIT; i++) {174 for(i = 1; i <= ushort_bit; i++) { 175 175 count[i] = 0; 176 weight[i] = 1 << ( USHORT_BIT- i);176 weight[i] = 1 << (ushort_bit - i); 177 177 } 178 178 179 179 for(i = 0; i < nchar; i++) 180 if (table->length[i] > USHORT_BIT) {180 if (table->length[i] > ushort_bit) { 181 181 safe_croak(stash, "Table is broken: bit length is too large"); 182 182 } … … 185 185 186 186 total = 0; 187 for(i = 1; i <= USHORT_BIT; i++) {187 for(i = 1; i <= ushort_bit; i++) { 188 188 start[i] = total; 189 189 total += weight[i] * count[i]; 190 190 } 191 if (total & USHORT_MAX) {191 if (total & ushort_max) { 192 192 safe_croak(stash, "Table is broken: total mismatch"); 193 193 } 194 194 195 bits_to_shift = USHORT_BIT- table->bit;195 bits_to_shift = ushort_bit - table->bit; 196 196 for(i = 1; i <= table->bit; i++) { 197 197 start[i] >>= bits_to_shift; … … 200 200 201 201 from = start[table->bit + 1] >> bits_to_shift; 202 to = MIN(1 << table->bit, table->size);202 to = min(1 << table->bit, table->size); 203 203 if (from) 204 204 for(i = from; i < to; i++) … … 212 212 l = start[bit] + weight[bit]; 213 213 if (bit <= table->bit) { 214 l = MIN(l, table->size);214 l = min(l, table->size); 215 215 for(j = start[bit]; j < l; j++) 216 216 table->table[j] = i; … … 229 229 *p = avail++; 230 230 } 231 if (j & USHORT_CENTER)231 if (j & ushort_center) 232 232 p = &(stash->tree->right[*p]); 233 233 else … … 264 264 else { 265 265 i = 0; 266 while (i < MIN(n, stash->pt->length_size)) {266 while (i < min(n, stash->pt->length_size)) { 267 267 c = peekbits(stash, 3); 268 268 if (c != 7) … … 305 305 else { 306 306 i = 0; 307 while (i < MIN(n, stash->c->length_size)) {307 while (i < min(n, stash->c->length_size)) { 308 308 c = stash->pt->table[peekbits(stash, stash->pt->bit)]; 309 309 if (c >= stash->NT) { … … 343 343 344 344 if (stash->bit->blocksize == 0) { 345 stash->bit->blocksize = getbits(stash, USHORT_BIT);345 stash->bit->blocksize = getbits(stash, ushort_bit); 346 346 read_pt_len(stash, stash->NT, stash->TBIT, 3); 347 347 read_c_len(stash); … … 402 402 { 403 403 while (len-- > 0) 404 crc = crctable[(crc ^ *str++) & UCHAR_MAX] ^ (crc >> CHAR_BIT);404 crc = crctable[(crc ^ *str++) & uchar_max] ^ (crc >> char_bit); 405 405 return crc; 406 406 } … … 497 497 init_bitstream(stash); 498 498 499 adjust = (1 << UCHAR_BIT) - self_uchar("THRESHOLD");499 adjust = (1 << uchar_bit) - self_uchar("THRESHOLD"); 500 500 crc16 = 0; 501 501 loc = 0; … … 503 503 while ( total < stash->original_size ) { 504 504 c = decode_c(stash); 505 if (c <= UCHAR_MAX) {505 if (c <= uchar_max) { 506 506 queue[loc++] = c; 507 507 if (loc == dicsize) { … … 546 546 547 547 unsigned short 548 xs_update(unsigned short crc, SV * str, unsignedint len)548 xs_update(unsigned short crc, SV * str, int len) 549 549 CODE: 550 550 RETVAL = calc_crc16(crc, SvPV(str, len), len);
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)