source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* docbook2mdoc: Move printing of text nodes out of pnode_print() into a
@ 2019-04-07 13:16 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2019-04-07 13:16 UTC (permalink / raw)
  To: source

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

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

only message in thread, other threads:[~2019-04-07 13:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-07 13:16 docbook2mdoc: Move printing of text nodes out of pnode_print() into a 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).