From 45592ea5a77c4965194a52d8af5e571ac4497ed7 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Wed, 21 Dec 2005 22:32:27 +0100 Subject: [PATCH] Make the DOM tree renderer thing usable without a dom_renderer defined It now hardcodes the codepage to ASCII when showing entity references. The tree debug context info is also exported. --- src/document/dom/renderer.c | 28 ++++++++++------------------ src/document/dom/renderer.h | 9 +++++++++ 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/document/dom/renderer.c b/src/document/dom/renderer.c index 04352d9c..cff2c672 100644 --- a/src/document/dom/renderer.c +++ b/src/document/dom/renderer.c @@ -357,11 +357,6 @@ add_dom_link(struct dom_renderer *renderer, unsigned char *string, int length) /* DOM Tree Debug Renderer */ -/* Define to have debug info about the nodes added printed to the log. - * Run as: ELINKS_LOG=/tmp/dom-dump.txt ./elinks -no-connect - * to have the debug dumped into a file. */ -/*#define DOM_TREE_RENDERER*/ - #ifdef DOM_TREE_RENDERER static inline unsigned char * compress_string(unsigned char *string, unsigned int length) @@ -388,8 +383,7 @@ compress_string(unsigned char *string, unsigned int length) /* @codepage denotes how entity strings should be decoded. */ static void -set_enhanced_dom_node_value(struct dom_string *string, struct dom_node *node, - int codepage) +set_enhanced_dom_node_value(struct dom_string *string, struct dom_node *node) { struct dom_string *value; @@ -399,9 +393,11 @@ set_enhanced_dom_node_value(struct dom_string *string, struct dom_node *node, switch (node->type) { case DOM_NODE_ENTITY_REFERENCE: + /* XXX: The ASCII codepage is hardcoded here since we do not + * want to depend on anything and this is really just for + * debugging. */ string->string = get_entity_string(node->string.string, - node->string.length, - codepage); + node->string.length, 0); string->string = null_or_stracpy(string->string); break; @@ -438,17 +434,15 @@ render_dom_tree(struct dom_stack *stack, struct dom_node *node, void *data) static void render_dom_tree_id_leaf(struct dom_stack *stack, struct dom_node *node, void *data) { - struct dom_renderer *renderer = stack->current->data; - struct document *document = renderer->document; struct dom_string value; struct dom_string *name; struct dom_string *id; - assert(node && document); + assert(node); name = get_dom_node_name(node); id = get_dom_node_type_name(node->type); - set_enhanced_dom_node_value(&value, node, document->options.cp); + set_enhanced_dom_node_value(&value, node); LOG_INFO("%.*s %.*s: %.*s -> %.*s", get_indent_offset(stack), indent_string, @@ -462,15 +456,13 @@ render_dom_tree_id_leaf(struct dom_stack *stack, struct dom_node *node, void *da static void render_dom_tree_leaf(struct dom_stack *stack, struct dom_node *node, void *data) { - struct dom_renderer *renderer = stack->current->data; - struct document *document = renderer->document; struct dom_string *name; struct dom_string value; - assert(node && document); + assert(node); name = get_dom_node_name(node); - set_enhanced_dom_node_value(&value, node, document->options.cp); + set_enhanced_dom_node_value(&value, node); LOG_INFO("%.*s %.*s: %.*s", get_indent_offset(stack), indent_string, @@ -497,7 +489,7 @@ render_dom_tree_branch(struct dom_stack *stack, struct dom_node *node, void *dat id->length, id->string, name->length, name->string); } -static struct dom_stack_context_info dom_tree_renderer_context_info = { +struct dom_stack_context_info dom_tree_renderer_context_info = { /* Object size: */ 0, /* Push: */ { diff --git a/src/document/dom/renderer.h b/src/document/dom/renderer.h index ebb95c9c..b1deb469 100644 --- a/src/document/dom/renderer.h +++ b/src/document/dom/renderer.h @@ -8,4 +8,13 @@ struct string; void render_dom_document(struct cache_entry *cached, struct document *document, struct string *buffer); +/* Define to have debug info about the nodes added printed to the log. + * Run as: ELINKS_LOG=/tmp/dom-dump.txt ./elinks -no-connect + * to have the debug dumped into a file. */ +#define DOM_TREE_RENDERER + +#ifdef DOM_TREE_RENDERER +extern struct dom_stack_context_info dom_tree_renderer_context_info; +#endif + #endif -- 2.11.4.GIT