source@mandoc.bsd.lv
 help / color / mirror / Atom feed
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:11:54 -0500 (EST)	[thread overview]
Message-ID: <e3feb1bc3ae27b9e@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.

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

             reply	other threads:[~2019-04-28 17:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-28 17:11 schwarze [this message]
  -- strict thread matches above, loose matches on Subject: below --
2019-04-28 17:10 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=e3feb1bc3ae27b9e@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).