home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_progs / prog-asm / talincod.lha / talincode.lha / hints.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-12  |  3.3 KB  |  73 lines

  1. /* ============================================================================ *
  2.                 hints.c - functions for computing hint bits
  3.                                Written by Talin.
  4.                            © 1991 The Dreamers Guild
  5.  * ============================================================================ */
  6.  
  7. #include "database.h"
  8.  
  9. #define NUMSYMBOLS        27                        /* number of distinct symbols    */
  10. #define OTHER_SYMBOL    26                        /* any non-alpha character        */
  11.  
  12. UBYTE hint_table[NUMSYMBOLS*NUMSYMBOLS] = {
  13.      0, 0,-1,-1, 0, 1,-1, 1, 2, 2, 2,-1,-1,-1, 2,-1, 2,-1,-1,-1, 3, 3, 4, 4, 5, 5, 5,
  14.      5, 5, 5, 5,-1, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,10,10,10,
  15.     -1,10,10,10,-1,10,10,-1,11,11,11,12,12,12,-1,12,12,13,13,-1,14,14,14,14,14,14,14,
  16.     15,15,15,15,-1,15,15,15,-1,16,16,16,16,16,17,17,17,17,18,18,18,18,18,18,19,19,19,
  17.     -1,19,-1,-1,-1,19,20,20,20,20,20,-1,-1,-1,21,21,21,-1,-1,-1,21,22,22,-1,23,23,23,
  18.     23,23,23,23,24,25,25,25,26,26,26,26,26,26,-1,26,26,27,27,27,28,28,28,28,28,28,28,
  19.     28,28,28,29,-1,29,29,29,30,30,30,30,30,30,31,31,31,32,32,32,32,33,33,33,33,33,33,
  20.     -1,33,33,33,-1,33,33,33,-1,33,33,33,33,33,34,34,34,34,34,35,35,35,35,35,35,35,35,
  21.     36,36,-1,37,-1,38,39,39,39,39,39,-1,-1,-1,-1,40,40,40,-1,-1,40,41,41,41,41,42,42,
  22.     42,42,42,42,42,42,42,42,42,42,42,42,42,42,43,43,43,43,43,43,43,43,43,43,43,43,43,
  23.     43,43,43,43,44,44,44,44,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,
  24.     -1,46,46,46,-1,46,47,47,-1,47,47,-1,47,47,-1,47,47,47,48,48,49,49,49,49,50,50,50,
  25.     -1,50,50,50,-1,50,50,50,51,51,51,52,52,52,-1,-1,52,52,53,53,53,53,53,53,53,53,53,
  26.     -1,53,-1,-1,-1,54,-1,54,-1,54,54,54,54,55,-1,55,55,55,-1,-1,55,56,56,56,56,56,56,
  27.     56,57,57,58,58,-1,59,59,59,59,59,-1,-1,-1,60,61,61,-1,62,-1,-1,62,-1,62,62,62,62,
  28.     63,63,63,63,-1,63,63,64,65,65,65,-1,65,65,-1,66,66,-1,66,67,67,67,67,67,67,67,67,
  29.     67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,67,68,68,68,68,68,68,68,
  30.     -1,68,68,69,-1,69,69,69,-1,69,70,70,71,71,-1,71,71,72,-1,-1,73,73,73,73,74,74,74,
  31.     74,75,75,75,-1,75,75,-1,-1,75,76,76,76,76,-1,-1,76,76,-1,-1,77,77,77,77,78,78,78,
  32.     -1,78,78,78,-1,78,78,-1,-1,78,78,78,79,79,-1,79,79,-1,80,81,82,82,82,82,82,83,83,
  33.     83,83,84,84,84,84,85,85,85,85,85,-1,86,-1,86,86,86,-1,-1,-1,86,86,86,86,86,86,86,
  34.     87,87,87,87,-1,87,87,87,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,88,
  35.     89,89,89,89,-1,89,89,90,-1,90,90,90,90,90,91,91,91,91,91,91,91,91,91,91,91,91,91,
  36.     91,91,91,91,92,92,92,92,92,92,92,92,92,92,92,92,92,92,92,92,92,92,92,92,93,93,93,
  37.     93,93,93,93,93,93,93,93,93,93,93,93,93,93,94,94,94,94,95,95,95,95,95,95,95,95,95,
  38.     95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,
  39.     95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,
  40. };
  41.  
  42.     /* REM: also convert foreign symbols */
  43.     /* REM: Mac uses a different character set -- we'll need to handle the
  44.         problem of ISO latin characters.
  45.     */
  46.  
  47. convert_symbol(int c)
  48. {    if (isalpha(c)) return (toupper(c) - 'A');
  49.     else return OTHER_SYMBOL;
  50. }
  51.  
  52. compute_hints(char *buffer,int length,Hint *h)
  53. {    WORD                c1,
  54.                         c2;
  55.  
  56.         /* REM: Should convert this to assembly. */
  57.  
  58.     zero(h,sizeof *h);
  59.  
  60.     c1 = c2 = OTHER_SYMBOL;
  61.  
  62.     while (length--)
  63.     {    c2 = convert_symbol(*buffer++);
  64.         if (c1 != OTHER_SYMBOL && c2 != OTHER_SYMBOL)
  65.         {    int bit = hint_table[c1 * NUMSYMBOLS + c2];
  66.             if (bit < HINTSIZE)
  67.             {    *h[bit >> 5] |= (1 << (bit & 31));
  68.             }
  69.         }
  70.         c1 = c2;
  71.     }
  72. }
  73.