[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.4 and 1.5

version 1.4, 2009/03/31 13:50:19 version 1.5, 2009/04/02 06:51:44
Line 16 
Line 16 
  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR   * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  * PERFORMANCE OF THIS SOFTWARE.   * PERFORMANCE OF THIS SOFTWARE.
  */   */
   #include <assert.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
   
 #include "libman.h"  #include "libman.h"
   
   
 /* ARGUSED */  /* ARGUSED */
 void  void
 man_hash_free(void *htab)  man_hash_free(void *htab)
 {  {
   
         /* Do nothing. */          free(htab);
 }  }
   
   
Line 34  man_hash_free(void *htab)
Line 36  man_hash_free(void *htab)
 void *  void *
 man_hash_alloc(void)  man_hash_alloc(void)
 {  {
           int             *htab;
           int              i, j, x;
   
         /* Do nothing. */          htab = calloc(26 * 4, sizeof(int));
         return(NULL);          if (NULL == htab)
                   return(NULL);
   
           for (i = 1; i < MAN_MAX; i++) {
                   x = man_macronames[i][0];
   
                   assert((x >= 65 && x <= 90) ||
                                   (x >= 97 && x <= 122));
   
                   x -= (x <= 90) ? 65 : 97;
                   x *= 4;
   
                   for (j = 0; j < 4; j++)
                           if (0 == htab[x + j]) {
                                   htab[x + j] = i;
                                   break;
                           }
   
                   assert(j < 4);
           }
   
           return((void *)htab);
 }  }
   
   
 int  int
 man_hash_find(const void *arg, const char *tmp)  man_hash_find(const void *arg, const char *tmp)
 {  {
         int              i;          int              x, i, tok;
           const int       *htab;
   
         /* TODO */          htab = (const int *)arg;
   
         for (i = 0; i < MAN_MAX; i++)          if (0 == (x = tmp[0]))
                 if (0 == strcmp(tmp, man_macronames[i]))                  return(MAN_MAX);
                         return(i);          if ( ! ((x >= 65 && x <= 90) || (x >= 97 && x <= 122)))
                   return(MAN_MAX);
   
           x -= (x <= 90) ? 65 : 97;
           x *= 4;
   
           for (i = 0; i < 4; i++) {
                   if (0 == (tok = htab[x + i]))
                           return(MAN_MAX);
                   if (0 == strcmp(tmp, man_macronames[tok]))
                           return(tok);
           }
   
         return(MAN_MAX);          return(MAN_MAX);
 }  }

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

CVSweb