From 159214e87d7c3e40cad0f3e836e8bd88070828c3 Mon Sep 17 00:00:00 2001 From: "yu.dongliang" <18588496441@163.com> Date: Tue, 14 Apr 2026 01:42:38 +0800 Subject: [PATCH] html/css: use caseless __html_strcmp() instead of strcmp() --- examples/css.html | 4 + examples/style.css | 11 ++- html/abc_css.c | 206 ++++++++++++++++++++++++++++++--------- html/abc_css_color.c | 136 ++++++++++++++++++++++---- html/abc_css_position.c | 2 +- html/abc_html.c | 23 +++-- html/abc_html.h | 2 + html/abc_io.h | 3 + html/abc_io_http.c | 4 +- html/abc_io_util.c | 56 ++++++++++- ui/abc_layout.c | 4 +- ui/abc_layout_h1.c | 4 +- ui/abc_layout_input.c | 2 +- ui/abc_render_bg_image.c | 6 +- ui/abc_render_h1.c | 10 +- ui/abc_render_input.c | 2 +- ui/main.c | 8 +- 17 files changed, 379 insertions(+), 104 deletions(-) diff --git a/examples/css.html b/examples/css.html index 47d68ec..1ae820a 100644 --- a/examples/css.html +++ b/examples/css.html @@ -11,6 +11,10 @@

这个段落采用CSS样式化。

链接到: runoob.com

+ +

This is some text.

+

This is some text.

+

This is some text.

