diff options
Diffstat (limited to 'tools')
| -rwxr-xr-x | tools/generate-input-keycodes.sh | 71 | 
1 files changed, 71 insertions, 0 deletions
diff --git a/tools/generate-input-keycodes.sh b/tools/generate-input-keycodes.sh new file mode 100755 index 0000000..96f28ff --- /dev/null +++ b/tools/generate-input-keycodes.sh @@ -0,0 +1,71 @@ +#!/bin/bash + +INPUT_HEADER="/usr/include/linux/input.h" +OUTPUT_ENUM="linux-input-enum.h" +OUTPUT_MAP="linux-input-keycodes.h" +SKIP="KEY_MIN_INTERESTING KEY_MAX KEY_CNT" + +if [ ! -e "$INPUT_HEADER" ]; then +	echo "Can't find input header: $INPUT_HEADER" >&2 +	exit 1 +fi + +cat > "$OUTPUT_ENUM" <<EOF +#ifndef foolinuxinputenumhfoo +#define foolinuximputenumhfoo + +/* AUTOGENERATED: DO NOT EDIT */ + +enum linux_input_keyval { +EOF + +cat > "$OUTPUT_MAP" <<EOF +#ifndef foolinuxinputkeycodesfoo +#define foolinuxinputkeycodesfoo + +/* AUTOGENERATED: DO NOT EDIT */ + +#include "$OUTPUT_ENUM" + +struct linux_input_keycode { +	const char *name; +	enum linux_input_keyval value; +	bool alias; +	GtkWidget *img; +}; + +struct linux_input_keycode linux_input_keycodes[] = { +EOF + +cat "$INPUT_HEADER" | grep "^#define[[:space:]]*KEY_" | while read DEF NAME VALUE COMMENTS; do +	for WORD in $SKIP; do +		if [ "$NAME" = "$WORD" ]; then +			continue +		fi +	done + +	if [ "${VALUE##KEY_}" != "$VALUE" ]; then +		ALIAS="true" +	else +		ALIAS="false" +	fi + +	echo "	$NAME = $VALUE," >> "$OUTPUT_ENUM" +	echo "	{ \"$NAME\",	$NAME,	$ALIAS,	NULL }," >> "$OUTPUT_MAP" +done + +cat >> "$OUTPUT_ENUM" << EOF +}; +#endif +EOF + +cat >> "$OUTPUT_MAP" << EOF +	{ NULL, 0, false, NULL } +}; +#endif +EOF + + +exit 0 + +  | 
