mm: remove unused pgdat->inactive_ratio
[linux/fpc-iii.git] / scripts / parse-maintainers.pl
blob5dbd2faa24494910d75c99c4f054b89715d51ae2
1 #!/usr/bin/perl -w
2 # SPDX-License-Identifier: GPL-2.0
4 use strict;
6 my $P = $0;
8 # sort comparison functions
9 sub by_category($$) {
10 my ($a, $b) = @_;
12 $a = uc $a;
13 $b = uc $b;
15 # This always sorts last
16 $a =~ s/THE REST/ZZZZZZ/g;
17 $b =~ s/THE REST/ZZZZZZ/g;
19 return $a cmp $b;
22 sub by_pattern($$) {
23 my ($a, $b) = @_;
24 my $preferred_order = 'MRPLSWTQBCFXNK';
26 my $a1 = uc(substr($a, 0, 1));
27 my $b1 = uc(substr($b, 0, 1));
29 my $a_index = index($preferred_order, $a1);
30 my $b_index = index($preferred_order, $b1);
32 $a_index = 1000 if ($a_index == -1);
33 $b_index = 1000 if ($b_index == -1);
35 if (($a1 =~ /^F$/ && $b1 =~ /^F$/) ||
36 ($a1 =~ /^X$/ && $b1 =~ /^X$/)) {
37 return $a cmp $b;
40 if ($a_index < $b_index) {
41 return -1;
42 } elsif ($a_index == $b_index) {
43 return 0;
44 } else {
45 return 1;
49 sub trim {
50 my $s = shift;
51 $s =~ s/\s+$//;
52 $s =~ s/^\s+//;
53 return $s;
56 sub alpha_output {
57 my ($hashref, $filename) = (@_);
59 open(my $file, '>', "$filename") or die "$P: $filename: open failed - $!\n";
60 foreach my $key (sort by_category keys %$hashref) {
61 if ($key eq " ") {
62 chomp $$hashref{$key};
63 print $file $$hashref{$key};
64 } else {
65 print $file "\n" . $key . "\n";
66 foreach my $pattern (sort by_pattern split('\n', %$hashref{$key})) {
67 print $file ($pattern . "\n");
71 close($file);
74 sub file_input {
75 my ($hashref, $filename) = (@_);
77 my $lastline = "";
78 my $case = " ";
79 $$hashref{$case} = "";
81 open(my $file, '<', "$filename") or die "$P: $filename: open failed - $!\n";
83 while (<$file>) {
84 my $line = $_;
86 # Pattern line?
87 if ($line =~ m/^([A-Z]):\s*(.*)/) {
88 $line = $1 . ":\t" . trim($2) . "\n";
89 if ($lastline eq "") {
90 $$hashref{$case} = $$hashref{$case} . $line;
91 next;
93 $case = trim($lastline);
94 exists $$hashref{$case} and die "Header '$case' already exists";
95 $$hashref{$case} = $line;
96 $lastline = "";
97 next;
100 if ($case eq " ") {
101 $$hashref{$case} = $$hashref{$case} . $lastline;
102 $lastline = $line;
103 next;
105 trim($lastline) eq "" or die ("Odd non-pattern line '$lastline' for '$case'");
106 $lastline = $line;
108 $$hashref{$case} = $$hashref{$case} . $lastline;
109 close($file);
112 my %hash;
113 my %new_hash;
115 file_input(\%hash, "MAINTAINERS");
117 foreach my $type (@ARGV) {
118 foreach my $key (keys %hash) {
119 if ($key =~ /$type/ || $hash{$key} =~ /$type/) {
120 $new_hash{$key} = $hash{$key};
121 delete $hash{$key};
126 alpha_output(\%hash, "MAINTAINERS.new");
127 alpha_output(\%new_hash, "SECTION.new");
129 exit(0);