mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
Introduce enum dom_stack_flag to make init_dom_stack() more obvious
This commit is contained in:
parent
632f12f82a
commit
2a24ad9099
@ -376,7 +376,7 @@ parse_dom_select(struct dom_select *select, unsigned char *string, int length)
|
|||||||
struct dom_select_node sel;
|
struct dom_select_node sel;
|
||||||
|
|
||||||
init_scanner(&scanner, &css_scanner_info, string, string + length);
|
init_scanner(&scanner, &css_scanner_info, string, string + length);
|
||||||
init_dom_stack(&stack, 1);
|
init_dom_stack(&stack, DOM_STACK_KEEP_NODES);
|
||||||
|
|
||||||
memset(&sel, 0, sizeof(sel));
|
memset(&sel, 0, sizeof(sel));
|
||||||
|
|
||||||
@ -869,11 +869,11 @@ select_dom_nodes(struct dom_select *select, struct dom_node *root)
|
|||||||
|
|
||||||
select_data.select = select;;
|
select_data.select = select;;
|
||||||
|
|
||||||
init_dom_stack(&stack, 1);
|
init_dom_stack(&stack, DOM_STACK_KEEP_NODES);
|
||||||
add_dom_stack_context(&stack, &select_data,
|
add_dom_stack_context(&stack, &select_data,
|
||||||
&dom_select_context_info);
|
&dom_select_context_info);
|
||||||
|
|
||||||
init_dom_stack(&select_data.stack, 1);
|
init_dom_stack(&select_data.stack, DOM_STACK_KEEP_NODES);
|
||||||
add_dom_stack_context(&stack, &select_data,
|
add_dom_stack_context(&stack, &select_data,
|
||||||
&dom_select_data_context_info);
|
&dom_select_data_context_info);
|
||||||
|
|
||||||
|
@ -53,13 +53,13 @@ realloc_dom_stack_state_objects(struct dom_stack_context *context, size_t depth)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
init_dom_stack(struct dom_stack *stack, int keep_nodes)
|
init_dom_stack(struct dom_stack *stack, enum dom_stack_flag flags)
|
||||||
{
|
{
|
||||||
assert(stack);
|
assert(stack);
|
||||||
|
|
||||||
memset(stack, 0, sizeof(*stack));
|
memset(stack, 0, sizeof(*stack));
|
||||||
|
|
||||||
stack->keep_nodes = !!keep_nodes;
|
stack->flags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -178,7 +178,7 @@ do_pop_dom_node(struct dom_stack *stack, struct dom_stack_state *parent)
|
|||||||
|
|
||||||
call_dom_stack_callbacks(stack, state, DOM_STACK_POP);
|
call_dom_stack_callbacks(stack, state, DOM_STACK_POP);
|
||||||
|
|
||||||
if (!stack->keep_nodes)
|
if (!(stack->flags & DOM_STACK_KEEP_NODES))
|
||||||
done_dom_node(state->node);
|
done_dom_node(state->node);
|
||||||
|
|
||||||
stack->depth--;
|
stack->depth--;
|
||||||
|
@ -53,6 +53,11 @@ struct dom_stack_state {
|
|||||||
unsigned int immutable:1;
|
unsigned int immutable:1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum dom_stack_flag {
|
||||||
|
/* Keep nodes when popping them or call done_dom_node() on them. */
|
||||||
|
DOM_STACK_KEEP_NODES = 1,
|
||||||
|
};
|
||||||
|
|
||||||
/* The DOM stack is a convenient way to traverse DOM trees. Also it
|
/* The DOM stack is a convenient way to traverse DOM trees. Also it
|
||||||
* maintains needed state info and is therefore also a holder of the current
|
* maintains needed state info and is therefore also a holder of the current
|
||||||
* context since the stack is used to when the DOM tree is manipulated. */
|
* context since the stack is used to when the DOM tree is manipulated. */
|
||||||
@ -61,8 +66,7 @@ struct dom_stack {
|
|||||||
struct dom_stack_state *states;
|
struct dom_stack_state *states;
|
||||||
size_t depth;
|
size_t depth;
|
||||||
|
|
||||||
/* Keep nodes when popping them or call done_dom_node() on them. */
|
enum dom_stack_flag flags;
|
||||||
unsigned int keep_nodes:1;
|
|
||||||
|
|
||||||
/* Callbacks which should be called for the pushed and popped nodes. */
|
/* Callbacks which should be called for the pushed and popped nodes. */
|
||||||
struct dom_stack_context *contexts;
|
struct dom_stack_context *contexts;
|
||||||
@ -121,7 +125,7 @@ search_dom_stack(struct dom_stack *stack, enum dom_node_type type,
|
|||||||
|
|
||||||
/* Life cycle functions. */
|
/* Life cycle functions. */
|
||||||
|
|
||||||
void init_dom_stack(struct dom_stack *stack, int keep_nodes);
|
void init_dom_stack(struct dom_stack *stack, enum dom_stack_flag flags);
|
||||||
void done_dom_stack(struct dom_stack *stack);
|
void done_dom_stack(struct dom_stack *stack);
|
||||||
|
|
||||||
/* Add a callback collection to the stack. */
|
/* Add a callback collection to the stack. */
|
||||||
|
@ -353,6 +353,7 @@ init_sgml_parser(enum sgml_parser_type type, enum sgml_document_type doctype,
|
|||||||
struct uri *uri)
|
struct uri *uri)
|
||||||
{
|
{
|
||||||
struct sgml_parser *parser;
|
struct sgml_parser *parser;
|
||||||
|
enum dom_stack_flag flags = 0;
|
||||||
|
|
||||||
parser = mem_calloc(1, sizeof(*parser));
|
parser = mem_calloc(1, sizeof(*parser));
|
||||||
if (!parser) return NULL;
|
if (!parser) return NULL;
|
||||||
@ -361,7 +362,10 @@ init_sgml_parser(enum sgml_parser_type type, enum sgml_document_type doctype,
|
|||||||
parser->uri = get_uri_reference(uri);
|
parser->uri = get_uri_reference(uri);
|
||||||
parser->info = get_sgml_info(doctype);
|
parser->info = get_sgml_info(doctype);
|
||||||
|
|
||||||
init_dom_stack(&parser->stack, type != SGML_PARSER_STREAM);
|
if (type == SGML_PARSER_TREE)
|
||||||
|
flags |= DOM_STACK_KEEP_NODES;
|
||||||
|
|
||||||
|
init_dom_stack(&parser->stack, flags);
|
||||||
/* FIXME: Some sgml backend specific callbacks? Handle HTML script tags,
|
/* FIXME: Some sgml backend specific callbacks? Handle HTML script tags,
|
||||||
* and feed document.write() data back to the parser. */
|
* and feed document.write() data back to the parser. */
|
||||||
add_dom_stack_context(&parser->stack, parser, &sgml_parser_context_info);
|
add_dom_stack_context(&parser->stack, parser, &sgml_parser_context_info);
|
||||||
|
Loading…
Reference in New Issue
Block a user