Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1704724
| From | Joe Perches <joe@perches.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 2/4] parse-maintainers: Use perl hash references and specific filenames |
| Date | 2017-08-06 03:50 +0200 |
| Message-ID | <ubiRA-4c2-9@gated-at.bofh.it> (permalink) |
| References | <ubiRz-4c2-3@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
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>
---
scripts/parse-maintainers.pl | 57 ++++++++++++++++++++++++++------------------
1 file changed, 34 insertions(+), 23 deletions(-)
diff --git a/scripts/parse-maintainers.pl b/scripts/parse-maintainers.pl
index 5c8e0504c67e..c286154a2b68 100644
--- a/scripts/parse-maintainers.pl
+++ b/scripts/parse-maintainers.pl
@@ -2,7 +2,7 @@
use strict;
-my %hash;
+my $P = $0;
# sort comparison functions
sub by_category($$) {
@@ -45,61 +45,72 @@ sub by_pattern($$) {
}
}
+sub trim {
+ my $s = shift;
+ $s =~ s/\s+$//;
+ $s =~ s/^\s+//;
+ return $s;
+}
+
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 " ") {
- chomp $hash{$key};
- print $hash{$key};
+ chomp $$hashref{$key};
+ print $file $$hashref{$key};
} else {
- print "\n" . $key . "\n";
- foreach my $pattern (sort by_pattern split('\n', $hash{$key})) {
- print($pattern . "\n");
+ print $file "\n" . $key . "\n";
+ foreach my $pattern (sort by_pattern split('\n', %$hashref{$key})) {
+ print $file ($pattern . "\n");
}
}
}
-}
-
-sub trim {
- my $s = shift;
- $s =~ s/\s+$//;
- $s =~ s/^\s+//;
- return $s;
+ close($file);
}
sub file_input {
+ my ($hashref, $filename) = (@_);
+
my $lastline = "";
my $case = " ";
- $hash{$case} = "";
+ $$hashref{$case} = "";
+
+ open(my $file, '<', "$filename") or die "$P: $filename: open failed - $!\n";
- while (<>) {
+ while (<$file>) {
my $line = $_;
# Pattern line?
if ($line =~ m/^([A-Z]):\s*(.*)/) {
$line = $1 . ":\t" . trim($2) . "\n";
if ($lastline eq "") {
- $hash{$case} = $hash{$case} . $line;
+ $$hashref{$case} = $$hashref{$case} . $line;
next;
}
$case = trim($lastline);
- exists $hash{$case} and die "Header '$case' already exists";
- $hash{$case} = $line;
+ exists $$hashref{$case} and die "Header '$case' already exists";
+ $$hashref{$case} = $line;
$lastline = "";
next;
}
if ($case eq " ") {
- $hash{$case} = $hash{$case} . $lastline;
+ $$hashref{$case} = $$hashref{$case} . $lastline;
$lastline = $line;
next;
}
trim($lastline) eq "" or die ("Odd non-pattern line '$lastline' for '$case'");
$lastline = $line;
}
- $hash{$case} = $hash{$case} . $lastline;
+ $$hashref{$case} = $$hashref{$case} . $lastline;
+ close($file);
}
-file_input();
-alpha_output();
+my %hash;
+
+file_input(\%hash, "MAINTAINERS");
+alpha_output(\%hash, "MAINTAINERS.new");
exit(0);
--
2.10.0.rc2.1.g053435c
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 0/4] Scripted update of the MAINTAINERS files Joe Perches <joe@perches.com> - 2017-08-06 03:50 +0200
[PATCH 4/4] scripts/move_maintainer_sections.bash Joe Perches <joe@perches.com> - 2017-08-06 03:50 +0200
Re: [PATCH 4/4] scripts/move_maintainer_sections.bash Joe Perches <joe@perches.com> - 2017-08-07 19:10 +0200
Re: [PATCH 4/4] scripts/move_maintainer_sections.bash Linus Torvalds <torvalds@linux-foundation.org> - 2017-08-08 20:40 +0200
Re: [PATCH 4/4] scripts/move_maintainer_sections.bash Joe Perches <joe@perches.com> - 2017-08-09 02:40 +0200
[PATCH 2/4] parse-maintainers: Use perl hash references and specific filenames Joe Perches <joe@perches.com> - 2017-08-06 03:50 +0200
[PATCH 3/4] parse-maintainers: Move matching sections from MAINTAINERS Joe Perches <joe@perches.com> - 2017-08-06 03:50 +0200
csiph-web