html/css: use caseless __html_strcmp() instead of strcmp() master
authoryu.dongliang <18588496441@163.com>
Mon, 13 Apr 2026 17:42:38 +0000 (01:42 +0800)
committeryu.dongliang <18588496441@163.com>
Mon, 13 Apr 2026 17:42:38 +0000 (01:42 +0800)
17 files changed:
examples/css.html
examples/style.css
html/abc_css.c
html/abc_css_color.c
html/abc_css_position.c
html/abc_html.c
html/abc_html.h
html/abc_io.h
html/abc_io_http.c
html/abc_io_util.c
ui/abc_layout.c
ui/abc_layout_h1.c
ui/abc_layout_input.c
ui/abc_render_bg_image.c
ui/abc_render_h1.c
ui/abc_render_input.c
ui/main.c

index 47d68ecf42cb5dd1c956105d2de0f30650ad2314..1ae820a61636e53bf0abe4fff4d480c2bdfd7d85 100644 (file)
 <p style="color:green">这个段落采用CSS样式化。</p>
 
 <p>链接到: <a href="https://www.runoob.com/">runoob.com</a></p>
 <p style="color:green">这个段落采用CSS样式化。</p>
 
 <p>链接到: <a href="https://www.runoob.com/">runoob.com</a></p>
+
+<p class="uppercase">This is some text.</p>
+<p class="lowercase">This is some text.</p>
+<p class="capitalize">This is some text.</p>
 </body>
 
 </html>
 </body>
 
 </html>
index 8754073f7b71c229695e4882d48a39c3a336c6c6..6cca9a1543c671016e3417511cc75cda6d65bd89 100644 (file)
@@ -15,7 +15,10 @@ a {text-decoration:none;}
        text-align:center;
 }
 
        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;}
index e354f41cbc18f6f7a7ed5444f991ff33106a1a48..859e07f3bd15d9a28da0b9bd39bd1acafca2949f 100644 (file)
@@ -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++) {
                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;
                        }
                }
                                        goto found;
                        }
                }
@@ -196,7 +196,7 @@ found:
                attr = scf_list_data(l, abc_obj_t, list);
 
                for (j = 0; attr->keys[j]; j++) {
                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;
                }
        }
                                break;
                }
        }
@@ -521,6 +521,49 @@ next:
        } while (c);
 }
 
        } 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)
 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_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:
                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;
        };
 }
 
                        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;
 
                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>
-       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;
 
                                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);
                }
        }
 
                }
        }
 
index 07cf730d41acfd7f56e9ef122cef018c2bc8c3d4..515f28c5a21ebd2f325e92076336a9328b137cb8 100644 (file)
 
 typedef struct css_color_s
 {
 
 typedef struct css_color_s
 {
-       char**  names;
-       double  r;
-       double  g;
-       double  b;
+       char**    names;
+       uint32_t  color;
 } css_color_t;
 
 } 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[] =
 {
 
 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)
 };
 
 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;
 
                *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;
                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++) {
 
                        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;
                                }
                        }
                                        return 0;
                                }
                        }
index 88df2c27be7aeb10cf8ff8637a6111339dcaae31..800d10d918af9817573c60323ecc56ded072b6be 100644 (file)
@@ -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++) {
 
                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;
                        }
                                *value = c->value;
                                return;
                        }
index 5ef572da9aa373aa30c99328902339b22ebe329b..353892710ea858ab836be381f35b6483d8d4c85b 100644 (file)
@@ -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_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},
        {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_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},
        {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++) {
 
 
                for (j = 0; label->names[j]; j++) {
 
-                       if (!strcmp(label->names[j], name))
+                       if (!__html_strcmp(label->names[j], name))
                                return  label;
                }
        }
                                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;
 
        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 {
                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];
 
                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];
 
                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 {
                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++) {
 
        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;
                }
                        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++) {
 
                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;
                }
        }
                                goto found;
                }
        }
@@ -1338,12 +1338,17 @@ static int __html_parse_obj(abc_html_t* html, abc_char_t* c)
                        if (!type)
                                break;
 
                        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;
                                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:
                        break;
 
                case ABC_HTML_VIDEO:
