diff options
Diffstat (limited to 'scripts/parse-maintainers.pl')
-rw-r--r-- | scripts/parse-maintainers.pl | 97 |
1 files changed, 74 insertions, 23 deletions
diff --git a/scripts/parse-maintainers.pl b/scripts/parse-maintainers.pl index a0fe34349b24..e40b53db7f9f 100644 --- a/scripts/parse-maintainers.pl +++ b/scripts/parse-maintainers.pl | |||
@@ -2,9 +2,9 @@ | |||
2 | 2 | ||
3 | use strict; | 3 | use strict; |
4 | 4 | ||
5 | my %map; | 5 | my $P = $0; |
6 | 6 | ||
7 | # sort comparison function | 7 | # sort comparison functions |
8 | sub by_category($$) { | 8 | sub by_category($$) { |
9 | my ($a, $b) = @_; | 9 | my ($a, $b) = @_; |
10 | 10 | ||
@@ -15,20 +15,33 @@ sub by_category($$) { | |||
15 | $a =~ s/THE REST/ZZZZZZ/g; | 15 | $a =~ s/THE REST/ZZZZZZ/g; |
16 | $b =~ s/THE REST/ZZZZZZ/g; | 16 | $b =~ s/THE REST/ZZZZZZ/g; |
17 | 17 | ||
18 | $a cmp $b; | 18 | return $a cmp $b; |
19 | } | 19 | } |
20 | 20 | ||
21 | sub alpha_output { | 21 | sub by_pattern($$) { |
22 | my $key; | 22 | my ($a, $b) = @_; |
23 | my $sort_method = \&by_category; | 23 | my $preferred_order = 'MRPLSWTQBCFXNK'; |
24 | my $sep = ""; | 24 | |
25 | 25 | my $a1 = uc(substr($a, 0, 1)); | |
26 | foreach $key (sort $sort_method keys %map) { | 26 | my $b1 = uc(substr($b, 0, 1)); |
27 | if ($key ne " ") { | 27 | |
28 | print $sep . $key . "\n"; | 28 | my $a_index = index($preferred_order, $a1); |
29 | $sep = "\n"; | 29 | my $b_index = index($preferred_order, $b1); |
30 | } | 30 | |
31 | print $map{$key}; | 31 | $a_index = 1000 if ($a_index == -1); |
32 | $b_index = 1000 if ($b_index == -1); | ||
33 | |||
34 | if (($a1 =~ /^F$/ && $b1 =~ /^F$/) || | ||
35 | ($a1 =~ /^X$/ && $b1 =~ /^X$/)) { | ||
36 | return $a cmp $b; | ||
37 | } | ||
38 | |||
39 | if ($a_index < $b_index) { | ||
40 | return -1; | ||
41 | } elsif ($a_index == $b_index) { | ||
42 | return 0; | ||
43 | } else { | ||
44 | return 1; | ||
32 | } | 45 | } |
33 | } | 46 | } |
34 | 47 | ||
@@ -39,39 +52,77 @@ sub trim { | |||
39 | return $s; | 52 | return $s; |
40 | } | 53 | } |
41 | 54 | ||
55 | sub alpha_output { | ||
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) { | ||
60 | if ($key eq " ") { | ||
61 | chomp $$hashref{$key}; | ||
62 | print $file $$hashref{$key}; | ||
63 | } else { | ||
64 | print $file "\n" . $key . "\n"; | ||
65 | foreach my $pattern (sort by_pattern split('\n', %$hashref{$key})) { | ||
66 | print $file ($pattern . "\n"); | ||
67 | } | ||
68 | } | ||
69 | } | ||
70 | close($file); | ||
71 | } | ||
72 | |||
42 | sub file_input { | 73 | sub file_input { |
74 | my ($hashref, $filename) = (@_); | ||
75 | |||
43 | my $lastline = ""; | 76 | my $lastline = ""; |
44 | my $case = " "; | 77 | my $case = " "; |
45 | $map{$case} = ""; | 78 | $$hashref{$case} = ""; |
79 | |||
80 | open(my $file, '<', "$filename") or die "$P: $filename: open failed - $!\n"; | ||
46 | 81 | ||
47 | while (<>) { | 82 | while (<$file>) { |
48 | my $line = $_; | 83 | my $line = $_; |
49 | 84 | ||
50 | # Pattern line? | 85 | # Pattern line? |
51 | if ($line =~ m/^([A-Z]):\s*(.*)/) { | 86 | if ($line =~ m/^([A-Z]):\s*(.*)/) { |
52 | $line = $1 . ":\t" . trim($2) . "\n"; | 87 | $line = $1 . ":\t" . trim($2) . "\n"; |
53 | if ($lastline eq "") { | 88 | if ($lastline eq "") { |
54 | $map{$case} = $map{$case} . $line; | 89 | $$hashref{$case} = $$hashref{$case} . $line; |
55 | next; | 90 | next; |
56 | } | 91 | } |
57 | $case = trim($lastline); | 92 | $case = trim($lastline); |
58 | exists $map{$case} and die "Header '$case' already exists"; | 93 | exists $$hashref{$case} and die "Header '$case' already exists"; |
59 | $map{$case} = $line; | 94 | $$hashref{$case} = $line; |
60 | $lastline = ""; | 95 | $lastline = ""; |
61 | next; | 96 | next; |
62 | } | 97 | } |
63 | 98 | ||
64 | if ($case eq " ") { | 99 | if ($case eq " ") { |
65 | $map{$case} = $map{$case} . $lastline; | 100 | $$hashref{$case} = $$hashref{$case} . $lastline; |
66 | $lastline = $line; | 101 | $lastline = $line; |
67 | next; | 102 | next; |
68 | } | 103 | } |
69 | 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'"); |
70 | $lastline = $line; | 105 | $lastline = $line; |
71 | } | 106 | } |
72 | $map{$case} = $map{$case} . $lastline; | 107 | $$hashref{$case} = $$hashref{$case} . $lastline; |
108 | close($file); | ||
73 | } | 109 | } |
74 | 110 | ||
75 | &file_input; | 111 | my %hash; |
76 | &alpha_output; | 112 | my %new_hash; |
113 | |||
114 | file_input(\%hash, "MAINTAINERS"); | ||
115 | |||
116 | foreach my $type (@ARGV) { | ||
117 | foreach my $key (keys %hash) { | ||
118 | if ($key =~ /$type/ || $hash{$key} =~ /$type/) { | ||
119 | $new_hash{$key} = $hash{$key}; | ||
120 | delete $hash{$key}; | ||
121 | } | ||
122 | } | ||
123 | } | ||
124 | |||
125 | alpha_output(\%hash, "MAINTAINERS.new"); | ||
126 | alpha_output(\%new_hash, "SECTION.new"); | ||
127 | |||
77 | exit(0); | 128 | exit(0); |