source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mandoc.bsd.lv
To: source@mandoc.bsd.lv
Subject: docbook2mdoc: Avoid reckless use of low-level stdio output functions
Date: Sun, 24 Mar 2019 16:00:41 -0500 (EST)	[thread overview]
Message-ID: <e3fcad1401efbb71@fantadrom.bsd.lv> (raw)

Log Message:
-----------
Avoid reckless use of low-level stdio output functions like putchar(3),
puts(3), and fputs(3) in high-level formatting code.  For clarity 
and robustness, be explicit whether we are printing to a text line
with print_text() or to a macro line with macro_addarg().

While here, fix NODE_REFNAME formatting which i broke previously.

For now, leave MathML to eqn(7) translation alone.  Usually, that 
happens in .EQ blocks, i.e. writing text lines.  But it can also
happen in inline ($$) context on macro lines.  That is certainly
very fragile and will often fail especially for non-trivial formulae,
but switching to print_text() would break it even more.  So postpone
repairs until i come round to work on equation formatting for real.

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

Revision Data
-------------
Index: docbook2mdoc.c
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/docbook2mdoc.c,v
retrieving revision 1.69
retrieving revision 1.70
diff -Ldocbook2mdoc.c -Ldocbook2mdoc.c -u -p -r1.69 -r1.70
--- docbook2mdoc.c
+++ docbook2mdoc.c
@@ -711,6 +711,23 @@ macro_closepunct(struct parse *p, struct
 }
 
 static void
+print_text(struct parse *p, const char *word)
+{
+	switch (p->linestate) {
+	case LINE_NEW:
+		break;
+	case LINE_TEXT:
+		putchar(' ');
+		break;
+	case LINE_MACRO:
+		macro_close(p);
+		break;
+	}
+	fputs(word, stdout);
+	p->linestate = LINE_TEXT;
+}
+
+static void
 pnode_printpara(struct parse *p, struct pnode *pn)
 {
 	struct pnode	*pp;
@@ -1109,7 +1126,7 @@ pnode_printprologue(struct parse *p, str
 
 	if (p->flags & PARSE_EQN) {
 		macro_line(p, "EQ");
-		puts("delim $$");
+		print_text(p, "delim $$");
 		macro_line(p, "EN");
 	}
 }
@@ -1129,7 +1146,7 @@ pnode_printvarlistentry(struct parse *p,
 		if (pp->node != NODE_TERM)
 			continue;
 		if ( ! first)
-			putchar(',');
+			macro_addarg(p, ",", MACROLINE_NOWS);
 		pnode_print(p, pp);
 		first = 0;
 	}
@@ -1273,10 +1290,7 @@ pnode_print(struct parse *p, struct pnod
 		macro_open(p, "Dv");
 		break;
 	case NODE_EDITOR:
-		if (p->linestate != LINE_NEW)
-			putchar('\n');
-		puts("editor:");
-		p->linestate = LINE_TEXT;
+		print_text(p, "editor:");
 		macro_open(p, "An");
 		break;
 	case NODE_EMAIL:
@@ -1391,7 +1405,8 @@ pnode_print(struct parse *p, struct pnod
 		break;
 	case NODE_REFNAME:
 		/* Suppress non-text children... */
-		macro_nodeline(p, "Nm", pn);
+		macro_open(p, "Nm");
+		macro_addnode(p, pn, 0);
 		pnode_unlinksub(pn);
 		break;
 	case NODE_REFNAMEDIV:
@@ -1566,7 +1581,7 @@ pnode_print(struct parse *p, struct pnod
 		    pn->parent->node == NODE_REFNAMEDIV &&
 		    TAILQ_NEXT(pn, child) != NULL &&
 		    TAILQ_NEXT(pn, child)->node == NODE_REFNAME)
-			fputs(" ,", stdout);
+			macro_addarg(p, ",", 0);
 		if (sv == LINE_NEW)
 			macro_close(p);
 		break;
--
 To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv

                 reply	other threads:[~2019-03-24 21:00 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=e3fcad1401efbb71@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).