index dd071ea4d627ab14033cee038a314a5515171980..4f59ebe5d41609fcdd3d960f786e6657a11f52ba 100644 (file)
@@ -32,6 +32,7 @@ struct abc_html_s
 
        abc_obj_t*      root;
        abc_obj_t*      current;
 
        abc_obj_t*      root;
        abc_obj_t*      current;
+       abc_obj_t*      css;
 
        abc_io_t        io;
 
 
        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_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);
 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);
index d21edd1e73857d7532a0967e41151a778935c585..dc70fbe2e43458bd6ba41a2fe0d6c386aba60292 100644 (file)
@@ -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          __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
 #endif
index 559fea123eb3338f67adc7b4de56a181873d0066..18a232c4885a1db0c4bfb78784fb60685fe1464f 100644 (file)
@@ -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");
 
                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;
 
                        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;
 
                        http->content_length = 0;
                        http->chunk_flag = 1;
 
index a96ee22e808c98a03a57952dca56f28b0cc0f0c4..9ac6bebdbd94785ffb295acf2cf8adc380a74566 100644 (file)
@@ -96,6 +96,52 @@ void __io_push_char(abc_io_t* io, abc_char_t* c)
        io->tmp_list = 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();
 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;
 
                        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;
 
                        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 {
                        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);
 
                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;
 
                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)
 {
 
 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;
                return -EINVAL;
 
        const char* p0 = current + 5;
index 6275c9c6fa46ebd09e88582b4a8186084fa4c785..2c0c4ee6b935942ffc1ccba92f9629c051c8f773 100644 (file)
@@ -117,10 +117,10 @@ int abc_layout_css(abc_obj_t* root)
 
                int x = root->x;
 
 
                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;
 
                        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);
                        root->x = parent->x + parent->w - root->w - 8;
 
                abc_css_update_xy(root, root->x - x, 0);
index 84e085a0a6f988f60a5b700c2ea741bf1d33c415..a4ade871f4f3b2db8dedd674fec7212bdee43a31 100644 (file)
@@ -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) {
 
                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;
 
                                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;
                }
 
                                italic = CAIRO_FONT_SLANT_OBLIQUE;
                }
 
index eb34e5935f3234c3096301d842073b1d45dab115..b4fa92b97dd0a24a543f143f6bede28efabe2537 100644 (file)
@@ -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);
 
 
        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);
 
 
                attr = abc_obj_find_attr(obj, ABC_HTML_ATTR_VALUE);
 
index 6dd4802924f6b60cc83ce34c4592eb48283ef1f0..267272df71e5fead42a06f5f5ffb806990d7e945 100644 (file)
@@ -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) {
 
        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;
 
                        repeat_y = 0;
 
-               else if (!strcmp(attr->value->data, "repeat-y"))
+               else if (!__html_strcmp(attr->value->data, "repeat-y"))
                        repeat_x = 0;
 
                        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;
                }
                        repeat_x = 0;
                        repeat_y = 0;
                }
index f33ba37748a0ef80959e52ca26366996abc59480..a3997546ca0376239c0641b0f73e648cb3e3e414 100644 (file)
@@ -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) {
 
                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;
 
                                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;
                }
 
                                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);
 
                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);
 
                        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);
 
                        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);
                }
                        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);
                }
index 8c7ebe05fe2cb9b68f16795fa767a0d5963d082d..aab897633b0b3334dee9e40087192ab8e7dd6a8a 100644 (file)
@@ -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 (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) {
 
                        char* passwd = strdup(attr->value->data);
                        if (!passwd) {
index 41801d7215d2bed2125804e6bac784fc4cff8a78..c3a890d9f2be4d4f398c630b9540ef96ed2e99cd 100644 (file)
--- 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) {
                        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));
 
                                                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);
 
 
                        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);
                                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);
 
 
        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;
 
                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 (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);
 
 
                        attr = abc_obj_get_attr(obj, ABC_HTML_ATTR_VALUE);