Skip to content

Commit fe90903

Browse files
JoePerchestorvalds
authored andcommitted
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: Joe Perches <joe@perches.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 61f7416 commit fe90903

1 file changed

Lines changed: 34 additions & 23 deletions

File tree

scripts/parse-maintainers.pl

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use strict;
44

5-
my %hash;
5+
my $P = $0;
66

77
# sort comparison functions
88
sub by_category($$) {
@@ -45,61 +45,72 @@ ($$)
4545
}
4646
}
4747

48+
sub trim {
49+
my $s = shift;
50+
$s =~ s/\s+$//;
51+
$s =~ s/^\s+//;
52+
return $s;
53+
}
54+
4855
sub alpha_output {
49-
foreach my $key (sort by_category keys %hash) {
56+
my ($hashref, $filename) = (@_);
57+
58+
open(my $file, '>', "$filename") or die "$P: $filename: open failed - $!\n";
59+
foreach my $key (sort by_category keys %$hashref) {
5060
if ($key eq " ") {
51-
chomp $hash{$key};
52-
print $hash{$key};
61+
chomp $$hashref{$key};
62+
print $file $$hashref{$key};
5363
} else {
54-
print "\n" . $key . "\n";
55-
foreach my $pattern (sort by_pattern split('\n', $hash{$key})) {
56-
print($pattern . "\n");
64+
print $file "\n" . $key . "\n";
65+
foreach my $pattern (sort by_pattern split('\n', %$hashref{$key})) {
66+
print $file ($pattern . "\n");
5767
}
5868
}
5969
}
60-
}
61-
62-
sub trim {
63-
my $s = shift;
64-
$s =~ s/\s+$//;
65-
$s =~ s/^\s+//;
66-
return $s;
70+
close($file);
6771
}
6872

6973
sub file_input {
74+
my ($hashref, $filename) = (@_);
75+
7076
my $lastline = "";
7177
my $case = " ";
72-
$hash{$case} = "";
78+
$$hashref{$case} = "";
79+
80+
open(my $file, '<', "$filename") or die "$P: $filename: open failed - $!\n";
7381

74-
while (<>) {
82+
while (<$file>) {
7583
my $line = $_;
7684

7785
# Pattern line?
7886
if ($line =~ m/^([A-Z]):\s*(.*)/) {
7987
$line = $1 . ":\t" . trim($2) . "\n";
8088
if ($lastline eq "") {
81-
$hash{$case} = $hash{$case} . $line;
89+
$$hashref{$case} = $$hashref{$case} . $line;
8290
next;
8391
}
8492
$case = trim($lastline);
85-
exists $hash{$case} and die "Header '$case' already exists";
86-
$hash{$case} = $line;
93+
exists $$hashref{$case} and die "Header '$case' already exists";
94+
$$hashref{$case} = $line;
8795
$lastline = "";
8896
next;
8997
}
9098

9199
if ($case eq " ") {
92-
$hash{$case} = $hash{$case} . $lastline;
100+
$$hashref{$case} = $$hashref{$case} . $lastline;
93101
$lastline = $line;
94102
next;
95103
}
96104
trim($lastline) eq "" or die ("Odd non-pattern line '$lastline' for '$case'");
97105
$lastline = $line;
98106
}
99-
$hash{$case} = $hash{$case} . $lastline;
107+
$$hashref{$case} = $$hashref{$case} . $lastline;
108+
close($file);
100109
}
101110

102-
file_input();
103-
alpha_output();
111+
my %hash;
112+
113+
file_input(\%hash, "MAINTAINERS");
114+
alpha_output(\%hash, "MAINTAINERS.new");
104115

105116
exit(0);

0 commit comments

Comments
 (0)