version 1.36, 2019/04/12 07:05:19 |
version 1.37, 2019/04/12 07:53:09 |
Line 412 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 424 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 443 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 509 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 681 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 1007 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 1092 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) |