aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/term_ps.c
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
commitfc5d71d822ac93dd1052a8f796bb03fd3e88ce3f (patch)
treea91f6e1dad8b2c70ae7e5faca225c435fc65ca9f /term_ps.c
parent7a77114452fc90a6f9175095b3ba098129bede0b (diff)
downloadmandoc-fc5d71d822ac93dd1052a8f796bb03fd3e88ce3f.tar.gz
mandoc-fc5d71d822ac93dd1052a8f796bb03fd3e88ce3f.tar.zst
mandoc-fc5d71d822ac93dd1052a8f796bb03fd3e88ce3f.zip
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.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/term_ps.c b/term_ps.c
index 29b2ce75..8f32ae11 100644
--- a/term_ps.c
+++ b/term_ps.c
@@ -1,4 +1,4 @@
-/* $Id: term_ps.c,v 1.6 2010/06/10 23:56:33 kristaps Exp $ */
+/* $Id: term_ps.c,v 1.7 2010/06/11 07:23:04 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -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;