aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2013-12-15 21:23:52 +0000
committerIngo Schwarze <schwarze@openbsd.org>2013-12-15 21:23:52 +0000
commita303f40898d21cb0d5552a2252710ddc741a1cec (patch)
treed38b1f7764118039b866dffbf2f2395e33241aff
parent9e9da087dda5194812500db223832a351d496b16 (diff)
downloadmandoc-a303f40898d21cb0d5552a2252710ddc741a1cec.tar.gz
mandoc-a303f40898d21cb0d5552a2252710ddc741a1cec.tar.zst
mandoc-a303f40898d21cb0d5552a2252710ddc741a1cec.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@.
-rw-r--r--libmandoc.h4
-rw-r--r--mdoc_validate.c6
-rw-r--r--roff.715
-rw-r--r--roff.c23
4 files changed, 32 insertions, 16 deletions
diff --git a/libmandoc.h b/libmandoc.h
index 18f200b7..3c005e10 100644
--- a/libmandoc.h
+++ b/libmandoc.h
@@ -1,4 +1,4 @@
-/* $Id: libmandoc.h,v 1.34 2013/10/05 22:15:03 schwarze Exp $ */
+/* $Id: libmandoc.h,v 1.35 2013/12/15 21:23:52 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/mdoc_validate.c b/mdoc_validate.c
index b8605a83..4cfd6204 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_validate.c,v 1.197 2013/10/21 23:47:58 schwarze Exp $ */
+/* $Id: mdoc_validate.c,v 1.198 2013/12/15 21:23:52 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2011, 2012, 2013 Ingo Schwarze <schwarze@openbsd.org>
@@ -1991,10 +1991,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/roff.7 b/roff.7
index 99e44611..21dd474e 100644
--- a/roff.7
+++ b/roff.7
@@ -1,4 +1,4 @@
-.\" $Id: roff.7,v 1.44 2013/10/22 20:38:00 schwarze Exp $
+.\" $Id: roff.7,v 1.45 2013/12/15 21:23:52 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
@@ -814,19 +814,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/roff.c b/roff.c
index 83738cef..e4c43c13 100644
--- a/roff.c
+++ b/roff.c
@@ -1,4 +1,4 @@
-/* $Id: roff.c,v 1.186 2013/10/22 20:38:00 schwarze Exp $ */
+/* $Id: roff.c,v 1.187 2013/12/15 21:23:52 schwarze Exp $ */
/*
* Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2011, 2012, 2013 Ingo Schwarze <schwarze@openbsd.org>
@@ -1360,7 +1360,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;
@@ -1375,11 +1375,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
@@ -1426,14 +1432,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);
}