version 1.150, 2010/06/26 15:36:37 |
version 1.156, 2010/06/30 12:30:36 |
Line 133 term_flushln(struct termp *p) |
|
Line 133 term_flushln(struct termp *p) |
|
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 for p->buf */ |
int jhy; /* last hyphen before line overflow */ |
int jhy; /* last hyph before overflow w/r/t j */ |
size_t maxvis, mmax; |
size_t maxvis; /* output position of visible boundary */ |
|
size_t mmax; /* used in calculating bp */ |
|
|
/* |
/* |
* First, establish the maximum columns of "visible" content. |
* First, establish the maximum columns of "visible" content. |
Line 160 term_flushln(struct termp *p) |
|
Line 161 term_flushln(struct termp *p) |
|
*/ |
*/ |
vbl = p->flags & TERMP_NOLPAD ? 0 : p->offset; |
vbl = p->flags & TERMP_NOLPAD ? 0 : p->offset; |
|
|
/* |
|
* FIXME: if bp is zero, we still output the first word before |
|
* breaking the line. |
|
*/ |
|
|
|
vis = vend = i = 0; |
vis = vend = i = 0; |
while (i < (int)p->col) { |
|
|
|
|
while (i < (int)p->col) { |
/* |
/* |
* Handle literal tab characters. |
* Handle literal tab characters: collapse all |
|
* subsequent tabs into a single huge set of spaces. |
*/ |
*/ |
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; |
vend = (vis/p->tabwidth+1)*p->tabwidth; |
vend = (vis / p->tabwidth + 1) * p->tabwidth; |
vbl += vend - vis; |
vbl += vend - vis; |
vis = vend; |
vis = vend; |
} |
} |
Line 190 term_flushln(struct termp *p) |
|
Line 187 term_flushln(struct termp *p) |
|
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; |
if (8 != p->buf[j]) { |
|
if (vend > vis && vend < bp && |
/* Back over the the last printed character. */ |
ASCII_HYPH == p->buf[j]) |
if (8 == p->buf[j]) { |
jhy = j; |
assert(j); |
vend++; |
vend -= (*p->width)(p, p->buf[j - 1]); |
} else |
continue; |
vend--; |
} |
|
|
|
/* Regular word. */ |
|
/* Break at the hyphen point if we overrun. */ |
|
if (vend > vis && vend < bp && |
|
ASCII_HYPH == p->buf[j]) |
|
jhy = j; |
|
|
|
vend += (*p->width)(p, p->buf[j]); |
} |
} |
|
|
/* |
/* |
Line 236 term_flushln(struct termp *p) |
|
Line 241 term_flushln(struct termp *p) |
|
break; |
break; |
if (' ' == p->buf[i]) { |
if (' ' == p->buf[i]) { |
while (' ' == p->buf[i]) { |
while (' ' == p->buf[i]) { |
vbl++; |
vbl += (*p->width)(p, p->buf[i]); |
i++; |
i++; |
} |
} |
break; |
break; |
} |
} |
if (ASCII_NBRSP == p->buf[i]) { |
if (ASCII_NBRSP == p->buf[i]) { |
vbl++; |
vbl += (*p->width)(p, ' '); |
continue; |
continue; |
} |
} |
|
|
Line 257 term_flushln(struct termp *p) |
|
Line 262 term_flushln(struct termp *p) |
|
vbl = 0; |
vbl = 0; |
} |
} |
|
|
if (ASCII_HYPH == p->buf[i]) |
if (ASCII_HYPH == p->buf[i]) { |
(*p->letter)(p, '-'); |
(*p->letter)(p, '-'); |
else |
p->viscol += (*p->width)(p, '-'); |
|
} else { |
(*p->letter)(p, p->buf[i]); |
(*p->letter)(p, p->buf[i]); |
|
p->viscol += (*p->width)(p, p->buf[i]); |
p->viscol += 1; |
} |
} |
} |
vend += vbl; |
vend += vbl; |
vis = vend; |
vis = vend; |
Line 280 term_flushln(struct termp *p) |
|
Line 286 term_flushln(struct termp *p) |
|
if (TERMP_HANG & p->flags) { |
if (TERMP_HANG & p->flags) { |
/* We need one blank after the tag. */ |
/* We need one blank after the tag. */ |
p->overstep = /* LINTED */ |
p->overstep = /* LINTED */ |
vis - maxvis + 1; |
vis - maxvis + (*p->width)(p, ' '); |
|
|
/* |
/* |
* Behave exactly the same way as groff: |
* Behave exactly the same way as groff: |
Line 304 term_flushln(struct termp *p) |
|
Line 310 term_flushln(struct termp *p) |
|
|
|
/* Right-pad. */ |
/* Right-pad. */ |
if (maxvis > vis + /* LINTED */ |
if (maxvis > vis + /* LINTED */ |
((TERMP_TWOSPACE & p->flags) ? 1 : 0)) { |
((TERMP_TWOSPACE & p->flags) ? |
|
(*p->width)(p, ' ') : 0)) { |
p->viscol += maxvis - vis; |
p->viscol += maxvis - vis; |
(*p->advance)(p, maxvis - vis); |
(*p->advance)(p, maxvis - vis); |
vis += (maxvis - vis); |
vis += (maxvis - vis); |
Line 480 term_word(struct termp *p, const char *word) |
|
Line 487 term_word(struct termp *p, const char *word) |
|
} |
} |
|
|
if ( ! (TERMP_NOSPACE & p->flags)) { |
if ( ! (TERMP_NOSPACE & p->flags)) { |
bufferc(p, ' '); |
if ( ! (TERMP_KEEP & p->flags)) { |
if (TERMP_SENTENCE & p->flags) |
if (TERMP_PREKEEP & p->flags) |
|
p->flags |= TERMP_KEEP; |
bufferc(p, ' '); |
bufferc(p, ' '); |
|
if (TERMP_SENTENCE & p->flags) |
|
bufferc(p, ' '); |
|
} else |
|
bufferc(p, ASCII_NBRSP); |
} |
} |
|
|
if ( ! (p->flags & TERMP_NONOSPACE)) |
if ( ! (p->flags & TERMP_NONOSPACE)) |
Line 680 term_vspan(const struct termp *p, const struct roffsu |
|
Line 692 term_vspan(const struct termp *p, const struct roffsu |
|
size_t |
size_t |
term_hspan(const struct termp *p, const struct roffsu *su) |
term_hspan(const struct termp *p, const struct roffsu *su) |
{ |
{ |
double r; |
double v; |
|
|
/* XXX: CM, IN, and PT are approximations. */ |
v = ((*p->hspan)(p, su)); |
|
if (v < 0.0) |
switch (su->unit) { |
v = 0.0; |
case (SCALE_CM): |
return((size_t) /* LINTED */ |
r = 4 * su->scale; |
v); |
break; |
|
case (SCALE_IN): |
|
/* XXX: this is an approximation. */ |
|
r = 10 * su->scale; |
|
break; |
|
case (SCALE_PC): |
|
r = (10 * su->scale) / 6; |
|
break; |
|
case (SCALE_PT): |
|
r = (10 * su->scale) / 72; |
|
break; |
|
case (SCALE_MM): |
|
r = su->scale / 1000; /* FIXME: double-check. */ |
|
break; |
|
case (SCALE_VS): |
|
r = su->scale * 2 - 1; /* FIXME: double-check. */ |
|
break; |
|
default: |
|
r = su->scale; |
|
break; |
|
} |
|
|
|
if (r < 0.0) |
|
r = 0.0; |
|
return((size_t)/* LINTED */ |
|
r); |
|
} |
} |
|
|
|
|