reindex.pl 1.7 KB

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