#ifndef lint static char rcsid[] = "$Header: lowtext.c,v 1.3 86/04/25 17:15:14 root Exp $"; #endif #include "fmtr.h" int ti_val; int e_of_sen; /* leadbl() deals with leading blanks, causes break, then sets * ti_val to number of blanks, unless line is blank. Then pulls * line forewards, so text() now has line starting with text, with * ti_val containing the needed indent. */ leadbl(line) char *line; { char *ip; n_brk(); ip = line; while (*ip == ' ') ip++; if (*ip != '\n') ti_val += ip - line; (void) strcpy(line, ip); } /* n_brk() causes a break */ void n_brk() { if (outp > outbuf) { outp--; /* back off from EOS */ while (*outp == ' ' && outp >= outbuf) /* remove trailing blanks */ outp--; *++outp = '\0'; put(outbuf); } outp = outbuf; } /* * getword gets the next word plus trailing space * from the array pointed to by pline and * returns it in that pointed at by word. If there are * no further words on that line, it returns NULL. * It returns a pointer to the start of the next word. */ char *getword(pline, word) char *pline, *word; { if (*pline == '\0') { *word = '\0'; return(NULL); } while (*pline != ' ' && *pline != '\0') { if (*pline == '\\' && isspace(pline[1])) /* get escaped space */ *word++ = *pline++; *word++ = *pline++; } /* are we at end of sentence? */ if (*pline == '\0' || (*pline == ' ' && *(pline + 1) == ' ')) { char *cptmp = pline; while (any(*--cptmp, "\"']})")) ; if (any(*cptmp, ".:!?")) e_of_sen = 1; else e_of_sen = 0; } /* if at end of line, add one space (two if end of sentence. * otherwise get trailing spaces. */ if (*pline == '\0') { *word++ = ' '; if (e_of_sen) *word++ = ' '; } while (*pline == ' ') *word++ = *pline++; *word = '\0'; return(pline); } putword(word) /* put word into output buffer */ char *word; { int s, t; /* not needed, but greatly simplify if */ t = strlen(word) - 1; /* -1 for one trailing blank */ s = outp - outbuf; if (s + t <= llength - ti_val) { for (; *word; *outp++ = *word++) ; } else { n_brk(); for (; *word; *outp++ = *word++) ; } if (e_of_sen && b_flag) { n_brk(); e_of_sen = 0; } } put(line) /* output routine, separate as is more complex in original */ char *line; { int i; for (i = 1; i <= ti_val; i++) putchar(' '); ti_val = 0; puts(line); } any(ch, string) /* returns true if character is in string */ char ch; char *string; { while (*string) if (ch == *string++) return(1); return(0); }