home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume8 / sp / part02 / sp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1987-02-19  |  3.5 KB  |  92 lines

  1. /* sp.h */
  2. /* vi: set tabstop=4 : */
  3.  
  4. /*
  5.  * A deleted dbm entry is denoted by a dsize of zero
  6.  */
  7. #define IS_DELETED(C)        (C.dsize == 0)
  8.  
  9. /*
  10.  * Because the soundex code (part of the key) includes the first character of
  11.  * the word, we don't need to store the first character again with the content.
  12.  * To do this we treat the first byte of the content stored in the dbm
  13.  * specially:  we rip off the two high order bits of the first byte of
  14.  * the content and therefore have to restrict the value of the second
  15.  * character of the word.  We use 'a' == 0, 'z' == 25, 'A' == 26, 'Z' == 51.
  16.  * See spchar_map[] (misc.c) for the mapping of codes 52 through 63.
  17.  * This behaviour is isolated in tospchar() and fromspchar().
  18.  * If spchar_map is changed you should change the man page too.
  19.  *
  20.  * The word can be reconstructed by extracting the first character of the word
  21.  * from the soundex code and then looking at the first byte of the content.
  22.  * If the UPPER_CHAR bit is on in the first byte of the content then the first
  23.  * character of the word should be upper case.
  24.  * The length of the content reflects the actual number of bytes stored in the
  25.  * dbm.  Words that have been deleted from the dbm are stored with a length of
  26.  * zero.  Because of this, words of length 1 are treated differently: they are
  27.  * stored with a length of 1 and with the SINGLE_CHAR bit set.  Words with
  28.  * original length > 1 will have (length - 1) bytes stored in the content.
  29.  * Clear?
  30.  */
  31. #define IS_VALID(w)        (isalpha(*w) && (*(w+1) == '\0' || isalpha(*(w+1)) \
  32.                                         || tospchar(*(w+1)) != '\0'))
  33. #define UPPER_CHAR        0200    /* 1st char of word is upper case */
  34. #define SINGLE_CHAR        0100    /* single char word */
  35. #define MASK_CHAR        0077    /* mask out the indicator bits */
  36. #define QUOTE_CHAR        0064    /* (52) code for single quote */
  37. #define AMPER_CHAR        0065    /* (53) for ampersand */
  38. #define PERIOD_CHAR        0066    /* (54) for period */
  39. #define SPACE_CHAR        0067    /* (55) for blank */
  40.  
  41. /*
  42.  * Map for first byte of dbm content (special characters)
  43.  * Terminated by a null entry
  44.  */
  45. struct spchar_map {
  46.     char spchar;
  47.     char code;
  48. };
  49.  
  50. #define MAXDICT            10        /* Max number of dictionaries to use */
  51. #define MAXWORDLEN        50        /* Max word length */
  52. #define MAXWORDS        400        /* Max number of words in one sp query */
  53. #define WORDSPACE        20480    /* Max space used words for one sp query */
  54.  
  55. /*
  56.  * This is the default path used by sp to find dictionaries
  57.  * Adjust for local conditions
  58.  */
  59. #define DEFAULT_SPPATH    "/usr/local/lib/sp.dict.1:/usr/local/lib/sp.dict.2"
  60.  
  61. /*
  62.  * The following must be the maximum value containable in the count part of
  63.  * a key.
  64.  * It must be always be less than: (the maximum positive value that can be
  65.  * contained in an int) - 1
  66.  * This value imposes a limit on the number of words in a dictionary having the
  67.  * same soundex code.  For /usr/dict/words (~25K words), a count of 255 is
  68.  * sufficient.  Larger dictionaries will need more.  In any case you can
  69.  * always just make another dictionary and split up your words.
  70.  * You might want to adjust MAXWORDS and WORDSPACE (above) to reflect MAXCOUNT
  71.  * if you've got plenty of memory.
  72.  */
  73. #define MAXCOUNT    1023                /* 2^10 - 1 */
  74.  
  75. /*
  76.  * The key used by dbm looks like this:
  77.  *
  78.  *     <10 bits>    <5 bits>    <9 bits>
  79.  *    counter        first char    soundex
  80.  *
  81.  * A soundex value is treated as a base 7 number (maximum is 666, base 7).
  82.  */
  83. #define KEYSIZE        3                    /* in bytes */
  84. typedef unsigned char key_t;
  85.  
  86. #define BAD_WORD    -1                    /* This must be an illegal Soundex */
  87. #define NO_MATCH     0
  88. #define MATCHED         1
  89.  
  90. extern char soundex_code_map[];
  91.  
  92.