#include"abc_html.h"
-int __html_add_attr (abc_obj_t* obj, int type, abc_str_t* names, size_t n_names, const char* value, int flags);
-html_label_t* __html_find_label (const char* name, size_t len);
-html_label_t* __html_find_label2(const int type);
+int __html_add_attr(abc_obj_t* obj, int type, abc_str_t* names, size_t n_names, const char* value, int flags);
+html_tag_t* __html_find_tag (const char* name, size_t len);
+html_tag_t* __html_find_tag2 (const int type);
static int __css_drop_comment(abc_obj_t* style)
{
};
}
- html_label_t* label;
+ html_tag_t* tag;
if (id >= 0)
- label = __html_find_label2(ABC_CSS_ID);
+ tag = __html_find_tag2(ABC_CSS_ID);
else if (class >= 0)
- label = __html_find_label2(ABC_CSS_CLASS);
+ tag = __html_find_tag2(ABC_CSS_CLASS);
else if (attr >= 0)
- label = __html_find_label2(ABC_CSS_ATTR);
+ tag = __html_find_tag2(ABC_CSS_ATTR);
else if (pseClass >= 0)
- label = __html_find_label2(ABC_CSS_PSE_CLASS);
+ tag = __html_find_tag2(ABC_CSS_PSE_CLASS);
else if (pseElement >= 0)
- label = __html_find_label2(ABC_CSS_PSE_ELEMENT);
+ tag = __html_find_tag2(ABC_CSS_PSE_ELEMENT);
else if (combinator >= 0)
- label = __html_find_label2(ABC_CSS_COMBINATOR);
+ tag = __html_find_tag2(ABC_CSS_COMBINATOR);
else {
- label = __html_find_label(css->text->data, css->text->len);
- if (!label) {
+ tag = __html_find_tag(css->text->data, css->text->len);
+ if (!tag) {
scf_loge("css selector '%s' invalid, file: %s, line: %d\n", css->text->data, css->file->data, css->line);
return -EINVAL;
}
- scf_logd("css selector '%s', label->name: %s\n", css->text->data, label->names[0].data);
+ scf_logd("css selector '%s', tag->name: %s\n", css->text->data, tag->names[0].data);
scf_string_free(css->text);
css->text = NULL;
}
- css->type = label->type;
- css->keys = label->names;
- css->n_keys = label->n_names;
- css->flags = label->flags;
+ css->type = tag->type;
+ css->keys = tag->names;
+ css->n_keys = tag->n_names;
+ css->flags = tag->flags;
if (css->text) {
if (j < 0)
case '~':
j++;
default:
- label = __html_find_label(css->text->data + j, k - j);
+ tag = __html_find_tag(css->text->data + j, k - j);
- css->key_type = label->type;
+ css->key_type = tag->type;
break;
};
return 0;
}
-static int __css_parse_selectors(abc_obj_t* style, scf_string_t* key, html_label_t* label, scf_list_t* h)
+static int __css_parse_selectors(abc_obj_t* style, scf_string_t* key, html_tag_t* tag, scf_list_t* h)
{
int tmp = EOF;
do {
break;
if (key->len > 0) {
- css_rule_t* css = css_rule_alloc(style->file, style->text_line, style->text_pos, label->type);
+ css_rule_t* css = css_rule_alloc(style->file, style->text_line, style->text_pos, tag->type);
if (!css) {
scf_string_free(key);
return -ENOMEM;
}
- css->flags = label->flags;
- css->keys = label->names;
- css->n_keys = label->n_names;
+ css->flags = tag->flags;
+ css->keys = tag->names;
+ css->n_keys = tag->n_names;
css->parent = style;
css->text = key;
static int __css_parse_obj(abc_obj_t* style, abc_char_t* c)
{
- html_label_t* label;
+ html_tag_t* tag;
scf_string_t* key = scf_string_cstr_len(c->utf8, c->len);
style->text_pos += c->len;
if (!key)
return -ENOMEM;
- label = __html_find_label2(ABC_CSS_COMBINATOR);
- if (!label) {
- scf_loge("invalid HTML label '%s' in file: %s, line: %d\n", key->data, style->file->data, style->text_line);
+ tag = __html_find_tag2(ABC_CSS_COMBINATOR);
+ if (!tag) {
+ scf_loge("invalid HTML tag '%s' in file: %s, line: %d\n", key->data, style->file->data, style->text_line);
scf_string_free(key);
return -EINVAL;
}
scf_list_init(&h);
- int ret = __css_parse_selectors(style, key, label, &h);
+ int ret = __css_parse_selectors(style, key, tag, &h);
if ('{' != ret) {
ret = -EINVAL;
goto error;
if (!src) {
src = css;
- ret = __css_parse_attr(style, css, label->attrs, label->n_attrs);
+ ret = __css_parse_attr(style, css, tag->attrs, tag->n_attrs);
} else
ret = abc_css_copy_attrs(css, src);
if (ret < 0)
if (attr && attr->value && attr->value->len > 0)
{
- html_label_t* label = __html_find_label2(obj->type);
- abc_io_t* io = abc_io_array[ABC_PROTO_STR];
+ html_tag_t* tag = __html_find_tag2(obj->type);
+ abc_io_t* io = abc_io_array[ABC_PROTO_STR];
abc_obj_t* css = abc_obj_alloc(obj->file, obj->line, obj->pos, ABC_HTML_STYLE);
if (!css)
return ret;
}
- ret = __css_parse_attr(css, (css_rule_t*)css, label->attrs, label->n_attrs);
+ ret = __css_parse_attr(css, (css_rule_t*)css, tag->attrs, tag->n_attrs);
io->close(&css->io);
if (ret < 0 && EOF != ret) {
abc_obj_free(css);
static abc_str_t http_equiv_keys[] = {ABC_STR("http-equiv")};
-// HTML labels
+// HTML tags
static abc_str_t html_keys[] = {ABC_STR("html"), ABC_STR("网页")};
static abc_str_t head_keys[] = {ABC_STR("head"), ABC_STR("头部")};
static abc_str_t body_keys[] = {ABC_STR("body"), ABC_STR("主体")};
{font_size_keys, abc_number_of(font_size_keys), "16", ABC_HTML_ATTR_FONT_SIZE, 0},
};
-static html_label_t html_labels[] =
+static html_tag_t html_tags[] =
{
{html_keys, abc_number_of(html_keys), ABC_HTML, abc_number_of(html_attrs), html_attrs, ABC_HTML_FLAG_CLOSE | ABC_HTML_FLAG_SHOW},
{meta_keys, abc_number_of(meta_keys), ABC_HTML_META, abc_number_of(meta_attrs), meta_attrs, ABC_HTML_FLAG_OPEN | ABC_HTML_FLAG_SHOW},
static int __html_parse_obj(abc_html_t* html, abc_char_t* c);
-html_label_t* __html_find_label(const char* name, size_t len)
+html_tag_t* __html_find_tag(const char* name, size_t len)
{
- html_label_t* label;
- abc_str_t* s;
+ html_tag_t* tag;
+ abc_str_t* s;
int i;
int j;
- for (i = 0; i < sizeof(html_labels) / sizeof(html_labels[0]); i++) {
- label = &html_labels[i];
+ for (i = 0; i < sizeof(html_tags) / sizeof(html_tags[0]); i++) {
+ tag = &html_tags[i];
- for (j = 0; j < label->n_names; j++) {
- s = &(label->names[j]);
+ for (j = 0; j < tag->n_names; j++) {
+ s = &(tag->names[j]);
if (len == s->len && !__html_strncmp(s->data, name, len))
- return label;
+ return tag;
}
}
return NULL;
}
-html_label_t* __html_find_label2(const int type)
+html_tag_t* __html_find_tag2(const int type)
{
- html_label_t* label;
+ html_tag_t* tag;
int i;
- for (i = 0; i < sizeof(html_labels) / sizeof(html_labels[0]); i++) {
- label = &html_labels[i];
+ for (i = 0; i < sizeof(html_tags) / sizeof(html_tags[0]); i++) {
+ tag = &html_tags[i];
- if (type == label->type)
- return label;
+ if (type == tag->type)
+ return tag;
}
return NULL;
static int __html_add_controls(abc_obj_t* obj)
{
- html_label_t* label;
- abc_obj_t* play;
- abc_obj_t* progress;
+ html_tag_t* tag;
+ abc_obj_t* play;
+ abc_obj_t* progress;
play = abc_obj_alloc(obj->file, obj->line, obj->pos, ABC_HTML_PLAY);
if (!play)
return -ENOMEM;
- label = __html_find_label2(ABC_HTML_PLAY);
- play->flags = label->flags;
- play->keys = label->names;
- play->n_keys = label->n_names;
+ tag = __html_find_tag2(ABC_HTML_PLAY);
+ play->flags = tag->flags;
+ play->keys = tag->names;
+ play->n_keys = tag->n_names;
play->parent = obj;
progress = abc_obj_alloc(obj->file, obj->line, obj->pos, ABC_HTML_PROGRESS);
return -ENOMEM;
}
- label = __html_find_label2(ABC_HTML_PROGRESS);
- progress->flags = label->flags;
- progress->keys = label->names;
- progress->n_keys = label->n_names;
+ tag = __html_find_tag2(ABC_HTML_PROGRESS);
+ progress->flags = tag->flags;
+ progress->keys = tag->names;
+ progress->n_keys = tag->n_names;
progress->parent = obj;
scf_list_add_tail(&obj->childs, &play->list);
}
}
- scf_loge("end label '%s' file: %s, line: %d, NOT for label '%s' line: %d\n",
+ scf_loge("end tag '%s' file: %s, line: %d, NOT for tag '%s' line: %d\n",
end->data, html->file->data, html->n_lines, obj->keys[0].data, obj->line);
scf_string_free(end);
static int __html_parse_text(abc_html_t* html, abc_obj_t* obj)
{
- if (ABC_HTML_FLAG_OPEN == (obj->flags & 0x1)) // single labels
+ if (ABC_HTML_FLAG_OPEN == (obj->flags & 0x1)) // single tags
return 0;
scf_string_t* text = scf_string_alloc();
static int __html_parse_obj(abc_html_t* html, abc_char_t* c)
{
- html_label_t* label;
+ html_tag_t* tag;
abc_obj_t* obj;
abc_attr_t* type;
scf_string_t* key = scf_string_cstr_len(c->utf8, c->len);
free(c);
c = NULL;
- label = __html_find_label(key->data, key->len);
- if (!label) {
- scf_loge("invalid HTML label '%s' in file: %s, line: %d\n",
+ tag = __html_find_tag(key->data, key->len);
+ if (!tag) {
+ scf_loge("invalid HTML tag '%s' in file: %s, line: %d\n",
key->data, html->file->data, html->n_lines);
scf_string_free(key);
return -1;
scf_string_free(key);
key = NULL;
- obj = abc_obj_alloc(html->file, html->n_lines, html->pos, label->type);
+ obj = abc_obj_alloc(html->file, html->n_lines, html->pos, tag->type);
if (!obj)
return -ENOMEM;
- obj->flags = label->flags;
- obj->keys = label->names;
- obj->n_keys = label->n_names;
-
+ obj->flags = tag->flags;
+ obj->keys = tag->names;
+ obj->n_keys = tag->n_names;
obj->parent = html->current;
- int ret = __html_load_attrs(obj, label->attrs, label->n_attrs);
+ int ret = __html_load_attrs(obj, tag->attrs, tag->n_attrs);
if (ret < 0) {
abc_obj_free(obj);
return ret;
switch (tmp) {
case ' ':
- ret = __html_parse_attr(html, obj, label->attrs, label->n_attrs);
+ ret = __html_parse_attr(html, obj, tag->attrs, tag->n_attrs);
if (ret < 0) {
abc_obj_free(obj);
return ret;
c = NULL;
if ('>' != tmp) {
- scf_loge("HTML label '%s' (%d) not closed, in file: %s, line: %d\n",
+ scf_loge("HTML tag '%s' (%d) not closed, in file: %s, line: %d\n",
obj->keys[0].data, tmp, html->file->data, html->n_lines);
return -1;
}