source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* docbook2mdoc: Improve the proplogue: * Use <pubdate> or <date> for .Dd.
@ 2019-04-13 13:07 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2019-04-13 13:07 UTC (permalink / raw)
  To: source

Log Message:
-----------
Improve the proplogue:
* Use <pubdate> or <date> for .Dd.
* Clean up the way how <title> from <bookinfo> is used for .Nd.
* Treat <articleinfo> just like <bookinfo>.

Modified Files:
--------------
    docbook2mdoc:
        docbook2mdoc.c
        node.c
        node.h
        parse.c
        statistics.c

Revision Data
-------------
Index: node.h
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/node.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -Lnode.h -Lnode.h -u -p -r1.21 -r1.22
--- node.h
+++ node.h
@@ -113,6 +113,7 @@ enum	nodeid {
 	NODE_PREFACE,
 	NODE_PROGRAMLISTING,
 	NODE_PROMPT,
+	NODE_PUBDATE,
 	NODE_QUOTE,
 	NODE_REFCLASS,
 	NODE_REFDESCRIPTOR,
@@ -251,3 +252,4 @@ void		 pnode_unlinksub(struct pnode *);
 enum attrval	 pnode_getattr(struct pnode *, enum attrkey);
 const char	*pnode_getattr_raw(struct pnode *, enum attrkey, const char *);
 struct pnode	*pnode_findfirst(struct pnode *, enum nodeid);
+struct pnode	*pnode_takefirst(struct pnode *, enum nodeid);
Index: parse.c
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/parse.c,v
retrieving revision 1.40
retrieving revision 1.41
diff -Lparse.c -Lparse.c -u -p -r1.40 -r1.41
--- parse.c
+++ parse.c
@@ -72,6 +72,7 @@ static	const struct alias aliases[] = {
 	{ "acronym",		NODE_IGNORE },
 	{ "anchor",		NODE_DELETE },
 	{ "article",		NODE_SECTION },
+	{ "articleinfo",	NODE_BOOKINFO },
 	{ "book",		NODE_SECTION },
 	{ "chapter",		NODE_SECTION },
 	{ "code",		NODE_LITERAL },
Index: docbook2mdoc.c
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/docbook2mdoc.c,v
retrieving revision 1.115
retrieving revision 1.116
diff -Ldocbook2mdoc.c -Ldocbook2mdoc.c -u -p -r1.115 -r1.116
--- docbook2mdoc.c
+++ docbook2mdoc.c
@@ -318,32 +318,6 @@ pnode_printciterefentry(struct format *f
 }
 
 static void
-pnode_printrefmeta(struct format *f, struct pnode *n)
-{
-	struct pnode	*nc, *title, *manvol;
-
-	title = manvol = NULL;
-	TAILQ_FOREACH(nc, &n->childq, child) {
-		if (nc->node == NODE_MANVOLNUM)
-			manvol = nc;
-		else if (nc->node == NODE_REFENTRYTITLE)
-			title = nc;
-	}
-	macro_close(f);
-	macro_open(f, "Dt");
-	if (title == NULL)
-		macro_addarg(f, "UNKNOWN", ARG_SPACE);
-	else
-		macro_addnode(f, title, ARG_SPACE | ARG_SINGLE | ARG_UPPER);
-	if (manvol == NULL)
-		macro_addarg(f, "1", ARG_SPACE);
-	else
-		macro_addnode(f, manvol, ARG_SPACE | ARG_SINGLE);
-	macro_close(f);
-	pnode_unlink(n);
-}
-
-static void
 pnode_printfuncdef(struct format *f, struct pnode *n)
 {
 	struct pnode	*nc;
@@ -658,24 +632,73 @@ pnode_printlink(struct format *f, struct
 }
 
 static void
-pnode_printprologue(struct format *f, struct ptree *tree)
+pnode_printprologue(struct format *f, struct pnode *root)
 {
-	struct pnode	*refmeta;
+	struct pnode	*date, *refmeta, *name, *vol, *descr, *nc;
+	const char	*sname;
 
-	refmeta = tree->root == NULL ? NULL :
-	    pnode_findfirst(tree->root, NODE_REFMETA);
+	/* Collect information. */
 
-	macro_line(f, "Dd $Mdocdate" "$");
-	if (refmeta == NULL) {
-		macro_open(f, "Dt");
-		macro_addarg(f,
-		    pnode_getattr_raw(tree->root, ATTRKEY_ID, "UNKNOWN"),
-		    ARG_SPACE | ARG_SINGLE | ARG_UPPER);
-		macro_addarg(f, "1", ARG_SPACE);
-		macro_close(f);
+	if ((date = pnode_takefirst(root, NODE_PUBDATE)) == NULL)
+		date = pnode_takefirst(root, NODE_DATE);
+
+	name = vol = NULL;
+	if ((refmeta = pnode_takefirst(root, NODE_REFMETA)) != NULL) {
+		TAILQ_FOREACH(nc, &refmeta->childq, child) {
+			switch (nc->node) {
+			case NODE_REFENTRYTITLE:
+				name = nc;
+				break;
+			case NODE_MANVOLNUM:
+				vol = nc;
+				break;
+			default:
+				break;
+			}
+		}
+	}
+
+	if (pnode_findfirst(root, NODE_REFNAMEDIV) == NULL &&
+	    ((nc = pnode_findfirst(root, NODE_BOOKINFO)) != NULL ||
+	     (nc = pnode_findfirst(root, NODE_REFENTRYINFO)) != NULL))
+		descr = pnode_takefirst(nc, NODE_TITLE);
+	else
+		descr = NULL;
+
+	/* Print prologue. */
+
+	if (date == NULL)
+		macro_line(f, "Dd $Mdocdate" "$");
+	else
+		macro_nodeline(f, "Dd", date, 0);
+
+	macro_open(f, "Dt");
+	if (name == NULL) {
+		sname = pnode_getattr_raw(root, ATTRKEY_ID, "UNKNOWN");
+		macro_addarg(f, sname, ARG_SPACE | ARG_SINGLE | ARG_UPPER);
 	} else
-		pnode_printrefmeta(f, refmeta);
+		macro_addnode(f, name, ARG_SPACE | ARG_SINGLE | ARG_UPPER);
+	if (vol == NULL)
+		macro_addarg(f, "1", ARG_SPACE);
+	else
+		macro_addnode(f, vol, ARG_SPACE | ARG_SINGLE);
+
 	macro_line(f, "Os");
+
+	if (descr != NULL) {
+		macro_line(f, "Sh NAME");
+		if (name == NULL)
+			macro_argline(f, "Nm", sname);
+		else
+			macro_nodeline(f, "Nm", name, ARG_SINGLE);
+		macro_nodeline(f, "Nd", descr, 0);
+	}
+
+	/* Clean up. */
+
+	pnode_unlink(date);
+	pnode_unlink(refmeta);
+	pnode_unlink(descr);
 }
 
 /*
@@ -876,9 +899,6 @@ pnode_print(struct format *f, struct pno
 	case NODE_BLOCKQUOTE:
 		macro_line(f, "Bd -ragged -offset indent");
 		break;
-	case NODE_BOOKINFO:
-		macro_line(f, "Sh NAME");
-		break;
 	case NODE_CITEREFENTRY:
 		pnode_printciterefentry(f, n);
 		break;
@@ -1046,11 +1066,6 @@ pnode_print(struct format *f, struct pno
 		pnode_printtgroup(f, n);
 		break;
 	case NODE_TITLE:
-		if (n->parent != NULL &&
-		    n->parent->node == NODE_BOOKINFO) {
-			macro_open(f, "Nd");
-			break;
-		}
 		pnode_printpara(f, n);
 		macro_nodeline(f, "Sy", n, 0);
 		pnode_unlinksub(n);
@@ -1148,11 +1163,6 @@ pnode_print(struct format *f, struct pno
 	case NODE_SYNOPSIS:
 		macro_line(f, "Ed");
 		break;
-	case NODE_TITLE:
-		if (n->parent != NULL &&
-		    n->parent->node == NODE_BOOKINFO)
-			macro_line(f, "Sh AUTHORS");
-		break;
 	default:
 		break;
 	}
@@ -1166,7 +1176,7 @@ ptree_print_mdoc(struct ptree *tree)
 
 	formatter.level = 0;
 	formatter.linestate = LINE_NEW;
-	pnode_printprologue(&formatter, tree);
+	pnode_printprologue(&formatter, tree->root);
 	pnode_print(&formatter, tree->root);
 	if (formatter.linestate != LINE_NEW)
 		putchar('\n');
Index: node.c
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/node.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -Lnode.c -Lnode.c -u -p -r1.11 -r1.12
--- node.c
+++ node.c
@@ -105,6 +105,7 @@ static	const struct nodeprop properties[
 	{ "preface",		CLASS_BLOCK },
 	{ "programlisting",	CLASS_BLOCK },
 	{ "prompt",		CLASS_TRANS },
+	{ "pubdate",		CLASS_TRANS },
 	{ "quote",		CLASS_ENCL },
 	{ "refclass",		CLASS_TRANS },
 	{ "refdescriptor",	CLASS_TRANS },
@@ -340,10 +341,25 @@ pnode_findfirst(struct pnode *n, enum no
 {
 	struct pnode	*nc, *res;
 
+	if (n == NULL)
+		return NULL;
 	if (n->node == node)
 		return n;
 	TAILQ_FOREACH(nc, &n->childq, child)
 		if ((res = pnode_findfirst(nc, node)) != NULL)
 			return res;
 	return NULL;
+}
+
+/*
+ * Like pnode_findfirst(), but also take the node out of the tree.
+ */
+struct pnode *
+pnode_takefirst(struct pnode *n, enum nodeid node)
+{
+	struct pnode	*nc;
+
+	if ((nc = pnode_findfirst(n, node)) != NULL && nc->parent != NULL)
+		TAILQ_REMOVE(&nc->parent->childq, nc, child);
+	return nc;
 }
Index: statistics.c
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/statistics.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -Lstatistics.c -Lstatistics.c -u -p -r1.20 -r1.21
--- statistics.c
+++ statistics.c
@@ -352,6 +352,8 @@ main(int argc, char *argv[])
 		table_add("acronym", "TEXT");
 		table_add("appendix", NULL);
 		table_add("article", NULL);
+		table_add("articleinfo", "pubdate");
+		table_add("articleinfo", "title");
 		table_add("author", "contrib");
 		table_add("author", "email");
 		table_add("author", "firstname");
@@ -359,10 +361,13 @@ main(int argc, char *argv[])
 		table_add("author", "surname");
 		table_add("blockquote", NULL);
 		table_add("book", NULL);
+		table_add("bookinfo", "pubdate");
+		table_add("bookinfo", "title");
 		table_add("chapter", NULL);
 		table_add("code", "TEXT");
 		table_add("computeroutput", "TEXT");
 		table_add("constant", "TEXT");
+		table_add("date", "TEXT");
 		table_add("emphasis", "TEXT");
 		table_add("entry", NULL);
 		table_add("errorname", "TEXT");
@@ -408,6 +413,7 @@ main(int argc, char *argv[])
 		table_add("parameter", "TEXT");
 		table_add("primary", NULL);
 		table_add("programlisting", NULL);
+		table_add("pubdate", "TEXT");
 		table_add("refentry", "refmeta");
 		table_add("refentry", "refnamediv");
 		table_add("refentry", "refsect1");
--
 To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-04-13 13:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-13 13:07 docbook2mdoc: Improve the proplogue: * Use <pubdate> or <date> for .Dd 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).