-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathevent2str.inc.sh
146 lines (113 loc) · 3.07 KB
/
event2str.inc.sh
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env bash
# Copyright (c) 2005-2010 Nikolai Kondrashov
#
# This file is part of evdev-dump.
#
# Evdev-dump is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Evdev-dump is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with evdev-dump; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
set -e
UNKNOWN_STR="<UNKNOWN>"
IGNORE_TYPE_REGEXP="(VERSION|MAX)"
IGNORE_CODE_REGEXP="MAX"
function get_type_synonym_regexp() {
local code=$1
if [ "$code" == "KEY" ]; then
echo "(KEY|BTN)"
else
echo "$code"
fi
}
function print_code_case() {
local code=$1
cat <<CUT
case ${code}:
*pcode_str = "${code}";
break;
CUT
}
function print_type_case() {
local INPUT_H=$1
local type=$2
local type_synonym_regexp=`get_type_synonym_regexp ${type}`
local code
cat <<CUT
case EV_$type:
*ptype_str = "EV_$type";
switch (e->code)
{
CUT
cat $INPUT_H |
egrep "^#define ${type_synonym_regexp}_" |
cut -d' ' -f2- |
egrep -v "^${type_synonym_regexp}_$IGNORE_CODE_REGEXP" |
gawk --non-decimal-data '{printf "%s\t%d\n", $1, $2}' |
sort --key=2 --numeric-sort --uniq | # remove duplicated code entries
cut -f1 |
while read code; do
cat <<CUT
MAP($code);
CUT
done
cat <<CUT
default:
*pcode_str = NULL;
break;
} /* switch (e->code) */
break; /* EV_$type */
CUT
}
function print_event2str() {
local INPUT_H=$1
local type
cat <<CUT
static void
event2str(const struct input_event *e,
const char **ptype_str,
const char **pcode_str)
{
#define MAP(_name) \\
case _name: \\
*pcode_str = #_name; \\
break
switch (e->type)
{
CUT
cat $INPUT_H |
egrep '^#define EV_' |
cut -d_ -f2- |
egrep -v "^$IGNORE_TYPE_REGEXP" |
gawk --non-decimal-data '{printf "%s\t%d\n", $1, $2}' |
sort --key=2 --numeric-sort --uniq | # remove duplicated code entries
cut -f1 |
while read type; do
print_type_case "$INPUT_H" "$type"
done
cat <<CUT
default:
*ptype_str = NULL;
*pcode_str = NULL;
break;
} /* switch (e->type) */
#undef MAP
}
CUT
}
cat <<CUT
/*
* vim:nomodifiable
* DO NOT EDIT
* This file is generated automatically by ${0##*/}.
*/
CUT
print_event2str $1