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
1=== modified file 'README'
2--- README 2011-01-05 10:17:01 +0000
3+++ README 2012-06-05 01:29:18 +0000
4@@ -10,15 +10,17 @@
5 and one for the device event data. hex data is without a 0x prefix.
6
7 Device Description Format:
8+ # comments are allowed at the top of the file only
9+ # Only lines with # as first character are regonized
10 N: <device name>
11 I: <bustype (hex)> <vendor (hex)> <product (hex)> <version (hex)>
12- # for each kernel property (2.3.38 only)
13+ --- for each kernel property (2.3.38 only) ---
14 P: <byte 0 (hex)> <byte 1 (hex)> ... <byte 7 (hex)>
15 P: <byte 8 (hex)> ...
16- # for each index from 0 to EV_CNT
17+ --- for each index from 0 to EV_CNT ---
18 B: <index (hex)> <byte 0 (hex)> <byte 1 (hex)> ... <byte 7 (hex)>
19 B: <index (hex)> <byte 8 (hex)> ...
20- # for each absolute axis
21+ --- for each absolute axis ---
22 A: <index (hex)> <min> <max> <fuzz> <flat>
23
24
25
26=== modified file 'src/evemu.c'
27--- src/evemu.c 2012-03-23 15:38:02 +0000
28+++ src/evemu.c 2012-06-05 01:29:18 +0000
29@@ -62,6 +62,19 @@
30
31 #define SYSCALL(call) while (((call) == -1) && (errno == EINTR))
32
33+static void skip_comment_block(FILE *fp)
34+{
35+ int first_char;
36+
37+ while ((first_char = getc(fp)) == '#') {
38+ char *line = NULL;
39+ size_t n = 0;
40+ getline(&line, &n, fp);
41+ free(line);
42+ }
43+ ungetc(first_char, fp);
44+}
45+
46 static void copy_bits(unsigned char *mask, const unsigned long *bits, int bytes)
47 {
48 int i;
49@@ -336,6 +349,8 @@
50
51 memset(dev, 0, sizeof(*dev));
52
53+ skip_comment_block(fp);
54+
55 ret = fscanf(fp, "N: %m[^\n]\n", &devname);
56 if (ret <= 0) {
57 if (devname != NULL)
58@@ -435,6 +450,8 @@
59 struct timeval evtime;
60 int ret;
61
62+ skip_comment_block(fp);
63+
64 memset(&evtime, 0, sizeof(evtime));
65 while (evemu_read_event_realtime(fp, &ev, &evtime) > 0)
66 SYSCALL(ret = write(fd, &ev, sizeof(ev)));

Subscribers

People subscribed via source and target branches