From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from localhost (fantadrom.bsd.lv [local]) by fantadrom.bsd.lv (OpenSMTPD) with ESMTPA id 201f3ca1 for ; Sun, 28 Apr 2019 12:11:54 -0500 (EST) Date: Sun, 28 Apr 2019 12:11:54 -0500 (EST) X-Mailinglist: mandoc-source Reply-To: source@mandoc.bsd.lv MIME-Version: 1.0 From: schwarze@mandoc.bsd.lv To: source@mandoc.bsd.lv Subject: docbook2mdoc: Start a reorg module, to edit and move around nodes X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Message-ID: 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 + * + * 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 + * + * 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