* docbook2mdoc: Move escaping of control characters and backslashes on
@ 2019-04-12 8:48 schwarze
0 siblings, 0 replies; only message in thread
From: schwarze @ 2019-04-12 8:48 UTC (permalink / raw)
To: source
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2019-04-12 8:48 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-12 8:48 docbook2mdoc: Move escaping of control characters and backslashes on 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).