From 293adde407f0adfc9546fdbe3169f617f28771b7 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Wed, 9 Apr 2014 17:36:09 +0200 Subject: lsinput overhaul --- lsinput.c | 52 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 10 deletions(-) (limited to 'lsinput.c') diff --git a/lsinput.c b/lsinput.c index b500d03..efe95cb 100644 --- a/lsinput.c +++ b/lsinput.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -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 ]\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); } -- cgit