summaryrefslogtreecommitdiffstats
path: root/scripts/parse-maintainers.pl
diff options
context:
space:
mode:
authorJoe Perches <joe@perches.com>2017-11-17 18:27:10 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2017-11-17 19:10:01 -0500
commit1e6270d07cde9bfbc27f8d0f16b323cf3a3b63dd (patch)
tree06133d7af87467953a2251596064732c432d4453 /scripts/parse-maintainers.pl
parentaaf5dcfb223617ac2d16113e4b500199c65689de (diff)
parse-maintainers: add ability to specify filenames
parse-maintainers.pl is convenient, but currently hard-codes the filenames that are used. Allow user-specified filenames to simplify the use of the script. Link: http://lkml.kernel.org/r/48703c068b3235223ffa3b2eb268fa0a125b25e0.1502251549.git.joe@perches.com Signed-off-by: Joe Perches <joe@perches.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts/parse-maintainers.pl')
-rw-r--r--scripts/parse-maintainers.pl52
1 files changed, 47 insertions, 5 deletions
diff --git a/scripts/parse-maintainers.pl b/scripts/parse-maintainers.pl
index 5dbd2faa2449..255cef1b098d 100644
--- a/scripts/parse-maintainers.pl
+++ b/scripts/parse-maintainers.pl
@@ -2,9 +2,44 @@
2# SPDX-License-Identifier: GPL-2.0 2# SPDX-License-Identifier: GPL-2.0
3 3
4use strict; 4use strict;
5use Getopt::Long qw(:config no_auto_abbrev);
6
7my $input_file = "MAINTAINERS";
8my $output_file = "MAINTAINERS.new";
9my $output_section = "SECTION.new";
10my $help = 0;
5 11
6my $P = $0; 12my $P = $0;
7 13
14if (!GetOptions(
15 'input=s' => \$input_file,
16 'output=s' => \$output_file,
17 'section=s' => \$output_section,
18 'h|help|usage' => \$help,
19 )) {
20 die "$P: invalid argument - use --help if necessary\n";
21}
22
23if ($help != 0) {
24 usage();
25 exit 0;
26}
27
28sub usage {
29 print <<EOT;
30usage: $P [options] <pattern matching regexes>
31
32 --input => MAINTAINERS file to read (default: MAINTAINERS)
33 --output => sorted MAINTAINERS file to write (default: MAINTAINERS.new)
34 --section => new sorted MAINTAINERS file to write to (default: SECTION.new)
35
36If <pattern match regexes> exist, then the sections that match the
37regexes are not written to the output file but are written to the
38section file.
39
40EOT
41}
42
8# sort comparison functions 43# sort comparison functions
9sub by_category($$) { 44sub by_category($$) {
10 my ($a, $b) = @_; 45 my ($a, $b) = @_;
@@ -56,13 +91,20 @@ sub trim {
56sub alpha_output { 91sub alpha_output {
57 my ($hashref, $filename) = (@_); 92 my ($hashref, $filename) = (@_);
58 93
94 return if ! scalar(keys %$hashref);
95
59 open(my $file, '>', "$filename") or die "$P: $filename: open failed - $!\n"; 96 open(my $file, '>', "$filename") or die "$P: $filename: open failed - $!\n";
97 my $separator;
60 foreach my $key (sort by_category keys %$hashref) { 98 foreach my $key (sort by_category keys %$hashref) {
61 if ($key eq " ") { 99 if ($key eq " ") {
62 chomp $$hashref{$key};
63 print $file $$hashref{$key}; 100 print $file $$hashref{$key};
64 } else { 101 } else {
65 print $file "\n" . $key . "\n"; 102 if (! defined $separator) {
103 $separator = "\n";
104 } else {
105 print $file $separator;
106 }
107 print $file $key . "\n";
66 foreach my $pattern (sort by_pattern split('\n', %$hashref{$key})) { 108 foreach my $pattern (sort by_pattern split('\n', %$hashref{$key})) {
67 print $file ($pattern . "\n"); 109 print $file ($pattern . "\n");
68 } 110 }
@@ -112,7 +154,7 @@ sub file_input {
112my %hash; 154my %hash;
113my %new_hash; 155my %new_hash;
114 156
115file_input(\%hash, "MAINTAINERS"); 157file_input(\%hash, $input_file);
116 158
117foreach my $type (@ARGV) { 159foreach my $type (@ARGV) {
118 foreach my $key (keys %hash) { 160 foreach my $key (keys %hash) {
@@ -123,7 +165,7 @@ foreach my $type (@ARGV) {
123 } 165 }
124} 166}
125 167
126alpha_output(\%hash, "MAINTAINERS.new"); 168alpha_output(\%hash, $output_file);
127alpha_output(\%new_hash, "SECTION.new"); 169alpha_output(\%new_hash, $output_section);
128 170
129exit(0); 171exit(0);