1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

DOM: Replace various DOM status/error/exception codes with dom_code enum

Replaces sgml_parser_code, dom_stack_code, and dom_exception_code and
generally tries to simplify things and remove redundant codes.
This commit is contained in:
Jonas Fonseca 2006-01-31 22:01:35 +01:00 committed by Jonas Fonseca
parent 73c06aaa10
commit 92a9cafb6e
9 changed files with 222 additions and 224 deletions

View File

@ -507,7 +507,7 @@ render_dom_node_enhanced_text(struct dom_renderer *renderer, struct dom_node *no
} }
#endif #endif
static enum dom_stack_code static enum dom_code
render_dom_node_source(struct dom_stack *stack, struct dom_node *node, void *data) render_dom_node_source(struct dom_stack *stack, struct dom_node *node, void *data)
{ {
struct dom_renderer *renderer = stack->current->data; struct dom_renderer *renderer = stack->current->data;
@ -524,11 +524,11 @@ render_dom_node_source(struct dom_stack *stack, struct dom_node *node, void *dat
#endif #endif
render_dom_node_text(renderer, &renderer->styles[node->type], node); render_dom_node_text(renderer, &renderer->styles[node->type], node);
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
} }
/* This callback is also used for rendering processing instruction nodes. */ /* This callback is also used for rendering processing instruction nodes. */
static enum dom_stack_code static enum dom_code
render_dom_element_source(struct dom_stack *stack, struct dom_node *node, void *data) render_dom_element_source(struct dom_stack *stack, struct dom_node *node, void *data)
{ {
struct dom_renderer *renderer = stack->current->data; struct dom_renderer *renderer = stack->current->data;
@ -537,10 +537,10 @@ render_dom_element_source(struct dom_stack *stack, struct dom_node *node, void *
render_dom_node_text(renderer, &renderer->styles[node->type], node); render_dom_node_text(renderer, &renderer->styles[node->type], node);
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
} }
enum dom_stack_code enum dom_code
render_dom_element_end_source(struct dom_stack *stack, struct dom_node *node, void *data) render_dom_element_end_source(struct dom_stack *stack, struct dom_node *node, void *data)
{ {
struct dom_renderer *renderer = stack->current->data; struct dom_renderer *renderer = stack->current->data;
@ -553,7 +553,7 @@ render_dom_element_end_source(struct dom_stack *stack, struct dom_node *node, vo
assert(node && renderer && renderer->document); assert(node && renderer && renderer->document);
if (!string || !length) if (!string || !length)
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
if (check_dom_node_source(renderer, string, length)) { if (check_dom_node_source(renderer, string, length)) {
render_dom_flush(renderer, string); render_dom_flush(renderer, string);
@ -563,7 +563,7 @@ render_dom_element_end_source(struct dom_stack *stack, struct dom_node *node, vo
render_dom_text(renderer, &renderer->styles[node->type], string, length); render_dom_text(renderer, &renderer->styles[node->type], string, length);
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
} }
static void static void
@ -587,7 +587,7 @@ set_base_uri(struct dom_renderer *renderer, unsigned char *value, size_t valuele
renderer->base_uri = uri; renderer->base_uri = uri;
} }
enum dom_stack_code enum dom_code
render_dom_attribute_source(struct dom_stack *stack, struct dom_node *node, void *data) render_dom_attribute_source(struct dom_stack *stack, struct dom_node *node, void *data)
{ {
struct dom_renderer *renderer = stack->current->data; struct dom_renderer *renderer = stack->current->data;
@ -659,10 +659,10 @@ render_dom_attribute_source(struct dom_stack *stack, struct dom_node *node, void
} }
} }
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
} }
enum dom_stack_code enum dom_code
render_dom_cdata_source(struct dom_stack *stack, struct dom_node *node, void *data) render_dom_cdata_source(struct dom_stack *stack, struct dom_node *node, void *data)
{ {
struct dom_renderer *renderer = stack->current->data; struct dom_renderer *renderer = stack->current->data;
@ -680,10 +680,10 @@ render_dom_cdata_source(struct dom_stack *stack, struct dom_node *node, void *da
render_dom_node_text(renderer, &renderer->styles[node->type], node); render_dom_node_text(renderer, &renderer->styles[node->type], node);
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
} }
enum dom_stack_code enum dom_code
render_dom_document_end(struct dom_stack *stack, struct dom_node *node, void *data) render_dom_document_end(struct dom_stack *stack, struct dom_node *node, void *data)
{ {
struct dom_renderer *renderer = stack->current->data; struct dom_renderer *renderer = stack->current->data;
@ -695,7 +695,7 @@ render_dom_document_end(struct dom_stack *stack, struct dom_node *node, void *da
render_dom_flush(renderer, renderer->end); render_dom_flush(renderer, renderer->end);
} }
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
} }
static struct dom_stack_context_info dom_source_renderer_context_info = { static struct dom_stack_context_info dom_source_renderer_context_info = {
@ -740,7 +740,7 @@ static struct dom_stack_context_info dom_source_renderer_context_info = {
#define RSS_CONFIG_FLAGS \ #define RSS_CONFIG_FLAGS \
(DOM_CONFIG_NORMALIZE_WHITESPACE | DOM_CONFIG_NORMALIZE_CHARACTERS) (DOM_CONFIG_NORMALIZE_WHITESPACE | DOM_CONFIG_NORMALIZE_CHARACTERS)
enum dom_stack_code enum dom_code
dom_rss_push_element(struct dom_stack *stack, struct dom_node *node, void *data) dom_rss_push_element(struct dom_stack *stack, struct dom_node *node, void *data)
{ {
struct dom_renderer *renderer = stack->current->data; struct dom_renderer *renderer = stack->current->data;
@ -783,10 +783,10 @@ dom_rss_push_element(struct dom_stack *stack, struct dom_node *node, void *data)
renderer->node = node; renderer->node = node;
} }
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
} }
enum dom_stack_code enum dom_code
dom_rss_pop_element(struct dom_stack *stack, struct dom_node *node, void *data) dom_rss_pop_element(struct dom_stack *stack, struct dom_node *node, void *data)
{ {
struct dom_renderer *renderer = stack->current->data; struct dom_renderer *renderer = stack->current->data;
@ -826,7 +826,7 @@ dom_rss_pop_element(struct dom_stack *stack, struct dom_node *node, void *data)
break; break;
} }
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
} }
@ -897,13 +897,13 @@ render_rss_item(struct dom_renderer *renderer, struct dom_node *item)
} }
} }
enum dom_stack_code enum dom_code
dom_rss_pop_document(struct dom_stack *stack, struct dom_node *root, void *data) dom_rss_pop_document(struct dom_stack *stack, struct dom_node *root, void *data)
{ {
struct dom_renderer *renderer = stack->current->data; struct dom_renderer *renderer = stack->current->data;
if (!renderer->channel) if (!renderer->channel)
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
render_rss_item(renderer, renderer->channel); render_rss_item(renderer, renderer->channel);
@ -924,7 +924,7 @@ dom_rss_pop_document(struct dom_stack *stack, struct dom_node *root, void *data)
done_dom_node(root); done_dom_node(root);
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
} }
@ -978,7 +978,7 @@ render_dom_document(struct cache_entry *cached, struct document *document,
unsigned char *string = struri(cached->uri); unsigned char *string = struri(cached->uri);
size_t length = strlen(string); size_t length = strlen(string);
struct dom_string uri = INIT_DOM_STRING(string, length); struct dom_string uri = INIT_DOM_STRING(string, length);
enum sgml_parser_code code; enum dom_code code;
convert_table = get_convert_table(head, document->options.cp, convert_table = get_convert_table(head, document->options.cp,
document->options.assume_cp, document->options.assume_cp,

View File

@ -12,7 +12,7 @@
#include "dom/string.h" #include "dom/string.h"
static enum dom_stack_code static enum dom_code
normalize_text_node_whitespace(struct dom_node *node) normalize_text_node_whitespace(struct dom_node *node)
{ {
unsigned char buf[256]; unsigned char buf[256];
@ -44,7 +44,7 @@ normalize_text_node_whitespace(struct dom_node *node)
if (!add_to_dom_string(&string, buf, j)) { if (!add_to_dom_string(&string, buf, j)) {
done_dom_string(&string); done_dom_string(&string);
return DOM_STACK_CODE_ERROR_MEM_ALLOC; return DOM_CODE_ALLOC_ERR;
} }
} }
@ -54,11 +54,11 @@ normalize_text_node_whitespace(struct dom_node *node)
set_dom_string(&node->string, string.string, string.length); set_dom_string(&node->string, string.string, string.length);
node->allocated = 1; node->allocated = 1;
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
} }
static enum dom_stack_code static enum dom_code
append_node_text(struct dom_config *config, struct dom_node *node) append_node_text(struct dom_config *config, struct dom_node *node)
{ {
struct dom_node *prev = get_dom_node_prev(node); struct dom_node *prev = get_dom_node_prev(node);
@ -72,7 +72,7 @@ append_node_text(struct dom_config *config, struct dom_node *node)
if (!prev || prev->type != DOM_NODE_TEXT) { if (!prev || prev->type != DOM_NODE_TEXT) {
/* Preserve text nodes with no one to append to. */ /* Preserve text nodes with no one to append to. */
if (node->type == DOM_NODE_TEXT) if (node->type == DOM_NODE_TEXT)
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
prev = NULL; prev = NULL;
set_dom_string(&dest, NULL, 0); set_dom_string(&dest, NULL, 0);
@ -83,7 +83,7 @@ append_node_text(struct dom_config *config, struct dom_node *node)
} else { } else {
set_dom_string(&dest, NULL, 0); set_dom_string(&dest, NULL, 0);
if (!add_to_dom_string(&dest, prev->string.string, prev->string.length)) if (!add_to_dom_string(&dest, prev->string.string, prev->string.length))
return DOM_STACK_CODE_ERROR_MEM_ALLOC; return DOM_CODE_ALLOC_ERR;
set_dom_string(&prev->string, dest.string, dest.length); set_dom_string(&prev->string, dest.string, dest.length);
prev->allocated = 1; prev->allocated = 1;
} }
@ -119,7 +119,7 @@ append_node_text(struct dom_config *config, struct dom_node *node)
prev->string.length = length; prev->string.length = length;
else else
done_dom_string(&dest); done_dom_string(&dest);
return DOM_STACK_CODE_ERROR_MEM_ALLOC; return DOM_CODE_ALLOC_ERR;
} }
if (prev) { if (prev) {
@ -132,7 +132,7 @@ append_node_text(struct dom_config *config, struct dom_node *node)
normalize_text_node_whitespace(prev); normalize_text_node_whitespace(prev);
} }
return DOM_STACK_CODE_FREE_NODE; return DOM_CODE_FREE_NODE;
} else { } else {
int was_cdata_section = node->type == DOM_NODE_CDATA_SECTION; int was_cdata_section = node->type == DOM_NODE_CDATA_SECTION;
@ -149,15 +149,15 @@ append_node_text(struct dom_config *config, struct dom_node *node)
normalize_text_node_whitespace(node); normalize_text_node_whitespace(node);
} }
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
} }
} }
static enum dom_stack_code static enum dom_code
dom_normalize_node_end(struct dom_stack *stack, struct dom_node *node, void *data) dom_normalize_node_end(struct dom_stack *stack, struct dom_node *node, void *data)
{ {
struct dom_config *config = stack->current->data; struct dom_config *config = stack->current->data;
enum dom_stack_code code = DOM_STACK_CODE_OK; enum dom_code code = DOM_CODE_OK;
switch (node->type) { switch (node->type) {
case DOM_NODE_ELEMENT: case DOM_NODE_ELEMENT:
@ -165,7 +165,7 @@ dom_normalize_node_end(struct dom_stack *stack, struct dom_node *node, void *dat
&& !node->data.element.type) { && !node->data.element.type) {
/* Drop elements that are not known from the built-in /* Drop elements that are not known from the built-in
* node info. */ * node info. */
code = DOM_STACK_CODE_FREE_NODE; code = DOM_CODE_FREE_NODE;
} }
break; break;
@ -174,7 +174,7 @@ dom_normalize_node_end(struct dom_stack *stack, struct dom_node *node, void *dat
&& !node->data.attribute.type) { && !node->data.attribute.type) {
/* Drop elements that are not known from the built-in /* Drop elements that are not known from the built-in
* node info. */ * node info. */
code = DOM_STACK_CODE_FREE_NODE; code = DOM_CODE_FREE_NODE;
} }
break; break;
@ -183,7 +183,7 @@ dom_normalize_node_end(struct dom_stack *stack, struct dom_node *node, void *dat
&& !node->data.proc_instruction.type) { && !node->data.proc_instruction.type) {
/* Drop elements that are not known from the built-in /* Drop elements that are not known from the built-in
* node info. */ * node info. */
code = DOM_STACK_CODE_FREE_NODE; code = DOM_CODE_FREE_NODE;
} }
break; break;
@ -192,7 +192,7 @@ dom_normalize_node_end(struct dom_stack *stack, struct dom_node *node, void *dat
&& node->data.text.only_space) { && node->data.text.only_space) {
/* Discard all Text nodes that contain /* Discard all Text nodes that contain
* whitespaces in element content]. */ * whitespaces in element content]. */
code = DOM_STACK_CODE_FREE_NODE; code = DOM_CODE_FREE_NODE;
} else { } else {
code = append_node_text(config, node); code = append_node_text(config, node);
} }
@ -201,7 +201,7 @@ dom_normalize_node_end(struct dom_stack *stack, struct dom_node *node, void *dat
case DOM_NODE_COMMENT: case DOM_NODE_COMMENT:
if (!(config->flags & DOM_CONFIG_COMMENTS)) { if (!(config->flags & DOM_CONFIG_COMMENTS)) {
/* Discard all comments. */ /* Discard all comments. */
code = DOM_STACK_CODE_FREE_NODE; code = DOM_CODE_FREE_NODE;
} }
break; break;
@ -234,7 +234,7 @@ dom_normalize_node_end(struct dom_stack *stack, struct dom_node *node, void *dat
return code; return code;
} }
enum dom_stack_code enum dom_code
dom_normalize_text(struct dom_stack *stack, struct dom_node *node, void *data) dom_normalize_text(struct dom_stack *stack, struct dom_node *node, void *data)
{ {
struct dom_config *config = stack->current->data; struct dom_config *config = stack->current->data;
@ -244,7 +244,7 @@ dom_normalize_text(struct dom_stack *stack, struct dom_node *node, void *data)
return normalize_text_node_whitespace(node); return normalize_text_node_whitespace(node);
} }
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
} }

