[PATCH 1/4] hal-info: Clean up keymap-check.sh

Victor Lowther victor.lowther at gmail.com
Mon Mar 24 20:08:10 PDT 2008


This patch series cleans up keymap-check.sh.

Streamlined isin().  Just using grep -q is much faster than iterating over
each line in a for loop.

Replaced xml processing pipeline in get_line with a single invocation of sed.

Use file globbing instead of find in get_files.
---
 tools/keymap-check.sh |   24 ++++++++++--------------
 1 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/tools/keymap-check.sh b/tools/keymap-check.sh
index a05e029..76f5c24 100755
--- a/tools/keymap-check.sh
+++ b/tools/keymap-check.sh
@@ -4,24 +4,20 @@
 # checks to see if the keycode is in the quirk keymap list
 isin ()
 {
-	got="0"
-	for query in `cat /tmp/quirk-keymap-list.txt`
-	do
-		if [ "$query" = "$1" ]; then
-			got="1"
-		fi
-	done
-	echo "$got"
+	grep -q "^${1}\$" /tmp/quirk-keymap-list.txt && return 1
+	return 0
 }
 
 # processes each line of the fdi file
 get_line ()
 {
-	cat "$1" | sed -ne '/<!--/ { :c; /-->/! { N; b c; }; /-->/s/<!--.*-->//g }; /^  *$/!p;' | grep "input.keymap.data" | while read line
+	local data
+	sed -ne '/<append key="input.keymap.data"/ { # only keymap data lines
+	        s,<[^>]*>,,g; 		# get rid of all xml tags
+		s,[^:]*:,,;   		# get rid of leading cruft
+		p };' "$1" | while read data;
 	do
-		data=`echo "${line}" | cut -d":" -f2 | cut -d"<" -f1`
-		found=`isin $data`
-		if [ "$found" = "0" ]; then
+		if isin $data; then
 			echo "$data "
 		fi
 	done
@@ -30,7 +26,7 @@ get_line ()
 # processes each line of the fdi file
 get_files ()
 {
-	find "../fdi/information/10freedesktop/" -name '30-keymap-*.fdi'  | while read file
+	for file in "../fdi/information/10freedesktop/30-keymap-"*".fdi";
 	do
 		status="ok"
 		ret=`get_line "${file}"`
@@ -56,7 +52,7 @@ if [ ! -e "$fqpath" ]; then
 fi
 
 # make lowercase and save in /tmp
-cat "$fqpath" | tr '[A-Z]' '[a-z]' | sort > /tmp/quirk-keymap-list.txt
+tr '[A-Z]' '[a-z]' < "$fqpath" | sort > /tmp/quirk-keymap-list.txt
 
 echo "Validating keycodes..."
 result=`get_files`
-- 
1.5.4.3



More information about the hal mailing list