reindex.pl 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/usr/bin/perl -w
  2. # Copyright 2007 Nick Mathewson. See LICENSE for licensing information.
  3. use strict;
  4. my $propdir = ".";
  5. local *DIR;
  6. local *F;
  7. opendir(DIR, $propdir) || die "Can't open $propdir";
  8. my @files = sort grep { /^\d\d\d-.*[^\~]$/ } readdir(DIR);
  9. closedir DIR;
  10. my %title = ();
  11. my %status = ();
  12. my @KNOWN_STATUSES = qw{
  13. OPEN ACCEPTED NEEDS-RESEARCH META FINISHED CLOSED SUPERSEDED DEAD DRAFT};
  14. for my $f (@files) {
  15. my $num = substr($f, 0, 3);
  16. my $status = undef;
  17. my $title = undef;
  18. open(F, "$f");
  19. while (<F>) {
  20. last if (/^\s*$/);
  21. if (/^Status: (.*)/) {
  22. $status = uc $1;
  23. chomp $status;
  24. }
  25. if (/^Title: (.*)/) {
  26. $title = $1;
  27. $title =~ s/\.$//;
  28. chomp $title;
  29. }
  30. }
  31. close F;
  32. die "I've never heard of status $status in proposal $num"
  33. unless (grep(/$status/, @KNOWN_STATUSES) == 1);
  34. die "Proposal $num has a bad status line" if (!defined $status);
  35. die "Proposal $num has a bad title line" if (!defined $title);
  36. $title{$num} = $title;
  37. $status{$num} = $status;
  38. }
  39. local *OUT;
  40. open(OUT, ">000-index.txt.tmp");
  41. open(F, "000-index.txt") or die "Can't open index file.";
  42. while (<F>) {
  43. print OUT;
  44. last if (/^={3,}/);
  45. }
  46. close(F);
  47. print OUT "Proposals by number:\n\n";
  48. for my $num (sort keys %title) {
  49. print OUT "$num $title{$num} [$status{$num}]\n";
  50. }
  51. print OUT "\n\nProposals by status:\n\n";
  52. for my $status (@KNOWN_STATUSES) {
  53. print OUT " $status:\n";
  54. for my $num (sort keys %status) {
  55. next unless ($status{$num} eq $status);
  56. print OUT " $num $title{$num}\n";
  57. }
  58. }
  59. rename('000-index.txt.tmp', '000-index.txt');