From 474623a0d69139a235bc797a559d0bddb25b0588 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 21 Mar 2017 21:42:27 +0100 Subject: [PATCH] colors: return bool instead of int --- src/colors.c | 14 +++++++------- src/colors.h | 9 +++++++-- src/conf.c | 16 ++++++++-------- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/colors.c b/src/colors.c index 1cf4c97..3b100bc 100644 --- a/src/colors.c +++ b/src/colors.c @@ -165,13 +165,13 @@ colors_str2color(const char *str) /* This function is called from conf.c before curses have been started, * it adds the definition to the color_definition_list and init_color() is * done in colors_start() */ -int +bool colors_define(const char *name, short r, short g, short b) { int color = colors_str2color(name); if (color < 0) - return color; + return false; color_definition_entry_t *entry = g_malloc(sizeof(color_definition_entry_t)); @@ -182,10 +182,10 @@ colors_define(const char *name, short r, short g, short b) color_definition_list = g_list_append(color_definition_list, entry); - return 0; + return true; } -int +bool colors_assign(const char *name, const char *value) { color_entry_t *entry = colors_lookup_by_name(name); @@ -193,15 +193,15 @@ colors_assign(const char *name, const char *value) if (!entry) { fprintf(stderr, "%s: %s", _("Unknown color field"), name); - return -1; + return false; } const int color = colors_str2color(value); if (color == COLOR_ERROR) - return -1; + return false; entry->color = color; - return 0; + return true; } void diff --git a/src/colors.h b/src/colors.h index c166c36..deb9105 100644 --- a/src/colors.h +++ b/src/colors.h @@ -24,6 +24,8 @@ #include "ncmpc_curses.h" #include "Compiler.h" +#include + enum color { COLOR_TITLE = 1, COLOR_TITLE_BOLD, @@ -47,8 +49,11 @@ gcc_pure int colors_str2color(const char *str); #ifdef ENABLE_COLORS -int colors_assign(const char *name, const char *value); -int colors_define(const char *name, short r, short g, short b); +bool +colors_assign(const char *name, const char *value); + +bool +colors_define(const char *name, short r, short g, short b); void colors_start(void); diff --git a/src/conf.c b/src/conf.c index 814a13b..496dcab 100644 --- a/src/conf.c +++ b/src/conf.c @@ -209,12 +209,12 @@ separate_value(char *p) return g_strchug(value); } -static int +static bool parse_color(char *str) { char *value = separate_value(str); if (value == NULL) - return -1; + return false; return colors_assign(str, value); } @@ -239,19 +239,19 @@ after_comma(char *p) return comma; } -static int +static bool parse_color_definition(char *str) { char *value = separate_value(str); if (value == NULL) - return -1; + return false; /* get the command name */ short color = colors_str2color(str); if (color < 0) { char buf[MAX_LINE_LENGTH]; print_error(_("Bad color name"), buf); - return -1; + return false; } /* parse r,g,b values */ @@ -261,13 +261,13 @@ parse_color_definition(char *str) char *next = after_comma(value), *endptr; if (*value == 0) { print_error(_("Incomplete color definition"), str); - return -1; + return false; } rgb[i] = strtol(value, &endptr, 0); if (endptr == value || *endptr != 0) { print_error(_("Invalid number"), value); - return -1; + return false; } value = next; @@ -275,7 +275,7 @@ parse_color_definition(char *str) if (*value != 0) { print_error(_("Malformed color definition"), str); - return -1; + return false; } return colors_define(str, rgb[0], rgb[1], rgb[2]); -- 2.30.2