aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2022-07-27 02:28:07 +0200
committerMattias Andrée <maandree@kth.se>2022-07-27 02:28:07 +0200
commitf0058b966ecf90070168c5b74a73ca2b2ff3e65a (patch)
tree89b22c89fe9dc7333e75dfe215440b8eb01ff1e7
parentImprove documentation and add LIBGAMEPAD_CONTROLLER_LINUX_4_12_RECTIFIED_3BTN (diff)
downloadlibgamepad-f0058b966ecf90070168c5b74a73ca2b2ff3e65a.tar.gz
libgamepad-f0058b966ecf90070168c5b74a73ca2b2ff3e65a.tar.bz2
libgamepad-f0058b966ecf90070168c5b74a73ca2b2ff3e65a.tar.xz
Fix button and axis names
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--Makefile6
-rw-r--r--TODO1
-rw-r--r--config.mk2
-rwxr-xr-xnames.sh33
4 files changed, 26 insertions, 16 deletions
diff --git a/Makefile b/Makefile
index 910c1c2..b177653 100644
--- a/Makefile
+++ b/Makefile
@@ -88,13 +88,13 @@ libgamepad_absolute_axis_names__.o: absolute-axis.names
libgamepad_relative_axis_names__.o: relative-axis.names
button.names: names.sh
- printf '%s\n' '#include <linux/input.h>' | $(CPP) -dM | ./names.sh BTN KEY > $@
+ ./names.sh '0x%03X' BTN KEY < $(INPUT_EVENT_CODES_H) > $@
absolute-axis.names: names.sh
- printf '%s\n' '#include <linux/input.h>' | $(CPP) -dM | ./names.sh ABS > $@
+ ./names.sh '0x%02X' ABS < $(INPUT_EVENT_CODES_H) > $@
relative-axis.names: names.sh
- printf '%s\n' '#include <linux/input.h>' | $(CPP) -dM | ./names.sh REL > $@
+ ./names.sh '0x%02X' REL < $(INPUT_EVENT_CODES_H) > $@
.names.count:
wc -l < $< > $@
diff --git a/TODO b/TODO
index f58da4e..8cd3c2a 100644
--- a/TODO
+++ b/TODO
@@ -7,4 +7,3 @@ Add support for creating instance from a file descriptor
Add man pages
Add readme file
Add force feedback tests
-Generic ABS and REL names shall be in "0x%02X" format
diff --git a/config.mk b/config.mk
index 34f4a3c..8453750 100644
--- a/config.mk
+++ b/config.mk
@@ -10,3 +10,5 @@ LDFLAGS =
LIBS_CFLAGS = $$(pkg-config --cflags libevdev)
LIBS_LDFLAGS = $$(pkg-config --libs libevdev) -ludev -lm
+
+INPUT_EVENT_CODES_H = /usr/include/linux/input-event-codes.h
diff --git a/names.sh b/names.sh
index 40ed998..a4d1eed 100755
--- a/names.sh
+++ b/names.sh
@@ -1,24 +1,33 @@
-#!/bin/sh
+#!/bin/sh -e
+
+format="$1"
+shift 1
prefix="$(printf '%s\\|' "$@" | sed 's/..$//')"
definitions_with_max="$(sed -n 's/^\s*#\s*define\s\+\(\('"$prefix"'\)_[A-Za-z0-9_]*\)\s\+\(0[xX][0-9A-Fa-f]\+\|[0-9]\+\)\(.*\)$/\3 \1/p')"
-definitions="$(echo "$definitions_with_max" | sed '/ \('"$prefix"'\)_MAX$/d')"
-max=$(printf '%u\n' $(echo "$definitions_with_max" | sed -n 's/^\(.*\) \('"$prefix"'\)_MAX$/\1/p'))
+definitions="$(printf '%s\n' "$definitions_with_max" | sed '/ \('"$prefix"'\)_MAX$/d')"
+max=$(printf '%u\n' $(printf '%s\n' "$definitions_with_max" | sed -n 's/^\(.*\) \('"$prefix"'\)_MAX$/\1/p'))
+
+nonunique="$(printf '%s\n' "$definitions" | while read num name; do printf '0x%08X\n' $num; done | sort | uniq -d)"
-nonunique="$(echo "$definitions" | while read num name; do printf '0x%03X\n' $num; done | sort | uniq -d)"
+printf '%s\n' "$definitions" |
+while read line; do
+ printf '0x%08X %s\n' $line
+done |
+(
+ prefixed="$(cat)"
-(echo "$definitions" |
- while read line; do
- printf '0x%03X %s\n' $line
- done |
- sed '/^\('"$(echo "$nonunique" | tr '\n' '|' | sed 's/|$/\n/' | sed 's/|/\\|/g')"'\) /d'
+ printf '%s\n' "$prefixed" |
+ sed '/^\('"$(printf '%s\\|' $nonunique | sed 's/..$/\n/')"'abcdef\) /d'
last_num=x
last_name=x
+ printf '%s\n' "$prefixed" |
+ sed -n 's/^\('"$(printf '%s\\|' $nonunique | sed 's/..$/\n/')"'\) .*$/&/p' |
while read num name; do
- num=$(printf '0x%03X\n' $num)
+ num=$(printf '0x%08X\n' $num)
if ! test $last_num = $num && ! test $last_num = x; then
printf '%s %s\n' $last_num $last_name
fi
@@ -38,7 +47,7 @@ awk '
BEGIN {num = 0}
{
while ($2 != num) {
- printf "\"0x%03X\",\n", num
+ printf "\"'"$format"'\",\n", num
num += 1
}
printf "\"%s\",\n", $1
@@ -46,7 +55,7 @@ BEGIN {num = 0}
}
END {
while (num <= '"$max"') {
- printf "\"0x%03X\",\n", num
+ printf "\"'"$format"'\",\n", num
num += 1
}
}' |