1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include "input.h"
/* ------------------------------------------------------------------ */
static void list_devices(int devnr, int 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)
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[])
{
int verbose = 0;
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++;
break;
case 'h':
usage(argv[0],0);
default:
usage(argv[0],1);
}
}
list_devices(devnr, verbose);
exit(0);
}
/* ---------------------------------------------------------------------
* Local variables:
* c-basic-offset: 8
* End:
*/
|