From: Max Kellermann Date: Mon, 14 Jul 2014 08:51:59 +0000 (+0200) Subject: command: return bool for success/failure X-Git-Tag: v0.24~8 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=6d21f051228ce9aa492bb4f7a1957a9525208217;p=ncmpc.git command: return bool for success/failure --- diff --git a/src/command.c b/src/command.c index 62d68a5..857bf48 100644 --- a/src/command.c +++ b/src/command.c @@ -453,7 +453,7 @@ get_keyboard_command(void) return get_key_command(key); } -int +bool assign_keys(command_t command, int keys[MAX_COMMAND_KEYS]) { for (size_t i = 0; cmds[i].name; i++) { @@ -462,19 +462,19 @@ assign_keys(command_t command, int keys[MAX_COMMAND_KEYS]) #ifndef NCMPC_MINI cmds[i].flags |= COMMAND_KEY_MODIFIED; #endif - return 0; + return true; } } - return -1; + return false; } #ifndef NCMPC_MINI -int +bool check_key_bindings(command_definition_t *cp, char *buf, size_t bufsize) { - int retval = 0; + bool success = true; if (cp == NULL) cp = cmds; @@ -505,15 +505,15 @@ check_key_bindings(command_definition_t *cp, char *buf, size_t bufsize) } cp[i].flags |= COMMAND_KEY_CONFLICT; set_key_flags(cp, cmd, COMMAND_KEY_CONFLICT); - retval = -1; + success = false; } } } - return retval; + return success; } -int +bool write_key_bindings(FILE *f, int flags) { if (flags & KEYDEF_WRITE_HEADER) @@ -541,7 +541,7 @@ write_key_bindings(FILE *f, int flags) } } - return ferror(f); + return ferror(f) == 0; } #endif /* NCMPC_MINI */ diff --git a/src/command.h b/src/command.h index 307bba1..e770a1d 100644 --- a/src/command.h +++ b/src/command.h @@ -140,8 +140,17 @@ void command_dump_keys(void); #ifndef NCMPC_MINI -int check_key_bindings(command_definition_t *cmds, char *buf, size_t size); -int write_key_bindings(FILE *f, int all); +/** + * @return true on success, false on error + */ +bool +check_key_bindings(command_definition_t *cmds, char *buf, size_t size); + +/** + * @return true on success, false on error + */ +bool +write_key_bindings(FILE *f, int all); #endif @@ -164,7 +173,11 @@ gcc_pure command_t get_key_command_from_name(const char *name); -int assign_keys(command_t command, int keys[MAX_COMMAND_KEYS]); +/** + * @return true on success, false on error + */ +bool +assign_keys(command_t command, int keys[MAX_COMMAND_KEYS]); gcc_pure command_t get_keyboard_command(void); diff --git a/src/conf.c b/src/conf.c index 5d8ec5e..03ba80d 100644 --- a/src/conf.c +++ b/src/conf.c @@ -122,7 +122,7 @@ parse_key_value(char *str, char **end) } } -static int +static bool parse_key_definition(char *str) { /* get the command name */ @@ -139,7 +139,7 @@ parse_key_definition(char *str) /* the hotkey configuration contains an unknown command */ print_error(_("Unknown command"), buf); - return -1; + return false; } /* skip whitespace */ @@ -152,7 +152,7 @@ parse_key_definition(char *str) if (*buf == 0) { /* the hotkey configuration line is incomplete */ print_error(_("Incomplete hotkey configuration"), str); - return -1; + return false; } /* parse key values */ @@ -170,7 +170,7 @@ parse_key_definition(char *str) } if (key < 0) - return -1; + return false; return assign_keys(cmd, keys); } diff --git a/src/main.c b/src/main.c index 4c0f881..341fb17 100644 --- a/src/main.c +++ b/src/main.c @@ -483,10 +483,8 @@ timer_check_key_bindings(gcc_unused gpointer data) #ifdef ENABLE_KEYDEF_SCREEN char comment[64]; #endif - gboolean key_error; - key_error = check_key_bindings(NULL, buf, sizeof(buf)); - if (!key_error) { + if (check_key_bindings(NULL, buf, sizeof(buf))) { /* no error: disable this timer for the rest of this process */ check_key_bindings_source_id = 0; diff --git a/src/screen_keydef.c b/src/screen_keydef.c index dde5ce5..164cf65 100644 --- a/src/screen_keydef.c +++ b/src/screen_keydef.c @@ -162,9 +162,9 @@ save_keys(void) } if (write_key_bindings(f, KEYDEF_WRITE_HEADER)) - screen_status_printf(_("Error: %s - %s"), filename, strerror(errno)); - else screen_status_printf(_("Wrote %s"), filename); + else + screen_status_printf(_("Error: %s - %s"), filename, strerror(errno)); g_free(filename); return fclose(f);