gen_keytables.pl: use a function to create files
authorMauro Carvalho Chehab <mchehab@redhat.com>
Mon, 8 Nov 2010 17:47:35 +0000 (15:47 -0200)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Mon, 8 Nov 2010 17:47:35 +0000 (15:47 -0200)
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 <mchehab@redhat.com>
utils/keytable/gen_keytables.pl

index d8cc664..06400bb 100755 (executable)
@@ -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 (<IN>) {
-       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 (<IN>) {
+               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;