version 1.32, 2010/05/15 21:09:53 |
version 1.33, 2010/05/17 02:25:42 |
|
|
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 vend; /* end of word visual position on 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 */ |
int jhy; /* last hyphen before line overflow */ |
|
|
|
|
bp = TERMP_NOBREAK & p->flags ? mmax : maxvis; |
bp = TERMP_NOBREAK & p->flags ? mmax : maxvis; |
|
|
|
/* |
|
* Indent the first line of a paragraph. |
|
*/ |
|
vbl = p->flags & TERMP_NOLPAD ? 0 : p->offset; |
|
|
/* |
/* |
* FIXME: if bp is zero, we still output the first word before |
* FIXME: if bp is zero, we still output the first word before |
* breaking the line. |
* breaking the line. |
*/ |
*/ |
|
|
vis = i = 0; |
vis = vend = i = 0; |
while (i < (int)p->col) { |
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)(0 == vis ? 0 : 1); |
|
vis += vbl; |
|
vend = vis; |
|
|
|
/* |
|
* Handle literal tab characters. |
* Handle literal tab characters. |
*/ |
*/ |
for (j = i; j < (int)p->col; j++) { |
for (j = i; j < (int)p->col; j++) { |
if ('\t' != p->buf[j]) |
if ('\t' != p->buf[j]) |
break; |
break; |
/* Collapse tab with inter-word spacing. */ |
vend = (vis/p->tabwidth+1)*p->tabwidth; |
if (vis > 0 && j == i) |
|
vend = vis - 1; |
|
vend = (vend/p->tabwidth+1)*p->tabwidth; |
|
vbl += vend - vis; |
vbl += vend - vis; |
vis = vend; |
vis = vend; |
} |
} |
|
|
for (jhy = 0; j < (int)p->col; j++) { |
for (jhy = 0; j < (int)p->col; j++) { |
if ((j && ' ' == p->buf[j]) || '\t' == p->buf[j]) |
if ((j && ' ' == p->buf[j]) || '\t' == p->buf[j]) |
break; |
break; |
else if (8 == p->buf[j]) |
if (8 == p->buf[j]) |
vend--; |
vend--; |
else { |
else { |
if (vend > vis && vend < bp && |
if (vend > vis && vend < bp && |
|
|
} |
} |
|
|
/* |
/* |
* Usually, indent the first line of each paragraph. |
|
*/ |
|
if (0 == i && ! (p->flags & TERMP_NOLPAD)) { |
|
p->viscol += p->offset; |
|
/* LINTED */ |
|
for (j = 0; j < (int)p->offset; j++) |
|
putchar(' '); |
|
} |
|
|
|
/* |
|
* 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. |
* Otherwise, write the chosen number of blanks now. |
|
*/ |
*/ |
if (vend > bp && 0 == jhy && vis > vbl) { |
if (vend > bp && 0 == jhy && vis > 0) { |
vend -= vis; |
vend -= vis; |
putchar('\n'); |
putchar('\n'); |
if (TERMP_NOBREAK & p->flags) { |
if (TERMP_NOBREAK & p->flags) { |
|
|
putchar(' '); |
putchar(' '); |
vend += p->rmargin - p->offset; |
vend += p->rmargin - p->offset; |
} else { |
} else { |
p->viscol = p->offset; |
p->viscol = 0; |
for (j = 0; j < (int)p->offset; j++) |
vbl = p->offset; |
putchar(' '); |
|
} |
} |
|
|
/* Remove the p->overstep width. */ |
/* Remove the p->overstep width. */ |
|
|
bp += (int)/* LINTED */ |
bp += (int)/* LINTED */ |
p->overstep; |
p->overstep; |
p->overstep = 0; |
p->overstep = 0; |
} else { |
|
p->viscol += vbl; |
|
for (j = 0; j < (int)vbl; j++) |
|
putchar(' '); |
|
} |
} |
|
|
/* |
/* |
|
|
while (i < (int)p->col && '\t' == p->buf[i]) |
while (i < (int)p->col && '\t' == p->buf[i]) |
i++; |
i++; |
|
|
/* |
/* Write out the [remaining] word. */ |
* Finally, write out the word. |
|
*/ |
|
for ( ; i < (int)p->col; i++) { |
for ( ; i < (int)p->col; i++) { |
if (vend > bp && jhy > 0 && i > jhy) |
if (vend > bp && jhy > 0 && i > jhy) |
break; |
break; |
if ('\t' == p->buf[i]) |
if ('\t' == p->buf[i]) |
break; |
break; |
if (' ' == p->buf[i]) { |
if (' ' == p->buf[i]) { |
i++; |
while (' ' == p->buf[i]) { |
|
vbl++; |
|
i++; |
|
} |
break; |
break; |
} |
} |
if (ASCII_NBRSP == p->buf[i]) |
if (ASCII_NBRSP == p->buf[i]) { |
putchar(' '); |
vbl++; |
else |
continue; |
putchar(p->buf[i]); |
} |
|
|
|
/* |
|
* Now we definitely know there will be |
|
* printable characters to output, |
|
* so write preceding white space now. |
|
*/ |
|
if (vbl) { |
|
for (j = 0; j < (int)vbl; j++) |
|
putchar(' '); |
|
p->viscol += vbl; |
|
vbl = 0; |
|
} |
|
putchar(p->buf[i]); |
|
p->viscol += 1; |
} |
} |
p->viscol += vend - vis; |
vend += vbl; |
vis = vend; |
vis = vend; |
} |
} |
|
|