mirror of
https://github.com/rkd77/elinks.git
synced 2024-11-04 08:17:17 -05:00
get_dom_node_name(): return struct dom_string *
Also, simplify the rendering a bit for now.
This commit is contained in:
parent
7d6db6b152
commit
295679a5e6
@ -345,34 +345,32 @@ done_dom_node(struct dom_node *node)
|
||||
#define set_node_name(name, namelen, str) \
|
||||
do { (name) = (str); (namelen) = sizeof(str) - 1; } while (0)
|
||||
|
||||
unsigned char *
|
||||
struct dom_string *
|
||||
get_dom_node_name(struct dom_node *node)
|
||||
{
|
||||
unsigned char *name;
|
||||
uint16_t namelen;
|
||||
static struct dom_string cdata_section_str = INIT_DOM_STRING("#cdata-section", -1);
|
||||
static struct dom_string comment_str = INIT_DOM_STRING("#comment", -1);
|
||||
static struct dom_string document_str = INIT_DOM_STRING("#document", -1);
|
||||
static struct dom_string document_fragment_str = INIT_DOM_STRING("#document-fragment", -1);
|
||||
static struct dom_string text_str = INIT_DOM_STRING("#text", -1);
|
||||
|
||||
assert(node);
|
||||
|
||||
switch (node->type) {
|
||||
case DOM_NODE_CDATA_SECTION:
|
||||
set_node_name(name, namelen, "#cdata-section");
|
||||
break;
|
||||
return &cdata_section_str;
|
||||
|
||||
case DOM_NODE_COMMENT:
|
||||
set_node_name(name, namelen, "#comment");
|
||||
break;
|
||||
return &comment_str;
|
||||
|
||||
case DOM_NODE_DOCUMENT:
|
||||
set_node_name(name, namelen, "#document");
|
||||
break;
|
||||
return &document_str;
|
||||
|
||||
case DOM_NODE_DOCUMENT_FRAGMENT:
|
||||
set_node_name(name, namelen, "#document-fragment");
|
||||
break;
|
||||
return &document_fragment_str;
|
||||
|
||||
case DOM_NODE_TEXT:
|
||||
set_node_name(name, namelen, "#text");
|
||||
break;
|
||||
return &text_str;
|
||||
|
||||
case DOM_NODE_ATTRIBUTE:
|
||||
case DOM_NODE_DOCUMENT_TYPE:
|
||||
@ -382,11 +380,8 @@ get_dom_node_name(struct dom_node *node)
|
||||
case DOM_NODE_NOTATION:
|
||||
case DOM_NODE_PROCESSING_INSTRUCTION:
|
||||
default:
|
||||
name = node->string.string;
|
||||
namelen = node->string.length;
|
||||
return &node->string;
|
||||
}
|
||||
|
||||
return memacpy(name, namelen);
|
||||
}
|
||||
|
||||
static inline unsigned char *
|
||||
|
@ -285,7 +285,7 @@ add_dom_proc_instruction(struct dom_node *parent, unsigned char *string, int len
|
||||
void done_dom_node(struct dom_node *node);
|
||||
|
||||
/* Returns the name of the node in an allocated string. */
|
||||
unsigned char *get_dom_node_name(struct dom_node *node);
|
||||
struct dom_string *get_dom_node_name(struct dom_node *node);
|
||||
|
||||
/* Returns the value of the node in an allocated string.
|
||||
* @codepage denotes how entity strings should be decoded. */
|
||||
|
@ -393,13 +393,10 @@ render_dom_tree(struct dom_stack *stack, struct dom_node *node, void *data)
|
||||
struct dom_renderer *renderer = stack->renderer;
|
||||
struct screen_char *template = &renderer->styles[node->type];
|
||||
struct dom_string *value = &node->string;
|
||||
unsigned char *name;
|
||||
struct dom_string *name = get_dom_node_name(node);
|
||||
|
||||
assert(node && renderer);
|
||||
|
||||
name = get_dom_node_name(node);
|
||||
|
||||
render_dom_printf(renderer, template, "%-16s: %.*s\n", name,
|
||||
render_dom_printf(renderer, template, "%.*s: %.*s\n",
|
||||
name->length, name->string,
|
||||
value->length, value->string);
|
||||
|
||||
mem_free_if(name);
|
||||
@ -413,7 +410,8 @@ render_dom_tree_id_leaf(struct dom_stack *stack, struct dom_node *node, void *da
|
||||
struct dom_renderer *renderer = stack->renderer;
|
||||
struct document *document = renderer->document;
|
||||
struct screen_char *template = &renderer->styles[node->type];
|
||||
unsigned char *name, *value;
|
||||
unsigned char *value;
|
||||
struct dom_string *name;
|
||||
struct dom_string *id;
|
||||
|
||||
assert(node && document);
|
||||
@ -423,12 +421,10 @@ render_dom_tree_id_leaf(struct dom_stack *stack, struct dom_node *node, void *da
|
||||
id = get_dom_node_type_name(node->type);
|
||||
|
||||
renderer->canvas_x += stack->depth;
|
||||
if (id->length < 16)
|
||||
render_dom_text(renderer, template, " ", 16 - id->length);
|
||||
render_dom_printf(renderer, template, "%.*s: %s -> %s\n",
|
||||
id->length, id->string, name, value);
|
||||
render_dom_printf(renderer, template, "%.*s: %.*s -> %s\n",
|
||||
id->length, id->string, name->length, name->string,
|
||||
value);
|
||||
|
||||
mem_free_if(name);
|
||||
mem_free_if(value);
|
||||
|
||||
return node;
|
||||
@ -440,7 +436,8 @@ render_dom_tree_leaf(struct dom_stack *stack, struct dom_node *node, void *data)
|
||||
struct dom_renderer *renderer = stack->renderer;
|
||||
struct document *document = renderer->document;
|
||||
struct screen_char *template = &renderer->styles[node->type];
|
||||
unsigned char *name, *value;
|
||||
struct dom_string *name;
|
||||
unsigned char *value;
|
||||
|
||||
assert(node && document);
|
||||
|
||||
@ -462,7 +459,7 @@ render_dom_tree_branch(struct dom_stack *stack, struct dom_node *node, void *dat
|
||||
struct dom_renderer *renderer = stack->renderer;
|
||||
struct document *document = renderer->document;
|
||||
struct screen_char *template = &renderer->styles[node->type];
|
||||
unsigned char *name;
|
||||
struct dom_string *name;
|
||||
struct dom_string *id;
|
||||
|
||||
assert(node && document);
|
||||
@ -471,10 +468,8 @@ render_dom_tree_branch(struct dom_stack *stack, struct dom_node *node, void *dat
|
||||
id = get_dom_node_type_name(node->type);
|
||||
|
||||
renderer->canvas_x += stack->depth;
|
||||
if (id->length < 16)
|
||||
render_dom_text(renderer, template, " ", 16 - id->length);
|
||||
render_dom_printf(renderer, template, "%.*s: %s\n",
|
||||
id->length, id->string, name);
|
||||
render_dom_printf(renderer, template, "%.*s: %.*s\n",
|
||||
id->length, id->string, name->length, name->string);
|
||||
|
||||
mem_free_if(name);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user