Skip to content

Commit

Permalink
NCD: Fix evdev event code names with newer headers.
Browse files Browse the repository at this point in the history
Most of the event codes may be defined in another header file not directly in linux/input.h.
Also remove _MAX and _CNT codes.
  • Loading branch information
ambrop72 committed Aug 27, 2016
1 parent 64f30f5 commit 432f2ba
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
13 changes: 10 additions & 3 deletions ncd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,19 @@ if (BADVPN_USE_LINUX_INPUT)
message(FATAL_ERROR "failed to match preprocessor output for path of linux/input.h")
endif ()
set(LINUX_INPUT_H_PATH ${CMAKE_MATCH_1})

message(STATUS "Generating linux_input_names.h from ${LINUX_INPUT_H_PATH}")

string(REGEX MATCH "\"(/[^\"]+/linux/input-event-codes.h)\"" LINUX_INPUT_EVENT_CODES_MATCH ${LINUX_INPUT_PREPROCESS_OUTPUT})
if (NOT LINUX_INPUT_EVENT_CODES_MATCH)
set(LINUX_INPUT_EVENT_CODES_H_PATH)
else ()
set(LINUX_INPUT_EVENT_CODES_H_PATH ${CMAKE_MATCH_1})
endif ()

message(STATUS "Generating linux_input_names.h from ${LINUX_INPUT_H_PATH} ${LINUX_INPUT_EVENT_CODES_H_PATH}")

execute_process(COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/parse_linux_input.sh
${LINUX_INPUT_H_PATH}
${CMAKE_CURRENT_BINARY_DIR}/linux_input_names.h
${LINUX_INPUT_H_PATH} ${LINUX_INPUT_EVENT_CODES_H_PATH}
RESULT_VARIABLE LINUX_INPUT_PARSE_RESULT)
if (NOT LINUX_INPUT_PARSE_RESULT EQUAL 0)
message(FATAL_ERROR "failed to generate linux_input_names.h")
Expand Down
13 changes: 8 additions & 5 deletions ncd/parse_linux_input.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env bash

INPUT=$1
OUTPUT=$2
OUTPUT=$1
shift
INPUTS=("$@")

types=""
keys=""
Expand All @@ -18,10 +19,12 @@ ffstatuss=""
while read LINE; do
tab=$'\t'
space="[ ${tab}]"
regex="^#define ((EV|SYN|KEY|BTN|REL|ABS|SW|MSC|LED|REP|SND|FF_STATUS)_[A-Z0-9_]+)${space}"
regex="^#define ((EV|SYN|KEY|BTN|REL|ABS|SW|MSC|LED|REP|SND|FF_STATUS)_([A-Z0-9_]+))${space}"
if [[ $LINE =~ $regex ]]; then
type=${BASH_REMATCH[2]}
name=${BASH_REMATCH[1]}
type=${BASH_REMATCH[2]}
nameonly=${BASH_REMATCH[3]}
[[ $nameonly = "MAX" || $nameonly = "CNT" ]] && continue
if [[ $type = "EV" ]]; then
if [[ $name != "EV_VERSION" ]]; then
types="${types} [${name}] = \"${name}\",
Expand Down Expand Up @@ -61,7 +64,7 @@ while read LINE; do
"
fi
fi
done < "${INPUT}"
done < <(cat "${INPUTS[@]}")

(
echo "
Expand Down

0 comments on commit 432f2ba

Please sign in to comment.