diff options
author | Johannes Löthberg <johannes@kyriasis.com> | 2014-11-10 23:04:48 +0100 |
---|---|---|
committer | Johannes Löthberg <johannes@kyriasis.com> | 2014-11-10 23:41:21 +0100 |
commit | 922137f64ae3f923cad45c1fa4af9502ed84e1a9 (patch) | |
tree | 3f61cc96beb67dcffe74b090f4aa8efcf8668e19 | |
parent | 657a5d2cdad645ea94a0970262efa5bfa864af25 (diff) | |
download | yawa-922137f64ae3f923cad45c1fa4af9502ed84e1a9.tar.xz |
Move parse_color to utils.c
-rw-r--r-- | src/utils.c | 46 | ||||
-rw-r--r-- | src/utils.h | 1 | ||||
-rw-r--r-- | src/yawa.c | 46 | ||||
-rw-r--r-- | src/yawa.h | 1 |
4 files changed, 47 insertions, 47 deletions
diff --git a/src/utils.c b/src/utils.c index 2425576..29fdd65 100644 --- a/src/utils.c +++ b/src/utils.c @@ -32,3 +32,49 @@ parse_int(char *string, char *arg) } return (int)val; } + +bool +parse_color (char *hex, Color *c, int a) +{ + if ((strlen(hex) != 7) && (strlen(hex) != 9)) + return false; + + int len; + if (strlen(hex) == 9) { + len = 4; + } else { + len = 3; + } + + hex++; + int colors[4]; + for (int i = 0; i < len; hex += 2, i++) { + char color[3]; + strlcpy(color, hex, 3); + + char *endptr; + errno = 0; + long val = strtol(color, &endptr, 16); + if (errno != 0) { + perror("strtol"); + exit(-2); + } + if (endptr == color) { + fprintf(stderr, "No valid hex color found\n"); + exit(-2); + } + + colors[i] = (int)val; + } + + c->r = colors[0]; + c->g = colors[1]; + c->b = colors[2]; + if (len == 4) { + c->a = colors[3]; + } else { + c->a = a; + } + + return true; +} diff --git a/src/utils.h b/src/utils.h index 25e51ee..1e50975 100644 --- a/src/utils.h +++ b/src/utils.h @@ -3,5 +3,6 @@ #include <stdbool.h> int parse_int(char *string, char *arg); +bool parse_color(char *arg, Color *c, int a); #endif @@ -199,52 +199,6 @@ set_root_atoms (Pixmap pixmap) return 1; } -bool -parse_color (char *hex, Color *c, int a) -{ - if ((strlen(hex) != 7) && (strlen(hex) != 9)) - return false; - - int len; - if (strlen(hex) == 9) { - len = 4; - } else { - len = 3; - } - - hex++; - int colors[4]; - for (int i = 0; i < len; hex += 2, i++) { - char color[3]; - strlcpy(color, hex, 3); - - char *endptr; - errno = 0; - long val = strtol(color, &endptr, 16); - if (errno != 0) { - perror("strtol"); - exit(-2); - } - if (endptr == color) { - fprintf(stderr, "No valid hex color found\n"); - exit(-2); - } - - colors[i] = (int)val; - } - - c->r = colors[0]; - c->g = colors[1]; - c->b = colors[2]; - if (len == 4) { - c->a = colors[3]; - } else { - c->a = a; - } - - return true; -} - int load_image (ImageMode mode, const char *arg, int rootW, int rootH, int alpha, Imlib_Image rootimg) @@ -16,7 +16,6 @@ typedef enum } ImageMode; int set_root_atoms(Pixmap pixmap); -bool parse_color (char *arg, Color *c, int a); int load_image(ImageMode mode, const char *arg, int rootW, int rootH, int alpha, Imlib_Image rootimg); |