History

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.

Joe Perches committed 8 years ago

Commit 1e6270d1 parent aaf5dcf1 file · +47 −5Browse files

Showing the changes to scripts (1 of 1 file). Show all

Unified · Split

scripts/parse-maintainers.pl+47−5
@@ -2,9 +2,44 @@ · 1 unmodified line
22 # SPDX-License-Identifier: GPL-2.0
33
44 use strict;
5+use Getopt::Long qw(:config no_auto_abbrev);
6+
7+my $input_file = "MAINTAINERS";
8+my $output_file = "MAINTAINERS.new";
9+my $output_section = "SECTION.new";
10+my $help = 0;
511
612 my $P = $0;
713
14+if (!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+
23+if ($help != 0) {
24+ usage();
25+ exit 0;
26+}
27+
28+sub usage {
29+ print <<EOT;
30+usage: $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+
36+If <pattern match regexes> exist, then the sections that match the
37+regexes are not written to the output file but are written to the
38+section file.
39+
40+EOT
41+}
42+
843 # sort comparison functions
944 sub by_category($$) {
1045 my ($a, $b) = @_;
@@ -56,13 +91,20 @@ sub trim { · 45 unmodified lines
5691 sub alpha_output {
5792 my ($hashref, $filename) = (@_);
5893
94+ return if ! scalar(keys %$hashref);
95+
5996 open(my $file, '>', "$filename") or die "$P: $filename: open failed - $!\n";
97+ my $separator;
6098 foreach my $key (sort by_category keys %$hashref) {
6199 if ($key eq " ") {
62− chomp $$hashref{$key};
63100 print $file $$hashref{$key};
64101 } 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";
66108 foreach my $pattern (sort by_pattern split('\n', %$hashref{$key})) {
67109 print $file ($pattern . "\n");
68110 }
@@ -112,7 +154,7 @@ sub file_input { · 43 unmodified lines
112154 my %hash;
113155 my %new_hash;
114156
115−file_input(\%hash, "MAINTAINERS");
157+file_input(\%hash, $input_file);
116158
117159 foreach my $type (@ARGV) {
118160 foreach my $key (keys %hash) {
@@ -123,7 +165,7 @@ foreach my $type (@ARGV) { · 4 unmodified lines
123165 }
124166 }
125167
126−alpha_output(\%hash, "MAINTAINERS.new");
127−alpha_output(\%new_hash, "SECTION.new");
168+alpha_output(\%hash, $output_file);
169+alpha_output(\%new_hash, $output_section);
128170
129171 exit(0);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t