source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mandoc.bsd.lv
To: source@mandoc.bsd.lv
Subject: docbook2mdoc: move default section titles to the reorg module
Date: Sun, 28 Apr 2019 14:05:41 -0500 (EST)	[thread overview]
Message-ID: <e3feb2c6f49d8576@fantadrom.bsd.lv> (raw)

Log Message:
-----------
move default section titles 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.141
retrieving revision 1.142
diff -Ldocbook2mdoc.c -Ldocbook2mdoc.c -u -p -r1.141 -r1.142
--- docbook2mdoc.c
+++ docbook2mdoc.c
@@ -194,7 +194,6 @@ static void
 pnode_printsection(struct format *f, struct pnode *n)
 {
 	struct pnode	*nc, *ncc;
-	const char	*title;
 	int		 flags, level;
 
 	if (n->parent == NULL) {
@@ -205,56 +204,27 @@ pnode_printsection(struct format *f, str
 	level = ++f->level;
 	flags = ARG_SPACE;
 	switch (n->node) {
-	case NODE_PREFACE:
 	case NODE_SECTION:
 	case NODE_APPENDIX:
 		if (level == 1)
 			flags |= ARG_UPPER;
 		break;
 	case NODE_SIMPLESECT:
-	case NODE_LEGALNOTICE:
 		if (level < 2)
 			level = 2;
 		break;
-	default:
+	case NODE_NOTE:
 		if (level < 3)
 			level = 3;
 		break;
+	default:
+		abort();
 	}
 
 	TAILQ_FOREACH(nc, &n->childq, child)
 		if (nc->node == NODE_TITLE)
 			break;
 
-	if (nc == NULL) {
-		switch (n->node) {
-		case NODE_PREFACE:
-			title = "Preface";
-			break;
-		case NODE_APPENDIX:
-			title = "Appendix";
-			break;
-		case NODE_LEGALNOTICE:
-			title = "Legal Notice";
-			break;
-		case NODE_CAUTION:
-			title = "Caution";
-			break;
-		case NODE_NOTE:
-			title = "Note";
-			break;
-		case NODE_TIP:
-			title = "Tip";
-			break;
-		case NODE_WARNING:
-			title = "Warning";
-			break;
-		default:
-			title = "Unknown";
-			break;
-		}
-	}
-
 	switch (level) {
 	case 1:
 		macro_close(f);
@@ -272,11 +242,7 @@ pnode_printsection(struct format *f, str
 		macro_open(f, "Sy");
 		break;
 	}
-
-	if (nc != NULL)
-		macro_addnode(f, nc, flags);
-	else
-		macro_addarg(f, title, flags | ARG_QUOTED);
+	macro_addnode(f, nc, flags);
 	macro_close(f);
 
 	/*
@@ -806,7 +772,6 @@ pnode_printrefentry(struct format *f, st
 		case NODE_REFENTRY:
 		case NODE_REFNAMEDIV:
 		case NODE_REFSYNOPSISDIV:
-		case NODE_PREFACE:
 			later = NULL;
 			continue;
 		case NODE_APPENDIX:
@@ -1277,15 +1242,10 @@ pnode_print(struct format *f, struct pno
 	case NODE_REFSYNOPSISDIV:
 		pnode_printrefsynopsisdiv(f, n);
 		break;
-	case NODE_PREFACE:
 	case NODE_SECTION:
 	case NODE_SIMPLESECT:
 	case NODE_APPENDIX:
-	case NODE_LEGALNOTICE:
 	case NODE_NOTE:
-	case NODE_TIP:
-	case NODE_CAUTION:
-	case NODE_WARNING:
 		pnode_printsection(f, n);
 		break;
 	case NODE_REPLACEABLE:
@@ -1337,6 +1297,12 @@ pnode_print(struct format *f, struct pno
 	case NODE_XREF:
 		pnode_printxref(f, n);
 		break;
+	case NODE_CAUTION:
+	case NODE_LEGALNOTICE:
+	case NODE_PREFACE:
+	case NODE_TIP:
+	case NODE_WARNING:
+		abort();
 	default:
 		break;
 	}
@@ -1421,14 +1387,10 @@ pnode_print(struct format *f, struct pno
 		} else
 			f->flags &= ~FMT_IMPL;
 		break;
-	case NODE_PREFACE:
 	case NODE_SECTION:
+	case NODE_SIMPLESECT:
 	case NODE_APPENDIX:
-	case NODE_LEGALNOTICE:
 	case NODE_NOTE:
-	case NODE_TIP:
-	case NODE_CAUTION:
-	case NODE_WARNING:
 		f->level--;
 		break;
 	case NODE_BLOCKQUOTE:
Index: reorg.c
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/reorg.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -Lreorg.c -Lreorg.c -u -p -r1.1 -r1.2
--- reorg.c
+++ reorg.c
@@ -22,12 +22,12 @@
  * The implementation of the tree reorganizer.
  */
 
-void
-ptree_reorg(struct ptree *tree)
+static void
+reorg_root(struct pnode *root)
 {
-	struct pnode	*date, *descr, *name, *root, *vol, *nc;
+	struct pnode	*date, *descr, *name, *vol, *nc;
 
-	if ((root = tree->root) == NULL)
+	if (root == NULL)
 		return;
 
 	/* Collect prologue information. */
@@ -69,4 +69,77 @@ ptree_reorg(struct ptree *tree)
 	TAILQ_INSERT_HEAD(&root->childq, vol, child);
 	TAILQ_INSERT_HEAD(&root->childq, name, child);
 	TAILQ_INSERT_HEAD(&root->childq, date, child);
+}
+
+static void
+default_title(struct pnode *n, const char *title)
+{
+	struct pnode	*nc;
+
+	if (n->parent == NULL)
+		return;
+
+	TAILQ_FOREACH(nc, &n->childq, child)
+		if (nc->node == NODE_TITLE)
+			return;
+
+	nc = pnode_alloc(NULL);
+	nc->node = NODE_TITLE;
+	nc->parent = n;
+	TAILQ_INSERT_HEAD(&n->childq, nc, child);
+	pnode_alloc_text(nc, title);
+}
+
+static void
+reorg_recurse(struct pnode *n)
+{
+	struct pnode	*nc;
+
+	if (n == NULL)
+		return;
+
+	switch (n->node) {
+	case NODE_APPENDIX:
+		default_title(n, "Appendix");
+		break;
+	case NODE_CAUTION:
+		default_title(n, "Caution");
+		n->node = NODE_NOTE;
+		break;
+	case NODE_LEGALNOTICE:
+		default_title(n, "Legal Notice");
+		n->node = NODE_SIMPLESECT;
+		break;
+	case NODE_NOTE:
+		default_title(n, "Note");
+		break;
+	case NODE_PREFACE:
+		default_title(n, "Preface");
+		n->node = NODE_SECTION;
+		break;
+	case NODE_SECTION:
+	case NODE_SIMPLESECT:
+		default_title(n, "Untitled");
+		break;
+	case NODE_TIP:
+		default_title(n, "Tip");
+		n->node = NODE_NOTE;
+		break;
+	case NODE_WARNING:
+		default_title(n, "Warning");
+		n->node = NODE_NOTE;
+		break;
+	default:
+		break;
+	}
+
+	TAILQ_FOREACH(nc, &n->childq, child)
+		reorg_recurse(nc);
+}
+
+void
+ptree_reorg(struct ptree *tree)
+{
+	reorg_recurse(tree->root);
+	reorg_root(tree->root);
 }
--
 To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv

                 reply	other threads:[~2019-04-28 19:05 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e3feb2c6f49d8576@fantadrom.bsd.lv \
    --to=schwarze@mandoc.bsd.lv \
    --cc=source@mandoc.bsd.lv \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).