aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2010-07-01 22:35:54 +0000
committerIngo Schwarze <schwarze@openbsd.org>2010-07-01 22:35:54 +0000
commite552a5cef0219ea63fb9521677e1a8a05ad35727 (patch)
tree4a4e069b6b57e03c5805f88f307dae15e95a65ad
parent9c216164abd606b0097a7d91e8e0026c721fa54d (diff)
downloadmandoc-e552a5cef0219ea63fb9521677e1a8a05ad35727.tar.gz
mandoc-e552a5cef0219ea63fb9521677e1a8a05ad35727.tar.zst
mandoc-e552a5cef0219ea63fb9521677e1a8a05ad35727.zip
In the mdoc(7) parser, inspect roff registers early such that all parts
of the parser can use the resulting cues. In particular, this allows to use .nr nS to force SYNOPSIS-style .Nm indentation outside the SYNOPSIS as needed by ifconfig(8). To actually make this useable, .Pp must rewind .Nm, or the rest of the section would end up indented. Implement a quick hack for now, a generic solution can be designed later. ok kristaps@ and tested by sobrado@
-rw-r--r--libmdoc.h3
-rw-r--r--mdoc.c34
-rw-r--r--mdoc_action.c13
-rw-r--r--mdoc_macro.c7
4 files changed, 38 insertions, 19 deletions
diff --git a/libmdoc.h b/libmdoc.h
index f4aba6a5..32328ff9 100644
--- a/libmdoc.h
+++ b/libmdoc.h
@@ -1,4 +1,4 @@
-/* $Id: libmdoc.h,v 1.58 2010/06/29 19:20:38 schwarze Exp $ */
+/* $Id: libmdoc.h,v 1.59 2010/07/01 22:35:54 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -36,6 +36,7 @@ struct mdoc {
#define MDOC_PHRASELIT (1 << 4) /* literal within a partila phrase */
#define MDOC_PPHRASE (1 << 5) /* within a partial phrase */
#define MDOC_FREECOL (1 << 6) /* `It' invocation should close */
+#define MDOC_SYNOPSIS (1 << 7) /* SYNOPSIS-style formatting */
int pflags;
enum mdoc_next next; /* where to put the next node */
struct mdoc_node *last; /* the last node parsed */
diff --git a/mdoc.c b/mdoc.c
index 4544e785..0526f5bd 100644
--- a/mdoc.c
+++ b/mdoc.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc.c,v 1.152 2010/06/29 19:20:38 schwarze Exp $ */
+/* $Id: mdoc.c,v 1.153 2010/07/01 22:35:54 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -239,6 +239,20 @@ mdoc_parseln(struct mdoc *m, int ln, char *buf, int offs)
return(0);
m->flags |= MDOC_NEWLINE;
+
+ /*
+ * Let the roff nS register switch SYNOPSIS mode early,
+ * such that the parser knows at all times
+ * whether this mode is on or off.
+ * Note that this mode is also switched by the Sh macro.
+ */
+ if (m->regs->regs[(int)REG_nS].set) {
+ if (m->regs->regs[(int)REG_nS].v.u)
+ m->flags |= MDOC_SYNOPSIS;
+ else
+ m->flags &= ~MDOC_SYNOPSIS;
+ }
+
return(('.' == buf[offs] || '\'' == buf[offs]) ?
mdoc_pmacro(m, ln, buf, offs) :
mdoc_ptext(m, ln, buf, offs));
@@ -373,24 +387,14 @@ node_alloc(struct mdoc *m, int line, int pos,
/* Flag analysis. */
+ if (MDOC_SYNOPSIS & m->flags)
+ p->flags |= MDOC_SYNPRETTY;
+ else
+ p->flags &= ~MDOC_SYNPRETTY;
if (MDOC_NEWLINE & m->flags)
p->flags |= MDOC_LINE;
m->flags &= ~MDOC_NEWLINE;
- /* Section analysis. */
-
- 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_action.c b/mdoc_action.c
index d01d665b..e4eed904 100644
--- a/mdoc_action.c
+++ b/mdoc_action.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_action.c,v 1.72 2010/06/27 15:52:41 kristaps Exp $ */
+/* $Id: mdoc_action.c,v 1.73 2010/07/01 22:35:54 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -457,6 +457,17 @@ post_sh(POST_ARGS)
if (SEC_NONE == m->lastnamed || SEC_CUSTOM != sec)
m->lastnamed = sec;
+ /*
+ * Switch the parser's SYNOPSIS mode, to be copied
+ * into individual nodes when creating them.
+ * Note that this mode can also be set and unset
+ * using the roff nS register.
+ */
+ if (SEC_SYNOPSIS == sec)
+ m->flags |= MDOC_SYNOPSIS;
+ else
+ m->flags &= ~MDOC_SYNOPSIS;
+
/* Some sections only live in certain manual sections. */
switch ((m->lastsec = sec)) {
diff --git a/mdoc_macro.c b/mdoc_macro.c
index 0a8d2c5c..7d0ee327 100644
--- a/mdoc_macro.c
+++ b/mdoc_macro.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_macro.c,v 1.89 2010/07/01 21:12:00 schwarze Exp $ */
+/* $Id: mdoc_macro.c,v 1.90 2010/07/01 22:35:54 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -1582,6 +1582,9 @@ in_line_eoln(MACRO_PROT_ARGS)
assert( ! (MDOC_PARSED & mdoc_macros[tok].flags));
+ if (tok == MDOC_Pp)
+ rew_sub(MDOC_BLOCK, m, MDOC_Nm, line, ppos);
+
/* Parse macro arguments. */
for (arg = NULL; ; ) {
@@ -1645,7 +1648,7 @@ ctx_synopsis(MACRO_PROT_ARGS)
nl = MDOC_NEWLINE & m->flags;
/* If we're not in the SYNOPSIS, go straight to in-line. */
- if (SEC_SYNOPSIS != m->lastsec)
+ if ( ! (MDOC_SYNOPSIS & m->flags))
return(in_line(m, tok, line, ppos, pos, buf));
/* If we're a nested call, same place. */