diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2014-04-09 17:36:09 +0200 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2014-04-09 17:36:09 +0200 |
commit | 293adde407f0adfc9546fdbe3169f617f28771b7 (patch) | |
tree | 5722ddf12d0a52aa728dc70eec80eceab0da0a28 /lsinput.c | |
parent | 3481f7bc531a2010c7e83940b6ed1f1b5b6e8b6f (diff) | |
download | input-293adde407f0adfc9546fdbe3169f617f28771b7.tar.gz |
lsinput overhaul
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); } |