mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
Make init_sgml_parser() take URI as dom_string struct
This commit is contained in:
parent
a21f192199
commit
11e168aba4
@ -670,6 +670,9 @@ render_dom_document(struct cache_entry *cached, struct document *document,
|
|||||||
struct conv_table *convert_table;
|
struct conv_table *convert_table;
|
||||||
struct sgml_parser *parser;
|
struct sgml_parser *parser;
|
||||||
enum sgml_document_type doctype;
|
enum sgml_document_type doctype;
|
||||||
|
unsigned char *string = struri(cached->uri);
|
||||||
|
size_t length = strlen(string);
|
||||||
|
struct dom_string uri = INIT_DOM_STRING(string, length);
|
||||||
|
|
||||||
assert(document->options.plain);
|
assert(document->options.plain);
|
||||||
|
|
||||||
@ -689,7 +692,7 @@ render_dom_document(struct cache_entry *cached, struct document *document,
|
|||||||
else
|
else
|
||||||
doctype = SGML_DOCTYPE_HTML;
|
doctype = SGML_DOCTYPE_HTML;
|
||||||
|
|
||||||
parser = init_sgml_parser(SGML_PARSER_STREAM, doctype, cached->uri);
|
parser = init_sgml_parser(SGML_PARSER_STREAM, doctype, &uri);
|
||||||
if (!parser) return;
|
if (!parser) return;
|
||||||
|
|
||||||
add_dom_stack_context(&parser->stack, &renderer,
|
add_dom_stack_context(&parser->stack, &renderer,
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
#include "dom/sgml/parser.h"
|
#include "dom/sgml/parser.h"
|
||||||
#include "dom/sgml/scanner.h"
|
#include "dom/sgml/scanner.h"
|
||||||
#include "dom/sgml/sgml.h"
|
#include "dom/sgml/sgml.h"
|
||||||
#include "protocol/uri.h"
|
|
||||||
#include "util/error.h"
|
#include "util/error.h"
|
||||||
#include "util/lists.h"
|
#include "util/lists.h"
|
||||||
#include "util/memory.h"
|
#include "util/memory.h"
|
||||||
@ -41,11 +40,9 @@ init_sgml_parsing_state(struct sgml_parser *parser, struct string *buffer);
|
|||||||
* information like node subtypes and SGML parser state information. */
|
* information like node subtypes and SGML parser state information. */
|
||||||
|
|
||||||
static inline struct dom_node *
|
static inline struct dom_node *
|
||||||
add_sgml_document(struct dom_stack *stack, struct uri *uri)
|
add_sgml_document(struct dom_stack *stack, struct dom_string *string)
|
||||||
{
|
{
|
||||||
unsigned char *string = struri(uri);
|
struct dom_node *node = init_dom_node(DOM_NODE_DOCUMENT, string->string, string->length);
|
||||||
size_t length = strlen(string);
|
|
||||||
struct dom_node *node = init_dom_node(DOM_NODE_DOCUMENT, string, length);
|
|
||||||
|
|
||||||
return node ? push_dom_node(stack, node) : NULL;
|
return node ? push_dom_node(stack, node) : NULL;
|
||||||
}
|
}
|
||||||
@ -329,7 +326,7 @@ parse_sgml(struct sgml_parser *parser, struct string *buffer)
|
|||||||
struct sgml_parsing_state *parsing;
|
struct sgml_parsing_state *parsing;
|
||||||
|
|
||||||
if (!parser->root) {
|
if (!parser->root) {
|
||||||
parser->root = add_sgml_document(&parser->stack, parser->uri);
|
parser->root = add_sgml_document(&parser->stack, &parser->uri);
|
||||||
if (!parser->root)
|
if (!parser->root)
|
||||||
return NULL;
|
return NULL;
|
||||||
get_dom_stack_top(&parser->stack)->immutable = 1;
|
get_dom_stack_top(&parser->stack)->immutable = 1;
|
||||||
@ -479,7 +476,7 @@ static struct dom_stack_context_info sgml_parser_context_info = {
|
|||||||
|
|
||||||
struct sgml_parser *
|
struct sgml_parser *
|
||||||
init_sgml_parser(enum sgml_parser_type type, enum sgml_document_type doctype,
|
init_sgml_parser(enum sgml_parser_type type, enum sgml_document_type doctype,
|
||||||
struct uri *uri)
|
struct dom_string *uri)
|
||||||
{
|
{
|
||||||
struct sgml_parser *parser;
|
struct sgml_parser *parser;
|
||||||
enum dom_stack_flag flags = 0;
|
enum dom_stack_flag flags = 0;
|
||||||
@ -487,8 +484,12 @@ init_sgml_parser(enum sgml_parser_type type, enum sgml_document_type doctype,
|
|||||||
parser = mem_calloc(1, sizeof(*parser));
|
parser = mem_calloc(1, sizeof(*parser));
|
||||||
if (!parser) return NULL;
|
if (!parser) return NULL;
|
||||||
|
|
||||||
|
if (!init_dom_string(&parser->uri, uri->string, uri->length)) {
|
||||||
|
mem_free(parser);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
parser->type = type;
|
parser->type = type;
|
||||||
parser->uri = get_uri_reference(uri);
|
|
||||||
parser->info = get_sgml_info(doctype);
|
parser->info = get_sgml_info(doctype);
|
||||||
|
|
||||||
if (type == SGML_PARSER_TREE)
|
if (type == SGML_PARSER_TREE)
|
||||||
@ -511,6 +512,6 @@ done_sgml_parser(struct sgml_parser *parser)
|
|||||||
{
|
{
|
||||||
done_dom_stack(&parser->stack);
|
done_dom_stack(&parser->stack);
|
||||||
done_dom_stack(&parser->parsing);
|
done_dom_stack(&parser->parsing);
|
||||||
done_uri(parser->uri);
|
done_dom_string(&parser->uri);
|
||||||
mem_free(parser);
|
mem_free(parser);
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ struct sgml_parser {
|
|||||||
|
|
||||||
struct sgml_info *info; /* Backend dependent info */
|
struct sgml_info *info; /* Backend dependent info */
|
||||||
|
|
||||||
struct uri *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 */
|
||||||
|
|
||||||
struct dom_stack stack; /* A stack for tracking parsed nodes */
|
struct dom_stack stack; /* A stack for tracking parsed nodes */
|
||||||
@ -53,7 +53,7 @@ struct sgml_parser_state {
|
|||||||
|
|
||||||
struct sgml_parser *
|
struct sgml_parser *
|
||||||
init_sgml_parser(enum sgml_parser_type type, enum sgml_document_type doctype,
|
init_sgml_parser(enum sgml_parser_type type, enum sgml_document_type doctype,
|
||||||
struct uri *uri);
|
struct dom_string *uri);
|
||||||
|
|
||||||
void done_sgml_parser(struct sgml_parser *parser);
|
void done_sgml_parser(struct sgml_parser *parser);
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#ifndef EL_DOM_STRING_H
|
#ifndef EL_DOM_STRING_H
|
||||||
#define EL_DOM_STRING_H
|
#define EL_DOM_STRING_H
|
||||||
|
|
||||||
|
#include "util/string.h"
|
||||||
|
|
||||||
struct dom_string {
|
struct dom_string {
|
||||||
size_t length;
|
size_t length;
|
||||||
unsigned char *string;
|
unsigned char *string;
|
||||||
@ -33,6 +35,13 @@ dom_string_ncasecmp(struct dom_string *string1, struct dom_string *string2, size
|
|||||||
return strncasecmp(string1->string, string2->string, length);
|
return strncasecmp(string1->string, string2->string, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline struct dom_string *
|
||||||
|
init_dom_string(struct dom_string *string, unsigned char *str, size_t len)
|
||||||
|
{
|
||||||
|
string->string = memacpy(str, len);
|
||||||
|
return string->string ? string : NULL;
|
||||||
|
}
|
||||||
|
|
||||||
#define is_dom_string_set(str) ((str)->string && (str)->length)
|
#define is_dom_string_set(str) ((str)->string && (str)->length)
|
||||||
|
|
||||||
#define done_dom_string(str) mem_free((str)->string);
|
#define done_dom_string(str) mem_free((str)->string);
|
||||||
|
Loading…
Reference in New Issue
Block a user