PennMUSH Community
Show
Ignore:
Timestamp:
06/12/07 15:21:47 (1 year ago)
Author:
shawnw
Message:

1.8.3p3

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 1.8.3/trunk/src/comp_w8.c

    r846 r919  
    129129#include "confmagic.h" 
    130130 
    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 */ 
    140140 
    141141/* Table of words */ 
     
    165165#ifdef COMP_STATS 
    166166void compress_stats(long *entries, long *mem_used, 
    167            long *total_uncompressed, long *total_compressed); 
     167                    long *total_uncompressed, long *total_compressed); 
    168168#endif 
    169169static unsigned int hash_fn(const char *s, int hashtab_mask); 
     
    175175  int i, j; 
    176176 
    177   word[wordpos++] = 0;     /* word's trailing null */ 
     177  word[wordpos++] = 0;          /* word's trailing null */ 
    178178 
    179179/* Don't bother putting few-letter words in the table */ 
     
    192192    if (words[i]) 
    193193      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; 
    198198      } 
    199199/* not in table, add to it */ 
    200200 
    201201  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 */ 
    203203    j++; 
    204204  } 
     
    228228  *b++ = i & 0xFF; 
    229229 
    230 }              /* end of output_previous_word */ 
     230}                               /* end of output_previous_word */ 
    231231 
    232232/** Word-compress a string. 
     
    254254/* break up input into words */ 
    255255  while (*p) { 
    256     if (!(isdigit(*p) || isalpha(*p)) || wordpos >= MAXWORDS) { 
     256    if (!isalnum(*p) || wordpos >= MAXWORDS) { 
    257257      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; 
    261261      } else 
    262    *b++ = *p; 
     262        *b++ = *p; 
    263263    } else 
    264264      word[wordpos++] = *p; 
     
    269269    output_previous_word(); 
    270270 
    271   *b = 0;          /* trailing null */ 
     271  *b = 0;                       /* trailing null */ 
    272272 
    273273#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 */ 
    276276#endif 
    277277 
    278278  return u_strdup(buf); 
    279 }              /* end of compress; */ 
     279}                               /* end of compress; */ 
    280280 
    281281 
     
    315315      i = ((c & TABLE_MASK) << 8) | *(++p); 
    316316      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       
    327327      } 
    328328      strncpy((char *) b, words[i], words_len[i]); 
     
    333333  } 
    334334 
    335   *b++ = 0;            /* trailing null */ 
     335  *b++ = 0;                     /* trailing null */ 
    336336 
    337337  return buf; 
    338338 
    339 }              /* end of uncompress; */ 
     339}                               /* end of uncompress; */ 
    340340 
    341341/** Word-uncompress a string, allocating memory. 
     
    378378void 
    379379compress_stats(long *entries, long *mem_used, long *total_uncompressed, 
    380           long *total_compressed) 
     380               long *total_compressed) 
    381381{ 
    382382