From: schwarze Date: Tue, 23 Dec 2014 09:31:17 +0000 (+0000) Subject: some scaling unit fixes: X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=84f230ba6e30895d9c993ecfab5b8fd60dc01934;p=openbsd some scaling unit fixes: - .sp with an invalid argument is .sp 1v, not .sp 0v - in man(1), trailing garbage doesn't make scaling units invalid --- diff --git a/regress/usr.bin/mandoc/man/PD/args.in b/regress/usr.bin/mandoc/man/PD/args.in index df344a1a9b2..97bd79935ee 100644 --- a/regress/usr.bin/mandoc/man/PD/args.in +++ b/regress/usr.bin/mandoc/man/PD/args.in @@ -1,4 +1,4 @@ -.TH PD-ARGS 1 "July 29, 2012" OpenBSD +.TH PD-ARGS 1 "December 23, 2014" OpenBSD .SH NAME PD-args \- unusual arguments to the PD macro .SH DESCRIPTION @@ -17,9 +17,9 @@ argument(2v) .PD 2p .PP argument(2p) -.PD 1c +.PD 1cx .PP -argument(1c) +argument(1cx) .PD xxx .PP argument(xxx) diff --git a/regress/usr.bin/mandoc/man/PD/args.out_ascii b/regress/usr.bin/mandoc/man/PD/args.out_ascii index e0bb2f18261..24f98d55d38 100644 --- a/regress/usr.bin/mandoc/man/PD/args.out_ascii +++ b/regress/usr.bin/mandoc/man/PD/args.out_ascii @@ -20,7 +20,7 @@ DDEESSCCRRIIPPTTIIOONN argument(2p) - argument(1c) + argument(1cx) argument(xxx) @@ -28,4 +28,4 @@ DDEESSCCRRIIPPTTIIOONN -OpenBSD July 29, 2012 PD-ARGS(1) +OpenBSD December 23, 2014 PD-ARGS(1) diff --git a/regress/usr.bin/mandoc/roff/scale/horiz.in b/regress/usr.bin/mandoc/roff/scale/horiz.in index cd74e7ccfe6..f3b36652019 100644 --- a/regress/usr.bin/mandoc/roff/scale/horiz.in +++ b/regress/usr.bin/mandoc/roff/scale/horiz.in @@ -1,4 +1,4 @@ -.TH HORIZ 1 "November 20, 2014" OpenBSD +.TH HORIZ 1 "December 23, 2014" OpenBSD .SH NAME horiz \- horizontal distances .SH DESCRIPTION @@ -23,5 +23,7 @@ initial text 5m .in 79n 79n +.in 1.5ix +1.5ix .PP final text diff --git a/regress/usr.bin/mandoc/roff/scale/horiz.out_ascii b/regress/usr.bin/mandoc/roff/scale/horiz.out_ascii index 5c7f1d5fbad..8db827eb1e3 100644 --- a/regress/usr.bin/mandoc/roff/scale/horiz.out_ascii +++ b/regress/usr.bin/mandoc/roff/scale/horiz.out_ascii @@ -17,9 +17,10 @@ DDEESSCCRRIIPPTTIIOONN 10n 5m 79n + 1.5ix final text -OpenBSD November 20, 2014 HORIZ(1) +OpenBSD December 23, 2014 HORIZ(1) diff --git a/regress/usr.bin/mandoc/roff/sp/badargs-man.in b/regress/usr.bin/mandoc/roff/sp/badargs-man.in index 46b9ab6512b..0a7eb075eed 100644 --- a/regress/usr.bin/mandoc/roff/sp/badargs-man.in +++ b/regress/usr.bin/mandoc/roff/sp/badargs-man.in @@ -1,4 +1,4 @@ -.TH SP-BADARGS-MAN 1 "December 4, 2014" OpenBSD +.TH SP-BADARGS-MAN 1 "December 23, 2014" OpenBSD .SH NAME sp-badargs-man \- bad arguments to .sp macros in man(7) .SH DESCRIPTION @@ -10,4 +10,8 @@ two arguments: .sp 3v 2i no scaling unit specified: .sp 1 +trailing garbage: +.sp 2vx +garbage only: +.sp xxx end of test document diff --git a/regress/usr.bin/mandoc/roff/sp/badargs-man.out_ascii b/regress/usr.bin/mandoc/roff/sp/badargs-man.out_ascii index 1c559570458..b04219168a8 100644 --- a/regress/usr.bin/mandoc/roff/sp/badargs-man.out_ascii +++ b/regress/usr.bin/mandoc/roff/sp/badargs-man.out_ascii @@ -17,8 +17,13 @@ DDEESSCCRRIIPPTTIIOONN no scaling unit specified: + trailing garbage: + + + garbage only: + end of test document -OpenBSD December 4, 2014 SP-BADARGS-MAN(1) +OpenBSD December 23, 2014 SP-BADARGS-MAN(1) diff --git a/regress/usr.bin/mandoc/roff/sp/badargs-mdoc.in b/regress/usr.bin/mandoc/roff/sp/badargs-mdoc.in index f7cf74a6578..684ee7e3a23 100644 --- a/regress/usr.bin/mandoc/roff/sp/badargs-mdoc.in +++ b/regress/usr.bin/mandoc/roff/sp/badargs-mdoc.in @@ -1,4 +1,4 @@ -.Dd December 4, 2014 +.Dd December 23, 2014 .Dt SP-BADARGS-MDOC 1 .Os OpenBSD .Sh NAME @@ -13,4 +13,8 @@ two arguments: .sp 3v 2i no scaling unit specified: .sp 1 +trailing garbage: +.sp 2vx +garbage only: +.sp xxx end of test document diff --git a/regress/usr.bin/mandoc/roff/sp/badargs-mdoc.out_ascii b/regress/usr.bin/mandoc/roff/sp/badargs-mdoc.out_ascii index c9d03c2ed67..3e1f87ed715 100644 --- a/regress/usr.bin/mandoc/roff/sp/badargs-mdoc.out_ascii +++ b/regress/usr.bin/mandoc/roff/sp/badargs-mdoc.out_ascii @@ -15,6 +15,11 @@ DDEESSCCRRIIPPTTIIOONN no scaling unit specified: + trailing garbage: + + + garbage only: + end of test document -OpenBSD December 4, 2014 OpenBSD +OpenBSD December 23, 2014 OpenBSD diff --git a/usr.bin/mandoc/man_html.c b/usr.bin/mandoc/man_html.c index facecf9b7af..21383c8fec6 100644 --- a/usr.bin/mandoc/man_html.c +++ b/usr.bin/mandoc/man_html.c @@ -1,4 +1,4 @@ -/* $OpenBSD: man_html.c,v 1.60 2014/12/04 02:05:16 schwarze Exp $ */ +/* $OpenBSD: man_html.c,v 1.61 2014/12/23 09:31:17 schwarze Exp $ */ /* * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons * Copyright (c) 2013, 2014 Ingo Schwarze @@ -360,7 +360,7 @@ man_br_pre(MAN_ARGS) if (MAN_sp == n->tok) { if (NULL != (n = n->child)) if ( ! a2roffsu(n->string, &su, SCALE_VS)) - SCALE_VS_INIT(&su, atoi(n->string)); + su.scale = 1.0; } else su.scale = 0.0; diff --git a/usr.bin/mandoc/man_term.c b/usr.bin/mandoc/man_term.c index 61db99d3906..06340e2a232 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.114 2014/12/23 08:15:37 schwarze Exp $ */ +/* $OpenBSD: man_term.c,v 1.115 2014/12/23 09:31:17 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze @@ -55,7 +55,6 @@ struct termact { }; static int a2width(const struct termp *, const char *); -static size_t a2height(const struct termp *, const char *); static void print_man_nodelist(DECL_ARGS); static void print_man_node(DECL_ARGS); @@ -182,18 +181,6 @@ terminal_man(void *arg, const struct man *man) } } - -static size_t -a2height(const struct termp *p, const char *cp) -{ - struct roffsu su; - - if ( ! a2roffsu(cp, &su, SCALE_VS)) - SCALE_VS_INIT(&su, atoi(cp)); - - return(term_vspan(p, &su)); -} - static int a2width(const struct termp *p, const char *cp) { @@ -462,6 +449,7 @@ pre_in(DECL_ARGS) static int pre_sp(DECL_ARGS) { + struct roffsu su; char *s; size_t i, len; int neg; @@ -499,7 +487,9 @@ pre_sp(DECL_ARGS) neg = 1; s++; } - len = a2height(p, s); + if ( ! a2roffsu(s, &su, SCALE_VS)) + su.scale = 1.0; + len = term_vspan(p, &su); break; } diff --git a/usr.bin/mandoc/mdoc_html.c b/usr.bin/mandoc/mdoc_html.c index 1b95dc47e92..05b678b2d26 100644 --- a/usr.bin/mandoc/mdoc_html.c +++ b/usr.bin/mandoc/mdoc_html.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc_html.c,v 1.91 2014/12/02 10:07:17 schwarze Exp $ */ +/* $OpenBSD: mdoc_html.c,v 1.92 2014/12/23 09:31:17 schwarze Exp $ */ /* * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons * Copyright (c) 2014 Ingo Schwarze @@ -277,7 +277,7 @@ static void a2width(const char *p, struct roffsu *su) { - if ( ! a2roffsu(p, su, SCALE_MAX)) { + if (a2roffsu(p, su, SCALE_MAX) < 2) { su->unit = SCALE_EN; su->scale = html_strlen(p); } @@ -1566,7 +1566,7 @@ mdoc_sp_pre(MDOC_ARGS) if (MDOC_sp == n->tok) { if (NULL != (n = n->child)) if ( ! a2roffsu(n->string, &su, SCALE_VS)) - SCALE_VS_INIT(&su, atoi(n->string)); + su.scale = 1.0; } else su.scale = 0.0; diff --git a/usr.bin/mandoc/mdoc_man.c b/usr.bin/mandoc/mdoc_man.c index 5989154f41d..30799cd4c7a 100644 --- a/usr.bin/mandoc/mdoc_man.c +++ b/usr.bin/mandoc/mdoc_man.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc_man.c,v 1.75 2014/11/30 05:28:00 schwarze Exp $ */ +/* $OpenBSD: mdoc_man.c,v 1.76 2014/12/23 09:31:17 schwarze Exp $ */ /* * Copyright (c) 2011, 2012, 2013, 2014 Ingo Schwarze * @@ -432,7 +432,7 @@ print_offs(const char *v, int keywords) sz = 6; else if (keywords && !strcmp(v, "indent-two")) sz = 12; - else if (a2roffsu(v, &su, SCALE_MAX)) { + else if (a2roffsu(v, &su, SCALE_EN) < 2) { if (SCALE_EN == su.unit) sz = su.scale; else { @@ -479,7 +479,7 @@ print_width(const char *v, const struct mdoc_node *child, size_t defsz) /* Convert v into a number (of characters). */ if (NULL == v) sz = defsz; - else if (a2roffsu(v, &su, SCALE_MAX)) { + else if (a2roffsu(v, &su, SCALE_MAX) < 2) { if (SCALE_EN == su.unit) sz = su.scale; else { diff --git a/usr.bin/mandoc/mdoc_term.c b/usr.bin/mandoc/mdoc_term.c index 29f604d89f5..f12989e5f54 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.198 2014/12/02 10:07:17 schwarze Exp $ */ +/* $OpenBSD: mdoc_term.c,v 1.199 2014/12/23 09:31:17 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2012, 2013, 2014 Ingo Schwarze @@ -48,7 +48,6 @@ struct termact { }; static size_t a2width(const struct termp *, const char *); -static size_t a2height(const struct termp *, const char *); static void print_bvspace(struct termp *, const struct mdoc_node *, @@ -524,26 +523,12 @@ print_mdoc_head(struct termp *p, const void *arg) free(volume); } -static size_t -a2height(const struct termp *p, const char *v) -{ - struct roffsu su; - - - assert(v); - if ( ! a2roffsu(v, &su, SCALE_VS)) - SCALE_VS_INIT(&su, atoi(v)); - - return(term_vspan(p, &su)); -} - static size_t a2width(const struct termp *p, const char *v) { struct roffsu su; - assert(v); - if ( ! a2roffsu(v, &su, SCALE_MAX)) { + if (a2roffsu(v, &su, SCALE_MAX) < 2) { SCALE_HS_INIT(&su, term_strlen(p, v)); su.scale /= term_strlen(p, "0"); } @@ -1814,11 +1799,17 @@ termp_in_post(DECL_ARGS) static int termp_sp_pre(DECL_ARGS) { + struct roffsu su; size_t i, len; switch (n->tok) { case MDOC_sp: - len = n->child ? a2height(p, n->child->string) : 1; + if (n->child) { + if ( ! a2roffsu(n->child->string, &su, SCALE_VS)) + su.scale = 1.0; + len = term_vspan(p, &su); + } else + len = 1; break; case MDOC_br: len = 0; diff --git a/usr.bin/mandoc/out.c b/usr.bin/mandoc/out.c index a7c3a6b9eea..e18224399cd 100644 --- a/usr.bin/mandoc/out.c +++ b/usr.bin/mandoc/out.c @@ -1,4 +1,4 @@ -/* $OpenBSD: out.c,v 1.27 2014/12/23 03:27:36 schwarze Exp $ */ +/* $OpenBSD: out.c,v 1.28 2014/12/23 09:31:17 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2011, 2014 Ingo Schwarze @@ -38,65 +38,64 @@ static void tblcalc_number(struct rofftbl *, struct roffcol *, * Parse the *src string and store a scaling unit into *dst. * If the string doesn't specify the unit, use the default. * If no default is specified, fail. - * Return 1 on success and 0 on failure. + * Return 2 on complete success, 1 when a conversion was done, + * but there was trailing garbage, and 0 on total failure. */ int a2roffsu(const char *src, struct roffsu *dst, enum roffscale def) { char *endptr; - double scale; - enum roffscale unit; - scale = strtod(src, &endptr); - if (endptr == src || (endptr[0] != '\0' && endptr[1] != '\0')) + dst->unit = def == SCALE_MAX ? SCALE_BU : def; + dst->scale = strtod(src, &endptr); + if (endptr == src) return(0); - switch (*endptr) { + switch (*endptr++) { case 'c': - unit = SCALE_CM; + dst->unit = SCALE_CM; break; case 'i': - unit = SCALE_IN; + dst->unit = SCALE_IN; + break; + case 'f': + dst->unit = SCALE_FS; + break; + case 'M': + dst->unit = SCALE_MM; + break; + case 'm': + dst->unit = SCALE_EM; + break; + case 'n': + dst->unit = SCALE_EN; break; case 'P': - unit = SCALE_PC; + dst->unit = SCALE_PC; break; case 'p': - unit = SCALE_PT; + dst->unit = SCALE_PT; break; - case 'f': - unit = SCALE_FS; + case 'u': + dst->unit = SCALE_BU; break; case 'v': - unit = SCALE_VS; - break; - case 'm': - unit = SCALE_EM; + dst->unit = SCALE_VS; break; case '\0': + endptr--; + /* FALLTHROUGH */ + default: if (SCALE_MAX == def) return(0); - unit = def; + dst->unit = def; break; - case 'u': - unit = SCALE_BU; - break; - case 'M': - unit = SCALE_MM; - break; - case 'n': - unit = SCALE_EN; - break; - default: - return(0); } /* FIXME: do this in the caller. */ - if (scale < 0.0) - scale = 0.0; - dst->scale = scale; - dst->unit = unit; - return(1); + if (dst->scale < 0.0) + dst->scale = 0.0; + return(*endptr == '\0' ? 2 : 1); } /*