diff options
| author | Louis Burda <quent.burda@gmail.com> | 2022-10-20 18:26:57 +0200 |
|---|---|---|
| committer | Louis Burda <quent.burda@gmail.com> | 2022-10-20 18:26:57 +0200 |
| commit | f85b9e1a2b333ecae9bc4d3417c8d7c7dc5df89e (patch) | |
| tree | 905754fc08c2b93e485cea6a70d4364d3e9c0203 | |
| parent | d3b3c3e306219a25b209a06bc8fe519bb7e5c7f3 (diff) | |
| download | xsnip-f85b9e1a2b333ecae9bc4d3417c8d7c7dc5df89e.tar.gz xsnip-f85b9e1a2b333ecae9bc4d3417c8d7c7dc5df89e.zip | |
Add delay option
| -rw-r--r-- | main.c | 56 |
1 files changed, 36 insertions, 20 deletions
@@ -4,6 +4,8 @@ #include <X11/keysym.h> #include <X11/cursorfont.h> +#include <unistd.h> +#include <err.h> #include <stdio.h> #include <stdlib.h> #include <stdarg.h> @@ -12,24 +14,15 @@ #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MAX(a, b) ((a) >= (b) ? (a) : (b)) -const char *filename; -XWindowAttributes scr; -Display *display; -Window root, win; -int rx, ry, rw, rh; -GC gc; +static const char usage[] = "dsnip [-h] [-d DELAY] OUTFILE"; -void -die(const char *fmt, ...) -{ - va_list ap; +static const char *filename; - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); - - exit(1); -} +static XWindowAttributes scr; +static Display *display; +static Window root, win; +static int rx, ry, rw, rh; +static GC gc; void update(int x1, int y1, int x2, int y2) @@ -151,12 +144,35 @@ capture(void) } int -main(int argc, const char **argv) +main(int argc, char **argv) { - if (argc != 2) - die("USAGE: dsnip OUTFILE\n"); + char **arg, *end; + int delay; + + delay = 0; + filename = NULL; + for (arg = &argv[1]; *arg; arg++) { + if (!strcmp(*arg, "-d")) { + delay = strtol(*(++arg), &end, 10); + if (end && *end || delay <= 0) + errx(1, "Invalid delay"); + } else if (!strcmp(*arg, "-h")) { + printf("Usage: %s\n", usage); + return 0; + } else if (!filename) { + filename = *arg; + } else { + fprintf(stderr, "Usage: %s\n", usage); + return 1; + } + } + + if (!filename) { + fprintf(stderr, "USAGE: %s\n", usage); + return 1; + } - filename = argv[1]; + if (delay) sleep(delay); init(); |
