diff options
-rw-r--r-- | libmandoc.h | 2 | ||||
-rw-r--r-- | mdoc_validate.c | 4 | ||||
-rw-r--r-- | roff.7 | 11 | ||||
-rw-r--r-- | roff.c | 21 |
4 files changed, 27 insertions, 11 deletions
diff --git a/libmandoc.h b/libmandoc.h index a96829f7..63943e5a 100644 --- a/libmandoc.h +++ b/libmandoc.h @@ -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 ecaaf57e..8c6e7606 100644 --- a/mdoc_validate.c +++ b/mdoc_validate.c @@ -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; } @@ -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 @@ -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); } |