From: schwarze@mandoc.bsd.lv
To: source@mandoc.bsd.lv
Subject: docbook2mdoc: More whitespace improvements: * Skip XML line breaks right
Date: Wed, 1 May 2019 12:21:18 -0500 (EST) [thread overview]
Message-ID: <e3fedc6a1f27e480@fantadrom.bsd.lv> (raw)
Log Message:
-----------
More whitespace improvements:
* Skip XML line breaks right after opening tags.
* When processing a text node, check whether a paragraph break is needed
before starting more detailed checks regarding macro arguments.
* Break the mdoc line at the beginning of a new XML line
unless a macro line is open and wants more arguments.
* Do not print "\c" escapes on macro lines.
Modified Files:
--------------
docbook2mdoc:
docbook2mdoc.c
macro.c
macro.h
parse.c
Revision Data
-------------
Index: docbook2mdoc.c
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/docbook2mdoc.c,v
retrieving revision 1.146
retrieving revision 1.147
diff -Ldocbook2mdoc.c -Ldocbook2mdoc.c -u -p -r1.146 -r1.147
--- docbook2mdoc.c
+++ docbook2mdoc.c
@@ -40,6 +40,7 @@ pnode_printtext(struct format *f, struct
char *cp;
int accept_arg;
+ para_check(f);
cp = n->b;
accept_arg = f->flags & FMT_ARG;
if (f->linestate == LINE_MACRO && !accept_arg &&
@@ -930,7 +931,8 @@ pnode_print(struct format *f, struct pno
if (n == NULL)
return;
- if (f->nofill && n->flags & NFLAG_LINE)
+ if (n->flags & NFLAG_LINE &&
+ (f->nofill || (f->flags & (FMT_ARG | FMT_IMPL)) == 0))
macro_close(f);
was_impl = f->flags & FMT_IMPL;
Index: macro.h
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/macro.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -Lmacro.h -Lmacro.h -u -p -r1.6 -r1.7
--- macro.h
+++ macro.h
@@ -59,5 +59,6 @@ void macro_argline(struct format *, con
void macro_addnode(struct format *, struct pnode *, int);
void macro_nodeline(struct format *, const char *, struct pnode *, int);
+void para_check(struct format *);
void print_text(struct format *, const char *, int);
void print_textnode(struct format *, struct pnode *);
Index: parse.c
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/parse.c,v
retrieving revision 1.56
retrieving revision 1.57
diff -Lparse.c -Lparse.c -u -p -r1.56 -r1.57
--- parse.c
+++ parse.c
@@ -268,8 +268,10 @@ xml_text(struct parse *p, const char *wo
n = pnode_alloc(p->cur);
n->node = NODE_TEXT;
- n->flags = ((p->flags & PFLAG_LINE) ? NFLAG_LINE : 0) |
- ((p->flags & PFLAG_SPC) ? NFLAG_SPC : 0);
+ if (p->flags & PFLAG_LINE && TAILQ_PREV(n, pnodeq, child) != NULL)
+ n->flags |= NFLAG_LINE;
+ if (p->flags & PFLAG_SPC)
+ n->flags |= NFLAG_SPC;
p->flags &= ~(PFLAG_LINE | PFLAG_SPC);
/*
@@ -433,8 +435,10 @@ xml_entity(struct parse *p, const char *
n->b = xstrdup(entity->roff);
done:
n->node = NODE_ESCAPE;
- n->flags = ((p->flags & PFLAG_LINE) ? NFLAG_LINE : 0) |
- ((p->flags & PFLAG_SPC) ? NFLAG_SPC : 0);
+ if (p->flags & PFLAG_LINE && TAILQ_PREV(n, pnodeq, child) != NULL)
+ n->flags |= NFLAG_LINE;
+ if (p->flags & PFLAG_SPC)
+ n->flags |= NFLAG_SPC;
p->flags &= ~(PFLAG_LINE | PFLAG_SPC);
}
@@ -506,6 +510,10 @@ xml_elem_start(struct parse *p, const ch
}
n = pnode_alloc(p->cur);
+ if (p->flags & PFLAG_LINE && p->cur != NULL &&
+ TAILQ_PREV(n, pnodeq, child) != NULL)
+ n->flags |= NFLAG_LINE;
+ p->flags &= ~PFLAG_LINE;
/*
* Some elements are self-closing.
@@ -526,8 +534,8 @@ xml_elem_start(struct parse *p, const ch
switch (pnode_class(p->ncur)) {
case CLASS_LINE:
case CLASS_ENCL:
- n->flags = ((p->flags & PFLAG_LINE) ? NFLAG_LINE : 0) |
- ((p->flags & PFLAG_SPC) ? NFLAG_SPC : 0);
+ if (p->flags & PFLAG_SPC)
+ n->flags |= NFLAG_SPC;
break;
case CLASS_NOFILL:
p->nofill++;
Index: macro.c
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/macro.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -Lmacro.c -Lmacro.c -u -p -r1.17 -r1.18
--- macro.c
+++ macro.c
@@ -28,15 +28,22 @@
*/
void
-macro_open(struct format *f, const char *name)
+para_check(struct format *f)
{
- if (f->parastate == PARA_WANT) {
- if (f->linestate != LINE_NEW) {
- putchar('\n');
- f->linestate = LINE_NEW;
- }
- puts(".Pp");
+ if (f->parastate != PARA_WANT)
+ return;
+ if (f->linestate != LINE_NEW) {
+ putchar('\n');
+ f->linestate = LINE_NEW;
}
+ puts(".Pp");
+ f->parastate = PARA_HAVE;
+}
+
+void
+macro_open(struct format *f, const char *name)
+{
+ para_check(f);
switch (f->linestate) {
case LINE_MACRO:
if (f->flags & FMT_NOSPC) {
@@ -49,7 +56,7 @@ macro_open(struct format *f, const char
}
/* FALLTHROUGH */
case LINE_TEXT:
- if (f->nofill)
+ if (f->nofill && f->linestate == LINE_TEXT)
fputs(" \\c", stdout);
putchar('\n');
/* FALLTHROUGH */
@@ -241,13 +248,7 @@ macro_nodeline(struct format *f, const c
void
print_text(struct format *f, const char *word, int flags)
{
- if (f->parastate == PARA_WANT) {
- if (f->linestate != LINE_NEW) {
- putchar('\n');
- f->linestate = LINE_NEW;
- }
- puts(".Pp");
- }
+ para_check(f);
switch (f->linestate) {
case LINE_NEW:
break;
--
To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv
reply other threads:[~2019-05-01 17:21 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e3fedc6a1f27e480@fantadrom.bsd.lv \
--to=schwarze@mandoc.bsd.lv \
--cc=source@mandoc.bsd.lv \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).