aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/utils.c46
-rw-r--r--src/utils.h1
-rw-r--r--src/yawa.c46
-rw-r--r--src/yawa.h1
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
diff --git a/src/yawa.c b/src/yawa.c
index 4d783a5..d585465 100644
--- a/src/yawa.c
+++ b/src/yawa.c
@@ -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)
diff --git a/src/yawa.h b/src/yawa.h
index 7d4a1e7..297512c 100644
--- a/src/yawa.h
+++ b/src/yawa.h
@@ -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);