From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from scc-mailout-kit-02.scc.kit.edu (scc-mailout-kit-02.scc.kit.edu [129.13.231.82]) by fantadrom.bsd.lv (OpenSMTPD) with ESMTP id 36fe8d3c for ; Fri, 12 Apr 2019 03:55:51 -0500 (EST) Received: from asta-nat.asta.uni-karlsruhe.de ([172.22.63.82] helo=hekate.usta.de) by scc-mailout-kit-02.scc.kit.edu with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (envelope-from ) id 1hEryO-0007a4-3t; Fri, 12 Apr 2019 10:55:50 +0200 Received: from donnerwolke.usta.de ([172.24.96.3]) by hekate.usta.de with esmtp (Exim 4.77) (envelope-from ) id 1hEryM-00082R-Rn; Fri, 12 Apr 2019 10:55:46 +0200 Received: from athene.usta.de ([172.24.96.10]) by donnerwolke.usta.de with esmtp (Exim 4.84_2) (envelope-from ) id 1hEryM-0004Ib-PJ; Fri, 12 Apr 2019 10:55:46 +0200 Received: from localhost (athene.usta.de [local]) by athene.usta.de (OpenSMTPD) with ESMTPA id 4dc56e32; Fri, 12 Apr 2019 10:55:46 +0200 (CEST) Date: Fri, 12 Apr 2019 10:55:46 +0200 From: Ingo Schwarze To: Stephen Gregoratto Cc: tech@mandoc.bsd.lv Subject: Re: [PATCH docbook2mdoc] Add markup, computeroutput (WIP) Message-ID: <20190412085546.GB89835@athene.usta.de> References: <20190412055748.umynmdcylrtp5pbs@BlackBox> X-Mailinglist: mandoc-tech Reply-To: tech@mandoc.bsd.lv MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190412055748.umynmdcylrtp5pbs@BlackBox> User-Agent: Mutt/1.8.0 (2017-02-23) 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 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