source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* docbook2mdoc: Avoid reckless use of low-level stdio output functions
@ 2019-03-24 21:00 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2019-03-24 21:00 UTC (permalink / raw)
  To: source

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-03-24 21:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-24 21:00 docbook2mdoc: Avoid reckless use of low-level stdio output functions 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).