]> git.cameronkatri.com Git - mandoc.git/blobdiff - term.c
Finally port the OpenBSD regression suite.
[mandoc.git] / term.c
diff --git a/term.c b/term.c
index 559f6caafd083138c868f8c2b68227069dc4771d..1217d473cadd8fccbc5988014633e834c4aae0b3 100644 (file)
--- a/term.c
+++ b/term.c
@@ -1,7 +1,7 @@
-/*     $Id: term.c,v 1.250 2015/09/21 13:25:00 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;
 }
@@ -454,12 +454,11 @@ term_word(struct termp *p, const char *word)
                        break;
                case ESCAPE_SPECIAL:
                        if (p->enc == TERMENC_ASCII) {
-                               cp = mchars_spec2str(p->symtab,
-                                   seq, sz, &ssz);
+                               cp = mchars_spec2str(seq, sz, &ssz);
                                if (cp != NULL)
                                        encode(p, cp, ssz);
                        } else {
-                               uc = mchars_spec2cp(p->symtab, seq, sz);
+                               uc = mchars_spec2cp(seq, sz);
                                if (uc > 0)
                                        encode1(p, uc);
                        }
@@ -474,7 +473,6 @@ term_word(struct termp *p, const char *word)
                        term_fontrepl(p, TERMFONT_BI);
                        continue;
                case ESCAPE_FONT:
-                       /* FALLTHROUGH */
                case ESCAPE_FONTROMAN:
                        term_fontrepl(p, TERMFONT_NONE);
                        continue;
@@ -506,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:
@@ -566,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;
@@ -606,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;
+                       }
+               }
        }
 }
 
@@ -644,7 +656,7 @@ size_t
 term_len(const struct termp *p, size_t sz)
 {
 
-       return((*p->width)(p, ' ') * sz);
+       return (*p->width)(p, ' ') * sz;
 }
 
 static size_t
@@ -653,9 +665,9 @@ cond_width(const struct termp *p, int c, int *skip)
 
        if (*skip) {
                (*skip) = 0;
-               return(0);
+               return 0;
        } else
-               return((*p->width)(p, c));
+               return (*p->width)(p, c);
 }
 
 size_t
@@ -701,13 +713,11 @@ term_strlen(const struct termp *p, const char *cp)
                                break;
                        case ESCAPE_SPECIAL:
                                if (p->enc == TERMENC_ASCII) {
-                                       rhs = mchars_spec2str(p->symtab,
-                                           seq, ssz, &rsz);
+                                       rhs = mchars_spec2str(seq, ssz, &rsz);
                                        if (rhs != NULL)
                                                break;
                                } else {
-                                       uc = mchars_spec2cp(p->symtab,
-                                           seq, ssz);
+                                       uc = mchars_spec2cp(seq, ssz);
                                        if (uc > 0)
                                                sz += cond_width(p, uc, &skip);
                                }
@@ -771,15 +781,13 @@ term_strlen(const struct termp *p, const char *cp)
                case ASCII_HYPH:
                        sz += cond_width(p, '-', &skip);
                        cp++;
-                       /* FALLTHROUGH */
-               case ASCII_BREAK:
                        break;
                default:
                        break;
                }
        }
 
-       return(sz);
+       return sz;
 }
 
 int
@@ -811,7 +819,6 @@ term_vspan(const struct termp *p, const struct roffsu *su)
                r = su->scale / 12.0;
                break;
        case SCALE_EN:
-               /* FALLTHROUGH */
        case SCALE_EM:
                r = su->scale * 0.6;
                break;
@@ -820,10 +827,9 @@ term_vspan(const struct termp *p, const struct roffsu *su)
                break;
        default:
                abort();
-               /* NOTREACHED */
        }
        ri = r > 0.0 ? r + 0.4995 : r - 0.4995;
-       return(ri < 66 ? ri : 1);
+       return ri < 66 ? ri : 1;
 }
 
 /*
@@ -833,5 +839,5 @@ int
 term_hspan(const struct termp *p, const struct roffsu *su)
 {
 
-       return((*p->hspan)(p, su));
+       return (*p->hspan)(p, su);
 }