tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

checkOptionDocs.pl.in (1927B)


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