mirror of
https://github.com/rkd77/elinks.git
synced 2025-06-30 22:19:29 -04:00
Introduce dom_stack_code enum and use it for push_dom_node()
This commit is contained in:
parent
a892c84601
commit
4a2cde1c00
@ -506,7 +506,7 @@ parse_dom_select(struct dom_select *select, struct dom_stack *stack,
|
|||||||
select->selector = select_node;
|
select->selector = select_node;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!push_dom_node(stack, &select_node->node))
|
if (push_dom_node(stack, &select_node->node) != DOM_STACK_CODE_OK)
|
||||||
return DOM_ERR_INVALID_STATE;
|
return DOM_ERR_INVALID_STATE;
|
||||||
|
|
||||||
if (select_node->node.type != DOM_NODE_ELEMENT)
|
if (select_node->node.type != DOM_NODE_ELEMENT)
|
||||||
@ -1070,7 +1070,7 @@ select_dom_nodes(struct dom_select *select, struct dom_node *root)
|
|||||||
&dom_select_data_context_info);
|
&dom_select_data_context_info);
|
||||||
add_dom_stack_tracer(&select_data.stack, "select-match: ");
|
add_dom_stack_tracer(&select_data.stack, "select-match: ");
|
||||||
|
|
||||||
if (push_dom_node(&select_data.stack, &select->selector->node)) {
|
if (push_dom_node(&select_data.stack, &select->selector->node) == DOM_STACK_CODE_OK) {
|
||||||
get_dom_stack_top(&select_data.stack)->immutable = 1;
|
get_dom_stack_top(&select_data.stack)->immutable = 1;
|
||||||
walk_dom_nodes(&stack, root);
|
walk_dom_nodes(&stack, root);
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,10 @@ add_sgml_document(struct dom_stack *stack, struct dom_string *string)
|
|||||||
{
|
{
|
||||||
struct dom_node *node = init_dom_node(DOM_NODE_DOCUMENT, string);
|
struct dom_node *node = init_dom_node(DOM_NODE_DOCUMENT, string);
|
||||||
|
|
||||||
return node ? push_dom_node(stack, node) : NULL;
|
if (node && push_dom_node(stack, node) == DOM_STACK_CODE_OK)
|
||||||
|
return node;
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline struct dom_node *
|
static inline struct dom_node *
|
||||||
@ -58,7 +61,7 @@ add_sgml_element(struct dom_stack *stack, struct dom_scanner_token *token)
|
|||||||
node_info = get_sgml_node_info(parser->info->elements, node);
|
node_info = get_sgml_node_info(parser->info->elements, node);
|
||||||
node->data.element.type = node_info->type;
|
node->data.element.type = node_info->type;
|
||||||
|
|
||||||
if (!push_dom_node(stack, node))
|
if (push_dom_node(stack, node) != DOM_STACK_CODE_OK)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
state = get_dom_stack_top(stack);
|
state = get_dom_stack_top(stack);
|
||||||
@ -92,7 +95,7 @@ add_sgml_attribute(struct dom_stack *stack,
|
|||||||
if (valtoken && valtoken->type == SGML_TOKEN_STRING)
|
if (valtoken && valtoken->type == SGML_TOKEN_STRING)
|
||||||
node->data.attribute.quoted = 1;
|
node->data.attribute.quoted = 1;
|
||||||
|
|
||||||
if (!node || !push_dom_node(stack, node))
|
if (!node || push_dom_node(stack, node) != DOM_STACK_CODE_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
pop_dom_node(stack);
|
pop_dom_node(stack);
|
||||||
@ -119,7 +122,10 @@ add_sgml_proc_instruction(struct dom_stack *stack, struct dom_scanner_token *tar
|
|||||||
node->data.proc_instruction.type = DOM_PROC_INSTRUCTION;
|
node->data.proc_instruction.type = DOM_PROC_INSTRUCTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
return push_dom_node(stack, node);
|
if (push_dom_node(stack, node) == DOM_STACK_CODE_OK)
|
||||||
|
return node;
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
@ -133,7 +139,7 @@ add_sgml_node(struct dom_stack *stack, enum dom_node_type type, struct dom_scann
|
|||||||
if (token->type == SGML_TOKEN_SPACE)
|
if (token->type == SGML_TOKEN_SPACE)
|
||||||
node->data.text.only_space = 1;
|
node->data.text.only_space = 1;
|
||||||
|
|
||||||
if (push_dom_node(stack, node))
|
if (push_dom_node(stack, node) == DOM_STACK_CODE_OK)
|
||||||
pop_dom_node(stack);
|
pop_dom_node(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -403,7 +409,7 @@ parse_sgml(struct sgml_parser *parser, unsigned char *buf, size_t bufsize,
|
|||||||
}
|
}
|
||||||
|
|
||||||
node = init_dom_node(DOM_NODE_TEXT, &source);
|
node = init_dom_node(DOM_NODE_TEXT, &source);
|
||||||
if (!node || !push_dom_node(&parser->parsing, node))
|
if (!node || push_dom_node(&parser->parsing, node) != DOM_STACK_CODE_OK)
|
||||||
return SGML_PARSER_CODE_MEM_ALLOC;
|
return SGML_PARSER_CODE_MEM_ALLOC;
|
||||||
|
|
||||||
pop_dom_node(&parser->parsing);
|
pop_dom_node(&parser->parsing);
|
||||||
|
@ -154,7 +154,7 @@ call_dom_stack_callbacks(struct dom_stack *stack, struct dom_stack_state *state,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct dom_node *
|
enum dom_stack_code
|
||||||
push_dom_node(struct dom_stack *stack, struct dom_node *node)
|
push_dom_node(struct dom_stack *stack, struct dom_node *node)
|
||||||
{
|
{
|
||||||
struct dom_stack_state *state;
|
struct dom_stack_state *state;
|
||||||
@ -164,13 +164,13 @@ push_dom_node(struct dom_stack *stack, struct dom_node *node)
|
|||||||
assert(0 < node->type && node->type < DOM_NODES);
|
assert(0 < node->type && node->type < DOM_NODES);
|
||||||
|
|
||||||
if (stack->depth > DOM_STACK_MAX_DEPTH) {
|
if (stack->depth > DOM_STACK_MAX_DEPTH) {
|
||||||
return NULL;
|
return DOM_STACK_CODE_ERROR_MAX_DEPTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
state = realloc_dom_stack_states(&stack->states, stack->depth);
|
state = realloc_dom_stack_states(&stack->states, stack->depth);
|
||||||
if (!state) {
|
if (!state) {
|
||||||
done_dom_node(node);
|
done_dom_node(node);
|
||||||
return NULL;
|
return DOM_STACK_CODE_ERROR_MEM_ALLOC;
|
||||||
}
|
}
|
||||||
|
|
||||||
state += stack->depth;
|
state += stack->depth;
|
||||||
@ -181,7 +181,7 @@ push_dom_node(struct dom_stack *stack, struct dom_node *node)
|
|||||||
if (context->info->object_size
|
if (context->info->object_size
|
||||||
&& !realloc_dom_stack_state_objects(context, stack->depth)) {
|
&& !realloc_dom_stack_state_objects(context, stack->depth)) {
|
||||||
done_dom_node(node);
|
done_dom_node(node);
|
||||||
return NULL;
|
return DOM_STACK_CODE_ERROR_MEM_ALLOC;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,7 +193,7 @@ push_dom_node(struct dom_stack *stack, struct dom_node *node)
|
|||||||
stack->depth++;
|
stack->depth++;
|
||||||
call_dom_stack_callbacks(stack, state, DOM_STACK_PUSH);
|
call_dom_stack_callbacks(stack, state, DOM_STACK_PUSH);
|
||||||
|
|
||||||
return node;
|
return DOM_STACK_CODE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -349,7 +349,8 @@ walk_dom_nodes(struct dom_stack *stack, struct dom_node *root)
|
|||||||
if (!context)
|
if (!context)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
push_dom_node(stack, root);
|
if (push_dom_node(stack, root) != DOM_STACK_CODE_OK)
|
||||||
|
return;
|
||||||
|
|
||||||
while (!dom_stack_is_empty(stack)) {
|
while (!dom_stack_is_empty(stack)) {
|
||||||
struct dom_stack_state *state = get_dom_stack_top(stack);
|
struct dom_stack_state *state = get_dom_stack_top(stack);
|
||||||
|
@ -9,6 +9,16 @@ struct dom_stack;
|
|||||||
|
|
||||||
/* API Doc :: dom-stack */
|
/* API Doc :: dom-stack */
|
||||||
|
|
||||||
|
/** DOM stack code
|
||||||
|
*
|
||||||
|
* Codes used by the DOM stack to indicate states.
|
||||||
|
*/
|
||||||
|
enum dom_stack_code {
|
||||||
|
DOM_STACK_CODE_OK, /*: All is well */
|
||||||
|
DOM_STACK_CODE_ERROR_MEM_ALLOC, /*: Memory allocation failure */
|
||||||
|
DOM_STACK_CODE_ERROR_MAX_DEPTH, /*: Stack max depth reached */
|
||||||
|
};
|
||||||
|
|
||||||
/** DOM stack callback
|
/** DOM stack callback
|
||||||
*
|
*
|
||||||
* Used by contexts, for 'hooking' into the node traversing. */
|
* Used by contexts, for 'hooking' into the node traversing. */
|
||||||
@ -230,7 +240,7 @@ void done_dom_stack_context(struct dom_stack *stack, struct dom_stack_context *c
|
|||||||
*
|
*
|
||||||
* If an error occurs the node is released with ref:[done_dom_node] and NULL is
|
* If an error occurs the node is released with ref:[done_dom_node] and NULL is
|
||||||
* returned. Else the pushed node is returned. */
|
* returned. Else the pushed node is returned. */
|
||||||
struct dom_node *push_dom_node(struct dom_stack *stack, struct dom_node *node);
|
enum dom_stack_code push_dom_node(struct dom_stack *stack, struct dom_node *node);
|
||||||
|
|
||||||
/** Pop the top stack state
|
/** Pop the top stack state
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user