version 1.92, 2019/04/06 22:37:57 |
version 1.95, 2019/04/07 15:06:56 |
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 129 pnode_printrefsect(struct format *p, struct pnode *pn) |
|
Line 196 pnode_printrefsect(struct format *p, struct pnode *pn) |
|
|
|
switch (level) { |
switch (level) { |
case 1: |
case 1: |
|
macro_close(p); |
macro_open(p, "Sh"); |
macro_open(p, "Sh"); |
break; |
break; |
case 2: |
case 2: |
|
macro_close(p); |
macro_open(p, "Ss"); |
macro_open(p, "Ss"); |
break; |
break; |
default: |
default: |
Line 187 pnode_printrefmeta(struct format *p, struct pnode *pn) |
|
Line 256 pnode_printrefmeta(struct format *p, struct pnode *pn) |
|
else if (pp->node == NODE_REFENTRYTITLE) |
else if (pp->node == NODE_REFENTRYTITLE) |
title = pp; |
title = pp; |
} |
} |
|
macro_close(p); |
macro_open(p, "Dt"); |
macro_open(p, "Dt"); |
if (title == NULL) |
if (title == NULL) |
macro_addarg(p, "UNKNOWN", ARG_SPACE); |
macro_addarg(p, "UNKNOWN", ARG_SPACE); |
Line 487 pnode_printvarlistentry(struct format *p, struct pnode |
|
Line 557 pnode_printvarlistentry(struct format *p, struct pnode |
|
struct pnode *pp; |
struct pnode *pp; |
int first = 1; |
int first = 1; |
|
|
|
macro_close(p); |
macro_open(p, "It"); |
macro_open(p, "It"); |
TAILQ_FOREACH(pp, &pn->childq, child) { |
TAILQ_FOREACH(pp, &pn->childq, child) { |
if (pp->node != NODE_TERM) |
if (pp->node != NODE_TERM) |
Line 555 pnode_printtgroup2(struct format *f, struct pnode *n) |
|
Line 626 pnode_printtgroup2(struct format *f, struct pnode *n) |
|
while ((nr = pnode_findfirst(n, NODE_ROW)) != NULL) { |
while ((nr = pnode_findfirst(n, NODE_ROW)) != NULL) { |
if ((ne = pnode_findfirst(n, NODE_ENTRY)) == NULL) |
if ((ne = pnode_findfirst(n, NODE_ENTRY)) == NULL) |
break; |
break; |
|
macro_close(f); |
macro_open(f, "It"); |
macro_open(f, "It"); |
pnode_print(f, ne); |
pnode_print(f, ne); |
macro_close(f); |
macro_close(f); |
Line 635 pnode_print(struct format *p, struct pnode *pn) |
|
Line 707 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 761 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 740 pnode_print(struct format *p, struct pnode *pn) |
|
Line 803 pnode_print(struct format *p, struct pnode *pn) |
|
macro_open(p, "Ql"); |
macro_open(p, "Ql"); |
break; |
break; |
case NODE_LITERALLAYOUT: |
case NODE_LITERALLAYOUT: |
|
macro_close(p); |
macro_argline(p, "Bd", pnode_getattr(pn, ATTRKEY_CLASS) == |
macro_argline(p, "Bd", pnode_getattr(pn, ATTRKEY_CLASS) == |
ATTRVAL_MONOSPACED ? "-literal" : "-unfilled"); |
ATTRVAL_MONOSPACED ? "-literal" : "-unfilled"); |
break; |
break; |
Line 818 pnode_print(struct format *p, struct pnode *pn) |
|
Line 882 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); |