1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-06-23 00:45:39 +00:00

DOM: Add STATIC_DOM_STRING macro and make INIT_DOM_STRING cleaner

This commit is contained in:
Jonas Fonseca 2006-01-28 22:55:15 +01:00 committed by Jonas Fonseca
parent 58b8635caf
commit 2918e3f595
10 changed files with 39 additions and 30 deletions

View File

@ -304,7 +304,7 @@ struct dom_config_info {
};
#define DOM_CONFIG(name, flag) \
{ INIT_DOM_STRING(name, -1), (flag) }
{ STATIC_DOM_STRING(name), (flag) }
static struct dom_config_info dom_config_info[] = {
DOM_CONFIG("cdata-sections", DOM_CONFIG_CDATA_SECTIONS),

View File

@ -55,7 +55,7 @@ static const struct dom_scan_table_info css_scan_table_info[] = {
};
#define CSS_STRING_MAP(str, type, family) \
{ INIT_DOM_STRING(str, -1), CSS_TOKEN_##type, CSS_TOKEN_##family }
{ STATIC_DOM_STRING(str), CSS_TOKEN_##type, CSS_TOKEN_##family }
static const struct dom_scanner_string_mapping css_string_mappings[] = {
CSS_STRING_MAP("Hz", FREQUENCY, DIMENSION),

View File

@ -451,11 +451,11 @@ done_dom_node(struct dom_node *node)
struct dom_string *
get_dom_node_name(struct dom_node *node)
{
static struct dom_string cdata_section_str = INIT_DOM_STRING("#cdata-section", -1);
static struct dom_string comment_str = INIT_DOM_STRING("#comment", -1);
static struct dom_string document_str = INIT_DOM_STRING("#document", -1);
static struct dom_string document_fragment_str = INIT_DOM_STRING("#document-fragment", -1);
static struct dom_string text_str = INIT_DOM_STRING("#text", -1);
static struct dom_string cdata_section_str = STATIC_DOM_STRING("#cdata-section");
static struct dom_string comment_str = STATIC_DOM_STRING("#comment");
static struct dom_string document_str = STATIC_DOM_STRING("#document");
static struct dom_string document_fragment_str = STATIC_DOM_STRING("#document-fragment");
static struct dom_string text_str = STATIC_DOM_STRING("#text");
assert(node);
@ -521,18 +521,18 @@ get_dom_node_type_name(enum dom_node_type type)
{
static struct dom_string dom_node_type_names[DOM_NODES] = {
INIT_DOM_STRING(NULL, 0),
/* DOM_NODE_ELEMENT */ INIT_DOM_STRING("element", -1),
/* DOM_NODE_ATTRIBUTE */ INIT_DOM_STRING("attribute", -1),
/* DOM_NODE_TEXT */ INIT_DOM_STRING("text", -1),
/* DOM_NODE_CDATA_SECTION */ INIT_DOM_STRING("cdata-section", -1),
/* DOM_NODE_ENTITY_REFERENCE */ INIT_DOM_STRING("entity-reference", -1),
/* DOM_NODE_ENTITY */ INIT_DOM_STRING("entity", -1),
/* DOM_NODE_PROCESSING_INSTRUCTION */ INIT_DOM_STRING("proc-instruction", -1),
/* DOM_NODE_COMMENT */ INIT_DOM_STRING("comment", -1),
/* DOM_NODE_DOCUMENT */ INIT_DOM_STRING("document", -1),
/* DOM_NODE_DOCUMENT_TYPE */ INIT_DOM_STRING("document-type", -1),
/* DOM_NODE_DOCUMENT_FRAGMENT */ INIT_DOM_STRING("document-fragment", -1),
/* DOM_NODE_NOTATION */ INIT_DOM_STRING("notation", -1),
/* DOM_NODE_ELEMENT */ STATIC_DOM_STRING("element"),
/* DOM_NODE_ATTRIBUTE */ STATIC_DOM_STRING("attribute"),
/* DOM_NODE_TEXT */ STATIC_DOM_STRING("text"),
/* DOM_NODE_CDATA_SECTION */ STATIC_DOM_STRING("cdata-section"),
/* DOM_NODE_ENTITY_REFERENCE */ STATIC_DOM_STRING("entity-reference"),
/* DOM_NODE_ENTITY */ STATIC_DOM_STRING("entity"),
/* DOM_NODE_PROCESSING_INSTRUCTION */ STATIC_DOM_STRING("proc-instruction"),
/* DOM_NODE_COMMENT */ STATIC_DOM_STRING("comment"),
/* DOM_NODE_DOCUMENT */ STATIC_DOM_STRING("document"),
/* DOM_NODE_DOCUMENT_TYPE */ STATIC_DOM_STRING("document-type"),
/* DOM_NODE_DOCUMENT_FRAGMENT */ STATIC_DOM_STRING("document-fragment"),
/* DOM_NODE_NOTATION */ STATIC_DOM_STRING("notation"),
};
assert(type < DOM_NODES);

View File

@ -67,7 +67,7 @@ struct dom_scanner_string_mapping {
};
#define DOM_STRING_MAP(str, type, family) \
{ INIT_DOM_STRING(str, -1), (type), (family) }
{ STATIC_DOM_STRING(str), (type), (family) }
#define DOM_STRING_MAP_END \
{ INIT_DOM_STRING(NULL, 0), 0, 0 }

View File

@ -28,7 +28,7 @@ get_dom_select_pseudo(struct dom_scanner_token *token)
} pseudo_info[] = {
#define INIT_DOM_SELECT_PSEUDO_STRING(str, type) \
{ INIT_DOM_STRING(str, -1), DOM_SELECT_PSEUDO_##type }
{ STATIC_DOM_STRING(str), DOM_SELECT_PSEUDO_##type }
INIT_DOM_SELECT_PSEUDO_STRING("first-line", FIRST_LINE),
INIT_DOM_SELECT_PSEUDO_STRING("first-letter", FIRST_LETTER),

View File

@ -44,7 +44,7 @@ static struct dom_scan_table_info sgml_scan_table_info[] = {
};
#define SGML_STRING_MAP(str, type, family) \
{ INIT_DOM_STRING(str, -1), SGML_TOKEN_##type, SGML_TOKEN_##family }
{ STATIC_DOM_STRING(str), SGML_TOKEN_##type, SGML_TOKEN_##family }
static struct dom_scanner_string_mapping sgml_string_mappings[] = {
SGML_STRING_MAP("--", NOTATION_COMMENT, NOTATION),

View File

@ -55,10 +55,10 @@ struct sgml_node_info {
{ INIT_DOM_STRING(NULL, doctype##_##nodetype##S - 1), doctype##_##nodetype##_UNKNOWN }
#define SGML_NODE_INFO(doctype, nodetype, name, data) \
{ INIT_DOM_STRING(#name, sizeof(#name) - 1), doctype##_##nodetype##_##name, data }
{ STATIC_DOM_STRING(#name), doctype##_##nodetype##_##name, data }
#define SGML_NODE_INF2(doctype, nodetype, name, ident, data) \
{ INIT_DOM_STRING(ident, sizeof(ident) - 1), doctype##_##nodetype##_##name, data }
{ STATIC_DOM_STRING(ident), doctype##_##nodetype##_##name, data }
#define SGML_NODE_INFO_TYPE(doctype, nodetype, name) doctype##_##nodetype##_##name

View File

@ -3,13 +3,22 @@
#include "util/memory.h"
/* For now DOM has it's own little string library. Mostly because there are
* some memory overhead associated with util/string's block-based allocation
* scheme which is optimized for building strings and quickly dispose of it.
* Also, at some point we need to switch to use mainly UTF-8 strings for DOM
* and it needs to be possible to adapt the string library to that. --jonas */
struct dom_string {
size_t length;
unsigned char *string;
};
#define INIT_DOM_STRING(strvalue, strlength) \
{ (strlength) == -1 ? sizeof(strvalue) - 1 : (strlength), (strvalue) }
{ (strlength), (strvalue) }
#define STATIC_DOM_STRING(strvalue) \
{ sizeof(strvalue) - 1, (strvalue) }
static inline void
set_dom_string(struct dom_string *string, unsigned char *value, size_t length)

View File

@ -38,9 +38,9 @@ main(int argc, char *argv[])
struct sgml_parser *parser;
struct dom_select *select;
enum sgml_document_type doctype = SGML_DOCTYPE_HTML;
struct dom_string uri = INIT_DOM_STRING("dom://test", -1);
struct dom_string source = INIT_DOM_STRING("(no source)", -1);
struct dom_string selector = INIT_DOM_STRING("(no select)", -1);
struct dom_string uri = STATIC_DOM_STRING("dom://test");
struct dom_string source = STATIC_DOM_STRING("(no source)");
struct dom_string selector = STATIC_DOM_STRING("(no select)");
int i;
for (i = 1; i < argc; i++) {

View File

@ -267,8 +267,8 @@ main(int argc, char *argv[])
int normalize = 0;
int complete = 1;
size_t read_stdin = 0;
struct dom_string uri = INIT_DOM_STRING("dom://test", -1);
struct dom_string source = INIT_DOM_STRING("(no source)", -1);
struct dom_string uri = STATIC_DOM_STRING("dom://test");
struct dom_string source = STATIC_DOM_STRING("(no source)");
int i;
for (i = 1; i < argc; i++) {