parse-maintainers.pl 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/perl -w
  2. use strict;
  3. my %map;
  4. # sort comparison function
  5. sub by_category($$) {
  6. my ($a, $b) = @_;
  7. $a = uc $a;
  8. $b = uc $b;
  9. # This always sorts last
  10. $a =~ s/THE REST/ZZZZZZ/g;
  11. $b =~ s/THE REST/ZZZZZZ/g;
  12. $a cmp $b;
  13. }
  14. sub alpha_output {
  15. my $key;
  16. my $sort_method = \&by_category;
  17. my $sep = "";
  18. foreach $key (sort $sort_method keys %map) {
  19. if ($key ne " ") {
  20. print $sep . $key . "\n";
  21. $sep = "\n";
  22. }
  23. print $map{$key};
  24. }
  25. }
  26. sub trim {
  27. my $s = shift;
  28. $s =~ s/\s+$//;
  29. $s =~ s/^\s+//;
  30. return $s;
  31. }
  32. sub file_input {
  33. my $lastline = "";
  34. my $case = " ";
  35. $map{$case} = "";
  36. while (<>) {
  37. my $line = $_;
  38. # Pattern line?
  39. if ($line =~ m/^([A-Z]):\s*(.*)/) {
  40. $line = $1 . ":\t" . trim($2) . "\n";
  41. if ($lastline eq "") {
  42. $map{$case} = $map{$case} . $line;
  43. next;
  44. }
  45. $case = trim($lastline);
  46. exists $map{$case} and die "Header '$case' already exists";
  47. $map{$case} = $line;
  48. $lastline = "";
  49. next;
  50. }
  51. if ($case eq " ") {
  52. $map{$case} = $map{$case} . $lastline;
  53. $lastline = $line;
  54. next;
  55. }
  56. trim($lastline) eq "" or die ("Odd non-pattern line '$lastline' for '$case'");
  57. $lastline = $line;
  58. }
  59. $map{$case} = $map{$case} . $lastline;
  60. }
  61. &file_input;
  62. &alpha_output;
  63. exit(0);