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