diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2017-06-14 17:50:45 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2017-06-14 17:50:45 +0000 |
commit | 80ac93be26e104b44e59db20f822b3f1b3727034 (patch) | |
tree | ac6ead0756eed56a0f66ab9975b9b840171f3032 /usr.bin | |
parent | da25b5189535e7811c024d84f0c57bf36591811b (diff) |
improve rounding rules for scaling units
in horizontal orientation in the terminal formatter
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/mandoc/man_term.c | 12 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_term.c | 8 | ||||
-rw-r--r-- | usr.bin/mandoc/roff_term.c | 4 | ||||
-rw-r--r-- | usr.bin/mandoc/tbl_term.c | 4 | ||||
-rw-r--r-- | usr.bin/mandoc/term.c | 22 | ||||
-rw-r--r-- | usr.bin/mandoc/term.h | 3 | ||||
-rw-r--r-- | usr.bin/mandoc/term_tab.c | 14 |
7 files changed, 39 insertions, 28 deletions
diff --git a/usr.bin/mandoc/man_term.c b/usr.bin/mandoc/man_term.c index f43d1bd2a34..9b76fdc53f7 100644 --- a/usr.bin/mandoc/man_term.c +++ b/usr.bin/mandoc/man_term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: man_term.c,v 1.157 2017/06/08 12:54:40 schwarze Exp $ */ +/* $OpenBSD: man_term.c,v 1.158 2017/06/14 17:50:43 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2015, 2017 Ingo Schwarze <schwarze@openbsd.org> @@ -375,7 +375,7 @@ pre_in(DECL_ARGS) if (a2roffsu(++cp, &su, SCALE_EN) == NULL) return 0; - v = (term_hspan(p, &su) + 11) / 24; + v = term_hen(p, &su); if (less < 0) p->tcol->offset -= p->tcol->offset > v ? v : p->tcol->offset; @@ -424,7 +424,7 @@ pre_HP(DECL_ARGS) if ((nn = n->parent->head->child) != NULL && a2roffsu(nn->string, &su, SCALE_EN) != NULL) { - len = term_hspan(p, &su) / 24; + len = term_hen(p, &su); if (len < 0 && (size_t)(-len) > mt->offset) len = -mt->offset; else if (len > SHRT_MAX) @@ -509,7 +509,7 @@ pre_IP(DECL_ARGS) if ((nn = n->parent->head->child) != NULL && (nn = nn->next) != NULL && a2roffsu(nn->string, &su, SCALE_EN) != NULL) { - len = term_hspan(p, &su) / 24; + len = term_hen(p, &su); if (len < 0 && (size_t)(-len) > mt->offset) len = -mt->offset; else if (len > SHRT_MAX) @@ -591,7 +591,7 @@ pre_TP(DECL_ARGS) if ((nn = n->parent->head->child) != NULL && nn->string != NULL && ! (NODE_LINE & nn->flags) && a2roffsu(nn->string, &su, SCALE_EN) != NULL) { - len = term_hspan(p, &su) / 24; + len = term_hen(p, &su); if (len < 0 && (size_t)(-len) > mt->offset) len = -mt->offset; else if (len > SHRT_MAX) @@ -795,7 +795,7 @@ pre_RS(DECL_ARGS) if (n->child == NULL) n->aux = mt->lmargin[mt->lmargincur]; else if (a2roffsu(n->child->string, &su, SCALE_EN) != NULL) - n->aux = term_hspan(p, &su) / 24; + n->aux = term_hen(p, &su); if (n->aux < 0 && (size_t)(-n->aux) > mt->offset) n->aux = -mt->offset; else if (n->aux > SHRT_MAX) diff --git a/usr.bin/mandoc/mdoc_term.c b/usr.bin/mandoc/mdoc_term.c index d91ad6ef46f..3adb397fcfa 100644 --- a/usr.bin/mandoc/mdoc_term.c +++ b/usr.bin/mandoc/mdoc_term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc_term.c,v 1.262 2017/06/08 12:54:40 schwarze Exp $ */ +/* $OpenBSD: mdoc_term.c,v 1.263 2017/06/14 17:50:43 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010, 2012-2017 Ingo Schwarze <schwarze@openbsd.org> @@ -538,7 +538,7 @@ a2width(const struct termp *p, const char *v) SCALE_HS_INIT(&su, term_strlen(p, v)); su.scale /= term_strlen(p, "0"); } - return term_hspan(p, &su) / 24; + return term_hen(p, &su); } /* @@ -684,7 +684,7 @@ termp_it_pre(DECL_ARGS) SCALE_HS_INIT(&su, term_strlen(p, bl->norm->Bl.cols[i])); su.scale /= term_strlen(p, "0"); - offset += term_hspan(p, &su) / 24 + dcol; + offset += term_hen(p, &su) + dcol; } /* @@ -702,7 +702,7 @@ termp_it_pre(DECL_ARGS) */ SCALE_HS_INIT(&su, term_strlen(p, bl->norm->Bl.cols[i])); su.scale /= term_strlen(p, "0"); - width = term_hspan(p, &su) / 24 + dcol; + width = term_hen(p, &su) + dcol; break; default: if (NULL == bl->norm->Bl.width) diff --git a/usr.bin/mandoc/roff_term.c b/usr.bin/mandoc/roff_term.c index 608a9c509c9..e561b43b57c 100644 --- a/usr.bin/mandoc/roff_term.c +++ b/usr.bin/mandoc/roff_term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: roff_term.c,v 1.11 2017/06/14 13:00:13 schwarze Exp $ */ +/* $OpenBSD: roff_term.c,v 1.12 2017/06/14 17:50:43 schwarze Exp $ */ /* * Copyright (c) 2010, 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org> * @@ -205,7 +205,7 @@ roff_term_pre_ti(ROFF_TERM_ARGS) if (a2roffsu(cp, &su, SCALE_EM) == NULL) return; - len = term_hspan(p, &su) / 24; + len = term_hen(p, &su); if (sign == 0) { p->ti = len - p->tcol->offset; diff --git a/usr.bin/mandoc/tbl_term.c b/usr.bin/mandoc/tbl_term.c index 8011095d221..1c98af0ef84 100644 --- a/usr.bin/mandoc/tbl_term.c +++ b/usr.bin/mandoc/tbl_term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tbl_term.c,v 1.39 2017/06/13 14:38:38 schwarze Exp $ */ +/* $OpenBSD: tbl_term.c,v 1.40 2017/06/14 17:50:43 schwarze Exp $ */ /* * Copyright (c) 2009, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011,2012,2014,2015,2017 Ingo Schwarze <schwarze@openbsd.org> @@ -45,7 +45,7 @@ static void tbl_word(struct termp *, const struct tbl_dat *); static size_t term_tbl_sulen(const struct roffsu *su, void *arg) { - return term_hspan((const struct termp *)arg, su) / 24; + return term_hen((const struct termp *)arg, su); } static size_t diff --git a/usr.bin/mandoc/term.c b/usr.bin/mandoc/term.c index e6aebdc379a..9c93a3a90a5 100644 --- a/usr.bin/mandoc/term.c +++ b/usr.bin/mandoc/term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: term.c,v 1.130 2017/06/14 01:31:19 schwarze Exp $ */ +/* $OpenBSD: term.c,v 1.131 2017/06/14 17:50:43 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2017 Ingo Schwarze <schwarze@openbsd.org> @@ -526,7 +526,7 @@ term_word(struct termp *p, const char *word) case ESCAPE_HORIZ: if (a2roffsu(seq, &su, SCALE_EM) == NULL) continue; - uc = term_hspan(p, &su) / 24; + uc = term_hen(p, &su); if (uc > 0) while (uc-- > 0) bufferc(p, ASCII_NBRSP); @@ -547,7 +547,7 @@ term_word(struct termp *p, const char *word) case ESCAPE_HLINE: if ((seq = a2roffsu(seq, &su, SCALE_EM)) == NULL) continue; - uc = term_hspan(p, &su) / 24; + uc = term_hen(p, &su); if (uc <= 0) { if (p->tcol->rmargin <= p->tcol->offset) continue; @@ -964,7 +964,7 @@ term_vspan(const struct termp *p, const struct roffsu *su) } /* - * Convert a scaling width to basic units, rounding down. + * Convert a scaling width to basic units, rounding towards 0. */ int term_hspan(const struct termp *p, const struct roffsu *su) @@ -972,3 +972,17 @@ term_hspan(const struct termp *p, const struct roffsu *su) return (*p->hspan)(p, su); } + +/* + * Convert a scaling width to basic units, rounding to closest. + */ +int +term_hen(const struct termp *p, const struct roffsu *su) +{ + int bu; + + if ((bu = (*p->hspan)(p, su)) >= 0) + return (bu + 11) / 24; + else + return -((-bu + 11) / 24); +} diff --git a/usr.bin/mandoc/term.h b/usr.bin/mandoc/term.h index ffbeb24127e..0042627cc82 100644 --- a/usr.bin/mandoc/term.h +++ b/usr.bin/mandoc/term.h @@ -1,4 +1,4 @@ -/* $OpenBSD: term.h,v 1.71 2017/06/12 18:55:42 schwarze Exp $ */ +/* $OpenBSD: term.h,v 1.72 2017/06/14 17:50:43 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011-2015, 2017 Ingo Schwarze <schwarze@openbsd.org> @@ -140,6 +140,7 @@ void term_end(struct termp *); void term_setwidth(struct termp *, const char *); int term_hspan(const struct termp *, const struct roffsu *); +int term_hen(const struct termp *, const struct roffsu *); int term_vspan(const struct termp *, const struct roffsu *); size_t term_strlen(const struct termp *, const char *); size_t term_len(const struct termp *, size_t); diff --git a/usr.bin/mandoc/term_tab.c b/usr.bin/mandoc/term_tab.c index 326a112c7f3..31648407388 100644 --- a/usr.bin/mandoc/term_tab.c +++ b/usr.bin/mandoc/term_tab.c @@ -1,4 +1,4 @@ -/* $OpenBSD: term_tab.c,v 1.2 2017/06/08 12:54:40 schwarze Exp $ */ +/* $OpenBSD: term_tab.c,v 1.3 2017/06/14 17:50:43 schwarze Exp $ */ /* * Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> * @@ -52,7 +52,7 @@ term_tab_set(const struct termp *p, const char *arg) recording_period = 0; if (tabs.d == 0) { a2roffsu(".8i", &su, SCALE_IN); - tabs.d = term_hspan(p, &su) / 24; + tabs.d = term_hen(p, &su); } return; } @@ -81,7 +81,7 @@ term_tab_set(const struct termp *p, const char *arg) /* Append the new position. */ - pos = term_hspan(p, &su); + pos = term_hen(p, &su); tl->t[tl->n] = pos; if (add && tl->n) tl->t[tl->n] += tl->t[tl->n - 1]; @@ -97,10 +97,6 @@ term_tab_next(size_t prev) if (i == tabs.a.n) { if (tabs.p.n == 0) return prev; -/* - return i ? prev : - (prev / tabs.d + 1) * tabs.d; - */ tabs.a.n += tabs.p.n; if (tabs.a.s < tabs.a.n) { tabs.a.s = tabs.a.n; @@ -111,7 +107,7 @@ term_tab_next(size_t prev) tabs.a.t[i + j] = tabs.p.t[j] + (i ? tabs.a.t[i - 1] : 0); } - if (prev < tabs.a.t[i] / 24) - return tabs.a.t[i] / 24; + if (prev < tabs.a.t[i]) + return tabs.a.t[i]; } } |