home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Product / Product.zip / ISPSRC.ZIP / sq.c < prev    next >
C/C++ Source or Header  |  1991-06-18  |  2KB  |  77 lines

  1. /* -*- Mode:Text -*- */
  2. #ifndef lint
  3. static char Rcs_Id[] =
  4.     "$Id: sq.c,v 1.6 90/12/31 00:59:26 geoff Exp $";
  5. #endif
  6.  
  7. /*
  8.  * $Log:    sq.c,v $
  9.  * Revision 1.6  90/12/31  00:59:26  geoff
  10.  * Reformat to follow a consistent convention throughout ispell
  11.  * 
  12.  * Revision 1.5  89/04/28  01:16:59  geoff
  13.  * Change Header to Id;  nobody cares about my pathnames.
  14.  * 
  15.  * Revision 1.4  88/11/25  19:54:17  geoff
  16.  * Get rid of an unused array.
  17.  * 
  18.  * Revision 1.3  88/03/27  01:04:50  geoff
  19.  * Fix to encode prefix sizes as a single printable (alphanumeric)
  20.  * character, rather than using a binary byte.  This loses very little,
  21.  * since it's not likely there are many dictionaries that make heavy use
  22.  * of very long prefixes.  The advantage is that the output is mailable.
  23.  * 
  24.  * Revision 1.2  88/03/13  00:58:20  geoff
  25.  * Add ID keywords
  26.  * 
  27.  */
  28.  
  29. #include <stdio.h>
  30.  
  31. /*
  32.  * The following table encodes prefix sizes as a single character.  A
  33.  * matching table will be found in unsq.c.
  34.  */
  35. static char size_encodings[] =
  36.     {
  37.     '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',    /* 00-09 */
  38.     'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',    /* 10-19 */
  39.     'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',    /* 20-29 */
  40.     'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',    /* 30-39 */
  41.     'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',    /* 40-49 */
  42.     'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',    /* 50-59 */
  43.     'y', 'z'                        /* 60-61 */
  44.     };
  45.  
  46. #define MAX_PREFIX    (sizeof (size_encodings) - 1)
  47.  
  48. main ()
  49.     {
  50.     char    word[257];
  51.     static char    prev[257] = "";
  52.  
  53.     while (gets (word) != NULL)
  54.     trunc (word, prev);
  55.     exit(0);
  56.     }
  57.  
  58. trunc (word, prev) 
  59.     char *        word;
  60.     char *        prev;
  61.     {
  62.     register char *    wordp;
  63.     register char *    prevp;
  64.     register int    same_count;
  65.  
  66.     wordp = word;
  67.     prevp = prev;
  68.     for (same_count = 0;  *wordp == *prevp++;  ++wordp, ++same_count)
  69.     ;
  70.     if (same_count>MAX_PREFIX)
  71.     same_count = MAX_PREFIX;
  72.     putchar (size_encodings[same_count]);
  73.     puts (wordp);
  74.     strcpy (prev, word);
  75.     }
  76.  
  77.