summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorPaul Menzel <pmenzel@molgen.mpg.de>2017-07-24 13:43:05 +0200
committerPhilipp Deppenwiese <zaolin.daisuki@gmail.com>2018-04-16 22:25:31 +0000
commit44ad86a723b365f597a3a0243783c8fd05837250 (patch)
treea3d368aca21d0f9d279d42f5454be2252bdcec37 /util
parentf3bd97cb8985af7dec1be0917ab6703636ccf79e (diff)
util/scripts: Add script to alphabetize MAINTAINERS file
Copy script from Linux added in commit 7683e9e5 (Properly alphabetize MAINTAINERS file) by Linus Torvalds. > This adds a perl script to actually parse the MAINTAINERS file, clean > up some whitespace in it, warn about errors in it, and then properly > sort the end result. > > My perl-fu is atrocious, so the script has basically been created by > randomly putting various characters in a pile, mixing them around, and > then looking it the end result does anything interesting when used as > a perl script. Change-Id: I2eb4e3f9863d0fe242fb690f1121842c80d72d6a Signed-off-by: Paul Menzel <pmenzel@molgen.mpg.de> Reviewed-on: https://review.coreboot.org/20742 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Philipp Deppenwiese <zaolin.daisuki@gmail.com>
Diffstat (limited to 'util')
-rwxr-xr-xutil/scripts/parse-maintainers.pl77
1 files changed, 77 insertions, 0 deletions
diff --git a/util/scripts/parse-maintainers.pl b/util/scripts/parse-maintainers.pl
new file mode 100755
index 0000000000..a0fe34349b
--- /dev/null
+++ b/util/scripts/parse-maintainers.pl
@@ -0,0 +1,77 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+my %map;
+
+# sort comparison function
+sub by_category($$) {
+ my ($a, $b) = @_;
+
+ $a = uc $a;
+ $b = uc $b;
+
+ # This always sorts last
+ $a =~ s/THE REST/ZZZZZZ/g;
+ $b =~ s/THE REST/ZZZZZZ/g;
+
+ $a cmp $b;
+}
+
+sub alpha_output {
+ my $key;
+ my $sort_method = \&by_category;
+ my $sep = "";
+
+ foreach $key (sort $sort_method keys %map) {
+ if ($key ne " ") {
+ print $sep . $key . "\n";
+ $sep = "\n";
+ }
+ print $map{$key};
+ }
+}
+
+sub trim {
+ my $s = shift;
+ $s =~ s/\s+$//;
+ $s =~ s/^\s+//;
+ return $s;
+}
+
+sub file_input {
+ my $lastline = "";
+ my $case = " ";
+ $map{$case} = "";
+
+ while (<>) {
+ my $line = $_;
+
+ # Pattern line?
+ if ($line =~ m/^([A-Z]):\s*(.*)/) {
+ $line = $1 . ":\t" . trim($2) . "\n";
+ if ($lastline eq "") {
+ $map{$case} = $map{$case} . $line;
+ next;
+ }
+ $case = trim($lastline);
+ exists $map{$case} and die "Header '$case' already exists";
+ $map{$case} = $line;
+ $lastline = "";
+ next;
+ }
+
+ if ($case eq " ") {
+ $map{$case} = $map{$case} . $lastline;
+ $lastline = $line;
+ next;
+ }
+ trim($lastline) eq "" or die ("Odd non-pattern line '$lastline' for '$case'");
+ $lastline = $line;
+ }
+ $map{$case} = $map{$case} . $lastline;
+}
+
+&file_input;
+&alpha_output;
+exit(0);