diff options
-rw-r--r-- | mdoc.c | 11 | ||||
-rw-r--r-- | mdoc_validate.c | 4 | ||||
-rw-r--r-- | regs.h | 19 | ||||
-rw-r--r-- | roff.7 | 11 | ||||
-rw-r--r-- | roff.c | 21 |
5 files changed, 47 insertions, 19 deletions
@@ -1,4 +1,4 @@ -/* $Id: mdoc.c,v 1.150 2010/06/27 16:18:13 kristaps Exp $ */ +/* $Id: mdoc.c,v 1.151 2010/06/27 16:36:22 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -380,6 +380,15 @@ node_alloc(struct mdoc *m, int line, int pos, if (SEC_SYNOPSIS == p->sec) p->flags |= MDOC_SYNPRETTY; + /* Register analysis. */ + + if (m->regs->regs[(int)REG_nS].set) { + if (m->regs->regs[(int)REG_nS].v.u) + p->flags |= MDOC_SYNPRETTY; + else + p->flags &= ~MDOC_SYNPRETTY; + } + return(p); } diff --git a/mdoc_validate.c b/mdoc_validate.c index de1a7cc1..93b7ed94 100644 --- a/mdoc_validate.c +++ b/mdoc_validate.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_validate.c,v 1.99 2010/06/13 21:02:49 kristaps Exp $ */ +/* $Id: mdoc_validate.c,v 1.100 2010/06/27 16:36:22 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -806,6 +806,8 @@ pre_sh(PRE_ARGS) if (MDOC_BLOCK != n->type) return(1); + + mdoc->regs->regs[(int)REG_nS].set = 0; return(check_parent(mdoc, n, MDOC_MAX, MDOC_ROOT)); } @@ -1,4 +1,4 @@ -/* $Id: regs.h,v 1.2 2010/06/26 15:36:37 kristaps Exp $ */ +/* $Id: regs.h,v 1.3 2010/06/27 16:36:22 kristaps Exp $ */ /* * Copyright (c) 2010 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -24,10 +24,21 @@ enum regs { REG__MAX }; -struct regset { +struct reg { + int set; /* whether set or not */ union { - int i; /* integer value */ - } regs[REG__MAX]; + unsigned u; /* unsigned integer */ + } v; +}; + +/* + * Registers are non-scoped state. These can be manipulated directly in + * libroff or indirectly in libman or libmdoc by macros. These should + * be implemented sparingly (we are NOT roffdoc!) and documented fully + * in roff.7. + */ +struct regset { + struct reg regs[REG__MAX]; }; __END_DECLS @@ -1,4 +1,4 @@ -.\" $Id: roff.7,v 1.10 2010/06/26 15:22:19 kristaps Exp $ +.\" $Id: roff.7,v 1.11 2010/06/27 16:36:22 kristaps Exp $ .\" .\" Copyright (c) 2010 Kristaps Dzonsons <kristaps@bsd.lv> .\" @@ -14,7 +14,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: June 26 2010 $ +.Dd $Mdocdate: June 27 2010 $ .Dt ROFF 7 .Os .Sh NAME @@ -289,12 +289,15 @@ requests are recognised: .It Cm nS If set to a positive integer value, certain .Xr mdoc 7 -macros will behave as if they are defined in the +macros will behave as if they were defined in the .Em SYNOPSIS -section to a manual. +section. Otherwise, this behaviour is unset (even if called within the .Em SYNOPSIS section itself). +Note that invoking a new +.Xr mdoc 7 +section will unset this value. .El .Ss \&tr Output character translation. @@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.90 2010/06/27 15:52:41 kristaps Exp $ */ +/* $Id: roff.c,v 1.91 2010/06/27 16:36:22 kristaps Exp $ */ /* * Copyright (c) 2010 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -155,7 +155,7 @@ static int roffnode_push(struct roff *, enum rofft, int, int); static void roffnode_pop(struct roff *); static enum rofft roff_parse(const char *, int *); -static int roff_parse_nat(const char *, int *); +static int roff_parse_nat(const char *, unsigned int *); /* See roff_hash_find() */ #define ROFF_HASH(p) (p[0] - ASCII_LO) @@ -425,7 +425,7 @@ roff_parse(const char *buf, int *pos) static int -roff_parse_nat(const char *buf, int *res) +roff_parse_nat(const char *buf, unsigned int *res) { char *ep; long lval; @@ -436,10 +436,10 @@ roff_parse_nat(const char *buf, int *res) return(0); if ((errno == ERANGE && (lval == LONG_MAX || lval == LONG_MIN)) || - (lval > INT_MAX || lval <= 0)) + (lval > INT_MAX || lval < 0)) return(0); - *res = (int)lval; + *res = (unsigned int)lval; return(1); } @@ -882,8 +882,10 @@ static enum rofferr roff_nr(ROFF_ARGS) { const char *key, *val; + struct reg *rg; key = &(*bufp)[pos]; + rg = r->regs->regs; /* Parse register request. */ while ((*bufp)[pos] && ' ' != (*bufp)[pos]) @@ -905,11 +907,12 @@ roff_nr(ROFF_ARGS) /* Process register token. */ if (0 == strcmp(key, "nS")) { - if ( ! roff_parse_nat(val, &r->regs->regs[(int)REG_nS].i)) - r->regs->regs[(int)REG_nS].i = 0; + rg[(int)REG_nS].set = 1; + if ( ! roff_parse_nat(val, &rg[(int)REG_nS].v.u)) + rg[(int)REG_nS].v.u = 0; - ROFF_DEBUG("roff: register nS: %d\n", - r->regs->regs[(int)REG_nS].i); + ROFF_DEBUG("roff: register nS: %u\n", + rg[(int)REG_nS].v.u); } else ROFF_DEBUG("roff: ignoring register: %s\n", key); |