aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/utils.c22
-rw-r--r--src/utils.h3
2 files changed, 25 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c
index d515b69..19d249d 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -53,6 +53,28 @@ parse_uint(char *string, char *arg)
return (unsigned int)val;
}
+double
+parse_double(char *string, char *arg)
+{
+ errno = 0;
+ char *endptr;
+ double val = strtod(string, &endptr);
+ if (errno != 0) {
+ char *errormsg;
+ asprintf(&errormsg, "parse_double: failed to parse %s", arg);
+
+ perror(errormsg);
+ free(errormsg);
+ exit(-2);
+ }
+
+ if (endptr == string) {
+ fprintf(stderr, "Valid %s not found\n", arg);
+ exit(-2);
+ }
+ return val;
+}
+
bool
parse_color(char *hex, Color *c, int a)
{
diff --git a/src/utils.h b/src/utils.h
index 50703b0..b21c6d5 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -10,6 +10,9 @@ parse_int(char *string, char *arg);
unsigned
parse_uint(char *string, char *arg);
+double
+parse_double(char *string, char *arg);
+
bool
parse_color(char *arg, Color *c, int a);