diff --git a/configure.in b/configure.in index 66493fbd7..7deaa6e27 100644 --- a/configure.in +++ b/configure.in @@ -459,8 +459,10 @@ EL_CONFIG_OPTIONAL_LIBRARY(CONFIG_BZIP2, bzlib, bzlib.h, bz2, BZ2_bzReadOpen, EL_CONFIG_OPTIONAL_LIBRARY(CONFIG_IDN, idn, idna.h, idn, stringprep_check_version, [ --without-idn disable international domain names support]) -EL_CONFIG_OPTIONAL_LIBRARY(CONFIG_GC, gc, gc.h, gc, GC_init, - [ --with-gc enable Boehm's garbage collector]) +if test "x{with_gc}" != xno; then + EL_CONFIG_OPTIONAL_LIBRARY(CONFIG_GC, gc, gc.h, gc, GC_init, + [ --with-gc enable Boehm's garbage collector]) +fi dnl =================================================================== dnl Bookmark and XBEL support diff --git a/src/document/dom/renderer.c b/src/document/dom/renderer.c index 8d391e181..0dfb3890a 100644 --- a/src/document/dom/renderer.c +++ b/src/document/dom/renderer.c @@ -507,7 +507,7 @@ render_dom_node_enhanced_text(struct dom_renderer *renderer, struct dom_node *no } #endif -static enum dom_stack_code +static enum dom_code render_dom_node_source(struct dom_stack *stack, struct dom_node *node, void *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 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. */ -static enum dom_stack_code +static enum dom_code render_dom_element_source(struct dom_stack *stack, struct dom_node *node, void *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); - 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) { 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); if (!string || !length) - return DOM_STACK_CODE_OK; + return DOM_CODE_OK; if (check_dom_node_source(renderer, string, length)) { 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); - return DOM_STACK_CODE_OK; + return DOM_CODE_OK; } static void @@ -587,7 +587,7 @@ set_base_uri(struct dom_renderer *renderer, unsigned char *value, size_t valuele 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) { 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) { 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); - 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) { 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); } - return DOM_STACK_CODE_OK; + return DOM_CODE_OK; } 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 \ (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) { 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; } - 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) { 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; } - 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) { struct dom_renderer *renderer = stack->current->data; if (!renderer->channel) - return DOM_STACK_CODE_OK; + return DOM_CODE_OK; 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); - 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); size_t length = strlen(string); 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, document->options.assume_cp, diff --git a/src/dom/code.h b/src/dom/code.h new file mode 100644 index 000000000..92de7fc85 --- /dev/null +++ b/src/dom/code.h @@ -0,0 +1,47 @@ +#ifndef EL_DOM_CODE_H +#define EL_DOM_CODE_H + +/* API Doc :: dom-code */ + +/** DOM status/error/exception codes + * + * These enum values are used for return codes throughout the DOM engine. + */ +enum dom_code { + /** ELinks specific codes: */ + DOM_CODE_OK = 0, /*: The sane default. */ + DOM_CODE_ERR = -1000, /*: Anything by DOM_CODE_OK. */ + + DOM_CODE_INCOMPLETE, /*: The parsing could not be completed */ + DOM_CODE_FREE_NODE, /*: Discard the node */ + + /** Error codes: */ + DOM_CODE_ALLOC_ERR, /*: Failed to allocate memory */ + 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 diff --git a/src/dom/configuration.c b/src/dom/configuration.c index 657f916bc..fa933610e 100644 --- a/src/dom/configuration.c +++ b/src/dom/configuration.c @@ -12,7 +12,7 @@ #include "dom/string.h" -static enum dom_stack_code +static enum dom_code normalize_text_node_whitespace(struct dom_node *node) { unsigned char buf[256]; @@ -44,7 +44,7 @@ normalize_text_node_whitespace(struct dom_node *node) if (!add_to_dom_string(&string, buf, j)) { 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); 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) { 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) { /* Preserve text nodes with no one to append to. */ if (node->type == DOM_NODE_TEXT) - return DOM_STACK_CODE_OK; + return DOM_CODE_OK; prev = NULL; set_dom_string(&dest, NULL, 0); @@ -83,7 +83,7 @@ append_node_text(struct dom_config *config, struct dom_node *node) } else { set_dom_string(&dest, NULL, 0); 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); prev->allocated = 1; } @@ -119,7 +119,7 @@ append_node_text(struct dom_config *config, struct dom_node *node) prev->string.length = length; else done_dom_string(&dest); - return DOM_STACK_CODE_ERROR_MEM_ALLOC; + return DOM_CODE_ALLOC_ERR; } if (prev) { @@ -132,7 +132,7 @@ append_node_text(struct dom_config *config, struct dom_node *node) normalize_text_node_whitespace(prev); } - return DOM_STACK_CODE_FREE_NODE; + return DOM_CODE_FREE_NODE; } else { 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); } - 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) { 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) { 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) { /* Drop elements that are not known from the built-in * node info. */ - code = DOM_STACK_CODE_FREE_NODE; + code = DOM_CODE_FREE_NODE; } break; @@ -174,7 +174,7 @@ dom_normalize_node_end(struct dom_stack *stack, struct dom_node *node, void *dat && !node->data.attribute.type) { /* Drop elements that are not known from the built-in * node info. */ - code = DOM_STACK_CODE_FREE_NODE; + code = DOM_CODE_FREE_NODE; } break; @@ -183,7 +183,7 @@ dom_normalize_node_end(struct dom_stack *stack, struct dom_node *node, void *dat && !node->data.proc_instruction.type) { /* Drop elements that are not known from the built-in * node info. */ - code = DOM_STACK_CODE_FREE_NODE; + code = DOM_CODE_FREE_NODE; } break; @@ -192,7 +192,7 @@ dom_normalize_node_end(struct dom_stack *stack, struct dom_node *node, void *dat && node->data.text.only_space) { /* Discard all Text nodes that contain * whitespaces in element content]. */ - code = DOM_STACK_CODE_FREE_NODE; + code = DOM_CODE_FREE_NODE; } else { 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: if (!(config->flags & DOM_CONFIG_COMMENTS)) { /* Discard all comments. */ - code = DOM_STACK_CODE_FREE_NODE; + code = DOM_CODE_FREE_NODE; } break; @@ -234,7 +234,7 @@ dom_normalize_node_end(struct dom_stack *stack, struct dom_node *node, void *dat return code; } -enum dom_stack_code +enum dom_code dom_normalize_text(struct dom_stack *stack, struct dom_node *node, void *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 DOM_STACK_CODE_OK; + return DOM_CODE_OK; } diff --git a/src/dom/dom.h b/src/dom/dom.h deleted file mode 100644 index 5eadc5a8e..000000000 --- a/src/dom/dom.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef EL_DOM_DOM_H -#define EL_DOM_DOM_H - -enum dom_exception_code { - DOM_ERR_NONE = 0, - DOM_ERR_INDEX_SIZE = 1, - DOM_ERR_STRING_SIZE = 2, - DOM_ERR_HIERARCHY_REQUEST = 3, - DOM_ERR_WRONG_DOCUMENT = 4, - DOM_ERR_INVALID_CHARACTER = 5, - DOM_ERR_NO_DATA_ALLOWED = 6, - 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_ERR_INVALID_STATE = 11, - DOM_ERR_SYNTAX = 12, - DOM_ERR_INVALID_MODIFICATION = 13, - DOM_ERR_NAMESPACE = 14, - DOM_ERR_INVALID_ACCESS = 15, -}; - -#endif diff --git a/src/dom/select.c b/src/dom/select.c index af60c4d5e..472bd07fe 100644 --- a/src/dom/select.c +++ b/src/dom/select.c @@ -7,7 +7,7 @@ #include "elinks.h" #include "dom/css/scanner.h" -#include "dom/dom.h" +#include "dom/code.h" #include "dom/node.h" #include "dom/scanner.h" #include "dom/select.h" @@ -80,7 +80,7 @@ get_dom_select_pseudo(struct dom_scanner_token *token) } /* 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) { 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 '['. */ if (token->type != '[') - return DOM_ERR_INVALID_STATE; + return DOM_CODE_SYNTAX_ERR; /* Get the attribute name. */ token = get_next_dom_scanner_token(scanner); if (!token || token->type != CSS_TOKEN_IDENT) - return DOM_ERR_SYNTAX; + return DOM_CODE_SYNTAX_ERR; copy_dom_string(&sel->node.string, &token->string); /* Get the optional '=' combo or ending ']'. */ token = get_next_dom_scanner_token(scanner); - if (!token) return DOM_ERR_SYNTAX; + if (!token) return DOM_CODE_SYNTAX_ERR; switch (token->type) { case ']': sel->match.attribute |= DOM_SELECT_ATTRIBUTE_ANY; - return DOM_ERR_NONE; + return DOM_CODE_OK; case CSS_TOKEN_SELECT_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; default: - return DOM_ERR_SYNTAX; + return DOM_CODE_SYNTAX_ERR; } /* Get the required value. */ token = get_next_dom_scanner_token(scanner); - if (!token) return DOM_ERR_SYNTAX; + if (!token) return DOM_CODE_SYNTAX_ERR; switch (token->type) { case CSS_TOKEN_IDENT: @@ -144,16 +144,16 @@ parse_dom_select_attribute(struct dom_select_node *sel, struct dom_scanner *scan break; default: - return DOM_ERR_SYNTAX; + return DOM_CODE_SYNTAX_ERR; } /* Get the ending ']'. */ token = get_next_dom_scanner_token(scanner); if (token && token->type == ']') - return DOM_ERR_NONE; + return DOM_CODE_OK; - return DOM_ERR_SYNTAX; + return DOM_CODE_SYNTAX_ERR; } /* Parse: @@ -190,7 +190,7 @@ get_scanner_token_number(struct dom_scanner_token *token) } /* 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) { 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; if (!token || token->type != '(') - return DOM_ERR_SYNTAX; + return DOM_CODE_SYNTAX_ERR; token = get_next_dom_scanner_token(scanner); if (!token) - return DOM_ERR_SYNTAX; + return DOM_CODE_SYNTAX_ERR; switch (token->type) { 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, ')')) - return DOM_ERR_NONE; + return DOM_CODE_OK; - return DOM_ERR_SYNTAX; + return DOM_CODE_SYNTAX_ERR; case '-': sign = -1; 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) break; if (token->type != CSS_TOKEN_NUMBER) - return DOM_ERR_SYNTAX; + return DOM_CODE_SYNTAX_ERR; /* Fall-through */ case CSS_TOKEN_NUMBER: number = get_scanner_token_number(token); if (number < 0) - return DOM_ERR_INVALID_STATE; + return DOM_CODE_VALUE_ERR; token = get_next_dom_scanner_token(scanner); - if (!token) return DOM_ERR_SYNTAX; + if (!token) return DOM_CODE_SYNTAX_ERR; break; default: - return DOM_ERR_SYNTAX; + return DOM_CODE_SYNTAX_ERR; } /* The rest can contain n+ part */ switch (token->type) { case CSS_TOKEN_IDENT: if (!dom_scanner_token_contains(token, "n")) - return DOM_ERR_SYNTAX; + return DOM_CODE_SYNTAX_ERR; nth->step = sign * number; token = get_next_dom_scanner_token(scanner); - if (!token) return DOM_ERR_SYNTAX; + if (!token) return DOM_CODE_SYNTAX_ERR; if (token->type != '+') break; 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) break; number = get_scanner_token_number(token); if (number < 0) - return DOM_ERR_INVALID_STATE; + return DOM_CODE_VALUE_ERR; nth->index = sign * number; 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, ')')) - 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: ':'. */ -static enum dom_exception_code +static enum dom_code parse_dom_select_pseudo(struct dom_select *select, struct dom_select_node *sel, struct dom_scanner *scanner) { struct dom_scanner_token *token = get_dom_scanner_token(scanner); 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.) */ do { @@ -303,12 +303,12 @@ parse_dom_select_pseudo(struct dom_select *select, struct dom_select_node *sel, } while (token && token->type == ':'); if (!token || token->type != CSS_TOKEN_IDENT) - return DOM_ERR_SYNTAX; + return DOM_CODE_SYNTAX_ERR; pseudo = get_dom_select_pseudo(token); switch (pseudo) { case DOM_SELECT_PSEUDO_UNKNOWN: - return DOM_ERR_NOT_FOUND; + return DOM_CODE_ERR; case DOM_SELECT_PSEUDO_CONTAINS: /* 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_LAST_CHILD: code = parse_dom_select_nth_arg(&sel->nth_child, scanner); - if (code != DOM_ERR_NONE) + if (code != DOM_CODE_OK) return code; 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_LAST_TYPE: code = parse_dom_select_nth_arg(&sel->nth_type, scanner); - if (code != DOM_ERR_NONE) + if (code != DOM_CODE_OK) return code; 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; } - return DOM_ERR_NONE; + return DOM_CODE_OK; } /* 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) /* 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, 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)) { 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; assert(token); @@ -430,14 +430,14 @@ parse_dom_select(struct dom_select *select, struct dom_stack *stack, case '[': sel.node.type = DOM_NODE_ATTRIBUTE; code = parse_dom_select_attribute(&sel, &scanner); - if (code != DOM_ERR_NONE) + if (code != DOM_CODE_OK) return code; break; case '.': token = get_next_dom_scanner_token(&scanner); if (!token || token->type != CSS_TOKEN_IDENT) - return DOM_ERR_SYNTAX; + return DOM_CODE_SYNTAX_ERR; sel.node.type = DOM_NODE_ATTRIBUTE; sel.match.attribute |= DOM_SELECT_ATTRIBUTE_SPACE_LIST; @@ -447,30 +447,30 @@ parse_dom_select(struct dom_select *select, struct dom_stack *stack, case ':': code = parse_dom_select_pseudo(select, &sel, &scanner); - if (code != DOM_ERR_NONE) + if (code != DOM_CODE_OK) return code; break; case '>': 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; break; case '+': 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; break; case '~': 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; break; default: - return DOM_ERR_SYNTAX; + return DOM_CODE_SYNTAX_ERR; } 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)) { done_dom_node(node); - return DOM_ERR_INVALID_STATE; + return DOM_CODE_ALLOC_ERR; } node->parent = parent; @@ -506,8 +506,9 @@ parse_dom_select(struct dom_select *select, struct dom_stack *stack, select->selector = select_node; } - if (push_dom_node(stack, &select_node->node) != DOM_STACK_CODE_OK) - return DOM_ERR_INVALID_STATE; + code = push_dom_node(stack, &select_node->node); + if (code != DOM_CODE_OK) + return code; if (select_node->node.type != DOM_NODE_ELEMENT) pop_dom_node(stack); @@ -516,9 +517,9 @@ parse_dom_select(struct dom_select *select, struct dom_stack *stack, } 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 @@ -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_stack stack; - enum dom_exception_code code; + enum dom_code code; init_dom_stack(&stack, DOM_STACK_FLAG_NONE); 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); done_dom_stack(&stack); - if (code == DOM_ERR_NONE) + if (code == DOM_CODE_OK) return 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) /* 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) { 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); } - return DOM_STACK_CODE_OK; + return DOM_CODE_OK; } /* Ensures that nodes, no longer 'reachable' on the stack do not have any * 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) { 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()' pseudo-class. * Any node which can contain text and thus characters from the given * 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) { 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); if (!text_sel) - return DOM_STACK_CODE_OK; + return DOM_CODE_OK; 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"); } - return DOM_STACK_CODE_OK; + return DOM_CODE_OK; } /* 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); 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; walk_dom_nodes(&stack, root); } diff --git a/src/dom/sgml/dump.c b/src/dom/sgml/dump.c index 902a7e4f3..3bac87e81 100644 --- a/src/dom/sgml/dump.c +++ b/src/dom/sgml/dump.c @@ -15,7 +15,7 @@ #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) { 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) 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) { 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, "", 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) { 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; if (node->parent->type == DOM_NODE_PROCESSING_INSTRUCTION) - return DOM_STACK_CODE_OK; + return DOM_CODE_OK; 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)) 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) { 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, 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) { 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); - 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) { 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, "", 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) { 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, "", 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) { 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); - return DOM_STACK_CODE_OK; + return DOM_CODE_OK; } struct dom_stack_context_info sgml_file_dumper = { diff --git a/src/dom/sgml/parser.c b/src/dom/sgml/parser.c index 9ead5c794..c34bf93bb 100644 --- a/src/dom/sgml/parser.c +++ b/src/dom/sgml/parser.c @@ -41,7 +41,7 @@ add_sgml_document(struct sgml_parser *parser) struct dom_node *node; 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 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->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; state = get_dom_stack_top(stack); @@ -97,7 +97,7 @@ add_sgml_attribute(struct dom_stack *stack, if (valtoken && valtoken->type == SGML_TOKEN_STRING) 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; 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; } - if (push_dom_node(stack, node) == DOM_STACK_CODE_OK) + if (push_dom_node(stack, node) == DOM_CODE_OK) return node; 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) 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); 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: */ -static enum sgml_parser_code +static enum dom_code call_sgml_error_function(struct dom_stack *stack, struct dom_scanner_token *token) { 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 * as identifiers. */ -static enum sgml_parser_code +static enum dom_code check_sgml_incomplete(struct dom_scanner *scanner, struct dom_scanner_token *start, struct dom_scanner_token *token) @@ -198,7 +198,7 @@ check_sgml_incomplete(struct dom_scanner *scanner, return 0; } -static inline enum sgml_parser_code +static inline enum dom_code parse_sgml_attributes(struct dom_stack *stack, struct dom_scanner *scanner) { 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_END: case SGML_TOKEN_ELEMENT_EMPTY_END: - return SGML_PARSER_CODE_OK; + return DOM_CODE_OK; case SGML_TOKEN_IDENT: copy_struct(&name, token); @@ -229,7 +229,7 @@ parse_sgml_attributes(struct dom_stack *stack, struct dom_scanner *scanner) * ignore it. */ token = get_next_dom_scanner_token(scanner); if (check_sgml_incomplete(scanner, &name, token)) - return SGML_PARSER_CODE_INCOMPLETE; + return DOM_CODE_INCOMPLETE; if (token && token->type != SGML_TOKEN_IDENT @@ -238,14 +238,14 @@ parse_sgml_attributes(struct dom_stack *stack, struct dom_scanner *scanner) token = NULL; } else if (check_sgml_incomplete(scanner, &name, token)) { - return SGML_PARSER_CODE_INCOMPLETE; + return DOM_CODE_INCOMPLETE; } else { token = NULL; } if (!add_sgml_attribute(stack, &name, token)) - return SGML_PARSER_CODE_MEM_ALLOC; + return DOM_CODE_ALLOC_ERR; /* Skip the value token */ if (token) @@ -253,14 +253,14 @@ parse_sgml_attributes(struct dom_stack *stack, struct dom_scanner *scanner) break; case SGML_TOKEN_INCOMPLETE: - return SGML_PARSER_CODE_INCOMPLETE; + return DOM_CODE_INCOMPLETE; case SGML_TOKEN_ERROR: { - enum sgml_parser_code code; + enum dom_code code; code = call_sgml_error_function(stack, token); - if (code != SGML_PARSER_CODE_OK) + if (code != DOM_CODE_OK) return code; 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) { 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_BEGIN: if (!add_sgml_element(stack, token)) - return SGML_PARSER_CODE_MEM_ALLOC; + return DOM_CODE_ALLOC_ERR; if (token->type == SGML_TOKEN_ELEMENT_BEGIN) { - enum sgml_parser_code code; + enum dom_code code; skip_dom_scanner_token(scanner); code = parse_sgml_attributes(stack, scanner); - if (code != SGML_PARSER_CODE_OK) + if (code != DOM_CODE_OK) return code; } else { @@ -332,7 +332,7 @@ parse_sgml_plain(struct dom_stack *stack, struct dom_scanner *scanner) case SGML_TOKEN_NOTATION_COMMENT: 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); break; @@ -346,7 +346,7 @@ parse_sgml_plain(struct dom_stack *stack, struct dom_scanner *scanner) case SGML_TOKEN_CDATA_SECTION: 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); break; @@ -358,7 +358,7 @@ parse_sgml_plain(struct dom_stack *stack, struct dom_scanner *scanner) /* Skip the target token */ token = get_next_dom_scanner_token(scanner); if (!token || token->type == SGML_TOKEN_INCOMPLETE) - return SGML_PARSER_CODE_INCOMPLETE; + return DOM_CODE_INCOMPLETE; if (token->type == SGML_TOKEN_ERROR) break; @@ -367,7 +367,7 @@ parse_sgml_plain(struct dom_stack *stack, struct dom_scanner *scanner) /* Fall-through */ 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 || target.type == SGML_TOKEN_PROCESS_XML_STYLESHEET) && token->string.length > 0) { @@ -399,14 +399,14 @@ parse_sgml_plain(struct dom_stack *stack, struct dom_scanner *scanner) break; case SGML_TOKEN_INCOMPLETE: - return SGML_PARSER_CODE_INCOMPLETE; + return DOM_CODE_INCOMPLETE; case SGML_TOKEN_ERROR: { - enum sgml_parser_code code; + enum dom_code code; code = call_sgml_error_function(stack, token); - if (code != SGML_PARSER_CODE_OK) + if (code != DOM_CODE_OK) return code; 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, int complete) { @@ -436,13 +436,13 @@ parse_sgml(struct sgml_parser *parser, unsigned char *buf, size_t bufsize, if (!parser->root) { parser->root = add_sgml_document(parser); if (!parser->root) - return SGML_PARSER_CODE_MEM_ALLOC; + return DOM_CODE_ALLOC_ERR; get_dom_stack_top(&parser->stack)->immutable = 1; } node = init_dom_node(DOM_NODE_TEXT, &source, 0); - if (!node || push_dom_node(&parser->parsing, node) != DOM_STACK_CODE_OK) - return SGML_PARSER_CODE_MEM_ALLOC; + if (!node || push_dom_node(&parser->parsing, node) != DOM_CODE_OK) + return DOM_CODE_ALLOC_ERR; return parser->code; } @@ -464,7 +464,7 @@ struct sgml_parsing_state { unsigned int resume:1; }; -enum dom_stack_code +enum dom_code sgml_parsing_push(struct dom_stack *stack, struct dom_node *node, void *data) { 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->length)) { - parser->code = SGML_PARSER_CODE_MEM_ALLOC; - return DOM_STACK_CODE_OK; + parser->code = DOM_CODE_ALLOC_ERR; + return DOM_CODE_OK; } 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) { 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); } else { 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) { 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. */ if (parsing->scanner.state == SGML_STATE_TEXT) { pop_dom_node(&parser->parsing); - return DOM_STACK_CODE_OK; + return DOM_CODE_OK; } done_dom_string(&parsing->incomplete); parsing->resume = 1; - return DOM_STACK_CODE_OK; + return DOM_CODE_OK; } 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); if (!init_dom_string(&incomplete, string->string, string->length)) { - parser->code = SGML_PARSER_CODE_MEM_ALLOC; - return DOM_STACK_CODE_OK; + parser->code = DOM_CODE_ALLOC_ERR; + return DOM_CODE_OK; } done_dom_string(&parsing->incomplete); set_dom_string(&parsing->incomplete, incomplete.string, incomplete.length); 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) { 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); - return DOM_STACK_CODE_OK; + return DOM_CODE_OK; } static struct dom_stack_context_info sgml_parsing_context_info = { diff --git a/src/dom/sgml/parser.h b/src/dom/sgml/parser.h index 956ff9b39..c83f857dc 100644 --- a/src/dom/sgml/parser.h +++ b/src/dom/sgml/parser.h @@ -2,6 +2,7 @@ #ifndef EL_DOM_SGML_PARSER_H #define EL_DOM_SGML_PARSER_H +#include "dom/code.h" #include "dom/node.h" #include "dom/stack.h" #include "dom/sgml/sgml.h" @@ -62,27 +63,13 @@ struct sgml_parser_state { 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 * * 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. */ -typedef enum sgml_parser_code +typedef enum dom_code (*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_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 */ 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. * 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. */ -enum sgml_parser_code +enum dom_code parse_sgml(struct sgml_parser *parser, unsigned char *buf, size_t bufsize, int complete); /** Get the line position in the source diff --git a/src/dom/stack.c b/src/dom/stack.c index 328a7ef4c..5546757d6 100644 --- a/src/dom/stack.c +++ b/src/dom/stack.c @@ -151,7 +151,7 @@ call_dom_stack_callbacks(struct dom_stack *stack, struct dom_stack_state *state, stack->current = context; switch (callback(stack, state->node, data)) { - case DOM_STACK_CODE_FREE_NODE: + case DOM_CODE_FREE_NODE: free_node = 1; break; default: @@ -164,7 +164,7 @@ call_dom_stack_callbacks(struct dom_stack *stack, struct dom_stack_state *state, return free_node; } -enum dom_stack_code +enum dom_code push_dom_node(struct dom_stack *stack, struct dom_node *node) { 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); 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); if (!state) { done_dom_node(node); - return DOM_STACK_CODE_ERROR_MEM_ALLOC; + return DOM_CODE_ALLOC_ERR; } state += stack->depth; @@ -191,7 +191,7 @@ push_dom_node(struct dom_stack *stack, struct dom_node *node) if (context->info->object_size && !realloc_dom_stack_state_objects(context, stack->depth)) { 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++; call_dom_stack_callbacks(stack, state, DOM_STACK_PUSH); - return DOM_STACK_CODE_OK; + return DOM_CODE_OK; } void @@ -358,7 +358,7 @@ walk_dom_nodes(struct dom_stack *stack, struct dom_node *root) if (!context) return; - if (push_dom_node(stack, root) != DOM_STACK_CODE_OK) + if (push_dom_node(stack, root) != DOM_CODE_OK) return; 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)) { 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; } @@ -498,7 +498,7 @@ static unsigned char indent_string[] = #define get_indent_offset(stack) \ ((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) { 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, 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) { 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); - 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) { 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); - 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) { 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, 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 = { diff --git a/src/dom/stack.h b/src/dom/stack.h index 996b2a00b..0feeff73e 100644 --- a/src/dom/stack.h +++ b/src/dom/stack.h @@ -1,6 +1,7 @@ #ifndef EL_DOM_STACK_H #define EL_DOM_STACK_H +#include "dom/code.h" #include "dom/node.h" #include "util/error.h" #include "util/hash.h" @@ -9,21 +10,10 @@ struct 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 * * 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 *); #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 * 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 * diff --git a/src/dom/test/.gitignore b/src/dom/test/.gitignore new file mode 100644 index 000000000..1a42ef7f2 --- /dev/null +++ b/src/dom/test/.gitignore @@ -0,0 +1,3 @@ +html-mangle +sgml-parser +trash diff --git a/src/dom/test/sgml-parser.c b/src/dom/test/sgml-parser.c index 23b2ef680..df8eb1102 100644 --- a/src/dom/test/sgml-parser.c +++ b/src/dom/test/sgml-parser.c @@ -99,7 +99,7 @@ print_indent(struct dom_stack *stack) printf("%.*s", get_indent_offset(stack), indent_string); } -static enum dom_stack_code +static enum dom_code sgml_parser_test_tree(struct dom_stack *stack, struct dom_node *node, void *data) { struct dom_string *value = &node->string; @@ -107,17 +107,17 @@ sgml_parser_test_tree(struct dom_stack *stack, struct dom_node *node, void *data /* Always print the URI for identification. */ if (update_number_of_lines(stack)) - return DOM_STACK_CODE_OK; + return DOM_CODE_OK; print_indent(stack); printf("%.*s: %.*s\n", name->length, name->string, value->length, value->string); - return DOM_STACK_CODE_OK; + return DOM_CODE_OK; } -static enum dom_stack_code +static enum dom_code sgml_parser_test_id_leaf(struct dom_stack *stack, struct dom_node *node, void *data) { struct dom_string *name; @@ -126,7 +126,7 @@ sgml_parser_test_id_leaf(struct dom_stack *stack, struct dom_node *node, void *d assert(node); if (update_number_of_lines(stack)) - return DOM_STACK_CODE_OK; + return DOM_CODE_OK; name = get_dom_node_name(node); id = get_dom_node_type_name(node->type); @@ -138,10 +138,10 @@ sgml_parser_test_id_leaf(struct dom_stack *stack, struct dom_node *node, void *d print_dom_node_value(node); printf("\n"); - return DOM_STACK_CODE_OK; + return DOM_CODE_OK; } -static enum dom_stack_code +static enum dom_code sgml_parser_test_leaf(struct dom_stack *stack, struct dom_node *node, void *data) { struct dom_string *name; @@ -149,7 +149,7 @@ sgml_parser_test_leaf(struct dom_stack *stack, struct dom_node *node, void *data assert(node); if (update_number_of_lines(stack)) - return DOM_STACK_CODE_OK; + return DOM_CODE_OK; name = get_dom_node_name(node); @@ -159,10 +159,10 @@ sgml_parser_test_leaf(struct dom_stack *stack, struct dom_node *node, void *data print_dom_node_value(node); printf("\n"); - return DOM_STACK_CODE_OK; + return DOM_CODE_OK; } -static enum dom_stack_code +static enum dom_code sgml_parser_test_branch(struct dom_stack *stack, struct dom_node *node, void *data) { struct dom_string *name; @@ -171,7 +171,7 @@ sgml_parser_test_branch(struct dom_stack *stack, struct dom_node *node, void *da assert(node); if (update_number_of_lines(stack)) - return DOM_STACK_CODE_OK; + return DOM_CODE_OK; name = get_dom_node_name(node); id = get_dom_node_type_name(node->type); @@ -180,10 +180,10 @@ sgml_parser_test_branch(struct dom_stack *stack, struct dom_node *node, void *da printf("%.*s: %.*s\n", id->length, id->string, name->length, name->string); - return DOM_STACK_CODE_OK; + return DOM_CODE_OK; } -static enum dom_stack_code +static enum dom_code sgml_parser_test_end(struct dom_stack *stack, struct dom_node *node, void *data) { struct sgml_parser *parser = stack->contexts[0]->data; @@ -193,7 +193,7 @@ sgml_parser_test_end(struct dom_stack *stack, struct dom_node *node, void *data) printf("%d\n", number_of_lines); } - return DOM_STACK_CODE_OK; + return DOM_CODE_OK; } struct dom_stack_context_info sgml_parser_test_context_info = { @@ -232,14 +232,14 @@ struct dom_stack_context_info sgml_parser_test_context_info = { } }; -static enum sgml_parser_code +static enum dom_code sgml_error_function(struct sgml_parser *parser, struct dom_string *string, unsigned int line_number) { printf("error on line %d: %.*s\n", line_number, string->length, string->string); - return SGML_PARSER_CODE_OK; + return DOM_CODE_OK; } void die(const char *msg, ...) @@ -263,7 +263,7 @@ main(int argc, char *argv[]) enum sgml_document_type doctype = SGML_DOCTYPE_HTML; enum sgml_parser_flag flags = 0; enum sgml_parser_type type = SGML_PARSER_STREAM; - enum sgml_parser_code code = 0; + enum dom_code code = 0; enum dom_config_flag normalize_flags = 0; int normalize = 0; int dump = 0; @@ -383,10 +383,10 @@ main(int argc, char *argv[]) code = parse_sgml(parser, buffer, size, complete); switch (code) { - case SGML_PARSER_CODE_OK: + case DOM_CODE_OK: break; - case SGML_PARSER_CODE_INCOMPLETE: + case DOM_CODE_INCOMPLETE: if (!complete) break; /* Error */ default: @@ -433,5 +433,5 @@ main(int argc, char *argv[]) check_memory_leaks(); #endif - return code; + return code != DOM_CODE_OK ? 1 : 0; } diff --git a/src/mime/backend/.gitignore b/src/mime/backend/.gitignore new file mode 100644 index 000000000..8ebfa0828 --- /dev/null +++ b/src/mime/backend/.gitignore @@ -0,0 +1,2 @@ +mailcap-cache +trash diff --git a/src/protocol/ftp/.gitignore b/src/protocol/ftp/.gitignore new file mode 100644 index 000000000..01f9a0f49 --- /dev/null +++ b/src/protocol/ftp/.gitignore @@ -0,0 +1,2 @@ +ftp-parser +trash diff --git a/src/util/time.h b/src/util/time.h index 40a0680e4..e80417caa 100644 --- a/src/util/time.h +++ b/src/util/time.h @@ -1,6 +1,9 @@ #ifndef EL__UTIL_TIME_H #define EL__UTIL_TIME_H +#ifdef HAVE_SYS_TYPES_H +#include +#endif #ifdef HAVE_SYS_TIME_H #include #endif