source@mandoc.bsd.lv
 help / color / Atom feed
* docbook2mdoc: move reshuffling of document info and meta nodes to the 
@ 2019-04-28 19:59 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2019-04-28 19:59 UTC (permalink / raw)
  To: source

Log Message:
-----------
move reshuffling of document info and meta nodes to the reorg module

Modified Files:
--------------
    docbook2mdoc:
        docbook2mdoc.c
        reorg.c

Revision Data
-------------
Index: docbook2mdoc.c
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/docbook2mdoc.c,v
retrieving revision 1.142
retrieving revision 1.143
diff -Ldocbook2mdoc.c -Ldocbook2mdoc.c -u -p -r1.142 -r1.143
--- docbook2mdoc.c
+++ docbook2mdoc.c
@@ -31,7 +31,6 @@
  */
 
 static void	 pnode_print(struct format *, struct pnode *);
-static void	 pnode_printrefentry(struct format *, struct pnode *);
 
 
 static void
@@ -196,10 +195,8 @@ pnode_printsection(struct format *f, str
 	struct pnode	*nc, *ncc;
 	int		 flags, level;
 
-	if (n->parent == NULL) {
-		pnode_printrefentry(f, n);
+	if (n->parent == NULL)
 		return;
-	}
 
 	level = ++f->level;
 	flags = ARG_SPACE;
@@ -726,123 +723,6 @@ pnode_printprologue(struct format *f, st
 	f->parastate = PARA_HAVE;
 }
 
-static void
-pnode_printrefentry(struct format *f, struct pnode *n)
-{
-	struct pnode	*info, *meta, *nc, *title;
-	struct pnode	*match, *later;
-
-	/* Collect nodes that remained behind when writing the prologue. */
-
-	meta = NULL;
-	info = pnode_takefirst(n, NODE_BOOKINFO);
-	if (info != NULL && TAILQ_FIRST(&info->childq) == NULL) {
-		pnode_unlink(info);
-		info = NULL;
-	}
-	if (info == NULL) {
-		info = pnode_takefirst(n, NODE_REFENTRYINFO);
-		if (info != NULL && TAILQ_FIRST(&info->childq) == NULL) {
-			pnode_unlink(info);
-			info = NULL;
-		}
-		if (info == NULL)
-			info = pnode_takefirst(n, NODE_INFO);
-		meta = pnode_takefirst(n, NODE_REFMETA);
-		if (meta != NULL && TAILQ_FIRST(&meta->childq) == NULL) {
-			pnode_unlink(meta);
-			meta = NULL;
-		}
-	}
-	if (info == NULL && meta == NULL)
-		return;
-
-	/*
-	 * Find the best place to put this information.
-	 * Use the last existing AUTHORS node, if any.
-	 * Otherwise, put it behind all standard sections that
-	 * conventionally precede AUTHORS, and also behind any
-	 * non-standard sections that follow the last of these,
-	 * but before the next standard section.
-	 */
-
-	match = later = NULL;
-	TAILQ_FOREACH(nc, &n->childq, child) {
-		switch (nc->node) {
-		case NODE_REFENTRY:
-		case NODE_REFNAMEDIV:
-		case NODE_REFSYNOPSISDIV:
-			later = NULL;
-			continue;
-		case NODE_APPENDIX:
-		case NODE_INDEX:
-			if (later == NULL)
-				later = nc;
-			continue;
-		default:
-			break;
-		}
-		if ((title = pnode_findfirst(nc, NODE_TITLE)) == NULL ||
-		    (title = TAILQ_FIRST(&title->childq)) == NULL ||
-		    title->node != NODE_TEXT)
-			continue;
-		if (strcasecmp(title->b, "AUTHORS") == 0 ||
-		    strcasecmp(title->b, "AUTHOR") == 0)
-			match = nc;
-		else if (strcasecmp(title->b, "NAME") == 0 ||
-		    strcasecmp(title->b, "SYNOPSIS") == 0 ||
-		    strcasecmp(title->b, "DESCRIPTION") == 0 ||
-		    strcasecmp(title->b, "RETURN VALUES") == 0 ||
-		    strcasecmp(title->b, "ENVIRONMENT") == 0 ||
-		    strcasecmp(title->b, "FILES") == 0 ||
-		    strcasecmp(title->b, "EXIT STATUS") == 0 ||
-		    strcasecmp(title->b, "EXAMPLES") == 0 ||
-		    strcasecmp(title->b, "DIAGNOSTICS") == 0 ||
-		    strcasecmp(title->b, "ERRORS") == 0 ||
-		    strcasecmp(title->b, "SEE ALSO") == 0 ||
-		    strcasecmp(title->b, "STANDARDS") == 0 ||
-		    strcasecmp(title->b, "HISTORY") == 0)
-			later = NULL;
-		else if ((strcasecmp(title->b, "CAVEATS") == 0 ||
-		    strcasecmp(title->b, "BUGS") == 0) &&
-		    later == NULL)
-			later = nc;
-	}
-
-	/*
-	 * If no AUTHORS section was found, create one from scratch,
-	 * and insert that at the place selected earlier.
-	 */
-
-	if (match == NULL) {
-		match = xcalloc(1, sizeof(*match));
-		match->node = NODE_SECTION;
-		match->flags |= NFLAG_SPC;
-		match->parent = n;
-		TAILQ_INIT(&match->childq);
-		TAILQ_INIT(&match->attrq);
-		nc = pnode_alloc(match);
-		nc->node = NODE_TITLE;
-		nc->flags |= NFLAG_SPC;
-		nc = pnode_alloc_text(nc, "AUTHORS");
-		nc->flags |= NFLAG_SPC;
-		if (later == NULL)
-			TAILQ_INSERT_TAIL(&n->childq, match, child);
-		else
-			TAILQ_INSERT_BEFORE(later, match, child);
-	}
-
-	/*
-	 * Dump the stuff excised at the beginning
-	 * into this AUTHORS section.
-	 */
-
-	if (info != NULL)
-		TAILQ_INSERT_TAIL(&match->childq, info, child);
-	if (meta != NULL)
-		TAILQ_INSERT_TAIL(&match->childq, meta, child);
-}
-
 /*
  * We can have multiple <term> elements within a <varlistentry>, which
  * we should comma-separate as list headers.
@@ -1226,9 +1106,6 @@ pnode_print(struct format *f, struct pno
 	case NODE_SYSTEMITEM:
 		pnode_printsystemitem(f, n);
 		break;
-	case NODE_REFENTRY:
-		pnode_printrefentry(f, n);
-		break;
 	case NODE_REFNAME:
 		/* More often, these appear inside NODE_REFNAMEDIV. */
 		macro_open(f, "Nm");
@@ -1391,7 +1268,8 @@ pnode_print(struct format *f, struct pno
 	case NODE_SIMPLESECT:
 	case NODE_APPENDIX:
 	case NODE_NOTE:
-		f->level--;
+		if (n->parent != NULL)
+			f->level--;
 		break;
 	case NODE_BLOCKQUOTE:
 	case NODE_LITERALLAYOUT:
Index: reorg.c
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/reorg.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -Lreorg.c -Lreorg.c -u -p -r1.2 -r1.3
--- reorg.c
+++ reorg.c
@@ -14,6 +14,7 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+#include "string.h"
 
 #include "node.h"
 #include "reorg.h"
@@ -72,6 +73,121 @@ reorg_root(struct pnode *root)
 }
 
 static void
+reorg_refentry(struct pnode *n)
+{
+	struct pnode	*info, *meta, *nc, *title;
+	struct pnode	*match, *later;
+
+	/* Collect nodes that remained behind from the prologue. */
+
+	meta = NULL;
+	info = pnode_takefirst(n, NODE_BOOKINFO);
+	if (info != NULL && TAILQ_FIRST(&info->childq) == NULL) {
+		pnode_unlink(info);
+		info = NULL;
+	}
+	if (info == NULL) {
+		info = pnode_takefirst(n, NODE_REFENTRYINFO);
+		if (info != NULL && TAILQ_FIRST(&info->childq) == NULL) {
+			pnode_unlink(info);
+			info = NULL;
+		}
+		if (info == NULL)
+			info = pnode_takefirst(n, NODE_INFO);
+		meta = pnode_takefirst(n, NODE_REFMETA);
+		if (meta != NULL && TAILQ_FIRST(&meta->childq) == NULL) {
+			pnode_unlink(meta);
+			meta = NULL;
+		}
+	}
+	if (info == NULL && meta == NULL)
+		return;
+
+	/*
+	 * Find the best place to put this information.
+	 * Use the last existing AUTHORS node, if any.
+	 * Otherwise, put it behind all standard sections that
+	 * conventionally precede AUTHORS, and also behind any
+	 * non-standard sections that follow the last of these,
+	 * but before the next standard section.
+	 */
+
+	match = later = NULL;
+	TAILQ_FOREACH(nc, &n->childq, child) {
+		switch (nc->node) {
+		case NODE_REFENTRY:
+		case NODE_REFNAMEDIV:
+		case NODE_REFSYNOPSISDIV:
+			later = NULL;
+			continue;
+		case NODE_APPENDIX:
+		case NODE_INDEX:
+			if (later == NULL)
+				later = nc;
+			continue;
+		default:
+			break;
+		}
+		if ((title = pnode_findfirst(nc, NODE_TITLE)) == NULL ||
+		    (title = TAILQ_FIRST(&title->childq)) == NULL ||
+		    title->node != NODE_TEXT)
+			continue;
+		if (strcasecmp(title->b, "AUTHORS") == 0 ||
+		    strcasecmp(title->b, "AUTHOR") == 0)
+			match = nc;
+		else if (strcasecmp(title->b, "NAME") == 0 ||
+		    strcasecmp(title->b, "SYNOPSIS") == 0 ||
+		    strcasecmp(title->b, "DESCRIPTION") == 0 ||
+		    strcasecmp(title->b, "RETURN VALUES") == 0 ||
+		    strcasecmp(title->b, "ENVIRONMENT") == 0 ||
+		    strcasecmp(title->b, "FILES") == 0 ||
+		    strcasecmp(title->b, "EXIT STATUS") == 0 ||
+		    strcasecmp(title->b, "EXAMPLES") == 0 ||
+		    strcasecmp(title->b, "DIAGNOSTICS") == 0 ||
+		    strcasecmp(title->b, "ERRORS") == 0 ||
+		    strcasecmp(title->b, "SEE ALSO") == 0 ||
+		    strcasecmp(title->b, "STANDARDS") == 0 ||
+		    strcasecmp(title->b, "HISTORY") == 0)
+			later = NULL;
+		else if ((strcasecmp(title->b, "CAVEATS") == 0 ||
+		    strcasecmp(title->b, "BUGS") == 0) &&
+		    later == NULL)
+			later = nc;
+	}
+
+	/*
+	 * If no AUTHORS section was found, create one from scratch,
+	 * and insert that at the place selected earlier.
+	 */
+
+	if (match == NULL) {
+		match = pnode_alloc(NULL);
+		match->node = NODE_SECTION;
+		match->flags |= NFLAG_SPC;
+		match->parent = n;
+		nc = pnode_alloc(match);
+		nc->node = NODE_TITLE;
+		nc->flags |= NFLAG_SPC;
+		nc = pnode_alloc_text(nc, "AUTHORS");
+		nc->flags |= NFLAG_SPC;
+		if (later == NULL)
+			TAILQ_INSERT_TAIL(&n->childq, match, child);
+		else
+			TAILQ_INSERT_BEFORE(later, match, child);
+	}
+
+	/*
+	 * Dump the stuff excised at the beginning
+	 * into this AUTHORS section.
+	 */
+
+	if (info != NULL)
+		TAILQ_INSERT_TAIL(&match->childq, info, child);
+	if (meta != NULL)
+		TAILQ_INSERT_TAIL(&match->childq, meta, child);
+}
+
+static void
 default_title(struct pnode *n, const char *title)
 {
 	struct pnode	*nc;
@@ -100,6 +216,8 @@ reorg_recurse(struct pnode *n)
 
 	switch (n->node) {
 	case NODE_APPENDIX:
+		if (n->parent == NULL)
+			reorg_refentry(n);
 		default_title(n, "Appendix");
 		break;
 	case NODE_CAUTION:
@@ -114,10 +232,18 @@ reorg_recurse(struct pnode *n)
 		default_title(n, "Note");
 		break;
 	case NODE_PREFACE:
+		if (n->parent == NULL)
+			reorg_refentry(n);
 		default_title(n, "Preface");
 		n->node = NODE_SECTION;
 		break;
+	case NODE_REFENTRY:
+		reorg_refentry(n);
+		break;
 	case NODE_SECTION:
+		if (n->parent == NULL)
+			reorg_refentry(n);
+		/* FALLTHROUGH */
 	case NODE_SIMPLESECT:
 		default_title(n, "Untitled");
 		break;
@@ -140,6 +266,6 @@ reorg_recurse(struct pnode *n)
 void
 ptree_reorg(struct ptree *tree)
 {
-	reorg_recurse(tree->root);
 	reorg_root(tree->root);
+	reorg_recurse(tree->root);
 }
--
 To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv

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

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-28 19:59 docbook2mdoc: move reshuffling of document info and meta nodes to the schwarze

source@mandoc.bsd.lv

Archives are clonable: git clone --mirror http://inbox.vuxu.org/mandoc-source

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.mandoc.source


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git