source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mandoc.bsd.lv
To: source@mandoc.bsd.lv
Subject: docbook2mdoc: Improve formatting of <arg> and <group>: * Respect the
Date: Sat, 13 Apr 2019 10:14:02 -0500 (EST)	[thread overview]
Message-ID: <e3fdc4df560164da@fantadrom.bsd.lv> (raw)

Log Message:
-----------
Improve formatting of <arg> and <group>:
* Respect the repeat attribute even if there is a child macro.
* Mark up all children of <group>, not just the first.
* Implement the repeat attribute for <group>.
* Do the proper was_impl dance for <group>.

Modified Files:
--------------
    docbook2mdoc:
        docbook2mdoc.c

Revision Data
-------------
Index: docbook2mdoc.c
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/docbook2mdoc.c,v
retrieving revision 1.116
retrieving revision 1.117
diff -Ldocbook2mdoc.c -Ldocbook2mdoc.c -u -p -r1.116 -r1.117
--- docbook2mdoc.c
+++ docbook2mdoc.c
@@ -442,14 +442,13 @@ pnode_printarg(struct format *f, struct 
 			f->flags |= FMT_IMPL;
 		}
 	}
-
 	TAILQ_FOREACH(nc, &n->childq, child) {
 		if (nc->node == NODE_TEXT)
 			macro_open(f, "Ar");
 		pnode_print(f, nc);
-		if (isrep && nc->node == NODE_TEXT)
-			macro_addarg(f, "...", ARG_SPACE);
 	}
+	if (isrep && f->linestate == LINE_MACRO)
+		macro_addarg(f, "...", ARG_SPACE);
 	if (isop) {
 		if (was_impl)
 			macro_open(f, "Oc");
@@ -462,53 +461,56 @@ pnode_printarg(struct format *f, struct 
 static void
 pnode_printgroup(struct format *f, struct pnode *n)
 {
-	struct pnode	*nc, *nn;
+	struct pnode	*nc;
 	struct pattr	*a;
-	int		 isop, sv;
+	int		 bar, isop, isrep, was_impl;
 
 	isop = 1;
-	TAILQ_FOREACH(a, &n->attrq, child)
+	isrep = was_impl = 0;
+	TAILQ_FOREACH(a, &n->attrq, child) {
 		if (a->key == ATTRKEY_CHOICE &&
-		    (a->val == ATTRVAL_PLAIN || a->val == ATTRVAL_REQ)) {
+		    (a->val == ATTRVAL_PLAIN || a->val == ATTRVAL_REQ))
 			isop = 0;
-			break;
+		else if (a->key == ATTRKEY_REP && a->val == ATTRVAL_REPEAT)
+			isrep = 1;
+	}
+	if (isop) {
+		if (f->flags & FMT_IMPL) {
+			was_impl = 1;
+			macro_open(f, "Oo");
+		} else {
+			macro_open(f, "Op");
+			f->flags |= FMT_IMPL;
 		}
-
-	/*
-	 * Make sure we're on a macro line.
-	 * This will prevent pnode_print() for putting us on a
-	 * subsequent line.
-	 */
-	sv = f->linestate == LINE_NEW;
-	if (isop)
-		macro_open(f, "Op");
-	else if (sv)
-		macro_open(f, "No");
-	f->flags |= FMT_IMPL;
-
-	/*
-	 * Keep on printing text separated by the vertical bar as long
-	 * as we're within the same origin node as the group.
-	 * This is kind of a nightmare.
-	 * Eh, DocBook...
-	 * FIXME: if there's a "Fl", we don't cut off the leading "-"
-	 * like we do in pnode_print().
-	 */
+	} else if (isrep) {
+		if (f->flags & FMT_IMPL) {
+			was_impl = 1;
+			macro_open(f, "Bro");
+		} else {
+			macro_open(f, "Brq");
+			f->flags |= FMT_IMPL;
+		}
+	}
+	bar = 0;
 	TAILQ_FOREACH(nc, &n->childq, child) {
-		pnode_print(f, nc);
-		nn = TAILQ_NEXT(nc, child);
-		while (nn != NULL) {
-			if (nc->node != nn->node)
-				break;
+		if (bar && f->linestate == LINE_MACRO)
 			macro_addarg(f, "|", ARG_SPACE);
-			macro_addnode(f, nn, ARG_SPACE);
-			nc = nn;
-			nn = TAILQ_NEXT(nn, child);
-		}
+		pnode_print(f, nc);
+		bar = 1;
+	}
+	if (isop) {
+		if (was_impl)
+			macro_open(f, "Oc");
+		else
+			f->flags &= ~FMT_IMPL;
+	} else if (isrep) {
+		if (was_impl)
+			macro_open(f, "Brc");
+		else
+			f->flags &= ~FMT_IMPL;
 	}
-	if (sv)
-		macro_close(f);
-	f->flags &= ~FMT_IMPL;
+	if (isrep && f->linestate == LINE_MACRO)
+		macro_addarg(f, "...", ARG_SPACE);
 	pnode_unlinksub(n);
 }
 
--
 To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv

                 reply	other threads:[~2019-04-13 15:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=e3fdc4df560164da@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).