version 1.251, 2015/09/26 00:54:04 |
version 1.259, 2017/01/08 18:16:58 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org> |
* Copyright (c) 2010-2017 Ingo Schwarze <schwarze@openbsd.org> |
* |
* |
* Permission to use, copy, modify, and distribute this software for any |
* Permission to use, copy, modify, and distribute this software for any |
* purpose with or without fee is hereby granted, provided that the above |
* purpose with or without fee is hereby granted, provided that the above |
Line 160 term_flushln(struct termp *p) |
|
Line 160 term_flushln(struct termp *p) |
|
if (' ' == p->buf[j] || '\t' == p->buf[j]) |
if (' ' == p->buf[j] || '\t' == p->buf[j]) |
break; |
break; |
|
|
/* Back over the the last printed character. */ |
/* Back over the last printed character. */ |
if (8 == p->buf[j]) { |
if (8 == p->buf[j]) { |
assert(j); |
assert(j); |
vend -= (*p->width)(p, p->buf[j - 1]); |
vend -= (*p->width)(p, p->buf[j - 1]); |
Line 365 term_fontpush(struct termp *p, enum termfont f) |
|
Line 365 term_fontpush(struct termp *p, enum termfont f) |
|
if (++p->fonti == p->fontsz) { |
if (++p->fonti == p->fontsz) { |
p->fontsz += 8; |
p->fontsz += 8; |
p->fontq = mandoc_reallocarray(p->fontq, |
p->fontq = mandoc_reallocarray(p->fontq, |
p->fontsz, sizeof(enum termfont *)); |
p->fontsz, sizeof(*p->fontq)); |
} |
} |
p->fontq[p->fonti] = f; |
p->fontq[p->fonti] = f; |
} |
} |
Line 454 term_word(struct termp *p, const char *word) |
|
Line 454 term_word(struct termp *p, const char *word) |
|
break; |
break; |
case ESCAPE_SPECIAL: |
case ESCAPE_SPECIAL: |
if (p->enc == TERMENC_ASCII) { |
if (p->enc == TERMENC_ASCII) { |
cp = mchars_spec2str(p->symtab, |
cp = mchars_spec2str(seq, sz, &ssz); |
seq, sz, &ssz); |
|
if (cp != NULL) |
if (cp != NULL) |
encode(p, cp, ssz); |
encode(p, cp, ssz); |
} else { |
} else { |
uc = mchars_spec2cp(p->symtab, seq, sz); |
uc = mchars_spec2cp(seq, sz); |
if (uc > 0) |
if (uc > 0) |
encode1(p, uc); |
encode1(p, uc); |
} |
} |
Line 474 term_word(struct termp *p, const char *word) |
|
Line 473 term_word(struct termp *p, const char *word) |
|
term_fontrepl(p, TERMFONT_BI); |
term_fontrepl(p, TERMFONT_BI); |
continue; |
continue; |
case ESCAPE_FONT: |
case ESCAPE_FONT: |
/* FALLTHROUGH */ |
|
case ESCAPE_FONTROMAN: |
case ESCAPE_FONTROMAN: |
term_fontrepl(p, TERMFONT_NONE); |
term_fontrepl(p, TERMFONT_NONE); |
continue; |
continue; |
Line 506 term_word(struct termp *p, const char *word) |
|
Line 504 term_word(struct termp *p, const char *word) |
|
} |
} |
} |
} |
/* Trim trailing backspace/blank pair. */ |
/* Trim trailing backspace/blank pair. */ |
if (p->col > 2 && p->buf[p->col - 1] == ' ') |
if (p->col > 2 && |
|
(p->buf[p->col - 1] == ' ' || |
|
p->buf[p->col - 1] == '\t')) |
p->col -= 2; |
p->col -= 2; |
continue; |
continue; |
default: |
default: |
Line 566 encode1(struct termp *p, int c) |
|
Line 566 encode1(struct termp *p, int c) |
|
if (p->col + 7 >= p->maxcols) |
if (p->col + 7 >= p->maxcols) |
adjbuf(p, p->col + 7); |
adjbuf(p, p->col + 7); |
|
|
f = (c == ASCII_HYPH || isgraph(c)) ? |
f = (c == ASCII_HYPH || c > 127 || isgraph(c)) ? |
p->fontq[p->fonti] : TERMFONT_NONE; |
p->fontq[p->fonti] : TERMFONT_NONE; |
|
|
if (p->flags & TERMP_BACKBEFORE) { |
if (p->flags & TERMP_BACKBEFORE) { |
if (p->buf[p->col - 1] == ' ') |
if (p->buf[p->col - 1] == ' ' || p->buf[p->col - 1] == '\t') |
p->col--; |
p->col--; |
else |
else |
p->buf[p->col++] = 8; |
p->buf[p->col++] = 8; |
Line 606 encode(struct termp *p, const char *word, size_t sz) |
|
Line 606 encode(struct termp *p, const char *word, size_t sz) |
|
if (ASCII_HYPH == word[i] || |
if (ASCII_HYPH == word[i] || |
isgraph((unsigned char)word[i])) |
isgraph((unsigned char)word[i])) |
encode1(p, word[i]); |
encode1(p, word[i]); |
else |
else { |
p->buf[p->col++] = word[i]; |
p->buf[p->col++] = word[i]; |
|
|
|
/* |
|
* Postpone the effect of \z while handling |
|
* an overstrike sequence from ascii_uc2str(). |
|
*/ |
|
|
|
if (word[i] == '\b' && |
|
(p->flags & TERMP_BACKBEFORE)) { |
|
p->flags &= ~TERMP_BACKBEFORE; |
|
p->flags |= TERMP_BACKAFTER; |
|
} |
|
} |
} |
} |
} |
} |
|
|
|
|
term_len(const struct termp *p, size_t sz) |
term_len(const struct termp *p, size_t sz) |
{ |
{ |
|
|
return((*p->width)(p, ' ') * sz); |
return (*p->width)(p, ' ') * sz; |
} |
} |
|
|
static size_t |
static size_t |
Line 653 cond_width(const struct termp *p, int c, int *skip) |
|
Line 665 cond_width(const struct termp *p, int c, int *skip) |
|
|
|
if (*skip) { |
if (*skip) { |
(*skip) = 0; |
(*skip) = 0; |
return(0); |
return 0; |
} else |
} else |
return((*p->width)(p, c)); |
return (*p->width)(p, c); |
} |
} |
|
|
size_t |
size_t |
Line 701 term_strlen(const struct termp *p, const char *cp) |
|
Line 713 term_strlen(const struct termp *p, const char *cp) |
|
break; |
break; |
case ESCAPE_SPECIAL: |
case ESCAPE_SPECIAL: |
if (p->enc == TERMENC_ASCII) { |
if (p->enc == TERMENC_ASCII) { |
rhs = mchars_spec2str(p->symtab, |
rhs = mchars_spec2str(seq, ssz, &rsz); |
seq, ssz, &rsz); |
|
if (rhs != NULL) |
if (rhs != NULL) |
break; |
break; |
} else { |
} else { |
uc = mchars_spec2cp(p->symtab, |
uc = mchars_spec2cp(seq, ssz); |
seq, ssz); |
|
if (uc > 0) |
if (uc > 0) |
sz += cond_width(p, uc, &skip); |
sz += cond_width(p, uc, &skip); |
} |
} |
Line 771 term_strlen(const struct termp *p, const char *cp) |
|
Line 781 term_strlen(const struct termp *p, const char *cp) |
|
case ASCII_HYPH: |
case ASCII_HYPH: |
sz += cond_width(p, '-', &skip); |
sz += cond_width(p, '-', &skip); |
cp++; |
cp++; |
/* FALLTHROUGH */ |
|
case ASCII_BREAK: |
|
break; |
break; |
default: |
default: |
break; |
break; |
} |
} |
} |
} |
|
|
return(sz); |
return sz; |
} |
} |
|
|
int |
int |
Line 811 term_vspan(const struct termp *p, const struct roffsu |
|
Line 819 term_vspan(const struct termp *p, const struct roffsu |
|
r = su->scale / 12.0; |
r = su->scale / 12.0; |
break; |
break; |
case SCALE_EN: |
case SCALE_EN: |
/* FALLTHROUGH */ |
|
case SCALE_EM: |
case SCALE_EM: |
r = su->scale * 0.6; |
r = su->scale * 0.6; |
break; |
break; |
Line 822 term_vspan(const struct termp *p, const struct roffsu |
|
Line 829 term_vspan(const struct termp *p, const struct roffsu |
|
abort(); |
abort(); |
} |
} |
ri = r > 0.0 ? r + 0.4995 : r - 0.4995; |
ri = r > 0.0 ? r + 0.4995 : r - 0.4995; |
return(ri < 66 ? ri : 1); |
return ri < 66 ? ri : 1; |
} |
} |
|
|
/* |
/* |
|
|
term_hspan(const struct termp *p, const struct roffsu *su) |
term_hspan(const struct termp *p, const struct roffsu *su) |
{ |
{ |
|
|
return((*p->hspan)(p, su)); |
return (*p->hspan)(p, su); |
} |
} |