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 6c30c0a7 for ; Wed, 24 Apr 2019 13:38:32 -0500 (EST) Date: Wed, 24 Apr 2019 13:38:32 -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: Remove some needless output line breaks between text X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Message-ID: Log Message: ----------- Remove some needless output line breaks between text nodes. Some of them were incorrect in no-fill mode. Modified Files: -------------- docbook2mdoc: docbook2mdoc.1 docbook2mdoc.c macro.c node.h parse.c tree.c Revision Data ------------- Index: docbook2mdoc.1 =================================================================== RCS file: /home/cvs/mdocml/docbook2mdoc/docbook2mdoc.1,v retrieving revision 1.13 retrieving revision 1.14 diff -Ldocbook2mdoc.1 -Ldocbook2mdoc.1 -u -p -r1.13 -r1.14 --- docbook2mdoc.1 +++ docbook2mdoc.1 @@ -58,7 +58,8 @@ Child nodes are indented with respect to The columns are: .Bl -enum -width 2n .It -A hyphen if the node follows the previous node +An asterisk if the node starts a new text line, +or a hyphen if the node follows the previous node without intervening whitespace. .It The node type. Index: parse.c =================================================================== RCS file: /home/cvs/mdocml/docbook2mdoc/parse.c,v retrieving revision 1.50 retrieving revision 1.51 diff -Lparse.c -Lparse.c -u -p -r1.50 -r1.51 --- parse.c +++ parse.c @@ -59,9 +59,10 @@ struct parse { 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. */ -#define PFLAG_ATTR (1 << 2) /* The most recent attribute is valid. */ -#define PFLAG_EEND (1 << 3) /* This element is self-closing. */ +#define PFLAG_LINE (1 << 1) /* New line before the next element. */ +#define PFLAG_SPC (1 << 2) /* Whitespace before the next element. */ +#define PFLAG_ATTR (1 << 3) /* The most recent attribute is valid. */ +#define PFLAG_EEND (1 << 4) /* This element is self-closing. */ }; struct alias { @@ -261,7 +262,7 @@ xml_text(struct parse *p, const char *wo n->b[oldsz++] = ' '; memcpy(n->b + oldsz, word, sz); n->b[newsz] = '\0'; - p->flags &= ~PFLAG_SPC; + p->flags &= ~(PFLAG_LINE | PFLAG_SPC); return; } @@ -273,8 +274,9 @@ xml_text(struct parse *p, const char *wo if ((n = pnode_alloc(p->cur)) == NULL) fatal(p); n->node = NODE_TEXT; - n->spc = (p->flags & PFLAG_SPC) != 0; - p->flags &= ~PFLAG_SPC; + n->flags = ((p->flags & PFLAG_LINE) ? NFLAG_LINE : 0) | + ((p->flags & PFLAG_SPC) ? NFLAG_SPC : 0); + p->flags &= ~(PFLAG_LINE | PFLAG_SPC); /* * If this node follows an in-line macro without intervening @@ -282,7 +284,7 @@ xml_text(struct parse *p, const char *wo * and do not keep it open. */ - np = n->spc ? NULL : TAILQ_PREV(n, pnodeq, child); + np = n->flags & NFLAG_SPC ? NULL : TAILQ_PREV(n, pnodeq, child); while (np != NULL) { switch (pnode_class(np->node)) { case CLASS_VOID: @@ -320,7 +322,7 @@ xml_text(struct parse *p, const char *wo if ((n = pnode_alloc(p->cur)) == NULL) fatal(p); n->node = NODE_TEXT; - n->spc = 1; + n->flags |= NFLAG_SPC; word += i; sz -= i; } @@ -371,7 +373,7 @@ pnode_closetext(struct parse *p, int che if ((n = pnode_alloc(p->cur)) == NULL) fatal(p); n->node = NODE_TEXT; - n->spc = 1; + n->flags |= NFLAG_SPC; if ((n->b = strdup(last_word)) == NULL) fatal(p); } @@ -413,7 +415,7 @@ xml_entity(struct parse *p, const char * if ((ccp = pnode_getattr_raw(n, ATTRKEY_SYSTEM, NULL)) != NULL) { parse_file(p, -1, ccp); - p->flags &= ~PFLAG_SPC; + p->flags &= ~(PFLAG_LINE | PFLAG_SPC); return; } if ((ccp = pnode_getattr_raw(n, @@ -423,7 +425,7 @@ xml_entity(struct parse *p, const char * fatal(p); pstate = PARSE_ELEM; parse_string(p, cp, strlen(cp), &pstate, 0); - p->flags &= ~PFLAG_SPC; + p->flags &= ~(PFLAG_LINE | PFLAG_SPC); free(cp); return; } @@ -448,8 +450,9 @@ xml_entity(struct parse *p, const char * fatal(p); done: n->node = NODE_ESCAPE; - n->spc = (p->flags & PFLAG_SPC) != 0; - p->flags &= ~PFLAG_SPC; + n->flags = ((p->flags & PFLAG_LINE) ? NFLAG_LINE : 0) | + ((p->flags & PFLAG_SPC) ? NFLAG_SPC : 0); + p->flags &= ~(PFLAG_LINE | PFLAG_SPC); } /* @@ -541,13 +544,14 @@ xml_elem_start(struct parse *p, const ch switch (pnode_class(p->ncur)) { case CLASS_LINE: case CLASS_ENCL: - n->spc = (p->flags & PFLAG_SPC) != 0; + n->flags = ((p->flags & PFLAG_LINE) ? NFLAG_LINE : 0) | + ((p->flags & PFLAG_SPC) ? NFLAG_SPC : 0); break; case CLASS_NOFILL: p->nofill++; /* FALLTHROUGH */ default: - n->spc = 1; + n->flags |= NFLAG_SPC; break; } p->cur = n; @@ -659,7 +663,7 @@ xml_elem_end(struct parse *p, const char else parse_file(p, -1, cp); pnode_unlink(n); - p->flags &= ~PFLAG_SPC; + p->flags &= ~(PFLAG_LINE | PFLAG_SPC); break; case NODE_DOCTYPE: case NODE_SBR: @@ -687,7 +691,7 @@ xml_elem_end(struct parse *p, const char p->ncur = p->cur->node; } else p->tree->flags |= TREE_CLOSED; - p->flags &= ~PFLAG_SPC; + p->flags &= ~(PFLAG_LINE | PFLAG_SPC); /* Include a file containing entity declarations. */ @@ -806,8 +810,10 @@ parse_string(struct parse *p, char *b, s break; if (isspace((unsigned char)b[pend])) { p->flags |= PFLAG_SPC; - if (b[pend] == '\n') + if (b[pend] == '\n') { + p->flags |= PFLAG_LINE; pws = pend + 1; + } increment(p, b, &pend, refill); continue; } Index: docbook2mdoc.c =================================================================== RCS file: /home/cvs/mdocml/docbook2mdoc/docbook2mdoc.c,v retrieving revision 1.137 retrieving revision 1.138 diff -Ldocbook2mdoc.c -Ldocbook2mdoc.c -u -p -r1.137 -r1.138 --- docbook2mdoc.c +++ docbook2mdoc.c @@ -42,7 +42,8 @@ pnode_printtext(struct format *f, struct cp = n->b; accept_arg = f->flags & FMT_ARG; - if (f->linestate == LINE_MACRO && !n->spc && !accept_arg) { + if (f->linestate == LINE_MACRO && !accept_arg && + (n->flags & NFLAG_SPC) == 0) { for (;;) { if (*cp == '\0') return; @@ -71,14 +72,15 @@ pnode_printtext(struct format *f, struct */ if (f->linestate != LINE_MACRO && - (nn = TAILQ_NEXT(n, child)) != NULL && nn->spc == 0) { + (nn = TAILQ_NEXT(n, child)) != NULL && + (nn->flags & NFLAG_SPC) == 0) { switch (pnode_class(nn->node)) { case CLASS_LINE: case CLASS_ENCL: macro_open(f, "Pf"); accept_arg = 1; f->flags |= FMT_CHILD; - nn->spc = 1; + nn->flags |= NFLAG_SPC; break; default: break; @@ -89,8 +91,9 @@ pnode_printtext(struct format *f, struct case LINE_NEW: break; case LINE_TEXT: - if (n->spc) { - if (pnode_class(n->node) == CLASS_TEXT) + if (n->flags & NFLAG_SPC) { + if (n->flags & NFLAG_LINE && + pnode_class(n->node) == CLASS_TEXT) macro_close(f); else putchar(' '); @@ -99,7 +102,8 @@ pnode_printtext(struct format *f, struct case LINE_MACRO: if (accept_arg == 0) macro_close(f); - else if (n->spc || (f->flags & FMT_ARG) == 0 || + else if (n->flags & NFLAG_SPC || + (f->flags & FMT_ARG) == 0 || (nn = TAILQ_PREV(n, pnodeq, child)) == NULL || pnode_class(nn->node) != CLASS_TEXT) putchar(' '); @@ -889,7 +893,7 @@ pnode_printrefentry(struct format *f, st exit(1); } match->node = NODE_SECTION; - match->spc = 1; + match->flags |= NFLAG_SPC; match->parent = n; TAILQ_INIT(&match->childq); TAILQ_INIT(&match->attrq); @@ -898,7 +902,7 @@ pnode_printrefentry(struct format *f, st exit(1); } nc->node = NODE_TITLE; - nc->spc = 1; + nc->flags |= NFLAG_SPC; if ((nc = pnode_alloc(nc)) == NULL) { perror(NULL); exit(1); @@ -908,7 +912,7 @@ pnode_printrefentry(struct format *f, st perror(NULL); exit(1); } - nc->spc = 1; + nc->flags |= NFLAG_SPC; if (later == NULL) TAILQ_INSERT_TAIL(&n->childq, match, child); else @@ -1125,7 +1129,7 @@ pnode_print(struct format *f, struct pno return; was_impl = f->flags & FMT_IMPL; - if (n->spc) + if (n->flags & NFLAG_SPC) f->flags &= ~FMT_NOSPC; else f->flags |= FMT_NOSPC; @@ -1290,8 +1294,8 @@ pnode_print(struct format *f, struct pno if ((nc = TAILQ_FIRST(&n->childq)) != NULL && nc->node == NODE_FILENAME && TAILQ_NEXT(nc, child) == NULL) { - if (n->spc) - nc->spc = 1; + if (n->flags & NFLAG_SPC) + nc->flags |= NFLAG_SPC; } else if (was_impl) macro_open(f, "Do"); else { @@ -1349,12 +1353,12 @@ pnode_print(struct format *f, struct pno else print_text(f, "_", 0); if ((nc = TAILQ_FIRST(&n->childq)) != NULL) - nc->spc = 0; + nc->flags &= ~(NFLAG_LINE | NFLAG_SPC); break; case NODE_SUPERSCRIPT: fputs("\\(ha", stdout); if ((nc = TAILQ_FIRST(&n->childq)) != NULL) - nc->spc = 0; + nc->flags &= ~(NFLAG_LINE | NFLAG_SPC); break; case NODE_TEXT: case NODE_ESCAPE: Index: macro.c =================================================================== RCS file: /home/cvs/mdocml/docbook2mdoc/macro.c,v retrieving revision 1.15 retrieving revision 1.16 diff -Lmacro.c -Lmacro.c -u -p -r1.15 -r1.16 --- macro.c +++ macro.c @@ -213,7 +213,7 @@ macro_addnode(struct format *f, struct p nc = TAILQ_NEXT(nc, child); if (nc == NULL || pnode_class(nc->node) != CLASS_TEXT) is_text = 0; - if (is_text && !nc->spc) + if (is_text && (nc->flags & NFLAG_SPC) == 0) flags &= ~ARG_SPACE; else flags |= ARG_SPACE; Index: tree.c =================================================================== RCS file: /home/cvs/mdocml/docbook2mdoc/tree.c,v retrieving revision 1.2 retrieving revision 1.3 diff -Ltree.c -Ltree.c -u -p -r1.2 -r1.3 --- tree.c +++ tree.c @@ -29,7 +29,9 @@ print_node(struct pnode *n, int indent) struct pnode *nc; struct pattr *a; - printf("%*s%c%s", indent, "", n->spc ? ' ' : '-', + printf("%*s%c%s", indent, "", + (n->flags & NFLAG_LINE) ? '*' : + (n->flags & NFLAG_SPC) ? ' ' : '-', pnode_name(n->node)); if (n->b != NULL) { putchar(' '); Index: node.h =================================================================== RCS file: /home/cvs/mdocml/docbook2mdoc/node.h,v retrieving revision 1.32 retrieving revision 1.33 diff -Lnode.h -Lnode.h -u -p -r1.32 -r1.33 --- node.h +++ node.h @@ -231,8 +231,10 @@ struct pattr { struct pnode { enum nodeid node; /* Node type. */ char *b; /* String value. */ - int spc; /* Whitespace before this node. */ struct pnode *parent; /* Parent node or NULL. */ + int flags; +#define NFLAG_LINE (1 << 0) /* New line before this node. */ +#define NFLAG_SPC (1 << 1) /* Whitespace before this node. */ struct pnodeq childq; /* Queue of children. */ struct pattrq attrq; /* Attributes of the node. */ TAILQ_ENTRY(pnode) child; -- To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv