From e552a5cef0219ea63fb9521677e1a8a05ad35727 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Thu, 1 Jul 2010 22:35:54 +0000 Subject: 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@ --- mdoc.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'mdoc.c') 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 * @@ -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); } -- cgit v1.2.3-56-ge451