reindex.pl 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. if ($f !~ /\.txt/) { print "$f doesn't end with .txt\n"; }
  19. open(F, "$f");
  20. while (<F>) {
  21. last if (/^\s*$/);
  22. if (/^Status: (.*)/) {
  23. $status = uc $1;
  24. chomp $status;
  25. }
  26. if (/^Title: (.*)/) {
  27. $title = $1;
  28. $title =~ s/\.$//;
  29. chomp $title;
  30. }
  31. }
  32. close F;
  33. die "I've never heard of status $status in proposal $num"
  34. unless (grep(/$status/, @KNOWN_STATUSES) == 1);
  35. die "Proposal $num has a bad status line" if (!defined $status);
  36. die "Proposal $num has a bad title line" if (!defined $title);
  37. $title{$num} = $title;
  38. $status{$num} = $status;
  39. }
  40. local *OUT;
  41. open(OUT, ">000-index.txt.tmp");
  42. open(F, "000-index.txt") or die "Can't open index file.";
  43. while (<F>) {
  44. print OUT;
  45. last if (/^={3,}/);
  46. }
  47. close(F);
  48. print OUT "Proposals by number:\n\n";
  49. for my $num (sort keys %title) {
  50. print OUT "$num $title{$num} [$status{$num}]\n";
  51. }
  52. print OUT "\n\nProposals by status:\n\n";
  53. for my $status (@KNOWN_STATUSES) {
  54. print OUT " $status:\n";
  55. for my $num (sort keys %status) {
  56. next unless ($status{$num} eq $status);
  57. print OUT " $num $title{$num}\n";
  58. }
  59. }
  60. rename('000-index.txt.tmp', '000-index.txt');