home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Resources / System / BoingBag1 / Contributions / Workbench / RexxArpLib3p6 / src / whhtable.c < prev    next >
C/C++ Source or Header  |  1998-06-21  |  2KB  |  83 lines

  1. /** Whhtable.c
  2.   *
  3.   *   DESCRIPTION:
  4.   *   ===========
  5.   *
  6.   * This function finds the index associated with the function
  7.   * name given in the argument string.
  8.   *
  9.   * It uses a hashing function that was found using the program
  10.   * 'hash' by W.G.J. Langeveld.
  11.   *
  12.   *   SYNOPSIS:
  13.   *   =========
  14.   *
  15.   * index = whhtable_index(name)
  16.   *
  17.   * int index the index of the function, -1 if not found.
  18.   * char *name name of function.
  19.   *
  20.   *    Implement the Amiga environment access functions for rexxarplib.library.
  21.   *
  22.   *   AUTHOR/DATE:  W.G.J. Langeveld, November 1987.
  23.   *   ============
  24.   *
  25.   *    CURRENT VERSION:
  26.   *
  27.   *    This version has been converted to SAS C 6.5 format. It has been modified
  28.   *    for modern definition sequences for ANSI compilation. This no longer works
  29.   *    with OS versions prior to 2.04.
  30.   *
  31.   *   AUTHOR/DATE:  Joanne Dow, jdow@bix.com, June 1998.
  32.   *   ============
  33.   *
  34.   **/
  35.  
  36. #include <exec/types.h>
  37. //#include "ralprotos.h"
  38. #include <stdio.h>
  39. #include <stdlib.h>
  40. #include <string.h>
  41. #include <ctype.h>
  42.  
  43. static int hash_table[] = 
  44. {
  45.     14,   2,   0,  -1,  37,  -1,  -1,  17,  32,   3,
  46.     11,  24,  -1,  21,  18,  29,  -1,  39,  -1,  -1,
  47.     -1,  -1,   5,   4,  -1,  -1,  15,  -1,  27,  36,
  48.     -1,  -1,  -1,  28,  42,  -1,  -1,  -1,  -1,  16,
  49.     -1,  12,   8,  45,  -1,  -1,  26,  23,  -1,  -1,
  50.     -1,  38,  -1,  -1,  40,  -1,  44,  -1,   1,  -1,
  51.     -1,   6,  -1,  43,  -1,  -1,  34,  31,  -1,  -1,
  52.     -1,  33,  41,  -1,  -1,  -1,  22,  20,  -1,  -1,
  53.     -1,  -1,  -1,  -1,   7,  -1,  -1,  -1,  -1,  30,
  54.     -1,  -1,  10,  -1,  -1,  -1,  -1,  13,  25,   9,
  55.     -1,  -1,  19,  -1,  -1,  -1,  -1,  -1,  -1,  35,
  56.     -1,  -1,  -1,  
  57. };
  58.  
  59.  
  60. int whhtable_index( char *s );
  61. static int hash(unsigned char *);
  62.  
  63. int whhtable_index( char *s )
  64. {
  65.     return(hash_table[hash(s)]);
  66. }
  67.  
  68. static int hash( unsigned char *s )
  69. {
  70.     register int res;
  71.     register unsigned char *sp;
  72.     register unsigned int c;
  73.     
  74.     res = strlen(s);
  75.     
  76.     for (sp = s; *sp; sp++ ) 
  77.     {
  78.         c = toupper(*sp);
  79.         res = ((res * 110 + c ) & 0x7ff);
  80.     }
  81.     return(res % 113);
  82. }
  83.