lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Fri, 31 Aug 2012 23:18:08 +1000
From:	Cruz Julian Bishop <cruzjbishop@...il.com>
To:	mcgrof@...il.com
Cc:	linux-kernel@...r.kernel.org,
	Cruz Julian Bishop <cruzjbishop@...il.com>
Subject: [PATCH 2/4] scripts/checkincludes.pl: Simplify and shorten argument logic

This patch allows for much easier implementation of arguments
when modifying checkincludes.pl

The variable $file is also initially named $arg - I wasn't sure
if memory would be a problem (I know it would be in Java/C#) if
another $file variable was initialized with the value of $arg,
so I just left it.

Overall, this still works nicely. There are some more
potential simplifications, but I will cover those in another
patch if I decide to implement them tonight.

Signed-off-by: Cruz Julian Bishop <cruzjbishop@...il.com>
---
 scripts/checkincludes.pl |   85 +++++++++++++++++++++-------------------------
 1 file changed, 39 insertions(+), 46 deletions(-)

diff --git a/scripts/checkincludes.pl b/scripts/checkincludes.pl
index 801ed5f..7d713c2 100755
--- a/scripts/checkincludes.pl
+++ b/scripts/checkincludes.pl
@@ -30,64 +30,57 @@ if ($#ARGV < 0) {
 	usage();
 }
 
-if ($#ARGV >= 1) {
-	if ($ARGV[0] =~ /^-/) {
-		if ($ARGV[0] eq "-r") {
-			$remove = 1;
-			shift;
-		} else {
-			usage();
-		}
-	}
-}
+foreach my $arg (@ARGV) {
+	if ($arg eq "-r") {
+		$remove = 1;
+	} else {
+		open(my $f, '<', $arg)
+		    or die "Cannot open $arg: $!.\n";
 
-foreach my $file (@ARGV) {
-	open(my $f, '<', $file)
-	    or die "Cannot open $file: $!.\n";
+		my %includedfiles = ();
+		my @file_lines = ();
 
-	my %includedfiles = ();
-	my @file_lines = ();
-
-	while (<$f>) {
-		if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) {
-			++$includedfiles{$1};
+		while (<$f>) {
+			if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) {
+				++$includedfiles{$1};
+			}
+			push(@file_lines, $_);
 		}
-		push(@file_lines, $_);
-	}
 
-	close($f);
+		close($f);
 
-	if (!$remove) {
-		foreach my $filename (keys %includedfiles) {
-			if ($includedfiles{$filename} > 1) {
-				print "$file: $filename is included more than once.\n";
+		if (!$remove) {
+			foreach my $filename (keys %includedfiles) {
+				if ($includedfiles{$filename} > 1) {
+					print "$arg: $filename is included more than once.\n";
+				}
 			}
+			next;
 		}
-		next;
-	}
 
-	open($f, '>', $file)
-	    or die("Cannot write to $file: $!");
+		open($f, '>', $arg)
+			or die("Cannot write to $arg: $!");
 
-	my $dups = 0;
-	foreach (@file_lines) {
-		if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) {
-			foreach my $filename (keys %includedfiles) {
-				if ($1 eq $filename) {
-					if ($includedfiles{$filename} > 1) {
-						$includedfiles{$filename}--;
-						$dups++;
-					} else {
-						print {$f} $_;
+		my $dups = 0;
+		foreach(@file_lines) {
+			if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) {
+				foreach my $filename (keys %includedfiles) {
+					if ($1 eq $filename) {
+						if ($includedfiles{$filename} > 1) {
+							$includedfiles{$filename}--;
+							$dups++;
+						} else {
+							print {$f} $_;
+						}
 					}
 				}
+			} else {
+				print {$f} $_;
 			}
-		} else {
-			print {$f} $_;
 		}
+		if ($dups > 0) {
+			print "$arg: removed $dups duplicate includes \n";
+		}
+		close($f);
 	}
-	if ($dups > 0) {
-		print "$file: removed $dups duplicate includes\n";
-	}
-	close($f);
 }
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