[PATCH v2 evemu 13/13] Call write_event_desc from evemu_write_event

Peter Hutterer peter.hutterer at who-t.net
Sun Aug 3 21:38:13 PDT 2014


This was exported API and we're now changing the behavior here:
- adding a human-readable comment for each event. technically the output of
  evemu_write_event isn't compatible with evemu 1.0 output anymore now
- a newline character is now appended to the output

I don't expect either to be an issue though.

The return value of evemu_write_event is just documented as "Returns a
positive number if successful, zero or negative error otherwise." but just in
case someone was using the return value as the length of the printed string
keep that behavior.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
Changes to v1:
- new patch

The only reference to evemu_write_event() I could find was in ChromeOS
https://chromium.googlesource.com/chromiumos/platform/touchpad-tests/+/factory-2717.B/replay/src/evemu_device.cc
and that won't be affected. if anything, that code would've broken with
a7c35392c9e1438d587e468157660b79867e42e7 (dropping the \n at the events) and
should now be working again.

 src/evemu.c | 35 ++++++++++++++++++++---------------
 1 file changed, 20 insertions(+), 15 deletions(-)

diff --git a/src/evemu.c b/src/evemu.c
index a0a3038..aae1913 100644
--- a/src/evemu.c
+++ b/src/evemu.c
@@ -586,30 +586,36 @@ out:
 	return rc;
 }
 
-static void write_event_desc(FILE *fp, const struct input_event *ev)
+static int write_event_desc(FILE *fp, const struct input_event *ev)
 {
+	int rc;
+
 	if (ev->type == EV_SYN) {
 		if (ev->code == SYN_MT_REPORT)
-			fprintf(fp, "# ++++++++++++ %s (%d) ++++++++++\n",
-				libevdev_event_code_get_name(ev->type, ev->code),
-				ev->value);
+			rc = fprintf(fp, "# ++++++++++++ %s (%d) ++++++++++\n",
+				     libevdev_event_code_get_name(ev->type, ev->code),
+				     ev->value);
 		else
-			fprintf(fp, "# ------------ %s (%d) ----------\n",
-				libevdev_event_code_get_name(ev->type, ev->code),
-				ev->value);
+			rc = fprintf(fp, "# ------------ %s (%d) ----------\n",
+				     libevdev_event_code_get_name(ev->type, ev->code),
+				     ev->value);
 	} else {
-		fprintf(fp, "# %s / %-20s %d\n",
-			libevdev_event_type_get_name(ev->type),
-			libevdev_event_code_get_name(ev->type, ev->code),
-			ev->value);
+		rc = fprintf(fp, "# %s / %-20s %d\n",
+			     libevdev_event_type_get_name(ev->type),
+			     libevdev_event_code_get_name(ev->type, ev->code),
+			     ev->value);
 	}
+	return rc;
 }
 
 int evemu_write_event(FILE *fp, const struct input_event *ev)
 {
-	return fprintf(fp, "E: %lu.%06u %04x %04x %04d	",
-		       ev->time.tv_sec, (unsigned)ev->time.tv_usec,
-		       ev->type, ev->code, ev->value);
+	int rc;
+	rc = fprintf(fp, "E: %lu.%06u %04x %04x %04d	",
+		     ev->time.tv_sec, (unsigned)ev->time.tv_usec,
+		     ev->type, ev->code, ev->value);
+	rc += write_event_desc(fp, ev);
+	return rc;
 }
 
 static inline long time_to_long(const struct timeval *tv) {
@@ -643,7 +649,6 @@ int evemu_record(FILE *fp, int fd, int ms)
 			time = time_to_long(&ev.time);
 			ev.time = long_to_time(time - offset);
 			evemu_write_event(fp, &ev);
-			write_event_desc(fp, &ev);
 			fflush(fp);
 		}
 	}
-- 
1.9.3



More information about the Input-tools mailing list