From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from localhost (fantadrom.bsd.lv [local]) by fantadrom.bsd.lv (OpenSMTPD) with ESMTPA id 6b132b2a for ; Fri, 12 Apr 2019 03:48:46 -0500 (EST) Date: Fri, 12 Apr 2019 03:48:46 -0500 (EST) X-Mailinglist: mandoc-source Reply-To: source@mandoc.bsd.lv MIME-Version: 1.0 From: schwarze@mandoc.bsd.lv To: source@mandoc.bsd.lv Subject: docbook2mdoc: Move escaping of control characters and backslashes on X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Message-ID: 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 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