mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
Make the DOM node creators take dom_string structs
This commit is contained in:
parent
ec7b293e4e
commit
1bd0c8758e
@ -247,7 +247,7 @@ get_dom_node_list_index(struct dom_node *parent, struct dom_node *node)
|
||||
struct dom_node *
|
||||
init_dom_node_(unsigned char *file, int line,
|
||||
struct dom_node *parent, enum dom_node_type type,
|
||||
unsigned char *string, size_t length)
|
||||
struct dom_string *string)
|
||||
{
|
||||
#ifdef DEBUG_MEMLEAK
|
||||
struct dom_node *node = debug_mem_calloc(file, line, 1, sizeof(*node));
|
||||
@ -259,7 +259,7 @@ init_dom_node_(unsigned char *file, int line,
|
||||
|
||||
node->type = type;
|
||||
node->parent = parent;
|
||||
set_dom_string(&node->string, string, length);
|
||||
copy_dom_string(&node->string, string);
|
||||
|
||||
if (parent) {
|
||||
struct dom_node_list **list = get_dom_node_list(parent, node);
|
||||
|
@ -255,34 +255,34 @@ get_dom_node_map_entry(struct dom_node_list *node_map,
|
||||
struct dom_node *
|
||||
init_dom_node_(unsigned char *file, int line,
|
||||
struct dom_node *parent, enum dom_node_type type,
|
||||
unsigned char *string, size_t length);
|
||||
#define init_dom_node(type, string, length) init_dom_node_(__FILE__, __LINE__, NULL, type, string, length)
|
||||
#define add_dom_node(parent, type, string, length) init_dom_node_(__FILE__, __LINE__, parent, type, string, length)
|
||||
struct dom_string *string);
|
||||
#define init_dom_node(type, string) init_dom_node_(__FILE__, __LINE__, NULL, type, string)
|
||||
#define add_dom_node(parent, type, string) init_dom_node_(__FILE__, __LINE__, parent, type, string)
|
||||
|
||||
#define add_dom_element(parent, string, length) \
|
||||
add_dom_node(parent, DOM_NODE_ELEMENT, string, length)
|
||||
#define add_dom_element(parent, string) \
|
||||
add_dom_node(parent, DOM_NODE_ELEMENT, string)
|
||||
|
||||
static inline struct dom_node *
|
||||
add_dom_attribute(struct dom_node *parent, unsigned char *string, int length,
|
||||
unsigned char *value, size_t valuelen)
|
||||
add_dom_attribute(struct dom_node *parent, struct dom_string *name,
|
||||
struct dom_string *value)
|
||||
{
|
||||
struct dom_node *node = add_dom_node(parent, DOM_NODE_ATTRIBUTE, string, length);
|
||||
struct dom_node *node = add_dom_node(parent, DOM_NODE_ATTRIBUTE, name);
|
||||
|
||||
if (node && value) {
|
||||
set_dom_string(&node->data.attribute.value, value, valuelen);
|
||||
copy_dom_string(&node->data.attribute.value, value);
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
static inline struct dom_node *
|
||||
add_dom_proc_instruction(struct dom_node *parent, unsigned char *string, int length,
|
||||
unsigned char *instruction, size_t instructionlen)
|
||||
add_dom_proc_instruction(struct dom_node *parent, struct dom_string *string,
|
||||
struct dom_string *instruction)
|
||||
{
|
||||
struct dom_node *node = add_dom_node(parent, DOM_NODE_PROCESSING_INSTRUCTION, string, length);
|
||||
struct dom_node *node = add_dom_node(parent, DOM_NODE_PROCESSING_INSTRUCTION, string);
|
||||
|
||||
if (node && instruction) {
|
||||
set_dom_string(&node->data.proc_instruction.instruction, instruction, instructionlen);
|
||||
copy_dom_string(&node->data.proc_instruction.instruction, instruction);
|
||||
}
|
||||
|
||||
return node;
|
||||
|
@ -41,7 +41,7 @@ init_sgml_parsing_state(struct sgml_parser *parser, struct dom_string *buffer);
|
||||
static inline struct dom_node *
|
||||
add_sgml_document(struct dom_stack *stack, struct dom_string *string)
|
||||
{
|
||||
struct dom_node *node = init_dom_node(DOM_NODE_DOCUMENT, string->string, string->length);
|
||||
struct dom_node *node = init_dom_node(DOM_NODE_DOCUMENT, string);
|
||||
|
||||
return node ? push_dom_node(stack, node) : NULL;
|
||||
}
|
||||
@ -56,7 +56,7 @@ add_sgml_element(struct dom_stack *stack, struct dom_scanner_token *token)
|
||||
struct dom_node *node;
|
||||
struct sgml_node_info *node_info;
|
||||
|
||||
node = add_dom_element(parent, token->string.string, token->string.length);
|
||||
node = add_dom_element(parent, &token->string);
|
||||
if (!node) return NULL;
|
||||
|
||||
node_info = get_sgml_node_info(parser->info->elements, node);
|
||||
@ -81,13 +81,11 @@ add_sgml_attribute(struct dom_stack *stack,
|
||||
{
|
||||
struct sgml_parser *parser = get_sgml_parser(stack);
|
||||
struct dom_node *parent = get_dom_stack_top(stack)->node;
|
||||
unsigned char *value = valtoken ? valtoken->string.string : NULL;
|
||||
size_t valuelen = valtoken ? valtoken->string.length : 0;
|
||||
struct dom_string *value = valtoken ? &valtoken->string : NULL;
|
||||
struct sgml_node_info *info;
|
||||
struct dom_node *node;
|
||||
|
||||
node = add_dom_attribute(parent, token->string.string, token->string.length,
|
||||
value, valuelen);
|
||||
node = add_dom_attribute(parent, &token->string, value);
|
||||
|
||||
info = get_sgml_node_info(parser->info->attributes, node);
|
||||
|
||||
@ -113,14 +111,15 @@ add_sgml_proc_instruction(struct dom_stack *stack, struct dom_scanner_token *tok
|
||||
unsigned char *separator = memchr(token->string.string, ' ', token->string.length);
|
||||
|
||||
/* Anything before the separator becomes the target name ... */
|
||||
unsigned char *name = token->string.string;
|
||||
size_t namelen = separator ? separator - token->string.string : token->string.length;
|
||||
struct dom_string name = INIT_DOM_STRING(token->string.string, namelen);
|
||||
|
||||
/* ... and everything after the instruction value. */
|
||||
unsigned char *value = separator ? separator + 1 : NULL;
|
||||
size_t valuelen = value ? token->string.length - namelen - 1 : 0;
|
||||
unsigned char *valuestr = separator ? separator + 1 : NULL;
|
||||
size_t valuelen = valuestr ? token->string.length - namelen - 1 : 0;
|
||||
struct dom_string value = INIT_DOM_STRING(valuestr, valuelen);
|
||||
|
||||
node = add_dom_proc_instruction(parent, name, namelen, value, valuelen);
|
||||
node = add_dom_proc_instruction(parent, &name, &value);
|
||||
if (!node) return NULL;
|
||||
|
||||
switch (token->type) {
|
||||
@ -146,7 +145,7 @@ static inline void
|
||||
add_sgml_node(struct dom_stack *stack, enum dom_node_type type, struct dom_scanner_token *token)
|
||||
{
|
||||
struct dom_node *parent = get_dom_stack_top(stack)->node;
|
||||
struct dom_node *node = add_dom_node(parent, type, token->string.string, token->string.length);
|
||||
struct dom_node *node = add_dom_node(parent, type, &token->string);
|
||||
|
||||
if (!node) return;
|
||||
|
||||
@ -421,7 +420,7 @@ init_sgml_parsing_state(struct sgml_parser *parser, struct dom_string *buffer)
|
||||
struct dom_stack_state *state;
|
||||
struct dom_node *node;
|
||||
|
||||
node = init_dom_node(DOM_NODE_TEXT, buffer->string, buffer->length);
|
||||
node = init_dom_node(DOM_NODE_TEXT, buffer);
|
||||
if (!node || !push_dom_node(&parser->parsing, node))
|
||||
return NULL;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user