version 1.39, 2014/04/30 13:18:38 |
version 1.43, 2014/10/19 19:11:29 |
|
|
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; /* nil-terminated buffer for pre-print */ |
|
|
|
|
static const char *attrkeys[ATTRKEY__MAX] = { |
static const char *attrkeys[ATTRKEY__MAX] = { |
"choice", |
"choice", |
|
"close", |
"id", |
"id", |
|
"open", |
"rep" |
"rep" |
}; |
}; |
|
|
Line 114 static const struct node nodes[NODE__MAX] = { |
|
Line 118 static const struct node nodes[NODE__MAX] = { |
|
{ "group", NODE_IGNTEXT }, |
{ "group", NODE_IGNTEXT }, |
{ "holder", NODE_IGNTEXT }, |
{ "holder", NODE_IGNTEXT }, |
{ "info", NODE_IGNTEXT }, |
{ "info", NODE_IGNTEXT }, |
|
{ "informalequation", NODE_IGNTEXT }, |
{ "informaltable", NODE_IGNTEXT }, |
{ "informaltable", 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:mfenced", 0 }, |
|
{ "mml:mfrac", 0 }, |
|
{ "mml:mi", 0 }, |
|
{ "mml:mn", 0 }, |
|
{ "mml:mo", 0 }, |
|
{ "mml:mrow", 0 }, |
|
{ "mml:msub", 0 }, |
|
{ "mml:msup", 0 }, |
{ "modifier", 0 }, |
{ "modifier", 0 }, |
{ "note", NODE_IGNTEXT }, |
{ "note", NODE_IGNTEXT }, |
{ "option", 0 }, |
{ "option", 0 }, |
Line 292 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 328 xml_elem_start(void *arg, const XML_Char *name, const |
|
Line 342 xml_elem_start(void *arg, const XML_Char *name, const |
|
return; |
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 851 pnode_printparamdef(struct parse *p, struct pnode *pn) |
|
Line 868 pnode_printparamdef(struct parse *p, struct pnode *pn) |
|
p->newln = 1; |
p->newln = 1; |
} |
} |
|
|
|
/* |
|
* The <mml:mfenced> node is a little peculiar. |
|
* First, it can have arbitrary open and closing tokens, which default |
|
* to parentheses. |
|
* Second, >1 arguments are separated by commas. |
|
*/ |
static void |
static void |
|
pnode_printmathfenced(struct parse *p, struct pnode *pn) |
|
{ |
|
struct pnode *pp; |
|
struct pattr *ap; |
|
|
|
TAILQ_FOREACH(ap, &pn->attrq, child) |
|
if (ATTRKEY_OPEN == ap->key) { |
|
printf("left %s ", ap->rawval); |
|
break; |
|
} |
|
if (NULL == ap) |
|
printf("left ( "); |
|
|
|
pp = TAILQ_FIRST(&pn->childq); |
|
pnode_print(p, pp); |
|
|
|
while (NULL != (pp = TAILQ_NEXT(pp, child))) { |
|
putchar(','); |
|
pnode_print(p, pp); |
|
} |
|
|
|
TAILQ_FOREACH(ap, &pn->attrq, child) |
|
if (ATTRKEY_CLOSE == ap->key) { |
|
printf("right %s ", ap->rawval); |
|
break; |
|
} |
|
if (NULL == ap) |
|
printf("right ) "); |
|
} |
|
|
|
/* |
|
* These math nodes require special handling because they have infix |
|
* syntax, instead of the usual prefix or prefix. |
|
* So we need to break up the first and second child node with a |
|
* particular eqn(7) word. |
|
*/ |
|
static void |
|
pnode_printmath(struct parse *p, struct pnode *pn) |
|
{ |
|
struct pnode *pp; |
|
|
|
pp = TAILQ_FIRST(&pn->childq); |
|
pnode_print(p, pp); |
|
|
|
switch (pn->node) { |
|
case (NODE_MML_MSUP): |
|
fputs(" sup ", stdout); |
|
break; |
|
case (NODE_MML_MFRAC): |
|
fputs(" over ", stdout); |
|
break; |
|
case (NODE_MML_MSUB): |
|
fputs(" sub ", stdout); |
|
break; |
|
default: |
|
break; |
|
} |
|
|
|
pp = TAILQ_NEXT(pp, child); |
|
pnode_print(p, pp); |
|
} |
|
|
|
static void |
pnode_printfuncprototype(struct parse *p, struct pnode *pn) |
pnode_printfuncprototype(struct parse *p, struct pnode *pn) |
{ |
{ |
struct pnode *pp, *fdef; |
struct pnode *pp, *fdef; |
Line 984 pnode_printprologue(struct parse *p, struct pnode *pn) |
|
Line 1070 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 1178 pnode_print(struct parse *p, struct pnode *pn) |
|
Line 1277 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 1191 pnode_print(struct parse *p, struct pnode *pn) |
|
Line 1300 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_MFENCED): |
|
pnode_printmathfenced(p, pn); |
|
pnode_unlinksub(pn); |
|
break; |
|
case (NODE_MML_MROW): |
|
case (NODE_MML_MI): |
|
case (NODE_MML_MN): |
|
case (NODE_MML_MO): |
|
if (TAILQ_EMPTY(&pn->childq)) |
|
break; |
|
fputs(" { ", stdout); |
|
break; |
|
case (NODE_MML_MFRAC): |
|
case (NODE_MML_MSUB): |
|
case (NODE_MML_MSUP): |
|
pnode_printmath(p, pn); |
|
pnode_unlinksub(pn); |
|
break; |
case (NODE_OPTION): |
case (NODE_OPTION): |
pnode_printmopen(p); |
pnode_printmopen(p); |
fputs("Fl", stdout); |
fputs("Fl", stdout); |
Line 1371 pnode_print(struct parse *p, struct pnode *pn) |
|
Line 1498 pnode_print(struct parse *p, struct pnode *pn) |
|
pnode_print(p, pp); |
pnode_print(p, pp); |
|
|
switch (pn->node) { |
switch (pn->node) { |
|
case (NODE_INFORMALEQUATION): |
|
if ( ! p->newln) |
|
putchar('\n'); |
|
puts(".EN"); |
|
p->newln = 1; |
|
break; |
|
case (NODE_INLINEEQUATION): |
|
fputs("$ ", stdout); |
|
p->newln = sv; |
|
break; |
|
case (NODE_MML_MROW): |
|
case (NODE_MML_MI): |
|
case (NODE_MML_MN): |
|
case (NODE_MML_MO): |
|
if (TAILQ_EMPTY(&pn->childq)) |
|
break; |
|
fputs(" } ", stdout); |
|
break; |
case (NODE_APPLICATION): |
case (NODE_APPLICATION): |
case (NODE_ARG): |
case (NODE_ARG): |
case (NODE_CITEREFENTRY): |
case (NODE_CITEREFENTRY): |