* mdocml: Allow registers to be unset.
@ 2010-06-27 16:36 kristaps
0 siblings, 0 replies; only message in thread
From: kristaps @ 2010-06-27 16:36 UTC (permalink / raw)
To: source
Log Message:
-----------
Allow registers to be unset. Implement and document the `.nr nS val'.
Modified Files:
--------------
mdocml:
mdoc.c
mdoc_validate.c
regs.h
roff.7
roff.c
Revision Data
-------------
Index: roff.7
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/roff.7,v
retrieving revision 1.10
retrieving revision 1.11
diff -Lroff.7 -Lroff.7 -u -p -r1.10 -r1.11
--- roff.7
+++ 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.
Index: mdoc_validate.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_validate.c,v
retrieving revision 1.99
retrieving revision 1.100
diff -Lmdoc_validate.c -Lmdoc_validate.c -u -p -r1.99 -r1.100
--- mdoc_validate.c
+++ 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));
}
Index: regs.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/regs.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -Lregs.h -Lregs.h -u -p -r1.2 -r1.3
--- regs.h
+++ 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
Index: mdoc.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc.c,v
retrieving revision 1.150
retrieving revision 1.151
diff -Lmdoc.c -Lmdoc.c -u -p -r1.150 -r1.151
--- mdoc.c
+++ mdoc.c
@@ -380,6 +380,15 @@ node_alloc(struct mdoc *m, int line, int
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);
}
Index: roff.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/roff.c,v
retrieving revision 1.90
retrieving revision 1.91
diff -Lroff.c -Lroff.c -u -p -r1.90 -r1.91
--- roff.c
+++ 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);
--
To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2010-06-27 16:36 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-27 16:36 mdocml: Allow registers to be unset kristaps
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).