diff options
author | Mattias Andrée <maandree@kth.se> | 2022-07-26 16:01:13 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2022-07-26 16:02:05 +0200 |
commit | 9de0de4d3d32ab97226fa9868de1fa2290120429 (patch) | |
tree | 292473831841529716f97565391303fb9b071c15 /names.sh | |
parent | Update information about Sixaxis (diff) | |
download | libgamepad-9de0de4d3d32ab97226fa9868de1fa2290120429.tar.gz libgamepad-9de0de4d3d32ab97226fa9868de1fa2290120429.tar.bz2 libgamepad-9de0de4d3d32ab97226fa9868de1fa2290120429.tar.xz |
Do not relay on libevdev for button/axis names, an prepare for device specific names, and add reverse lookup functions
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'names.sh')
-rwxr-xr-x | names.sh | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/names.sh b/names.sh new file mode 100755 index 0000000..40ed998 --- /dev/null +++ b/names.sh @@ -0,0 +1,53 @@ +#!/bin/sh + +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')) + +nonunique="$(echo "$definitions" | while read num name; do printf '0x%03X\n' $num; done | sort | uniq -d)" + +(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' + + last_num=x + last_name=x + while read num name; do + num=$(printf '0x%03X\n' $num) + if ! test $last_num = $num && ! test $last_num = x; then + printf '%s %s\n' $last_num $last_name + fi + last_num=$num + last_name=$name + done + if ! test $last_num = x; then + printf '%s %s\n' $last_num $last_name + fi +) | +sort | +while read num name; do + printf '%s %u\n' $name $num; +done | +uniq -f 1 | +awk ' +BEGIN {num = 0} +{ + while ($2 != num) { + printf "\"0x%03X\",\n", num + num += 1 + } + printf "\"%s\",\n", $1 + num += 1 +} +END { + while (num <= '"$max"') { + printf "\"0x%03X\",\n", num + num += 1 + } +}' | +sed '$s/,$//' |