diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2010-12-20 16:27:09 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2010-12-20 16:27:09 +0100 |
commit | f7a3a2d995a4cbaed33e595dee5f7a7962b299c0 (patch) | |
tree | f67d58535c60c4ad7b3590699e3218a40d2b5ad8 /src/gui | |
parent | 2ee9f7b0fcac460fca5597ec349309e83de64d00 (diff) | |
download | weechat-f7a3a2d995a4cbaed33e595dee5f7a7962b299c0.zip |
Fix parsing of palette options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/curses/gui-curses-color.c | 137 |
1 files changed, 90 insertions, 47 deletions
diff --git a/src/gui/curses/gui-curses-color.c b/src/gui/curses/gui-curses-color.c index 2f44518ef..5afc5d76b 100644 --- a/src/gui/curses/gui-curses-color.c +++ b/src/gui/curses/gui-curses-color.c @@ -583,8 +583,9 @@ struct t_gui_color_palette * gui_color_palette_new (int number, const char *value) { struct t_gui_color_palette *new_color_palette; - char **items, *pos, *pos2, *error1, *error2, *error3, str_number[64]; - int num_items, fg, bg, r, g, b; + char *pos_semicolon, *ptr_value, *pos, *pos2, *error1, *error2, *error3; + char *str_alias, *str_pair, *str_rgb, str_number[64]; + int fg, bg, r, g, b; if (!value) return NULL; @@ -598,67 +599,109 @@ gui_color_palette_new (int number, const char *value) new_color_palette->r = -1; new_color_palette->g = -1; new_color_palette->b = -1; - items = string_split (value, ";", 0, 0, &num_items); - if (items) + + str_alias = NULL; + str_pair = NULL; + str_rgb = NULL; + + pos_semicolon = strchr (value, ';'); + if (pos_semicolon) { - if ((num_items >= 1) && items[0][0]) + if (pos_semicolon > value) { - new_color_palette->alias = strdup (items[0]); + str_alias = string_strndup (value, pos_semicolon - value); } - if ((num_items >= 2) && items[1][0]) + ptr_value = pos_semicolon + 1; + if (ptr_value[0]) { - pos = strchr (items[1], ','); - if (pos) + pos_semicolon = strchr (ptr_value, ';'); + if (pos_semicolon) { - pos[0] = '\0'; - error1 = NULL; - fg = (int)strtol (items[1], &error1, 10); - error2 = NULL; - bg = (int)strtol (pos + 1, &error2, 10); - if (error1 && !error1[0] && error2 && !error2[0] - && (fg >= -1) && (bg >= -1)) + if (pos_semicolon > ptr_value) { - new_color_palette->foreground = fg; - new_color_palette->background = bg; + str_pair = string_strndup (ptr_value, + pos_semicolon - ptr_value); } - } - } - if ((num_items >= 3) && items[2][0]) - { - pos = strchr (items[2], '/'); - if (pos) - { - pos[0] = '\0'; - pos2 = strchr (pos + 1, '/'); - if (pos2) + ptr_value = pos_semicolon + 1; + if (ptr_value[0]) { - pos2[0] = '\0'; - error1 = NULL; - r = (int)strtol (items[2], &error1, 10); - error2 = NULL; - g = (int)strtol (pos + 1, &error2, 10); - error3 = NULL; - b = (int)strtol (pos2 + 1, &error3, 10); - if (error1 && !error1[0] && error2 && !error2[0] - && error3 && !error3[0] - && (r >= 0) && (r <= 1000) - && (g >= 0) && (g <= 1000) - && (b >= 0) && (b <= 1000)) - { - new_color_palette->r = r; - new_color_palette->g = g; - new_color_palette->b = b; - } + str_rgb = strdup (ptr_value); } } + else + str_pair = strdup (ptr_value); } - string_free_split (items); } - if (!new_color_palette->alias) + else if (value[0]) + { + str_alias = strdup (value); + } + + if (str_alias) + { + new_color_palette->alias = strdup (str_alias); + } + else { snprintf (str_number, sizeof (str_number), "%d", number); new_color_palette->alias = strdup (str_number); } + + if (str_pair) + { + pos = strchr (str_pair, ','); + if (pos) + { + pos[0] = '\0'; + error1 = NULL; + fg = (int)strtol (str_pair, &error1, 10); + error2 = NULL; + bg = (int)strtol (pos + 1, &error2, 10); + if (error1 && !error1[0] && error2 && !error2[0] + && (fg >= -1) && (bg >= -1)) + { + new_color_palette->foreground = fg; + new_color_palette->background = bg; + } + } + } + + if (str_rgb) + { + pos = strchr (str_rgb, '/'); + if (pos) + { + pos[0] = '\0'; + pos2 = strchr (pos + 1, '/'); + if (pos2) + { + pos2[0] = '\0'; + error1 = NULL; + r = (int)strtol (str_rgb, &error1, 10); + error2 = NULL; + g = (int)strtol (pos + 1, &error2, 10); + error3 = NULL; + b = (int)strtol (pos2 + 1, &error3, 10); + if (error1 && !error1[0] && error2 && !error2[0] + && error3 && !error3[0] + && (r >= 0) && (r <= 1000) + && (g >= 0) && (g <= 1000) + && (b >= 0) && (b <= 1000)) + { + new_color_palette->r = r; + new_color_palette->g = g; + new_color_palette->b = b; + } + } + } + } + + if (str_alias) + free (str_alias); + if (str_pair) + free (str_pair); + if (str_rgb) + free (str_rgb); } return new_color_palette; |