diff options
-rw-r--r-- | libmandoc.h | 4 | ||||
-rw-r--r-- | mdoc_validate.c | 6 | ||||
-rw-r--r-- | roff.7 | 15 | ||||
-rw-r--r-- | roff.c | 23 |
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; } @@ -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 @@ -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); } |