version 1.21, 2010/03/02 00:38:59 |
version 1.22, 2010/03/05 20:46:48 |
|
|
int i; /* current input position in p->buf */ |
int i; /* current input position in p->buf */ |
size_t vis; /* current visual position on output */ |
size_t vis; /* current visual position on output */ |
size_t vbl; /* number of blanks to prepend to output */ |
size_t vbl; /* number of blanks to prepend to output */ |
size_t vsz; /* visual characters to write to output */ |
size_t vend; /* end of word visual position on output */ |
size_t bp; /* visual right border position */ |
size_t bp; /* visual right border position */ |
int j; /* temporary loop index */ |
int j; /* temporary loop index */ |
|
int jhy; /* last hyphen before line overflow */ |
size_t maxvis, mmax; |
size_t maxvis, mmax; |
static int overstep = 0; |
static int overstep = 0; |
|
|
|
|
* breaking the line. |
* breaking the line. |
*/ |
*/ |
|
|
vis = 0; |
|
|
|
/* |
/* |
* If in the standard case (left-justified), then begin with our |
* If in the standard case (left-justified), then begin with our |
* indentation, otherwise (columns, etc.) just start spitting |
* indentation, otherwise (columns, etc.) just start spitting |
|
|
for (j = 0; j < (int)p->offset; j++) |
for (j = 0; j < (int)p->offset; j++) |
putchar(' '); |
putchar(' '); |
|
|
for (i = 0; i < (int)p->col; i++) { |
vis = vend = i = 0; |
|
while (i < (int)p->col) { |
|
|
/* |
/* |
|
* Choose the number of blanks to prepend: no blank at the |
|
* beginning of a line, one between words -- but do not |
|
* actually write them yet. |
|
*/ |
|
vbl = (size_t)(ASCII_EOS == p->buf[i] ? 2 : |
|
(0 == vis ? 0 : 1)); |
|
vis += vbl; |
|
|
|
/* |
* Count up visible word characters. Control sequences |
* Count up visible word characters. Control sequences |
* (starting with the CSI) aren't counted. A space |
* (starting with the CSI) aren't counted. A space |
* generates a non-printing word, which is valid (the |
* generates a non-printing word, which is valid (the |
|
|
*/ |
*/ |
|
|
/* LINTED */ |
/* LINTED */ |
for (j = i, vsz = 0; j < (int)p->col; j++) { |
for (j = i, jhy = 0, vend = vis; j < (int)p->col; j++) { |
if (j && ' ' == p->buf[j]) |
if (j && ' ' == p->buf[j]) |
break; |
break; |
else if (8 == p->buf[j]) |
else if (8 == p->buf[j]) |
vsz--; |
vend--; |
else if (ASCII_EOS != p->buf[j]) |
else if (ASCII_EOS != p->buf[j]) { |
vsz++; |
if (vend > vis && vend < bp && |
|
'-' == p->buf[j]) |
|
jhy = j; |
|
vend++; |
|
} |
} |
} |
|
|
/* |
/* |
* Skip empty words. This happens due to the ASCII_EOS |
* Skip empty words. This happens due to the ASCII_EOS |
* after the end of the final sentence of a paragraph. |
* after the end of the final sentence of a paragraph. |
*/ |
*/ |
if (vsz == 0 && j == (int)p->col) |
if (vend == vis && j == (int)p->col) |
break; |
break; |
|
|
/* |
/* |
* Choose the number of blanks to prepend: no blank at the |
|
* beginning of a line, one between words -- but do not |
|
* actually write them yet. |
|
*/ |
|
vbl = (size_t)(ASCII_EOS == p->buf[i] ? 2 : |
|
(0 == vis ? 0 : 1)); |
|
|
|
/* |
|
* Find out whether we would exceed the right margin. |
* Find out whether we would exceed the right margin. |
* If so, break to the next line. (TODO: hyphenate) |
* If so, break to the next line. (TODO: hyphenate) |
* Otherwise, write the chosen number of blanks now. |
* Otherwise, write the chosen number of blanks now. |
*/ |
*/ |
if (vis && vis + vbl + vsz > bp) { |
if (vend > bp && 0 == jhy) { |
|
vend -= vis; |
putchar('\n'); |
putchar('\n'); |
if (TERMP_NOBREAK & p->flags) { |
if (TERMP_NOBREAK & p->flags) { |
for (j = 0; j < (int)p->rmargin; j++) |
for (j = 0; j < (int)p->rmargin; j++) |
putchar(' '); |
putchar(' '); |
vis = p->rmargin - p->offset; |
vend += p->rmargin - p->offset; |
} else { |
} else { |
for (j = 0; j < (int)p->offset; j++) |
for (j = 0; j < (int)p->offset; j++) |
putchar(' '); |
putchar(' '); |
vis = 0; |
|
} |
} |
/* Remove the overstep width. */ |
/* Remove the overstep width. */ |
bp += (int)/* LINTED */ |
bp += (int)/* LINTED */ |
|
|
} else { |
} else { |
for (j = 0; j < (int)vbl; j++) |
for (j = 0; j < (int)vbl; j++) |
putchar(' '); |
putchar(' '); |
vis += vbl; |
|
} |
} |
|
|
/* |
/* |
* Finally, write out the word. |
* Finally, write out the word. |
*/ |
*/ |
for ( ; i < (int)p->col; i++) { |
for ( ; i < (int)p->col; i++) { |
if (' ' == p->buf[i]) |
if (vend > bp && i > jhy) |
break; |
break; |
|
if (' ' == p->buf[i]) { |
|
i++; |
|
break; |
|
} |
if (ASCII_NBRSP == p->buf[i]) |
if (ASCII_NBRSP == p->buf[i]) |
putchar(' '); |
putchar(' '); |
else if (ASCII_EOS != p->buf[i]) |
else if (ASCII_EOS != p->buf[i]) |
putchar(p->buf[i]); |
putchar(p->buf[i]); |
} |
} |
vis += vsz; |
vis = vend; |
} |
} |
|
|
p->col = 0; |
p->col = 0; |