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

Use dom_string for storing the name member of dom_scanner_string_mapping

This commit is contained in:
Jonas Fonseca 2005-12-28 21:10:05 +01:00 committed by Jonas Fonseca
parent f1015f8a6a
commit fb6ca9a390
4 changed files with 46 additions and 34 deletions

View File

@ -54,33 +54,36 @@ static const struct dom_scan_table_info css_scan_table_info[] = {
DOM_SCAN_TABLE_END,
};
#define CSS_STRING_MAP(str, type, family) \
{ INIT_DOM_STRING(str, -1), CSS_TOKEN_##type, CSS_TOKEN_##family }
static const struct dom_scanner_string_mapping css_string_mappings[] = {
{ "Hz", CSS_TOKEN_FREQUENCY, CSS_TOKEN_DIMENSION },
{ "cm", CSS_TOKEN_LENGTH, CSS_TOKEN_DIMENSION },
{ "deg", CSS_TOKEN_ANGLE, CSS_TOKEN_DIMENSION },
{ "em", CSS_TOKEN_EM, CSS_TOKEN_DIMENSION },
{ "ex", CSS_TOKEN_EX, CSS_TOKEN_DIMENSION },
{ "grad", CSS_TOKEN_ANGLE, CSS_TOKEN_DIMENSION },
{ "in", CSS_TOKEN_LENGTH, CSS_TOKEN_DIMENSION },
{ "kHz", CSS_TOKEN_FREQUENCY, CSS_TOKEN_DIMENSION },
{ "mm", CSS_TOKEN_LENGTH, CSS_TOKEN_DIMENSION },
{ "ms", CSS_TOKEN_TIME, CSS_TOKEN_DIMENSION },
{ "pc", CSS_TOKEN_LENGTH, CSS_TOKEN_DIMENSION },
{ "pt", CSS_TOKEN_LENGTH, CSS_TOKEN_DIMENSION },
{ "px", CSS_TOKEN_LENGTH, CSS_TOKEN_DIMENSION },
{ "rad", CSS_TOKEN_ANGLE, CSS_TOKEN_DIMENSION },
{ "s", CSS_TOKEN_TIME, CSS_TOKEN_DIMENSION },
CSS_STRING_MAP("Hz", FREQUENCY, DIMENSION),
CSS_STRING_MAP("cm", LENGTH, DIMENSION),
CSS_STRING_MAP("deg", ANGLE, DIMENSION),
CSS_STRING_MAP("em", EM, DIMENSION),
CSS_STRING_MAP("ex", EX, DIMENSION),
CSS_STRING_MAP("grad", ANGLE, DIMENSION),
CSS_STRING_MAP("in", LENGTH, DIMENSION),
CSS_STRING_MAP("kHz", FREQUENCY, DIMENSION),
CSS_STRING_MAP("mm", LENGTH, DIMENSION),
CSS_STRING_MAP("ms", TIME, DIMENSION),
CSS_STRING_MAP("pc", LENGTH, DIMENSION),
CSS_STRING_MAP("pt", LENGTH, DIMENSION),
CSS_STRING_MAP("px", LENGTH, DIMENSION),
CSS_STRING_MAP("rad", ANGLE, DIMENSION),
CSS_STRING_MAP("s", TIME, DIMENSION),
{ "rgb", CSS_TOKEN_RGB, CSS_TOKEN_FUNCTION },
{ "url", CSS_TOKEN_URL, CSS_TOKEN_FUNCTION },
CSS_STRING_MAP("rgb", RGB, FUNCTION),
CSS_STRING_MAP("url", URL, FUNCTION),
{ "charset", CSS_TOKEN_AT_CHARSET, CSS_TOKEN_AT_KEYWORD },
{ "font-face", CSS_TOKEN_AT_FONT_FACE, CSS_TOKEN_AT_KEYWORD },
{ "import", CSS_TOKEN_AT_IMPORT, CSS_TOKEN_AT_KEYWORD },
{ "media", CSS_TOKEN_AT_MEDIA, CSS_TOKEN_AT_KEYWORD },
{ "page", CSS_TOKEN_AT_PAGE, CSS_TOKEN_AT_KEYWORD },
CSS_STRING_MAP("charset", AT_CHARSET, AT_KEYWORD),
CSS_STRING_MAP("font-face", AT_FONT_FACE, AT_KEYWORD),
CSS_STRING_MAP("import", AT_IMPORT, AT_KEYWORD),
CSS_STRING_MAP("media", AT_MEDIA, AT_KEYWORD),
CSS_STRING_MAP("page", AT_PAGE, AT_KEYWORD),
{ NULL, CSS_TOKEN_NONE, CSS_TOKEN_NONE },
DOM_STRING_MAP_END,
};
static struct dom_scanner_token *scan_css_tokens(struct dom_scanner *scanner);

View File

@ -19,11 +19,11 @@ map_dom_scanner_string(struct dom_scanner *scanner,
unsigned char *ident, unsigned char *end, int base_type)
{
const struct dom_scanner_string_mapping *mappings = scanner->info->mappings;
int length = end - ident;
struct dom_string name = INIT_DOM_STRING(ident, end - ident);
for (; mappings->name; mappings++) {
for (; is_dom_string_set(&mappings->name); mappings++) {
if (mappings->base_type == base_type
&& !strlcasecmp(mappings->name, -1, ident, length))
&& !dom_string_casecmp(&mappings->name, &name))
return mappings->type;
}

View File

@ -61,11 +61,17 @@ struct dom_scan_table_info {
DOM_SCAN_TABLE_INFO(DOM_SCAN_END, NULL, 0, 0)
struct dom_scanner_string_mapping {
unsigned char *name;
struct dom_string name;
int type;
int base_type;
};
#define DOM_STRING_MAP(str, type, family) \
{ INIT_DOM_STRING(str, -1), (type), (family) }
#define DOM_STRING_MAP_END \
{ INIT_DOM_STRING(NULL, 0), 0, 0 }
struct dom_scanner;
struct dom_scanner_info {

View File

@ -51,16 +51,19 @@ static struct dom_scan_table_info sgml_scan_table_info[] = {
DOM_SCAN_TABLE_END,
};
#define SGML_STRING_MAP(str, type, family) \
{ INIT_DOM_STRING(str, -1), SGML_TOKEN_##type, SGML_TOKEN_##family }
static struct dom_scanner_string_mapping sgml_string_mappings[] = {
{ "--", SGML_TOKEN_NOTATION_COMMENT, SGML_TOKEN_NOTATION },
{ "ATTLIST", SGML_TOKEN_NOTATION_ATTLIST, SGML_TOKEN_NOTATION },
{ "DOCTYPE", SGML_TOKEN_NOTATION_DOCTYPE, SGML_TOKEN_NOTATION },
{ "ELEMENT", SGML_TOKEN_NOTATION_ELEMENT, SGML_TOKEN_NOTATION },
{ "ENTITY", SGML_TOKEN_NOTATION_ENTITY, SGML_TOKEN_NOTATION },
SGML_STRING_MAP("--", NOTATION_COMMENT, NOTATION),
SGML_STRING_MAP("ATTLIST", NOTATION_ATTLIST, NOTATION),
SGML_STRING_MAP("DOCTYPE", NOTATION_DOCTYPE, NOTATION),
SGML_STRING_MAP("ELEMENT", NOTATION_ELEMENT, NOTATION),
SGML_STRING_MAP("ENTITY", NOTATION_ENTITY, NOTATION),
{ "xml", SGML_TOKEN_PROCESS_XML, SGML_TOKEN_PROCESS },
SGML_STRING_MAP("xml", PROCESS_XML, PROCESS),
{ NULL, SGML_TOKEN_NONE, SGML_TOKEN_NONE },
DOM_STRING_MAP_END,
};
static struct dom_scanner_token *scan_sgml_tokens(struct dom_scanner *scanner);