From: schwarze@mandoc.bsd.lv
To: source@mandoc.bsd.lv
Subject: docbook2mdoc: Move printing of text nodes out of pnode_print() into a
Date: Sun, 7 Apr 2019 08:16:52 -0500 (EST) [thread overview]
Message-ID: <e3fd6f588dcc8b2d@fantadrom.bsd.lv> (raw)
Log Message:
-----------
Move printing of text nodes out of pnode_print() into a dedicated
function, like for all other node types that require a substantial
amount of code. No functional change.
Modified Files:
--------------
docbook2mdoc:
docbook2mdoc.c
Revision Data
-------------
Index: docbook2mdoc.c
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/docbook2mdoc.c,v
retrieving revision 1.92
retrieving revision 1.93
diff -Ldocbook2mdoc.c -Ldocbook2mdoc.c -u -p -r1.92 -r1.93
--- docbook2mdoc.c
+++ docbook2mdoc.c
@@ -32,6 +32,59 @@ static void pnode_print(struct format *
static void
+pnode_printtext(struct format *f, struct pnode *n)
+{
+ char *cp;
+ char last;
+
+ if (n->bsz == 0) {
+ assert(n->real < n->b);
+ return;
+ }
+
+ if (f->linestate == LINE_NEW) {
+ last = '\n';
+ f->linestate = LINE_TEXT;
+ } else {
+ last = ' ';
+ if (n->spc || f->linestate == LINE_MACRO)
+ putchar(' ');
+ }
+
+ if (n->node == NODE_ESCAPE) {
+ fputs(n->b, stdout);
+ return;
+ }
+
+ /*
+ * Remove the prefix '-' from <option> elements
+ * because the arguments of .Fl macros do not need it.
+ */
+
+ cp = n->b;
+ if (n->parent != NULL && n->parent->node == NODE_OPTION && *cp == '-')
+ cp++;
+
+ /*
+ * Print the text, skipping whitespace on new lines,
+ * escaping control characters on new lines,
+ * and escaping backslashes.
+ */
+
+ for (; *cp != '\0'; cp++) {
+ if (last == '\n') {
+ if (isspace((unsigned char)*cp))
+ continue;
+ if (*cp == '\'' || *cp == '.')
+ fputs("\\&", stdout);
+ }
+ putchar(last = *cp);
+ if (last == '\\')
+ putchar('e');
+ }
+}
+
+static void
pnode_printpara(struct format *p, struct pnode *pn)
{
struct pnode *pp;
@@ -635,8 +688,6 @@ pnode_print(struct format *p, struct pno
{
struct pnode *pp;
const char *ccp;
- char *cp;
- int last;
enum linestate sv;
if (pn == NULL)
@@ -691,13 +742,6 @@ pnode_print(struct format *p, struct pno
case NODE_ERRORNAME:
macro_open(p, "Er");
break;
- case NODE_ESCAPE:
- if (p->linestate == LINE_NEW)
- p->linestate = LINE_TEXT;
- else if (pn->spc || p->linestate == LINE_MACRO)
- putchar(' ');
- fputs(pn->b, stdout);
- break;
case NODE_FILENAME:
macro_open(p, "Pa");
break;
@@ -818,47 +862,8 @@ pnode_print(struct format *p, struct pno
macro_open(p, "Ic");
break;
case NODE_TEXT:
- if (pn->bsz == 0) {
- assert(pn->real != pn->b);
- break;
- }
- if (p->linestate == LINE_NEW)
- p->linestate = LINE_TEXT;
- else if (pn->spc || p->linestate == LINE_MACRO)
- putchar(' ');
-
- /*
- * Output all characters, squeezing out whitespace
- * between newlines.
- * XXX: all whitespace, including tabs (?).
- * Remember to escape control characters and escapes.
- */
- cp = pn->b;
-
- /*
- * There's often a superfluous "-" in its <option> tags
- * before the actual flags themselves.
- * "Fl" does this for us, so remove it.
- */
- if (pn->parent != NULL &&
- pn->parent->node == NODE_OPTION &&
- *cp == '-')
- cp++;
- for (last = '\n'; *cp != '\0'; ) {
- if (last == '\n') {
- /* Consume all whitespace. */
- if (isspace((unsigned char)*cp)) {
- while (isspace((unsigned char)*cp))
- cp++;
- continue;
- } else if (*cp == '\'' || *cp == '.')
- fputs("\\&", stdout);
- }
- putchar(last = *cp++);
- /* If we're a character escape, escape us. */
- if (last == '\\')
- putchar('e');
- }
+ case NODE_ESCAPE:
+ pnode_printtext(p, pn);
break;
case NODE_TGROUP:
pnode_printtgroup(p, pn);
--
To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv
reply other threads:[~2019-04-07 13:16 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=e3fd6f588dcc8b2d@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).