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 371153d3 for ; Tue, 16 Apr 2019 09:58:49 -0500 (EST) Date: Tue, 16 Apr 2019 09:58:49 -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: preserve leading whitespace in no-fill mode X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Message-ID: 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: ", 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