source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Teach -Tps to ignore backspace-encoding by using a one-char
@ 2010-06-11  7:23 kristaps
  0 siblings, 0 replies; only message in thread
From: kristaps @ 2010-06-11  7:23 UTC (permalink / raw)
  To: source

Log Message:
-----------
Teach -Tps to ignore backspace-encoding by using a one-char buffer and a
simple state machine.  This paves the way for decorated text.

Modified Files:
--------------
    mdocml:
        term.c
        term.h
        term_ps.c

Revision Data
-------------
Index: term.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/term.c,v
retrieving revision 1.146
retrieving revision 1.147
diff -Lterm.c -Lterm.c -u -p -r1.146 -r1.147
--- term.c
+++ term.c
@@ -603,10 +603,7 @@ encode(struct termp *p, const char *word
 	 * 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;
 	}
Index: term.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/term.h,v
retrieving revision 1.61
retrieving revision 1.62
diff -Lterm.h -Lterm.h -u -p -r1.61 -r1.62
--- term.h
+++ 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 {
Index: term_ps.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/term_ps.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -Lterm_ps.c -Lterm_ps.c -u -p -r1.6 -r1.7
--- term_ps.c
+++ 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;
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-06-11  7:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-11  7:23 mdocml: Teach -Tps to ignore backspace-encoding by using a one-char kristaps

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).