source@mandoc.bsd.lv
 help / color / Atom feed
* docbook2mdoc: More whitespace improvements: * Skip XML line breaks right 
@ 2019-05-01 17:21 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2019-05-01 17:21 UTC (permalink / raw)
  To: source

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-01 17:21 docbook2mdoc: More whitespace improvements: * Skip XML line breaks right schwarze

source@mandoc.bsd.lv

Archives are clonable: git clone --mirror http://inbox.vuxu.org/mandoc-source

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.mandoc.source


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git