* docbook2mdoc: preserve leading whitespace in no-fill mode
@ 2019-04-16 14:58 schwarze
0 siblings, 0 replies; only message in thread
From: schwarze @ 2019-04-16 14:58 UTC (permalink / raw)
To: source
Log Message:
-----------
preserve leading whitespace in no-fill mode
Modified Files:
--------------
docbook2mdoc:
node.c
node.h
parse.c
Revision Data
-------------
Index: node.c
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/node.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -Lnode.c -Lnode.c -u -p -r1.20 -r1.21
--- node.c
+++ node.c
@@ -78,7 +78,7 @@ static const struct nodeprop properties[
{ "link", CLASS_ENCL },
{ "listitem", CLASS_TRANS },
{ "literal", CLASS_ENCL },
- { "literallayout", CLASS_BLOCK },
+ { "literallayout", CLASS_NOFILL },
{ "manvolnum", CLASS_TRANS },
{ "markup", CLASS_LINE },
{ "member", CLASS_LINE },
@@ -101,7 +101,7 @@ static const struct nodeprop properties[
{ "parameter", CLASS_LINE },
{ "personname", CLASS_TRANS },
{ "preface", CLASS_BLOCK },
- { "programlisting", CLASS_BLOCK },
+ { "programlisting", CLASS_NOFILL },
{ "prompt", CLASS_TRANS },
{ "pubdate", CLASS_TRANS },
{ "quote", CLASS_ENCL },
@@ -120,7 +120,7 @@ static const struct nodeprop properties[
{ "replaceable", CLASS_LINE },
{ "row", CLASS_BLOCK },
{ "sbr", CLASS_BLOCK },
- { "screen", CLASS_BLOCK },
+ { "screen", CLASS_NOFILL },
{ "section", CLASS_BLOCK },
{ "simplelist", CLASS_TRANS },
{ "simplesect", CLASS_BLOCK },
@@ -128,7 +128,7 @@ static const struct nodeprop properties[
{ "subscript", CLASS_TEXT },
{ "subtitle", CLASS_BLOCK },
{ "superscript", CLASS_TEXT },
- { "synopsis", CLASS_BLOCK },
+ { "synopsis", CLASS_NOFILL },
{ "systemitem", CLASS_LINE },
{ "table", CLASS_TRANS },
{ "tbody", CLASS_TRANS },
Index: node.h
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/node.h,v
retrieving revision 1.29
retrieving revision 1.30
diff -Lnode.h -Lnode.h -u -p -r1.29 -r1.30
--- node.h
+++ node.h
@@ -31,7 +31,8 @@ enum nodeclass {
CLASS_TRANS, /* Transparent: only the children are shown. */
CLASS_LINE, /* Generates only simple in-line macros. */
CLASS_ENCL, /* Explicit or implicit partial blocks. */
- CLASS_BLOCK /* Output linebreak before and after. */
+ CLASS_BLOCK, /* Output linebreak before and after. */
+ CLASS_NOFILL /* Block preserving leading whitespace. */
};
/*
Index: parse.c
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/parse.c,v
retrieving revision 1.44
retrieving revision 1.45
diff -Lparse.c -Lparse.c -u -p -r1.44 -r1.45
--- parse.c
+++ parse.c
@@ -56,6 +56,7 @@ struct parse {
int nline; /* Line number of next token. */
int ncol; /* Column number of next token. */
int del; /* Levels of nested nodes being deleted. */
+ int nofill; /* Levels of open no-fill displays. */
int flags;
#define PFLAG_WARN (1 << 0) /* Print warning messages. */
#define PFLAG_SPC (1 << 1) /* Whitespace before the next element. */
@@ -284,6 +285,7 @@ xml_text(struct parse *p, const char *wo
case CLASS_VOID:
case CLASS_TEXT:
case CLASS_BLOCK:
+ case CLASS_NOFILL:
np = NULL;
break;
case CLASS_TRANS:
@@ -525,6 +527,9 @@ xml_elem_start(struct parse *p, const ch
case CLASS_ENCL:
n->spc = (p->flags & PFLAG_SPC) != 0;
break;
+ case CLASS_NOFILL:
+ p->nofill++;
+ /* FALLTHROUGH */
default:
n->spc = 1;
break;
@@ -649,6 +654,8 @@ xml_elem_end(struct parse *p, const char
warn_msg(p, "element not open: </%s>", name);
break;
}
+ if (pnode_class(node) == CLASS_NOFILL)
+ p->nofill--;
/*
* Refrain from actually closing the document element.
@@ -756,11 +763,12 @@ parse_string(struct parse *p, char *b, s
enum pstate *pstate, int refill)
{
char *cp;
+ size_t pws; /* Parse offset including whitespace. */
size_t poff; /* Parse offset in b[]. */
size_t pend; /* Offset of the end of the current word. */
int elem_end;
- pend = 0;
+ pend = pws = 0;
for (;;) {
/* Proceed to the next token, skipping whitespace. */
@@ -773,6 +781,8 @@ parse_string(struct parse *p, char *b, s
break;
if (isspace((unsigned char)b[pend])) {
p->flags |= PFLAG_SPC;
+ if (b[pend] == '\n')
+ pws = pend + 1;
increment(p, b, &pend, refill);
continue;
}
@@ -934,10 +944,13 @@ parse_string(struct parse *p, char *b, s
advance(p, b, rlen, &pend,
p->ncur == NODE_DOCTYPE ? "<&]\n" : "<&\n",
refill);
+ if (p->nofill)
+ poff = pws;
xml_text(p, b + poff, pend - poff);
if (b[pend] == '\n')
pnode_closetext(p, 0);
}
+ pws = pend;
}
return poff;
}
--
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-16 14:58 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-16 14:58 docbook2mdoc: preserve leading whitespace in no-fill mode 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).