aboutsummaryrefslogtreecommitdiffstatshomepage
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
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.
-rw-r--r--term.c7
-rw-r--r--term.h3
-rw-r--r--term_ps.c33
3 files changed, 35 insertions, 8 deletions
diff --git a/term.c b/term.c
index bdcd2879..dbdc2441 100644
--- a/term.c
+++ b/term.c
@@ -1,4 +1,4 @@
-/* $Id: term.c,v 1.146 2010/06/08 15:00:17 kristaps Exp $ */
+/* $Id: term.c,v 1.147 2010/06/11 07:23:04 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -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 ace4b9ba..7f67e246 100644
--- a/term.h
+++ b/term.h
@@ -1,4 +1,4 @@
-/* $Id: term.h,v 1.61 2010/06/09 08:07:13 kristaps Exp $ */
+/* $Id: term.h,v 1.62 2010/06/11 07:23:04 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -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 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;