View File

@ -1,25 +1,45 @@
#ifndef EL_DOM_DOM_H #ifndef EL_DOM_DOM_H
#define EL_DOM_DOM_H #define EL_DOM_DOM_H
enum dom_exception_code { /** DOM status/error/exception codes
DOM_ERR_NONE = 0, *
DOM_ERR_INDEX_SIZE = 1, * These enum values are used for return codes throughout the DOM engine.
DOM_ERR_STRING_SIZE = 2, */
DOM_ERR_HIERARCHY_REQUEST = 3, enum dom_code {
DOM_ERR_WRONG_DOCUMENT = 4, /** ELinks specific codes: */
DOM_ERR_INVALID_CHARACTER = 5, DOM_CODE_OK = 0, /*: The sane default. */
DOM_ERR_NO_DATA_ALLOWED = 6, DOM_CODE_ERR = -1000, /*: Anything by DOM_CODE_OK. */
DOM_ERR_NO_MODIFICATION_ALLOWED = 7,
DOM_ERR_NOT_FOUND = 8,
DOM_ERR_NOT_SUPPORTED = 9,
DOM_ERR_INUSE_ATTRIBUTE = 10,
/* Introduced in DOM Level 2: */ DOM_CODE_INCOMPLETE, /*: The parsing could not be completed */
DOM_ERR_INVALID_STATE = 11, DOM_CODE_FREE_NODE, /*: Discard the node */
DOM_ERR_SYNTAX = 12,
DOM_ERR_INVALID_MODIFICATION = 13, /** Error codes: */
DOM_ERR_NAMESPACE = 14, DOM_CODE_ALLOC_ERR, /*: Failed to allocate memory */
DOM_ERR_INVALID_ACCESS = 15, DOM_CODE_MAX_DEPTH_ERR, /*: Stack max depth reached */
DOM_CODE_VALUE_ERR, /*: Bad/unexpected value */
/** DOM Level 1 codes: */
DOM_CODE_INDEX_SIZE_ERR = 1,
DOM_CODE_STRING_SIZE_ERR = 2,
DOM_CODE_HIERARCHY_REQUEST_ERR = 3,
DOM_CODE_WRONG_DOCUMENT_ERR = 4,
DOM_CODE_INVALID_CHARACTER_ERR = 5,
DOM_CODE_NO_DATA_ALLOWED_ERR = 6,
DOM_CODE_NO_MODIFICATION_ALLOWED_ERR = 7,
DOM_CODE_NOT_FOUND_ERR = 8,
DOM_CODE_NOT_SUPPORTED_ERR = 9,
DOM_CODE_INUSE_ATTRIBUTE_ERR = 10,
/** Introduced in DOM Level 2: */
DOM_CODE_INVALID_STATE_ERR = 11,
DOM_CODE_SYNTAX_ERR = 12,
DOM_CODE_INVALID_MODIFICATION_ERR = 13,
DOM_CODE_NAMESPACE_ERR = 14,
DOM_CODE_INVALID_ACCESS_ERR = 15,
/** Introduced in DOM Level 3: */
DOM_CODE_VALIDATION_ERR = 16,
DOM_CODE_TYPE_MISMATCH_ERR = 17,
}; };
#endif #endif

