Changeset 919 for 1.8.3/trunk/src/comp_w.c
- Timestamp:
- 06/12/07 15:21:47 (1 year ago)
- Files:
-
- 1.8.3/trunk/src/comp_w.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
1.8.3/trunk/src/comp_w.c
r846 r919 128 128 #include "confmagic.h" 129 129 130 #define MAXTABLE 32768 /**< Maximum words in the table */131 #define MAXWORDS 100 /**< Maximum size of a word */132 #define COLLISION_LIMIT 20 /**< Maximum allowed collisions */133 134 #define COMPRESS_HASH_MASK 0x7FFF /**< 32767 in hex */135 136 #define TABLE_FLAG 0x80 /**< Distinguish a table */137 #define TABLE_MASK 0x7F /**< Mask out words within a table */130 #define MAXTABLE 32768 /**< Maximum words in the table */ 131 #define MAXWORDS 100 /**< Maximum size of a word */ 132 #define COLLISION_LIMIT 20 /**< Maximum allowed collisions */ 133 134 #define COMPRESS_HASH_MASK 0x7FFF /**< 32767 in hex */ 135 136 #define TABLE_FLAG 0x80 /**< Distinguish a table */ 137 #define TABLE_MASK 0x7F /**< Mask out words within a table */ 138 138 139 139 /* Table of words */ … … 163 163 #ifdef COMP_STATS 164 164 void compress_stats(long *entries, long *mem_used, 165 long *total_uncompressed, long *total_compressed);165 long *total_uncompressed, long *total_compressed); 166 166 #endif 167 167 static unsigned int hash_fn(const char *s, int hashtab_mask); … … 173 173 int i, j; 174 174 175 word[wordpos++] = 0; /* word's trailing null */175 word[wordpos++] = 0; /* word's trailing null */ 176 176 177 177 /* Don't bother putting single or double letter words in the table */ … … 190 190 if (words[i]) 191 191 if (strcmp(word, words[i]) == 0) { 192 *b++ = (i >> 8) | TABLE_FLAG;193 *b++ = i & 0xFF;194 return;192 *b++ = (i >> 8) | TABLE_FLAG; 193 *b++ = i & 0xFF; 194 return; 195 195 } 196 196 /* not in table, add to it */ 197 197 198 198 if ((i & 0xFF) == 0) { 199 i++; /* make sure we don't have a null in the message */199 i++; /* make sure we don't have a null in the message */ 200 200 j++; 201 201 } … … 224 224 *b++ = i & 0xFF; 225 225 226 } /* end of output_previous_word */226 } /* end of output_previous_word */ 227 227 228 228 /** Word-compress a string. … … 250 250 /* break up input into words */ 251 251 while (*p) { 252 if (! (isdigit(*p) || isalpha(*p)) || wordpos >= MAXWORDS) {252 if (!isalnum(*p) || wordpos >= MAXWORDS) { 253 253 if (wordpos) { 254 word[wordpos++] = *p & 0x7F;/* add trailing punctuation */255 output_previous_word();256 wordpos = 0;254 word[wordpos++] = *p & 0x7F; /* add trailing punctuation */ 255 output_previous_word(); 256 wordpos = 0; 257 257 } else 258 *b++ = *p & 0x7F;258 *b++ = *p & 0x7F; 259 259 } else 260 260 word[wordpos++] = *p & 0x7F; … … 265 265 output_previous_word(); 266 266 267 *b = 0; /* trailing null */268 269 #ifdef COMP_STATS 270 total_comp += u_strlen(buf); /* calculate size of compressed text */271 total_uncomp += strlen(s); /* calculate size of uncompressed text */267 *b = 0; /* trailing null */ 268 269 #ifdef COMP_STATS 270 total_comp += u_strlen(buf); /* calculate size of compressed text */ 271 total_uncomp += strlen(s); /* calculate size of uncompressed text */ 272 272 #endif 273 273 274 274 return u_strdup(buf); 275 } /* end of compress; */275 } /* end of compress; */ 276 276 277 277 … … 309 309 i = ((c & TABLE_MASK) << 8) | *(++p); 310 310 if (i >= MAXTABLE || words[i] == NULL) { 311 static int panicking = 0;312 if (panicking) {313 do_rawlog(LT_ERR,314 "Error in string decompression occurred during panic dump.");315 exit(1);316 } else {317 panicking = 1;/* don't panic from within panic */318 do_rawlog(LT_ERR, "Error in string decompression, i = %i", i);319 mush_panic("Fatal error in decompression");320 }311 static int panicking = 0; 312 if (panicking) { 313 do_rawlog(LT_ERR, 314 "Error in string decompression occurred during panic dump."); 315 exit(1); 316 } else { 317 panicking = 1; /* don't panic from within panic */ 318 do_rawlog(LT_ERR, "Error in string decompression, i = %i", i); 319 mush_panic("Fatal error in decompression"); 320 } 321 321 } 322 322 strncpy((char *) b, words[i], words_len[i]); … … 327 327 } 328 328 329 *b++ = 0; /* trailing null */329 *b++ = 0; /* trailing null */ 330 330 331 331 return buf; 332 332 333 } /* end of uncompress; */333 } /* end of uncompress; */ 334 334 335 335 /** Word-uncompress a string, allocating memory. … … 372 372 void 373 373 compress_stats(long *entries, long *mem_used, long *total_uncompressed, 374 long *total_compressed)374 long *total_compressed) 375 375 { 376 376
