home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_200 / 217_01 / hy.c < prev    next >
Text File  |  1979-12-31  |  2KB  |  77 lines

  1. /*
  2.  * hy.c
  3.  *
  4.  * Mark words for hyphenation.
  5.  * Output is one word per line.
  6.  * May be used as a filter.
  7.  *
  8.  * Not too useful unless a decent exception list is added
  9.  * to the hyphenation processing.
  10.  *
  11.  * Bob Denny
  12.  * 28-Mar-82
  13.  */
  14.  
  15. /*)BUILD    $(PROGRAM)    = hy
  16.         $(FILES)    = { hy hyphen digram suffix }
  17.         $(TKBOPTIONS)    = {
  18.             STACK    = 256
  19.             TASK    = ...HYP
  20.             ACTFIL    = 3
  21.             UNITS    = 3
  22.         }
  23. */
  24.  
  25. #include <stdio.h>
  26. #include <ctype.h>
  27.  
  28. #define    EOS    0
  29.  
  30. /*
  31.  * Hyphenation marker character
  32.  */
  33. #define HYCH '-'
  34.  
  35. char *wdstart, *wdend;            /* Shared with hyphen()        */
  36. char *hyptr[16];            /* Hyphenation locations    */
  37.  
  38. static char intext[133];        /* Input text line        */
  39. static char iwbuf[32];            /* Input word buffer        */
  40. static char owbuf[48];            /* Marked output word        */
  41.  
  42. main()
  43. {
  44.     int        i;        /* Hyphen buffer index        */
  45.     register char    *tp;        /* Text pointer            */
  46.     register char    *wp;        /* Input word pointer        */
  47.     register char    *op;        /* Output word pointer        */
  48.  
  49.     while((tp = gets(intext)) != NULL) {
  50.         while (*tp != EOS) {
  51.         while (isspace(*tp))    /* Skip over whitespace        */
  52.             tp++;        /* between words        */
  53.         if (*tp == EOS)
  54.             break;
  55.         for (wp = iwbuf; (*wp++ = *tp) != EOS && !isspace(*tp); tp++)
  56.             ;
  57.         *--wp = EOS;        /* Terminate word        */
  58.         if (wp == iwbuf)    /* Ignore null words        */
  59.             continue;
  60.             hyphen(iwbuf);        /* Get hyphenation pointers    */
  61.         i = 0;            /* Start with 1st pointer    */
  62.         op = owbuf;        /* Initialize output pointer    */
  63.         wp = iwbuf;
  64.         while ((*op++ = tolower(*wp)) != EOS) {
  65.             wp++;        /* (no side effect in tolower)    */
  66.             if (hyptr[i] == wp) {
  67.             /*
  68.              * Mark hyphenation point
  69.              */
  70.             *op++ = HYCH;
  71.             i++;        /* Next hyphenation pointer    */
  72.             }
  73.         }
  74.         puts(owbuf);            /* Write the marked word    */
  75.         }
  76.     }
  77. }