Merge lp:~peter-hutterer/evemu/comment-parsing into lp:evemu

Proposed by Peter Hutterer
Status: Merged
Merged at revision: 54
Proposed branch: lp:~peter-hutterer/evemu/comment-parsing
Merge into: lp:evemu
Diff against target: 66 lines (+22/-3)
2 files modified
README (+5/-3)
src/evemu.c (+17/-0)
To merge this branch: bzr merge lp:~peter-hutterer/evemu/comment-parsing
Reviewer Review Type Date Requested Status
Stephen M. Webb (community) Approve
Review via email: mp+108662@code.launchpad.net

Description of the change

Parse simple comments at the top of the file to allow for more extensive description of what data a file contain.s

To post a comment you must log in.
53. By Peter Hutterer

Add support for comment lines starting with '#'

Very basic parser, recognises comments at the top of the file, and only if
'#' is the first character of that line.

Revision history for this message
Stephen M. Webb (bregma) wrote :

Nice addition. Huzzah!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'README'
--- README 2011-01-05 10:17:01 +0000
+++ README 2012-06-05 01:29:18 +0000
@@ -10,15 +10,17 @@
10and one for the device event data. hex data is without a 0x prefix.10and one for the device event data. hex data is without a 0x prefix.
1111
12Device Description Format:12Device Description Format:
13 # comments are allowed at the top of the file only
14 # Only lines with # as first character are regonized
13 N: <device name>15 N: <device name>
14 I: <bustype (hex)> <vendor (hex)> <product (hex)> <version (hex)>16 I: <bustype (hex)> <vendor (hex)> <product (hex)> <version (hex)>
15 # for each kernel property (2.3.38 only)17 --- for each kernel property (2.3.38 only) ---
16 P: <byte 0 (hex)> <byte 1 (hex)> ... <byte 7 (hex)>18 P: <byte 0 (hex)> <byte 1 (hex)> ... <byte 7 (hex)>
17 P: <byte 8 (hex)> ...19 P: <byte 8 (hex)> ...
18 # for each index from 0 to EV_CNT20 --- for each index from 0 to EV_CNT ---
19 B: <index (hex)> <byte 0 (hex)> <byte 1 (hex)> ... <byte 7 (hex)>21 B: <index (hex)> <byte 0 (hex)> <byte 1 (hex)> ... <byte 7 (hex)>
20 B: <index (hex)> <byte 8 (hex)> ...22 B: <index (hex)> <byte 8 (hex)> ...
21 # for each absolute axis23 --- for each absolute axis ---
22 A: <index (hex)> <min> <max> <fuzz> <flat>24 A: <index (hex)> <min> <max> <fuzz> <flat>
2325
2426
2527
=== modified file 'src/evemu.c'
--- src/evemu.c 2012-03-23 15:38:02 +0000
+++ src/evemu.c 2012-06-05 01:29:18 +0000
@@ -62,6 +62,19 @@
6262
63#define SYSCALL(call) while (((call) == -1) && (errno == EINTR))63#define SYSCALL(call) while (((call) == -1) && (errno == EINTR))
6464
65static void skip_comment_block(FILE *fp)
66{
67 int first_char;
68
69 while ((first_char = getc(fp)) == '#') {
70 char *line = NULL;
71 size_t n = 0;
72 getline(&line, &n, fp);
73 free(line);
74 }
75 ungetc(first_char, fp);
76}
77
65static void copy_bits(unsigned char *mask, const unsigned long *bits, int bytes)78static void copy_bits(unsigned char *mask, const unsigned long *bits, int bytes)
66{79{
67 int i;80 int i;
@@ -336,6 +349,8 @@
336349
337 memset(dev, 0, sizeof(*dev));350 memset(dev, 0, sizeof(*dev));
338351
352 skip_comment_block(fp);
353
339 ret = fscanf(fp, "N: %m[^\n]\n", &devname);354 ret = fscanf(fp, "N: %m[^\n]\n", &devname);
340 if (ret <= 0) {355 if (ret <= 0) {
341 if (devname != NULL)356 if (devname != NULL)
@@ -435,6 +450,8 @@
435 struct timeval evtime;450 struct timeval evtime;
436 int ret;451 int ret;
437452
453 skip_comment_block(fp);
454
438 memset(&evtime, 0, sizeof(evtime));455 memset(&evtime, 0, sizeof(evtime));
439 while (evemu_read_event_realtime(fp, &ev, &evtime) > 0)456 while (evemu_read_event_realtime(fp, &ev, &evtime) > 0)
440 SYSCALL(ret = write(fd, &ev, sizeof(ev)));457 SYSCALL(ret = write(fd, &ev, sizeof(ev)));

Subscribers

People subscribed via source and target branches