diff options
Diffstat (limited to 'test/tree2.c')
-rw-r--r-- | test/tree2.c | 103 |
1 files changed, 53 insertions, 50 deletions
diff --git a/test/tree2.c b/test/tree2.c index 5da41ef..d6ae196 100644 --- a/test/tree2.c +++ b/test/tree2.c @@ -74,25 +74,25 @@ node_t *Document; static void node_print(buf_t *buf, node_t *node, unsigned depth); -static int create_comment(void *ctx, const hubbub_string *data, void **result); -static int create_doctype(void *ctx, const hubbub_doctype *doctype, +static hubbub_error create_comment(void *ctx, const hubbub_string *data, void **result); +static hubbub_error create_doctype(void *ctx, const hubbub_doctype *doctype, void **result); -static int create_element(void *ctx, const hubbub_tag *tag, void **result); -static int create_text(void *ctx, const hubbub_string *data, void **result); -static int ref_node(void *ctx, void *node); -static int unref_node(void *ctx, void *node); -static int append_child(void *ctx, void *parent, void *child, void **result); -static int insert_before(void *ctx, void *parent, void *child, void *ref_child, +static hubbub_error create_element(void *ctx, const hubbub_tag *tag, void **result); +static hubbub_error create_text(void *ctx, const hubbub_string *data, void **result); +static hubbub_error ref_node(void *ctx, void *node); +static hubbub_error unref_node(void *ctx, void *node); +static hubbub_error append_child(void *ctx, void *parent, void *child, void **result); +static hubbub_error insert_before(void *ctx, void *parent, void *child, void *ref_child, void **result); -static int remove_child(void *ctx, void *parent, void *child, void **result); -static int clone_node(void *ctx, void *node, bool deep, void **result); -static int reparent_children(void *ctx, void *node, void *new_parent); -static int get_parent(void *ctx, void *node, bool element_only, void **result); -static int has_children(void *ctx, void *node, bool *result); -static int form_associate(void *ctx, void *form, void *node); -static int add_attributes(void *ctx, void *node, +static hubbub_error remove_child(void *ctx, void *parent, void *child, void **result); +static hubbub_error clone_node(void *ctx, void *node, bool deep, void **result); +static hubbub_error reparent_children(void *ctx, void *node, void *new_parent); +static hubbub_error get_parent(void *ctx, void *node, bool element_only, void **result); +static hubbub_error has_children(void *ctx, void *node, bool *result); +static hubbub_error form_associate(void *ctx, void *form, void *node); +static hubbub_error add_attributes(void *ctx, void *node, const hubbub_attribute *attributes, uint32_t n_attributes); -static int set_quirks_mode(void *ctx, hubbub_quirks_mode mode); +static hubbub_error set_quirks_mode(void *ctx, hubbub_quirks_mode mode); static void delete_node(node_t *node); static void delete_attr(attr_t *attr); @@ -358,7 +358,7 @@ int main(int argc, char **argv) /*** Tree construction functions ***/ -int create_comment(void *ctx, const hubbub_string *data, void **result) +hubbub_error create_comment(void *ctx, const hubbub_string *data, void **result) { node_t *node = calloc(1, sizeof *node); @@ -371,10 +371,11 @@ int create_comment(void *ctx, const hubbub_string *data, void **result) *result = node; - return 0; + return HUBBUB_OK; } -int create_doctype(void *ctx, const hubbub_doctype *doctype, void **result) +hubbub_error create_doctype(void *ctx, const hubbub_doctype *doctype, + void **result) { node_t *node = calloc(1, sizeof *node); @@ -400,10 +401,10 @@ int create_doctype(void *ctx, const hubbub_doctype *doctype, void **result) *result = node; - return 0; + return HUBBUB_OK; } -int create_element(void *ctx, const hubbub_tag *tag, void **result) +hubbub_error create_element(void *ctx, const hubbub_tag *tag, void **result) { node_t *node = calloc(1, sizeof *node); @@ -440,10 +441,10 @@ int create_element(void *ctx, const hubbub_tag *tag, void **result) *result = node; - return 0; + return HUBBUB_OK; } -int create_text(void *ctx, const hubbub_string *data, void **result) +hubbub_error create_text(void *ctx, const hubbub_string *data, void **result) { node_t *node = calloc(1, sizeof *node); @@ -456,10 +457,10 @@ int create_text(void *ctx, const hubbub_string *data, void **result) *result = node; - return 0; + return HUBBUB_OK; } -int ref_node(void *ctx, void *node) +hubbub_error ref_node(void *ctx, void *node) { node_t *n = node; @@ -468,10 +469,10 @@ int ref_node(void *ctx, void *node) if (node != (void *) 1) n->refcnt++; - return 0; + return HUBBUB_OK; } -int unref_node(void *ctx, void *node) +hubbub_error unref_node(void *ctx, void *node) { node_t *n = node; @@ -482,17 +483,19 @@ int unref_node(void *ctx, void *node) n->refcnt--; - printf("Unreferencing node %p (%d)\n", node, n->refcnt); + printf("Unreferencing node %p (%d) [%d : %s]\n", node, + n->refcnt, n->type, + n->type == ELEMENT ? n->data.element.name : ""); if (n->refcnt == 0 && n->parent == NULL) { delete_node(n); } } - return 0; + return HUBBUB_OK; } -int append_child(void *ctx, void *parent, void *child, void **result) +hubbub_error append_child(void *ctx, void *parent, void *child, void **result) { node_t *tparent = parent; node_t *tchild = child; @@ -546,12 +549,12 @@ int append_child(void *ctx, void *parent, void *child, void **result) ref_node(ctx, *result); - return 0; + return HUBBUB_OK; } /* insert 'child' before 'ref_child', under 'parent' */ -int insert_before(void *ctx, void *parent, void *child, void *ref_child, - void **result) +hubbub_error insert_before(void *ctx, void *parent, void *child, + void *ref_child, void **result) { node_t *tparent = parent; node_t *tchild = child; @@ -594,10 +597,10 @@ int insert_before(void *ctx, void *parent, void *child, void *ref_child, ref_node(ctx, *result); - return 0; + return HUBBUB_OK; } -int remove_child(void *ctx, void *parent, void *child, void **result) +hubbub_error remove_child(void *ctx, void *parent, void *child, void **result) { node_t *tparent = parent; node_t *tchild = child; @@ -624,10 +627,10 @@ int remove_child(void *ctx, void *parent, void *child, void **result) ref_node(ctx, *result); - return 0; + return HUBBUB_OK; } -int clone_node(void *ctx, void *node, bool deep, void **result) +hubbub_error clone_node(void *ctx, void *node, bool deep, void **result) { node_t *old_node = node; node_t *new_node = calloc(1, sizeof *new_node); @@ -701,11 +704,11 @@ int clone_node(void *ctx, void *node, bool deep, void **result) last = n; } - return 0; + return HUBBUB_OK; } /* Take all of the child nodes of "node" and append them to "new_parent" */ -int reparent_children(void *ctx, void *node, void *new_parent) +hubbub_error reparent_children(void *ctx, void *node, void *new_parent) { node_t *parent = new_parent; node_t *old_parent = node; @@ -737,10 +740,10 @@ int reparent_children(void *ctx, void *node, void *new_parent) kids = kids->next; } - return 0; + return HUBBUB_OK; } -int get_parent(void *ctx, void *node, bool element_only, void **result) +hubbub_error get_parent(void *ctx, void *node, bool element_only, void **result) { UNUSED(element_only); @@ -749,28 +752,28 @@ int get_parent(void *ctx, void *node, bool element_only, void **result) if (*result != NULL) ref_node(ctx, *result); - return 0; + return HUBBUB_OK; } -int has_children(void *ctx, void *node, bool *result) +hubbub_error has_children(void *ctx, void *node, bool *result) { UNUSED(ctx); *result = ((node_t *)node)->child ? true : false; - return 0; + return HUBBUB_OK; } -int form_associate(void *ctx, void *form, void *node) +hubbub_error form_associate(void *ctx, void *form, void *node) { UNUSED(ctx); UNUSED(form); UNUSED(node); - return 0; + return HUBBUB_OK; } -int add_attributes(void *ctx, void *vnode, +hubbub_error add_attributes(void *ctx, void *vnode, const hubbub_attribute *attributes, uint32_t n_attributes) { node_t *node = vnode; @@ -801,15 +804,15 @@ int add_attributes(void *ctx, void *vnode, } - return 0; + return HUBBUB_OK; } -int set_quirks_mode(void *ctx, hubbub_quirks_mode mode) +hubbub_error set_quirks_mode(void *ctx, hubbub_quirks_mode mode) { UNUSED(ctx); UNUSED(mode); - return 0; + return HUBBUB_OK; } |