summaryrefslogtreecommitdiff
path: root/tools/generate-input-keycodes.sh
blob: 51d09e837c7051063d2558963468ef2679157d56 (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
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;
	void *cairo_surface;
};

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