Code

colors: return bool instead of int
authorMax Kellermann <max.kellermann@gmail.com>
Tue, 21 Mar 2017 20:42:27 +0000 (21:42 +0100)
committerMax Kellermann <max.kellermann@gmail.com>
Tue, 21 Mar 2017 20:47:17 +0000 (21:47 +0100)
src/colors.c
src/colors.h
src/conf.c

index 1cf4c973cfc63c933b221b4384041764eb51beac..3b100bc22f3c06ea30614b69a48d0710a133f44d 100644 (file)
@@ -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
index c166c363be4378e7c774eff76cc099a1b50a78a0..deb910561cfa24a7cf203393f20bf4fdb5c1510a 100644 (file)
@@ -24,6 +24,8 @@
 #include "ncmpc_curses.h"
 #include "Compiler.h"
 
+#include <stdbool.h>
+
 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);
index 814a13b774486e2e204ee1d8bc61aba2ea12f8c6..496dcab6dc974cc429247fd0ee9fb54a1e9a92a2 100644 (file)
@@ -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]);