Commit fe909030 authored by Joe Perches's avatar Joe Perches Committed by Linus Torvalds

parse-maintainers: Use perl hash references and specific filenames

Instead of reading STDIN and writing STDOUT, use specific filenames of
MAINTAINERS and MAINTAINERS.new.

Use hash references instead of global hash %hash so future modifications
can read and write specific hashes to split up MAINTAINERS into multiple
files using a script.
Signed-off-by: default avatarJoe Perches <joe@perches.com>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 61f74164
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
use strict; use strict;
my %hash; my $P = $0;
# sort comparison functions # sort comparison functions
sub by_category($$) { sub by_category($$) {
...@@ -45,61 +45,72 @@ sub by_pattern($$) { ...@@ -45,61 +45,72 @@ sub by_pattern($$) {
} }
} }
sub trim {
my $s = shift;
$s =~ s/\s+$//;
$s =~ s/^\s+//;
return $s;
}
sub alpha_output { sub alpha_output {
foreach my $key (sort by_category keys %hash) { my ($hashref, $filename) = (@_);
open(my $file, '>', "$filename") or die "$P: $filename: open failed - $!\n";
foreach my $key (sort by_category keys %$hashref) {
if ($key eq " ") { if ($key eq " ") {
chomp $hash{$key}; chomp $$hashref{$key};
print $hash{$key}; print $file $$hashref{$key};
} else { } else {
print "\n" . $key . "\n"; print $file "\n" . $key . "\n";
foreach my $pattern (sort by_pattern split('\n', $hash{$key})) { foreach my $pattern (sort by_pattern split('\n', %$hashref{$key})) {
print($pattern . "\n"); print $file ($pattern . "\n");
} }
} }
} }
} close($file);
sub trim {
my $s = shift;
$s =~ s/\s+$//;
$s =~ s/^\s+//;
return $s;
} }
sub file_input { sub file_input {
my ($hashref, $filename) = (@_);
my $lastline = ""; my $lastline = "";
my $case = " "; my $case = " ";
$hash{$case} = ""; $$hashref{$case} = "";
open(my $file, '<', "$filename") or die "$P: $filename: open failed - $!\n";
while (<>) { while (<$file>) {
my $line = $_; my $line = $_;
# Pattern line? # Pattern line?
if ($line =~ m/^([A-Z]):\s*(.*)/) { if ($line =~ m/^([A-Z]):\s*(.*)/) {
$line = $1 . ":\t" . trim($2) . "\n"; $line = $1 . ":\t" . trim($2) . "\n";
if ($lastline eq "") { if ($lastline eq "") {
$hash{$case} = $hash{$case} . $line; $$hashref{$case} = $$hashref{$case} . $line;
next; next;
} }
$case = trim($lastline); $case = trim($lastline);
exists $hash{$case} and die "Header '$case' already exists"; exists $$hashref{$case} and die "Header '$case' already exists";
$hash{$case} = $line; $$hashref{$case} = $line;
$lastline = ""; $lastline = "";
next; next;
} }
if ($case eq " ") { if ($case eq " ") {
$hash{$case} = $hash{$case} . $lastline; $$hashref{$case} = $$hashref{$case} . $lastline;
$lastline = $line; $lastline = $line;
next; next;
} }
trim($lastline) eq "" or die ("Odd non-pattern line '$lastline' for '$case'"); trim($lastline) eq "" or die ("Odd non-pattern line '$lastline' for '$case'");
$lastline = $line; $lastline = $line;
} }
$hash{$case} = $hash{$case} . $lastline; $$hashref{$case} = $$hashref{$case} . $lastline;
close($file);
} }
file_input(); my %hash;
alpha_output();
file_input(\%hash, "MAINTAINERS");
alpha_output(\%hash, "MAINTAINERS.new");
exit(0); exit(0);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment