diff options
Diffstat (limited to 'html.c')
| -rw-r--r-- | html.c | 28 |
1 files changed, 21 insertions, 7 deletions
@@ -20,6 +20,9 @@ struct html_node struct html_node *child, *sibling; }; +static int serialize_siblings(struct dynstr *, const struct html_node *, + unsigned); + static char *html_encode(const char *s) { struct dynstr d; @@ -210,9 +213,9 @@ static int serialize_node(struct dynstr *const d, { dynstr_append_or_ret_nonzero(d, "\n"); - if (serialize_node(d, n->child, level + 1)) + if (serialize_siblings(d, n->child, level + 1)) { - fprintf(stderr, "%s: serialize_node failed\n", __func__); + fprintf(stderr, "%s: serialize_siblings failed\n", __func__); return -1; } @@ -223,19 +226,30 @@ static int serialize_node(struct dynstr *const d, dynstr_append_or_ret_nonzero(d, "</%s>", n->element); } - /* TODO: print siblings */ - dynstr_append_or_ret_nonzero(d, "\n"); + return 0; +} + +static int serialize_siblings(struct dynstr *const d, + const struct html_node *n, const unsigned level) +{ + struct html_node *sibling; + + do + { + sibling = n->sibling; + + if (serialize_node(d, n, level)) + return -1; - if (n->sibling) - return serialize_node(d, n->sibling, level); + } while ((n = sibling)); return 0; } int html_serialize(const struct html_node *const n, struct dynstr *const d) { - return serialize_node(d, n, 0); + return serialize_siblings(d, n, 0); } static void html_attribute_free(struct html_attribute *const a) |
