source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: kristaps@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: Teach -Tps to ignore backspace-encoding by using a one-char
Date: Fri, 11 Jun 2010 03:23:04 -0400 (EDT)	[thread overview]
Message-ID: <201006110723.o5B7N4wr015322@krisdoz.my.domain> (raw)

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

                 reply	other threads:[~2010-06-11  7:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201006110723.o5B7N4wr015322@krisdoz.my.domain \
    --to=kristaps@mdocml.bsd.lv \
    --cc=source@mdocml.bsd.lv \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).