View File

@ -80,7 +80,7 @@ get_dom_select_pseudo(struct dom_scanner_token *token)
} }
/* Parses attribute selector. For example '[foo="bar"]' or '[foo|="boo"]'. */ /* Parses attribute selector. For example '[foo="bar"]' or '[foo|="boo"]'. */
static enum dom_exception_code static enum dom_code
parse_dom_select_attribute(struct dom_select_node *sel, struct dom_scanner *scanner) parse_dom_select_attribute(struct dom_select_node *sel, struct dom_scanner *scanner)
{ {
struct dom_scanner_token *token = get_dom_scanner_token(scanner); struct dom_scanner_token *token = get_dom_scanner_token(scanner);
@ -88,25 +88,25 @@ parse_dom_select_attribute(struct dom_select_node *sel, struct dom_scanner *scan
/* Get '['. */ /* Get '['. */
if (token->type != '[') if (token->type != '[')
return DOM_ERR_INVALID_STATE; return DOM_CODE_SYNTAX_ERR;
/* Get the attribute name. */ /* Get the attribute name. */
token = get_next_dom_scanner_token(scanner); token = get_next_dom_scanner_token(scanner);
if (!token || token->type != CSS_TOKEN_IDENT) if (!token || token->type != CSS_TOKEN_IDENT)
return DOM_ERR_SYNTAX; return DOM_CODE_SYNTAX_ERR;
copy_dom_string(&sel->node.string, &token->string); copy_dom_string(&sel->node.string, &token->string);
/* Get the optional '=' combo or ending ']'. */ /* Get the optional '=' combo or ending ']'. */
token = get_next_dom_scanner_token(scanner); token = get_next_dom_scanner_token(scanner);
if (!token) return DOM_ERR_SYNTAX; if (!token) return DOM_CODE_SYNTAX_ERR;
switch (token->type) { switch (token->type) {
case ']': case ']':
sel->match.attribute |= DOM_SELECT_ATTRIBUTE_ANY; sel->match.attribute |= DOM_SELECT_ATTRIBUTE_ANY;
return DOM_ERR_NONE; return DOM_CODE_OK;
case CSS_TOKEN_SELECT_SPACE_LIST: case CSS_TOKEN_SELECT_SPACE_LIST:
sel->match.attribute |= DOM_SELECT_ATTRIBUTE_SPACE_LIST; sel->match.attribute |= DOM_SELECT_ATTRIBUTE_SPACE_LIST;
@ -129,13 +129,13 @@ parse_dom_select_attribute(struct dom_select_node *sel, struct dom_scanner *scan
break; break;
default: default:
return DOM_ERR_SYNTAX; return DOM_CODE_SYNTAX_ERR;
} }
/* Get the required value. */ /* Get the required value. */
token = get_next_dom_scanner_token(scanner); token = get_next_dom_scanner_token(scanner);
if (!token) return DOM_ERR_SYNTAX; if (!token) return DOM_CODE_SYNTAX_ERR;
switch (token->type) { switch (token->type) {
case CSS_TOKEN_IDENT: case CSS_TOKEN_IDENT:
@ -144,16 +144,16 @@ parse_dom_select_attribute(struct dom_select_node *sel, struct dom_scanner *scan
break; break;
default: default:
return DOM_ERR_SYNTAX; return DOM_CODE_SYNTAX_ERR;
} }
/* Get the ending ']'. */ /* Get the ending ']'. */
token = get_next_dom_scanner_token(scanner); token = get_next_dom_scanner_token(scanner);
if (token && token->type == ']') if (token && token->type == ']')
return DOM_ERR_NONE; return DOM_CODE_OK;
return DOM_ERR_SYNTAX; return DOM_CODE_SYNTAX_ERR;
} }
/* Parse: /* Parse:
@ -190,7 +190,7 @@ get_scanner_token_number(struct dom_scanner_token *token)
} }
/* Parses the '(...)' part of ':nth-of-type(...)' and ':nth-child(...)'. */ /* Parses the '(...)' part of ':nth-of-type(...)' and ':nth-child(...)'. */
static enum dom_exception_code static enum dom_code
parse_dom_select_nth_arg(struct dom_select_nth_match *nth, struct dom_scanner *scanner) parse_dom_select_nth_arg(struct dom_select_nth_match *nth, struct dom_scanner *scanner)
{ {
struct dom_scanner_token *token = get_next_dom_scanner_token(scanner); struct dom_scanner_token *token = get_next_dom_scanner_token(scanner);
@ -198,11 +198,11 @@ parse_dom_select_nth_arg(struct dom_select_nth_match *nth, struct dom_scanner *s
int number = -1; int number = -1;
if (!token || token->type != '(') if (!token || token->type != '(')
return DOM_ERR_SYNTAX; return DOM_CODE_SYNTAX_ERR;
token = get_next_dom_scanner_token(scanner); token = get_next_dom_scanner_token(scanner);
if (!token) if (!token)
return DOM_ERR_SYNTAX; return DOM_CODE_SYNTAX_ERR;
switch (token->type) { switch (token->type) {
case CSS_TOKEN_IDENT: case CSS_TOKEN_IDENT:
@ -220,59 +220,59 @@ parse_dom_select_nth_arg(struct dom_select_nth_match *nth, struct dom_scanner *s
} }
if (skip_css_tokens(scanner, ')')) if (skip_css_tokens(scanner, ')'))
return DOM_ERR_NONE; return DOM_CODE_OK;
return DOM_ERR_SYNTAX; return DOM_CODE_SYNTAX_ERR;
case '-': case '-':
sign = -1; sign = -1;
token = get_next_dom_scanner_token(scanner); token = get_next_dom_scanner_token(scanner);
if (!token) return DOM_ERR_SYNTAX; if (!token) return DOM_CODE_SYNTAX_ERR;
if (token->type != CSS_TOKEN_IDENT) if (token->type != CSS_TOKEN_IDENT)
break; break;
if (token->type != CSS_TOKEN_NUMBER) if (token->type != CSS_TOKEN_NUMBER)
return DOM_ERR_SYNTAX; return DOM_CODE_SYNTAX_ERR;
/* Fall-through */ /* Fall-through */
case CSS_TOKEN_NUMBER: case CSS_TOKEN_NUMBER:
number = get_scanner_token_number(token); number = get_scanner_token_number(token);
if (number < 0) if (number < 0)
return DOM_ERR_INVALID_STATE; return DOM_CODE_VALUE_ERR;
token = get_next_dom_scanner_token(scanner); token = get_next_dom_scanner_token(scanner);
if (!token) return DOM_ERR_SYNTAX; if (!token) return DOM_CODE_SYNTAX_ERR;
break; break;
default: default:
return DOM_ERR_SYNTAX; return DOM_CODE_SYNTAX_ERR;
} }
/* The rest can contain n+ part */ /* The rest can contain n+ part */
switch (token->type) { switch (token->type) {
case CSS_TOKEN_IDENT: case CSS_TOKEN_IDENT:
if (!dom_scanner_token_contains(token, "n")) if (!dom_scanner_token_contains(token, "n"))
return DOM_ERR_SYNTAX; return DOM_CODE_SYNTAX_ERR;
nth->step = sign * number; nth->step = sign * number;
token = get_next_dom_scanner_token(scanner); token = get_next_dom_scanner_token(scanner);
if (!token) return DOM_ERR_SYNTAX; if (!token) return DOM_CODE_SYNTAX_ERR;
if (token->type != '+') if (token->type != '+')
break; break;
token = get_next_dom_scanner_token(scanner); token = get_next_dom_scanner_token(scanner);
if (!token) return DOM_ERR_SYNTAX; if (!token) return DOM_CODE_SYNTAX_ERR;
if (token->type != CSS_TOKEN_NUMBER) if (token->type != CSS_TOKEN_NUMBER)
break; break;
number = get_scanner_token_number(token); number = get_scanner_token_number(token);
if (number < 0) if (number < 0)
return DOM_ERR_INVALID_STATE; return DOM_CODE_VALUE_ERR;
nth->index = sign * number; nth->index = sign * number;
break; break;
@ -283,19 +283,19 @@ parse_dom_select_nth_arg(struct dom_select_nth_match *nth, struct dom_scanner *s
} }
if (skip_css_tokens(scanner, ')')) if (skip_css_tokens(scanner, ')'))
return DOM_ERR_NONE; return DOM_CODE_OK;
return DOM_ERR_SYNTAX; return DOM_CODE_SYNTAX_ERR;
} }
/* Parse a pseudo-class or -element with the syntax: ':<ident>'. */ /* Parse a pseudo-class or -element with the syntax: ':<ident>'. */
static enum dom_exception_code static enum dom_code
parse_dom_select_pseudo(struct dom_select *select, struct dom_select_node *sel, parse_dom_select_pseudo(struct dom_select *select, struct dom_select_node *sel,
struct dom_scanner *scanner) struct dom_scanner *scanner)
{ {
struct dom_scanner_token *token = get_dom_scanner_token(scanner); struct dom_scanner_token *token = get_dom_scanner_token(scanner);
enum dom_select_pseudo pseudo; enum dom_select_pseudo pseudo;
enum dom_exception_code code; enum dom_code code;
/* Skip double :'s in front of some pseudo's (::first-line, etc.) */ /* Skip double :'s in front of some pseudo's (::first-line, etc.) */
do { do {
@ -303,12 +303,12 @@ parse_dom_select_pseudo(struct dom_select *select, struct dom_select_node *sel,
} while (token && token->type == ':'); } while (token && token->type == ':');
if (!token || token->type != CSS_TOKEN_IDENT) if (!token || token->type != CSS_TOKEN_IDENT)
return DOM_ERR_SYNTAX; return DOM_CODE_SYNTAX_ERR;
pseudo = get_dom_select_pseudo(token); pseudo = get_dom_select_pseudo(token);
switch (pseudo) { switch (pseudo) {
case DOM_SELECT_PSEUDO_UNKNOWN: case DOM_SELECT_PSEUDO_UNKNOWN:
return DOM_ERR_NOT_FOUND; return DOM_CODE_ERR;
case DOM_SELECT_PSEUDO_CONTAINS: case DOM_SELECT_PSEUDO_CONTAINS:
/* FIXME: E:contains("text") */ /* FIXME: E:contains("text") */
@ -317,7 +317,7 @@ parse_dom_select_pseudo(struct dom_select *select, struct dom_select_node *sel,
case DOM_SELECT_PSEUDO_NTH_CHILD: case DOM_SELECT_PSEUDO_NTH_CHILD:
case DOM_SELECT_PSEUDO_NTH_LAST_CHILD: case DOM_SELECT_PSEUDO_NTH_LAST_CHILD:
code = parse_dom_select_nth_arg(&sel->nth_child, scanner); code = parse_dom_select_nth_arg(&sel->nth_child, scanner);
if (code != DOM_ERR_NONE) if (code != DOM_CODE_OK)
return code; return code;
sel->match.element |= DOM_SELECT_ELEMENT_NTH_CHILD; sel->match.element |= DOM_SELECT_ELEMENT_NTH_CHILD;
@ -341,7 +341,7 @@ parse_dom_select_pseudo(struct dom_select *select, struct dom_select_node *sel,
case DOM_SELECT_PSEUDO_NTH_TYPE: case DOM_SELECT_PSEUDO_NTH_TYPE:
case DOM_SELECT_PSEUDO_NTH_LAST_TYPE: case DOM_SELECT_PSEUDO_NTH_LAST_TYPE:
code = parse_dom_select_nth_arg(&sel->nth_type, scanner); code = parse_dom_select_nth_arg(&sel->nth_type, scanner);
if (code != DOM_ERR_NONE) if (code != DOM_CODE_OK)
return code; return code;
sel->match.element |= DOM_SELECT_ELEMENT_NTH_TYPE; sel->match.element |= DOM_SELECT_ELEMENT_NTH_TYPE;
@ -375,7 +375,7 @@ parse_dom_select_pseudo(struct dom_select *select, struct dom_select_node *sel,
select->pseudo |= pseudo; select->pseudo |= pseudo;
} }
return DOM_ERR_NONE; return DOM_CODE_OK;
} }
/* The element relation flags are mutual exclusive. This macro can be used /* The element relation flags are mutual exclusive. This macro can be used
@ -384,7 +384,7 @@ parse_dom_select_pseudo(struct dom_select *select, struct dom_select_node *sel,
((sel)->match.element & DOM_SELECT_RELATION_FLAGS) ((sel)->match.element & DOM_SELECT_RELATION_FLAGS)
/* Parse a CSS3 selector and add selector nodes to the @select struct. */ /* Parse a CSS3 selector and add selector nodes to the @select struct. */
static enum dom_exception_code static enum dom_code
parse_dom_select(struct dom_select *select, struct dom_stack *stack, parse_dom_select(struct dom_select *select, struct dom_stack *stack,
struct dom_string *string) struct dom_string *string)
{ {
@ -397,7 +397,7 @@ parse_dom_select(struct dom_select *select, struct dom_stack *stack,
while (dom_scanner_has_tokens(&scanner)) { while (dom_scanner_has_tokens(&scanner)) {
struct dom_scanner_token *token = get_dom_scanner_token(&scanner); struct dom_scanner_token *token = get_dom_scanner_token(&scanner);
enum dom_exception_code code; enum dom_code code;
struct dom_select_node *select_node; struct dom_select_node *select_node;
assert(token); assert(token);
@ -430,14 +430,14 @@ parse_dom_select(struct dom_select *select, struct dom_stack *stack,
case '[': case '[':
sel.node.type = DOM_NODE_ATTRIBUTE; sel.node.type = DOM_NODE_ATTRIBUTE;
code = parse_dom_select_attribute(&sel, &scanner); code = parse_dom_select_attribute(&sel, &scanner);
if (code != DOM_ERR_NONE) if (code != DOM_CODE_OK)
return code; return code;
break; break;
case '.': case '.':
token = get_next_dom_scanner_token(&scanner); token = get_next_dom_scanner_token(&scanner);
if (!token || token->type != CSS_TOKEN_IDENT) if (!token || token->type != CSS_TOKEN_IDENT)
return DOM_ERR_SYNTAX; return DOM_CODE_SYNTAX_ERR;
sel.node.type = DOM_NODE_ATTRIBUTE; sel.node.type = DOM_NODE_ATTRIBUTE;
sel.match.attribute |= DOM_SELECT_ATTRIBUTE_SPACE_LIST; sel.match.attribute |= DOM_SELECT_ATTRIBUTE_SPACE_LIST;
@ -447,30 +447,30 @@ parse_dom_select(struct dom_select *select, struct dom_stack *stack,
case ':': case ':':
code = parse_dom_select_pseudo(select, &sel, &scanner); code = parse_dom_select_pseudo(select, &sel, &scanner);
if (code != DOM_ERR_NONE) if (code != DOM_CODE_OK)
return code; return code;
break; break;
case '>': case '>':
if (get_element_relation(&sel) != DOM_SELECT_RELATION_DESCENDANT) if (get_element_relation(&sel) != DOM_SELECT_RELATION_DESCENDANT)
return DOM_ERR_SYNTAX; return DOM_CODE_SYNTAX_ERR;
sel.match.element |= DOM_SELECT_RELATION_DIRECT_CHILD; sel.match.element |= DOM_SELECT_RELATION_DIRECT_CHILD;
break; break;
case '+': case '+':
if (get_element_relation(&sel) != DOM_SELECT_RELATION_DESCENDANT) if (get_element_relation(&sel) != DOM_SELECT_RELATION_DESCENDANT)
return DOM_ERR_SYNTAX; return DOM_CODE_SYNTAX_ERR;
sel.match.element |= DOM_SELECT_RELATION_DIRECT_ADJACENT; sel.match.element |= DOM_SELECT_RELATION_DIRECT_ADJACENT;
break; break;
case '~': case '~':
if (get_element_relation(&sel) != DOM_SELECT_RELATION_DESCENDANT) if (get_element_relation(&sel) != DOM_SELECT_RELATION_DESCENDANT)
return DOM_ERR_SYNTAX; return DOM_CODE_SYNTAX_ERR;
sel.match.element |= DOM_SELECT_RELATION_INDIRECT_ADJACENT; sel.match.element |= DOM_SELECT_RELATION_INDIRECT_ADJACENT;
break; break;
default: default:
return DOM_ERR_SYNTAX; return DOM_CODE_SYNTAX_ERR;
} }
skip_dom_scanner_token(&scanner); skip_dom_scanner_token(&scanner);
@ -496,7 +496,7 @@ parse_dom_select(struct dom_select *select, struct dom_stack *stack,
if (!add_to_dom_node_list(list, node, index)) { if (!add_to_dom_node_list(list, node, index)) {
done_dom_node(node); done_dom_node(node);
return DOM_ERR_INVALID_STATE; return DOM_CODE_ALLOC_ERR;
} }
node->parent = parent; node->parent = parent;
@ -506,8 +506,9 @@ 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) != DOM_STACK_CODE_OK) code = push_dom_node(stack, &select_node->node);
return DOM_ERR_INVALID_STATE; if (code != DOM_CODE_OK)
return code;
if (select_node->node.type != DOM_NODE_ELEMENT) if (select_node->node.type != DOM_NODE_ELEMENT)
pop_dom_node(stack); pop_dom_node(stack);
@ -516,9 +517,9 @@ parse_dom_select(struct dom_select *select, struct dom_stack *stack,
} }
if (select->selector) if (select->selector)
return DOM_ERR_NONE; return DOM_CODE_OK;
return DOM_ERR_INVALID_STATE; return DOM_CODE_ERR;
} }
/* Basically this is just a wrapper for parse_dom_select() to ease error /* Basically this is just a wrapper for parse_dom_select() to ease error
@ -528,7 +529,7 @@ init_dom_select(enum dom_select_syntax syntax, struct dom_string *string)
{ {
struct dom_select *select = mem_calloc(1, sizeof(select)); struct dom_select *select = mem_calloc(1, sizeof(select));
struct dom_stack stack; struct dom_stack stack;
enum dom_exception_code code; enum dom_code code;
init_dom_stack(&stack, DOM_STACK_FLAG_NONE); init_dom_stack(&stack, DOM_STACK_FLAG_NONE);
add_dom_stack_tracer(&stack, "init-select: "); add_dom_stack_tracer(&stack, "init-select: ");
@ -536,7 +537,7 @@ init_dom_select(enum dom_select_syntax syntax, struct dom_string *string)
code = parse_dom_select(select, &stack, string); code = parse_dom_select(select, &stack, string);
done_dom_stack(&stack); done_dom_stack(&stack);
if (code == DOM_ERR_NONE) if (code == DOM_CODE_OK)
return select; return select;
done_dom_select(select); done_dom_select(select);
@ -897,7 +898,7 @@ match_element_selector(struct dom_select_node *selector, struct dom_node *node,
#define get_dom_select_data(stack) ((stack)->current->data) #define get_dom_select_data(stack) ((stack)->current->data)
/* Matches an element node being visited against the current selector stack. */ /* Matches an element node being visited against the current selector stack. */
enum dom_stack_code enum dom_code
dom_select_push_element(struct dom_stack *stack, struct dom_node *node, void *data) dom_select_push_element(struct dom_stack *stack, struct dom_node *node, void *data)
{ {
struct dom_select_data *select_data = get_dom_select_data(stack); struct dom_select_data *select_data = get_dom_select_data(stack);
@ -922,12 +923,12 @@ dom_select_push_element(struct dom_stack *stack, struct dom_node *node, void *da
push_dom_node(&select_data->stack, &selector->node); push_dom_node(&select_data->stack, &selector->node);
} }
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
} }
/* Ensures that nodes, no longer 'reachable' on the stack do not have any /* Ensures that nodes, no longer 'reachable' on the stack do not have any
* states associated with them on the select data stack. */ * states associated with them on the select data stack. */
enum dom_stack_code enum dom_code
dom_select_pop_element(struct dom_stack *stack, struct dom_node *node, void *data) dom_select_pop_element(struct dom_stack *stack, struct dom_node *node, void *data)
{ {
struct dom_select_data *select_data = get_dom_select_data(stack); struct dom_select_data *select_data = get_dom_select_data(stack);
@ -947,13 +948,13 @@ dom_select_pop_element(struct dom_stack *stack, struct dom_node *node, void *dat
} }
} }
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
} }
/* For now this is only for matching the ':contains(<string>)' pseudo-class. /* For now this is only for matching the ':contains(<string>)' pseudo-class.
* Any node which can contain text and thus characters from the given <string> * Any node which can contain text and thus characters from the given <string>
* are handled in this common callback. */ * are handled in this common callback. */
enum dom_stack_code enum dom_code
dom_select_push_text(struct dom_stack *stack, struct dom_node *node, void *data) dom_select_push_text(struct dom_stack *stack, struct dom_node *node, void *data)
{ {
struct dom_select_data *select_data = get_dom_select_data(stack); struct dom_select_data *select_data = get_dom_select_data(stack);
@ -965,7 +966,7 @@ dom_select_push_text(struct dom_stack *stack, struct dom_node *node, void *data)
WDBG("Text node: %d chars", node->string.length); WDBG("Text node: %d chars", node->string.length);
if (!text_sel) if (!text_sel)
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
text = &text_sel->node.string; text = &text_sel->node.string;
@ -978,7 +979,7 @@ dom_select_push_text(struct dom_stack *stack, struct dom_node *node, void *data)
ERROR("Unhandled type"); ERROR("Unhandled type");
} }
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
} }
/* Context info for interacting with the DOM tree or stream stack. */ /* Context info for interacting with the DOM tree or stream stack. */
@ -1076,7 +1077,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) == DOM_STACK_CODE_OK) { if (push_dom_node(&select_data.stack, &select->selector->node) == DOM_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);
} }

