source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: In the mdoc(7) parser, inspect roff registers early such that
@ 2010-07-01 22:35 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2010-07-01 22:35 UTC (permalink / raw)
  To: source

Log Message:
-----------
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@

Modified Files:
--------------
    mdocml:
        libmdoc.h
        mdoc.c
        mdoc_action.c
        mdoc_macro.c

Revision Data
-------------
Index: mdoc_macro.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_macro.c,v
retrieving revision 1.89
retrieving revision 1.90
diff -Lmdoc_macro.c -Lmdoc_macro.c -u -p -r1.89 -r1.90
--- mdoc_macro.c
+++ mdoc_macro.c
@@ -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. */
Index: mdoc_action.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_action.c,v
retrieving revision 1.72
retrieving revision 1.73
diff -Lmdoc_action.c -Lmdoc_action.c -u -p -r1.72 -r1.73
--- mdoc_action.c
+++ mdoc_action.c
@@ -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)) {
Index: libmdoc.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/libmdoc.h,v
retrieving revision 1.58
retrieving revision 1.59
diff -Llibmdoc.h -Llibmdoc.h -u -p -r1.58 -r1.59
--- libmdoc.h
+++ libmdoc.h
@@ -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 */
Index: mdoc.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc.c,v
retrieving revision 1.152
retrieving revision 1.153
diff -Lmdoc.c -Lmdoc.c -u -p -r1.152 -r1.153
--- mdoc.c
+++ mdoc.c
@@ -239,6 +239,20 @@ mdoc_parseln(struct mdoc *m, int ln, cha
 		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,23 +387,13 @@ node_alloc(struct mdoc *m, int line, int
 
 	/* 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);
 }
--
 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-07-01 22:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-01 22:35 mdocml: In the mdoc(7) parser, inspect roff registers early such that schwarze

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).