version 1.92, 2019/04/06 22:37:57 |
version 1.94, 2019/04/07 14:49:26 |
Line 32 static void pnode_print(struct format *, struct pnode |
|
Line 32 static void pnode_print(struct format *, struct pnode |
|
|
|
|
|
static void |
static void |
|
pnode_printtext(struct format *f, struct pnode *n) |
|
{ |
|
struct pnode *nn; |
|
char *cp; |
|
char last; |
|
|
|
if (n->bsz == 0) { |
|
assert(n->real < n->b); |
|
return; |
|
} |
|
|
|
/* |
|
* Text preceding a macro without intervening whitespace |
|
* requires a .Pf macro. |
|
* Set the spacing flag to avoid a redundant .Ns macro. |
|
*/ |
|
|
|
if (f->linestate != LINE_MACRO && |
|
(nn = TAILQ_NEXT(n, child)) != NULL && nn->spc == 0 && |
|
(nn->node != NODE_TEXT && nn->node != NODE_ESCAPE)) { |
|
macro_open(f, "Pf"); |
|
nn->spc = 1; |
|
} |
|
|
|
if (f->linestate == LINE_NEW) { |
|
last = '\n'; |
|
f->linestate = LINE_TEXT; |
|
} else { |
|
last = ' '; |
|
if (n->spc || f->linestate == LINE_MACRO) |
|
putchar(' '); |
|
} |
|
|
|
if (n->node == NODE_ESCAPE) { |
|
fputs(n->b, stdout); |
|
return; |
|
} |
|
|
|
/* |
|
* Remove the prefix '-' from <option> elements |
|
* because the arguments of .Fl macros do not need it. |
|
*/ |
|
|
|
cp = n->b; |
|
if (n->parent != NULL && n->parent->node == NODE_OPTION && *cp == '-') |
|
cp++; |
|
|
|
/* |
|
* Print the text, skipping whitespace on new lines, |
|
* escaping control characters on new lines, |
|
* and escaping backslashes. |
|
*/ |
|
|
|
for (; *cp != '\0'; cp++) { |
|
if (last == '\n') { |
|
if (isspace((unsigned char)*cp)) |
|
continue; |
|
if (*cp == '\'' || *cp == '.') |
|
fputs("\\&", stdout); |
|
} |
|
putchar(last = *cp); |
|
if (last == '\\') |
|
putchar('e'); |
|
} |
|
} |
|
|
|
static void |
pnode_printpara(struct format *p, struct pnode *pn) |
pnode_printpara(struct format *p, struct pnode *pn) |
{ |
{ |
struct pnode *pp; |
struct pnode *pp; |
Line 635 pnode_print(struct format *p, struct pnode *pn) |
|
Line 702 pnode_print(struct format *p, struct pnode *pn) |
|
{ |
{ |
struct pnode *pp; |
struct pnode *pp; |
const char *ccp; |
const char *ccp; |
char *cp; |
|
int last; |
|
enum linestate sv; |
enum linestate sv; |
|
|
if (pn == NULL) |
if (pn == NULL) |
Line 691 pnode_print(struct format *p, struct pnode *pn) |
|
Line 756 pnode_print(struct format *p, struct pnode *pn) |
|
case NODE_ERRORNAME: |
case NODE_ERRORNAME: |
macro_open(p, "Er"); |
macro_open(p, "Er"); |
break; |
break; |
case NODE_ESCAPE: |
|
if (p->linestate == LINE_NEW) |
|
p->linestate = LINE_TEXT; |
|
else if (pn->spc || p->linestate == LINE_MACRO) |
|
putchar(' '); |
|
fputs(pn->b, stdout); |
|
break; |
|
case NODE_FILENAME: |
case NODE_FILENAME: |
macro_open(p, "Pa"); |
macro_open(p, "Pa"); |
break; |
break; |
Line 818 pnode_print(struct format *p, struct pnode *pn) |
|
Line 876 pnode_print(struct format *p, struct pnode *pn) |
|
macro_open(p, "Ic"); |
macro_open(p, "Ic"); |
break; |
break; |
case NODE_TEXT: |
case NODE_TEXT: |
if (pn->bsz == 0) { |
case NODE_ESCAPE: |
assert(pn->real != pn->b); |
pnode_printtext(p, pn); |
break; |
|
} |
|
if (p->linestate == LINE_NEW) |
|
p->linestate = LINE_TEXT; |
|
else if (pn->spc || p->linestate == LINE_MACRO) |
|
putchar(' '); |
|
|
|
/* |
|
* Output all characters, squeezing out whitespace |
|
* between newlines. |
|
* XXX: all whitespace, including tabs (?). |
|
* Remember to escape control characters and escapes. |
|
*/ |
|
cp = pn->b; |
|
|
|
/* |
|
* There's often a superfluous "-" in its <option> tags |
|
* before the actual flags themselves. |
|
* "Fl" does this for us, so remove it. |
|
*/ |
|
if (pn->parent != NULL && |
|
pn->parent->node == NODE_OPTION && |
|
*cp == '-') |
|
cp++; |
|
for (last = '\n'; *cp != '\0'; ) { |
|
if (last == '\n') { |
|
/* Consume all whitespace. */ |
|
if (isspace((unsigned char)*cp)) { |
|
while (isspace((unsigned char)*cp)) |
|
cp++; |
|
continue; |
|
} else if (*cp == '\'' || *cp == '.') |
|
fputs("\\&", stdout); |
|
} |
|
putchar(last = *cp++); |
|
/* If we're a character escape, escape us. */ |
|
if (last == '\\') |
|
putchar('e'); |
|
} |
|
break; |
break; |
case NODE_TGROUP: |
case NODE_TGROUP: |
pnode_printtgroup(p, pn); |
pnode_printtgroup(p, pn); |