diff mbox series

[v4l-utils,1/2] gen_keytables.pl: strip comments from C files

Message ID 20190703141212.31719-1-sean@mess.org (mailing list archive)
State New, archived
Headers show
Series [v4l-utils,1/2] gen_keytables.pl: strip comments from C files | expand

Commit Message

Sean Young July 3, 2019, 2:12 p.m. UTC
Some keymaps contain mappings in comments which should have not been
included.

Cc: Bastien Nocera <hadess@hadess.net>
Signed-off-by: Sean Young <sean@mess.org>
---
 utils/keytable/gen_keytables.pl | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/utils/keytable/gen_keytables.pl b/utils/keytable/gen_keytables.pl
index 4124e366..8f3a87e6 100755
--- a/utils/keytable/gen_keytables.pl
+++ b/utils/keytable/gen_keytables.pl
@@ -82,7 +82,17 @@  sub parse_file($$)
 
 	printf "processing file $filename\n" if ($debug);
 	open IN, "<$filename" or die "couldn't find $filename";
-	while (<IN>) {
+	# read the entire file
+	my $file = do { local $/ = undef; <IN> };
+	close IN;
+
+	# remove comments
+	$file =~ s,/\*.*?\*/,,sg;
+	$file =~ s,//[^\n]*,,sg;
+
+	my @lines = split /\n/, $file;
+
+	foreach (@lines) {
 		if (m/struct\s+rc_map_table\s+(\w[\w\d_]+)/) {
 			flush($filename, $legacy);
 
@@ -140,7 +150,6 @@  sub parse_file($$)
 			}
 		}
 	}
-	close IN;
 
 	flush($filename, $legacy);