diff options
author | Kristaps Dzonsons <kristaps@bsd.lv> | 2010-06-11 07:23:04 +0000 |
---|---|---|
committer | Kristaps Dzonsons <kristaps@bsd.lv> | 2010-06-11 07:23:04 +0000 |
commit | 4320829a9974a95546e94df94a6b70b6b4831a68 (patch) | |
tree | e3ea0982f86fbdfebf5723d37be88cb45b4fad26 | |
parent | 7172afe8498d9da876e08e39960b11f31467e9ca (diff) | |
download | mandoc-4320829a9974a95546e94df94a6b70b6b4831a68.tar.gz |
Teach -Tps to ignore backspace-encoding by using a one-char buffer and a
simple state machine. This paves the way for decorated text.
-rw-r--r-- | term.c | 5 | ||||
-rw-r--r-- | term.h | 1 | ||||
-rw-r--r-- | term_ps.c | 31 |
3 files changed, 32 insertions, 5 deletions
@@ -603,10 +603,7 @@ encode(struct termp *p, const char *word, size_t sz) * character by character. */ - if (TERMTYPE_PS == p->type) { - buffera(p, word, sz); - return; - } else if (TERMFONT_NONE == (f = term_fonttop(p))) { + if (TERMFONT_NONE == (f = term_fonttop(p))) { buffera(p, word, sz); return; } @@ -50,6 +50,7 @@ struct termp_ps { size_t psmargsz; /* margin buf size */ size_t psmargcur; /* current pos in margin buf */ size_t pspage; /* current page */ + char last; /* character buffer */ }; struct termp { @@ -228,6 +228,7 @@ ps_begin(struct termp *p) static void ps_letter(struct termp *p, char c) { + char cc; if ( ! (PS_INLINE & p->engine.ps.psstate)) { /* @@ -240,6 +241,24 @@ ps_letter(struct termp *p, char c) p->engine.ps.psstate |= PS_INLINE; } + if ('\0' == p->engine.ps.last) { + assert(8 != c); + p->engine.ps.last = c; + return; + } else if (8 == p->engine.ps.last) { + assert(8 != c); + p->engine.ps.last = c; + return; + } else if (8 == c) { + assert(8 != p->engine.ps.last); + p->engine.ps.last = c; + return; + } else { + cc = p->engine.ps.last; + p->engine.ps.last = c; + c = cc; + } + /* * We need to escape these characters as per the PostScript * specification. We would also escape non-graphable characters @@ -271,11 +290,16 @@ ps_advance(struct termp *p, size_t len) size_t i; if (PS_INLINE & p->engine.ps.psstate) { + assert(8 != p->engine.ps.last); + if (p->engine.ps.last) + ps_letter(p, p->engine.ps.last); + p->engine.ps.last = '\0'; for (i = 0; i < len; i++) ps_letter(p, ' '); return; } + assert('\0' == p->engine.ps.last); p->engine.ps.pscol += len ? len * PS_CHAR_WIDTH : 0; } @@ -285,9 +309,14 @@ ps_endline(struct termp *p) { if (PS_INLINE & p->engine.ps.psstate) { + assert(8 != p->engine.ps.last); + if (p->engine.ps.last) + ps_letter(p, p->engine.ps.last); + p->engine.ps.last = '\0'; ps_printf(p, ") show\n"); p->engine.ps.psstate &= ~PS_INLINE; - } + } else + assert('\0' == p->engine.ps.last); if (PS_MARGINS & p->engine.ps.psstate) return; |