diff options
Diffstat (limited to 'lsinput.c')
-rw-r--r-- | lsinput.c | 52 |
1 files changed, 42 insertions, 10 deletions
@@ -1,5 +1,6 @@ #include <stdio.h> #include <stdlib.h> +#include <stdbool.h> #include <sys/stat.h> #include <unistd.h> #include <fcntl.h> @@ -8,29 +9,60 @@ /* ------------------------------------------------------------------ */ -static void list_devices(void) +static void list_devices(int devnr, bool verbose) { int i,fd; char filename[32]; struct stat statbuf; for (i = 0; i < 32; i++) { + if (devnr > 0 && devnr != i) + continue; snprintf(filename,sizeof(filename), "/dev/input/event%d",i); - if (stat(filename, &statbuf) == 0) { - /* try to open */ - fd = device_open(i,1); - if (-1 == fd) - return; - device_info(fd); - close(fd); - } + if (stat(filename, &statbuf) != 0) + continue; + fd = device_open(i, verbose); + if (-1 == fd) + continue; + device_info(i, fd, verbose); + close(fd); } return; } +static int usage(char *prog, int error) +{ + fprintf(error ? stderr : stdout, + "usage: %s" + " [ -v ] [ -s <devnr> ]\n", + prog); + exit(error); +} + int main(int argc, char *argv[]) { - list_devices(); + bool verbose = false; + int devnr = -1; + int c; + + for (;;) { + if (-1 == (c = getopt(argc, argv, "hvs:"))) + break; + switch (c) { + case 's': + devnr = atoi(optarg); + break; + case 'v': + verbose = true; + break; + case 'h': + usage(argv[0],0); + default: + usage(argv[0],1); + } + } + + list_devices(devnr, verbose); exit(0); } |