version 1.35, 2019/04/12 06:46:45 |
version 1.37, 2019/04/12 07:53:09 |
Line 89 static const struct element elements[] = { |
|
Line 89 static const struct element elements[] = { |
|
{ "code", NODE_LITERAL }, |
{ "code", NODE_LITERAL }, |
{ "colspec", NODE_COLSPEC }, |
{ "colspec", NODE_COLSPEC }, |
{ "command", NODE_COMMAND }, |
{ "command", NODE_COMMAND }, |
|
{ "computeroutput", NODE_LITERAL }, |
{ "constant", NODE_CONSTANT }, |
{ "constant", NODE_CONSTANT }, |
{ "contrib", NODE_CONTRIB }, |
{ "contrib", NODE_CONTRIB }, |
{ "copyright", NODE_COPYRIGHT }, |
{ "copyright", NODE_COPYRIGHT }, |
Line 134 static const struct element elements[] = { |
|
Line 135 static const struct element elements[] = { |
|
{ "literal", NODE_LITERAL }, |
{ "literal", NODE_LITERAL }, |
{ "literallayout", NODE_LITERALLAYOUT }, |
{ "literallayout", NODE_LITERALLAYOUT }, |
{ "manvolnum", NODE_MANVOLNUM }, |
{ "manvolnum", NODE_MANVOLNUM }, |
|
{ "markup", NODE_MARKUP }, |
{ "member", NODE_MEMBER }, |
{ "member", NODE_MEMBER }, |
{ "mml:math", NODE_MML_MATH }, |
{ "mml:math", NODE_MML_MATH }, |
{ "mml:mfenced", NODE_MML_MFENCED }, |
{ "mml:mfenced", NODE_MML_MFENCED }, |
Line 186 static const struct element elements[] = { |
|
Line 188 static const struct element elements[] = { |
|
{ "sect1", NODE_SECTION }, |
{ "sect1", NODE_SECTION }, |
{ "sect2", NODE_SECTION }, |
{ "sect2", NODE_SECTION }, |
{ "section", NODE_SECTION }, |
{ "section", NODE_SECTION }, |
{ "sgmltag", NODE_SGMLTAG }, |
{ "sgmltag", NODE_MARKUP }, |
{ "simpara", NODE_PARA }, |
{ "simpara", NODE_PARA }, |
{ "simplelist", NODE_SIMPLELIST }, |
{ "simplelist", NODE_SIMPLELIST }, |
{ "spanspec", NODE_SPANSPEC }, |
{ "spanspec", NODE_SPANSPEC }, |
Line 410 xml_text(struct parse *p, const char *word, int sz) |
|
Line 412 xml_text(struct parse *p, const char *word, int sz) |
|
* Close out the text node and strip trailing whitespace, if one is open. |
* Close out the text node and strip trailing whitespace, if one is open. |
*/ |
*/ |
static void |
static void |
pnode_closetext(struct parse *p) |
pnode_closetext(struct parse *p, int check_last_word) |
{ |
{ |
struct pnode *n; |
struct pnode *n; |
char *cp; |
char *cp, *last_word; |
|
|
if ((n = p->cur) == NULL || n->node != NODE_TEXT) |
if ((n = p->cur) == NULL || n->node != NODE_TEXT) |
return; |
return; |
Line 422 pnode_closetext(struct parse *p) |
|
Line 424 pnode_closetext(struct parse *p) |
|
cp > n->b && isspace((unsigned char)cp[-1]); |
cp > n->b && isspace((unsigned char)cp[-1]); |
*--cp = '\0') |
*--cp = '\0') |
p->flags |= PFLAG_SPC; |
p->flags |= PFLAG_SPC; |
|
|
|
if (p->flags & PFLAG_SPC || !check_last_word) |
|
return; |
|
|
|
/* |
|
* Find the beginning of the last word |
|
* and delete whitespace before it. |
|
*/ |
|
|
|
while (cp > n->b && !isspace((unsigned char)cp[-1])) |
|
cp--; |
|
if (cp == n->b) |
|
return; |
|
|
|
last_word = cp; |
|
while (cp > n->b && isspace((unsigned char)cp[-1])) |
|
*--cp = '\0'; |
|
|
|
/* Move the last word into its own node, for use with .Pf. */ |
|
|
|
if ((n = pnode_alloc(p->cur)) == NULL) |
|
fatal(p); |
|
n->node = NODE_TEXT; |
|
n->spc = 1; |
|
if ((n->b = strdup(last_word)) == NULL) |
|
fatal(p); |
} |
} |
|
|
static void |
static void |
Line 441 xml_entity(struct parse *p, const char *name) |
|
Line 469 xml_entity(struct parse *p, const char *name) |
|
return; |
return; |
} |
} |
|
|
pnode_closetext(p); |
pnode_closetext(p, 0); |
|
|
if (p->tree->flags & TREE_CLOSED && p->cur == p->tree->root) |
if (p->tree->flags & TREE_CLOSED && p->cur == p->tree->root) |
warn_msg(p, "entity after end of document: &%s;", name); |
warn_msg(p, "entity after end of document: &%s;", name); |
Line 507 xml_elem_start(struct parse *p, const char *name) |
|
Line 535 xml_elem_start(struct parse *p, const char *name) |
|
return; |
return; |
} |
} |
|
|
pnode_closetext(p); |
pnode_closetext(p, 1); |
|
|
for (elem = elements; elem->name != NULL; elem++) |
for (elem = elements; elem->name != NULL; elem++) |
if (strcmp(elem->name, name) == 0) |
if (strcmp(elem->name, name) == 0) |
Line 679 xml_elem_end(struct parse *p, const char *name) |
|
Line 707 xml_elem_end(struct parse *p, const char *name) |
|
} |
} |
|
|
if (p->del == 0) |
if (p->del == 0) |
pnode_closetext(p); |
pnode_closetext(p, 0); |
|
|
if (name != NULL) { |
if (name != NULL) { |
for (elem = elements; elem->name != NULL; elem++) |
for (elem = elements; elem->name != NULL; elem++) |
Line 1005 parse_string(struct parse *p, char *b, size_t rlen, |
|
Line 1033 parse_string(struct parse *p, char *b, size_t rlen, |
|
refill); |
refill); |
xml_text(p, b + poff, pend - poff); |
xml_text(p, b + poff, pend - poff); |
if (b[pend] == '\n') |
if (b[pend] == '\n') |
pnode_closetext(p); |
pnode_closetext(p, 0); |
} |
} |
} |
} |
return poff; |
return poff; |
Line 1090 parse_file(struct parse *p, int fd, const char *fname) |
|
Line 1118 parse_file(struct parse *p, int fd, const char *fname) |
|
/* On the top level, finalize the parse tree. */ |
/* On the top level, finalize the parse tree. */ |
|
|
if (save_fname == NULL) { |
if (save_fname == NULL) { |
pnode_closetext(p); |
pnode_closetext(p, 0); |
if (p->tree->root == NULL) |
if (p->tree->root == NULL) |
error_msg(p, "empty document"); |
error_msg(p, "empty document"); |
else if ((p->tree->flags & TREE_CLOSED) == 0) |
else if ((p->tree->flags & TREE_CLOSED) == 0) |