View File

@ -15,7 +15,7 @@
#include "dom/string.h" #include "dom/string.h"
static enum dom_stack_code static enum dom_code
sgml_file_dumper_element_push(struct dom_stack *stack, struct dom_node *node, void *data) sgml_file_dumper_element_push(struct dom_stack *stack, struct dom_node *node, void *data)
{ {
FILE *file = stack->current->data; FILE *file = stack->current->data;
@ -26,10 +26,10 @@ sgml_file_dumper_element_push(struct dom_stack *stack, struct dom_node *node, vo
|| node->data.element.map->size == 0) || node->data.element.map->size == 0)
fprintf(file, ">"); fprintf(file, ">");
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
} }
static enum dom_stack_code static enum dom_code
sgml_file_dumper_element_pop(struct dom_stack *stack, struct dom_node *node, void *data) sgml_file_dumper_element_pop(struct dom_stack *stack, struct dom_node *node, void *data)
{ {
FILE *file = stack->current->data; FILE *file = stack->current->data;
@ -37,10 +37,10 @@ sgml_file_dumper_element_pop(struct dom_stack *stack, struct dom_node *node, voi
fprintf(file, "</%.*s>", string->length, string->string); fprintf(file, "</%.*s>", string->length, string->string);
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
} }
static enum dom_stack_code static enum dom_code
sgml_file_dumper_attribute_push(struct dom_stack *stack, struct dom_node *node, void *data) sgml_file_dumper_attribute_push(struct dom_stack *stack, struct dom_node *node, void *data)
{ {
FILE *file = stack->current->data; FILE *file = stack->current->data;
@ -48,7 +48,7 @@ sgml_file_dumper_attribute_push(struct dom_stack *stack, struct dom_node *node,
struct dom_string *value = &node->data.attribute.value; struct dom_string *value = &node->data.attribute.value;
if (node->parent->type == DOM_NODE_PROCESSING_INSTRUCTION) if (node->parent->type == DOM_NODE_PROCESSING_INSTRUCTION)
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
fprintf(file, " %.*s", name->length, name->string); fprintf(file, " %.*s", name->length, name->string);
@ -66,10 +66,10 @@ sgml_file_dumper_attribute_push(struct dom_stack *stack, struct dom_node *node,
if (!get_dom_node_next(node)) if (!get_dom_node_next(node))
fprintf(file, ">"); fprintf(file, ">");
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
} }
static enum dom_stack_code static enum dom_code
sgml_file_dumper_proc_instruction_push(struct dom_stack *stack, struct dom_node *node, void *data) sgml_file_dumper_proc_instruction_push(struct dom_stack *stack, struct dom_node *node, void *data)
{ {
FILE *file = stack->current->data; FILE *file = stack->current->data;
@ -80,10 +80,10 @@ sgml_file_dumper_proc_instruction_push(struct dom_stack *stack, struct dom_node
target->length, target->string, target->length, target->string,
instruction->length, instruction->string); instruction->length, instruction->string);
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
} }
static enum dom_stack_code static enum dom_code
sgml_file_dumper_text_push(struct dom_stack *stack, struct dom_node *node, void *data) sgml_file_dumper_text_push(struct dom_stack *stack, struct dom_node *node, void *data)
{ {
FILE *file = stack->current->data; FILE *file = stack->current->data;
@ -91,10 +91,10 @@ sgml_file_dumper_text_push(struct dom_stack *stack, struct dom_node *node, void
fprintf(file, "%.*s", string->length, string->string); fprintf(file, "%.*s", string->length, string->string);
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
} }
static enum dom_stack_code static enum dom_code
sgml_file_dumper_cdata_section_push(struct dom_stack *stack, struct dom_node *node, void *data) sgml_file_dumper_cdata_section_push(struct dom_stack *stack, struct dom_node *node, void *data)
{ {
FILE *file = stack->current->data; FILE *file = stack->current->data;
@ -102,10 +102,10 @@ sgml_file_dumper_cdata_section_push(struct dom_stack *stack, struct dom_node *no
fprintf(file, "<![CDATA[%.*s]]>", string->length, string->string); fprintf(file, "<![CDATA[%.*s]]>", string->length, string->string);
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
} }
static enum dom_stack_code static enum dom_code
sgml_file_dumper_comment_push(struct dom_stack *stack, struct dom_node *node, void *data) sgml_file_dumper_comment_push(struct dom_stack *stack, struct dom_node *node, void *data)
{ {
FILE *file = stack->current->data; FILE *file = stack->current->data;
@ -113,10 +113,10 @@ sgml_file_dumper_comment_push(struct dom_stack *stack, struct dom_node *node, vo
fprintf(file, "<!--%.*s-->", string->length, string->string); fprintf(file, "<!--%.*s-->", string->length, string->string);
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
} }
static enum dom_stack_code static enum dom_code
sgml_file_dumper_entity_ref_push(struct dom_stack *stack, struct dom_node *node, void *data) sgml_file_dumper_entity_ref_push(struct dom_stack *stack, struct dom_node *node, void *data)
{ {
FILE *file = stack->current->data; FILE *file = stack->current->data;
@ -124,7 +124,7 @@ sgml_file_dumper_entity_ref_push(struct dom_stack *stack, struct dom_node *node,
fprintf(file, "&%.*s;", string->length, string->string); fprintf(file, "&%.*s;", string->length, string->string);
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
} }
struct dom_stack_context_info sgml_file_dumper = { struct dom_stack_context_info sgml_file_dumper = {

View File

@ -41,7 +41,7 @@ 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_STACK_CODE_OK) if (node && push_dom_node(&parser->stack, node) == DOM_CODE_OK)
return node; return node;
return NULL; return NULL;
@ -63,7 +63,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) != DOM_STACK_CODE_OK) if (push_dom_node(stack, node) != DOM_CODE_OK)
return NULL; return NULL;
state = get_dom_stack_top(stack); state = get_dom_stack_top(stack);
@ -97,7 +97,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 = valtoken->string.string[-1]; node->data.attribute.quoted = valtoken->string.string[-1];
if (!node || push_dom_node(stack, node) != DOM_STACK_CODE_OK) if (!node || push_dom_node(stack, node) != DOM_CODE_OK)
return NULL; return NULL;
pop_dom_node(stack); pop_dom_node(stack);
@ -130,7 +130,7 @@ 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;
} }
if (push_dom_node(stack, node) == DOM_STACK_CODE_OK) if (push_dom_node(stack, node) == DOM_CODE_OK)
return node; return node;
return NULL; return NULL;
@ -147,7 +147,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) == DOM_STACK_CODE_OK) if (push_dom_node(stack, node) == DOM_CODE_OK)
pop_dom_node(stack); pop_dom_node(stack);
return node; return node;
@ -156,7 +156,7 @@ add_sgml_node(struct dom_stack *stack, enum dom_node_type type, struct dom_scann
/* SGML parser main handling: */ /* SGML parser main handling: */
static enum sgml_parser_code static enum dom_code
call_sgml_error_function(struct dom_stack *stack, struct dom_scanner_token *token) call_sgml_error_function(struct dom_stack *stack, struct dom_scanner_token *token)
{ {
struct sgml_parser *parser = get_sgml_parser(stack); struct sgml_parser *parser = get_sgml_parser(stack);
@ -173,7 +173,7 @@ call_sgml_error_function(struct dom_stack *stack, struct dom_scanner_token *toke
* *
* NOTE: You can only do this for tokens that are not stripped of markup such * NOTE: You can only do this for tokens that are not stripped of markup such
* as identifiers. */ * as identifiers. */
static enum sgml_parser_code static enum dom_code
check_sgml_incomplete(struct dom_scanner *scanner, check_sgml_incomplete(struct dom_scanner *scanner,
struct dom_scanner_token *start, struct dom_scanner_token *start,
struct dom_scanner_token *token) struct dom_scanner_token *token)
@ -198,7 +198,7 @@ check_sgml_incomplete(struct dom_scanner *scanner,
return 0; return 0;
} }
static inline enum sgml_parser_code static inline enum dom_code
parse_sgml_attributes(struct dom_stack *stack, struct dom_scanner *scanner) parse_sgml_attributes(struct dom_stack *stack, struct dom_scanner *scanner)
{ {
struct dom_scanner_token name; struct dom_scanner_token name;
@ -216,7 +216,7 @@ parse_sgml_attributes(struct dom_stack *stack, struct dom_scanner *scanner)
case SGML_TOKEN_ELEMENT_BEGIN: case SGML_TOKEN_ELEMENT_BEGIN:
case SGML_TOKEN_ELEMENT_END: case SGML_TOKEN_ELEMENT_END:
case SGML_TOKEN_ELEMENT_EMPTY_END: case SGML_TOKEN_ELEMENT_EMPTY_END:
return SGML_PARSER_CODE_OK; return DOM_CODE_OK;
case SGML_TOKEN_IDENT: case SGML_TOKEN_IDENT:
copy_struct(&name, token); copy_struct(&name, token);
@ -229,7 +229,7 @@ parse_sgml_attributes(struct dom_stack *stack, struct dom_scanner *scanner)
* ignore it. */ * ignore it. */
token = get_next_dom_scanner_token(scanner); token = get_next_dom_scanner_token(scanner);
if (check_sgml_incomplete(scanner, &name, token)) if (check_sgml_incomplete(scanner, &name, token))
return SGML_PARSER_CODE_INCOMPLETE; return DOM_CODE_INCOMPLETE;
if (token if (token
&& token->type != SGML_TOKEN_IDENT && token->type != SGML_TOKEN_IDENT
@ -238,14 +238,14 @@ parse_sgml_attributes(struct dom_stack *stack, struct dom_scanner *scanner)
token = NULL; token = NULL;
} else if (check_sgml_incomplete(scanner, &name, token)) { } else if (check_sgml_incomplete(scanner, &name, token)) {
return SGML_PARSER_CODE_INCOMPLETE; return DOM_CODE_INCOMPLETE;
} else { } else {
token = NULL; token = NULL;
} }
if (!add_sgml_attribute(stack, &name, token)) if (!add_sgml_attribute(stack, &name, token))
return SGML_PARSER_CODE_MEM_ALLOC; return DOM_CODE_ALLOC_ERR;
/* Skip the value token */ /* Skip the value token */
if (token) if (token)
@ -253,14 +253,14 @@ parse_sgml_attributes(struct dom_stack *stack, struct dom_scanner *scanner)
break; break;
case SGML_TOKEN_INCOMPLETE: case SGML_TOKEN_INCOMPLETE:
return SGML_PARSER_CODE_INCOMPLETE; return DOM_CODE_INCOMPLETE;
case SGML_TOKEN_ERROR: case SGML_TOKEN_ERROR:
{ {
enum sgml_parser_code code; enum dom_code code;
code = call_sgml_error_function(stack, token); code = call_sgml_error_function(stack, token);
if (code != SGML_PARSER_CODE_OK) if (code != DOM_CODE_OK)
return code; return code;
skip_dom_scanner_token(scanner); skip_dom_scanner_token(scanner);
@ -271,10 +271,10 @@ parse_sgml_attributes(struct dom_stack *stack, struct dom_scanner *scanner)
} }
} }
return SGML_PARSER_CODE_OK; return DOM_CODE_OK;
} }
static enum sgml_parser_code static enum dom_code
parse_sgml_plain(struct dom_stack *stack, struct dom_scanner *scanner) parse_sgml_plain(struct dom_stack *stack, struct dom_scanner *scanner)
{ {
struct dom_scanner_token target; struct dom_scanner_token target;
@ -286,15 +286,15 @@ parse_sgml_plain(struct dom_stack *stack, struct dom_scanner *scanner)
case SGML_TOKEN_ELEMENT: case SGML_TOKEN_ELEMENT:
case SGML_TOKEN_ELEMENT_BEGIN: case SGML_TOKEN_ELEMENT_BEGIN:
if (!add_sgml_element(stack, token)) if (!add_sgml_element(stack, token))
return SGML_PARSER_CODE_MEM_ALLOC; return DOM_CODE_ALLOC_ERR;
if (token->type == SGML_TOKEN_ELEMENT_BEGIN) { if (token->type == SGML_TOKEN_ELEMENT_BEGIN) {
enum sgml_parser_code code; enum dom_code code;
skip_dom_scanner_token(scanner); skip_dom_scanner_token(scanner);
code = parse_sgml_attributes(stack, scanner); code = parse_sgml_attributes(stack, scanner);
if (code != SGML_PARSER_CODE_OK) if (code != DOM_CODE_OK)
return code; return code;
} else { } else {
@ -332,7 +332,7 @@ parse_sgml_plain(struct dom_stack *stack, struct dom_scanner *scanner)
case SGML_TOKEN_NOTATION_COMMENT: case SGML_TOKEN_NOTATION_COMMENT:
if (!add_sgml_node(stack, DOM_NODE_COMMENT, token)) if (!add_sgml_node(stack, DOM_NODE_COMMENT, token))
return SGML_PARSER_CODE_MEM_ALLOC; return DOM_CODE_ALLOC_ERR;
skip_dom_scanner_token(scanner); skip_dom_scanner_token(scanner);
break; break;
@ -346,7 +346,7 @@ parse_sgml_plain(struct dom_stack *stack, struct dom_scanner *scanner)
case SGML_TOKEN_CDATA_SECTION: case SGML_TOKEN_CDATA_SECTION:
if (!add_sgml_node(stack, DOM_NODE_CDATA_SECTION, token)) if (!add_sgml_node(stack, DOM_NODE_CDATA_SECTION, token))
return SGML_PARSER_CODE_MEM_ALLOC; return DOM_CODE_ALLOC_ERR;
skip_dom_scanner_token(scanner); skip_dom_scanner_token(scanner);
break; break;
@ -358,7 +358,7 @@ parse_sgml_plain(struct dom_stack *stack, struct dom_scanner *scanner)
/* Skip the target token */ /* Skip the target token */
token = get_next_dom_scanner_token(scanner); token = get_next_dom_scanner_token(scanner);
if (!token || token->type == SGML_TOKEN_INCOMPLETE) if (!token || token->type == SGML_TOKEN_INCOMPLETE)
return SGML_PARSER_CODE_INCOMPLETE; return DOM_CODE_INCOMPLETE;
if (token->type == SGML_TOKEN_ERROR) if (token->type == SGML_TOKEN_ERROR)
break; break;
@ -367,7 +367,7 @@ parse_sgml_plain(struct dom_stack *stack, struct dom_scanner *scanner)
/* Fall-through */ /* Fall-through */
if (!add_sgml_proc_instruction(stack, &target, token)) if (!add_sgml_proc_instruction(stack, &target, token))
return SGML_PARSER_CODE_MEM_ALLOC; return DOM_CODE_ALLOC_ERR;
if ((target.type == SGML_TOKEN_PROCESS_XML if ((target.type == SGML_TOKEN_PROCESS_XML
|| target.type == SGML_TOKEN_PROCESS_XML_STYLESHEET) || target.type == SGML_TOKEN_PROCESS_XML_STYLESHEET)
&& token->string.length > 0) { && token->string.length > 0) {
@ -399,14 +399,14 @@ parse_sgml_plain(struct dom_stack *stack, struct dom_scanner *scanner)
break; break;
case SGML_TOKEN_INCOMPLETE: case SGML_TOKEN_INCOMPLETE:
return SGML_PARSER_CODE_INCOMPLETE; return DOM_CODE_INCOMPLETE;
case SGML_TOKEN_ERROR: case SGML_TOKEN_ERROR:
{ {
enum sgml_parser_code code; enum dom_code code;
code = call_sgml_error_function(stack, token); code = call_sgml_error_function(stack, token);
if (code != SGML_PARSER_CODE_OK) if (code != DOM_CODE_OK)
return code; return code;
skip_dom_scanner_token(scanner); skip_dom_scanner_token(scanner);
@ -420,10 +420,10 @@ parse_sgml_plain(struct dom_stack *stack, struct dom_scanner *scanner)
} }
} }
return SGML_PARSER_CODE_OK; return DOM_CODE_OK;
} }
enum sgml_parser_code enum dom_code
parse_sgml(struct sgml_parser *parser, unsigned char *buf, size_t bufsize, parse_sgml(struct sgml_parser *parser, unsigned char *buf, size_t bufsize,
int complete) int complete)
{ {
@ -436,13 +436,13 @@ parse_sgml(struct sgml_parser *parser, unsigned char *buf, size_t bufsize,
if (!parser->root) { if (!parser->root) {
parser->root = add_sgml_document(parser); parser->root = add_sgml_document(parser);
if (!parser->root) if (!parser->root)
return SGML_PARSER_CODE_MEM_ALLOC; return DOM_CODE_ALLOC_ERR;
get_dom_stack_top(&parser->stack)->immutable = 1; get_dom_stack_top(&parser->stack)->immutable = 1;
} }
node = init_dom_node(DOM_NODE_TEXT, &source, 0); node = init_dom_node(DOM_NODE_TEXT, &source, 0);
if (!node || push_dom_node(&parser->parsing, node) != DOM_STACK_CODE_OK) if (!node || push_dom_node(&parser->parsing, node) != DOM_CODE_OK)
return SGML_PARSER_CODE_MEM_ALLOC; return DOM_CODE_ALLOC_ERR;
return parser->code; return parser->code;
} }
@ -464,7 +464,7 @@ struct sgml_parsing_state {
unsigned int resume:1; unsigned int resume:1;
}; };
enum dom_stack_code enum dom_code
sgml_parsing_push(struct dom_stack *stack, struct dom_node *node, void *data) sgml_parsing_push(struct dom_stack *stack, struct dom_node *node, void *data)
{ {
struct sgml_parser *parser = get_sgml_parser(stack); struct sgml_parser *parser = get_sgml_parser(stack);
@ -490,8 +490,8 @@ sgml_parsing_push(struct dom_stack *stack, struct dom_node *node, void *data)
string->string, string->string,
string->length)) { string->length)) {
parser->code = SGML_PARSER_CODE_MEM_ALLOC; parser->code = DOM_CODE_ALLOC_ERR;
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
} }
string = &parent->incomplete; string = &parent->incomplete;
@ -512,7 +512,7 @@ sgml_parsing_push(struct dom_stack *stack, struct dom_node *node, void *data)
if (scanner_state == SGML_STATE_ELEMENT) { if (scanner_state == SGML_STATE_ELEMENT) {
parser->code = parse_sgml_attributes(&parser->stack, &parsing->scanner); parser->code = parse_sgml_attributes(&parser->stack, &parsing->scanner);
if (parser->code == SGML_PARSER_CODE_OK) if (parser->code == DOM_CODE_OK)
parser->code = parse_sgml_plain(&parser->stack, &parsing->scanner); parser->code = parse_sgml_plain(&parser->stack, &parsing->scanner);
} else { } else {
parser->code = parse_sgml_plain(&parser->stack, &parsing->scanner); parser->code = parse_sgml_plain(&parser->stack, &parsing->scanner);
@ -520,19 +520,19 @@ sgml_parsing_push(struct dom_stack *stack, struct dom_node *node, void *data)
if (complete) { if (complete) {
pop_dom_node(&parser->parsing); pop_dom_node(&parser->parsing);
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
} }
if (parser->code != SGML_PARSER_CODE_INCOMPLETE) { if (parser->code != DOM_CODE_INCOMPLETE) {
/* No need to preserve the default scanner state. */ /* No need to preserve the default scanner state. */
if (parsing->scanner.state == SGML_STATE_TEXT) { if (parsing->scanner.state == SGML_STATE_TEXT) {
pop_dom_node(&parser->parsing); pop_dom_node(&parser->parsing);
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
} }
done_dom_string(&parsing->incomplete); done_dom_string(&parsing->incomplete);
parsing->resume = 1; parsing->resume = 1;
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
} }
token = get_dom_scanner_token(&parsing->scanner); token = get_dom_scanner_token(&parsing->scanner);
@ -543,18 +543,18 @@ sgml_parsing_push(struct dom_stack *stack, struct dom_node *node, void *data)
set_dom_string(&incomplete, NULL, 0); set_dom_string(&incomplete, NULL, 0);
if (!init_dom_string(&incomplete, string->string, string->length)) { if (!init_dom_string(&incomplete, string->string, string->length)) {
parser->code = SGML_PARSER_CODE_MEM_ALLOC; parser->code = DOM_CODE_ALLOC_ERR;
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
} }
done_dom_string(&parsing->incomplete); done_dom_string(&parsing->incomplete);
set_dom_string(&parsing->incomplete, incomplete.string, incomplete.length); set_dom_string(&parsing->incomplete, incomplete.string, incomplete.length);
parsing->resume = 1; parsing->resume = 1;
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
} }
enum dom_stack_code enum dom_code
sgml_parsing_pop(struct dom_stack *stack, struct dom_node *node, void *data) sgml_parsing_pop(struct dom_stack *stack, struct dom_node *node, void *data)
{ {
struct sgml_parser *parser = get_sgml_parser(stack); struct sgml_parser *parser = get_sgml_parser(stack);
@ -575,7 +575,7 @@ sgml_parsing_pop(struct dom_stack *stack, struct dom_node *node, void *data)
done_dom_string(&parsing->incomplete); done_dom_string(&parsing->incomplete);
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
} }
static struct dom_stack_context_info sgml_parsing_context_info = { static struct dom_stack_context_info sgml_parsing_context_info = {

View File

@ -2,6 +2,7 @@
#ifndef EL_DOM_SGML_PARSER_H #ifndef EL_DOM_SGML_PARSER_H
#define EL_DOM_SGML_PARSER_H #define EL_DOM_SGML_PARSER_H
#include "dom/dom.h"
#include "dom/node.h" #include "dom/node.h"
#include "dom/stack.h" #include "dom/stack.h"
#include "dom/sgml/sgml.h" #include "dom/sgml/sgml.h"
@ -62,27 +63,13 @@ struct sgml_parser_state {
struct dom_scanner_token end_token; struct dom_scanner_token end_token;
}; };
/** (Error) codes for the SGML parser
*
* These enum values are used for return codes.
*/
enum sgml_parser_code {
SGML_PARSER_CODE_OK, /*: The parsing was successful */
SGML_PARSER_CODE_INCOMPLETE, /*: The parsing could not be completed */
SGML_PARSER_CODE_MEM_ALLOC, /*: Failed to allocate memory */
/**
* FIXME: For when we will add support for requiring stricter parsing
* or even a validator. */
SGML_PARSER_CODE_ERROR,
};
/** SGML error callback /** SGML error callback
* *
* Called by the SGML parser when a parsing error has occurred. * Called by the SGML parser when a parsing error has occurred.
* *
* If the return code is not ref:[SGML_PARSER_CODE_OK] the parsing will be * If the return code is not ref:[DOM_CODE_OK] the parsing will be
* ended and that code will be returned. */ * ended and that code will be returned. */
typedef enum sgml_parser_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);
@ -101,7 +88,7 @@ struct sgml_parser {
struct dom_string uri; /*: The URI of the DOM document */ struct dom_string uri; /*: The URI of the DOM document */
struct dom_node *root; /*: The document root node */ struct dom_node *root; /*: The document root node */
enum sgml_parser_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 */
struct dom_stack stack; /*: A stack for tracking parsed nodes */ struct dom_stack stack; /*: A stack for tracking parsed nodes */
@ -142,10 +129,10 @@ void done_sgml_parser(struct sgml_parser *parser);
* bufsize:: The size of the buffer given in the buf parameter. * bufsize:: The size of the buffer given in the buf parameter.
* complete:: Whether this is the last chunk to parse. * complete:: Whether this is the last chunk to parse.
* *
* The returned code is ref:[SGML_PARSER_CODE_OK] if the buffer was * The returned code is ref:[DOM_CODE_OK] if the buffer was
* successfully parserd, else a code hinting at the error. * successfully parserd, else a code hinting at the error.
*/ */
enum sgml_parser_code enum dom_code
parse_sgml(struct sgml_parser *parser, unsigned char *buf, size_t bufsize, int complete); parse_sgml(struct sgml_parser *parser, unsigned char *buf, size_t bufsize, int complete);
/** Get the line position in the source /** Get the line position in the source

View File

@ -151,7 +151,7 @@ call_dom_stack_callbacks(struct dom_stack *stack, struct dom_stack_state *state,
stack->current = context; stack->current = context;
switch (callback(stack, state->node, data)) { switch (callback(stack, state->node, data)) {
case DOM_STACK_CODE_FREE_NODE: case DOM_CODE_FREE_NODE:
free_node = 1; free_node = 1;
break; break;
default: default:
@ -164,7 +164,7 @@ call_dom_stack_callbacks(struct dom_stack *stack, struct dom_stack_state *state,
return free_node; return free_node;
} }
enum dom_stack_code enum dom_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;
@ -174,13 +174,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 DOM_STACK_CODE_ERROR_MAX_DEPTH; return DOM_CODE_MAX_DEPTH_ERR;
} }
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 DOM_STACK_CODE_ERROR_MEM_ALLOC; return DOM_CODE_ALLOC_ERR;
} }
state += stack->depth; state += stack->depth;
@ -191,7 +191,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 DOM_STACK_CODE_ERROR_MEM_ALLOC; return DOM_CODE_ALLOC_ERR;
} }
} }
@ -203,7 +203,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 DOM_STACK_CODE_OK; return DOM_CODE_OK;
} }
void void
@ -358,7 +358,7 @@ walk_dom_nodes(struct dom_stack *stack, struct dom_node *root)
if (!context) if (!context)
return; return;
if (push_dom_node(stack, root) != DOM_STACK_CODE_OK) if (push_dom_node(stack, root) != DOM_CODE_OK)
return; return;
while (!dom_stack_is_empty(stack)) { while (!dom_stack_is_empty(stack)) {
@ -420,7 +420,7 @@ walk_dom_nodes(struct dom_stack *stack, struct dom_node *root)
if (is_dom_node_list_member(list, wstate->index)) { if (is_dom_node_list_member(list, wstate->index)) {
struct dom_node *child = list->entries[wstate->index++]; struct dom_node *child = list->entries[wstate->index++];
if (push_dom_node(stack, child) == DOM_STACK_CODE_OK) if (push_dom_node(stack, child) == DOM_CODE_OK)
continue; continue;
} }
@ -498,7 +498,7 @@ static unsigned char indent_string[] =
#define get_indent_offset(stack) \ #define get_indent_offset(stack) \
((stack)->depth < sizeof(indent_string)/2 ? (stack)->depth * 2 : sizeof(indent_string)) ((stack)->depth < sizeof(indent_string)/2 ? (stack)->depth * 2 : sizeof(indent_string))
enum dom_stack_code enum dom_code
dom_stack_trace_tree(struct dom_stack *stack, struct dom_node *node, void *data) dom_stack_trace_tree(struct dom_stack *stack, struct dom_node *node, void *data)
{ {
struct dom_string *value = &node->string; struct dom_string *value = &node->string;
@ -510,10 +510,10 @@ dom_stack_trace_tree(struct dom_stack *stack, struct dom_node *node, void *data)
name->length, name->string, name->length, name->string,
value->length, value->string); value->length, value->string);
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
} }
enum dom_stack_code enum dom_code
dom_stack_trace_id_leaf(struct dom_stack *stack, struct dom_node *node, void *data) dom_stack_trace_id_leaf(struct dom_stack *stack, struct dom_node *node, void *data)
{ {
struct dom_string value; struct dom_string value;
@ -534,10 +534,10 @@ dom_stack_trace_id_leaf(struct dom_stack *stack, struct dom_node *node, void *da
done_dom_string(&value); done_dom_string(&value);
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
} }
enum dom_stack_code enum dom_code
dom_stack_trace_leaf(struct dom_stack *stack, struct dom_node *node, void *data) dom_stack_trace_leaf(struct dom_stack *stack, struct dom_node *node, void *data)
{ {
struct dom_string *name; struct dom_string *name;
@ -556,10 +556,10 @@ dom_stack_trace_leaf(struct dom_stack *stack, struct dom_node *node, void *data)
done_dom_string(&value); done_dom_string(&value);
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
} }
enum dom_stack_code enum dom_code
dom_stack_trace_branch(struct dom_stack *stack, struct dom_node *node, void *data) dom_stack_trace_branch(struct dom_stack *stack, struct dom_node *node, void *data)
{ {
struct dom_string *name; struct dom_string *name;
@ -575,7 +575,7 @@ dom_stack_trace_branch(struct dom_stack *stack, struct dom_node *node, void *dat
get_indent_offset(stack), indent_string, get_indent_offset(stack), indent_string,
id->length, id->string, name->length, name->string); id->length, id->string, name->length, name->string);
return DOM_STACK_CODE_OK; return DOM_CODE_OK;
} }
struct dom_stack_context_info dom_stack_trace_context_info = { struct dom_stack_context_info dom_stack_trace_context_info = {

View File

@ -1,6 +1,7 @@
#ifndef EL_DOM_STACK_H #ifndef EL_DOM_STACK_H
#define EL_DOM_STACK_H #define EL_DOM_STACK_H
#include "dom/dom.h"
#include "dom/node.h" #include "dom/node.h"
#include "util/error.h" #include "util/error.h"
#include "util/hash.h" #include "util/hash.h"
@ -9,21 +10,10 @@ 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_FREE_NODE, /*: Free the (popped) node */
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. */
typedef enum dom_stack_code typedef enum dom_code
(*dom_stack_callback_T)(struct dom_stack *, struct dom_node *, void *); (*dom_stack_callback_T)(struct dom_stack *, struct dom_node *, void *);
#define DOM_STACK_MAX_DEPTH 4096 #define DOM_STACK_MAX_DEPTH 4096
@ -242,7 +232,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. */
enum dom_stack_code push_dom_node(struct dom_stack *stack, struct dom_node *node); enum dom_code push_dom_node(struct dom_stack *stack, struct dom_node *node);
/** Pop the top stack state /** Pop the top stack state
* *