summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorschwarze <schwarze@openbsd.org>2014-07-02 19:54:39 +0000
committerschwarze <schwarze@openbsd.org>2014-07-02 19:54:39 +0000
commitf9e7bf9911e824f4475ac468e0c2f1f17e55dafe (patch)
tree76f537a86447c8136e89c84150cf5f8b3c73b212
parentSync description of PROT_* flags between mmap.2 and mprotect.2 (diff)
downloadwireguard-openbsd-f9e7bf9911e824f4475ac468e0c2f1f17e55dafe.tar.xz
wireguard-openbsd-f9e7bf9911e824f4475ac468e0c2f1f17e55dafe.zip
When .Sm is called without an argument, groff toggles the spacing mode,
so let us do the same for compatibility. Using this feature is of course not recommended except in manual page obfuscation contests.
-rw-r--r--regress/usr.bin/mandoc/mdoc/Sm/Makefile4
-rw-r--r--regress/usr.bin/mandoc/mdoc/Sm/noarg.in20
-rw-r--r--regress/usr.bin/mandoc/mdoc/Sm/noarg.out_ascii11
-rw-r--r--share/man/man7/mdoc.713
-rw-r--r--usr.bin/mandoc/mdoc_html.c23
-rw-r--r--usr.bin/mandoc/mdoc_man.c13
-rw-r--r--usr.bin/mandoc/mdoc_term.c14
-rw-r--r--usr.bin/mandoc/mdoc_validate.c9
8 files changed, 72 insertions, 35 deletions
diff --git a/regress/usr.bin/mandoc/mdoc/Sm/Makefile b/regress/usr.bin/mandoc/mdoc/Sm/Makefile
index 6dd7203dd68..ef3a2de066f 100644
--- a/regress/usr.bin/mandoc/mdoc/Sm/Makefile
+++ b/regress/usr.bin/mandoc/mdoc/Sm/Makefile
@@ -1,6 +1,6 @@
-# $OpenBSD: Makefile,v 1.4 2012/07/07 14:10:55 schwarze Exp $
+# $OpenBSD: Makefile,v 1.5 2014/07/02 19:54:39 schwarze Exp $
-REGRESS_TARGETS=scope spacing-No spacing-Op
+REGRESS_TARGETS = noarg scope spacing-No spacing-Op
SKIP_TMAN ?= scope
diff --git a/regress/usr.bin/mandoc/mdoc/Sm/noarg.in b/regress/usr.bin/mandoc/mdoc/Sm/noarg.in
new file mode 100644
index 00000000000..bb777430845
--- /dev/null
+++ b/regress/usr.bin/mandoc/mdoc/Sm/noarg.in
@@ -0,0 +1,20 @@
+.Dd July 2, 2014
+.Dt SM-NOARG 1
+.Os OpenBSD
+.Sh NAME
+.Nm Sm-noarg
+.Nd spacing macro without arguments
+.Sh DESCRIPTION
+.Fl f Ar on
+.Sm off
+.Fl f Ar off
+.Sm
+.Fl f Ar toggle Pq now on
+.Sm on
+.Fl f Ar on
+.Sm
+.Fl f Ar toggle Pq now off
+.Pp
+.Sm on
+.Fl f Ar on
+on a new line
diff --git a/regress/usr.bin/mandoc/mdoc/Sm/noarg.out_ascii b/regress/usr.bin/mandoc/mdoc/Sm/noarg.out_ascii
new file mode 100644
index 00000000000..ad4d2c365bb
--- /dev/null
+++ b/regress/usr.bin/mandoc/mdoc/Sm/noarg.out_ascii
@@ -0,0 +1,11 @@
+SM-NOARG(1) OpenBSD Reference Manual SM-NOARG(1)
+
+NNAAMMEE
+ SSmm--nnooaarrgg - spacing macro without arguments
+
+DDEESSCCRRIIPPTTIIOONN
+ --ff _o_n --ff_o_f_f --ff _t_o_g_g_l_e (now on) --ff _o_n --ff_t_o_g_g_l_e(nowoff)
+
+ --ff _o_n on a new line
+
+OpenBSD July 2, 2014 OpenBSD
diff --git a/share/man/man7/mdoc.7 b/share/man/man7/mdoc.7
index 22bc0f5aa56..f9221d17f8f 100644
--- a/share/man/man7/mdoc.7
+++ b/share/man/man7/mdoc.7
@@ -1,4 +1,4 @@
-.\" $OpenBSD: mdoc.7,v 1.113 2014/07/02 03:47:07 schwarze Exp $
+.\" $OpenBSD: mdoc.7,v 1.114 2014/07/02 19:54:39 schwarze Exp $
.\"
.\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
.\" Copyright (c) 2010, 2011, 2013 Ingo Schwarze <schwarze@openbsd.org>
@@ -468,7 +468,7 @@ in the alphabetical
.It Sx \&Pf Ta prefix, no following horizontal space (one argument)
.It Sx \&Ns Ta roman font, no preceding horizontal space (no arguments)
.It Sx \&Ap Ta apostrophe without surrounding whitespace (no arguments)
-.It Sx \&Sm Ta switch horizontal spacing mode: Cm on | off
+.It Sx \&Sm Ta switch horizontal spacing mode: Op Cm on | off
.It Sx \&Bk , \&Ek Ta keep block: Fl words
.It Sx \&br Ta force output line break in text mode (no arguments)
.It Sx \&sp Ta force vertical space: Op Ar height
@@ -2340,7 +2340,7 @@ and
Switches the spacing mode for output generated from macros.
Its syntax is as follows:
.Pp
-.D1 Pf \. Sx \&Sm Cm on | off
+.D1 Pf \. Sx \&Sm Op Cm on | off
.Pp
By default, spacing is
.Cm on .
@@ -2349,6 +2349,11 @@ When switched
no white space is inserted between macro arguments and between the
output generated from adjacent macros, but text lines
still get normal spacing between words and sentences.
+.Pp
+When called without an argument, the
+.Sx \&Sm
+macro toggles the spacing mode.
+Using this is not recommended because it makes the code harder to read.
.Ss \&So
Multi-line version of
.Sx \&Sq .
@@ -3027,7 +3032,7 @@ then the macro accepts an arbitrary number of arguments.
.It Sx \&Pf Ta Yes Ta Yes Ta 1
.It Sx \&Pp Ta \&No Ta \&No Ta 0
.It Sx \&Rv Ta \&No Ta \&No Ta n
-.It Sx \&Sm Ta \&No Ta \&No Ta 1
+.It Sx \&Sm Ta \&No Ta \&No Ta <2
.It Sx \&St Ta \&No Ta Yes Ta 1
.It Sx \&Sx Ta Yes Ta Yes Ta >0
.It Sx \&Sy Ta Yes Ta Yes Ta >0
diff --git a/usr.bin/mandoc/mdoc_html.c b/usr.bin/mandoc/mdoc_html.c
index e4f3856642e..6444e9e68ed 100644
--- a/usr.bin/mandoc/mdoc_html.c
+++ b/usr.bin/mandoc/mdoc_html.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_html.c,v 1.74 2014/07/02 03:47:07 schwarze Exp $ */
+/* $Id: mdoc_html.c,v 1.75 2014/07/02 19:54:39 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -1520,23 +1520,16 @@ static int
mdoc_sm_pre(MDOC_ARGS)
{
- assert(n->child && MDOC_TEXT == n->child->type);
- if (0 == strcmp("on", n->child->string)) {
- /*
- * FIXME: no p->col to check. Thus, if we have
- * .Bd -literal
- * .Sm off
- * 1 2
- * .Sm on
- * 3
- * .Ed
- * the "3" is preceded by a space.
- */
- h->flags &= ~HTML_NOSPACE;
+ if (NULL == n->child)
+ h->flags ^= HTML_NONOSPACE;
+ else if (0 == strcmp("on", n->child->string))
h->flags &= ~HTML_NONOSPACE;
- } else
+ else
h->flags |= HTML_NONOSPACE;
+ if ( ! (HTML_NONOSPACE & h->flags))
+ h->flags &= ~HTML_NOSPACE;
+
return(0);
}
diff --git a/usr.bin/mandoc/mdoc_man.c b/usr.bin/mandoc/mdoc_man.c
index 1e4792e0a8a..bd6d38b23ac 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.63 2014/07/02 03:47:07 schwarze Exp $ */
+/* $Id: mdoc_man.c,v 1.64 2014/07/02 19:54:39 schwarze Exp $ */
/*
* Copyright (c) 2011, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
*
@@ -1561,11 +1561,16 @@ static int
pre_sm(DECL_ARGS)
{
- assert(n->child && MDOC_TEXT == n->child->type);
- if (0 == strcmp("on", n->child->string))
- outflags |= MMAN_Sm | MMAN_spc;
+ if (NULL == n->child)
+ outflags ^= MMAN_Sm;
+ else if (0 == strcmp("on", n->child->string))
+ outflags |= MMAN_Sm;
else
outflags &= ~MMAN_Sm;
+
+ if (MMAN_Sm & outflags)
+ outflags |= MMAN_spc;
+
return(0);
}
diff --git a/usr.bin/mandoc/mdoc_term.c b/usr.bin/mandoc/mdoc_term.c
index 55b37af7133..a240be9f8f7 100644
--- a/usr.bin/mandoc/mdoc_term.c
+++ b/usr.bin/mandoc/mdoc_term.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_term.c,v 1.170 2014/07/02 03:47:07 schwarze Exp $ */
+/* $Id: mdoc_term.c,v 1.171 2014/07/02 19:54:39 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -2052,14 +2052,16 @@ static int
termp_sm_pre(DECL_ARGS)
{
- assert(n->child && MDOC_TEXT == n->child->type);
- if (0 == strcmp("on", n->child->string)) {
- if (p->col)
- p->flags &= ~TERMP_NOSPACE;
+ if (NULL == n->child)
+ p->flags ^= TERMP_NONOSPACE;
+ else if (0 == strcmp("on", n->child->string))
p->flags &= ~TERMP_NONOSPACE;
- } else
+ else
p->flags |= TERMP_NONOSPACE;
+ if (p->col && ! (TERMP_NONOSPACE & p->flags))
+ p->flags &= ~TERMP_NOSPACE;
+
return(0);
}
diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c
index 9ff94ee2628..60564525cf3 100644
--- a/usr.bin/mandoc/mdoc_validate.c
+++ b/usr.bin/mandoc/mdoc_validate.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_validate.c,v 1.139 2014/07/02 13:10:15 schwarze Exp $ */
+/* $Id: mdoc_validate.c,v 1.140 2014/07/02 19:54:39 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -1664,11 +1664,12 @@ ebool(struct mdoc *mdoc)
{
if (NULL == mdoc->last->child) {
- mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_MACROEMPTY);
- mdoc_node_delete(mdoc, mdoc->last);
+ if (MDOC_Sm == mdoc->last->tok)
+ mdoc->flags ^= MDOC_SMOFF;
return(1);
}
- check_count(mdoc, MDOC_ELEM, CHECK_WARN, CHECK_EQ, 1);
+
+ check_count(mdoc, MDOC_ELEM, CHECK_WARN, CHECK_LT, 2);
assert(MDOC_TEXT == mdoc->last->child->type);