summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2015-04-29 18:35:00 +0000
committerIngo Schwarze <schwarze@openbsd.org>2015-04-29 18:35:00 +0000
commitc7573bb09a210ded3f9d982b74618c8ca065c367 (patch)
treea25b62f819197be8ab2fcf8932196ca933f6855f
parentdb57abddea61d27902926e8bc578816ece975d27 (diff)
downloadmandoc-c7573bb09a210ded3f9d982b74618c8ca065c367.tar.gz
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).
-rw-r--r--roff.75
-rw-r--r--term.c68
-rw-r--r--term.h15
3 files changed, 35 insertions, 53 deletions
diff --git a/roff.7 b/roff.7
index bb44f6b4..d7515f40 100644
--- a/roff.7
+++ b/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
diff --git a/term.c b/term.c
index b46659bd..0bd147cc 100644
--- a/term.c
+++ b/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 *word)
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 *word)
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 *word)
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 + 7 >= p->maxcols)
+ adjbuf(p, p->col + 7);
- if (p->col + 6 >= p->maxcols)
- adjbuf(p, p->col + 6);
-
- 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 sz)
{
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] ||
diff --git a/term.h b/term.h
index 5b5fcc95..fc4eda7d 100644
--- a/term.h
+++ b/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(). */