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 /term_ps.c | |
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.
Diffstat (limited to 'term_ps.c')
-rw-r--r-- | term_ps.c | 31 |
1 files changed, 30 insertions, 1 deletions
@@ -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; |