linput

Listen to input events
git clone git://git.akobets.xyz/linput
Log | Files | Refs | README | LICENSE

commit bf8c4e403a2b0bd3beee2002ee68fe55bb4a4634
parent babe0967e0381a0db6f9e4c25d63ea818673b435
Author: Artem Kobets <artem@akobets.xyz>
Date:   Mon, 20 Apr 2020 13:37:05 +0300

remove arg.h

Diffstat:
Darg.h | 49-------------------------------------------------
Mlinput.c | 30+++++++++++-------------------
2 files changed, 11 insertions(+), 68 deletions(-)

diff --git a/arg.h b/arg.h @@ -1,49 +0,0 @@ -/* - * Copy me if you can. - * by 20h - */ - -#ifndef ARG_H__ -#define ARG_H__ - -extern char *argv0; - -/* use main(int argc, char *argv[]) */ -#define ARGBEGIN for (argv0 = *argv, argv++, argc--;\ - argv[0] && argv[0][1]\ - && argv[0][0] == '-';\ - argc--, argv++) {\ - char argc_;\ - char **argv_;\ - int brk_;\ - if (argv[0][1] == '-' && argv[0][2] == '\0') {\ - argv++;\ - argc--;\ - break;\ - }\ - for (brk_ = 0, argv[0]++, argv_ = argv;\ - argv[0][0] && !brk_;\ - argv[0]++) {\ - if (argv_ != argv)\ - break;\ - argc_ = argv[0][0];\ - switch (argc_) - -#define ARGEND }\ - } - -#define ARGC() argc_ - -#define EARGF(x) ((argv[0][1] == '\0' && argv[1] == NULL)?\ - ((x), abort(), (char *)0) :\ - (brk_ = 1, (argv[0][1] != '\0')?\ - (&argv[0][1]) :\ - (argc--, argv++, argv[0]))) - -#define ARGF() ((argv[0][1] == '\0' && argv[1] == NULL)?\ - (char *)0 :\ - (brk_ = 1, (argv[0][1] != '\0')?\ - (&argv[0][1]) :\ - (argc--, argv++, argv[0]))) - -#endif diff --git a/linput.c b/linput.c @@ -13,7 +13,6 @@ #include <sys/wait.h> #include <unistd.h> -#include "arg.h" #include "config.h" #define LENGTH(x) (sizeof(x) / sizeof(x[0])) @@ -45,9 +44,7 @@ static void handle_inotify(int fd); static void sigchld(int unused); static void die(const char *fmt, ...); -static void usage(); -char *argv0; static int key_state[KEY_CNT] = { 0 }; static fd_node *fd_head = NULL; static int inotify_fd = -1; @@ -485,13 +482,6 @@ die(const char *fmt, ...) exit(EXIT_FAILURE); } -void -usage() -{ - die("usage: %s [-v]\n", argv0); -} - - int main(int argc, char **argv) { @@ -499,15 +489,11 @@ main(int argc, char **argv) sigset_t sigmask; int res; - ARGBEGIN { - case 'v': - puts("linput "VERSION); - exit(EXIT_FAILURE); - break; - default: - usage(); - break; - } ARGEND + if (argc == 2 && strcmp("-v", argv[1]) == 0) { + printf("linput %s\n", VERSION); + exit(EXIT_SUCCESS); + } else if (argc != 1) + die("usage: linput [-v]\n"); act.sa_handler = sigchld; sigemptyset(&sigmask); @@ -519,6 +505,7 @@ main(int argc, char **argv) init_inotify(); generate_poll_array(); + /* loop infinitely, reading input events */ while ( (res = poll(pfds, nfds, -1)) > 0 || (res == -1 && errno == EINTR) @@ -545,4 +532,9 @@ main(int argc, char **argv) if (poll_change) generate_poll_array(); } + + if (res == -1) + die("poll: %s\n", strerror(errno)); + + die("poll: unexpected error\n"); }