aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/utils.c24
-rw-r--r--src/utils.h1
-rw-r--r--src/yawa.c12
-rw-r--r--src/yawa.h12
4 files changed, 37 insertions, 12 deletions
diff --git a/src/utils.c b/src/utils.c
index 20cc6d4..0441ba2 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -33,6 +33,30 @@ parse_int(char *string, char *arg)
return (int)val;
}
+unsigned int
+parse_uint(char *string, char *arg)
+{
+ errno = 0;
+ char *endptr;
+ unsigned long val = strtoul(string, &endptr, 10);
+ if (errno != 0)
+ {
+ char *errormsg;
+ asprintf(&errormsg, "parse_uint: 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 (unsigned int)val;
+}
+
bool
parse_color(char *hex, Color *c, int a)
{
diff --git a/src/utils.h b/src/utils.h
index 1e50975..ae9612e 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -3,6 +3,7 @@
#include <stdbool.h>
int parse_int(char *string, char *arg);
+unsigned int parse_uint(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 a7978cf..dce73d7 100644
--- a/src/yawa.c
+++ b/src/yawa.c
@@ -90,27 +90,27 @@ parse_opt(int key, char *arg, struct argp_state *state)
case 'b':
arguments->blur = true;
- arguments->blur_radius = parse_int(arg, "blur radius");
+ arguments->blur_radius = parse_uint(arg, "blur radius");
break;
case 'S':
arguments->sharpen = true;
- arguments->sharpen_radius = parse_int(arg, "sharpen radius");
+ arguments->sharpen_radius = parse_uint(arg, "sharpen radius");
break;
case 'o':
arguments->contrast = true;
- arguments->contrast_amount = parse_int(arg, "contrast amount");
+ arguments->contrast_amount = parse_uint(arg, "contrast amount");
break;
case 'B':
arguments->brightness = true;
- arguments->brightness_amount = parse_int(arg, "brightness amount");
+ arguments->brightness_amount = parse_uint(arg, "brightness amount");
break;
case 'G':
arguments->gamma = true;
- arguments->gamma_amount = parse_int(arg, "gamma amount");
+ arguments->gamma_amount = parse_uint(arg, "gamma amount");
break;
case 'v':
@@ -128,7 +128,7 @@ parse_opt(int key, char *arg, struct argp_state *state)
case 'A':
arguments->alpha = true;
- arguments->alpha_amount = parse_int(arg, "alpha amount");
+ arguments->alpha_amount = parse_uint(arg, "alpha amount");
break;
case 'w':
diff --git a/src/yawa.h b/src/yawa.h
index 8c86fe0..60d3ee8 100644
--- a/src/yawa.h
+++ b/src/yawa.h
@@ -29,12 +29,12 @@ struct arguments {
char *tint_color;
int angle;
- int blur_radius;
- int sharpen_radius;
- int contrast_amount;
- int brightness_amount;
- int gamma_amount;
- int alpha_amount;
+ unsigned int blur_radius;
+ unsigned int sharpen_radius;
+ unsigned int contrast_amount;
+ unsigned int brightness_amount;
+ unsigned int gamma_amount;
+ unsigned int alpha_amount;
bool add: 1;
bool gradient: 1;