version 1.41, 2014/10/12 15:34:44 |
version 1.48, 2019/03/22 15:38:09 |
|
|
enum nodeid node; /* current (NODE_ROOT if pre-tree) */ |
enum nodeid node; /* current (NODE_ROOT if pre-tree) */ |
const char *fname; /* filename */ |
const char *fname; /* filename */ |
int stop; /* should we stop now? */ |
int stop; /* should we stop now? */ |
|
#define PARSE_EQN 1 |
|
unsigned int flags; /* document-wide flags */ |
struct pnode *root; /* root of parse tree */ |
struct pnode *root; /* root of parse tree */ |
struct pnode *cur; /* current node in tree */ |
struct pnode *cur; /* current node in tree */ |
char *b; /* nil-terminated buffer for pre-print */ |
char *b; /* NUL-terminated buffer for pre-print */ |
size_t bsz; /* current length of b */ |
size_t bsz; /* current length of b */ |
size_t mbsz; /* max bsz allocation */ |
size_t mbsz; /* max bsz allocation */ |
int newln; /* output: are we on a fresh line */ |
int newln; /* output: are we on a fresh line */ |
Line 89 static const char *attrvals[ATTRVAL__MAX] = { |
|
Line 91 static const char *attrvals[ATTRVAL__MAX] = { |
|
}; |
}; |
|
|
static const struct node nodes[NODE__MAX] = { |
static const struct node nodes[NODE__MAX] = { |
{ NULL, 0 }, |
{ NULL, 0 }, |
{ "acronym", 0 }, |
{ "acronym", 0 }, |
{ "anchor", NODE_IGNTEXT }, |
{ "anchor", NODE_IGNTEXT }, |
{ "application", 0 }, |
{ "application", 0 }, |
{ "arg", 0 }, |
{ "arg", 0 }, |
{ "caution", NODE_IGNTEXT }, |
{ "caution", NODE_IGNTEXT }, |
{ "citerefentry", NODE_IGNTEXT }, |
{ "citerefentry", NODE_IGNTEXT }, |
{ "cmdsynopsis", NODE_IGNTEXT }, |
{ "cmdsynopsis", NODE_IGNTEXT }, |
{ "code", 0 }, |
{ "code", 0 }, |
{ "colspec", NODE_IGNTEXT }, |
{ "colspec", NODE_IGNTEXT }, |
{ "command", 0 }, |
{ "command", 0 }, |
{ "constant", 0 }, |
{ "constant", 0 }, |
{ "copyright", NODE_IGNTEXT }, |
{ "copyright", NODE_IGNTEXT }, |
{ "date", 0 }, |
{ "date", 0 }, |
{ "emphasis", 0 }, |
{ "emphasis", 0 }, |
{ "entry", 0 }, |
{ "entry", 0 }, |
{ "envar", 0 }, |
{ "envar", 0 }, |
{ "fieldsynopsis", NODE_IGNTEXT }, |
{ "fieldsynopsis", NODE_IGNTEXT }, |
{ "filename", 0 }, |
{ "filename", 0 }, |
{ "funcdef", 0 }, |
{ "funcdef", 0 }, |
{ "funcprototype", NODE_IGNTEXT }, |
{ "funcprototype", NODE_IGNTEXT }, |
{ "funcsynopsis", NODE_IGNTEXT }, |
{ "funcsynopsis", NODE_IGNTEXT }, |
{ "funcsynopsisinfo", 0 }, |
{ "funcsynopsisinfo", 0 }, |
{ "function", 0 }, |
{ "function", 0 }, |
{ "group", NODE_IGNTEXT }, |
{ "group", NODE_IGNTEXT }, |
{ "holder", NODE_IGNTEXT }, |
{ "holder", NODE_IGNTEXT }, |
{ "info", NODE_IGNTEXT }, |
{ "info", NODE_IGNTEXT }, |
{ "informalequation", NODE_IGNTEXT }, |
{ "informalequation", NODE_IGNTEXT }, |
{ "informaltable", NODE_IGNTEXT }, |
{ "informaltable", NODE_IGNTEXT }, |
{ "inlineequation", NODE_IGNTEXT }, |
{ "inlineequation", NODE_IGNTEXT }, |
{ "itemizedlist", NODE_IGNTEXT }, |
{ "itemizedlist", NODE_IGNTEXT }, |
{ "link", 0 }, |
{ "link", 0 }, |
{ "listitem", NODE_IGNTEXT }, |
{ "listitem", NODE_IGNTEXT }, |
{ "literal", 0 }, |
{ "literal", 0 }, |
{ "manvolnum", 0 }, |
{ "manvolnum", 0 }, |
{ "mml:math", NODE_IGNTEXT }, |
{ "mml:math", NODE_IGNTEXT }, |
{ "mml:mfenced", 0 }, |
{ "mml:mfenced", 0 }, |
{ "mml:mfrac", 0 }, |
{ "mml:mfrac", 0 }, |
{ "mml:mi", 0 }, |
{ "mml:mi", 0 }, |
{ "mml:mn", 0 }, |
{ "mml:mn", 0 }, |
{ "mml:mo", 0 }, |
{ "mml:mo", 0 }, |
{ "mml:mrow", 0 }, |
{ "mml:mrow", 0 }, |
{ "mml:msub", 0 }, |
{ "mml:msub", 0 }, |
{ "mml:msup", 0 }, |
{ "mml:msup", 0 }, |
{ "modifier", 0 }, |
{ "modifier", 0 }, |
{ "note", NODE_IGNTEXT }, |
{ "note", NODE_IGNTEXT }, |
{ "option", 0 }, |
{ "option", 0 }, |
{ "orderedlist", NODE_IGNTEXT }, |
{ "orderedlist", NODE_IGNTEXT }, |
{ "para", 0 }, |
{ "para", 0 }, |
{ "paramdef", 0 }, |
{ "paramdef", 0 }, |
{ "parameter", 0 }, |
{ "parameter", 0 }, |
{ "programlisting", 0 }, |
{ "programlisting", 0 }, |
{ "prompt", 0 }, |
{ "prompt", 0 }, |
{ "quote", 0 }, |
{ "quote", 0 }, |
{ "refclass", NODE_IGNTEXT }, |
{ "refclass", NODE_IGNTEXT }, |
{ "refdescriptor", NODE_IGNTEXT }, |
{ "refdescriptor", NODE_IGNTEXT }, |
{ "refentry", NODE_IGNTEXT }, |
{ "refentry", NODE_IGNTEXT }, |
{ "refentryinfo", NODE_IGNTEXT }, |
{ "refentryinfo", NODE_IGNTEXT }, |
{ "refentrytitle", 0 }, |
{ "refentrytitle", 0 }, |
{ "refmeta", NODE_IGNTEXT }, |
{ "refmeta", NODE_IGNTEXT }, |
{ "refmetainfo", NODE_IGNTEXT }, |
{ "refmetainfo", NODE_IGNTEXT }, |
{ "refmiscinfo", NODE_IGNTEXT }, |
{ "refmiscinfo", NODE_IGNTEXT }, |
{ "refname", 0 }, |
{ "refname", 0 }, |
{ "refnamediv", NODE_IGNTEXT }, |
{ "refnamediv", NODE_IGNTEXT }, |
{ "refpurpose", 0 }, |
{ "refpurpose", 0 }, |
{ "refsect1", NODE_IGNTEXT }, |
{ "refsect1", NODE_IGNTEXT }, |
{ "refsect2", NODE_IGNTEXT }, |
{ "refsect2", NODE_IGNTEXT }, |
{ "refsect3", NODE_IGNTEXT }, |
{ "refsect3", NODE_IGNTEXT }, |
{ "refsection", NODE_IGNTEXT }, |
{ "refsection", NODE_IGNTEXT }, |
{ "refsynopsisdiv", NODE_IGNTEXT }, |
{ "refsynopsisdiv", NODE_IGNTEXT }, |
{ "replaceable", 0 }, |
{ "replaceable", 0 }, |
{ "row", NODE_IGNTEXT }, |
{ "row", NODE_IGNTEXT }, |
{ "sbr", NODE_IGNTEXT }, |
{ "sbr", NODE_IGNTEXT }, |
{ "screen", NODE_IGNTEXT }, |
{ "screen", NODE_IGNTEXT }, |
{ "sgmltag", 0 }, |
{ "sgmltag", 0 }, |
{ "structname", 0 }, |
{ "structname", 0 }, |
{ "synopsis", 0 }, |
{ "synopsis", 0 }, |
{ "table", NODE_IGNTEXT }, |
{ "table", NODE_IGNTEXT }, |
{ "tbody", NODE_IGNTEXT }, |
{ "tbody", NODE_IGNTEXT }, |
{ "term", 0 }, |
{ "term", 0 }, |
{ NULL, 0 }, |
{ NULL, 0 }, |
{ "tfoot", NODE_IGNTEXT }, |
{ "tfoot", NODE_IGNTEXT }, |
{ "tgroup", NODE_IGNTEXT }, |
{ "tgroup", NODE_IGNTEXT }, |
{ "thead", NODE_IGNTEXT }, |
{ "thead", NODE_IGNTEXT }, |
{ "tip", NODE_IGNTEXT }, |
{ "tip", NODE_IGNTEXT }, |
{ "title", 0 }, |
{ "title", 0 }, |
{ "trademark", 0 }, |
{ "trademark", 0 }, |
{ "type", 0 }, |
{ "type", 0 }, |
{ "ulink", 0 }, |
{ "ulink", 0 }, |
{ "userinput", 0 }, |
{ "userinput", 0 }, |
{ "variablelist", NODE_IGNTEXT }, |
{ "variablelist", NODE_IGNTEXT }, |
{ "varlistentry", NODE_IGNTEXT }, |
{ "varlistentry", NODE_IGNTEXT }, |
{ "varname", 0 }, |
{ "varname", 0 }, |
{ "warning", NODE_IGNTEXT }, |
{ "warning", NODE_IGNTEXT }, |
{ "wordasword", 0 }, |
{ "wordasword", 0 }, |
{ "year", NODE_IGNTEXT }, |
{ "year", NODE_IGNTEXT }, |
}; |
}; |
|
|
static int warn = 0; |
static int warn = 0; |
Line 223 xml_char(void *arg, const XML_Char *p, int sz) |
|
Line 225 xml_char(void *arg, const XML_Char *p, int sz) |
|
*/ |
*/ |
if (NODE_TEXT != ps->node) { |
if (NODE_TEXT != ps->node) { |
for (i = 0; i < sz; i++) |
for (i = 0; i < sz; i++) |
if ( ! isspace((int)p[i])) |
if ( ! isspace((unsigned char)p[i])) |
break; |
break; |
if (i == sz) |
if (i == sz) |
return; |
return; |
Line 246 xml_char(void *arg, const XML_Char *p, int sz) |
|
Line 248 xml_char(void *arg, const XML_Char *p, int sz) |
|
|
|
/* Append to current buffer. */ |
/* Append to current buffer. */ |
assert(sz >= 0); |
assert(sz >= 0); |
ps->cur->b = realloc(ps->cur->b, |
ps->cur->b = realloc(ps->cur->b, |
ps->cur->bsz + (size_t)sz); |
ps->cur->bsz + (size_t)sz); |
if (NULL == ps->cur->b) { |
if (NULL == ps->cur->b) { |
perror(NULL); |
perror(NULL); |
Line 263 pnode_trim(struct pnode *pn) |
|
Line 265 pnode_trim(struct pnode *pn) |
|
|
|
assert(NODE_TEXT == pn->node); |
assert(NODE_TEXT == pn->node); |
for ( ; pn->bsz > 0; pn->bsz--) |
for ( ; pn->bsz > 0; pn->bsz--) |
if ( ! isspace((int)pn->b[pn->bsz - 1])) |
if ( ! isspace((unsigned char)pn->b[pn->bsz - 1])) |
break; |
break; |
} |
} |
|
|
Line 305 xml_elem_start(void *arg, const XML_Char *name, const |
|
Line 307 xml_elem_start(void *arg, const XML_Char *name, const |
|
ps->node = ps->cur->node; |
ps->node = ps->cur->node; |
} |
} |
|
|
|
|
for (node = 0; node < NODE__MAX; node++) |
for (node = 0; node < NODE__MAX; node++) |
if (NULL == nodes[node].name) |
if (NULL == nodes[node].name) |
continue; |
continue; |
Line 315 xml_elem_start(void *arg, const XML_Char *name, const |
|
Line 316 xml_elem_start(void *arg, const XML_Char *name, const |
|
if (NODE__MAX == node && NODE_ROOT == ps->node) { |
if (NODE__MAX == node && NODE_ROOT == ps->node) { |
return; |
return; |
} else if (NODE__MAX == node) { |
} else if (NODE__MAX == node) { |
fprintf(stderr, "%s:%zu:%zu: unknown node \"%s\"\n", |
fprintf(stderr, "%s:%zu:%zu: unknown node \"%s\"\n", |
ps->fname, XML_GetCurrentLineNumber(ps->xml), |
ps->fname, XML_GetCurrentLineNumber(ps->xml), |
XML_GetCurrentColumnNumber(ps->xml), name); |
XML_GetCurrentColumnNumber(ps->xml), name); |
ps->stop = 1; |
ps->stop = 1; |
Line 326 xml_elem_start(void *arg, const XML_Char *name, const |
|
Line 327 xml_elem_start(void *arg, const XML_Char *name, const |
|
XML_GetCurrentColumnNumber(ps->xml)); |
XML_GetCurrentColumnNumber(ps->xml)); |
ps->stop = 1; |
ps->stop = 1; |
return; |
return; |
} else if (NODE_ROOT == ps->node && NODE_REFENTRY != node) { |
} else if (NODE_ROOT == ps->node && NODE_REFENTRY != node) |
return; |
return; |
} else if ( ! isparent(node, ps->node)) { |
|
fprintf(stderr, "%s:%zu:%zu: bad parent \"%s\" " |
|
"of node \"%s\"\n", |
|
ps->fname, XML_GetCurrentLineNumber(ps->xml), |
|
XML_GetCurrentColumnNumber(ps->xml), |
|
NULL == nodes[ps->node].name ? |
|
"(none)" : nodes[ps->node].name, |
|
NULL == nodes[node].name ? |
|
"(none)" : nodes[node].name); |
|
ps->stop = 1; |
|
return; |
|
} |
|
|
|
|
if (NODE_INLINEEQUATION == node) |
|
ps->flags |= PARSE_EQN; |
|
|
if (NULL == (dat = calloc(1, sizeof(struct pnode)))) { |
if (NULL == (dat = calloc(1, sizeof(struct pnode)))) { |
perror(NULL); |
perror(NULL); |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
Line 366 xml_elem_start(void *arg, const XML_Char *name, const |
|
Line 358 xml_elem_start(void *arg, const XML_Char *name, const |
|
if (0 == strcmp(*att, attrkeys[key])) |
if (0 == strcmp(*att, attrkeys[key])) |
break; |
break; |
if (ATTRKEY__MAX == key) { |
if (ATTRKEY__MAX == key) { |
if (warn) |
if (warn) |
fprintf(stderr, "%s:%zu:%zu: warning: " |
fprintf(stderr, "%s:%zu:%zu: warning: " |
"unknown attribute \"%s\"\n", |
"unknown attribute \"%s\"\n", |
ps->fname, |
ps->fname, |
XML_GetCurrentLineNumber(ps->xml), |
XML_GetCurrentLineNumber(ps->xml), |
XML_GetCurrentColumnNumber(ps->xml), |
XML_GetCurrentColumnNumber(ps->xml), |
*att); |
*att); |
continue; |
continue; |
} else if ( ! isattrkey(node, key)) { |
} else if ( ! isattrkey(node, key)) { |
if (warn) |
if (warn) |
fprintf(stderr, "%s:%zu:%zu: warning: " |
fprintf(stderr, "%s:%zu:%zu: warning: " |
"bad attribute \"%s\"\n", |
"bad attribute \"%s\"\n", |
ps->fname, |
ps->fname, |
XML_GetCurrentLineNumber(ps->xml), |
XML_GetCurrentLineNumber(ps->xml), |
XML_GetCurrentColumnNumber(ps->xml), |
XML_GetCurrentColumnNumber(ps->xml), |
*att); |
*att); |
continue; |
continue; |
} |
} |
Line 390 xml_elem_start(void *arg, const XML_Char *name, const |
|
Line 382 xml_elem_start(void *arg, const XML_Char *name, const |
|
if (ATTRVAL__MAX != val && ! isattrval(key, val)) { |
if (ATTRVAL__MAX != val && ! isattrval(key, val)) { |
if (warn) |
if (warn) |
fprintf(stderr, "%s:%zu:%zu: warning: " |
fprintf(stderr, "%s:%zu:%zu: warning: " |
"bad attribute value \"%s\"\n", |
"bad attribute value \"%s\"\n", |
ps->fname, |
ps->fname, |
XML_GetCurrentLineNumber(ps->xml), |
XML_GetCurrentLineNumber(ps->xml), |
XML_GetCurrentColumnNumber(ps->xml), |
XML_GetCurrentColumnNumber(ps->xml), |
*(att + 1)); |
*(att + 1)); |
continue; |
continue; |
} |
} |
Line 501 bufclear(struct parse *p) |
|
Line 493 bufclear(struct parse *p) |
|
/* |
/* |
* Append NODE_TEXT contents to the current buffer, reallocating its |
* Append NODE_TEXT contents to the current buffer, reallocating its |
* size if necessary. |
* size if necessary. |
* The buffer is ALWAYS nil-terminated. |
* The buffer is ALWAYS NUL-terminated. |
*/ |
*/ |
static void |
static void |
bufappend(struct parse *p, struct pnode *pn) |
bufappend(struct parse *p, struct pnode *pn) |
Line 537 bufappend_r(struct parse *p, struct pnode *pn) |
|
Line 529 bufappend_r(struct parse *p, struct pnode *pn) |
|
bufappend_r(p, pp); |
bufappend_r(p, pp); |
} |
} |
|
|
/* |
/* |
* Recursively search and return the first instance of "node". |
* Recursively search and return the first instance of "node". |
*/ |
*/ |
static struct pnode * |
static struct pnode * |
Line 576 pnode_printmacrolinetext(struct parse *p, struct pnode |
|
Line 568 pnode_printmacrolinetext(struct parse *p, struct pnode |
|
|
|
/* Convert all space to spaces. */ |
/* Convert all space to spaces. */ |
for (cp = p->b; '\0' != *cp; cp++) |
for (cp = p->b; '\0' != *cp; cp++) |
if (isspace((int)*cp)) |
if (isspace((unsigned char)*cp)) |
*cp = ' '; |
*cp = ' '; |
|
|
for (cp = p->b; isspace((int)*cp); cp++) |
for (cp = p->b; isspace((unsigned char)*cp); cp++) |
/* Spin past whitespace (XXX: necessary?) */ ; |
/* Spin past whitespace (XXX: necessary?) */ ; |
for ( ; '\0' != *cp; cp++) { |
for ( ; '\0' != *cp; cp++) { |
/* Escape us if we look like a macro. */ |
/* Escape us if we look like a macro. */ |
if ((cp == p->b || ' ' == *(cp - 1)) && |
if ((cp == p->b || ' ' == *(cp - 1)) && |
isupper((int)*cp) && |
isupper((unsigned char)*cp) && |
'\0' != *(cp + 1) && |
'\0' != *(cp + 1) && |
islower((int)*(cp + 1)) && |
islower((unsigned char)*(cp + 1)) && |
('\0' == *(cp + 2) || |
('\0' == *(cp + 2) || |
' ' == *(cp + 2) || |
' ' == *(cp + 2) || |
(islower((int)*(cp + 2)) && |
(islower((unsigned char)*(cp + 2)) && |
('\0' == *(cp + 3) || |
('\0' == *(cp + 3) || |
' ' == *(cp + 3))))) |
' ' == *(cp + 3))))) |
fputs("\\&", stdout); |
fputs("\\&", stdout); |
if (MACROLINE_UPPER & fl) |
if (MACROLINE_UPPER & fl) |
putchar(toupper((int)*cp)); |
putchar(toupper((unsigned char)*cp)); |
else |
else |
putchar((int)*cp); |
putchar(*cp); |
/* If we're a character escape, escape us. */ |
/* If we're a character escape, escape us. */ |
if ('\\' == *cp) |
if ('\\' == *cp) |
putchar('e'); |
putchar('e'); |
|
|
pnode_printmclosepunct(struct parse *p, struct pnode *pn, int sv) |
pnode_printmclosepunct(struct parse *p, struct pnode *pn, int sv) |
{ |
{ |
/* We wouldn't have done anything anyway. */ |
/* We wouldn't have done anything anyway. */ |
if ( ! (sv && ! p->newln)) |
if ( ! (sv && ! p->newln)) |
return; |
return; |
|
|
/* No next node or it's not text. */ |
/* No next node or it's not text. */ |
Line 663 pnode_printmclosepunct(struct parse *p, struct pnode * |
|
Line 655 pnode_printmclosepunct(struct parse *p, struct pnode * |
|
} else if (NODE_TEXT != pn->node) { |
} else if (NODE_TEXT != pn->node) { |
pnode_printmclose(p, sv); |
pnode_printmclose(p, sv); |
return; |
return; |
} |
} |
|
|
/* Only do this for the comma/period. */ |
/* Only do this for the comma/period. */ |
if (pn->bsz > 0 && |
if (pn->bsz > 0 && |
(',' == pn->b[0] || '.' == pn->b[0]) && |
(',' == pn->b[0] || '.' == pn->b[0]) && |
(1 == pn->bsz || isspace((int)pn->b[1]))) { |
(1 == pn->bsz || isspace((unsigned char)pn->b[1]))) { |
putchar(' '); |
putchar(' '); |
putchar(pn->b[0]); |
putchar(pn->b[0]); |
pn->b++; |
pn->b++; |
pn->bsz--; |
pn->bsz--; |
} |
} |
|
|
putchar('\n'); |
putchar('\n'); |
p->newln = 1; |
p->newln = 1; |
Line 687 pnode_printrefsynopsisdiv(struct parse *p, struct pnod |
|
Line 679 pnode_printrefsynopsisdiv(struct parse *p, struct pnod |
|
{ |
{ |
struct pnode *pp; |
struct pnode *pp; |
|
|
TAILQ_FOREACH(pp, &pn->childq, child) |
TAILQ_FOREACH(pp, &pn->childq, child) |
if (NODE_TITLE == pp->node) { |
if (NODE_TITLE == pp->node) { |
pnode_unlink(pp); |
pnode_unlink(pp); |
return; |
return; |
Line 738 pnode_printrefsect(struct parse *p, struct pnode *pn) |
|
Line 730 pnode_printrefsect(struct parse *p, struct pnode *pn) |
|
p->newln = 0; |
p->newln = 0; |
|
|
if (NULL != pp) { |
if (NULL != pp) { |
pnode_printmacrolinetext(p, pp, |
pnode_printmacrolinetext(p, pp, |
NODE_REFSECT1 == pn->node ? |
NODE_REFSECT1 == pn->node ? |
MACROLINE_UPPER : 0); |
MACROLINE_UPPER : 0); |
pnode_printmclose(p, 1); |
pnode_printmclose(p, 1); |
Line 917 pnode_printmath(struct parse *p, struct pnode *pn) |
|
Line 909 pnode_printmath(struct parse *p, struct pnode *pn) |
|
|
|
switch (pn->node) { |
switch (pn->node) { |
case (NODE_MML_MSUP): |
case (NODE_MML_MSUP): |
printf(" sup "); |
fputs(" sup ", stdout); |
break; |
break; |
case (NODE_MML_MFRAC): |
case (NODE_MML_MFRAC): |
printf(" over "); |
fputs(" over ", stdout); |
break; |
break; |
case (NODE_MML_MSUB): |
case (NODE_MML_MSUB): |
printf(" sub "); |
fputs(" sub ", stdout); |
break; |
break; |
default: |
default: |
break; |
break; |
Line 940 pnode_printfuncprototype(struct parse *p, struct pnode |
|
Line 932 pnode_printfuncprototype(struct parse *p, struct pnode |
|
|
|
assert(p->newln); |
assert(p->newln); |
TAILQ_FOREACH(fdef, &pn->childq, child) |
TAILQ_FOREACH(fdef, &pn->childq, child) |
if (NODE_FUNCDEF == fdef->node) |
if (NODE_FUNCDEF == fdef->node) |
break; |
break; |
|
|
if (NULL != fdef) |
if (NULL != fdef) |
Line 948 pnode_printfuncprototype(struct parse *p, struct pnode |
|
Line 940 pnode_printfuncprototype(struct parse *p, struct pnode |
|
else |
else |
puts(".Fo UNKNOWN"); |
puts(".Fo UNKNOWN"); |
|
|
TAILQ_FOREACH(pp, &pn->childq, child) |
TAILQ_FOREACH(pp, &pn->childq, child) |
if (NODE_PARAMDEF == pp->node) |
if (NODE_PARAMDEF == pp->node) |
pnode_printparamdef(p, pp); |
pnode_printparamdef(p, pp); |
|
|
Line 956 pnode_printfuncprototype(struct parse *p, struct pnode |
|
Line 948 pnode_printfuncprototype(struct parse *p, struct pnode |
|
p->newln = 1; |
p->newln = 1; |
} |
} |
|
|
/* |
/* |
* The <arg> element is more complicated than it should be because text |
* The <arg> element is more complicated than it should be because text |
* nodes are treated like ".Ar foo", but non-text nodes need to be |
* nodes are treated like ".Ar foo", but non-text nodes need to be |
* re-sent into the printer (i.e., without the preceding ".Ar"). |
* re-sent into the printer (i.e., without the preceding ".Ar"). |
Line 972 pnode_printarg(struct parse *p, struct pnode *pn) |
|
Line 964 pnode_printarg(struct parse *p, struct pnode *pn) |
|
|
|
isop = 1; |
isop = 1; |
isrep = 0; |
isrep = 0; |
TAILQ_FOREACH(ap, &pn->attrq, child) |
TAILQ_FOREACH(ap, &pn->attrq, child) |
if (ATTRKEY_CHOICE == ap->key && |
if (ATTRKEY_CHOICE == ap->key && |
(ATTRVAL_PLAIN == ap->val || |
(ATTRVAL_PLAIN == ap->val || |
ATTRVAL_REQ == ap->val)) |
ATTRVAL_REQ == ap->val)) |
isop = 0; |
isop = 0; |
else if (ATTRKEY_REP == ap->key && |
else if (ATTRKEY_REP == ap->key && |
(ATTRVAL_REPEAT == ap->val)) |
(ATTRVAL_REPEAT == ap->val)) |
Line 990 pnode_printarg(struct parse *p, struct pnode *pn) |
|
Line 982 pnode_printarg(struct parse *p, struct pnode *pn) |
|
if (NODE_TEXT == pp->node) { |
if (NODE_TEXT == pp->node) { |
pnode_printmopen(p); |
pnode_printmopen(p); |
fputs("Ar", stdout); |
fputs("Ar", stdout); |
} |
} |
pnode_print(p, pp); |
pnode_print(p, pp); |
if (NODE_TEXT == pp->node && isrep) |
if (NODE_TEXT == pp->node && isrep) |
fputs("...", stdout); |
fputs("...", stdout); |
} |
} |
} |
} |
Line 1005 pnode_printgroup(struct parse *p, struct pnode *pn) |
|
Line 997 pnode_printgroup(struct parse *p, struct pnode *pn) |
|
int isop, sv; |
int isop, sv; |
|
|
isop = 1; |
isop = 1; |
TAILQ_FOREACH(ap, &pn->attrq, child) |
TAILQ_FOREACH(ap, &pn->attrq, child) |
if (ATTRKEY_CHOICE == ap->key && |
if (ATTRKEY_CHOICE == ap->key && |
(ATTRVAL_PLAIN == ap->val || |
(ATTRVAL_PLAIN == ap->val || |
ATTRVAL_REQ == ap->val)) { |
ATTRVAL_REQ == ap->val)) { |
Line 1013 pnode_printgroup(struct parse *p, struct pnode *pn) |
|
Line 1005 pnode_printgroup(struct parse *p, struct pnode *pn) |
|
break; |
break; |
} |
} |
|
|
/* |
/* |
* Make sure we're on a macro line. |
* Make sure we're on a macro line. |
* This will prevent pnode_print() for putting us on a |
* This will prevent pnode_print() for putting us on a |
* subsequent line. |
* subsequent line. |
*/ |
*/ |
sv = p->newln; |
sv = p->newln; |
pnode_printmopen(p); |
pnode_printmopen(p); |
if (isop) |
if (isop) |
fputs("Op", stdout); |
fputs("Op", stdout); |
else if (sv) |
else if (sv) |
fputs("No", stdout); |
fputs("No", stdout); |
Line 1066 pnode_printprologue(struct parse *p, struct pnode *pn) |
|
Line 1058 pnode_printprologue(struct parse *p, struct pnode *pn) |
|
puts(".Dt UNKNOWN 1"); |
puts(".Dt UNKNOWN 1"); |
puts(".Os"); |
puts(".Os"); |
} |
} |
|
|
|
if (PARSE_EQN & p->flags) { |
|
puts(".EQ"); |
|
puts("delim $$"); |
|
puts(".EN"); |
|
} |
} |
} |
|
|
|
/* |
|
* We can have multiple <term> elements within a <varlistentry>, which |
|
* we should comma-separate as list headers. |
|
*/ |
static void |
static void |
pnode_printvarlistentry(struct parse *p, struct pnode *pn) |
pnode_printvarlistentry(struct parse *p, struct pnode *pn) |
{ |
{ |
struct pnode *pp; |
struct pnode *pp; |
|
int first = 1; |
|
|
assert(p->newln); |
assert(p->newln); |
|
fputs(".It", stdout); |
|
p->newln = 0; |
|
|
TAILQ_FOREACH(pp, &pn->childq, child) |
TAILQ_FOREACH(pp, &pn->childq, child) |
if (NODE_TERM == pp->node) { |
if (NODE_TERM == pp->node) { |
assert(p->newln); |
if ( ! first) |
fputs(".It", stdout); |
putchar(','); |
p->newln = 0; |
|
pnode_print(p, pp); |
pnode_print(p, pp); |
pnode_unlink(pp); |
pnode_unlink(pp); |
pnode_printmclose(p, 1); |
first = 0; |
return; |
} else |
} |
break; |
|
|
puts(".It"); |
putchar('\n'); |
p->newln = 1; |
p->newln = 1; |
} |
} |
|
|
Line 1260 pnode_print(struct parse *p, struct pnode *pn) |
|
Line 1265 pnode_print(struct parse *p, struct pnode *pn) |
|
pnode_printmopen(p); |
pnode_printmopen(p); |
fputs("Fd", stdout); |
fputs("Fd", stdout); |
break; |
break; |
|
case (NODE_INFORMALEQUATION): |
|
if ( ! p->newln) |
|
putchar('\n'); |
|
puts(".EQ"); |
|
p->newln = 0; |
|
break; |
|
case (NODE_INLINEEQUATION): |
|
fputc('$', stdout); |
|
p->newln = 0; |
|
break; |
case (NODE_ITEMIZEDLIST): |
case (NODE_ITEMIZEDLIST): |
assert(p->newln); |
assert(p->newln); |
pnode_printlist(p, pn); |
pnode_printlist(p, pn); |
Line 1273 pnode_print(struct parse *p, struct pnode *pn) |
|
Line 1288 pnode_print(struct parse *p, struct pnode *pn) |
|
pnode_printmopen(p); |
pnode_printmopen(p); |
fputs("Li", stdout); |
fputs("Li", stdout); |
break; |
break; |
case (NODE_MML_MATH): |
|
if ( ! p->newln) |
|
putchar('\n'); |
|
puts(".EQ"); |
|
p->newln = 0; |
|
break; |
|
case (NODE_MML_MFENCED): |
case (NODE_MML_MFENCED): |
pnode_printmathfenced(p, pn); |
pnode_printmathfenced(p, pn); |
pnode_unlinksub(pn); |
pnode_unlinksub(pn); |
Line 1287 pnode_print(struct parse *p, struct pnode *pn) |
|
Line 1296 pnode_print(struct parse *p, struct pnode *pn) |
|
case (NODE_MML_MI): |
case (NODE_MML_MI): |
case (NODE_MML_MN): |
case (NODE_MML_MN): |
case (NODE_MML_MO): |
case (NODE_MML_MO): |
putchar('{'); |
if (TAILQ_EMPTY(&pn->childq)) |
|
break; |
|
fputs(" { ", stdout); |
break; |
break; |
case (NODE_MML_MFRAC): |
case (NODE_MML_MFRAC): |
case (NODE_MML_MSUB): |
case (NODE_MML_MSUB): |
Line 1306 pnode_print(struct parse *p, struct pnode *pn) |
|
Line 1317 pnode_print(struct parse *p, struct pnode *pn) |
|
break; |
break; |
case (NODE_PARA): |
case (NODE_PARA): |
assert(p->newln); |
assert(p->newln); |
if (NULL != pn->parent && |
if (NULL != pn->parent && |
NODE_LISTITEM == pn->parent->node) |
NODE_LISTITEM == pn->parent->node) |
break; |
break; |
puts(".Pp"); |
puts(".Pp"); |
break; |
break; |
Line 1413 pnode_print(struct parse *p, struct pnode *pn) |
|
Line 1424 pnode_print(struct parse *p, struct pnode *pn) |
|
|
|
/* |
/* |
* Output all characters, squeezing out whitespace |
* Output all characters, squeezing out whitespace |
* between newlines. |
* between newlines. |
* XXX: all whitespace, including tabs (?). |
* XXX: all whitespace, including tabs (?). |
* Remember to escape control characters and escapes. |
* Remember to escape control characters and escapes. |
*/ |
*/ |
Line 1432 pnode_print(struct parse *p, struct pnode *pn) |
|
Line 1443 pnode_print(struct parse *p, struct pnode *pn) |
|
for (last = '\n'; '\0' != *cp; ) { |
for (last = '\n'; '\0' != *cp; ) { |
if ('\n' == last) { |
if ('\n' == last) { |
/* Consume all whitespace. */ |
/* Consume all whitespace. */ |
if (isspace((int)*cp)) { |
if (isspace((unsigned char)*cp)) { |
while (isspace((int)*cp)) |
while (isspace((unsigned char)*cp)) |
cp++; |
cp++; |
continue; |
continue; |
} else if ('\'' == *cp || '.' == *cp) |
} else if ('\'' == *cp || '.' == *cp) |
Line 1475 pnode_print(struct parse *p, struct pnode *pn) |
|
Line 1486 pnode_print(struct parse *p, struct pnode *pn) |
|
pnode_print(p, pp); |
pnode_print(p, pp); |
|
|
switch (pn->node) { |
switch (pn->node) { |
case (NODE_MML_MATH): |
case (NODE_INFORMALEQUATION): |
if ( ! p->newln) |
if ( ! p->newln) |
putchar('\n'); |
putchar('\n'); |
puts(".EN"); |
puts(".EN"); |
p->newln = 1; |
p->newln = 1; |
break; |
break; |
|
case (NODE_INLINEEQUATION): |
|
fputs("$ ", stdout); |
|
p->newln = sv; |
|
break; |
case (NODE_MML_MROW): |
case (NODE_MML_MROW): |
case (NODE_MML_MI): |
case (NODE_MML_MI): |
case (NODE_MML_MN): |
case (NODE_MML_MN): |
case (NODE_MML_MO): |
case (NODE_MML_MO): |
putchar('}'); |
if (TAILQ_EMPTY(&pn->childq)) |
|
break; |
|
fputs(" } ", stdout); |
break; |
break; |
case (NODE_APPLICATION): |
case (NODE_APPLICATION): |
case (NODE_ARG): |
case (NODE_ARG): |
Line 1524 pnode_print(struct parse *p, struct pnode *pn) |
|
Line 1541 pnode_print(struct parse *p, struct pnode *pn) |
|
* <refname> macros in sequence, then print out a |
* <refname> macros in sequence, then print out a |
* trailing comma before the newline. |
* trailing comma before the newline. |
*/ |
*/ |
if (NULL != pn->parent && |
if (NULL != pn->parent && |
NODE_REFNAMEDIV == pn->parent->node && |
NODE_REFNAMEDIV == pn->parent->node && |
NULL != TAILQ_NEXT(pn, child) && |
NULL != TAILQ_NEXT(pn, child) && |
NODE_REFNAME == TAILQ_NEXT(pn, child)->node) |
NODE_REFNAME == TAILQ_NEXT(pn, child)->node) |
fputs(" ,", stdout); |
fputs(" ,", stdout); |
pnode_printmclose(p, sv); |
pnode_printmclose(p, sv); |
break; |
break; |
Line 1548 pnode_print(struct parse *p, struct pnode *pn) |
|
Line 1565 pnode_print(struct parse *p, struct pnode *pn) |
|
* Invoke the parser context with each buffer fill. |
* Invoke the parser context with each buffer fill. |
*/ |
*/ |
static int |
static int |
readfile(XML_Parser xp, int fd, |
readfile(XML_Parser xp, int fd, |
char *b, size_t bsz, const char *fn) |
char *b, size_t bsz, const char *fn) |
{ |
{ |
struct parse p; |
struct parse p; |
Line 1569 readfile(XML_Parser xp, int fd, |
|
Line 1586 readfile(XML_Parser xp, int fd, |
|
if (0 == (rc = XML_Parse(xp, b, ssz, 0 == ssz))) |
if (0 == (rc = XML_Parse(xp, b, ssz, 0 == ssz))) |
fprintf(stderr, "%s:%zu:%zu: %s\n", fn, |
fprintf(stderr, "%s:%zu:%zu: %s\n", fn, |
XML_GetCurrentLineNumber(xp), |
XML_GetCurrentLineNumber(xp), |
XML_GetCurrentColumnNumber(xp), |
XML_GetCurrentColumnNumber(xp), |
XML_ErrorString |
XML_ErrorString |
(XML_GetErrorCode(xp))); |
(XML_GetErrorCode(xp))); |
else if ( ! p.stop && ssz > 0) |
else if ( ! p.stop && ssz > 0) |
continue; |
continue; |
/* |
/* |
* Exit when we've read all or errors have occured |
* Exit when we've read all or errors have occured |
* during the parse sequence. |
* during the parse sequence. |
*/ |
*/ |
Line 1625 main(int argc, char *argv[]) |
|
Line 1642 main(int argc, char *argv[]) |
|
argc -= optind; |
argc -= optind; |
argv += optind; |
argv += optind; |
|
|
if (argc > 1) |
if (argc > 1) { |
return(EXIT_FAILURE); |
fprintf(stderr, "%s: Too many arguments\n", argv[1]); |
else if (argc > 0) |
goto usage; |
|
} else if (argc > 0) |
fname = argv[0]; |
fname = argv[0]; |
|
|
/* Read from stdin or a file. */ |
/* Read from stdin or a file. */ |
fd = 0 == strcmp(fname, "-") ? |
fd = 0 == strcmp(fname, "-") ? |
STDIN_FILENO : open(fname, O_RDONLY, 0); |
STDIN_FILENO : open(fname, O_RDONLY, 0); |
|
|
/* |
/* |
Line 1656 main(int argc, char *argv[]) |
|
Line 1674 main(int argc, char *argv[]) |
|
return(rc ? EXIT_SUCCESS : EXIT_FAILURE); |
return(rc ? EXIT_SUCCESS : EXIT_FAILURE); |
|
|
usage: |
usage: |
fprintf(stderr, "usage: %s [-W]\n", progname); |
fprintf(stderr, "usage: %s [-W] [input_filename]\n", progname); |
return(EXIT_FAILURE); |
return(EXIT_FAILURE); |
} |
} |