-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgenerate_keymap.awk
More file actions
executable file
·57 lines (47 loc) · 1.38 KB
/
Copy pathgenerate_keymap.awk
File metadata and controls
executable file
·57 lines (47 loc) · 1.38 KB
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
#!/usr/bin/awk -f
BEGIN {
first_entry = -1;
print "/* THIS FILE IS GENERATED. DO NOT EDIT! */\n"
print "#include <stdint.h>\n"
print "uint16_t lookup_keycode(uint16_t keycode) {"
}
/^\s*[0-9]+\s+[0-9]+\s*$/ {
if (first_entry == -1) {
print " static const uint16_t keymap[] = {"
printf(" %d\n", $2);
first_entry = $1;
previous_entry = first_entry;
next;
}
if (previous_entry + 1 == $1) {
printf(" , %d\n", $2);
previous_entry = $1;
next;
}
for (i = previous_entry + 1; i < $1; i++) {
printf(" , %d\n", i);
}
printf(" , %d\n", $2);
previous_entry = $1;
}
# Fail for lines not matching the above or empty pattern
!/^\s*[0-9]+\s+[0-9]+\s*$|^\s*$/ {
printf("Bad pattern: '%s'\n", $0) > "/dev/stderr";
exit(1);
}
END {
if (first_entry == -1) {
print " return keycode;"
print "}"
exit 0;
}
print " };"
printf(" static const size_t keymap_start = %d;\n", first_entry);
printf(" static const size_t keymap_end = %d +\n", first_entry);
print " sizeof(keymap) / sizeof(keymap[0]);\n"
print " if (keycode >= keymap_start && keycode < keymap_end) {"
print " return keymap[keycode - keymap_start];"
print " }\n"
print " return keycode;"
print "}"
}