source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* docbook2mdoc: Add initial support for mml:* -> eqn(7).
@ 2014-10-12 15:08 kristaps
  0 siblings, 0 replies; only message in thread
From: kristaps @ 2014-10-12 15:08 UTC (permalink / raw)
  To: source

Log Message:
-----------
Add initial support for mml:* -> eqn(7).

Modified Files:
--------------
    docbook2mdoc:
        docbook2mdoc.1
        docbook2mdoc.c
        extern.h
        rules.c

Revision Data
-------------
Index: extern.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/docbook2mdoc/extern.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -Lextern.h -Lextern.h -u -p -r1.22 -r1.23
--- extern.h
+++ extern.h
@@ -33,12 +33,23 @@ enum	nodeid {
 	NODE_GROUP,
 	NODE_HOLDER,
 	NODE_INFO,
+	NODE_INFORMALEQUATION,
 	NODE_INFORMALTABLE,
+	NODE_INLINEEQUATION,
 	NODE_ITEMIZEDLIST,
 	NODE_LINK,
 	NODE_LISTITEM,
 	NODE_LITERAL,
 	NODE_MANVOLNUM, 
+	NODE_MML_MATH,
+	NODE_MML_MFENCED,
+	NODE_MML_MFRAC,
+	NODE_MML_MI,
+	NODE_MML_MN,
+	NODE_MML_MO,
+	NODE_MML_MROW,
+	NODE_MML_MSUB,
+	NODE_MML_MSUP,
 	NODE_MODIFIER, 
 	NODE_NOTE, 
 	NODE_OPTION,
Index: docbook2mdoc.1
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/docbook2mdoc/docbook2mdoc.1,v
retrieving revision 1.5
retrieving revision 1.6
diff -Ldocbook2mdoc.1 -Ldocbook2mdoc.1 -u -p -r1.5 -r1.6
--- docbook2mdoc.1
+++ docbook2mdoc.1
@@ -31,6 +31,8 @@ utility reads
 and
 generates
 .Xr mdoc 7
+and
+.Xr eqn 7
 from the
 .Aq refentry
 section of DocBook source, ignoring other sections.
@@ -50,8 +52,13 @@ Some earlier DocBook constructs are acce
 SGML DocBook documents may be parsed unless they contain SGML-specific
 constructs, such as empty end tags
 .Li </> .
-The only non-DocBook construct recognised (and discarded) is
-.Aq xi:include \(sl .
+The only non-DocBook construct recognised are
+.Aq xi:include \(sl
+.Pq which is discarded
+and
+.Aq mml:* ,
+which is accepted and converted to
+.Xr eqn 7 .
 .Sh EXIT STATUS
 .Ex -std
 .Sh EXAMPLES
Index: docbook2mdoc.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/docbook2mdoc/docbook2mdoc.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -Ldocbook2mdoc.c -Ldocbook2mdoc.c -u -p -r1.39 -r1.40
--- docbook2mdoc.c
+++ docbook2mdoc.c
@@ -114,12 +114,23 @@ static	const struct node nodes[NODE__MAX
 	{ "group", NODE_IGNTEXT }, 
 	{ "holder", NODE_IGNTEXT },
 	{ "info", NODE_IGNTEXT },
+	{ "informalequation", NODE_IGNTEXT }, 
 	{ "informaltable", NODE_IGNTEXT }, 
+	{ "inlineequation", NODE_IGNTEXT }, 
 	{ "itemizedlist", NODE_IGNTEXT }, 
 	{ "link", 0 }, 
 	{ "listitem", NODE_IGNTEXT }, 
 	{ "literal", 0 }, 
 	{ "manvolnum", 0 }, 
+	{ "mml:math", NODE_IGNTEXT }, 
+	{ "mml:mfenced", 0 }, 
+	{ "mml:mfrac", 0 }, 
+	{ "mml:mi", 0 }, 
+	{ "mml:mn", 0 }, 
+	{ "mml:mo", 0 }, 
+	{ "mml:mrow", 0 }, 
+	{ "mml:msub", 0 }, 
+	{ "mml:msup", 0 }, 
 	{ "modifier", 0 }, 
 	{ "note", NODE_IGNTEXT }, 
 	{ "option", 0 }, 
@@ -851,6 +862,38 @@ pnode_printparamdef(struct parse *p, str
 	p->newln = 1;
 }
 
+/*
+ * These math nodes require special handling because they have infix
+ * syntax, instead of the usual prefix or prefix.
+ * So we need to break up the first and second child node with a
+ * particular eqn(7) word.
+ */
+static void
+pnode_printmath(struct parse *p, struct pnode *pn)
+{
+	struct pnode	*pp;
+
+	pp = TAILQ_FIRST(&pn->childq);
+	pnode_print(p, pp);
+
+	switch (pn->node) {
+	case (NODE_MML_MSUP):
+		printf(" sup ");
+		break;
+	case (NODE_MML_MFRAC):
+		printf(" over ");
+		break;
+	case (NODE_MML_MSUB):
+		printf(" sub ");
+		break;
+	default:
+		break;
+	}
+
+	pp = TAILQ_NEXT(pp, child);
+	pnode_print(p, pp);
+}
+
 static void
 pnode_printfuncprototype(struct parse *p, struct pnode *pn)
 {
@@ -1191,6 +1234,27 @@ pnode_print(struct parse *p, struct pnod
 		pnode_printmopen(p);
 		fputs("Li", stdout);
 		break;
+	case (NODE_MML_MATH):
+		if ( ! p->newln)
+			putchar('\n');
+		puts(".EQ");
+		p->newln = 0;
+		break;
+	case (NODE_MML_MFENCED):
+		printf("left {");
+		break;
+	case (NODE_MML_MROW):
+	case (NODE_MML_MI):
+	case (NODE_MML_MN):
+	case (NODE_MML_MO):
+		putchar('{');
+		break;
+	case (NODE_MML_MFRAC):
+	case (NODE_MML_MSUB):
+	case (NODE_MML_MSUP):
+		pnode_printmath(p, pn);
+		pnode_unlinksub(pn);
+		break;
 	case (NODE_OPTION):
 		pnode_printmopen(p);
 		fputs("Fl", stdout);
@@ -1371,6 +1435,21 @@ pnode_print(struct parse *p, struct pnod
 		pnode_print(p, pp);
 
 	switch (pn->node) {
+	case (NODE_MML_MATH):
+		if ( ! p->newln)
+			putchar('\n');
+		puts(".EN");
+		p->newln = 1;
+		break;
+	case (NODE_MML_MFENCED):
+		printf("right }");
+		break;
+	case (NODE_MML_MROW):
+	case (NODE_MML_MI):
+	case (NODE_MML_MN):
+	case (NODE_MML_MO):
+		putchar('}');
+		break;
 	case (NODE_APPLICATION):
 	case (NODE_ARG):
 	case (NODE_CITEREFENTRY):
Index: rules.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/docbook2mdoc/rules.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -Lrules.c -Lrules.c -u -p -r1.22 -r1.23
--- rules.c
+++ rules.c
@@ -502,6 +502,47 @@ isparent(enum nodeid node, enum nodeid p
 			break;
 		}
 		return(0);
+	case (NODE_INFORMALEQUATION):
+		switch (parent) {
+		case (NODE_CAUTION):
+		case (NODE_ENTRY):
+		case (NODE_ITEMIZEDLIST):
+		case (NODE_LISTITEM):
+		case (NODE_NOTE):
+		case (NODE_ORDEREDLIST):
+		case (NODE_PARA):
+		case (NODE_REFSECT1):
+		case (NODE_REFSECT2):
+		case (NODE_REFSECT3):
+		case (NODE_REFSECTION):
+		case (NODE_REFSYNOPSISDIV):
+		case (NODE_VARIABLELIST):
+		case (NODE_WARNING):
+			return(1);
+		default:
+			break;
+		}
+		return(0);
+	case (NODE_INLINEEQUATION):
+		switch (parent) {
+		case (NODE_APPLICATION):
+		case (NODE_EMPHASIS):
+		case (NODE_ENTRY):
+		case (NODE_LINK):
+		case (NODE_PARA):
+		case (NODE_PROGRAMLISTING):
+		case (NODE_QUOTE):
+		case (NODE_REFENTRYTITLE):
+		case (NODE_SCREEN):
+		case (NODE_SYNOPSIS):
+		case (NODE_TERM):
+		case (NODE_TITLE):
+		case (NODE_ULINK):
+			return(1);
+		default:
+			break;
+		}
+		return(0);
 	case (NODE_ITEMIZEDLIST):
 		switch (parent) {
 		case (NODE_CAUTION):
@@ -615,6 +656,38 @@ isparent(enum nodeid node, enum nodeid p
 			break;
 		}
 		return(0);
+	case (NODE_MML_MATH):
+		switch (parent) {
+		case (NODE_INFORMALEQUATION):
+		case (NODE_INLINEEQUATION):
+			return(1);
+		default:
+			break;
+		}
+		return(0);
+	case (NODE_MML_MFENCED):
+	case (NODE_MML_MFRAC):
+	case (NODE_MML_MI):
+	case (NODE_MML_MN):
+	case (NODE_MML_MO):
+	case (NODE_MML_MROW):
+	case (NODE_MML_MSUB):
+	case (NODE_MML_MSUP):
+		switch (parent) {
+		case (NODE_MML_MATH):
+		case (NODE_MML_MFENCED):
+		case (NODE_MML_MFRAC):
+		case (NODE_MML_MI):
+		case (NODE_MML_MN):
+		case (NODE_MML_MO):
+		case (NODE_MML_MROW):
+		case (NODE_MML_MSUB):
+		case (NODE_MML_MSUP):
+			return(1);
+		default:
+			break;
+		}
+		return(0);
 	case (NODE_MODIFIER):
 		switch (parent) {
 		case (NODE_CODE):
@@ -736,6 +809,7 @@ isparent(enum nodeid node, enum nodeid p
 	case (NODE_PARAMETER):
 		switch (parent) {
 		case (NODE_CODE):
+		case (NODE_EMPHASIS):
 		case (NODE_ENTRY):
 		case (NODE_FUNCSYNOPSISINFO):
 		case (NODE_LINK):
--
 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:[~2014-10-12 15:08 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-12 15:08 docbook2mdoc: Add initial support for mml:* -> eqn(7) 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).