source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Replace the kludge for the \z escape sequence by an actual
@ 2015-04-29 18:35 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2015-04-29 18:35 UTC (permalink / raw)
  To: source

Log Message:
-----------
Replace the kludge for the \z escape sequence by an actual 
implementation.  As a side effect, minus ten lines of code.

As another side effect, this also fixes the assertion failure that 
used to be triggered by "\z\o'ab'c" at the beginning of an output
line, found by jsg@ with afl (test case 022/Apr27).

Modified Files:
--------------
    mdocml:
        term.c
        term.h
        roff.7

Revision Data
-------------
Index: term.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/term.c,v
retrieving revision 1.247
retrieving revision 1.248
diff -Lterm.c -Lterm.c -u -p -r1.247 -r1.248
--- term.c
+++ term.c
@@ -265,6 +265,7 @@ term_flushln(struct termp *p)
 
 	p->col = 0;
 	p->overstep = 0;
+	p->flags &= ~(TERMP_BACKAFTER | TERMP_BACKBEFORE);
 
 	if ( ! (TERMP_NOBREAK & p->flags)) {
 		p->viscol = 0;
@@ -417,11 +418,6 @@ term_word(struct termp *p, const char *w
 
 	while ('\0' != *word) {
 		if ('\\' != *word) {
-			if (TERMP_SKIPCHAR & p->flags) {
-				p->flags &= ~TERMP_SKIPCHAR;
-				word++;
-				continue;
-			}
 			if (TERMP_NBRWORD & p->flags) {
 				if (' ' == *word) {
 					encode(p, nbrsp, 1);
@@ -480,13 +476,13 @@ term_word(struct termp *p, const char *w
 			term_fontlast(p);
 			continue;
 		case ESCAPE_NOSPACE:
-			if (TERMP_SKIPCHAR & p->flags)
-				p->flags &= ~TERMP_SKIPCHAR;
-			else if ('\0' == *word)
+			if (p->flags & TERMP_BACKAFTER)
+				p->flags &= ~TERMP_BACKAFTER;
+			else if (*word == '\0')
 				p->flags |= (TERMP_NOSPACE | TERMP_NONEWLINE);
 			continue;
 		case ESCAPE_SKIPCHAR:
-			p->flags |= TERMP_SKIPCHAR;
+			p->flags |= TERMP_BACKAFTER;
 			continue;
 		case ESCAPE_OVERSTRIKE:
 			cp = seq + sz;
@@ -496,9 +492,14 @@ term_word(struct termp *p, const char *w
 					continue;
 				}
 				encode1(p, *seq++);
-				if (seq < cp)
-					encode(p, "\b", 1);
+				if (seq < cp) {
+					if (p->flags & TERMP_BACKBEFORE)
+						p->flags |= TERMP_BACKAFTER;
+					else
+						p->flags |= TERMP_BACKBEFORE;
+				}
 			}
+			continue;
 		default:
 			continue;
 		}
@@ -553,16 +554,16 @@ encode1(struct termp *p, int c)
 {
 	enum termfont	  f;
 
-	if (TERMP_SKIPCHAR & p->flags) {
-		p->flags &= ~TERMP_SKIPCHAR;
-		return;
-	}
-
-	if (p->col + 6 >= p->maxcols)
-		adjbuf(p, p->col + 6);
+	if (p->col + 7 >= p->maxcols)
+		adjbuf(p, p->col + 7);
 
-	f = p->fontq[p->fonti];
+	f = (c == ASCII_HYPH || isgraph(c)) ?
+	    p->fontq[p->fonti] : TERMFONT_NONE;
 
+	if (p->flags & TERMP_BACKBEFORE) {
+		p->buf[p->col++] = 8;
+		p->flags &= ~TERMP_BACKBEFORE;
+	}
 	if (TERMFONT_UNDER == f || TERMFONT_BI == f) {
 		p->buf[p->col++] = '_';
 		p->buf[p->col++] = 8;
@@ -575,6 +576,10 @@ encode1(struct termp *p, int c)
 		p->buf[p->col++] = 8;
 	}
 	p->buf[p->col++] = c;
+	if (p->flags & TERMP_BACKAFTER) {
+		p->flags |= TERMP_BACKBEFORE;
+		p->flags &= ~TERMP_BACKAFTER;
+	}
 }
 
 static void
@@ -582,29 +587,8 @@ encode(struct termp *p, const char *word
 {
 	size_t		  i;
 
-	if (TERMP_SKIPCHAR & p->flags) {
-		p->flags &= ~TERMP_SKIPCHAR;
-		return;
-	}
-
-	/*
-	 * Encode and buffer a string of characters.  If the current
-	 * font mode is unset, buffer directly, else encode then buffer
-	 * character by character.
-	 */
-
-	if (p->fontq[p->fonti] == TERMFONT_NONE) {
-		if (p->col + sz >= p->maxcols)
-			adjbuf(p, p->col + sz);
-		for (i = 0; i < sz; i++)
-			p->buf[p->col++] = word[i];
-		return;
-	}
-
-	/* Pre-buffer, assuming worst-case. */
-
-	if (p->col + 1 + (sz * 5) >= p->maxcols)
-		adjbuf(p, p->col + 1 + (sz * 5));
+	if (p->col + 2 + (sz * 5) >= p->maxcols)
+		adjbuf(p, p->col + 2 + (sz * 5));
 
 	for (i = 0; i < sz; i++) {
 		if (ASCII_HYPH == word[i] ||
Index: roff.7
===================================================================
RCS file: /home/cvs/mdocml/mdocml/roff.7,v
retrieving revision 1.70
retrieving revision 1.71
diff -Lroff.7 -Lroff.7 -u -p -r1.70 -r1.71
--- roff.7
+++ roff.7
@@ -2028,10 +2028,7 @@ Print
 with zero width and height; ignored by
 .Xr mandoc 1 .
 .Ss \ez
-Output the next character without advancing the cursor position;
-approximated in
-.Xr mandoc 1
-by simply skipping the next character.
+Output the next character without advancing the cursor position.
 .Sh COMPATIBILITY
 The
 .Xr mandoc 1
Index: term.h
===================================================================
RCS file: /home/cvs/mdocml/mdocml/term.h,v
retrieving revision 1.113
retrieving revision 1.114
diff -Lterm.h -Lterm.h -u -p -r1.113 -r1.114
--- term.h
+++ term.h
@@ -67,13 +67,14 @@ struct	termp {
 	int		  overstep;	/* See termp_flushln(). */
 	int		  skipvsp;	/* Vertical space to skip. */
 	int		  flags;
-#define	TERMP_SENTENCE	 (1 << 1)	/* Space before a sentence. */
-#define	TERMP_NOSPACE	 (1 << 2)	/* No space before words. */
-#define	TERMP_NONOSPACE	 (1 << 3)	/* No space (no autounset). */
-#define	TERMP_NBRWORD	 (1 << 4)	/* Make next word nonbreaking. */
-#define	TERMP_KEEP	 (1 << 5)	/* Keep words together. */
-#define	TERMP_PREKEEP	 (1 << 6)	/* ...starting with the next one. */
-#define	TERMP_SKIPCHAR	 (1 << 7)	/* Skip the next character. */
+#define	TERMP_SENTENCE	 (1 << 0)	/* Space before a sentence. */
+#define	TERMP_NOSPACE	 (1 << 1)	/* No space before words. */
+#define	TERMP_NONOSPACE	 (1 << 2)	/* No space (no autounset). */
+#define	TERMP_NBRWORD	 (1 << 3)	/* Make next word nonbreaking. */
+#define	TERMP_KEEP	 (1 << 4)	/* Keep words together. */
+#define	TERMP_PREKEEP	 (1 << 5)	/* ...starting with the next one. */
+#define	TERMP_BACKAFTER	 (1 << 6)	/* Back up after next character. */
+#define	TERMP_BACKBEFORE (1 << 7)	/* Back up before next character. */
 #define	TERMP_NOBREAK	 (1 << 8)	/* See term_flushln(). */
 #define	TERMP_BRIND	 (1 << 9)	/* See term_flushln(). */
 #define	TERMP_DANGLE	 (1 << 10)	/* See term_flushln(). */
--
 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:[~2015-04-29 18:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-29 18:35 mdocml: Replace the kludge for the \z escape sequence by an actual schwarze

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).