Changeset 919 for 1.8.3/trunk/src/comp_w8.c
- Timestamp:
- 06/12/07 15:21:47 (1 year ago)
- Files:
-
- 1.8.3/trunk/src/comp_w8.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
1.8.3/trunk/src/comp_w8.c
r846 r919 129 129 #include "confmagic.h" 130 130 131 #define MAXTABLE 32768 /**< Maximum words in the table */132 #define MAXWORDS 100 /**< Maximum length of a word */133 #define COLLISION_LIMIT 20 /**< Maximum allowed collisions */134 135 #define COMPRESS_HASH_MASK 0x7FFF /**< 32767 in hex */136 137 #define MARKER_CHAR 0x06 /**< Separates words. This char is the only one that can't be represented */138 #define TABLE_FLAG 0x80 /**< Distinguishes a table */139 #define TABLE_MASK 0x7F /**< Mask out words within a table */131 #define MAXTABLE 32768 /**< Maximum words in the table */ 132 #define MAXWORDS 100 /**< Maximum length of a word */ 133 #define COLLISION_LIMIT 20 /**< Maximum allowed collisions */ 134 135 #define COMPRESS_HASH_MASK 0x7FFF /**< 32767 in hex */ 136 137 #define MARKER_CHAR 0x06 /**< Separates words. This char is the only one that can't be represented */ 138 #define TABLE_FLAG 0x80 /**< Distinguishes a table */ 139 #define TABLE_MASK 0x7F /**< Mask out words within a table */ 140 140 141 141 /* Table of words */ … … 165 165 #ifdef COMP_STATS 166 166 void compress_stats(long *entries, long *mem_used, 167 long *total_uncompressed, long *total_compressed);167 long *total_uncompressed, long *total_compressed); 168 168 #endif 169 169 static unsigned int hash_fn(const char *s, int hashtab_mask); … … 175 175 int i, j; 176 176 177 word[wordpos++] = 0; /* word's trailing null */177 word[wordpos++] = 0; /* word's trailing null */ 178 178 179 179 /* Don't bother putting few-letter words in the table */ … … 192 192 if (words[i]) 193 193 if (strcmp(word, words[i]) == 0) { 194 *b++ = MARKER_CHAR;195 *b++ = (i >> 8) | TABLE_FLAG;196 *b++ = i & 0xFF;197 return;194 *b++ = MARKER_CHAR; 195 *b++ = (i >> 8) | TABLE_FLAG; 196 *b++ = i & 0xFF; 197 return; 198 198 } 199 199 /* not in table, add to it */ 200 200 201 201 if ((i & 0xFF) == 0) { 202 i++; /* make sure we don't have a null in the message */202 i++; /* make sure we don't have a null in the message */ 203 203 j++; 204 204 } … … 228 228 *b++ = i & 0xFF; 229 229 230 } /* end of output_previous_word */230 } /* end of output_previous_word */ 231 231 232 232 /** Word-compress a string. … … 254 254 /* break up input into words */ 255 255 while (*p) { 256 if (! (isdigit(*p) || isalpha(*p)) || wordpos >= MAXWORDS) {256 if (!isalnum(*p) || wordpos >= MAXWORDS) { 257 257 if (wordpos) { 258 word[wordpos++] = *p;/* add trailing punctuation */259 output_previous_word();260 wordpos = 0;258 word[wordpos++] = *p; /* add trailing punctuation */ 259 output_previous_word(); 260 wordpos = 0; 261 261 } else 262 *b++ = *p;262 *b++ = *p; 263 263 } else 264 264 word[wordpos++] = *p; … … 269 269 output_previous_word(); 270 270 271 *b = 0; /* trailing null */271 *b = 0; /* trailing null */ 272 272 273 273 #ifdef COMP_STATS 274 total_comp += u_strlen(buf); /* calculate size of compressed text */275 total_uncomp += strlen(s); /* calculate size of uncompressed text */274 total_comp += u_strlen(buf); /* calculate size of compressed text */ 275 total_uncomp += strlen(s); /* calculate size of uncompressed text */ 276 276 #endif 277 277 278 278 return u_strdup(buf); 279 } /* end of compress; */279 } /* end of compress; */ 280 280 281 281 … … 315 315 i = ((c & TABLE_MASK) << 8) | *(++p); 316 316 if (i >= MAXTABLE || words[i] == NULL) { 317 static int panicking = 0;318 if (panicking) {319 fprintf(stderr,320 "Error in string decompression occurred during panic dump.\n");321 exit(1);322 } else {323 panicking = 1;/* don't panic from within panic */324 fprintf(stderr, "Error in string decompression, i = %i\n", i);325 mush_panic("Fatal error in decompression");326 }317 static int panicking = 0; 318 if (panicking) { 319 fprintf(stderr, 320 "Error in string decompression occurred during panic dump.\n"); 321 exit(1); 322 } else { 323 panicking = 1; /* don't panic from within panic */ 324 fprintf(stderr, "Error in string decompression, i = %i\n", i); 325 mush_panic("Fatal error in decompression"); 326 } 327 327 } 328 328 strncpy((char *) b, words[i], words_len[i]); … … 333 333 } 334 334 335 *b++ = 0; /* trailing null */335 *b++ = 0; /* trailing null */ 336 336 337 337 return buf; 338 338 339 } /* end of uncompress; */339 } /* end of uncompress; */ 340 340 341 341 /** Word-uncompress a string, allocating memory. … … 378 378 void 379 379 compress_stats(long *entries, long *mem_used, long *total_uncompressed, 380 long *total_compressed)380 long *total_compressed) 381 381 { 382 382
