summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2011-02-10 08:27:35 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2011-02-10 09:33:18 +1000
commit7c03a3f5f113fb202dd6999edceaa2b5580cc134 (patch)
tree395abbd1d491807d779bd51b65ea21bce171f55d
parent2416568475cc47eb9ca3a0175904382cb75a9ecc (diff)
Factor out printing device info and device events.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r--evtest.c65
1 files changed, 45 insertions, 20 deletions
diff --git a/evtest.c b/evtest.c
index 9a9abac..3af6f66 100644
--- a/evtest.c
+++ b/evtest.c
@@ -502,29 +502,19 @@ static char* parse_args(int argc, char **argv)
return filename;
}
-
-int main (int argc, char **argv)
+/**
+ * Print static device information (no events).
+ *
+ * Returns 0 on success or 1 otherwise.
+ */
+static int print_device_info(int fd)
{
- int fd, rd, i, j, k;
- struct input_event ev[64];
+ int i, j, k;
int version;
unsigned short id[4];
- unsigned long bit[EV_MAX][NBITS(KEY_MAX)];
- char name[256] = "Unknown";
int abs[6] = {0};
- char *filename;
-
- filename = parse_args(argc, argv);
-
- if (!filename)
- return 1;
-
- if ((fd = open(filename, O_RDONLY)) < 0) {
- perror("evtest");
- return 1;
- }
-
- free(filename);
+ char name[256] = "Unknown";
+ unsigned long bit[EV_MAX][NBITS(KEY_MAX)];
if (ioctl(fd, EVIOCGVERSION, &version)) {
perror("evtest: can't get version");
@@ -562,8 +552,18 @@ int main (int argc, char **argv)
}
}
+ return 0;
+}
- printf("Testing ... (interrupt to exit)\n");
+/**
+ * Print device events.
+ *
+ * Returns 0 on success or 1 otherwise.
+ */
+static int print_events(int fd)
+{
+ struct input_event ev[64];
+ int i, rd;
while (1) {
rd = read(fd, ev, sizeof(struct input_event) * 64);
@@ -597,3 +597,28 @@ int main (int argc, char **argv)
}
}
+
+int main (int argc, char **argv)
+{
+ int fd;
+ char *filename;
+
+ filename = parse_args(argc, argv);
+
+ if (!filename)
+ return 1;
+
+ if ((fd = open(filename, O_RDONLY)) < 0) {
+ perror("evtest");
+ return 1;
+ }
+
+ free(filename);
+
+ if (print_device_info(fd))
+ return 1;
+
+ printf("Testing ... (interrupt to exit)\n");
+
+ return print_events(fd);
+}