summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mdoc.c9
-rw-r--r--mdoc_validate.c2
-rw-r--r--regs.h17
-rw-r--r--roff.77
-rw-r--r--roff.c19
5 files changed, 41 insertions, 13 deletions
diff --git a/mdoc.c b/mdoc.c
index f2f5f1cf..59c54b83 100644
--- a/mdoc.c
+++ b/mdoc.c
@@ -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 8615ad46..99c2e359 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -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));
}
diff --git a/regs.h b/regs.h
index ca388597..0bec3a53 100644
--- a/regs.h
+++ b/regs.h
@@ -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
diff --git a/roff.7 b/roff.7
index e35f37d4..44759861 100644
--- a/roff.7
+++ b/roff.7
@@ -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.
diff --git a/roff.c b/roff.c
index 15d4cfe6..9d2294c6 100644
--- a/roff.c
+++ b/roff.c
@@ -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);