* docbook2mdoc: Start a reorg module, to edit and move around nodes
@ 2019-04-28 17:10 schwarze
0 siblings, 0 replies; 2+ messages in thread
From: schwarze @ 2019-04-28 17:10 UTC (permalink / raw)
To: source
Log Message:
-----------
Start a reorg module, to edit and move around nodes between parsing
and formatting. This helps because using queue macros is prone to
bugs, but inspecting the resulting trees with a C debugger is quite
hard. Using -T tree is much easier.
Modified Files:
--------------
docbook2mdoc:
Makefile
docbook2mdoc.c
main.c
Revision Data
-------------
Index: main.c
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/main.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -Lmain.c -Lmain.c -u -p -r1.7 -r1.8
--- main.c
+++ main.c
@@ -22,6 +22,7 @@
#include "node.h"
#include "parse.h"
+#include "reorg.h"
#include "format.h"
/*
@@ -96,6 +97,7 @@ main(int argc, char *argv[])
parser = parse_alloc(warn);
tree = parse_file(parser, fd, fname);
+ ptree_reorg(tree);
rc = tree->flags & TREE_ERROR ? 3 : tree->flags & TREE_WARN ? 2 : 0;
/* Format. */
Index: Makefile
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/Makefile,v
retrieving revision 1.27
retrieving revision 1.28
diff -LMakefile -LMakefile -u -p -r1.27 -r1.28
--- Makefile
+++ Makefile
@@ -3,9 +3,9 @@ CFLAGS += -g -W -Wall -Wstrict-prototype
WWWPREFIX = /var/www/vhosts/mdocml.bsd.lv/htdocs/docbook2mdoc
PREFIX = /usr/local
-HEADS = xmalloc.h node.h parse.h macro.h format.h
-SRCS = xmalloc.c node.c parse.c macro.c docbook2mdoc.c tree.c main.c
-OBJS = xmalloc.o node.o parse.o macro.o docbook2mdoc.o tree.o main.o
+HEADS = xmalloc.h node.h parse.h reorg.h macro.h format.h
+SRCS = xmalloc.c node.c parse.c reorg.c macro.c docbook2mdoc.c tree.c main.c
+OBJS = xmalloc.o node.o parse.o reorg.o macro.o docbook2mdoc.o tree.o main.o
DISTFILES = Makefile NEWS docbook2mdoc.1
all: docbook2mdoc
@@ -43,6 +43,7 @@ docbook2mdoc-$(VERSION).tgz:
xmalloc.o: xmalloc.h
node.o: xmalloc.h node.h
parse.o: xmalloc.h node.h parse.h
+reorg.o: node.h reorg.h
macro.o: node.h macro.h
docbook2mdoc.o: xmalloc.h node.h macro.h format.h
tree.o: node.h format.h
Index: docbook2mdoc.c
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/docbook2mdoc.c,v
retrieving revision 1.140
retrieving revision 1.141
diff -Ldocbook2mdoc.c -Ldocbook2mdoc.c -u -p -r1.140 -r1.141
--- docbook2mdoc.c
+++ docbook2mdoc.c
@@ -729,73 +729,34 @@ pnode_printolink(struct format *f, struc
static void
pnode_printprologue(struct format *f, struct pnode *root)
{
- struct pnode *date, *refmeta, *name, *vol, *descr, *nc, *nn;
- const char *sname;
+ struct pnode *name, *nc;
- /* Collect information. */
-
- if ((date = pnode_takefirst(root, NODE_PUBDATE)) == NULL)
- date = pnode_takefirst(root, NODE_DATE);
-
- name = vol = NULL;
- if ((refmeta = pnode_findfirst(root, NODE_REFMETA)) != NULL) {
- TAILQ_FOREACH_SAFE(nc, &refmeta->childq, child, nn) {
- switch (nc->node) {
- case NODE_REFENTRYTITLE:
- name = nc;
- break;
- case NODE_MANVOLNUM:
- vol = nc;
- break;
- default:
- continue;
- }
- TAILQ_REMOVE(&refmeta->childq, nc, child);
- }
- }
-
- 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);
+ nc = TAILQ_FIRST(&root->childq);
+ assert(nc->node == NODE_DATE);
+ macro_nodeline(f, "Dd", nc, 0);
+ pnode_unlink(nc);
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
- 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);
+ name = TAILQ_FIRST(&root->childq);
+ assert(name->node == NODE_REFENTRYTITLE);
+ macro_addnode(f, name, ARG_SPACE | ARG_SINGLE | ARG_UPPER);
+ TAILQ_REMOVE(&root->childq, name, child);
+ name->parent = NULL;
+ nc = TAILQ_FIRST(&root->childq);
+ assert (nc->node == NODE_MANVOLNUM);
+ macro_addnode(f, nc, ARG_SPACE | ARG_SINGLE);
+ pnode_unlink(nc);
macro_line(f, "Os");
- if (descr != NULL) {
+ nc = TAILQ_FIRST(&root->childq);
+ if (nc != NULL && nc->node == NODE_TITLE) {
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);
+ macro_nodeline(f, "Nm", name, ARG_SINGLE);
+ macro_nodeline(f, "Nd", nc, 0);
+ pnode_unlink(nc);
}
-
- /* Clean up. */
-
- pnode_unlink(date);
pnode_unlink(name);
- pnode_unlink(vol);
- pnode_unlink(descr);
f->parastate = PARA_HAVE;
}
--
To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv
^ permalink raw reply [flat|nested] 2+ messages in thread
* docbook2mdoc: Start a reorg module, to edit and move around nodes
@ 2019-04-28 17:11 schwarze
0 siblings, 0 replies; 2+ messages in thread
From: schwarze @ 2019-04-28 17:11 UTC (permalink / raw)
To: source
Log Message:
-----------
Start a reorg module, to edit and move around nodes between parsing
and formatting. This helps because using queue macros is prone to
bugs, but inspecting the resulting trees with a C debugger is quite
hard. Using -T tree is much easier.
Added Files:
-----------
docbook2mdoc:
reorg.c
reorg.h
Revision Data
-------------
--- /dev/null
+++ reorg.h
@@ -0,0 +1,22 @@
+/* $Id: reorg.h,v 1.1 2019/04/28 17:11:53 schwarze Exp $ */
+/*
+ * Copyright (c) 2019 Ingo Schwarze <schwarze@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * The interface of the tree reorganizer.
+ */
+
+void ptree_reorg(struct ptree *);
--- /dev/null
+++ reorg.c
@@ -0,0 +1,72 @@
+/* $Id: reorg.c,v 1.1 2019/04/28 17:11:53 schwarze Exp $ */
+/*
+ * Copyright (c) 2019 Ingo Schwarze <schwarze@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "node.h"
+#include "reorg.h"
+
+/*
+ * The implementation of the tree reorganizer.
+ */
+
+void
+ptree_reorg(struct ptree *tree)
+{
+ struct pnode *date, *descr, *name, *root, *vol, *nc;
+
+ if ((root = tree->root) == NULL)
+ return;
+
+ /* Collect prologue information. */
+
+ if ((date = pnode_takefirst(root, NODE_PUBDATE)) == NULL &&
+ (date = pnode_takefirst(root, NODE_DATE)) == NULL) {
+ date = pnode_alloc(NULL);
+ pnode_alloc_text(date, "$Mdocdate" "$");
+ }
+ date->node = NODE_DATE;
+ date->parent = root;
+
+ name = vol = NULL;
+ if ((nc = pnode_findfirst(root, NODE_REFMETA)) != NULL) {
+ name = pnode_takefirst(nc, NODE_REFENTRYTITLE);
+ vol = pnode_takefirst(nc, NODE_MANVOLNUM);
+ }
+ if (name == NULL) {
+ name = pnode_alloc(NULL);
+ name->node = NODE_REFENTRYTITLE;
+ name->parent = root;
+ pnode_alloc_text(name,
+ pnode_getattr_raw(root, ATTRKEY_ID, "UNKNOWN"));
+ }
+ if (vol == NULL) {
+ vol = pnode_alloc(NULL);
+ vol->node = NODE_MANVOLNUM;
+ vol->parent = root;
+ pnode_alloc_text(vol, "1");
+ }
+
+ /* Insert prologue information at the beginning. */
+
+ 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)) != NULL)
+ TAILQ_INSERT_HEAD(&root->childq, descr, child);
+ TAILQ_INSERT_HEAD(&root->childq, vol, child);
+ TAILQ_INSERT_HEAD(&root->childq, name, child);
+ TAILQ_INSERT_HEAD(&root->childq, date, child);
+}
--
To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-04-28 17:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-28 17:10 docbook2mdoc: Start a reorg module, to edit and move around nodes schwarze
2019-04-28 17:11 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).