diff --git a/src/gui/curses/gui-curses-color.c b/src/gui/curses/gui-curses-color.c index 872c96211..d1fe83257 100644 --- a/src/gui/curses/gui-curses-color.c +++ b/src/gui/curses/gui-curses-color.c @@ -37,6 +37,7 @@ #include "../../core/core-list.h" #include "../../core/core-string.h" #include "../../core/core-utf8.h" +#include "../../core/core-util.h" #include "../../plugins/plugin.h" #include "../gui-buffer.h" #include "../gui-color.h" @@ -225,7 +226,6 @@ int gui_color_assign (int *color, const char *color_name) { int flag, extra_attr, color_index, number; - char *error; /* read extended attributes */ extra_attr = 0; @@ -244,9 +244,7 @@ gui_color_assign (int *color, const char *color_name) } /* is it a color number? */ - error = NULL; - number = (int)strtol (color_name, &error, 10); - if (color_name[0] && error && !error[0] && (number >= 0)) + if (color_name[0] && util_parse_int (color_name, 10, &number) && (number >= 0)) { /* color_name is a number, use this color number */ if (number > GUI_COLOR_EXTENDED_MAX) @@ -1357,7 +1355,6 @@ gui_color_palette_add_alias_cb (void *data, const void *key, const void *value) { struct t_gui_color_palette *color_palette; - char *error; int number; /* make C compiler happy */ @@ -1368,9 +1365,7 @@ gui_color_palette_add_alias_cb (void *data, if (color_palette && color_palette->alias) { - error = NULL; - number = (int)strtol ((char *)key, &error, 10); - if (error && !error[0]) + if (util_parse_int ((const char *)key, 10, &number)) { hashtable_set (gui_color_hash_palette_alias, color_palette->alias, @@ -1437,8 +1432,7 @@ 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; - char *str_alias, *str_rgb, str_number[64]; + char **items, *pos, *pos2, *str_alias, *str_rgb, str_number[64]; int num_items, i, r, g, b; if (!value) @@ -1490,16 +1484,11 @@ gui_color_palette_new (int number, const char *value) 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] + if (util_parse_int (str_rgb, 10, &r) && (r >= 0) && (r <= 1000) + && util_parse_int (pos + 1, 10, &g) && (g >= 0) && (g <= 1000) + && util_parse_int (pos2 + 1, 10, &b) && (b >= 0) && (b <= 1000)) { new_color_palette->r = r; diff --git a/src/gui/curses/gui-curses-mouse.c b/src/gui/curses/gui-curses-mouse.c index daa4987f9..809a7cc00 100644 --- a/src/gui/curses/gui-curses-mouse.c +++ b/src/gui/curses/gui-curses-mouse.c @@ -36,6 +36,7 @@ #include "../../core/core-hook.h" #include "../../core/core-string.h" #include "../../core/core-utf8.h" +#include "../../core/core-util.h" #include "../../plugins/plugin.h" #include "../gui-bar.h" #include "../gui-bar-window.h" @@ -355,10 +356,9 @@ gui_mouse_event_concat_gesture (char *key) const char * gui_mouse_event_name_sgr (const char *key) { - int length, num_items, is_release; - char **items, *error; + int length, num_items, is_release, button, x, y; + char **items; static char mouse_key[128]; - long button, x, y; if (!key || !key[0]) return NULL; @@ -372,14 +372,10 @@ gui_mouse_event_name_sgr (const char *key) if (num_items < 3) goto error; - error = NULL; - button = strtol (items[0], &error, 10); - if (!error || error[0]) + if (!util_parse_int (items[0], 10, &button)) goto error; - error = NULL; - x = strtol (items[1], &error, 10); - if (!error || error[0]) + if (!util_parse_int (items[1], 10, &x)) goto error; x = (x >= 1) ? x - 1 : 0; @@ -388,9 +384,7 @@ gui_mouse_event_name_sgr (const char *key) goto error; is_release = (items[2][length - 1] == 'm') ? 1 : 0; items[2][length - 1] = '\0'; - error = NULL; - y = strtol (items[2], &error, 10); - if (!error || error[0]) + if (!util_parse_int (items[2], 10, &y)) goto error; y = (y >= 1) ? y - 1 : 0; diff --git a/src/gui/curses/gui-curses-window.c b/src/gui/curses/gui-curses-window.c index cd16b095e..b9857fea9 100644 --- a/src/gui/curses/gui-curses-window.c +++ b/src/gui/curses/gui-curses-window.c @@ -41,6 +41,7 @@ #include "../../core/core-hook.h" #include "../../core/core-log.h" #include "../../core/core-string.h" +#include "../../core/core-util.h" #include "../../plugins/plugin.h" #include "../gui-window.h" #include "../gui-bar.h" @@ -638,7 +639,7 @@ void gui_window_string_apply_color_fg (unsigned char **string, WINDOW *window) { unsigned char *ptr_string; - char str_fg[6], *error; + char str_fg[6]; int fg, extra_attr, flag; ptr_string = *string; @@ -659,9 +660,7 @@ gui_window_string_apply_color_fg (unsigned char **string, WINDOW *window) { memcpy (str_fg, ptr_string, 5); str_fg[5] = '\0'; - error = NULL; - fg = (int)strtol (str_fg, &error, 10); - if (error && !error[0]) + if (util_parse_int (str_fg, 10, &fg)) { gui_window_set_custom_color_fg (window, fg | GUI_COLOR_EXTENDED_FLAG | extra_attr); @@ -685,9 +684,7 @@ gui_window_string_apply_color_fg (unsigned char **string, WINDOW *window) str_fg[0] = ptr_string[0]; str_fg[1] = ptr_string[1]; str_fg[2] = '\0'; - error = NULL; - fg = (int)strtol (str_fg, &error, 10); - if (error && !error[0]) + if (util_parse_int (str_fg, 10, &fg)) { gui_window_set_custom_color_fg (window, fg | extra_attr); } @@ -710,7 +707,7 @@ void gui_window_string_apply_color_bg (unsigned char **string, WINDOW *window) { unsigned char *ptr_string; - char str_bg[6], *error; + char str_bg[6]; int bg; ptr_string = *string; @@ -724,9 +721,7 @@ gui_window_string_apply_color_bg (unsigned char **string, WINDOW *window) { memcpy (str_bg, ptr_string + 1, 5); str_bg[5] = '\0'; - error = NULL; - bg = (int)strtol (str_bg, &error, 10); - if (error && !error[0]) + if (util_parse_int (str_bg, 10, &bg)) { gui_window_set_custom_color_bg (window, bg | GUI_COLOR_EXTENDED_FLAG); @@ -744,9 +739,7 @@ gui_window_string_apply_color_bg (unsigned char **string, WINDOW *window) str_bg[0] = ptr_string[0]; str_bg[1] = ptr_string[1]; str_bg[2] = '\0'; - error = NULL; - bg = (int)strtol (str_bg, &error, 10); - if (error && !error[0]) + if (util_parse_int (str_bg, 10, &bg)) { gui_window_set_custom_color_bg (window, bg); } @@ -769,7 +762,7 @@ void gui_window_string_apply_color_fg_bg (unsigned char **string, WINDOW *window) { unsigned char *ptr_string; - char str_fg[6], str_bg[6], *error; + char str_fg[6], str_bg[6]; int fg, bg, extra_attr, flag; ptr_string = *string; @@ -794,12 +787,10 @@ gui_window_string_apply_color_fg_bg (unsigned char **string, WINDOW *window) { memcpy (str_fg, ptr_string, 5); str_fg[5] = '\0'; - error = NULL; - fg = (int)strtol (str_fg, &error, 10); - if (!error || error[0]) - fg = -1; - else + if (util_parse_int (str_fg, 10, &fg)) fg |= GUI_COLOR_EXTENDED_FLAG | extra_attr; + else + fg = -1; } ptr_string += 5; } @@ -819,12 +810,10 @@ gui_window_string_apply_color_fg_bg (unsigned char **string, WINDOW *window) str_fg[0] = ptr_string[0]; str_fg[1] = ptr_string[1]; str_fg[2] = '\0'; - error = NULL; - fg = (int)strtol (str_fg, &error, 10); - if (!error || error[0]) - fg = -1; - else + if (util_parse_int (str_fg, 10, &fg)) fg |= extra_attr; + else + fg = -1; } ptr_string += 2; } @@ -846,12 +835,10 @@ gui_window_string_apply_color_fg_bg (unsigned char **string, WINDOW *window) { memcpy (str_bg, ptr_string + 1, 5); str_bg[5] = '\0'; - error = NULL; - bg = (int)strtol (str_bg, &error, 10); - if (!error || error[0]) - bg = -1; - else + if (util_parse_int (str_bg, 10, &bg)) bg |= GUI_COLOR_EXTENDED_FLAG; + else + bg = -1; } ptr_string += 6; } @@ -865,9 +852,7 @@ gui_window_string_apply_color_fg_bg (unsigned char **string, WINDOW *window) str_bg[0] = ptr_string[0]; str_bg[1] = ptr_string[1]; str_bg[2] = '\0'; - error = NULL; - bg = (int)strtol (str_bg, &error, 10); - if (!error || error[0]) + if (!util_parse_int (str_bg, 10, &bg)) bg = -1; } ptr_string += 2; @@ -893,7 +878,7 @@ void gui_window_string_apply_color_pair (unsigned char **string, WINDOW *window) { unsigned char *ptr_string; - char str_pair[6], *error; + char str_pair[6]; int pair; ptr_string = *string; @@ -906,12 +891,8 @@ gui_window_string_apply_color_pair (unsigned char **string, WINDOW *window) { memcpy (str_pair, ptr_string, 5); str_pair[5] = '\0'; - error = NULL; - pair = (int)strtol (str_pair, &error, 10); - if (error && !error[0]) - { + if (util_parse_int (str_pair, 10, &pair)) gui_window_set_custom_color_pair (window, pair); - } } ptr_string += 5; } @@ -930,7 +911,7 @@ void gui_window_string_apply_color_weechat (unsigned char **string, WINDOW *window) { unsigned char *ptr_string; - char str_number[3], *error; + char str_number[3]; int weechat_color; ptr_string = *string; @@ -942,13 +923,8 @@ gui_window_string_apply_color_weechat (unsigned char **string, WINDOW *window) str_number[0] = ptr_string[0]; str_number[1] = ptr_string[1]; str_number[2] = '\0'; - error = NULL; - weechat_color = (int)strtol (str_number, &error, 10); - if (error && !error[0]) - { - gui_window_set_weechat_color (window, - weechat_color); - } + if (util_parse_int (str_number, 10, &weechat_color)) + gui_window_set_weechat_color (window, weechat_color); } ptr_string += 2; } @@ -2517,7 +2493,6 @@ void gui_window_bare_display_toggle (const char *delay) { long seconds; - char *error; gui_window_bare_display ^= 1; @@ -2529,9 +2504,7 @@ gui_window_bare_display_toggle (const char *delay) gui_mouse_disable (); if (delay) { - error = NULL; - seconds = strtol (delay, &error, 10); - if (error && !error[0] && (seconds >= 0)) + if (util_parse_long (delay, 10, &seconds) && (seconds >= 0)) { if (gui_window_bare_display_timer) {