version 1.80, 2009/06/22 10:40:04 |
version 1.83, 2009/06/22 13:13:10 |
Line 200 term_isopendelim(const char *p, int len) |
|
Line 200 term_isopendelim(const char *p, int len) |
|
* Otherwise, the line will break at the right margin. Extremely long |
* Otherwise, the line will break at the right margin. Extremely long |
* lines will cause the system to emit a warning (TODO: hyphenate, if |
* lines will cause the system to emit a warning (TODO: hyphenate, if |
* possible). |
* possible). |
|
* |
|
* FIXME: newline breaks occur (in groff) also occur when a single |
|
* space follows a NOBREAK! |
*/ |
*/ |
void |
void |
term_flushln(struct termp *p) |
term_flushln(struct termp *p) |
{ |
{ |
int i, j; |
int i, j; |
size_t vsz, vis, maxvis, mmax, bp; |
size_t vbl, vsz, vis, maxvis, mmax, bp; |
|
|
/* |
/* |
* First, establish the maximum columns of "visible" content. |
* First, establish the maximum columns of "visible" content. |
Line 250 term_flushln(struct termp *p) |
|
Line 253 term_flushln(struct termp *p) |
|
} |
} |
|
|
/* |
/* |
* Do line-breaking. If we're greater than our |
* Choose the number of blanks to prepend: no blank at the |
* break-point and already in-line, break to the next |
* beginning of a line, one between words -- but do not |
* line and start writing. If we're at the line start, |
* actually write them yet. |
* then write out the word (TODO: hyphenate) and break |
|
* in a subsequent loop invocation. |
|
*/ |
*/ |
|
vbl = (size_t)(0 == vis ? 0 : 1); |
|
|
if ( ! (TERMP_NOBREAK & p->flags)) { |
/* |
if (vis && vis + vsz > bp) { |
* Find out whether we would exceed the right margin. |
putchar('\n'); |
* If so, break to the next line. (TODO: hyphenate) |
|
* Otherwise, write the chosen number of blanks now. |
|
*/ |
|
if (vis && vis + vbl + vsz > bp) { |
|
putchar('\n'); |
|
if (TERMP_NOBREAK & p->flags) { |
|
for (j = 0; j < (int)p->rmargin; j++) |
|
putchar(' '); |
|
vis = p->rmargin - p->offset; |
|
} else { |
for (j = 0; j < (int)p->offset; j++) |
for (j = 0; j < (int)p->offset; j++) |
putchar(' '); |
putchar(' '); |
vis = 0; |
vis = 0; |
} |
} |
} else if (vis && vis + vsz > bp) { |
} else { |
putchar('\n'); |
for (j = 0; j < (int)vbl; j++) |
for (j = 0; j < (int)p->rmargin; j++) |
|
putchar(' '); |
putchar(' '); |
vis = p->rmargin - p->offset; |
vis += vbl; |
} |
} |
|
|
/* |
/* |
* Prepend a space if we're not already at the beginning |
* Finally, write out the word. |
* of the line, then the word. |
|
*/ |
*/ |
|
|
if (0 < vis++) |
|
putchar(' '); |
|
|
|
for ( ; i < (int)p->col; i++) { |
for ( ; i < (int)p->col; i++) { |
if (' ' == p->buf[i]) |
if (' ' == p->buf[i]) |
break; |
break; |
Line 292 term_flushln(struct termp *p) |
|
Line 297 term_flushln(struct termp *p) |
|
* cause a newline and offset at the right margin. |
* cause a newline and offset at the right margin. |
*/ |
*/ |
|
|
if ((TERMP_NOBREAK & p->flags) && vis > maxvis) { |
if ((TERMP_NOBREAK & p->flags) && vis >= maxvis) { |
if ( ! (TERMP_NONOBREAK & p->flags)) { |
if ( ! (TERMP_NONOBREAK & p->flags)) { |
putchar('\n'); |
putchar('\n'); |
for (i = 0; i < (int)p->rmargin; i++) |
for (i = 0; i < (int)p->rmargin; i++) |
Line 309 term_flushln(struct termp *p) |
|
Line 314 term_flushln(struct termp *p) |
|
|
|
if (p->flags & TERMP_NOBREAK) { |
if (p->flags & TERMP_NOBREAK) { |
if ( ! (TERMP_NONOBREAK & p->flags)) |
if ( ! (TERMP_NONOBREAK & p->flags)) |
for ( ; vis <= maxvis; vis++) |
for ( ; vis < maxvis; vis++) |
putchar(' '); |
putchar(' '); |
} else |
} else |
putchar('\n'); |
putchar('\n'); |
Line 408 term_nescape(struct termp *p, const char *word, size_t |
|
Line 413 term_nescape(struct termp *p, const char *word, size_t |
|
size_t sz; |
size_t sz; |
int i; |
int i; |
|
|
if ((rhs = term_a2ascii(p->symtab, word, len, &sz))) |
rhs = term_a2ascii(p->symtab, word, len, &sz); |
|
if (rhs) |
for (i = 0; i < (int)sz; i++) |
for (i = 0; i < (int)sz; i++) |
term_encodea(p, rhs[i]); |
term_encodea(p, rhs[i]); |
} |
} |