tech@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: Ingo Schwarze <schwarze@usta.de>
To: Stephen Gregoratto <dev@sgregoratto.me>
Cc: tech@mandoc.bsd.lv
Subject: Re: [PATCH docbook2mdoc] Add markup, computeroutput (WIP)
Date: Fri, 12 Apr 2019 10:55:46 +0200	[thread overview]
Message-ID: <20190412085546.GB89835@athene.usta.de> (raw)
In-Reply-To: <20190412055748.umynmdcylrtp5pbs@BlackBox>

Hi Stephen,

Stephen Gregoratto wrote on Fri, Apr 12, 2019 at 03:57:48PM +1000:

> The only problem

Unfortunately, that's by far not the only remaining problem.  ;-/

> is that using macro_open(f, "Ic") doesn't escape the markup like
> pnode_printtext does (worst case would format as: .Ic Pp). 

I guess you meant like macro_addarg() does.
Anyway, it does now, see the commit below.

Yours,
  Ingo


Log Message:
-----------
Move escaping of control characters and backslashes on text lines 
to print_text() such that it works for all text lines.

In pnode_printtext(), use macro_addarg() or print_text() to get the
required escaping.  On the other hand, there is no need to handle
linefeed characters because these can no longer occur in text nodes.

Stephen Gregoratto <dev at sgregoratto dot me>
reported that escaping was incomplete in some cases.

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

Revision Data
-------------
Index: macro.c
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/macro.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -Lmacro.c -Lmacro.c -u -p -r1.9 -r1.10
--- macro.c
+++ macro.c
@@ -212,9 +212,12 @@ macro_nodeline(struct format *f, const c
  * line otherwise.  The flag ARG_SPACE inserts spaces between words.
  */
 void
-print_text(struct format *f, const char *word, int flags) {
+print_text(struct format *f, const char *word, int flags)
+{
 	switch (f->linestate) {
 	case LINE_NEW:
+		if (*word == '.' || *word == '\'')
+			fputs("\\&", stdout);
 		break;
 	case LINE_TEXT:
 		if (flags & ARG_SPACE)
@@ -224,7 +227,11 @@ print_text(struct format *f, const char 
 		macro_close(f);
 		break;
 	}
-	fputs(word, stdout);
+	while (*word != '\0') {
+		putchar(*word);
+		if (*word++ == '\\')
+			putchar('e');
+	}
 	f->linestate = LINE_TEXT;
 	f->flags = 0;
 }
Index: docbook2mdoc.c
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/docbook2mdoc.c,v
retrieving revision 1.106
retrieving revision 1.107
diff -Ldocbook2mdoc.c -Ldocbook2mdoc.c -u -p -r1.106 -r1.107
--- docbook2mdoc.c
+++ docbook2mdoc.c
@@ -38,11 +38,10 @@ pnode_printtext(struct format *f, struct
 	struct pnode	*nn;
 	char		*cp;
 	int		 accept_arg;
-	char		 last;
 
 	cp = n->b;
 	accept_arg = f->flags & FMT_ARG;
-	if (f->linestate == LINE_MACRO && n->spc == 0 && !accept_arg) {
+	if (f->linestate == LINE_MACRO && !n->spc && !accept_arg) {
 		for (;;) {
 			if (*cp == '\0')
 				return;
@@ -80,33 +79,28 @@ pnode_printtext(struct format *f, struct
 	}
 
 	switch (f->linestate) {
+	case LINE_NEW:
+		break;
 	case LINE_TEXT:
 		if (n->spc) {
-			if (n->node == NODE_TEXT) {
-				putchar('\n');
-				last = '\n';
-				break;
-			}
-			putchar(' ');
+			if (n->node == NODE_TEXT)
+				macro_close(f);
+			else
+				putchar(' ');
 		}
-		last = ' ';
 		break;
 	case LINE_MACRO:
-		if (accept_arg) {
+		if (accept_arg)
 			putchar(' ');
-			last = ' ';
-			break;
-		}
-		macro_close(f);
-		/* FALLTHROUGH */
-	case LINE_NEW:
-		f->linestate = LINE_TEXT;
-		last = '\n';
+		else
+			macro_close(f);
 		break;
 	}
 
 	if (n->node == NODE_ESCAPE) {
 		fputs(n->b, stdout);
+		if (f->linestate == LINE_NEW)
+			f->linestate = LINE_TEXT;
 		return;
 	}
 
@@ -118,23 +112,10 @@ pnode_printtext(struct format *f, struct
 	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');
-	}
+	if (f->linestate == LINE_MACRO)
+		macro_addarg(f, cp, 0);
+	else
+		print_text(f, cp, 0);
 }
 
 static void
--
 To unsubscribe send an email to tech+unsubscribe@mandoc.bsd.lv

      parent reply	other threads:[~2019-04-12  8:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-12  5:57 Stephen Gregoratto
2019-04-12  7:14 ` Ingo Schwarze
2019-04-12  8:55 ` Ingo Schwarze [this message]

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=20190412085546.GB89835@athene.usta.de \
    --to=schwarze@usta.de \
    --cc=dev@sgregoratto.me \
    --cc=tech@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).