* [PATCH docbook2mdoc] Add markup, computeroutput (WIP)
@ 2019-04-12 5:57 Stephen Gregoratto
2019-04-12 7:14 ` Ingo Schwarze
2019-04-12 8:55 ` Ingo Schwarze
0 siblings, 2 replies; 3+ messages in thread
From: Stephen Gregoratto @ 2019-04-12 5:57 UTC (permalink / raw)
To: tech
Both of these are frequently used in the doclifter manpage.
First up, <markup>. The docs say:
> A markup element contains a string of formatting markup that is to be
> represented literally in the text. The utility of this element is
> almost wholly constrained to books about document formatting tools.
doclifter uses it to designate troff macros, e.g <markup>.Pp</markup>.
Since this is similar to <sgmltag>, I decided to set NODE_SGMLTAG to the
new NODE_MARKUP.
The only problem is that using macro_open(f, "Ic") doesn't escape the
markup like pnode_printtext does (worst case would format as: .Ic Pp).
Secondly, <computerlayout>. The docs say:
> A computeroutput identifies lines of text generated by a computer
> program (messages, results, or other output).
Setting this to NODE_LITERAL
Index: docbook2mdoc.c
===================================================================
RCS file: /cvs/docbook2mdoc/docbook2mdoc.c,v
retrieving revision 1.105
diff -u -p -r1.105 docbook2mdoc.c
--- docbook2mdoc.c 12 Apr 2019 04:17:11 -0000 1.105
+++ docbook2mdoc.c 12 Apr 2019 05:53:31 -0000
@@ -914,6 +914,9 @@ pnode_print(struct format *f, struct pno
macro_argline(f, "Bd", pnode_getattr(n, ATTRKEY_CLASS) ==
ATTRVAL_MONOSPACED ? "-literal" : "-unfilled");
break;
+ case NODE_MARKUP:
+ macro_open(f, "Ic");
+ break;
case NODE_MML_MFENCED:
pnode_printmathfenced(f, n);
break;
@@ -988,9 +991,6 @@ pnode_print(struct format *f, struct pno
break;
case NODE_SBR:
macro_line(f, "br");
- break;
- case NODE_SGMLTAG:
- macro_open(f, "Ic");
break;
case NODE_TEXT:
case NODE_ESCAPE:
Index: node.h
===================================================================
RCS file: /cvs/docbook2mdoc/node.h,v
retrieving revision 1.17
diff -u -p -r1.17 node.h
--- node.h 12 Apr 2019 04:39:24 -0000 1.17
+++ node.h 12 Apr 2019 05:53:31 -0000
@@ -82,6 +82,7 @@ enum nodeid {
NODE_LITERAL,
NODE_LITERALLAYOUT,
NODE_MANVOLNUM,
+ NODE_MARKUP,
NODE_MEMBER,
NODE_MML_MATH,
NODE_MML_MFENCED,
@@ -123,7 +124,6 @@ enum nodeid {
NODE_SBR,
NODE_SCREEN,
NODE_SECTION,
- NODE_SGMLTAG,
NODE_SIMPLELIST,
NODE_SPANSPEC,
NODE_SUBTITLE,
Index: parse.c
===================================================================
RCS file: /cvs/docbook2mdoc/parse.c,v
retrieving revision 1.34
diff -u -p -r1.34 parse.c
--- parse.c 12 Apr 2019 04:39:24 -0000 1.34
+++ parse.c 12 Apr 2019 05:53:31 -0000
@@ -89,6 +89,7 @@ static const struct element elements[] =
{ "code", NODE_LITERAL },
{ "colspec", NODE_COLSPEC },
{ "command", NODE_COMMAND },
+ { "computeroutput", NODE_LITERAL },
{ "constant", NODE_CONSTANT },
{ "contrib", NODE_CONTRIB },
{ "copyright", NODE_COPYRIGHT },
@@ -134,6 +135,7 @@ static const struct element elements[] =
{ "literal", NODE_LITERAL },
{ "literallayout", NODE_LITERALLAYOUT },
{ "manvolnum", NODE_MANVOLNUM },
+ { "markup", NODE_MARKUP },
{ "member", NODE_MEMBER },
{ "mml:math", NODE_MML_MATH },
{ "mml:mfenced", NODE_MML_MFENCED },
@@ -186,7 +188,7 @@ static const struct element elements[] =
{ "sect1", NODE_SECTION },
{ "sect2", NODE_SECTION },
{ "section", NODE_SECTION },
- { "sgmltag", NODE_SGMLTAG },
+ { "sgmltag", NODE_MARKUP },
{ "simpara", NODE_PARA },
{ "simplelist", NODE_SIMPLELIST },
{ "spanspec", NODE_SPANSPEC },
--
Stephen Gregoratto
PGP: 3FC6 3D0E 2801 C348 1C44 2D34 A80C 0F8E 8BAB EC8:q
--
To unsubscribe send an email to tech+unsubscribe@mandoc.bsd.lv
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH docbook2mdoc] Add markup, computeroutput (WIP)
2019-04-12 5:57 [PATCH docbook2mdoc] Add markup, computeroutput (WIP) Stephen Gregoratto
@ 2019-04-12 7:14 ` Ingo Schwarze
2019-04-12 8:55 ` Ingo Schwarze
1 sibling, 0 replies; 3+ messages in thread
From: Ingo Schwarze @ 2019-04-12 7:14 UTC (permalink / raw)
To: Stephen Gregoratto; +Cc: tech
Hi Stephen,
Stephen Gregoratto wrote on Fri, Apr 12, 2019 at 03:57:48PM +1000:
> Both of these are frequently used in the doclifter manpage.
Thanks for pointing out where they are used.
> First up, <markup>. The docs say:
>> A markup element contains a string of formatting markup that is to be
>> represented literally in the text. The utility of this element is
>> almost wholly constrained to books about document formatting tools.
> doclifter uses it to designate troff macros, e.g <markup>.Pp</markup>.
> Since this is similar to <sgmltag>, I decided to set NODE_SGMLTAG to the
> new NODE_MARKUP.
Your argument makes sense to me.
I committed your patch unchanged.
> The only 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 think you habe a point here, text escaping is not consistent.
I should fix that, but that's independent of your patch.
> Secondly, <computerlayout>. The docs say:
>> A computeroutput identifies lines of text generated by a computer
>> program (messages, results, or other output).
> Setting this to NODE_LITERAL
Sure, makes sense, too.
There is a slight problem with NODE_LITERAL formatting:
It is translated to .Ql, but sometimes, authors manually
put quotes around it. The formatter should probably delete
those additional quotes. But again, that's independent of your
patch.
Thanks,
Ingo
> Index: docbook2mdoc.c
> ===================================================================
> RCS file: /cvs/docbook2mdoc/docbook2mdoc.c,v
> retrieving revision 1.105
> diff -u -p -r1.105 docbook2mdoc.c
> --- docbook2mdoc.c 12 Apr 2019 04:17:11 -0000 1.105
> +++ docbook2mdoc.c 12 Apr 2019 05:53:31 -0000
> @@ -914,6 +914,9 @@ pnode_print(struct format *f, struct pno
> macro_argline(f, "Bd", pnode_getattr(n, ATTRKEY_CLASS) ==
> ATTRVAL_MONOSPACED ? "-literal" : "-unfilled");
> break;
> + case NODE_MARKUP:
> + macro_open(f, "Ic");
> + break;
> case NODE_MML_MFENCED:
> pnode_printmathfenced(f, n);
> break;
> @@ -988,9 +991,6 @@ pnode_print(struct format *f, struct pno
> break;
> case NODE_SBR:
> macro_line(f, "br");
> - break;
> - case NODE_SGMLTAG:
> - macro_open(f, "Ic");
> break;
> case NODE_TEXT:
> case NODE_ESCAPE:
> Index: node.h
> ===================================================================
> RCS file: /cvs/docbook2mdoc/node.h,v
> retrieving revision 1.17
> diff -u -p -r1.17 node.h
> --- node.h 12 Apr 2019 04:39:24 -0000 1.17
> +++ node.h 12 Apr 2019 05:53:31 -0000
> @@ -82,6 +82,7 @@ enum nodeid {
> NODE_LITERAL,
> NODE_LITERALLAYOUT,
> NODE_MANVOLNUM,
> + NODE_MARKUP,
> NODE_MEMBER,
> NODE_MML_MATH,
> NODE_MML_MFENCED,
> @@ -123,7 +124,6 @@ enum nodeid {
> NODE_SBR,
> NODE_SCREEN,
> NODE_SECTION,
> - NODE_SGMLTAG,
> NODE_SIMPLELIST,
> NODE_SPANSPEC,
> NODE_SUBTITLE,
> Index: parse.c
> ===================================================================
> RCS file: /cvs/docbook2mdoc/parse.c,v
> retrieving revision 1.34
> diff -u -p -r1.34 parse.c
> --- parse.c 12 Apr 2019 04:39:24 -0000 1.34
> +++ parse.c 12 Apr 2019 05:53:31 -0000
> @@ -89,6 +89,7 @@ static const struct element elements[] =
> { "code", NODE_LITERAL },
> { "colspec", NODE_COLSPEC },
> { "command", NODE_COMMAND },
> + { "computeroutput", NODE_LITERAL },
> { "constant", NODE_CONSTANT },
> { "contrib", NODE_CONTRIB },
> { "copyright", NODE_COPYRIGHT },
> @@ -134,6 +135,7 @@ static const struct element elements[] =
> { "literal", NODE_LITERAL },
> { "literallayout", NODE_LITERALLAYOUT },
> { "manvolnum", NODE_MANVOLNUM },
> + { "markup", NODE_MARKUP },
> { "member", NODE_MEMBER },
> { "mml:math", NODE_MML_MATH },
> { "mml:mfenced", NODE_MML_MFENCED },
> @@ -186,7 +188,7 @@ static const struct element elements[] =
> { "sect1", NODE_SECTION },
> { "sect2", NODE_SECTION },
> { "section", NODE_SECTION },
> - { "sgmltag", NODE_SGMLTAG },
> + { "sgmltag", NODE_MARKUP },
> { "simpara", NODE_PARA },
> { "simplelist", NODE_SIMPLELIST },
> { "spanspec", NODE_SPANSPEC },
--
To unsubscribe send an email to tech+unsubscribe@mandoc.bsd.lv
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH docbook2mdoc] Add markup, computeroutput (WIP)
2019-04-12 5:57 [PATCH docbook2mdoc] Add markup, computeroutput (WIP) Stephen Gregoratto
2019-04-12 7:14 ` Ingo Schwarze
@ 2019-04-12 8:55 ` Ingo Schwarze
1 sibling, 0 replies; 3+ messages in thread
From: Ingo Schwarze @ 2019-04-12 8:55 UTC (permalink / raw)
To: Stephen Gregoratto; +Cc: tech
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-04-12 8:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-12 5:57 [PATCH docbook2mdoc] Add markup, computeroutput (WIP) Stephen Gregoratto
2019-04-12 7:14 ` Ingo Schwarze
2019-04-12 8:55 ` Ingo 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).