summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2010-06-11 07:23:04 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2010-06-11 07:23:04 +0000
commit4320829a9974a95546e94df94a6b70b6b4831a68 (patch)
treee3ea0982f86fbdfebf5723d37be88cb45b4fad26
parent7172afe8498d9da876e08e39960b11f31467e9ca (diff)
downloadmandoc-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.c5
-rw-r--r--term.h1
-rw-r--r--term_ps.c31
3 files changed, 32 insertions, 5 deletions
diff --git a/term.c b/term.c
index a3093d60..f9c43be2 100644
--- a/term.c
+++ b/term.c
@@ -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;
}
diff --git a/term.h b/term.h
index dad0a71d..9206e4ad 100644
--- a/term.h
+++ b/term.h
@@ -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 {
diff --git a/term_ps.c b/term_ps.c
index 26762ace..36304bdc 100644
--- a/term_ps.c
+++ b/term_ps.c
@@ -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;