From: schwarze@mandoc.bsd.lv
To: source@mandoc.bsd.lv
Subject: docbook2mdoc: Start a reorg module, to edit and move around nodes
Date: Sun, 28 Apr 2019 12:10:37 -0500 (EST) [thread overview]
Message-ID: <e3feb1979abe4bd0@fantadrom.bsd.lv> (raw)
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
next reply other threads:[~2019-04-28 17:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-28 17:10 schwarze [this message]
2019-04-28 17:11 schwarze
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=e3feb1979abe4bd0@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).