* docbook2mdoc: Move content from <bookinfo>, <articleinfo>,
@ 2019-04-14 12:39 schwarze
0 siblings, 0 replies; only message in thread
From: schwarze @ 2019-04-14 12:39 UTC (permalink / raw)
To: source
Log Message:
-----------
Move content from <bookinfo>, <articleinfo>, <refentryinfo>, and <refmeta>
that is not used in the prologue to the AUTHORS section.
Modified Files:
--------------
docbook2mdoc:
README
docbook2mdoc.c
statistics.c
Revision Data
-------------
Index: statistics.c
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/statistics.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -Lstatistics.c -Lstatistics.c -u -p -r1.22 -r1.23
--- statistics.c
+++ statistics.c
@@ -359,11 +359,17 @@ main(int argc, char *argv[])
table_add("author", "firstname");
table_add("author", "othername");
table_add("author", "surname");
+ table_add("authorgroup", "author");
+ table_add("authorgroup", "othercredit");
table_add("blockquote", NULL);
table_add("book", NULL);
+ table_add("bookinfo", "authorgroup");
+ table_add("bookinfo", "legalnotice");
table_add("bookinfo", "pubdate");
table_add("bookinfo", "title");
table_add("chapter", NULL);
+ table_add("citerefentry", "manvolnum");
+ table_add("citerefentry", "refentrytitle");
table_add("code", "TEXT");
table_add("computeroutput", "TEXT");
table_add("constant", "TEXT");
@@ -398,6 +404,7 @@ main(int argc, char *argv[])
table_add("listitem", NULL);
table_add("literal", "TEXT");
table_add("literallayout", NULL);
+ table_add("manvolnum", "TEXT");
table_add("markup", "TEXT");
table_add("member", "TEXT");
table_add("note", NULL);
@@ -414,12 +421,16 @@ main(int argc, char *argv[])
table_add("primary", NULL);
table_add("programlisting", NULL);
table_add("pubdate", "TEXT");
+ table_add("refentry", "refentryinfo");
table_add("refentry", "refmeta");
table_add("refentry", "refnamediv");
table_add("refentry", "refsect1");
table_add("refentry", "refsynopsisdiv");
+ table_add("refentrytitle", "TEXT");
table_add("refmeta", "manvolnum");
table_add("refmeta", "refentrytitle");
+ table_add("refmeta", "refmiscinfo");
+ table_add("refmiscinfo", "TEXT");
table_add("refname", "TEXT");
table_add("refnamediv", "refname");
table_add("refnamediv", "refpurpose");
Index: README
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/README,v
retrieving revision 1.6
retrieving revision 1.7
diff -LREADME -LREADME -u -p -r1.6 -r1.7
--- README
+++ README
@@ -69,13 +69,14 @@ include:
* Nodes with complex formatting requirements call their own,
dedicated pnode_print*() formatting functions.
- These functions are ordered roughly as follows:
+ For historical reasons, these functions are ordered roughly as follows:
1. paragraphs
2. sections
3. functions and mathematics
4. semantic markup for command line utilities
5. various semantic markup
- 6. structural markup like lists and tables
+ 6. prologue and top level structures
+ 7. structural markup like lists and tables
Such functions often contain their own loops over children and
remove the children with pnode_unlinksub() at the end. But in
some cases, it is alternatively possible to let the common loop
Index: docbook2mdoc.c
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/docbook2mdoc.c,v
retrieving revision 1.118
retrieving revision 1.119
diff -Ldocbook2mdoc.c -Ldocbook2mdoc.c -u -p -r1.118 -r1.119
--- docbook2mdoc.c
+++ docbook2mdoc.c
@@ -30,6 +30,7 @@
*/
static void pnode_print(struct format *, struct pnode *);
+static void pnode_printrefentry(struct format *, struct pnode *);
static void
@@ -196,14 +197,16 @@ pnode_printrefsynopsisdiv(struct format
* Start a hopefully-named `Sh' section.
*/
static void
-pnode_printrefsect(struct format *f, struct pnode *n)
+pnode_printsection(struct format *f, struct pnode *n)
{
struct pnode *nc, *ncc;
const char *title;
int flags, level;
- if (n->parent == NULL)
+ if (n->parent == NULL) {
+ pnode_printrefentry(f, n);
return;
+ }
level = ++f->level;
flags = ARG_SPACE;
@@ -652,7 +655,7 @@ pnode_printlink(struct format *f, struct
static void
pnode_printprologue(struct format *f, struct pnode *root)
{
- struct pnode *date, *refmeta, *name, *vol, *descr, *nc;
+ struct pnode *date, *refmeta, *name, *vol, *descr, *nc, *nn;
const char *sname;
/* Collect information. */
@@ -661,8 +664,8 @@ pnode_printprologue(struct format *f, st
date = pnode_takefirst(root, NODE_DATE);
name = vol = NULL;
- if ((refmeta = pnode_takefirst(root, NODE_REFMETA)) != NULL) {
- TAILQ_FOREACH(nc, &refmeta->childq, child) {
+ if ((refmeta = pnode_findfirst(root, NODE_REFMETA)) != NULL) {
+ TAILQ_FOREACH_SAFE(nc, &refmeta->childq, child, nn) {
switch (nc->node) {
case NODE_REFENTRYTITLE:
name = nc;
@@ -671,8 +674,9 @@ pnode_printprologue(struct format *f, st
vol = nc;
break;
default:
- break;
+ continue;
}
+ TAILQ_REMOVE(&refmeta->childq, nc, child);
}
}
@@ -715,10 +719,141 @@ pnode_printprologue(struct format *f, st
/* Clean up. */
pnode_unlink(date);
- pnode_unlink(refmeta);
+ pnode_unlink(name);
+ pnode_unlink(vol);
pnode_unlink(descr);
}
+static void
+pnode_printrefentry(struct format *f, struct pnode *n)
+{
+ struct pnode *info, *meta, *nc, *title;
+ struct pnode *match, *later;
+
+ /* Collect nodes that remained behind when writing the prologue. */
+
+ meta = NULL;
+ info = pnode_takefirst(n, NODE_BOOKINFO);
+ if (info != NULL && TAILQ_FIRST(&info->childq) == NULL) {
+ pnode_unlink(info);
+ info = NULL;
+ }
+ if (info == NULL) {
+ info = pnode_takefirst(n, NODE_REFENTRYINFO);
+ if (info != NULL && TAILQ_FIRST(&info->childq) == NULL) {
+ pnode_unlink(info);
+ info = NULL;
+ }
+ meta = pnode_takefirst(n, NODE_REFMETA);
+ if (meta != NULL && TAILQ_FIRST(&meta->childq) == NULL) {
+ pnode_unlink(meta);
+ meta = NULL;
+ }
+ }
+ if (info == NULL && meta == NULL)
+ return;
+
+ /*
+ * Find the best place to put this information.
+ * Use the last existing AUTHORS node, if any.
+ * Otherwise, put it behind all standard sections that
+ * conventionally precede AUTHORS, and also behind any
+ * non-standard sections that follow the last of these,
+ * but before the next standard section.
+ */
+
+ match = later = NULL;
+ TAILQ_FOREACH(nc, &n->childq, child) {
+ switch (nc->node) {
+ case NODE_REFENTRY:
+ case NODE_REFNAMEDIV:
+ case NODE_REFSYNOPSISDIV:
+ case NODE_PREFACE:
+ later = NULL;
+ continue;
+ case NODE_APPENDIX:
+ case NODE_INDEX:
+ if (later == NULL)
+ later = nc;
+ continue;
+ default:
+ break;
+ }
+ if ((title = pnode_findfirst(nc, NODE_TITLE)) == NULL ||
+ (title = TAILQ_FIRST(&title->childq)) == NULL ||
+ title->node != NODE_TEXT)
+ continue;
+ if (strcasecmp(title->b, "AUTHORS") == 0 ||
+ strcasecmp(title->b, "AUTHOR") == 0)
+ match = nc;
+ else if (strcasecmp(title->b, "NAME") == 0 ||
+ strcasecmp(title->b, "SYNOPSIS") == 0 ||
+ strcasecmp(title->b, "DESCRIPTION") == 0 ||
+ strcasecmp(title->b, "RETURN VALUES") == 0 ||
+ strcasecmp(title->b, "ENVIRONMENT") == 0 ||
+ strcasecmp(title->b, "FILES") == 0 ||
+ strcasecmp(title->b, "EXIT STATUS") == 0 ||
+ strcasecmp(title->b, "EXAMPLES") == 0 ||
+ strcasecmp(title->b, "DIAGNOSTICS") == 0 ||
+ strcasecmp(title->b, "ERRORS") == 0 ||
+ strcasecmp(title->b, "SEE ALSO") == 0 ||
+ strcasecmp(title->b, "STANDARDS") == 0 ||
+ strcasecmp(title->b, "HISTORY") == 0)
+ later = NULL;
+ else if ((strcasecmp(title->b, "CAVEATS") == 0 ||
+ strcasecmp(title->b, "BUGS") == 0) &&
+ later == NULL)
+ later = nc;
+ }
+
+ /*
+ * If no AUTHORS section was found, create one from scratch,
+ * and insert that at the place selected earlier.
+ */
+
+ if (match == NULL) {
+ if ((match = calloc(1, sizeof(*match))) == NULL) {
+ perror(NULL);
+ exit(1);
+ }
+ match->node = NODE_SECTION;
+ match->spc = 1;
+ match->parent = n;
+ TAILQ_INIT(&match->childq);
+ TAILQ_INIT(&match->attrq);
+ if ((nc = pnode_alloc(match)) == NULL) {
+ perror(NULL);
+ exit(1);
+ }
+ nc->node = NODE_TITLE;
+ nc->spc = 1;
+ if ((nc = pnode_alloc(nc)) == NULL) {
+ perror(NULL);
+ exit(1);
+ }
+ nc->node = NODE_TEXT;
+ if ((nc->b = strdup("AUTHORS")) == NULL) {
+ perror(NULL);
+ exit(1);
+ }
+ nc->spc = 1;
+ if (later == NULL)
+ TAILQ_INSERT_TAIL(&n->childq, match, child);
+ else
+ TAILQ_INSERT_BEFORE(later, match, child);
+ }
+
+ /*
+ * Dump the stuff excised at the beginning
+ * into this AUTHORS section.
+ */
+
+ if (info != NULL)
+ TAILQ_INSERT_TAIL(&match->childq, info, child);
+ if (meta != NULL)
+ TAILQ_INSERT_TAIL(&match->childq, meta, child);
+}
+
/*
* We can have multiple <term> elements within a <varlistentry>, which
* we should comma-separate as list headers.
@@ -1046,9 +1181,8 @@ pnode_print(struct format *f, struct pno
case NODE_SYSTEMITEM:
pnode_printsystemitem(f, n);
break;
- case NODE_REFENTRYINFO:
- /* Suppress. */
- pnode_unlinksub(n);
+ case NODE_REFENTRY:
+ pnode_printrefentry(f, n);
break;
case NODE_REFNAME:
/* More often, these appear inside NODE_REFNAMEDIV. */
@@ -1071,7 +1205,7 @@ pnode_print(struct format *f, struct pno
case NODE_TIP:
case NODE_CAUTION:
case NODE_WARNING:
- pnode_printrefsect(f, n);
+ pnode_printsection(f, n);
break;
case NODE_REPLACEABLE:
macro_open(f, "Ar");
--
To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2019-04-14 12:39 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-14 12:39 docbook2mdoc: Move content from <bookinfo>, <articleinfo>, 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).