diff --git a/examples/style.css b/examples/style.css index 8754073..6cca9a1 100644 --- a/examples/style.css +++ b/examples/style.css @@ -15,7 +15,10 @@ a {text-decoration:none;} text-align:center; } -p.red -{ - color:red; -} +p.red {color:red;} + +p.uppercase {text-transform:uppercase;} +p.lowercase {text-transform:lowercase;} +p.capitalize {text-transform:capitalize;} +p {color:DarkGreen;} +p {color:Fuchsia;} diff --git a/html/abc_css.c b/html/abc_css.c index e354f41..859e07f 100644 --- a/html/abc_css.c +++ b/html/abc_css.c @@ -181,7 +181,7 @@ static int __css_parse_attr2(abc_obj_t* css, abc_obj_t* obj, const html_attr_t* for (i = 0; i < n_attrs; i++) { for (j = 0; attrs[i].names[j]; j++) { - if (!strcmp(attrs[i].names[j], key->data)) + if (!__html_strcmp(attrs[i].names[j], key->data)) goto found; } } @@ -196,7 +196,7 @@ found: attr = scf_list_data(l, abc_obj_t, list); for (j = 0; attr->keys[j]; j++) { - if (!strcmp(attr->keys[j], key->data)) + if (!__html_strcmp(attr->keys[j], key->data)) break; } } @@ -521,6 +521,49 @@ next: } while (c); } +static void __css_text_transform(abc_obj_t* obj, int case_flag) +{ + if (obj->text) { + char* p = obj->text->data; + int c0 = ' '; + int c; + + while (*p) { + c = *p; + + if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z')) + { + switch (case_flag) { + case 0: + *p &= ~0x20; + break; + + case 1: + *p |= 0x20; + break; + + default: + if (' ' == c0 || '\t' == c0 || '\r' == c0 || '\n' == c0) + *p &= ~0x20; + break; + }; + } + + c0 = c; + p++; + } + } + + scf_list_t* l; + abc_obj_t* child; + + for (l = scf_list_head(&obj->childs); l != scf_list_sentinel(&obj->childs); l = scf_list_next(l)) { + child = scf_list_data(l, abc_obj_t, list); + + __css_text_transform(child, case_flag); + } +} + static void __css_set_attr(abc_obj_t* obj, abc_obj_t* attr) { switch (attr->type) @@ -535,69 +578,144 @@ static void __css_set_attr(abc_obj_t* obj, abc_obj_t* attr) case ABC_HTML_ATTR_BG_POSITION: abc_obj_set_attr(obj, attr->type, attr->value->data, attr->value->len); break; + + case ABC_HTML_ATTR_TEXT_TRANSFORM: + if (!__html_strcmp(attr->value->data, "uppercase")) + __css_text_transform(obj, 0); + + else if (!__html_strcmp(attr->value->data, "lowercase")) + __css_text_transform(obj, 1); + + else if (!__html_strcmp(attr->value->data, "capitalize")) + __css_text_transform(obj, 2); + break; default: - abc_recursive_set_attr(obj, attr->type, attr->value->data, attr->value->len); + abc_obj_set_attr(obj, attr->type, attr->value->data, attr->value->len); break; }; } -int abc_css_use(abc_html_t* html, abc_obj_t* obj) +static void __css_merge(abc_obj_t* dst, abc_obj_t* src) { - if (!html->root || !obj) + scf_list_t* l; + abc_obj_t* s; + abc_obj_t* d; + + for (l = scf_list_head(&src->attrs); l != scf_list_sentinel(&src->attrs); ) { + s = scf_list_data(l, abc_obj_t, list); + l = scf_list_next(l); + + d = abc_obj_get_attr(dst, s->type); + if (d) + SCF_XCHG(d->value, s->value); + else { + scf_list_del(&s->list); + scf_list_add_tail(&dst->attrs, &s->list); + } + } +} + +int abc_css_merge(abc_html_t* html, abc_obj_t* css) +{ + if (!html || !css) return -EINVAL; - scf_list_t* l; - scf_list_t* l2; - scf_list_t* l3; - abc_obj_t* head; - abc_obj_t* css; - abc_obj_t* style; - abc_obj_t* attr; + if (!html->css) + html->css = css; + else + scf_list_mov2(&html->css->childs, &css->childs); - // for css in HTML - head = abc_obj_find_type(html->root, ABC_HTML_HEAD); - if (head) { - for (l = scf_list_head(&head->childs); l != scf_list_sentinel(&head->childs); l = scf_list_next(l)) { - css = scf_list_data(l, abc_obj_t, list); + scf_list_t h; + scf_list_t* s; + scf_list_t* d; + abc_obj_t* src; // merge from + abc_obj_t* dst; // merge to - if (ABC_HTML_LINK == css->type) - { - attr = abc_obj_get_attr(css, ABC_HTML_ATTR_TYPE); - if (!attr) - continue; + for (s = scf_list_tail(&html->css->childs); s != scf_list_sentinel(&html->css->childs); ) { + src = scf_list_data(s, abc_obj_t, list); + s = scf_list_prev(s); - if (strcmp(attr->value->data, "text/css")) - continue; + for (d = s; d != scf_list_sentinel(&html->css->childs); d = scf_list_prev(d)) { + dst = scf_list_data(d, abc_obj_t, list); - } else if (ABC_HTML_STYLE != css->type) + if (src->type != dst->type) continue; - for (l2 = scf_list_head(&css->childs); l2 != scf_list_sentinel(&css->childs); l2 = scf_list_next(l2)) { - style = scf_list_data(l2, abc_obj_t, list); + int ret = -1; - if (ABC_CSS_ID == style->type || ABC_CSS_CLASS == style->type) - { - attr = abc_obj_get_attr(obj, style->type); - if (!attr) - continue; + switch (dst->type) { + case ABC_CSS_ID: + case ABC_CSS_CLASS: + ret = scf_string_cmp(src->text, dst->text); + break; + default: + ret = __html_strcmp(src->keys[0], dst->keys[0]); + break; + }; - if (strcmp(attr->value->data, style->text->data + style->css_dot + 1)) - continue; + if (0 == ret) { + __css_merge(dst, src); - if (style->css_dot > 0) { - if (strncmp(obj->keys[0], style->text->data, style->css_dot)) - continue; - } + scf_list_del(&src->list); + abc_obj_free(src); + break; + } + } + } - } else if (style->type != obj->type) - continue; + scf_list_init(&h); + + for (s = scf_list_head(&html->css->childs); s != scf_list_sentinel(&html->css->childs); ) { + src = scf_list_data(s, abc_obj_t, list); + s = scf_list_next(s); + + if (ABC_CSS_ID == src->type || ABC_CSS_CLASS == src->type) { + scf_list_del(&src->list); + scf_list_add_tail(&h, &src->list); + } + } + + scf_list_mov2(&html->css->childs, &h); + return 0; +} + +int abc_css_use(abc_html_t* html, abc_obj_t* obj) +{ + if (!html || !obj) + return -EINVAL; + + if (!html->css) + return 0; + + scf_list_t* l; + scf_list_t* l2; + abc_obj_t* css; + abc_obj_t* attr; + + for (l = scf_list_head(&html->css->childs); l != scf_list_sentinel(&html->css->childs); l = scf_list_next(l)) { + css = scf_list_data(l, abc_obj_t, list); + + if (ABC_CSS_ID == css->type || ABC_CSS_CLASS == css->type) + { + attr = abc_obj_get_attr(obj, css->type); + if (!attr) + continue; - for (l3 = scf_list_head(&style->attrs); l3 != scf_list_sentinel(&style->attrs); l3 = scf_list_next(l3)) { - attr = scf_list_data(l3, abc_obj_t, list); + if (__html_strcmp(attr->value->data, css->text->data + css->css_dot + 1)) + continue; - __css_set_attr(obj, attr); - } + if (css->css_dot > 0) { + if (__html_strncmp(obj->keys[0], css->text->data, css->css_dot)) + continue; } + + } else if (css->type != obj->type) + continue; + + for (l2 = scf_list_head(&css->attrs); l2 != scf_list_sentinel(&css->attrs); l2 = scf_list_next(l2)) { + attr = scf_list_data(l2, abc_obj_t, list); + + __css_set_attr(obj, attr); } } diff --git a/html/abc_css_color.c b/html/abc_css_color.c index 07cf730..515f28c 100644 --- a/html/abc_css_color.c +++ b/html/abc_css_color.c @@ -2,27 +2,121 @@ typedef struct css_color_s { - char** names; - double r; - double g; - double b; + char** names; + uint32_t color; } css_color_t; -static char* css_red[] = {"red", "红", NULL}; -static char* css_green[] = {"green", "绿", NULL}; -static char* css_blue[] = {"blue", "蓝", NULL}; - -static char* css_white[] = {"white", "白", NULL}; -static char* css_black[] = {"black", "黑", NULL}; +static char* css_AliceBlue[] = {"aliceblue", NULL}; +static char* css_AntiqueWhite[] = {"antiquewhite", NULL}; +static char* css_Aqua[] = {"aqua", NULL}; +static char* css_Aquamarine[] = {"aquamarine", NULL}; +static char* css_Azure[] = {"azure", NULL}; +static char* css_Beige[] = {"beige", NULL}; +static char* css_Bisque[] = {"bisque", NULL}; + +static char* css_black[] = {"black", "黑", NULL}; +static char* css_BlanchedAlmond[] = {"blanchedalmond", NULL}; + +static char* css_blue[] = {"blue", "蓝", NULL}; +static char* css_BlueViolet[] = {"blueviolet", NULL}; + +static char* css_brown[] = {"brown", NULL}; +static char* css_BurlyWood[] = {"burlywood", NULL}; +static char* css_CadetBlue[] = {"cadetblue", NULL}; +static char* css_Chartreuse[] = {"chartreuse", NULL}; +static char* css_Chocolate[] = {"chocolate", NULL}; +static char* css_Coral[] = {"coral", NULL}; +static char* css_CornflowerBlue[] = {"cornflowerblue", NULL}; +static char* css_Cornsilk[] = {"cornsilk", NULL}; +static char* css_Crimson[] = {"crimson", NULL}; +static char* css_Cyan[] = {"cyan", NULL}; +static char* css_DarkBlue[] = {"darkblue", NULL}; +static char* css_DarkCyan[] = {"darkcyan", NULL}; +static char* css_DarkGoldenRod[] = {"darkgoldenrod", NULL}; +static char* css_DarkGray[] = {"darkgray", NULL}; +static char* css_DarkGreen[] = {"darkgreen", NULL}; +static char* css_DarkKhaki[] = {"darkkhaki", NULL}; +static char* css_DarkMagenta[] = {"darkmagenta", NULL}; +static char* css_DarkOliveGreen[] = {"darkolivegreen", NULL}; +static char* css_DarkOrange[] = {"darkorange", NULL}; +static char* css_DarkOrchid[] = {"darkorchid", NULL}; +static char* css_DarkRed[] = {"darkred", NULL}; +static char* css_DarkSalmon[] = {"darksalmon", NULL}; +static char* css_DarkSeaGreen[] = {"darkseagreen", NULL}; +static char* css_DarkSlateBlue[] = {"darkslateblue", NULL}; +static char* css_DarkSlateGray[] = {"darkslategray", NULL}; +static char* css_DarkTurquoise[] = {"darkturquoise", NULL}; +static char* css_DarkViolet[] = {"darkviolet", NULL}; +static char* css_DeepPink[] = {"deeppink", NULL}; +static char* css_DeepSkyBlue[] = {"deepskyblue", NULL}; +static char* css_DimGray[] = {"dimgray", NULL}; +static char* css_DodgerBlue[] = {"dodgerblue", NULL}; +static char* css_FireBrick[] = {"firebrick", NULL}; +static char* css_FloralWhite[] = {"floralwhite", NULL}; +static char* css_ForestGreen[] = {"forestgreen", NULL}; + +static char* css_fuchsia[] = {"fuchsia", "紫红", "洋红", NULL}; + +static char* css_green[] = {"green", "绿", NULL}; +static char* css_red[] = {"red", "红", NULL}; +static char* css_white[] = {"white", "白", NULL}; static css_color_t css_colors[] = { - {css_red, 1.0, 0.0, 0.0}, - {css_green, 0.0, 1.0, 0.0}, - {css_blue, 0.0, 0.0, 1.0}, - - {css_white, 1.0, 1.0, 1.0}, - {css_black, 0.0, 0.0, 0.0}, + {css_AliceBlue, 0xf0f8ff}, + {css_AntiqueWhite, 0xfaebd7}, + {css_Aqua, 0x00ffff}, + {css_Aquamarine, 0x7fffd4}, + {css_Azure, 0xf0ffff}, + {css_Beige, 0xf5f5dc}, + {css_Bisque, 0xffe4c4}, + + {css_black, 0x000000}, + {css_BlanchedAlmond, 0xffebcd}, + + {css_blue, 0x0000ff}, + {css_BlueViolet, 0x8a2be2}, + + {css_brown, 0xa52a2a}, + {css_BurlyWood, 0xdeb887}, + {css_CadetBlue, 0x5f9ea0}, + {css_Chartreuse, 0x7fff00}, + {css_Chocolate, 0xd2691e}, + {css_Coral, 0xff7f50}, + {css_CornflowerBlue, 0x6495ed}, + {css_Cornsilk, 0xfff8dc}, + {css_Crimson, 0xdc143c}, + {css_Cyan, 0x00ffff}, + {css_DarkBlue, 0x00008b}, + {css_DarkCyan, 0x008b8b}, + {css_DarkGoldenRod, 0xb8860b}, + {css_DarkGray, 0xa9a9a9}, + {css_DarkGreen, 0x006400}, + {css_DarkKhaki, 0xbdb76b}, + {css_DarkMagenta, 0x8b008b}, + {css_DarkOliveGreen, 0x556b2f}, + {css_DarkOrange, 0xff8c00}, + {css_DarkOrchid, 0x9932cc}, + {css_DarkRed, 0x8b0000}, + {css_DarkSalmon, 0xe9967a}, + {css_DarkSeaGreen, 0x8fbc8f}, + {css_DarkSlateBlue, 0x483d8b}, + {css_DarkSlateGray, 0x2f4f4f}, + {css_DarkTurquoise, 0x00ced1}, + {css_DarkViolet, 0x9400d3}, + {css_DeepPink, 0xff1493}, + {css_DeepSkyBlue, 0x00bfff}, + {css_DimGray, 0x696969}, + {css_DodgerBlue, 0x1e90ff}, + {css_FireBrick, 0xb22222}, + {css_FloralWhite, 0xfffaf0}, + {css_ForestGreen, 0x228b22}, + + {css_fuchsia, 0xff00ff}, + + {css_green, 0x00ff00}, + {css_red, 0xff0000}, + {css_white, 0xffffff}, }; int abc_css_color(double* r, double* g, double* b, const uint8_t* str) @@ -54,7 +148,7 @@ int abc_css_color(double* r, double* g, double* b, const uint8_t* str) *g = ((value >> 8) & 0xff) / 255.0; *b = ( value & 0xff) / 255.0; - } else if (!strncmp(str, "rgb(", 4)) { + } else if (!__html_strncmp(str, "rgb(", 4)) { const uint8_t* p = str + 4; str = p; @@ -82,10 +176,10 @@ int abc_css_color(double* r, double* g, double* b, const uint8_t* str) int j; for (j = 0; c->names[j]; j++) { - if (!strcmp(c->names[j], str)) { - *r = c->r; - *g = c->g; - *b = c->b; + if (!__html_strcmp(c->names[j], str)) { + *r = ((c->color >> 16) & 0xff) / 255.0; + *g = ((c->color >> 8) & 0xff) / 255.0; + *b = ( c->color & 0xff) / 255.0; return 0; } } diff --git a/html/abc_css_position.c b/html/abc_css_position.c index 88df2c2..800d10d 100644 --- a/html/abc_css_position.c +++ b/html/abc_css_position.c @@ -27,7 +27,7 @@ static void __css_pos_value(float* value, const char* name, size_t name_len) int j; for (j = 0; c->names[j]; j++) { - if (!strncmp(c->names[j], name, name_len)) { + if (!__html_strncmp(c->names[j], name, name_len)) { *value = c->value; return; } diff --git a/html/abc_html.c b/html/abc_html.c index 5ef572d..3538927 100644 --- a/html/abc_html.c +++ b/html/abc_html.c @@ -271,7 +271,7 @@ static html_attr_t b_attrs[] = { {font_keys, "SimHei", ABC_HTML_ATTR_FONT, 0}, {font_size_keys, "16", ABC_HTML_ATTR_FONT_SIZE, 0}, - {font_color_keys, "black", ABC_HTML_ATTR_FONT_COLOR, ABC_HTML_FLAG_SHOW}, + {font_color_keys, "", ABC_HTML_ATTR_FONT_COLOR, ABC_HTML_FLAG_SHOW}, {font_style_keys, "bold", ABC_HTML_ATTR_FONT_STYLE, 0}, {bg_color_keys, "", ABC_HTML_ATTR_BG_COLOR, ABC_HTML_FLAG_SHOW}, @@ -286,7 +286,7 @@ static html_attr_t i_attrs[] = { {font_keys, "SimSong", ABC_HTML_ATTR_FONT, 0}, {font_size_keys, "16", ABC_HTML_ATTR_FONT_SIZE, 0}, - {font_color_keys, "black", ABC_HTML_ATTR_FONT_COLOR, ABC_HTML_FLAG_SHOW}, + {font_color_keys, "", ABC_HTML_ATTR_FONT_COLOR, ABC_HTML_FLAG_SHOW}, {font_style_keys, "italic", ABC_HTML_ATTR_FONT_STYLE, 0}, {bg_color_keys, "", ABC_HTML_ATTR_BG_COLOR, ABC_HTML_FLAG_SHOW}, @@ -447,7 +447,7 @@ html_label_t* __html_find_label(const char* name) for (j = 0; label->names[j]; j++) { - if (!strcmp(label->names[j], name)) + if (!__html_strcmp(label->names[j], name)) return label; } } @@ -563,7 +563,7 @@ int abc_html_post(abc_html_t** pp, abc_html_t* form, abc_obj_t* submit) abc_io_t* io; int n; - if (!strncmp(form->file->data, "http://", 7)) { + if (!__html_strncmp(form->file->data, "http://", 7)) { n = 7; io = abc_io_array[ABC_PROTO_HTTP]; } else { @@ -644,11 +644,11 @@ int abc_html_open(abc_html_t** pp, const char* path) n = 0; io = abc_io_array[ABC_PROTO_FILE]; - } else if (!strncmp(path, "file://", 7)) { + } else if (!__html_strncmp(path, "file://", 7)) { n = 7; io = abc_io_array[ABC_PROTO_FILE]; - } else if (!strncmp(path, "http://", 7)) { + } else if (!__html_strncmp(path, "http://", 7)) { n = 7; io = abc_io_array[ABC_PROTO_HTTP]; } else { @@ -744,7 +744,7 @@ static int __html_parse_end(abc_html_t* html, abc_obj_t* obj) int j; for (j = 0; obj->keys[j]; j++) { - if (!strcmp(obj->keys[j], end->data)) { + if (!__html_strcmp(obj->keys[j], end->data)) { scf_string_free(end); return 0; } @@ -1015,7 +1015,7 @@ static int __html_parse_attr2(abc_html_t* html, abc_obj_t* obj, const html_attr_ int j; for (j = 0; attr->keys[j]; j++) { - if (!strcmp(attr->keys[j], key->data)) + if (!__html_strcmp(attr->keys[j], key->data)) goto found; } } @@ -1338,12 +1338,17 @@ static int __html_parse_obj(abc_html_t* html, abc_char_t* c) if (!type) break; - if (strcmp(type->value->data, "text/css")) + if (__html_strcmp(type->value->data, "text/css")) break; case ABC_HTML_STYLE: if (abc_css_parse(obj) < 0) return -1; + + if (abc_css_merge(html, obj) < 0) { + scf_loge("\n"); + return -1; + } break; case ABC_HTML_VIDEO: diff --git a/html/abc_html.h b/html/abc_html.h index dd071ea..4f59ebe 100644 --- a/html/abc_html.h +++ b/html/abc_html.h @@ -32,6 +32,7 @@ struct abc_html_s abc_obj_t* root; abc_obj_t* current; + abc_obj_t* css; abc_io_t io; @@ -50,6 +51,7 @@ void abc_html_close(abc_html_t* html); int abc_html_parse(abc_html_t* html); int abc_css_parse (abc_obj_t* css); +int abc_css_merge (abc_html_t* html, abc_obj_t* css); int abc_css_use (abc_html_t* html, abc_obj_t* obj); int abc_css_color (double* r, double* g, double* b, const uint8_t* str); diff --git a/html/abc_io.h b/html/abc_io.h index d21edd1..dc70fbe 100644 --- a/html/abc_io.h +++ b/html/abc_io.h @@ -50,4 +50,7 @@ void __io_push_char(abc_io_t* io, abc_char_t* c); int __io_url_path (abc_io_t** io, scf_string_t** spath, const char* main, const char* current, size_t current_len); int __io_url_css (abc_io_t** io, scf_string_t** spath, const char* main, const char* current); +int __html_strcmp (const char* s0, const char* s1); +int __html_strncmp(const char* s0, const char* s1, size_t n); + #endif diff --git a/html/abc_io_http.c b/html/abc_io_http.c index 559fea1..18a232c 100644 --- a/html/abc_io_http.c +++ b/html/abc_io_http.c @@ -40,14 +40,14 @@ static void http_parse_head(abc_http_t* http) size_t i = strlen("Content-Length: "); size_t j = strlen("Transfer-Encoding: chunked"); - if (!strncmp(p0, "Content-Length: ", i)) { + if (!__html_strncmp(p0, "Content-Length: ", i)) { http->content_length = atoi(p0 + i); http->chunk_flag = 0; scf_logi("Content-Length: %d\n", http->content_length); break; - } else if (!strncmp(p0, "Transfer-Encoding: chunked", j)) { + } else if (!__html_strncmp(p0, "Transfer-Encoding: chunked", j)) { http->content_length = 0; http->chunk_flag = 1; diff --git a/html/abc_io_util.c b/html/abc_io_util.c index a96ee22..9ac6beb 100644 --- a/html/abc_io_util.c +++ b/html/abc_io_util.c @@ -96,6 +96,52 @@ void __io_push_char(abc_io_t* io, abc_char_t* c) io->tmp_list = c; } +int __html_strcmp(const char* s0, const char* s1) +{ + int c0; + int c1; + do { + c0 = *s0++; + c1 = *s1++; + + if ('A' <= c0 && 'Z' >= c0) + c0 |= 0x20; + + if ('A' <= c1 && 'Z' >= c1) + c1 |= 0x20; + + } while (c0 == c1 && c0); + + if (c0 > c1) + return 1; + else if (c0 < c1) + return -1; + return 0; +} + +int __html_strncmp(const char* s0, const char* s1, size_t n) +{ + int c0; + int c1; + do { + c0 = *s0++; + c1 = *s1++; + + if ('A' <= c0 && 'Z' >= c0) + c0 |= 0x20; + + if ('A' <= c1 && 'Z' >= c1) + c1 |= 0x20; + + } while (c0 == c1 && c0 && 0 != --n); + + if (c0 > c1) + return 1; + else if (c0 < c1) + return -1; + return 0; +} + int __io_url_path(abc_io_t** io, scf_string_t** spath, const char* main, const char* current, size_t current_len) { scf_string_t* path = scf_string_alloc(); @@ -111,11 +157,11 @@ int __io_url_path(abc_io_t** io, scf_string_t** spath, const char* main, const c prefix = 0; proto = ABC_PROTO_FILE; - } else if (!strncmp(main, "file://", 7)) { + } else if (!__html_strncmp(main, "file://", 7)) { prefix = 7; proto = ABC_PROTO_FILE; - } else if (!strncmp(main, "http://", 7)) { + } else if (!__html_strncmp(main, "http://", 7)) { prefix = 7; proto = ABC_PROTO_HTTP; } else { @@ -144,13 +190,13 @@ int __io_url_path(abc_io_t** io, scf_string_t** spath, const char* main, const c } } - if (!strncmp(current, "file://", 7)) { + if (!__html_strncmp(current, "file://", 7)) { prefix = 7; proto = ABC_PROTO_FILE; ret = scf_string_copy_cstr_len(path, current, current_len); - } else if (!strncmp(current, "http://", 7)) { + } else if (!__html_strncmp(current, "http://", 7)) { prefix = 7; proto = ABC_PROTO_HTTP; @@ -184,7 +230,7 @@ int __io_url_path(abc_io_t** io, scf_string_t** spath, const char* main, const c int __io_url_css(abc_io_t** io, scf_string_t** spath, const char* main, const char* current) { - if (strncmp(current, "url('", 5)) + if (__html_strncmp(current, "url('", 5)) return -EINVAL; const char* p0 = current + 5; diff --git a/ui/abc_layout.c b/ui/abc_layout.c index 6275c9c..2c0c4ee 100644 --- a/ui/abc_layout.c +++ b/ui/abc_layout.c @@ -117,10 +117,10 @@ int abc_layout_css(abc_obj_t* root) int x = root->x; - if (!strcmp(attr->value->data, "center")) + if (!__html_strcmp(attr->value->data, "center")) root->x = parent->x + (parent->w - root->w) / 2 + 4; - else if (!strcmp(attr->value->data, "right")) + else if (!__html_strcmp(attr->value->data, "right")) root->x = parent->x + parent->w - root->w - 8; abc_css_update_xy(root, root->x - x, 0); diff --git a/ui/abc_layout_h1.c b/ui/abc_layout_h1.c index 84e085a..a4ade87 100644 --- a/ui/abc_layout_h1.c +++ b/ui/abc_layout_h1.c @@ -21,10 +21,10 @@ int abc_layout_h1(abc_layout_t* layout, abc_obj_t* obj, int width, int height) style = abc_obj_find_attr(obj, ABC_HTML_ATTR_FONT_STYLE); if (style) { - if (!strcmp(style->value->data, "bold")) + if (!__html_strcmp(style->value->data, "bold")) bold = CAIRO_FONT_WEIGHT_BOLD; - else if (!strcmp(style->value->data, "italic") || !strcmp(style->value->data, "oblique")) + else if (!__html_strcmp(style->value->data, "italic") || !__html_strcmp(style->value->data, "oblique")) italic = CAIRO_FONT_SLANT_OBLIQUE; } diff --git a/ui/abc_layout_input.c b/ui/abc_layout_input.c index eb34e59..b4fa92b 100644 --- a/ui/abc_layout_input.c +++ b/ui/abc_layout_input.c @@ -11,7 +11,7 @@ int abc_layout_input(abc_layout_t* layout, abc_obj_t* obj, int width, int height attr = abc_obj_find_attr(obj, ABC_HTML_ATTR_TYPE); - if (!strcmp(attr->value->data, "submit")) { + if (!__html_strcmp(attr->value->data, "submit")) { attr = abc_obj_find_attr(obj, ABC_HTML_ATTR_VALUE); diff --git a/ui/abc_render_bg_image.c b/ui/abc_render_bg_image.c index 6dd4802..267272d 100644 --- a/ui/abc_render_bg_image.c +++ b/ui/abc_render_bg_image.c @@ -166,13 +166,13 @@ static int _render_draw_bg_image(abc_render_t* render, abc_obj_t* obj, int width attr = abc_obj_get_attr(obj, ABC_HTML_ATTR_BG_REPEAT); if (attr) { - if (!strcmp(attr->value->data, "repeat-x")) + if (!__html_strcmp(attr->value->data, "repeat-x")) repeat_y = 0; - else if (!strcmp(attr->value->data, "repeat-y")) + else if (!__html_strcmp(attr->value->data, "repeat-y")) repeat_x = 0; - else if (!strcmp(attr->value->data, "no-repeat")) { + else if (!__html_strcmp(attr->value->data, "no-repeat")) { repeat_x = 0; repeat_y = 0; } diff --git a/ui/abc_render_h1.c b/ui/abc_render_h1.c index f33ba37..a399754 100644 --- a/ui/abc_render_h1.c +++ b/ui/abc_render_h1.c @@ -47,10 +47,10 @@ static int __init_text(cairo_t* cr, abc_obj_t* obj) abc_obj_t* style = abc_obj_find_attr(obj, ABC_HTML_ATTR_FONT_STYLE); if (style) { - if (!strcmp(style->value->data, "bold")) + if (!__html_strcmp(style->value->data, "bold")) bold = CAIRO_FONT_WEIGHT_BOLD; - else if (!strcmp(style->value->data, "italic") || !strcmp(style->value->data, "oblique")) + else if (!__html_strcmp(style->value->data, "italic") || !__html_strcmp(style->value->data, "oblique")) italic = CAIRO_FONT_SLANT_OBLIQUE; } @@ -84,15 +84,15 @@ static int __init_text(cairo_t* cr, abc_obj_t* obj) double line = 0.5 + size / 16.0; cairo_set_line_width(cr, line); - if (!strcmp(attr->value->data, "underline")) { + if (!__html_strcmp(attr->value->data, "underline")) { cairo_move_to(cr, extents.x_bearing, -extents.y_bearing + line + 1.0); cairo_line_to(cr, extents.width, -extents.y_bearing + line + 1.0); - } else if (!strcmp(attr->value->data, "overline")) { + } else if (!__html_strcmp(attr->value->data, "overline")) { cairo_move_to(cr, extents.x_bearing, 1.0); cairo_line_to(cr, extents.width, 1.0); - } else if (!strcmp(attr->value->data, "line-through")) { + } else if (!__html_strcmp(attr->value->data, "line-through")) { cairo_move_to(cr, extents.x_bearing, -extents.y_bearing / 2.0 + line); cairo_line_to(cr, extents.width, -extents.y_bearing / 2.0 + line); } diff --git a/ui/abc_render_input.c b/ui/abc_render_input.c index 8c7ebe0..aab8976 100644 --- a/ui/abc_render_input.c +++ b/ui/abc_render_input.c @@ -88,7 +88,7 @@ static int _render_draw_input(abc_render_t* render, abc_obj_t* obj, int width, i if (attr && attr->value && attr->value->len > 0) { - if (!strcmp(type->value->data, "password")) { + if (!__html_strcmp(type->value->data, "password")) { char* passwd = strdup(attr->value->data); if (!passwd) { diff --git a/ui/main.c b/ui/main.c index 41801d7..c3a890d 100644 --- a/ui/main.c +++ b/ui/main.c @@ -104,7 +104,7 @@ static int __do_button_move(abc_ctx_t* ctx, int x, int y) case ABC_HTML_INPUT: attr = abc_obj_get_attr(obj, ABC_HTML_ATTR_TYPE); if (attr) { - if (!strcmp(attr->value->data, "text") || !strcmp(attr->value->data, "password")) { + if (!__html_strcmp(attr->value->data, "text") || !__html_strcmp(attr->value->data, "password")) { display = gtk_widget_get_display(GTK_WIDGET(ctx->gl_area)); window = gtk_widget_get_window (GTK_WIDGET(ctx->gl_area)); @@ -184,7 +184,7 @@ static int __do_button_release(abc_ctx_t* ctx, int x, int y) attr = abc_obj_find_attr(obj, ABC_HTML_ATTR_TYPE); - if (!strcmp(attr->value->data, "submit")) { + if (!__html_strcmp(attr->value->data, "submit")) { html = NULL; int ret = abc_html_post(&html, ctx->current, obj); @@ -320,7 +320,7 @@ static void __utf8_delete(abc_ctx_t* ctx) attr = abc_obj_get_attr(obj, ABC_HTML_ATTR_TYPE); - if (!strcmp(attr->value->data, "text") || !strcmp(attr->value->data, "password")) { + if (!__html_strcmp(attr->value->data, "text") || !__html_strcmp(attr->value->data, "password")) { uint8_t c; int i; @@ -445,7 +445,7 @@ static void im_commit(GtkIMContext* self, gchar* str, gpointer user_data) if (obj && ABC_HTML_INPUT == obj->type) { attr = abc_obj_get_attr(obj, ABC_HTML_ATTR_TYPE); - if (!strcmp(attr->value->data, "text") || !strcmp(attr->value->data, "password")) { + if (!__html_strcmp(attr->value->data, "text") || !__html_strcmp(attr->value->data, "password")) { attr = abc_obj_get_attr(obj, ABC_HTML_ATTR_VALUE); -- 2.25.1