From d3d94b467eeb5fac10f38041ad44fd843ffca6bf Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Mon, 8 Nov 2010 15:47:35 -0200 Subject: [PATCH] gen_keytables.pl: use a function to create files We want to move part of the logic from Makefile into gen_keytables.pl, in order to make it process a group of files. So, convert the main logic into a function. Signed-off-by: Mauro Carvalho Chehab --- utils/keytable/gen_keytables.pl | 75 ++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 34 deletions(-) diff --git a/utils/keytable/gen_keytables.pl b/utils/keytable/gen_keytables.pl index d8cc664..06400bb 100755 --- a/utils/keytable/gen_keytables.pl +++ b/utils/keytable/gen_keytables.pl @@ -13,7 +13,7 @@ my $check_type = 0; my $name; my $warn; -my $filename = shift or die "Need a file name to proceed."; +my $file = shift or die "Need a file name to proceed."; sub flush() { return if (!$keyname || !$out); @@ -33,48 +33,55 @@ sub flush() $name = ""; } -open IN, "<$filename"; -while () { - if (m/struct\s+ir_scancode\s+(\w[\w\d_]+)/) { - flush(); +sub parse_file($) +{ + my $filename = shift; - $keyname = $1; - $keyname =~ s/^ir_codes_//; - $keyname =~ s/_table$//; - $read = 1; - next; - } - if (m/struct\s+rc_keymap.*=\s+{/) { - $check_type = 1; - next; - } - if (m/\.name\s*=\s*(RC_MAP_[^\s\,]+)/) { - $name = $1; - } + open IN, "<$filename"; + while () { + if (m/struct\s+ir_scancode\s+(\w[\w\d_]+)/) { + flush(); - if ($check_type) { - if (m/^\s*}/) { - $check_type = 0; + $keyname = $1; + $keyname =~ s/^ir_codes_//; + $keyname =~ s/_table$//; + $read = 1; next; } - if (m/IR_TYPE_([\w\d_]+)/) { - $type = $1; + if (m/struct\s+rc_keymap.*=\s+{/) { + $check_type = 1; + next; + } + if (m/\.name\s*=\s*(RC_MAP_[^\s\,]+)/) { + $name = $1; } - next; - } - if ($read) { - if (m/(0x[\dA-Fa-f]+).*(KEY_[^\s\,\}]+)/) { - $out .= "$1 $2\n"; + if ($check_type) { + if (m/^\s*}/) { + $check_type = 0; + next; + } + if (m/IR_TYPE_([\w\d_]+)/) { + $type = $1; + } next; } - if (m/\}/) { - $read = 0; + + if ($read) { + if (m/(0x[\dA-Fa-f]+).*(KEY_[^\s\,\}]+)/) { + $out .= "$1 $2\n"; + next; + } + if (m/\}/) { + $read = 0; + } } } -} -close IN; + close IN; -flush(); + flush(); + + printf STDERR "WARNING: keyboard name not found on %d tables at file $filename\n", $warn if ($warn); +} -printf STDERR "WARNING: keyboard name not found on %d tables at file $filename\n", $warn if ($warn); +parse_file $file; -- 2.7.4