From baadfd3a8f06d72c3088ed9b44c6a327f67f57a3 Mon Sep 17 00:00:00 2001 From: Andrew Sidwell Date: Fri, 11 Jul 2008 14:59:41 +0000 Subject: Export a hubbub_doctype type to create_doctype() directly, rather than passing all its members as individual arguments. svn path=/trunk/hubbub/; revision=4602 --- include/hubbub/functypes.h | 4 ++-- src/treebuilder/initial.c | 5 ++--- test/tree.c | 13 ++++--------- test/tree2.c | 28 +++++++++++++++------------- 4 files changed, 23 insertions(+), 27 deletions(-) diff --git a/include/hubbub/functypes.h b/include/hubbub/functypes.h index 80c8388..0d45e6a 100644 --- a/include/hubbub/functypes.h +++ b/include/hubbub/functypes.h @@ -43,8 +43,8 @@ typedef int (*hubbub_tree_create_comment)(void *ctx, const hubbub_string *data, /** * Type of tree doctype node creation function */ -typedef int (*hubbub_tree_create_doctype)(void *ctx, const hubbub_string *qname, - const hubbub_string *public_id, const hubbub_string *system_id, +typedef int (*hubbub_tree_create_doctype)(void *ctx, + const hubbub_doctype *doctype, void **result); /** diff --git a/src/treebuilder/initial.c b/src/treebuilder/initial.c index 910cf33..a1e623d 100644 --- a/src/treebuilder/initial.c +++ b/src/treebuilder/initial.c @@ -273,9 +273,8 @@ bool handle_initial(hubbub_treebuilder *treebuilder, const hubbub_token *token) /** \todo need public and system ids from tokeniser */ success = treebuilder->tree_handler->create_doctype( treebuilder->tree_handler->ctx, - &token->data.doctype.name, - &token->data.doctype.public_id, - &token->data.doctype.system_id, &doctype); + &token->data.doctype, + &doctype); if (success != 0) { /** \todo errors */ } diff --git a/test/tree.c b/test/tree.c index aee360d..a854491 100644 --- a/test/tree.c +++ b/test/tree.c @@ -33,8 +33,7 @@ static const uint8_t *pbuffer; static void buffer_handler(const uint8_t *buffer, size_t len, void *pw); static int create_comment(void *ctx, const hubbub_string *data, void **result); -static int create_doctype(void *ctx, const hubbub_string *qname, - const hubbub_string *public_id, const hubbub_string *system_id, +static int 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); @@ -224,15 +223,11 @@ int create_comment(void *ctx, const hubbub_string *data, void **result) return 0; } -int create_doctype(void *ctx, const hubbub_string *qname, - const hubbub_string *public_id, const hubbub_string *system_id, - void **result) +int create_doctype(void *ctx, const hubbub_doctype *doctype, void **result) { - UNUSED(public_id); - UNUSED(system_id); - printf("Creating (%" PRIuPTR ") [doctype '%.*s']\n", ++node_counter, - (int) qname->len, ptr_from_hubbub_string(qname)); + (int) doctype->name.len, + ptr_from_hubbub_string(&doctype->name)); GROW_REF node_ref[node_counter] = 0; diff --git a/test/tree2.c b/test/tree2.c index 79809ca..6f78fb5 100644 --- a/test/tree2.c +++ b/test/tree2.c @@ -79,8 +79,7 @@ static const uint8_t *pbuffer; static void buffer_handler(const uint8_t *buffer, size_t len, void *pw); static int create_comment(void *ctx, const hubbub_string *data, void **result); -static int create_doctype(void *ctx, const hubbub_string *qname, - const hubbub_string *public_id, const hubbub_string *system_id, +static int 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); @@ -358,24 +357,27 @@ int create_comment(void *ctx, const hubbub_string *data, void **result) return 0; } -int create_doctype(void *ctx, const hubbub_string *qname, - const hubbub_string *public_id, const hubbub_string *system_id, - void **result) +int create_doctype(void *ctx, const hubbub_doctype *doctype, void **result) { node_t *node = calloc(1, sizeof *node); node->type = DOCTYPE; - node->data.doctype.name = strndup((char *)ptr_from_hubbub_string(qname), - qname->len); - if (public_id->len) { + node->data.doctype.name = strndup( + (char *)ptr_from_hubbub_string(&doctype->name), + doctype->name.len); + + if (!doctype->public_missing) { node->data.doctype.public_id = strndup( - (char *)ptr_from_hubbub_string(public_id), - public_id->len); + (char *)ptr_from_hubbub_string( + &doctype->public_id), + doctype->public_id.len); } - if (system_id->len) { + + if (!doctype->system_missing) { node->data.doctype.system_id = strndup( - (char *)ptr_from_hubbub_string(system_id), - system_id->len); + (char *)ptr_from_hubbub_string( + &doctype->system_id), + doctype->system_id.len); } *result = node; -- cgit v1.2.3