summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorschwarze <schwarze@openbsd.org>2014-10-30 20:05:33 +0000
committerschwarze <schwarze@openbsd.org>2014-10-30 20:05:33 +0000
commit90d52a15db492c50d3bf425de213ffe6237f3ef0 (patch)
tree616ddd3725a2aa59f5789ba6b9e85c5220b1d037
parentmuliply to get correct size for free. reported by kspillner (diff)
downloadwireguard-openbsd-90d52a15db492c50d3bf425de213ffe6237f3ef0.tar.xz
wireguard-openbsd-90d52a15db492c50d3bf425de213ffe6237f3ef0.zip
Major bugsquashing with respect to -offset and -width:
1. Support specifying the .Bd and .Bl -offset as a macro default width; while here, simplify the code handling the same for .Bl -width. 2. Correct handling of .Bl -offset arguments: unlike .Bd -offset, the arguments "left", "indent", and "indent-two" have no special meaning. 3. Fix the scaling of string length -offset and -width arguments in -Thtml. Triggered by an incomplete documentation patch from bentley@.
-rw-r--r--regress/usr.bin/mandoc/mdoc/Bd/offset-empty.in5
-rw-r--r--regress/usr.bin/mandoc/mdoc/Bd/offset-empty.out_ascii4
-rw-r--r--regress/usr.bin/mandoc/mdoc/Bl/Makefile4
-rw-r--r--regress/usr.bin/mandoc/mdoc/Bl/offset.in63
-rw-r--r--regress/usr.bin/mandoc/mdoc/Bl/offset.out_ascii35
-rw-r--r--share/man/man7/mdoc.711
-rw-r--r--usr.bin/mandoc/mdoc_html.c42
-rw-r--r--usr.bin/mandoc/mdoc_man.c20
-rw-r--r--usr.bin/mandoc/mdoc_term.c39
-rw-r--r--usr.bin/mandoc/mdoc_validate.c62
10 files changed, 171 insertions, 114 deletions
diff --git a/regress/usr.bin/mandoc/mdoc/Bd/offset-empty.in b/regress/usr.bin/mandoc/mdoc/Bd/offset-empty.in
index 816920b0129..ec0d8a1b48a 100644
--- a/regress/usr.bin/mandoc/mdoc/Bd/offset-empty.in
+++ b/regress/usr.bin/mandoc/mdoc/Bd/offset-empty.in
@@ -1,4 +1,4 @@
-.Dd July 6, 2012
+.Dd October 30, 2014
.Dt BD-OFFSET-EMPTY 1
.Os OpenBSD
.Sh NAME
@@ -23,3 +23,6 @@ Bd literal offset 4n
.Bd -literal -offset mystring
Bd literal offset mystring
.Ed
+.Bd -literal -offset Ds
+Bd literal offset Ds
+.Ed
diff --git a/regress/usr.bin/mandoc/mdoc/Bd/offset-empty.out_ascii b/regress/usr.bin/mandoc/mdoc/Bd/offset-empty.out_ascii
index d33b537d15f..8552fe804c0 100644
--- a/regress/usr.bin/mandoc/mdoc/Bd/offset-empty.out_ascii
+++ b/regress/usr.bin/mandoc/mdoc/Bd/offset-empty.out_ascii
@@ -16,4 +16,6 @@ DDEESSCCRRIIPPTTIIOONN
Bd literal offset mystring
-OpenBSD July 6, 2012 OpenBSD
+ Bd literal offset Ds
+
+OpenBSD October 30, 2014 OpenBSD
diff --git a/regress/usr.bin/mandoc/mdoc/Bl/Makefile b/regress/usr.bin/mandoc/mdoc/Bl/Makefile
index cb734622e39..cbf736004cc 100644
--- a/regress/usr.bin/mandoc/mdoc/Bl/Makefile
+++ b/regress/usr.bin/mandoc/mdoc/Bl/Makefile
@@ -1,7 +1,7 @@
-# $OpenBSD: Makefile,v 1.24 2014/08/14 02:00:52 schwarze Exp $
+# $OpenBSD: Makefile,v 1.25 2014/10/30 20:05:33 schwarze Exp $
REGRESS_TARGETS = item inset diag ohang bullet dash enum hang tag
-REGRESS_TARGETS += column extend nested
+REGRESS_TARGETS += column extend nested offset
REGRESS_TARGETS += notype multitype badargs
REGRESS_TARGETS += empty noIt emptyhead emptytag emptyitem multitag
diff --git a/regress/usr.bin/mandoc/mdoc/Bl/offset.in b/regress/usr.bin/mandoc/mdoc/Bl/offset.in
new file mode 100644
index 00000000000..ca36c545f5f
--- /dev/null
+++ b/regress/usr.bin/mandoc/mdoc/Bl/offset.in
@@ -0,0 +1,63 @@
+.Dd October 30, 2014
+.Dt BL-OFFSET 1
+.Os OpenBSD
+.Sh NAME
+.Nm Bl-offset
+.Nd various arguments for Bl offset
+.Sh DESCRIPTION
+.Bl -item -offset
+.It
+Bl item offset empty
+.El
+.Bl -item -offset left
+.It
+Bl item offset left
+.El
+.Bl -item -offset indent
+.It
+Bl item offset indent
+.El
+.Bl -item -offset indent-two
+.It
+Bl item offset indent-two
+.El
+.Bl -item -offset 4n
+.It
+Bl item offset 4n
+.El
+.Bl -item -offset mystring
+.It
+Bl item offset mystring
+.El
+.Bl -item -offset Ds
+.It
+Bl item offset Ds
+.El
+.Bl -tag -width Ds -offset
+.It tag
+Bl tag width Ds offset empty
+.El
+.Bl -tag -width Ds -offset left
+.It tag
+Bl tag width Ds offset left
+.El
+.Bl -tag -width Ds -offset indent
+.It tag
+Bl tag width Ds offset indent
+.El
+.Bl -tag -width Ds -offset indent-two
+.It tag
+Bl tag width Ds offset indent-two
+.El
+.Bl -tag -width Ds -offset 4n
+.It tag
+Bl tag width Ds offset 4n
+.El
+.Bl -tag -width Ds -offset mystring
+.It tag
+Bl tag width Ds offset mystring
+.El
+.Bl -tag -width Ds -offset Ds
+.It tag
+Bl tag width Ds offset Ds
+.El
diff --git a/regress/usr.bin/mandoc/mdoc/Bl/offset.out_ascii b/regress/usr.bin/mandoc/mdoc/Bl/offset.out_ascii
new file mode 100644
index 00000000000..4c2cdeb3929
--- /dev/null
+++ b/regress/usr.bin/mandoc/mdoc/Bl/offset.out_ascii
@@ -0,0 +1,35 @@
+BL-OFFSET(1) General Commands Manual BL-OFFSET(1)
+
+NNAAMMEE
+ BBll--ooffffsseett - various arguments for Bl offset
+
+DDEESSCCRRIIPPTTIIOONN
+ Bl item offset empty
+
+ Bl item offset left
+
+ Bl item offset indent
+
+ Bl item offset indent-two
+
+ Bl item offset 4n
+
+ Bl item offset mystring
+
+ Bl item offset Ds
+
+ tag Bl tag width Ds offset empty
+
+ tag Bl tag width Ds offset left
+
+ tag Bl tag width Ds offset indent
+
+ tag Bl tag width Ds offset indent-two
+
+ tag Bl tag width Ds offset 4n
+
+ tag Bl tag width Ds offset mystring
+
+ tag Bl tag width Ds offset Ds
+
+OpenBSD October 30, 2014 OpenBSD
diff --git a/share/man/man7/mdoc.7 b/share/man/man7/mdoc.7
index 1d25b21798f..8167025ed7d 100644
--- a/share/man/man7/mdoc.7
+++ b/share/man/man7/mdoc.7
@@ -1,4 +1,4 @@
-.\" $OpenBSD: mdoc.7,v 1.121 2014/10/20 17:58:56 schwarze Exp $
+.\" $OpenBSD: mdoc.7,v 1.122 2014/10/30 20:05:33 schwarze Exp $
.\"
.\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
.\" Copyright (c) 2010, 2011, 2013 Ingo Schwarze <schwarze@openbsd.org>
@@ -15,7 +15,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: October 20 2014 $
+.Dd $Mdocdate: October 30 2014 $
.Dt MDOC 7
.Os
.Sh NAME
@@ -937,8 +937,11 @@ The
.Fl width
and
.Fl offset
-arguments accept scaling widths as described in
-.Xr roff 7
+arguments accept macro names as described for
+.Sx \&Bd
+.Fl offset ,
+scaling widths as described in
+.Xr roff 7 ,
or use the length of the given string.
The
.Fl offset
diff --git a/usr.bin/mandoc/mdoc_html.c b/usr.bin/mandoc/mdoc_html.c
index 0d9dd16e6b0..961b8b6bdad 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.83 2014/10/07 18:17:05 schwarze Exp $ */
+/* $OpenBSD: mdoc_html.c,v 1.84 2014/10/30 20:05:33 schwarze Exp $ */
/*
* Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -54,7 +54,6 @@ static void synopsis_pre(struct html *,
const struct mdoc_node *);
static void a2width(const char *, struct roffsu *);
-static void a2offs(const char *, struct roffsu *);
static void mdoc_root_post(MDOC_ARGS);
static int mdoc_root_pre(MDOC_ARGS);
@@ -279,7 +278,7 @@ a2width(const char *p, struct roffsu *su)
{
if ( ! a2roffsu(p, su, SCALE_MAX)) {
- su->unit = SCALE_BU;
+ su->unit = SCALE_EN;
su->scale = html_strlen(p);
}
}
@@ -326,27 +325,6 @@ synopsis_pre(struct html *h, const struct mdoc_node *n)
}
}
-/*
- * Calculate the scaling unit passed in an `-offset' argument. This
- * uses either a native scaling unit (e.g., 1i, 2m), one of a set of
- * predefined strings (indent, etc.), or the string length of the value.
- */
-static void
-a2offs(const char *p, struct roffsu *su)
-{
-
- /* FIXME: "right"? */
-
- if (0 == strcmp(p, "left"))
- SCALE_HS_INIT(su, 0);
- else if (0 == strcmp(p, "indent"))
- SCALE_HS_INIT(su, INDENT);
- else if (0 == strcmp(p, "indent-two"))
- SCALE_HS_INIT(su, INDENT * 2);
- else if ( ! a2roffsu(p, su, SCALE_MAX))
- SCALE_HS_INIT(su, html_strlen(p));
-}
-
static void
print_mdoc(MDOC_ARGS)
{
@@ -992,7 +970,7 @@ mdoc_bl_pre(MDOC_ARGS)
/* Set the block's left-hand margin. */
if (n->norm->Bl.offs) {
- a2offs(n->norm->Bl.offs, &su);
+ a2width(n->norm->Bl.offs, &su);
bufcat_su(h, "margin-left", &su);
}
@@ -1158,9 +1136,17 @@ mdoc_bd_pre(MDOC_ARGS)
return(1);
}
- SCALE_HS_INIT(&su, 0);
- if (n->norm->Bd.offs)
- a2offs(n->norm->Bd.offs, &su);
+ /* Handle the -offset argument. */
+
+ if (n->norm->Bd.offs == NULL ||
+ ! strcmp(n->norm->Bd.offs, "left"))
+ SCALE_HS_INIT(&su, 0);
+ else if ( ! strcmp(n->norm->Bd.offs, "indent"))
+ SCALE_HS_INIT(&su, INDENT);
+ else if ( ! strcmp(n->norm->Bd.offs, "indent-two"))
+ SCALE_HS_INIT(&su, INDENT * 2);
+ else
+ a2width(n->norm->Bd.offs, &su);
bufinit(h);
bufcat_su(h, "margin-left", &su);
diff --git a/usr.bin/mandoc/mdoc_man.c b/usr.bin/mandoc/mdoc_man.c
index bd91f048580..1c830af54b3 100644
--- a/usr.bin/mandoc/mdoc_man.c
+++ b/usr.bin/mandoc/mdoc_man.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_man.c,v 1.68 2014/08/21 12:56:24 schwarze Exp $ */
+/* $OpenBSD: mdoc_man.c,v 1.69 2014/10/30 20:05:33 schwarze Exp $ */
/*
* Copyright (c) 2011, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
*
@@ -14,6 +14,8 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include <sys/types.h>
+
#include <assert.h>
#include <stdio.h>
#include <string.h>
@@ -108,7 +110,7 @@ static int pre_xr(DECL_ARGS);
static void print_word(const char *);
static void print_line(const char *, int);
static void print_block(const char *, int);
-static void print_offs(const char *);
+static void print_offs(const char *, int);
static void print_width(const char *,
const struct mdoc_node *, size_t);
static void print_count(int *);
@@ -412,7 +414,7 @@ print_block(const char *s, int newflags)
}
static void
-print_offs(const char *v)
+print_offs(const char *v, int keywords)
{
char buf[24];
struct roffsu su;
@@ -421,11 +423,11 @@ print_offs(const char *v)
print_line(".RS", MMAN_Bk_susp);
/* Convert v into a number (of characters). */
- if (NULL == v || '\0' == *v || 0 == strcmp(v, "left"))
+ if (NULL == v || '\0' == *v || (keywords && !strcmp(v, "left")))
sz = 0;
- else if (0 == strcmp(v, "indent"))
+ else if (keywords && !strcmp(v, "indent"))
sz = 6;
- else if (0 == strcmp(v, "indent-two"))
+ else if (keywords && !strcmp(v, "indent-two"))
sz = 12;
else if (a2roffsu(v, &su, SCALE_MAX)) {
if (SCALE_EN == su.unit)
@@ -872,7 +874,7 @@ pre_bd(DECL_ARGS)
print_line(".nf", 0);
if (0 == n->norm->Bd.comp && NULL != n->parent->prev)
outflags |= MMAN_sp;
- print_offs(n->norm->Bd.offs);
+ print_offs(n->norm->Bd.offs, 1);
return(1);
}
@@ -959,7 +961,7 @@ pre_bl(DECL_ARGS)
* just nest and do not add up their indentation.
*/
if (n->norm->Bl.offs) {
- print_offs(n->norm->Bl.offs);
+ print_offs(n->norm->Bl.offs, 0);
Bl_stack[Bl_stack_len++] = 0;
}
@@ -1044,7 +1046,7 @@ static int
pre_dl(DECL_ARGS)
{
- print_offs("6n");
+ print_offs("6n", 0);
return(1);
}
diff --git a/usr.bin/mandoc/mdoc_term.c b/usr.bin/mandoc/mdoc_term.c
index f778add7667..2bbb990f6b4 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.186 2014/10/28 17:35:42 schwarze Exp $ */
+/* $OpenBSD: mdoc_term.c,v 1.187 2014/10/30 20:05:33 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -49,7 +49,6 @@ struct termact {
static size_t a2width(const struct termp *, const char *);
static size_t a2height(const struct termp *, const char *);
-static size_t a2offs(const struct termp *, const char *);
static void print_bvspace(struct termp *,
const struct mdoc_node *,
@@ -548,27 +547,6 @@ a2width(const struct termp *p, const char *v)
return(term_hspan(p, &su));
}
-static size_t
-a2offs(const struct termp *p, const char *v)
-{
- struct roffsu su;
-
- if ('\0' == *v)
- return(0);
- else if (0 == strcmp(v, "left"))
- return(0);
- else if (0 == strcmp(v, "indent"))
- return(term_len(p, p->defindent + 1));
- else if (0 == strcmp(v, "indent-two"))
- return(term_len(p, (p->defindent + 1) * 2));
- else if ( ! a2roffsu(v, &su, SCALE_MAX)) {
- SCALE_HS_INIT(&su, term_strlen(p, v));
- su.scale /= term_strlen(p, "0");
- }
-
- return(term_hspan(p, &su));
-}
-
/*
* Determine how much space to print out before block elements of `It'
* (and thus `Bl') and `Bd'. And then go ahead and print that space,
@@ -657,7 +635,7 @@ termp_it_pre(DECL_ARGS)
width = offset = 0;
if (bl->norm->Bl.offs)
- offset = a2offs(p, bl->norm->Bl.offs);
+ offset = a2width(p, bl->norm->Bl.offs);
switch (type) {
case LIST_column:
@@ -1579,8 +1557,17 @@ termp_bd_pre(DECL_ARGS)
} else if (MDOC_HEAD == n->type)
return(0);
- if (n->norm->Bd.offs)
- p->offset += a2offs(p, n->norm->Bd.offs);
+ /* Handle the -offset argument. */
+
+ if (n->norm->Bd.offs == NULL ||
+ ! strcmp(n->norm->Bd.offs, "left"))
+ /* nothing */;
+ else if ( ! strcmp(n->norm->Bd.offs, "indent"))
+ p->offset += term_len(p, p->defindent + 1);
+ else if ( ! strcmp(n->norm->Bd.offs, "indent-two"))
+ p->offset += term_len(p, (p->defindent + 1) * 2);
+ else
+ p->offset += a2width(p, n->norm->Bd.offs);
/*
* If -ragged or -filled are specified, the block does nothing
diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c
index 79e479c18bc..a367317ca28 100644
--- a/usr.bin/mandoc/mdoc_validate.c
+++ b/usr.bin/mandoc/mdoc_validate.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mdoc_validate.c,v 1.169 2014/10/13 14:01:03 schwarze Exp $ */
+/* $OpenBSD: mdoc_validate.c,v 1.170 2014/10/30 20:05:33 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -69,6 +69,7 @@ static void check_args(struct mdoc *, struct mdoc_node *);
static int child_an(const struct mdoc_node *);
static enum mdoc_sec a2sec(const char *);
static size_t macro2len(enum mdoct);
+static void rewrite_macro2len(char **);
static int ebool(POST_ARGS);
static int berr_ge1(POST_ARGS);
@@ -87,7 +88,6 @@ static int post_bf(POST_ARGS);
static int post_bk(POST_ARGS);
static int post_bl(POST_ARGS);
static int post_bl_block(POST_ARGS);
-static int post_bl_block_width(POST_ARGS);
static int post_bl_block_tag(POST_ARGS);
static int post_bl_head(POST_ARGS);
static int post_bx(POST_ARGS);
@@ -596,6 +596,7 @@ pre_bl(PRE_ARGS)
mdoc->parse, argv->line,
argv->pos, "Bl -width %s",
argv->value[0]);
+ rewrite_macro2len(argv->value);
n->norm->Bl.width = argv->value[0];
break;
case MDOC_Offset:
@@ -610,6 +611,7 @@ pre_bl(PRE_ARGS)
mdoc->parse, argv->line,
argv->pos, "Bl -offset %s",
argv->value[0]);
+ rewrite_macro2len(argv->value);
n->norm->Bl.offs = argv->value[0];
break;
default:
@@ -757,6 +759,7 @@ pre_bd(PRE_ARGS)
mdoc->parse, argv->line,
argv->pos, "Bd -offset %s",
argv->value[0]);
+ rewrite_macro2len(argv->value);
n->norm->Bd.offs = argv->value[0];
break;
case MDOC_Compact:
@@ -1335,10 +1338,6 @@ post_bl_block(POST_ARGS)
if ( ! post_bl_block_tag(mdoc))
return(0);
assert(n->norm->Bl.width);
- } else if (NULL != n->norm->Bl.width) {
- if ( ! post_bl_block_width(mdoc))
- return(0);
- assert(n->norm->Bl.width);
}
for (ni = n->body->child; ni; ni = ni->next) {
@@ -1378,50 +1377,27 @@ post_bl_block(POST_ARGS)
return(1);
}
-static int
-post_bl_block_width(POST_ARGS)
+/*
+ * If the argument of -offset or -width is a macro,
+ * replace it with the associated default width.
+ */
+void
+rewrite_macro2len(char **arg)
{
size_t width;
- int i;
enum mdoct tok;
- struct mdoc_node *n;
- char buf[24];
-
- n = mdoc->last;
- /*
- * Calculate the real width of a list from the -width string,
- * which may contain a macro (with a known default width), a
- * literal string, or a scaling width.
- *
- * If the value to -width is a macro, then we re-write it to be
- * the macro's width as set in share/tmac/mdoc/doc-common.
- */
-
- if (0 == strcmp(n->norm->Bl.width, "Ds"))
+ if (*arg == NULL)
+ return;
+ else if ( ! strcmp(*arg, "Ds"))
width = 6;
- else if (MDOC_MAX == (tok = mdoc_hash_find(n->norm->Bl.width)))
- return(1);
+ else if ((tok = mdoc_hash_find(*arg)) == MDOC_MAX)
+ return;
else
width = macro2len(tok);
- /* The value already exists: free and reallocate it. */
-
- assert(n->args);
-
- for (i = 0; i < (int)n->args->argc; i++)
- if (MDOC_Width == n->args->argv[i].arg)
- break;
-
- assert(i < (int)n->args->argc);
-
- (void)snprintf(buf, sizeof(buf), "%un", (unsigned int)width);
- free(n->args->argv[i].value[0]);
- n->args->argv[i].value[0] = mandoc_strdup(buf);
-
- /* Set our width! */
- n->norm->Bl.width = n->args->argv[i].value[0];
- return(1);
+ free(*arg);
+ mandoc_asprintf(arg, "%zun", width);
}
static int
@@ -1436,7 +1412,7 @@ post_bl_block_tag(POST_ARGS)
* Calculate the -width for a `Bl -tag' list if it hasn't been
* provided. Uses the first head macro. NOTE AGAIN: this is
* ONLY if the -width argument has NOT been provided. See
- * post_bl_block_width() for converting the -width string.
+ * rewrite_macro2len() for converting the -width string.
*/
sz = 10;