version 1.80, 2009/06/22 10:40:04 |
version 1.84, 2009/07/14 15:16:41 |
Line 176 term_isopendelim(const char *p, int len) |
|
Line 176 term_isopendelim(const char *p, int len) |
|
* Specifically, a line is whatever's in p->buf of length p->col, which |
* Specifically, a line is whatever's in p->buf of length p->col, which |
* is zeroed after this function returns. |
* is zeroed after this function returns. |
* |
* |
* The variables TERMP_NOLPAD, TERMP_LITERAL and TERMP_NOBREAK are of |
* The usage of termp:flags is as follows: |
* critical importance here. Their behaviour follows: |
|
* |
* |
* - TERMP_NOLPAD: when beginning to write the line, don't left-pad the |
* - TERMP_NOLPAD: when beginning to write the line, don't left-pad the |
* offset value. This is useful when doing columnar lists where the |
* offset value. This is useful when doing columnar lists where the |
Line 187 term_isopendelim(const char *p, int len) |
|
Line 186 term_isopendelim(const char *p, int len) |
|
* columns. In short: don't print a newline and instead pad to the |
* columns. In short: don't print a newline and instead pad to the |
* right margin. Used in conjunction with TERMP_NOLPAD. |
* right margin. Used in conjunction with TERMP_NOLPAD. |
* |
* |
* - TERMP_NONOBREAK: don't newline when TERMP_NOBREAK is specified. |
* - TERMP_DANGLE: don't newline when TERMP_NOBREAK is specified and |
|
* the line is overrun, and don't pad-right if it's underrun. |
* |
* |
|
* - TERMP_HANG: like TERMP_DANGLE, but doesn't newline when |
|
* overruning, instead save the position and continue at that point |
|
* when the next invocation. |
|
* |
* In-line line breaking: |
* In-line line breaking: |
* |
* |
* If TERMP_NOBREAK is specified and the line overruns the right |
* If TERMP_NOBREAK is specified and the line overruns the right |
Line 200 term_isopendelim(const char *p, int len) |
|
Line 204 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; |
|
static int sv = -1; |
|
|
/* |
/* |
* First, establish the maximum columns of "visible" content. |
* First, establish the maximum columns of "visible" content. |
Line 220 term_flushln(struct termp *p) |
|
Line 228 term_flushln(struct termp *p) |
|
bp = TERMP_NOBREAK & p->flags ? mmax : maxvis; |
bp = TERMP_NOBREAK & p->flags ? mmax : maxvis; |
vis = 0; |
vis = 0; |
|
|
|
if (sv >= 0) { |
|
vis = (size_t)sv; |
|
sv = -1; |
|
} |
|
|
/* |
/* |
* 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 |
Line 250 term_flushln(struct termp *p) |
|
Line 263 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 307 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_DANGLE & p->flags) && |
|
! (TERMP_HANG & p->flags)) { |
putchar('\n'); |
putchar('\n'); |
for (i = 0; i < (int)p->rmargin; i++) |
for (i = 0; i < (int)p->rmargin; i++) |
putchar(' '); |
putchar(' '); |
} |
} |
|
if (TERMP_HANG & p->flags) |
|
sv = vis - maxvis; |
p->col = 0; |
p->col = 0; |
return; |
return; |
} |
} |
Line 308 term_flushln(struct termp *p) |
|
Line 326 term_flushln(struct termp *p) |
|
*/ |
*/ |
|
|
if (p->flags & TERMP_NOBREAK) { |
if (p->flags & TERMP_NOBREAK) { |
if ( ! (TERMP_NONOBREAK & p->flags)) |
if ( ! (TERMP_DANGLE & 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 426 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]); |
} |
} |