checkOptionDocs.pl 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/usr/bin/perl -w
  2. # $Id
  3. use strict;
  4. my %options = ();
  5. my %descOptions = ();
  6. my %torrcSampleOptions = ();
  7. my %torrcCompleteOptions = ();
  8. my %manPageOptions = ();
  9. # Load the canonical list as actually accepted by Tor.
  10. my $mostRecentOption;
  11. open(F, "./src/or/tor --list-torrc-options |") or die;
  12. while (<F>) {
  13. next if m!\[notice\] Tor v0\.!;
  14. if (m!^([A-Za-z0-9_]+)!) {
  15. $mostRecentOption = lc $1;
  16. $options{$mostRecentOption} = 1;
  17. } elsif (m!^ !) {
  18. $descOptions{$mostRecentOption} = 1;
  19. if (m!\{DEPRECATED\}!) {
  20. delete $descOptions{$mostRecentOption};
  21. delete $options{$mostRecentOption};
  22. }
  23. } else {
  24. print "Unrecognized output> ";
  25. print;
  26. }
  27. }
  28. close F;
  29. # Load the contents of torrc.sample and torrc.complete
  30. sub loadTorrc {
  31. my ($fname, $options) = @_;
  32. local *F;
  33. open(F, "$fname") or die;
  34. while (<F>) {
  35. next if (m!##+!);
  36. if (m!#([A-Za-z0-9_]+)!) {
  37. $options->{lc $1} = 1;
  38. }
  39. }
  40. close F;
  41. 0;
  42. }
  43. loadTorrc("./src/config/torrc.sample.in", \%torrcSampleOptions);
  44. loadTorrc("./src/config/torrc.complete.in", \%torrcCompleteOptions);
  45. # Try to figure out what's in the man page.
  46. my $considerNextLine = 0;
  47. open(F, "./doc/tor.1.in") or die;
  48. while (<F>) {
  49. if ($considerNextLine and
  50. m!^\\fB([A-Za-z0-9_]+)!) {
  51. $manPageOptions{lc $1} = 1;
  52. next;
  53. }
  54. if (m!^\.(?:SH|TP|PP)!) {
  55. $considerNextLine = 1; next;
  56. } else {
  57. $considerNextLine = 0;
  58. }
  59. }
  60. close F;
  61. # Now, display differences:
  62. sub subtractHashes {
  63. my ($s, $a, $b) = @_;
  64. my @lst = ();
  65. for my $k (keys %$a) {
  66. push @lst, $k unless (exists $b->{$k});
  67. }
  68. print "$s: ", join(' ', sort @lst), "\n\n";
  69. 0;
  70. }
  71. subtractHashes("No online docs", \%options, \%descOptions);
  72. # subtractHashes("Orphaned online docs", \%descOptions, \%options);
  73. subtractHashes("Not in torrc.complete.in", \%options, \%torrcCompleteOptions);
  74. subtractHashes("Orphaned in torrc.complete.in", \%torrcCompleteOptions, \%options);
  75. subtractHashes("Orphaned in torrc.sample.in", \%torrcSampleOptions, \%options);
  76. subtractHashes("Not in man page", \%options, \%manPageOptions);
  77. subtractHashes("Orphaned in man page", \%manPageOptions, \%options);