From: schwarze@mandoc.bsd.lv
To: source@mandoc.bsd.lv
Subject: docbook2mdoc: Move escaping of control characters and backslashes on
Date: Fri, 12 Apr 2019 03:48:46 -0500 (EST) [thread overview]
Message-ID: <e3fdb2ce437a3f7c@fantadrom.bsd.lv> (raw)
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 source+unsubscribe@mandoc.bsd.lv
reply other threads:[~2019-04-12 8:48 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=e3fdb2ce437a3f7c@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).