source@mandoc.bsd.lv
 help / color / Atom feed
* docbook2mdoc: move default section titles to the reorg module
@ 2019-04-28 19:05 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2019-04-28 19:05 UTC (permalink / raw)
  To: source

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

^ 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:05 docbook2mdoc: move default section titles to the reorg module 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