mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
Make parse_sgml() return the sgml_parser_code enum
It is mostly just ignored for now. The SGML parser test tool will however return parser code.
This commit is contained in:
parent
29279e71b7
commit
af72dd8435
@ -665,7 +665,6 @@ render_dom_document(struct cache_entry *cached, struct document *document,
|
||||
struct string *buffer)
|
||||
{
|
||||
unsigned char *head = empty_string_or_(cached->head);
|
||||
struct dom_node *root;
|
||||
struct dom_renderer renderer;
|
||||
struct conv_table *convert_table;
|
||||
struct sgml_parser *parser;
|
||||
@ -674,6 +673,7 @@ render_dom_document(struct cache_entry *cached, struct document *document,
|
||||
size_t length = strlen(string);
|
||||
struct dom_string uri = INIT_DOM_STRING(string, length);
|
||||
struct dom_string source = INIT_DOM_STRING(buffer->source, buffer->length);
|
||||
enum sgml_parser_code code;
|
||||
|
||||
assert(document->options.plain);
|
||||
|
||||
@ -713,8 +713,12 @@ render_dom_document(struct cache_entry *cached, struct document *document,
|
||||
add_dom_stack_context(&parser->stack, &renderer,
|
||||
&dom_source_renderer_context_info);
|
||||
|
||||
root = parse_sgml(parser, &source, 1);
|
||||
if (root) {
|
||||
/* FIXME: When rendering this way we don't really care about the code.
|
||||
* However, it will be useful when we will be able to also
|
||||
* incrementally parse new data. This will require the parser to live
|
||||
* during the fetching of data. */
|
||||
code = parse_sgml(parser, &source, 1);
|
||||
if (parser->root) {
|
||||
assert(parser->stack.depth == 1);
|
||||
|
||||
get_dom_stack_top(&parser->stack)->immutable = 0;
|
||||
|
@ -154,15 +154,6 @@ add_sgml_node(struct dom_stack *stack, enum dom_node_type type, struct dom_scann
|
||||
|
||||
/* SGML parser main handling: */
|
||||
|
||||
enum sgml_parser_code {
|
||||
SGML_PARSER_CODE_OK, /* The parsing was successful */
|
||||
SGML_PARSER_CODE_INCOMPLETE, /* The parsing could not be completed */
|
||||
|
||||
/* FIXME: For when we will add support for requiring stricter parsing
|
||||
* or even a validator. */
|
||||
SGML_PARSER_CODE_ERROR,
|
||||
};
|
||||
|
||||
static inline enum sgml_parser_code
|
||||
parse_sgml_attributes(struct dom_stack *stack, struct dom_scanner *scanner)
|
||||
{
|
||||
@ -361,7 +352,7 @@ parse_sgml_plain(struct dom_stack *stack, struct dom_scanner *scanner)
|
||||
return SGML_PARSER_CODE_OK;
|
||||
}
|
||||
|
||||
struct dom_node *
|
||||
enum sgml_parser_code
|
||||
parse_sgml(struct sgml_parser *parser, struct dom_string *buffer, int complete)
|
||||
{
|
||||
struct sgml_parsing_state *parsing;
|
||||
@ -373,18 +364,18 @@ parse_sgml(struct sgml_parser *parser, struct dom_string *buffer, int complete)
|
||||
if (!parser->root) {
|
||||
parser->root = add_sgml_document(&parser->stack, &parser->uri);
|
||||
if (!parser->root)
|
||||
return NULL;
|
||||
return SGML_PARSER_CODE_MEM_ALLOC;
|
||||
get_dom_stack_top(&parser->stack)->immutable = 1;
|
||||
}
|
||||
|
||||
parsing = init_sgml_parsing_state(parser, buffer);
|
||||
if (!parsing) return NULL;
|
||||
if (!parsing) return SGML_PARSER_CODE_MEM_ALLOC;
|
||||
|
||||
code = parse_sgml_plain(&parser->stack, &parsing->scanner);
|
||||
|
||||
pop_dom_node(&parser->parsing);
|
||||
|
||||
return parser->root;
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
|
@ -25,6 +25,7 @@ enum sgml_parser_type {
|
||||
enum sgml_parser_flag {
|
||||
SGML_PARSER_COUNT_LINES = 1,
|
||||
SGML_PARSER_COMPLETE = 2,
|
||||
SGML_PARSER_INCREMENTAL = 4,
|
||||
};
|
||||
|
||||
struct sgml_parser_state {
|
||||
@ -56,7 +57,17 @@ init_sgml_parser(enum sgml_parser_type type, enum sgml_document_type doctype,
|
||||
|
||||
void done_sgml_parser(struct sgml_parser *parser);
|
||||
|
||||
struct dom_node *
|
||||
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,
|
||||
};
|
||||
|
||||
enum sgml_parser_code
|
||||
parse_sgml(struct sgml_parser *parser, struct dom_string *buffer, int complete);
|
||||
|
||||
unsigned int get_sgml_parser_line_number(struct sgml_parser *parser);
|
||||
|
@ -236,10 +236,10 @@ void die(const char *msg, ...)
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
struct dom_node *root;
|
||||
struct sgml_parser *parser;
|
||||
enum sgml_document_type doctype = SGML_DOCTYPE_HTML;
|
||||
enum sgml_parser_flag flags = 0;
|
||||
enum sgml_parser_code code = 0;
|
||||
struct dom_string uri = INIT_DOM_STRING("dom://test", -1);
|
||||
struct dom_string source = INIT_DOM_STRING("(no source)", -1);
|
||||
int i;
|
||||
@ -292,8 +292,8 @@ main(int argc, char *argv[])
|
||||
|
||||
add_dom_stack_context(&parser->stack, NULL, &sgml_parser_test_context_info);
|
||||
|
||||
root = parse_sgml(parser, &source, 1);
|
||||
if (root) {
|
||||
code = parse_sgml(parser, &source, 1);
|
||||
if (parser->root) {
|
||||
assert(parser->stack.depth == 1);
|
||||
|
||||
get_dom_stack_top(&parser->stack)->immutable = 0;
|
||||
@ -304,5 +304,5 @@ main(int argc, char *argv[])
|
||||
|
||||
done_sgml_parser(parser);
|
||||
|
||||
return 0;
|
||||
return code;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user