diff options
| author | James Booth <boothj5@gmail.com> | 2015-03-16 01:06:40 +0000 |
|---|---|---|
| committer | James Booth <boothj5@gmail.com> | 2015-03-16 01:06:40 +0000 |
| commit | e7e1688d8aa3e7deaea7e15cad7c189a32c570e0 (patch) | |
| tree | 961eaa01f64a24e7a85227184b072c0642d8450d /src/command | |
| parent | 23ef3498b5b3b7377ca5995c68357b6bc62b0739 (diff) | |
| download | profani-tty-e7e1688d8aa3e7deaea7e15cad7c189a32c570e0.tar.gz | |
Moved _strtoi to common, strtoi_range
Diffstat (limited to 'src/command')
| -rw-r--r-- | src/command/commands.c | 50 |
1 files changed, 11 insertions, 39 deletions
diff --git a/src/command/commands.c b/src/command/commands.c index 400a7c8d..4919648a 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -72,7 +72,6 @@ static void _update_presence(const resource_presence_t presence, const char * const show, gchar **args); static gboolean _cmd_set_boolean_preference(gchar *arg, struct cmd_help_t help, const char * const display, preference_t pref); -static gboolean _strtoi(char *str, int *saveptr, int min, int max, char **err_msg); static void _cmd_show_filtered_help(char *heading, gchar *cmd_filter[], int filter_size); static gint _compare_commands(Command *a, Command *b); static void _who_room(gchar **args, struct cmd_help_t help); @@ -213,7 +212,7 @@ cmd_connect(gchar **args, struct cmd_help_t help) if (g_hash_table_contains(options, "port")) { char *port_str = g_hash_table_lookup(options, "port"); char *err_msg = NULL; - gboolean res = _strtoi(port_str, &port, 1, 65535, &err_msg); + gboolean res = strtoi_range(port_str, &port, 1, 65535, &err_msg); if (!res) { cons_show(err_msg); cons_show(""); @@ -469,7 +468,7 @@ cmd_account(gchar **args, struct cmd_help_t help) } else if (strcmp(property, "port") == 0) { int port; char *err_msg = NULL; - gboolean res = _strtoi(value, &port, 1, 65535, &err_msg); + gboolean res = strtoi_range(value, &port, 1, 65535, &err_msg); if (!res) { cons_show(err_msg); cons_show(""); @@ -529,7 +528,7 @@ cmd_account(gchar **args, struct cmd_help_t help) } else if (valid_resource_presence_string(property)) { int intval; char *err_msg = NULL; - gboolean res = _strtoi(value, &intval, -128, 127, &err_msg); + gboolean res = strtoi_range(value, &intval, -128, 127, &err_msg); if (res) { resource_presence_t presence_type = resource_presence_from_string(property); switch (presence_type) @@ -1575,7 +1574,7 @@ cmd_roster(gchar **args, struct cmd_help_t help) } int intval = 0; char *err_msg = NULL; - gboolean res = _strtoi(args[1], &intval, 1, 99, &err_msg); + gboolean res = strtoi_range(args[1], &intval, 1, 99, &err_msg); if (res) { prefs_set_roster_size(intval); cons_show("Roster screen size set to: %d%%", intval); @@ -2859,7 +2858,7 @@ cmd_occupants(gchar **args, struct cmd_help_t help) } else { int intval = 0; char *err_msg = NULL; - gboolean res = _strtoi(args[1], &intval, 1, 99, &err_msg); + gboolean res = strtoi_range(args[1], &intval, 1, 99, &err_msg); if (res) { prefs_set_occupants_size(intval); cons_show("Occupants screen size set to: %d%%", intval); @@ -3630,7 +3629,7 @@ cmd_inpblock(gchar **args, struct cmd_help_t help) int intval = 0; char *err_msg = NULL; - gboolean res = _strtoi(value, &intval, 1, 1000, &err_msg); + gboolean res = strtoi_range(value, &intval, 1, 1000, &err_msg); if (res) { cons_show("Input blocking set to %d milliseconds.", intval); prefs_set_inpblock(intval); @@ -3676,7 +3675,7 @@ cmd_log(gchar **args, struct cmd_help_t help) int intval = 0; char *err_msg = NULL; - gboolean res = _strtoi(value, &intval, PREFS_MIN_LOG_SIZE, INT_MAX, &err_msg); + gboolean res = strtoi_range(value, &intval, PREFS_MIN_LOG_SIZE, INT_MAX, &err_msg); if (res) { prefs_set_max_log_size(intval); cons_show("Log maxinum size set to %d bytes", intval); @@ -3725,7 +3724,7 @@ cmd_reconnect(gchar **args, struct cmd_help_t help) int intval = 0; char *err_msg = NULL; - gboolean res = _strtoi(value, &intval, 0, INT_MAX, &err_msg); + gboolean res = strtoi_range(value, &intval, 0, INT_MAX, &err_msg); if (res) { prefs_set_reconnect(intval); if (intval == 0) { @@ -3749,7 +3748,7 @@ cmd_autoping(gchar **args, struct cmd_help_t help) int intval = 0; char *err_msg = NULL; - gboolean res = _strtoi(value, &intval, 0, INT_MAX, &err_msg); + gboolean res = strtoi_range(value, &intval, 0, INT_MAX, &err_msg); if (res) { prefs_set_autoping(intval); iq_set_autoping(intval); @@ -3814,7 +3813,7 @@ cmd_autoaway(gchar **args, struct cmd_help_t help) if (strcmp(setting, "time") == 0) { int minutesval = 0; char *err_msg = NULL; - gboolean res = _strtoi(value, &minutesval, 1, INT_MAX, &err_msg); + gboolean res = strtoi_range(value, &minutesval, 1, INT_MAX, &err_msg); if (res) { prefs_set_autoaway_time(minutesval); cons_show("Auto away time set to: %d minutes.", minutesval); @@ -3860,7 +3859,7 @@ cmd_priority(gchar **args, struct cmd_help_t help) int intval = 0; char *err_msg = NULL; - gboolean res = _strtoi(value, &intval, -128, 127, &err_msg); + gboolean res = strtoi_range(value, &intval, -128, 127, &err_msg); if (res) { accounts_set_priority_all(jabber_get_account_name(), intval); resource_presence_t last_presence = accounts_get_last_presence(jabber_get_account_name()); @@ -4412,33 +4411,6 @@ _cmd_set_boolean_preference(gchar *arg, struct cmd_help_t help, return TRUE; } -static gboolean -_strtoi(char *str, int *saveptr, int min, int max, char **err_msg) -{ - char *ptr; - int val; - - errno = 0; - val = (int)strtol(str, &ptr, 0); - if (errno != 0 || *str == '\0' || *ptr != '\0') { - GString *err_str = g_string_new(""); - g_string_printf(err_str, "Could not convert \"%s\" to a number.", str); - *err_msg = err_str->str; - g_string_free(err_str, FALSE); - return FALSE; - } else if (val < min || val > max) { - GString *err_str = g_string_new(""); - g_string_printf(err_str, "Value %s out of range. Must be in %d..%d.", str, min, max); - *err_msg = err_str->str; - g_string_free(err_str, FALSE); - return FALSE; - } - - *saveptr = val; - - return TRUE; -} - static void _cmd_show_filtered_help(char *heading, gchar *cmd_filter[], int filter_size) { |