]> git.cameronkatri.com Git - mandoc.git/blobdiff - term.c
Move .sp to the roff modules. Enough infrastructure is in place
[mandoc.git] / term.c
diff --git a/term.c b/term.c
index 4bab903497beb23b0214062b591b2e26e9e9b051..1217d473cadd8fccbc5988014633e834c4aae0b3 100644 (file)
--- a/term.c
+++ b/term.c
@@ -1,7 +1,7 @@
-/*     $Id: term.c,v 1.254 2015/10/13 22:59:54 schwarze Exp $ */
+/*     $Id: term.c,v 1.259 2017/01/08 18:16:58 schwarze Exp $ */
 /*
  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2010-2017 Ingo Schwarze <schwarze@openbsd.org>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -160,7 +160,7 @@ term_flushln(struct termp *p)
                        if (' ' == p->buf[j] || '\t' == p->buf[j])
                                break;
 
-                       /* Back over the the last printed character. */
+                       /* Back over the last printed character. */
                        if (8 == p->buf[j]) {
                                assert(j);
                                vend -= (*p->width)(p, p->buf[j - 1]);
@@ -365,7 +365,7 @@ term_fontpush(struct termp *p, enum termfont f)
        if (++p->fonti == p->fontsz) {
                p->fontsz += 8;
                p->fontq = mandoc_reallocarray(p->fontq,
-                   p->fontsz, sizeof(enum termfont *));
+                   p->fontsz, sizeof(*p->fontq));
        }
        p->fontq[p->fonti] = f;
 }
@@ -504,7 +504,9 @@ term_word(struct termp *p, const char *word)
                                }
                        }
                        /* Trim trailing backspace/blank pair. */
-                       if (p->col > 2 && p->buf[p->col - 1] == ' ')
+                       if (p->col > 2 &&
+                           (p->buf[p->col - 1] == ' ' ||
+                            p->buf[p->col - 1] == '\t'))
                                p->col -= 2;
                        continue;
                default:
@@ -564,11 +566,11 @@ encode1(struct termp *p, int c)
        if (p->col + 7 >= p->maxcols)
                adjbuf(p, p->col + 7);
 
-       f = (c == ASCII_HYPH || isgraph(c)) ?
+       f = (c == ASCII_HYPH || c > 127 || isgraph(c)) ?
            p->fontq[p->fonti] : TERMFONT_NONE;
 
        if (p->flags & TERMP_BACKBEFORE) {
-               if (p->buf[p->col - 1] == ' ')
+               if (p->buf[p->col - 1] == ' ' || p->buf[p->col - 1] == '\t')
                        p->col--;
                else
                        p->buf[p->col++] = 8;
@@ -604,8 +606,20 @@ encode(struct termp *p, const char *word, size_t sz)
                if (ASCII_HYPH == word[i] ||
                    isgraph((unsigned char)word[i]))
                        encode1(p, word[i]);
-               else
+               else {
                        p->buf[p->col++] = word[i];
+
+                       /*
+                        * Postpone the effect of \z while handling
+                        * an overstrike sequence from ascii_uc2str().
+                        */
+
+                       if (word[i] == '\b' &&
+                           (p->flags & TERMP_BACKBEFORE)) {
+                               p->flags &= ~TERMP_BACKBEFORE;
+                               p->flags |= TERMP_BACKAFTER;
+                       }
+               }
        }
 }