diff options
author | 2013-12-15 21:18:00 +0000 | |
---|---|---|
committer | 2013-12-15 21:18:00 +0000 | |
commit | 75088a499f6e2e38ecd77511ee22b36042a1c647 (patch) | |
tree | cde96f9434b350debce63d2d5e538ecb15541476 | |
parent | update comment, 4.3BSD tty compatibility and the associated ioctls are gone (diff) | |
download | wireguard-openbsd-75088a499f6e2e38ecd77511ee22b36042a1c647.tar.xz wireguard-openbsd-75088a499f6e2e38ecd77511ee22b36042a1c647.zip |
The "value" argument to the roff(7) .nr requests ends right before
the first non-digit character. While here, implement and document
an optional sign, requesting increment or decrement, as documented
in the Ossanna/Kernighan/Ritter troff manual and supported by groff.
Reported by bentley@ on discuss at mdocml.
-rw-r--r-- | regress/usr.bin/mandoc/roff/nr/Makefile | 4 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/roff/nr/argc.in | 21 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/roff/nr/argc.out_ascii | 17 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/roff/nr/int.in | 5 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/roff/nr/int.out_ascii | 3 | ||||
-rw-r--r-- | share/man/man7/roff.7 | 15 | ||||
-rw-r--r-- | usr.bin/mandoc/libmandoc.h | 4 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_validate.c | 6 | ||||
-rw-r--r-- | usr.bin/mandoc/roff.c | 23 |
9 files changed, 79 insertions, 19 deletions
diff --git a/regress/usr.bin/mandoc/roff/nr/Makefile b/regress/usr.bin/mandoc/roff/nr/Makefile index ed0ad3c5ad1..82dfd046182 100644 --- a/regress/usr.bin/mandoc/roff/nr/Makefile +++ b/regress/usr.bin/mandoc/roff/nr/Makefile @@ -1,5 +1,5 @@ -# $OpenBSD: Makefile,v 1.1 2013/10/03 22:04:07 schwarze Exp $ +# $OpenBSD: Makefile,v 1.2 2013/12/15 21:18:00 schwarze Exp $ -REGRESS_TARGETS = int +REGRESS_TARGETS = int argc .include <bsd.regress.mk> diff --git a/regress/usr.bin/mandoc/roff/nr/argc.in b/regress/usr.bin/mandoc/roff/nr/argc.in new file mode 100644 index 00000000000..bf204a70a2a --- /dev/null +++ b/regress/usr.bin/mandoc/roff/nr/argc.in @@ -0,0 +1,21 @@ +.Dd December 15, 2013 +.Dt NR-ARGC 1 +.Os OpenBSD +.Sh NAME +.Nm nr-argc +.Nd varying number of arguments to the .nr macro +.Sh DESCRIPTION +.nr onearg +one argument: \n[onearg] +.Pp +.nr twoargs 2 +two arguments: \n[twoargs] +.Pp +.nr withsuffix 2x +with suffix: \n[withsuffix] +.Pp +.nr threeargs 2 3 +three arguments: \n[threeargs] +.Pp +.nr fourargs 2 3 4 +four arguments: \n[fourargs] diff --git a/regress/usr.bin/mandoc/roff/nr/argc.out_ascii b/regress/usr.bin/mandoc/roff/nr/argc.out_ascii new file mode 100644 index 00000000000..82c86bfd3a4 --- /dev/null +++ b/regress/usr.bin/mandoc/roff/nr/argc.out_ascii @@ -0,0 +1,17 @@ +NR-ARGC(1) OpenBSD Reference Manual NR-ARGC(1) + +NNAAMMEE + nnrr--aarrggcc - varying number of arguments to the .nr macro + +DDEESSCCRRIIPPTTIIOONN + one argument: 0 + + two arguments: 2 + + with suffix: 2 + + three arguments: 2 + + four arguments: 2 + +OpenBSD December 15, 2013 OpenBSD diff --git a/regress/usr.bin/mandoc/roff/nr/int.in b/regress/usr.bin/mandoc/roff/nr/int.in index 8dd7c477f3f..3f907697a54 100644 --- a/regress/usr.bin/mandoc/roff/nr/int.in +++ b/regress/usr.bin/mandoc/roff/nr/int.in @@ -7,4 +7,9 @@ initial contents: \nY \n(YY \n[YYY] .nr Y 42 .nr YY -1 .nr YYY 2147483647 +intermediate contents: \nY \n(YY \n[YYY] +.br +.nr Y -19 +.nr YY +2 +.nr YYY +1 final contents: \nY \n(YY \n[YYY] diff --git a/regress/usr.bin/mandoc/roff/nr/int.out_ascii b/regress/usr.bin/mandoc/roff/nr/int.out_ascii index 8da2aa50eda..638321d368d 100644 --- a/regress/usr.bin/mandoc/roff/nr/int.out_ascii +++ b/regress/usr.bin/mandoc/roff/nr/int.out_ascii @@ -7,7 +7,8 @@ NNAAMMEE DDEESSCCRRIIPPTTIIOONN initial contents: 0 0 0 - final contents: 42 -1 2147483647 + intermediate contents: 42 -1 2147483647 + final contents: 23 1 -2147483648 diff --git a/share/man/man7/roff.7 b/share/man/man7/roff.7 index 527a6923961..e8d10a5efb9 100644 --- a/share/man/man7/roff.7 +++ b/share/man/man7/roff.7 @@ -1,4 +1,4 @@ -.\" $OpenBSD: roff.7,v 1.24 2013/10/22 20:37:54 schwarze Exp $ +.\" $OpenBSD: roff.7,v 1.25 2013/12/15 21:18:00 schwarze Exp $ .\" .\" Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> .\" Copyright (c) 2010, 2011 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 22 2013 $ +.Dd $Mdocdate: December 15 2013 $ .Dt ROFF 7 .Os .Sh NAME @@ -840,19 +840,22 @@ the name of the request, macro or string to be undefined. Currently, it is ignored including its arguments, and the number of arguments is not checked. .Ss \&nr -Define a register. +Define or change a register. A register is an arbitrary string value that defines some sort of state, which influences parsing and/or formatting. Its syntax is as follows: .Pp -.D1 Pf \. Cm \&nr Ar name Ar value +.D1 Pf \. Cm \&nr Ar name Oo +|- Oc Ns Ar value .Pp The .Ar value may, at the moment, only be an integer. -So far, only the following register +If it is prefixed by a sign, the register will be +incremented or decremented instead of assigned to. +.Pp +The following register .Ar name -is recognised: +is handled specially: .Bl -tag -width Ds .It Cm nS If set to a positive integer value, certain diff --git a/usr.bin/mandoc/libmandoc.h b/usr.bin/mandoc/libmandoc.h index 302187d965d..9f24af6b95c 100644 --- a/usr.bin/mandoc/libmandoc.h +++ b/usr.bin/mandoc/libmandoc.h @@ -1,4 +1,4 @@ -/* $Id: libmandoc.h,v 1.21 2013/10/03 22:04:08 schwarze Exp $ */ +/* $Id: libmandoc.h,v 1.22 2013/12/15 21:18:00 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2013 Ingo Schwarze <schwarze@openbsd.org> @@ -68,7 +68,7 @@ void roff_reset(struct roff *); enum rofferr roff_parseln(struct roff *, int, char **, size_t *, int, int *); void roff_endparse(struct roff *); -void roff_setreg(struct roff *, const char *, int); +void roff_setreg(struct roff *, const char *, int, char sign); int roff_getreg(const struct roff *, const char *); char *roff_strdup(const struct roff *, const char *); int roff_getcontrol(const struct roff *, diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c index 2d85c62f0a5..683e6464049 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.115 2013/10/21 23:32:33 schwarze Exp $ */ +/* $Id: mdoc_validate.c,v 1.116 2013/12/15 21:18:00 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010, 2011, 2012, 2013 Ingo Schwarze <schwarze@openbsd.org> @@ -1987,10 +1987,10 @@ post_sh_head(POST_ARGS) /* The SYNOPSIS gets special attention in other areas. */ if (SEC_SYNOPSIS == sec) { - roff_setreg(mdoc->roff, "nS", 1); + roff_setreg(mdoc->roff, "nS", 1, '='); mdoc->flags |= MDOC_SYNOPSIS; } else { - roff_setreg(mdoc->roff, "nS", 0); + roff_setreg(mdoc->roff, "nS", 0, '='); mdoc->flags &= ~MDOC_SYNOPSIS; } diff --git a/usr.bin/mandoc/roff.c b/usr.bin/mandoc/roff.c index 2b98bab84a9..6c9dfa97282 100644 --- a/usr.bin/mandoc/roff.c +++ b/usr.bin/mandoc/roff.c @@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.59 2013/10/22 20:37:54 schwarze Exp $ */ +/* $Id: roff.c,v 1.60 2013/12/15 21:18:00 schwarze Exp $ */ /* * Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010, 2011, 2012, 2013 Ingo Schwarze <schwarze@openbsd.org> @@ -1356,7 +1356,7 @@ roff_ds(ROFF_ARGS) } void -roff_setreg(struct roff *r, const char *name, int val) +roff_setreg(struct roff *r, const char *name, int val, char sign) { struct roffreg *reg; @@ -1371,11 +1371,17 @@ roff_setreg(struct roff *r, const char *name, int val) reg = mandoc_malloc(sizeof(struct roffreg)); reg->key.p = mandoc_strdup(name); reg->key.sz = strlen(name); + reg->val = 0; reg->next = r->regtab; r->regtab = reg; } - reg->val = val; + if ('+' == sign) + reg->val += val; + else if ('-' == sign) + reg->val -= val; + else + reg->val = val; } int @@ -1422,14 +1428,21 @@ roff_nr(ROFF_ARGS) { const char *key; char *val; + size_t sz; int iv; + char sign; val = *bufp + pos; key = roff_getname(r, &val, ln, pos); - iv = mandoc_strntoi(val, strlen(val), 10); + sign = *val; + if ('+' == sign || '-' == sign) + val++; + + sz = strspn(val, "0123456789"); + iv = sz ? mandoc_strntoi(val, sz, 10) : 0; - roff_setreg(r, key, iv); + roff_setreg(r, key, iv, sign); return(ROFF_IGN); } |