home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume4 / fmtr / lowtext.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  2.4 KB  |  122 lines

  1. #ifndef lint
  2. static char rcsid[] = "$Header: lowtext.c,v 1.3 86/04/25 17:15:14 root Exp $";
  3. #endif
  4.  
  5. #include "fmtr.h"
  6.  
  7. int ti_val;
  8.  
  9. /*  leadbl() deals with leading blanks, causes break, then sets
  10.  *  ti_val to number of blanks, unless line is blank.  Then pulls
  11.  *  line forewards, so text() now has line starting with text, with
  12.  *  ti_val containing the needed indent.
  13.  */
  14.  
  15. leadbl(line)
  16. char *line;
  17. {
  18.     char *ip;
  19.  
  20.     n_brk();
  21.  
  22.     ip = line;
  23.     while (*ip == ' ')
  24.     ip++;
  25.     if (*ip != '\n')
  26.     ti_val += ip - line;
  27.     (void) strcpy(line, ip);
  28. }
  29.  
  30. /* n_brk() causes a break */
  31.  
  32. void n_brk()
  33. {
  34.     if (outp > outbuf) {
  35.         outp--;    /* back off from EOS */
  36.     while (*outp == ' ' && outp >= outbuf)    /* remove trailing blanks */
  37.         outp--;
  38.     *++outp  = '\0';
  39.     put(outbuf);
  40.     }
  41.     outp = outbuf;
  42. }
  43.  
  44. /*
  45.  *    getword gets the next word plus trailing space
  46.  *      from the array pointed to by pline and
  47.  *    returns it in that pointed at by word.  If there are
  48.  *    no further words on that line, it returns NULL.
  49.  *    It returns a pointer to the start of the next word.
  50.  */
  51.  
  52. char *getword(pline, word)
  53. char *pline, *word;
  54. {
  55.     if (*pline == '\0') {
  56.     *word = '\0';
  57.     return(NULL);
  58.     }
  59.  
  60.     while (*pline != ' ' && *pline != '\0') {
  61.     if (*pline == '\\' && isspace(pline[1])) /* get escaped space in word */
  62.         *word++ = *pline++;
  63.         *word++ = *pline++;
  64.     }
  65.  
  66.     /*  get trailing spaces, and guarantee spaces at end of line;
  67.      *  normally one but two at end of sentence.
  68.      */
  69.  
  70.     if (*pline == '\0') {
  71.     char *cptmp = pline;
  72.  
  73.     *word++ = ' ';
  74.     while (any(*--cptmp, "\"']})"))
  75.         ;
  76.     if (any(*cptmp, ".:!?"))
  77.         *word++ = ' ';
  78.     }
  79.     while (*pline == ' ')
  80.     *word++ = *pline++;
  81.     *word = '\0';
  82.     return(pline);
  83. }
  84.  
  85. putword(word)    /* put word into output buffer */
  86. char *word;
  87. {
  88.     int s, t;    /* not needed, but greatly simplify if */
  89.  
  90.     t = strlen(word) - 1;    /* -1 for one trailing blank */
  91.     s = outp - outbuf;
  92.     if (s + t <= llength - ti_val) {
  93.     for (; *word; *outp++ = *word++)
  94.         ;
  95.     return;
  96.     }
  97.     n_brk();
  98.     for (; *word; *outp++ = *word++)
  99.     ;
  100. }
  101.  
  102. put(line)    /* output routine, separate as is more complex in original */
  103. char *line;
  104. {
  105.     int i;
  106.  
  107.     for (i = 1; i <= ti_val; i++)
  108.     putchar(' ');
  109.     ti_val = 0;
  110.     puts(line);
  111. }
  112.  
  113. any(ch, string)    /* returns true if character is in string */
  114. char ch;
  115. char *string;
  116. {
  117.     while (*string)
  118.     if (ch == *string++)
  119.         return(1);
  120.     return(0);
  121. }
  122.