aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c22
1 files changed, 22 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)
{