2 # SPDX-License-Identifier: GPL-2.0
5 use Getopt
::Long
qw(:config no_auto_abbrev);
7 my $input_file = "MAINTAINERS";
8 my $output_file = "MAINTAINERS.new";
9 my $output_section = "SECTION.new";
15 'input=s' => \
$input_file,
16 'output=s' => \
$output_file,
17 'section=s' => \
$output_section,
18 'h|help|usage' => \
$help,
20 die "$P: invalid argument - use --help if necessary\n";
30 usage: $P [options] <pattern matching regexes>
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)
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
43 # sort comparison functions
50 # This always sorts last
51 $a =~ s/THE REST/ZZZZZZ/g;
52 $b =~ s/THE REST/ZZZZZZ/g;
59 my $preferred_order = 'MRPLSWTQBCFXNK';
61 my $a1 = uc(substr($a, 0, 1));
62 my $b1 = uc(substr($b, 0, 1));
64 my $a_index = index($preferred_order, $a1);
65 my $b_index = index($preferred_order, $b1);
67 $a_index = 1000 if ($a_index == -1);
68 $b_index = 1000 if ($b_index == -1);
70 if (($a1 =~ /^F$/ && $b1 =~ /^F$/) ||
71 ($a1 =~ /^X$/ && $b1 =~ /^X$/)) {
75 if ($a_index < $b_index) {
77 } elsif ($a_index == $b_index) {
92 my ($hashref, $filename) = (@_);
94 return if ! scalar(keys %$hashref);
96 open(my $file, '>', "$filename") or die "$P: $filename: open failed - $!\n";
98 foreach my $key (sort by_category
keys %$hashref) {
100 print $file $$hashref{$key};
102 if (! defined $separator) {
105 print $file $separator;
107 print $file $key . "\n";
108 foreach my $pattern (sort by_pattern
split('\n', %$hashref{$key})) {
109 print $file ($pattern . "\n");
117 my ($hashref, $filename) = (@_);
121 $$hashref{$case} = "";
123 open(my $file, '<', "$filename") or die "$P: $filename: open failed - $!\n";
129 if ($line =~ m/^([A-Z]):\s*(.*)/) {
130 $line = $1 . ":\t" . trim
($2) . "\n";
131 if ($lastline eq "") {
132 $$hashref{$case} = $$hashref{$case} . $line;
135 $case = trim
($lastline);
136 exists $$hashref{$case} and die "Header '$case' already exists";
137 $$hashref{$case} = $line;
143 $$hashref{$case} = $$hashref{$case} . $lastline;
147 trim
($lastline) eq "" or die ("Odd non-pattern line '$lastline' for '$case'");
150 $$hashref{$case} = $$hashref{$case} . $lastline;
157 file_input
(\
%hash, $input_file);
159 foreach my $type (@ARGV) {
160 foreach my $key (keys %hash) {
161 if ($key =~ /$type/ || $hash{$key} =~ /$type/) {
162 $new_hash{$key} = $hash{$key};
168 alpha_output
(\
%hash, $output_file);
169 alpha_output
(\
%new_hash, $output_section);