aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorDmitrij D. Czarkoff <czarkoff@gmail.com>2016-10-23 03:32:58 +0200
committerDmitrij D. Czarkoff <czarkoff@gmail.com>2016-10-23 03:32:58 +0200
commitdf6393be75b8b09184426269135e031bda0e8621 (patch)
tree49fc9d94fcab88aec5ac313d4cc07688c4b8ae6f /src/main.c
parente59d0e9e120f1dbde9ab068748a190e93978e5b7 (diff)
downloadimv-df6393be75b8b09184426269135e031bda0e8621.tar.gz
Simplify hex color parser
It is actually a trivial task for strtoul + some bit shifting, so there is no need for two separate functions.
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/main.c b/src/main.c
index 2671a21..21fbc77 100644
--- a/src/main.c
+++ b/src/main.c
@@ -103,7 +103,7 @@ static void parse_args(int argc, char** argv)
/* Do not print getopt errors */
opterr = 0;
- char *argp, o;
+ char *argp, *ep = *argv, o;
while((o = getopt(argc, argv, "firasSudxhln:b:e:t:")) != -1) {
switch(o) {
@@ -129,11 +129,15 @@ static void parse_args(int argc, char** argv)
g_options.solid_bg = 0;
} else {
g_options.solid_bg = 1;
- if(parse_hex_color(optarg,
- &g_options.bg_r, &g_options.bg_g, &g_options.bg_b) != 0) {
+ argp = (*optarg == '#') ? optarg + 1 : optarg;
+ uint32_t n = strtoul(argp, &ep, 16);
+ if(*ep != '\0' || ep - argp != 6 || n > 0xFFFFFF) {
fprintf(stderr, "Invalid hex color: '%s'\n", optarg);
exit(1);
}
+ g_options.bg_b = n & 0xFF;
+ g_options.bg_g = (n >> 8) & 0xFF;
+ g_options.bg_r = (n >> 16);
}
break;
case 'e':
@@ -143,7 +147,6 @@ static void parse_args(int argc, char** argv)
g_options.delay = strtoul(optarg, &argp, 10);
g_options.delay *= 1000;
if (*argp == '.') {
- char *ep;
long delay = strtoul(++argp, &ep, 10);
for (int i = 3 - (ep - argp); i; i--) {
delay *= 10;