checkOptionDocs.pl 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. } else {
  20. print "Unrecognized output> ";
  21. print;
  22. }
  23. }
  24. close F;
  25. # Load the contents of torrc.sample and torrc.complete
  26. sub loadTorrc {
  27. my ($fname, $options) = @_;
  28. local *F;
  29. open(F, "$fname") or die;
  30. while (<F>) {
  31. next if (m!##+!);
  32. if (m!#([A-Za-z0-9_]+)!) {
  33. $options->{lc $1} = 1;
  34. }
  35. }
  36. close F;
  37. 0;
  38. }
  39. loadTorrc("./src/config/torrc.sample.in", \%torrcSampleOptions);
  40. loadTorrc("./src/config/torrc.complete.in", \%torrcCompleteOptions);
  41. # Try to figure out what's in the man page.
  42. my $considerNextLine = 0;
  43. open(F, "./doc/tor.1.in") or die;
  44. while (<F>) {
  45. if ($considerNextLine and
  46. m!^\\fB([A-Za-z0-9_]+)!) {
  47. $manPageOptions{lc $1} = 1;
  48. }
  49. if (m!^\.(?:SH|TP)!) {
  50. $considerNextLine = 1; next;
  51. } else {
  52. $considerNextLine = 0;
  53. }
  54. }
  55. close F;
  56. # Now, display differences:
  57. sub subtractHashes {
  58. my ($s, $a, $b) = @_;
  59. my @lst = ();
  60. for my $k (keys %$a) {
  61. push @lst, $k unless (exists $b->{$k});
  62. }
  63. print "$s: ", join(' ', sort @lst), "\n\n";
  64. 0;
  65. }
  66. subtractHashes("No online docs", \%options, \%descOptions);
  67. # subtractHashes("Orphaned online docs", \%descOptions, \%options);
  68. subtractHashes("Not in torrc.complete.in", \%options, \%torrcCompleteOptions);
  69. subtractHashes("Orphaned in torrc.complete.in", \%torrcCompleteOptions, \%options);
  70. subtractHashes("Orphaned in torrc.sample.in", \%torrcSampleOptions, \%options);
  71. subtractHashes("Not in man page", \%options, \%manPageOptions);
  72. subtractHashes("Orphaned in man page", \%manPageOptions, \%options);