[BACK]Return to man_hash.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Diff for /mandoc/Attic/man_hash.c between version 1.11 and 1.12

version 1.11, 2009/08/19 09:14:50 version 1.12, 2009/09/16 14:40:56
Line 15 
Line 15 
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.   * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */   */
 #include <assert.h>  #include <assert.h>
   #include <limits.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
   
 #include "libman.h"  #include "libman.h"
   
   
 /* ARGUSED */  static  unsigned char   table[26 * 6];
 void  
 man_hash_free(void *htab)  
 {  
   
         free(htab);  
 }  
   
   void
 /* ARGUSED */  man_hash_init(void)
 void *  
 man_hash_alloc(void)  
 {  {
         int             *htab;  
         int              i, j, x;          int              i, j, x;
   
         /* Initialised to -1. */          memset(table, UCHAR_MAX, sizeof(table));
   
         htab = malloc(26 * 6 * sizeof(int));  
         if (NULL == htab)  
                 return(NULL);  
         for (i = 0; i < 26 * 6; i++)  
                 htab[i] = -1;  
   
         for (i = 0; i < MAN_MAX; i++) {          for (i = 0; i < MAN_MAX; i++) {
                 x = man_macronames[i][0];                  x = man_macronames[i][0];
   
                 assert((x >= 65 && x <= 90) ||                  assert((x >= 65 && x <= 90) ||
                                 (x >= 97 && x <= 122));                                  (x >= 97 && x <= 122));
   
Line 55  man_hash_alloc(void)
Line 41  man_hash_alloc(void)
                 x *= 6;                  x *= 6;
   
                 for (j = 0; j < 6; j++)                  for (j = 0; j < 6; j++)
                         if (-1 == htab[x + j]) {                          if (UCHAR_MAX == table[x + j]) {
                                 htab[x + j] = i;                                  table[x + j] = i;
                                 break;                                  break;
                         }                          }
   
                 assert(j < 6);                  assert(j < 6);
         }          }
   
         return((void *)htab);  
 }  }
   
   
 int  int
 man_hash_find(const void *arg, const char *tmp)  man_hash_find(const char *tmp)
 {  {
         int              x, i, tok;          int              x, i, tok;
         const int       *htab;  
   
         htab = (const int *)arg;  
   
         if (0 == (x = tmp[0]))          if (0 == (x = tmp[0]))
                 return(MAN_MAX);                  return(MAN_MAX);
         if ( ! ((x >= 65 && x <= 90) || (x >= 97 && x <= 122)))          if ( ! ((x >= 65 && x <= 90) || (x >= 97 && x <= 122)))
Line 84  man_hash_find(const void *arg, const char *tmp)
Line 64  man_hash_find(const void *arg, const char *tmp)
         x *= 6;          x *= 6;
   
         for (i = 0; i < 6; i++) {          for (i = 0; i < 6; i++) {
                 if (-1 == (tok = htab[x + i]))                  if (UCHAR_MAX == (tok = table[x + i]))
                         return(MAN_MAX);                          return(MAN_MAX);
                 if (0 == strcmp(tmp, man_macronames[tok]))                  if (0 == strcmp(tmp, man_macronames[tok]))
                         return(tok);                          return(tok);
Line 92  man_hash_find(const void *arg, const char *tmp)
Line 72  man_hash_find(const void *arg, const char *tmp)
   
         return(MAN_MAX);          return(MAN_MAX);
 }  }
   

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.12

CVSweb