0
0
mirror of https://github.com/rkd77/elinks.git synced 2025-06-30 22:19:29 -04:00

DOM: Added add_document_callback and redefined the other callbacks.

This commit is contained in:
Witold Filipczyk 2007-05-16 21:21:52 +02:00 committed by Witold Filipczyk
parent c6a8822926
commit e53f3b2c99
2 changed files with 14 additions and 10 deletions

View File

@ -41,10 +41,13 @@ add_sgml_document(struct sgml_parser *parser)
struct dom_node *node; struct dom_node *node;
node = init_dom_node(DOM_NODE_DOCUMENT, &parser->uri, allocated); node = init_dom_node(DOM_NODE_DOCUMENT, &parser->uri, allocated);
if (node && push_dom_node(&parser->stack, node) == DOM_CODE_OK)
return node;
return NULL; if (!node || push_dom_node(&parser->stack, node) != DOM_CODE_OK)
return NULL;
if (parser->add_document_callback)
parser->add_document_callback(node);
return node;
} }
static inline struct dom_node * static inline struct dom_node *
@ -67,7 +70,7 @@ add_sgml_element(struct dom_stack *stack, struct dom_scanner_token *token)
return NULL; return NULL;
if (parser->add_element_callback) if (parser->add_element_callback)
parser->add_element_callback(parent, node); parser->add_element_callback(parser->root, parent, node);
state = get_dom_stack_top(stack); state = get_dom_stack_top(stack);
assert(node == state->node); assert(node == state->node);
@ -104,7 +107,8 @@ add_sgml_attribute(struct dom_stack *stack,
return NULL; return NULL;
if (parser->add_attribute_callback) if (parser->add_attribute_callback)
parser->add_attribute_callback(parent, node); parser->add_attribute_callback(parser->root, parent,
&token->string, value);
pop_dom_node(stack); pop_dom_node(stack);

View File

@ -69,9 +69,6 @@ struct sgml_parser_state {
typedef enum dom_code typedef enum dom_code
(*sgml_error_T)(struct sgml_parser *, struct dom_string *, unsigned int); (*sgml_error_T)(struct sgml_parser *, struct dom_string *, unsigned int);
typedef void
(*sgml_callback_T)(struct dom_node *parent, struct dom_node *current);
/** The SGML parser /** The SGML parser
* *
* This struct hold info used while parsing SGML data. * This struct hold info used while parsing SGML data.
@ -90,8 +87,11 @@ struct sgml_parser {
enum dom_code code; /**< The latest (error) code */ enum dom_code code; /**< The latest (error) code */
sgml_error_T error_func; /**< Called for detected errors */ sgml_error_T error_func; /**< Called for detected errors */
sgml_callback_T add_element_callback; /**< Called for added elements */ void (*add_document_callback)(struct dom_node *root);
sgml_callback_T add_attribute_callback; /**< Called for added attributes */ void (*add_element_callback)(struct dom_node *root, struct dom_node *parent,
struct dom_node *node);
void (*add_attribute_callback)(struct dom_node *root, struct dom_node *node,
struct dom_string *attr, struct dom_string *value);
struct dom_stack stack; /**< A stack for tracking parsed nodes */ struct dom_stack stack; /**< A stack for tracking parsed nodes */
struct dom_stack parsing; /**< Used for tracking parsing states */ struct dom_stack parsing; /**< Used for tracking parsing states */