version 1.202, 2012/05/27 18:02:49 |
version 1.204, 2012/07/10 15:35:41 |
|
|
#include "term.h" |
#include "term.h" |
#include "main.h" |
#include "main.h" |
|
|
|
static size_t cond_width(const struct termp *, int, int *); |
static void adjbuf(struct termp *p, int); |
static void adjbuf(struct termp *p, int); |
static void bufferc(struct termp *, char); |
static void bufferc(struct termp *, char); |
static void encode(struct termp *, const char *, size_t); |
static void encode(struct termp *, const char *, size_t); |
Line 264 term_flushln(struct termp *p) |
|
Line 265 term_flushln(struct termp *p) |
|
p->overstep = (int)(vis - maxvis + (*p->width)(p, ' ')); |
p->overstep = (int)(vis - maxvis + (*p->width)(p, ' ')); |
|
|
/* |
/* |
* Behave exactly the same way as groff: |
|
* If we have overstepped the margin, temporarily move |
* If we have overstepped the margin, temporarily move |
* it to the right and flag the rest of the line to be |
* it to the right and flag the rest of the line to be |
* shorter. |
* shorter. |
* If we landed right at the margin, be happy. |
|
* If we are one step before the margin, temporarily |
|
* move it one step LEFT and flag the rest of the line |
|
* to be longer. |
|
*/ |
*/ |
if (p->overstep < -1) |
if (p->overstep < 0) |
p->overstep = 0; |
p->overstep = 0; |
return; |
return; |
|
|
Line 419 term_word(struct termp *p, const char *word) |
|
Line 415 term_word(struct termp *p, const char *word) |
|
p->flags &= ~(TERMP_SENTENCE | TERMP_IGNDELIM); |
p->flags &= ~(TERMP_SENTENCE | TERMP_IGNDELIM); |
|
|
while ('\0' != *word) { |
while ('\0' != *word) { |
if ((ssz = strcspn(word, "\\")) > 0) |
if ('\\' != *word) { |
|
if (TERMP_SKIPCHAR & p->flags) { |
|
p->flags &= ~TERMP_SKIPCHAR; |
|
word++; |
|
continue; |
|
} |
|
ssz = strcspn(word, "\\"); |
encode(p, word, ssz); |
encode(p, word, ssz); |
|
word += (int)ssz; |
word += (int)ssz; |
|
if ('\\' != *word) |
|
continue; |
continue; |
|
} |
|
|
word++; |
word++; |
esc = mandoc_escape(&word, &seq, &sz); |
esc = mandoc_escape(&word, &seq, &sz); |
Line 480 term_word(struct termp *p, const char *word) |
|
Line 481 term_word(struct termp *p, const char *word) |
|
term_fontlast(p); |
term_fontlast(p); |
break; |
break; |
case (ESCAPE_NOSPACE): |
case (ESCAPE_NOSPACE): |
if ('\0' == *word) |
if (TERMP_SKIPCHAR & p->flags) |
|
p->flags &= ~TERMP_SKIPCHAR; |
|
else if ('\0' == *word) |
p->flags |= TERMP_NOSPACE; |
p->flags |= TERMP_NOSPACE; |
break; |
break; |
|
case (ESCAPE_SKIPCHAR): |
|
p->flags |= TERMP_SKIPCHAR; |
|
break; |
default: |
default: |
break; |
break; |
} |
} |
Line 522 encode1(struct termp *p, int c) |
|
Line 528 encode1(struct termp *p, int c) |
|
{ |
{ |
enum termfont f; |
enum termfont f; |
|
|
|
if (TERMP_SKIPCHAR & p->flags) { |
|
p->flags &= ~TERMP_SKIPCHAR; |
|
return; |
|
} |
|
|
if (p->col + 4 >= p->maxcols) |
if (p->col + 4 >= p->maxcols) |
adjbuf(p, p->col + 4); |
adjbuf(p, p->col + 4); |
|
|
Line 545 encode(struct termp *p, const char *word, size_t sz) |
|
Line 556 encode(struct termp *p, const char *word, size_t sz) |
|
enum termfont f; |
enum termfont f; |
int i, len; |
int i, len; |
|
|
|
if (TERMP_SKIPCHAR & p->flags) { |
|
p->flags &= ~TERMP_SKIPCHAR; |
|
return; |
|
} |
|
|
/* LINTED */ |
/* LINTED */ |
len = sz; |
len = sz; |
|
|
Line 593 term_len(const struct termp *p, size_t sz) |
|
Line 609 term_len(const struct termp *p, size_t sz) |
|
return((*p->width)(p, ' ') * sz); |
return((*p->width)(p, ' ') * sz); |
} |
} |
|
|
|
static size_t |
|
cond_width(const struct termp *p, int c, int *skip) |
|
{ |
|
|
|
if (*skip) { |
|
(*skip) = 0; |
|
return(0); |
|
} else |
|
return((*p->width)(p, c)); |
|
} |
|
|
size_t |
size_t |
term_strlen(const struct termp *p, const char *cp) |
term_strlen(const struct termp *p, const char *cp) |
{ |
{ |
size_t sz, rsz, i; |
size_t sz, rsz, i; |
int ssz, c; |
int ssz, skip, c; |
const char *seq, *rhs; |
const char *seq, *rhs; |
enum mandoc_esc esc; |
enum mandoc_esc esc; |
static const char rej[] = { '\\', ASCII_HYPH, ASCII_NBRSP, '\0' }; |
static const char rej[] = { '\\', ASCII_HYPH, ASCII_NBRSP, '\0' }; |
Line 610 term_strlen(const struct termp *p, const char *cp) |
|
Line 636 term_strlen(const struct termp *p, const char *cp) |
|
*/ |
*/ |
|
|
sz = 0; |
sz = 0; |
|
skip = 0; |
while ('\0' != *cp) { |
while ('\0' != *cp) { |
rsz = strcspn(cp, rej); |
rsz = strcspn(cp, rej); |
for (i = 0; i < rsz; i++) |
for (i = 0; i < rsz; i++) |
sz += (*p->width)(p, *cp++); |
sz += cond_width(p, *cp++, &skip); |
|
|
c = 0; |
c = 0; |
switch (*cp) { |
switch (*cp) { |
Line 630 term_strlen(const struct termp *p, const char *cp) |
|
Line 657 term_strlen(const struct termp *p, const char *cp) |
|
(seq + 1, ssz - 1); |
(seq + 1, ssz - 1); |
if ('\0' == c) |
if ('\0' == c) |
break; |
break; |
sz += (*p->width)(p, c); |
sz += cond_width(p, c, &skip); |
continue; |
continue; |
case (ESCAPE_SPECIAL): |
case (ESCAPE_SPECIAL): |
c = mchars_spec2cp |
c = mchars_spec2cp |
(p->symtab, seq, ssz); |
(p->symtab, seq, ssz); |
if (c <= 0) |
if (c <= 0) |
break; |
break; |
sz += (*p->width)(p, c); |
sz += cond_width(p, c, &skip); |
continue; |
continue; |
default: |
default: |
break; |
break; |
Line 647 term_strlen(const struct termp *p, const char *cp) |
|
Line 674 term_strlen(const struct termp *p, const char *cp) |
|
|
|
switch (esc) { |
switch (esc) { |
case (ESCAPE_UNICODE): |
case (ESCAPE_UNICODE): |
sz += (*p->width)(p, '?'); |
sz += cond_width(p, '?', &skip); |
break; |
break; |
case (ESCAPE_NUMBERED): |
case (ESCAPE_NUMBERED): |
c = mchars_num2char(seq, ssz); |
c = mchars_num2char(seq, ssz); |
if ('\0' != c) |
if ('\0' != c) |
sz += (*p->width)(p, c); |
sz += cond_width(p, c, &skip); |
break; |
break; |
case (ESCAPE_SPECIAL): |
case (ESCAPE_SPECIAL): |
rhs = mchars_spec2str |
rhs = mchars_spec2str |
Line 664 term_strlen(const struct termp *p, const char *cp) |
|
Line 691 term_strlen(const struct termp *p, const char *cp) |
|
rhs = seq; |
rhs = seq; |
rsz = ssz; |
rsz = ssz; |
break; |
break; |
|
case (ESCAPE_SKIPCHAR): |
|
skip = 1; |
|
break; |
default: |
default: |
break; |
break; |
} |
} |
Line 671 term_strlen(const struct termp *p, const char *cp) |
|
Line 701 term_strlen(const struct termp *p, const char *cp) |
|
if (NULL == rhs) |
if (NULL == rhs) |
break; |
break; |
|
|
|
if (skip) { |
|
skip = 0; |
|
break; |
|
} |
|
|
for (i = 0; i < rsz; i++) |
for (i = 0; i < rsz; i++) |
sz += (*p->width)(p, *rhs++); |
sz += (*p->width)(p, *rhs++); |
break; |
break; |
case (ASCII_NBRSP): |
case (ASCII_NBRSP): |
sz += (*p->width)(p, ' '); |
sz += cond_width(p, ' ', &skip); |
cp++; |
cp++; |
break; |
break; |
case (ASCII_HYPH): |
case (ASCII_HYPH): |
sz += (*p->width)(p, '-'); |
sz += cond_width(p, '-', &skip); |
cp++; |
cp++; |
break; |
break; |
default: |
default: |