version 1.36, 2014/04/30 10:11:24 |
version 1.40, 2014/10/12 15:08:45 |
|
|
struct pnode { |
struct pnode { |
enum nodeid node; /* node type */ |
enum nodeid node; /* node type */ |
char *b; /* binary data buffer */ |
char *b; /* binary data buffer */ |
|
char *real; /* store for "b" */ |
size_t bsz; /* data buffer size */ |
size_t bsz; /* data buffer size */ |
struct pnode *parent; /* parent (or NULL if top) */ |
struct pnode *parent; /* parent (or NULL if top) */ |
struct pnodeq childq; /* queue of children */ |
struct pnodeq childq; /* queue of children */ |
Line 95 static const struct node nodes[NODE__MAX] = { |
|
Line 96 static const struct node nodes[NODE__MAX] = { |
|
{ "citerefentry", NODE_IGNTEXT }, |
{ "citerefentry", NODE_IGNTEXT }, |
{ "cmdsynopsis", NODE_IGNTEXT }, |
{ "cmdsynopsis", NODE_IGNTEXT }, |
{ "code", 0 }, |
{ "code", 0 }, |
|
{ "colspec", NODE_IGNTEXT }, |
{ "command", 0 }, |
{ "command", 0 }, |
{ "constant", 0 }, |
{ "constant", 0 }, |
{ "copyright", NODE_IGNTEXT }, |
{ "copyright", NODE_IGNTEXT }, |
Line 102 static const struct node nodes[NODE__MAX] = { |
|
Line 104 static const struct node nodes[NODE__MAX] = { |
|
{ "emphasis", 0 }, |
{ "emphasis", 0 }, |
{ "entry", 0 }, |
{ "entry", 0 }, |
{ "envar", 0 }, |
{ "envar", 0 }, |
|
{ "fieldsynopsis", NODE_IGNTEXT }, |
{ "filename", 0 }, |
{ "filename", 0 }, |
{ "funcdef", 0 }, |
{ "funcdef", 0 }, |
{ "funcprototype", NODE_IGNTEXT }, |
{ "funcprototype", NODE_IGNTEXT }, |
Line 111 static const struct node nodes[NODE__MAX] = { |
|
Line 114 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 }, |
{ "note", NODE_IGNTEXT }, |
{ "note", NODE_IGNTEXT }, |
{ "option", 0 }, |
{ "option", 0 }, |
{ "orderedlist", NODE_IGNTEXT }, |
{ "orderedlist", NODE_IGNTEXT }, |
Line 132 static const struct node nodes[NODE__MAX] = { |
|
Line 147 static const struct node nodes[NODE__MAX] = { |
|
{ "refentryinfo", NODE_IGNTEXT }, |
{ "refentryinfo", NODE_IGNTEXT }, |
{ "refentrytitle", 0 }, |
{ "refentrytitle", 0 }, |
{ "refmeta", NODE_IGNTEXT }, |
{ "refmeta", NODE_IGNTEXT }, |
|
{ "refmetainfo", NODE_IGNTEXT }, |
{ "refmiscinfo", NODE_IGNTEXT }, |
{ "refmiscinfo", NODE_IGNTEXT }, |
{ "refname", 0 }, |
{ "refname", 0 }, |
{ "refnamediv", NODE_IGNTEXT }, |
{ "refnamediv", NODE_IGNTEXT }, |
Line 158 static const struct node nodes[NODE__MAX] = { |
|
Line 174 static const struct node nodes[NODE__MAX] = { |
|
{ "tip", NODE_IGNTEXT }, |
{ "tip", NODE_IGNTEXT }, |
{ "title", 0 }, |
{ "title", 0 }, |
{ "trademark", 0 }, |
{ "trademark", 0 }, |
|
{ "type", 0 }, |
{ "ulink", 0 }, |
{ "ulink", 0 }, |
{ "userinput", 0 }, |
{ "userinput", 0 }, |
{ "variablelist", NODE_IGNTEXT }, |
{ "variablelist", NODE_IGNTEXT }, |
Line 168 static const struct node nodes[NODE__MAX] = { |
|
Line 185 static const struct node nodes[NODE__MAX] = { |
|
{ "year", NODE_IGNTEXT }, |
{ "year", NODE_IGNTEXT }, |
}; |
}; |
|
|
|
static int warn = 0; |
|
|
static void |
static void |
pnode_print(struct parse *p, struct pnode *pn); |
pnode_print(struct parse *p, struct pnode *pn); |
|
|
Line 233 xml_char(void *arg, const XML_Char *p, int sz) |
|
Line 252 xml_char(void *arg, const XML_Char *p, int sz) |
|
} |
} |
memcpy(ps->cur->b + ps->cur->bsz, p, sz); |
memcpy(ps->cur->b + ps->cur->bsz, p, sz); |
ps->cur->bsz += (size_t)sz; |
ps->cur->bsz += (size_t)sz; |
|
ps->cur->real = ps->cur->b; |
} |
} |
|
|
static void |
static void |
Line 344 xml_elem_start(void *arg, const XML_Char *name, const |
|
Line 364 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) { |
fprintf(stderr, "%s:%zu:%zu: warning: " |
if (warn) |
"unknown attribute \"%s\"\n", |
fprintf(stderr, "%s:%zu:%zu: warning: " |
ps->fname, |
"unknown attribute \"%s\"\n", |
XML_GetCurrentLineNumber(ps->xml), |
ps->fname, |
XML_GetCurrentColumnNumber(ps->xml), |
XML_GetCurrentLineNumber(ps->xml), |
*att); |
XML_GetCurrentColumnNumber(ps->xml), |
|
*att); |
continue; |
continue; |
} else if ( ! isattrkey(node, key)) { |
} else if ( ! isattrkey(node, key)) { |
fprintf(stderr, "%s:%zu:%zu: warning: " |
if (warn) |
"bad attribute \"%s\"\n", |
fprintf(stderr, "%s:%zu:%zu: warning: " |
ps->fname, |
"bad attribute \"%s\"\n", |
XML_GetCurrentLineNumber(ps->xml), |
ps->fname, |
XML_GetCurrentColumnNumber(ps->xml), |
XML_GetCurrentLineNumber(ps->xml), |
*att); |
XML_GetCurrentColumnNumber(ps->xml), |
|
*att); |
continue; |
continue; |
} |
} |
for (val = 0; val < ATTRVAL__MAX; val++) |
for (val = 0; val < ATTRVAL__MAX; val++) |
if (0 == strcmp(*(att + 1), attrvals[val])) |
if (0 == strcmp(*(att + 1), attrvals[val])) |
break; |
break; |
if (ATTRVAL__MAX != val && ! isattrval(key, val)) { |
if (ATTRVAL__MAX != val && ! isattrval(key, val)) { |
fprintf(stderr, "%s:%zu:%zu: warning: " |
if (warn) |
"bad attribute value \"%s\"\n", |
fprintf(stderr, "%s:%zu:%zu: warning: " |
ps->fname, |
"bad attribute value \"%s\"\n", |
XML_GetCurrentLineNumber(ps->xml), |
ps->fname, |
XML_GetCurrentColumnNumber(ps->xml), |
XML_GetCurrentLineNumber(ps->xml), |
*(att + 1)); |
XML_GetCurrentColumnNumber(ps->xml), |
|
*(att + 1)); |
continue; |
continue; |
} |
} |
pattr = calloc(1, sizeof(struct pattr)); |
pattr = calloc(1, sizeof(struct pattr)); |
Line 436 pnode_free(struct pnode *pn) |
|
Line 459 pnode_free(struct pnode *pn) |
|
free(ap); |
free(ap); |
} |
} |
|
|
free(pn->b); |
free(pn->real); |
free(pn); |
free(pn); |
} |
} |
|
|
Line 620 pnode_printmclose(struct parse *p, int sv) |
|
Line 643 pnode_printmclose(struct parse *p, int sv) |
|
} |
} |
|
|
/* |
/* |
|
* Like pnode_printmclose() except we look to the next node, and, if |
|
* found, see if it starts with punctuation. |
|
* If it does, then we print that punctuation before the newline. |
|
*/ |
|
static void |
|
pnode_printmclosepunct(struct parse *p, struct pnode *pn, int sv) |
|
{ |
|
/* We wouldn't have done anything anyway. */ |
|
if ( ! (sv && ! p->newln)) |
|
return; |
|
|
|
/* No next node or it's not text. */ |
|
if (NULL == (pn = TAILQ_NEXT(pn, child))) { |
|
pnode_printmclose(p, sv); |
|
return; |
|
} else if (NODE_TEXT != pn->node) { |
|
pnode_printmclose(p, sv); |
|
return; |
|
} |
|
|
|
/* Only do this for the comma/period. */ |
|
if (pn->bsz > 0 && |
|
(',' == pn->b[0] || '.' == pn->b[0]) && |
|
(1 == pn->bsz || isspace((int)pn->b[1]))) { |
|
putchar(' '); |
|
putchar(pn->b[0]); |
|
pn->b++; |
|
pn->bsz--; |
|
} |
|
|
|
putchar('\n'); |
|
p->newln = 1; |
|
} |
|
|
|
/* |
* If the SYNOPSIS macro has a superfluous title, kill it. |
* If the SYNOPSIS macro has a superfluous title, kill it. |
*/ |
*/ |
static void |
static void |
Line 804 pnode_printparamdef(struct parse *p, struct pnode *pn) |
|
Line 862 pnode_printparamdef(struct parse *p, struct pnode *pn) |
|
p->newln = 1; |
p->newln = 1; |
} |
} |
|
|
|
/* |
|
* 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 |
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): |
|
printf(" sup "); |
|
break; |
|
case (NODE_MML_MFRAC): |
|
printf(" over "); |
|
break; |
|
case (NODE_MML_MSUB): |
|
printf(" sub "); |
|
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 1144 pnode_print(struct parse *p, struct pnode *pn) |
|
Line 1234 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): |
|
printf("left {"); |
|
break; |
|
case (NODE_MML_MROW): |
|
case (NODE_MML_MI): |
|
case (NODE_MML_MN): |
|
case (NODE_MML_MO): |
|
putchar('{'); |
|
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 1251 pnode_print(struct parse *p, struct pnode *pn) |
|
Line 1362 pnode_print(struct parse *p, struct pnode *pn) |
|
case (NODE_TEXT): |
case (NODE_TEXT): |
if (0 == p->newln) |
if (0 == p->newln) |
putchar(' '); |
putchar(' '); |
|
|
bufclear(p); |
bufclear(p); |
bufappend(p, pn); |
bufappend(p, pn); |
|
|
|
if (0 == p->bsz) { |
|
assert(pn->real != pn->b); |
|
break; |
|
} |
|
|
/* |
/* |
* Output all characters, squeezing out whitespace |
* Output all characters, squeezing out whitespace |
* between newlines. |
* between newlines. |
Line 1261 pnode_print(struct parse *p, struct pnode *pn) |
|
Line 1379 pnode_print(struct parse *p, struct pnode *pn) |
|
*/ |
*/ |
assert(p->bsz); |
assert(p->bsz); |
cp = p->b; |
cp = p->b; |
|
|
/* |
/* |
* There's often a superfluous "-" in its <option> tags |
* There's often a superfluous "-" in its <option> tags |
* before the actual flags themselves. |
* before the actual flags themselves. |
Line 1287 pnode_print(struct parse *p, struct pnode *pn) |
|
Line 1406 pnode_print(struct parse *p, struct pnode *pn) |
|
} |
} |
p->newln = 0; |
p->newln = 0; |
break; |
break; |
|
case (NODE_TYPE): |
|
pnode_printmopen(p); |
|
fputs("Vt", stdout); |
|
break; |
case (NODE_USERINPUT): |
case (NODE_USERINPUT): |
pnode_printmopen(p); |
pnode_printmopen(p); |
fputs("Li", stdout); |
fputs("Li", stdout); |
Line 1312 pnode_print(struct parse *p, struct pnode *pn) |
|
Line 1435 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): |
|
if ( ! p->newln) |
|
putchar('\n'); |
|
puts(".EN"); |
|
p->newln = 1; |
|
break; |
|
case (NODE_MML_MFENCED): |
|
printf("right }"); |
|
break; |
|
case (NODE_MML_MROW): |
|
case (NODE_MML_MI): |
|
case (NODE_MML_MN): |
|
case (NODE_MML_MO): |
|
putchar('}'); |
|
break; |
case (NODE_APPLICATION): |
case (NODE_APPLICATION): |
case (NODE_ARG): |
case (NODE_ARG): |
case (NODE_CITEREFENTRY): |
case (NODE_CITEREFENTRY): |
Line 1331 pnode_print(struct parse *p, struct pnode *pn) |
|
Line 1469 pnode_print(struct parse *p, struct pnode *pn) |
|
case (NODE_SGMLTAG): |
case (NODE_SGMLTAG): |
case (NODE_STRUCTNAME): |
case (NODE_STRUCTNAME): |
case (NODE_TEXT): |
case (NODE_TEXT): |
|
case (NODE_TYPE): |
case (NODE_USERINPUT): |
case (NODE_USERINPUT): |
case (NODE_VARNAME): |
case (NODE_VARNAME): |
pnode_printmclose(p, sv); |
pnode_printmclosepunct(p, pn, sv); |
break; |
break; |
case (NODE_QUOTE): |
case (NODE_QUOTE): |
pnode_printmclose(p, sv); |
pnode_printmclose(p, sv); |
Line 1423 main(int argc, char *argv[]) |
|
Line 1562 main(int argc, char *argv[]) |
|
XML_Parser xp; |
XML_Parser xp; |
const char *fname; |
const char *fname; |
char *buf; |
char *buf; |
int fd, rc; |
int fd, rc, ch; |
|
const char *progname; |
|
|
|
progname = strrchr(argv[0], '/'); |
|
if (progname == NULL) |
|
progname = argv[0]; |
|
else |
|
++progname; |
|
|
fname = "-"; |
fname = "-"; |
xp = NULL; |
xp = NULL; |
buf = NULL; |
buf = NULL; |
rc = 0; |
rc = 0; |
|
|
if (-1 != getopt(argc, argv, "")) |
while (-1 != (ch = getopt(argc, argv, "W"))) |
return(EXIT_FAILURE); |
switch (ch) { |
|
case ('W'): |
|
warn = 1; |
|
break; |
|
default: |
|
goto usage; |
|
} |
|
|
argc -= optind; |
argc -= optind; |
argv += optind; |
argv += optind; |
Line 1465 main(int argc, char *argv[]) |
|
Line 1617 main(int argc, char *argv[]) |
|
if (STDIN_FILENO != fd) |
if (STDIN_FILENO != fd) |
close(fd); |
close(fd); |
return(rc ? EXIT_SUCCESS : EXIT_FAILURE); |
return(rc ? EXIT_SUCCESS : EXIT_FAILURE); |
|
|
|
usage: |
|
fprintf(stderr, "usage: %s [-W]\n", progname); |
|
return(EXIT_FAILURE); |
} |
} |