source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Add ability to interpret initial free-form lines as part of a
@ 2010-05-31 15:42 kristaps
  0 siblings, 0 replies; only message in thread
From: kristaps @ 2010-05-31 15:42 UTC (permalink / raw)
  To: source

Log Message:
-----------
Add ability to interpret initial free-form lines as part of a `Bl
-column' up until the first `It'.  This is UGLY and should have all
sorts of warnings, and will.  On the one hand, it fits with groff's
notion of tabs and tab-spaces.  On the other hand, it's not really
"free-form" text any more.  Note that this does not yet accomodate for
macros coming on these lines.

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

Added Files:
-----------
    mdocml/regress/mdoc/It:
        freecol0.in
        freecol1.in
        freecol2.in

Revision Data
-------------
Index: TODO
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/TODO,v
retrieving revision 1.10
retrieving revision 1.11
diff -LTODO -LTODO -u -p -r1.10 -r1.11
--- TODO
+++ TODO
@@ -54,6 +54,9 @@
   .Bl -column
   .It foo Ta bar
   .El
+
+- explicitly disallow nested `Bl -column', which would clobber internal
+  flags defined for struct mdoc_macro
   
 ************************************************************************
 * formatting issues: ugly output
Index: mdoc_macro.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_macro.c,v
retrieving revision 1.76
retrieving revision 1.77
diff -Lmdoc_macro.c -Lmdoc_macro.c -u -p -r1.76 -r1.77
--- mdoc_macro.c
+++ mdoc_macro.c
@@ -1118,7 +1118,7 @@ blk_full(MACRO_PROT_ARGS)
 	/* If we've already opened our body, exit now. */
 
 	if (NULL != body)
-		return(1);
+		goto out;
 
 #ifdef	UGLY
 	/*
@@ -1145,6 +1145,16 @@ blk_full(MACRO_PROT_ARGS)
 	if ( ! mdoc_body_alloc(m, line, ppos, tok))
 		return(0);
 
+out:
+	if ( ! (MDOC_FREECOL & m->flags))
+		return(1);
+
+	if ( ! rew_sub(MDOC_BODY, m, tok, line, ppos))
+		return(0);
+	if ( ! rew_sub(MDOC_BLOCK, m, tok, line, ppos))
+		return(0);
+
+	m->flags &= ~MDOC_FREECOL;
 	return(1);
 }
 
Index: libmdoc.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/libmdoc.h,v
retrieving revision 1.50
retrieving revision 1.51
diff -Llibmdoc.h -Llibmdoc.h -u -p -r1.50 -r1.51
--- libmdoc.h
+++ libmdoc.h
@@ -34,6 +34,7 @@ struct	mdoc {
 #define	MDOC_NEWLINE	 (1 << 3) /* first macro/text in a line */
 #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 */
 	int		  pflags;
 	enum mdoc_next	  next;
 	struct mdoc_node *last;
Index: mdoc.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc.c,v
retrieving revision 1.141
retrieving revision 1.142
diff -Lmdoc.c -Lmdoc.c -u -p -r1.141 -r1.142
--- mdoc.c
+++ mdoc.c
@@ -542,7 +542,8 @@ mdoc_node_delete(struct mdoc *m, struct 
 static int
 mdoc_ptext(struct mdoc *m, int line, char *buf, int offs)
 {
-	char		*c, *ws, *end;
+	char		 *c, *ws, *end;
+	struct mdoc_node *n;
 
 	/* Ignore bogus comments. */
 
@@ -555,6 +556,29 @@ mdoc_ptext(struct mdoc *m, int line, cha
 
 	if (SEC_NONE == m->lastnamed)
 		return(mdoc_pmsg(m, line, offs, MANDOCERR_NOTEXT));
+
+	assert(m->last);
+	n = m->last;
+
+	/*
+	 * Diver directly into list processing if we're encountering a
+	 * columnar MDOC_BLOCK with or without a prior MDOC_BLOCK entry
+	 * (if it's a MDOC_BODY that means it's open, in which case we
+	 * should process within its context).
+	 */
+
+	if (MDOC_Bl == n->tok && LIST_column == n->data.list) {
+		m->flags |= MDOC_FREECOL;
+		return(mdoc_macro(m, MDOC_It, line, offs, &offs, buf));
+	}
+
+	if (MDOC_It == n->tok && MDOC_BLOCK == n->type &&
+			NULL != n->parent &&
+			MDOC_Bl == n->parent->tok &&
+			LIST_column == n->parent->data.list) {
+		m->flags |= MDOC_FREECOL;
+		return(mdoc_macro(m, MDOC_It, line, offs, &offs, buf));
+	}
 
 	/*
 	 * Search for the beginning of unescaped trailing whitespace (ws)
--- /dev/null
+++ regress/mdoc/It/freecol0.in
@@ -0,0 +1,11 @@
+.Dd $Mdocdate: May 31 2010 $
+.Dt FOO
+.Os
+.Sh NAME
+.Nm foo
+.Nd bar
+.Sh DESCRIPTION
+hello
+.Bl -column asdfasdf asdfasdf
+hello	there
+.El
--- /dev/null
+++ regress/mdoc/It/freecol1.in
@@ -0,0 +1,12 @@
+.Dd $Mdocdate: May 31 2010 $
+.Dt FOO
+.Os
+.Sh NAME
+.Nm foo
+.Nd bar
+.Sh DESCRIPTION
+hello
+.Bl -column asdfasdf asdfasdf
+hello	there
+hello	there
+.El
--- /dev/null
+++ regress/mdoc/It/freecol2.in
@@ -0,0 +1,16 @@
+.Dd $Mdocdate: May 31 2010 $
+.Dt FOO
+.Os
+.Sh NAME
+.Nm foo
+.Nd bar
+.Sh DESCRIPTION
+hello
+.Bl -column asdfasdf asdfasdf
+hello	there
+hello	there
+.It hello	there
+.It hello Ta there
+.It hello Ta
+there
+.El
--
 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-05-31 15:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-31 15:42 mdocml: Add ability to interpret initial free-form lines as part of a 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).