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

  1. /* -*- Mode:Text -*- */
  2. #ifndef lint
  3. static char Rcs_Id[] =
  4.     "$Id: unsq.c,v 1.8 90/12/31 00:59:28 geoff Exp $";
  5. #endif
  6.  
  7. /*
  8.  * $Log:    unsq.c,v $
  9.  * Revision 1.8  90/12/31  00:59:28  geoff
  10.  * Reformat to follow a consistent convention throughout ispell
  11.  * 
  12.  * Revision 1.7  89/12/27  03:19:23  geoff
  13.  * Move all messages to msgs.h so they can be reconfigured
  14.  * 
  15.  * Revision 1.6  89/04/28  01:18:03  geoff
  16.  * Change Header to Id;  nobody cares about my pathnames.
  17.  * 
  18.  * Revision 1.5  88/11/25  19:54:56  geoff
  19.  * Get rid of some unused variables.
  20.  * 
  21.  * Revision 1.4  88/11/16  02:20:50  geoff
  22.  * Make the "Unexpected EOF" message come out only when the EOF is in the
  23.  * middle of a line.  Previously, it was issued only when the EOF was *not*
  24.  * in the middle of a line.
  25.  * 
  26.  * Revision 1.3  88/03/27  01:06:59  geoff
  27.  * Fix to use the ASCII-encoded count characters that sq now produces.
  28.  * 
  29.  * Revision 1.2  88/03/13  00:58:24  geoff
  30.  * Add ID keywords
  31.  * 
  32.  */
  33.  
  34. #include <stdio.h>
  35. #include "msgs.h"
  36.  
  37. /*
  38.  * The following table encodes prefix sizes as a single character.  A
  39.  * matching table will be found in sq.c.
  40.  */
  41. static char size_encodings[] =
  42.     {
  43.     '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',    /* 00-09 */
  44.     'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',    /* 10-19 */
  45.     'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',    /* 20-29 */
  46.     'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',    /* 30-39 */
  47.     'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',    /* 40-49 */
  48.     'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',    /* 50-59 */
  49.     'y', 'z'                        /* 60-61 */
  50.     };
  51.  
  52. #define MAX_PREFIX    (sizeof (size_encodings) - 1)
  53.  
  54. main ()
  55.     {
  56.     char        word[257];
  57.     static char        prev[257] = "";
  58.  
  59.     while (!expand (word, prev))
  60.         puts (word);
  61.     exit(0);
  62.     }
  63.  
  64. expand (word, prev) 
  65.     char *        word;
  66.     char *        prev;
  67.     {
  68.     register char *    wordp;
  69.     register char *    prevp;
  70.     register int    same_count;
  71.     register int    count_char;
  72.  
  73.     count_char = getchar ();
  74.     if (count_char == EOF)
  75.     return(1);
  76.     for (same_count = 0;
  77.       same_count < MAX_PREFIX  &&  size_encodings[same_count] != count_char;
  78.       same_count++)
  79.     ;
  80.     if (same_count == MAX_PREFIX)
  81.     {
  82.     fprintf (stderr, UNSQ_C_BAD_COUNT, count_char);
  83.     exit (1);
  84.     }
  85.     prevp = prev;
  86.     wordp = word;
  87.     while (same_count--)
  88.     *wordp++ = (*prevp++);
  89.     if (gets(wordp) == NULL)
  90.     {
  91.     fprintf(stderr, UNSQ_C_SURPRISE_EOF);
  92.     exit (1);
  93.     }
  94.     strcpy (prev, word);
  95.     return 0 ;
  96.     }
  97.  
  98.