diff options
| author | Joe Perches <joe@perches.com> | 2017-08-05 21:45:48 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-08-08 14:16:14 -0400 |
| commit | fe9090301fed202a80a6113534efaa0d9184543b (patch) | |
| tree | a4a89d1f652b626fade689d6e7fbb925660a74f4 /scripts | |
| parent | 61f741645a354d91fece7b9cbb2f3f3587db8b8a (diff) | |
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>
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/parse-maintainers.pl | 57 |
1 files 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 @@ | |||
| 2 | 2 | ||
| 3 | use strict; | 3 | use strict; |
| 4 | 4 | ||
| 5 | my %hash; | 5 | my $P = $0; |
| 6 | 6 | ||
| 7 | # sort comparison functions | 7 | # sort comparison functions |
| 8 | sub by_category($$) { | 8 | sub by_category($$) { |
| @@ -45,61 +45,72 @@ sub by_pattern($$) { | |||
| 45 | } | 45 | } |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | sub trim { | ||
| 49 | my $s = shift; | ||
| 50 | $s =~ s/\s+$//; | ||
| 51 | $s =~ s/^\s+//; | ||
| 52 | return $s; | ||
| 53 | } | ||
| 54 | |||
| 48 | sub alpha_output { | 55 | 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) { | ||
| 50 | if ($key eq " ") { | 60 | if ($key eq " ") { |
| 51 | chomp $hash{$key}; | 61 | chomp $$hashref{$key}; |
| 52 | print $hash{$key}; | 62 | print $file $$hashref{$key}; |
| 53 | } else { | 63 | } else { |
| 54 | print "\n" . $key . "\n"; | 64 | print $file "\n" . $key . "\n"; |
| 55 | foreach my $pattern (sort by_pattern split('\n', $hash{$key})) { | 65 | foreach my $pattern (sort by_pattern split('\n', %$hashref{$key})) { |
| 56 | print($pattern . "\n"); | 66 | print $file ($pattern . "\n"); |
| 57 | } | 67 | } |
| 58 | } | 68 | } |
| 59 | } | 69 | } |
| 60 | } | 70 | close($file); |
| 61 | |||
| 62 | sub trim { | ||
| 63 | my $s = shift; | ||
| 64 | $s =~ s/\s+$//; | ||
| 65 | $s =~ s/^\s+//; | ||
| 66 | return $s; | ||
| 67 | } | 71 | } |
| 68 | 72 | ||
| 69 | sub file_input { | 73 | sub file_input { |
| 74 | my ($hashref, $filename) = (@_); | ||
| 75 | |||
| 70 | my $lastline = ""; | 76 | my $lastline = ""; |
| 71 | my $case = " "; | 77 | my $case = " "; |
| 72 | $hash{$case} = ""; | 78 | $$hashref{$case} = ""; |
| 79 | |||
| 80 | open(my $file, '<', "$filename") or die "$P: $filename: open failed - $!\n"; | ||
| 73 | 81 | ||
| 74 | while (<>) { | 82 | while (<$file>) { |
| 75 | my $line = $_; | 83 | my $line = $_; |
| 76 | 84 | ||
| 77 | # Pattern line? | 85 | # Pattern line? |
| 78 | if ($line =~ m/^([A-Z]):\s*(.*)/) { | 86 | if ($line =~ m/^([A-Z]):\s*(.*)/) { |
| 79 | $line = $1 . ":\t" . trim($2) . "\n"; | 87 | $line = $1 . ":\t" . trim($2) . "\n"; |
| 80 | if ($lastline eq "") { | 88 | if ($lastline eq "") { |
| 81 | $hash{$case} = $hash{$case} . $line; | 89 | $$hashref{$case} = $$hashref{$case} . $line; |
| 82 | next; | 90 | next; |
| 83 | } | 91 | } |
| 84 | $case = trim($lastline); | 92 | $case = trim($lastline); |
| 85 | exists $hash{$case} and die "Header '$case' already exists"; | 93 | exists $$hashref{$case} and die "Header '$case' already exists"; |
| 86 | $hash{$case} = $line; | 94 | $$hashref{$case} = $line; |
| 87 | $lastline = ""; | 95 | $lastline = ""; |
| 88 | next; | 96 | next; |
| 89 | } | 97 | } |
| 90 | 98 | ||
| 91 | if ($case eq " ") { | 99 | if ($case eq " ") { |
| 92 | $hash{$case} = $hash{$case} . $lastline; | 100 | $$hashref{$case} = $$hashref{$case} . $lastline; |
| 93 | $lastline = $line; | 101 | $lastline = $line; |
| 94 | next; | 102 | next; |
| 95 | } | 103 | } |
| 96 | trim($lastline) eq "" or die ("Odd non-pattern line '$lastline' for '$case'"); | 104 | trim($lastline) eq "" or die ("Odd non-pattern line '$lastline' for '$case'"); |
| 97 | $lastline = $line; | 105 | $lastline = $line; |
| 98 | } | 106 | } |
| 99 | $hash{$case} = $hash{$case} . $lastline; | 107 | $$hashref{$case} = $$hashref{$case} . $lastline; |
| 108 | close($file); | ||
| 100 | } | 109 | } |
| 101 | 110 | ||
| 102 | file_input(); | 111 | my %hash; |
| 103 | alpha_output(); | 112 | |
| 113 | file_input(\%hash, "MAINTAINERS"); | ||
| 114 | alpha_output(\%hash, "MAINTAINERS.new"); | ||
| 104 | 115 | ||
| 105 | exit(0); | 116 | exit(0); |
