aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohannes Löthberg <johannes@kyriasis.com>2014-11-11 01:35:00 +0100
committerJohannes Löthberg <johannes@kyriasis.com>2014-11-11 01:35:00 +0100
commitaf0d7f5ab90341f353d3632ee25e70e08ded0d69 (patch)
treeb3bb7e54e1b7f5a4a5217339ceeaec67d5733f80
parentb4c780ac731398b5ebeb04b95f763c9e08b814c2 (diff)
downloadyawa-af0d7f5ab90341f353d3632ee25e70e08ded0d69.tar.xz
Add parse_double function to utils.c
-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);