2010-06-04 05:12:19 -04:00
|
|
|
#!/usr/bin/env perl
|
2008-05-16 00:17:34 -04:00
|
|
|
|
2015-03-09 11:32:01 -04:00
|
|
|
# Copyright (C) 2008, 2009, 2010, 2011, 2015 Free Software Foundation,
|
|
|
|
# Inc.
|
2008-05-16 13:39:35 -04:00
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2008-05-16 00:17:34 -04:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
2009-06-28 16:44:13 -04:00
|
|
|
use constant true => 1;
|
|
|
|
use constant false => 0;
|
2008-05-16 00:17:34 -04:00
|
|
|
|
|
|
|
use FindBin qw($Bin);
|
|
|
|
use File::Spec ();
|
|
|
|
|
2009-07-10 04:29:22 -04:00
|
|
|
my $main_c_file = File::Spec->catfile($Bin, File::Spec->updir, 'src', 'main.c');
|
|
|
|
my $init_c_file = File::Spec->catfile($Bin, File::Spec->updir, 'src', 'init.c');
|
2009-07-11 07:50:52 -04:00
|
|
|
my $tex_file = File::Spec->catfile($Bin, File::Spec->updir, 'doc', 'wget.texi');
|
|
|
|
|
2009-07-10 04:29:22 -04:00
|
|
|
my $main_content = read_file($main_c_file);
|
|
|
|
my $init_content = read_file($init_c_file);
|
2009-07-11 07:50:52 -04:00
|
|
|
my $tex_content = read_file($tex_file);
|
2009-07-10 04:29:22 -04:00
|
|
|
|
2008-05-16 00:17:34 -04:00
|
|
|
my @args = ([
|
2009-07-10 04:29:22 -04:00
|
|
|
$main_content,
|
2011-10-21 16:10:02 -04:00
|
|
|
qr/static \s+? struct \s+? cmdline_option \s+? option_data\[\] \s+? = \s+? \{ (.+?) \}\;/sx,
|
2008-05-16 00:17:34 -04:00
|
|
|
[ qw(long_name short_name type data argtype) ],
|
|
|
|
], [
|
2009-07-10 04:29:22 -04:00
|
|
|
$init_content,
|
2011-10-21 16:10:02 -04:00
|
|
|
qr/commands\[\] \s+? = \s+? \{ (.+?) \}\;/sx,
|
2008-05-16 00:17:34 -04:00
|
|
|
[ qw(name place action) ],
|
|
|
|
]);
|
|
|
|
|
|
|
|
{
|
2009-06-28 16:44:13 -04:00
|
|
|
my @data;
|
|
|
|
|
2008-05-16 00:17:34 -04:00
|
|
|
foreach my $arg (@args) {
|
2009-07-10 04:29:22 -04:00
|
|
|
my ($source, $regex, $names) = @$arg;
|
2009-06-28 16:44:13 -04:00
|
|
|
my @chunks = extract_chunks($source, $regex);
|
|
|
|
push @data, extract_entries(\@chunks, $names);
|
2008-05-16 00:17:34 -04:00
|
|
|
}
|
2009-06-28 16:44:13 -04:00
|
|
|
|
|
|
|
output_results(@data);
|
2008-05-16 00:17:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
sub read_file
|
|
|
|
{
|
|
|
|
my ($file) = @_;
|
2009-06-28 16:44:13 -04:00
|
|
|
|
2008-05-16 00:17:34 -04:00
|
|
|
open(my $fh, '<', $file) or die "Cannot open $file: $!";
|
2009-06-28 16:44:13 -04:00
|
|
|
|
2008-05-16 00:17:34 -04:00
|
|
|
return do { local $/; <$fh> };
|
|
|
|
}
|
|
|
|
|
2009-06-28 16:44:13 -04:00
|
|
|
sub extract_chunks
|
2008-05-16 00:17:34 -04:00
|
|
|
{
|
|
|
|
my ($source, $regex) = @_;
|
2009-06-28 16:44:13 -04:00
|
|
|
|
|
|
|
my ($raw_data) = $source =~ $regex;
|
|
|
|
|
|
|
|
return map { /\S/ && !/^\#/ ? $_ : () } split /(?<=\})/, $raw_data;
|
2008-05-16 00:17:34 -04:00
|
|
|
}
|
|
|
|
|
2009-06-28 16:44:13 -04:00
|
|
|
sub extract_entries
|
2008-05-16 00:17:34 -04:00
|
|
|
{
|
2009-06-28 16:44:13 -04:00
|
|
|
my ($chunks, $names) = @_;
|
|
|
|
|
|
|
|
my (@entries, %index, $i);
|
|
|
|
|
|
|
|
foreach my $chunk (@$chunks) {
|
2011-10-21 16:10:02 -04:00
|
|
|
my ($args) = $chunk =~ /\{ \s+? (.+?) \s+? \}/sx;
|
2008-05-16 00:17:34 -04:00
|
|
|
next unless defined $args;
|
2009-06-28 16:44:13 -04:00
|
|
|
|
|
|
|
my @args = map {
|
|
|
|
tr/'"//d; $_
|
|
|
|
} map {
|
2011-10-21 16:10:02 -04:00
|
|
|
/\((.+?)\)/ ? $1 : $_
|
2009-06-28 16:44:13 -04:00
|
|
|
} split /\,\s+/, $args;
|
|
|
|
|
|
|
|
my $entry = { map { $_ => shift @args } @$names };
|
|
|
|
|
2011-10-21 16:10:02 -04:00
|
|
|
($entry->{line}) = $chunk =~ /^ \s+? (\{.+)/mx;
|
2009-06-28 16:44:13 -04:00
|
|
|
if ($chunk =~ /deprecated/i) {
|
|
|
|
$entries[-1]->{deprecated} = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $index_name = exists $entry->{data}
|
|
|
|
? $entry->{data}
|
|
|
|
: $entry->{name};
|
|
|
|
|
|
|
|
$index{$index_name} = $i++;
|
|
|
|
|
|
|
|
push @entries, $entry;
|
2008-05-16 00:17:34 -04:00
|
|
|
}
|
2009-06-28 16:44:13 -04:00
|
|
|
|
2011-10-21 16:10:02 -04:00
|
|
|
push @entries, { %index };
|
2009-06-28 16:44:13 -04:00
|
|
|
|
2011-10-21 16:10:02 -04:00
|
|
|
return [ @entries ];
|
2008-05-16 00:17:34 -04:00
|
|
|
}
|
|
|
|
|
2009-06-28 16:44:13 -04:00
|
|
|
sub output_results
|
2008-05-16 00:17:34 -04:00
|
|
|
{
|
2009-06-28 16:44:13 -04:00
|
|
|
my ($opts, $cmds) = @_;
|
|
|
|
|
|
|
|
my %index = (
|
|
|
|
opts => pop @$opts,
|
|
|
|
cmds => pop @$cmds,
|
|
|
|
);
|
|
|
|
|
|
|
|
emit_no_corresponding_cmds($opts);
|
|
|
|
print "\n";
|
|
|
|
emit_no_matching_long_cmds($opts);
|
|
|
|
print "\n";
|
|
|
|
emit_no_corresponding_opts($opts, $cmds);
|
2008-05-16 00:17:34 -04:00
|
|
|
print "\n";
|
2009-06-28 16:44:13 -04:00
|
|
|
emit_deprecated_opts($opts);
|
2008-05-16 00:17:34 -04:00
|
|
|
print "\n";
|
2009-06-28 16:44:13 -04:00
|
|
|
emit_deprecated_cmds($cmds);
|
2008-05-16 00:17:34 -04:00
|
|
|
print "\n";
|
2009-06-28 16:44:13 -04:00
|
|
|
|
2009-07-10 04:29:22 -04:00
|
|
|
emit_undocumented_opts($tex_content, $main_content, $opts);
|
2008-05-16 00:17:34 -04:00
|
|
|
print "\n";
|
2009-07-10 04:29:22 -04:00
|
|
|
emit_undocumented_cmds($tex_content, $opts, $cmds, \%index);
|
2008-05-16 00:17:34 -04:00
|
|
|
print "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
sub emit_no_corresponding_cmds
|
|
|
|
{
|
|
|
|
my ($opts) = @_;
|
2009-06-28 16:44:13 -04:00
|
|
|
|
|
|
|
my @options;
|
2008-05-16 00:17:34 -04:00
|
|
|
foreach my $opt (@$opts) {
|
|
|
|
unless ($opt->{type} =~ /^(?:OPT_BOOLEAN|OPT_VALUE)$/
|
|
|
|
&& $opt->{argtype} == -1)
|
|
|
|
{
|
2009-06-28 16:44:13 -04:00
|
|
|
push @options, $opt->{line};
|
2008-05-16 00:17:34 -04:00
|
|
|
}
|
|
|
|
}
|
2009-06-28 16:44:13 -04:00
|
|
|
|
|
|
|
local $" = "\n";
|
|
|
|
print <<EOT;
|
|
|
|
No corresponding commands
|
|
|
|
=========================
|
|
|
|
@options
|
|
|
|
EOT
|
2008-05-16 00:17:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
sub emit_no_matching_long_cmds
|
|
|
|
{
|
|
|
|
my ($opts) = @_;
|
2009-06-28 16:44:13 -04:00
|
|
|
|
|
|
|
my @options;
|
2008-05-16 00:17:34 -04:00
|
|
|
foreach my $opt (@$opts) {
|
|
|
|
my $long_name = $opt->{long_name};
|
|
|
|
$long_name =~ tr/-//d;
|
|
|
|
unless ($long_name eq $opt->{data}) {
|
2009-06-28 16:44:13 -04:00
|
|
|
push @options, $opt->{line};
|
2008-05-16 00:17:34 -04:00
|
|
|
}
|
|
|
|
}
|
2009-06-28 16:44:13 -04:00
|
|
|
|
|
|
|
local $" = "\n";
|
|
|
|
print <<EOT;
|
|
|
|
Non-matching commands
|
|
|
|
=====================
|
|
|
|
@options
|
|
|
|
EOT
|
2008-05-16 00:17:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
sub emit_no_corresponding_opts
|
|
|
|
{
|
|
|
|
my ($opts, $cmds) = @_;
|
2009-06-28 16:44:13 -04:00
|
|
|
|
|
|
|
my @commands;
|
2008-05-16 00:17:34 -04:00
|
|
|
foreach my $cmd (@$cmds) {
|
2009-06-28 16:44:13 -04:00
|
|
|
my $found = false;
|
2008-05-16 00:17:34 -04:00
|
|
|
foreach my $opt (@$opts) {
|
|
|
|
my $long_name = $opt->{long_name};
|
|
|
|
$long_name =~ tr/-//d;
|
|
|
|
if ($cmd->{name} eq $opt->{data}
|
|
|
|
|| $cmd->{name} eq $long_name) {
|
2009-06-28 16:44:13 -04:00
|
|
|
$found = true;
|
2008-05-16 00:17:34 -04:00
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unless ($found) {
|
2009-06-28 16:44:13 -04:00
|
|
|
push @commands, $cmd->{line};
|
2008-05-16 00:17:34 -04:00
|
|
|
}
|
|
|
|
}
|
2009-06-28 16:44:13 -04:00
|
|
|
|
|
|
|
local $" = "\n";
|
|
|
|
print <<EOT;
|
|
|
|
No corresponding options
|
|
|
|
========================
|
|
|
|
@commands
|
|
|
|
EOT
|
2008-05-16 00:17:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
sub emit_deprecated_opts
|
|
|
|
{
|
|
|
|
my ($opts) = @_;
|
2009-06-28 16:44:13 -04:00
|
|
|
|
|
|
|
my @options;
|
|
|
|
foreach my $opt (@$opts) {
|
|
|
|
if ($opt->{deprecated}) {
|
|
|
|
push @options, $opt->{line};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
local $" = "\n";
|
2008-05-16 00:17:34 -04:00
|
|
|
print <<EOT;
|
|
|
|
Deprecated options
|
|
|
|
==================
|
2009-06-28 16:44:13 -04:00
|
|
|
@options
|
2008-05-16 00:17:34 -04:00
|
|
|
EOT
|
|
|
|
}
|
|
|
|
|
|
|
|
sub emit_deprecated_cmds
|
|
|
|
{
|
2009-06-28 16:44:13 -04:00
|
|
|
my ($cmds) = @_;
|
|
|
|
|
|
|
|
my @commands;
|
|
|
|
foreach my $cmd (@$cmds) {
|
|
|
|
if ($cmd->{deprecated}) {
|
|
|
|
push @commands, $cmd->{line};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
local $" = "\n";
|
2008-05-16 00:17:34 -04:00
|
|
|
print <<EOT;
|
|
|
|
Deprecated commands
|
|
|
|
===================
|
2009-06-28 16:44:13 -04:00
|
|
|
@commands
|
|
|
|
EOT
|
|
|
|
}
|
|
|
|
|
2009-07-10 04:29:22 -04:00
|
|
|
sub find_documentation
|
|
|
|
{
|
2009-07-11 07:50:52 -04:00
|
|
|
my ($options, $opt, $tex_items, $main_items) = @_;
|
|
|
|
|
|
|
|
my %found_in;
|
|
|
|
my %items = (
|
|
|
|
tex => $tex_items,
|
|
|
|
main => $main_items,
|
|
|
|
);
|
|
|
|
my $opt_name = $opt->{long_name};
|
2009-07-10 04:29:22 -04:00
|
|
|
|
2009-07-11 07:50:52 -04:00
|
|
|
foreach my $doc_type (qw(tex main)) {
|
|
|
|
my $doc = $items{$doc_type};
|
2009-07-10 04:29:22 -04:00
|
|
|
if ($doc->{$opt_name}
|
|
|
|
|| ($opt_name !~ /^no/ && $doc->{"no-$opt_name"})) {
|
2009-07-11 07:50:52 -04:00
|
|
|
$found_in{$doc_type} = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$found_in{$doc_type} = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (scalar grep { $_ == false } values %found_in) {
|
|
|
|
push @$options, {
|
|
|
|
name => $opt_name,
|
|
|
|
tex => $found_in{tex},
|
|
|
|
main => $found_in{main},
|
2009-07-10 04:29:22 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-28 16:44:13 -04:00
|
|
|
sub emit_undocumented_opts
|
|
|
|
{
|
2009-07-10 04:29:22 -04:00
|
|
|
my ($tex, $main, $opts) = @_;
|
2009-06-28 16:44:13 -04:00
|
|
|
|
2009-07-10 04:29:22 -04:00
|
|
|
my (%tex_items, %main_items);
|
2009-07-11 07:50:52 -04:00
|
|
|
while ($tex =~ /^\@item\w*? \s+? --([-a-z0-9]+)/gmx) {
|
2009-07-10 04:29:22 -04:00
|
|
|
$tex_items{$1} = true;
|
|
|
|
}
|
2011-10-21 16:10:02 -04:00
|
|
|
my ($help) = $main =~ /\n print_help .*? \{\n (.+) \n\} \n/sx;
|
2009-07-11 07:50:52 -04:00
|
|
|
while ($help =~ /--([-a-z0-9]+)/g) {
|
2009-07-10 04:29:22 -04:00
|
|
|
$main_items{$1} = true;
|
2009-06-28 16:44:13 -04:00
|
|
|
}
|
2009-07-11 07:50:52 -04:00
|
|
|
|
2009-06-28 16:44:13 -04:00
|
|
|
my @options;
|
|
|
|
foreach my $opt (@$opts) {
|
2009-07-11 07:50:52 -04:00
|
|
|
next if $opt->{deprecated};
|
|
|
|
find_documentation(\@options, $opt, \%tex_items, \%main_items);
|
2009-06-28 16:44:13 -04:00
|
|
|
}
|
|
|
|
|
2009-07-11 07:50:52 -04:00
|
|
|
my ($opt, $not_found_in);
|
|
|
|
|
|
|
|
format STDOUT_TOP =
|
2009-07-10 04:29:22 -04:00
|
|
|
Undocumented options Not In:
|
|
|
|
==================== ==================
|
2009-07-11 07:50:52 -04:00
|
|
|
.
|
|
|
|
|
|
|
|
format STDOUT =
|
|
|
|
@<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<
|
|
|
|
$opt->{name}, $not_found_in
|
|
|
|
.
|
|
|
|
foreach $opt (@options) {
|
|
|
|
$not_found_in = join ' ', (
|
|
|
|
! $opt->{tex} ? 'texinfo' : (),
|
|
|
|
!($opt->{tex} || $opt->{main}) ? 'nor' : (),
|
|
|
|
! $opt->{main} ? '--help' : (),
|
|
|
|
);
|
|
|
|
write;
|
2009-07-10 04:29:22 -04:00
|
|
|
}
|
2009-06-28 16:44:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
sub emit_undocumented_cmds
|
|
|
|
{
|
|
|
|
my ($tex, $opts, $cmds, $index) = @_;
|
|
|
|
|
|
|
|
my %items;
|
2009-07-11 07:50:52 -04:00
|
|
|
while ($tex =~ /^\@item\w*? \s+? ([_a-z0-9]+) \s+? = \s+? \S+?/gmx) {
|
2009-06-28 16:44:13 -04:00
|
|
|
my $cmd = $1;
|
|
|
|
$cmd =~ tr/_//d;
|
|
|
|
$items{$cmd} = true;
|
|
|
|
}
|
|
|
|
my @commands;
|
2008-05-16 00:17:34 -04:00
|
|
|
foreach my $cmd (@$cmds) {
|
2009-06-28 16:44:13 -04:00
|
|
|
my $cmd_name = do {
|
|
|
|
local $_ = exists $index->{opts}->{$cmd->{name}}
|
|
|
|
? $opts->[$index->{opts}->{$cmd->{name}}]->{long_name}
|
|
|
|
: $cmd->{name};
|
|
|
|
tr/-/_/;
|
|
|
|
$_;
|
|
|
|
};
|
|
|
|
if (not $items{$cmd->{name}} || $cmd->{deprecated}) {
|
|
|
|
push @commands, $cmd_name;
|
2008-05-16 00:17:34 -04:00
|
|
|
}
|
|
|
|
}
|
2009-06-28 16:44:13 -04:00
|
|
|
|
|
|
|
local $" = "\n";
|
|
|
|
print <<EOT;
|
|
|
|
Undocumented commands
|
|
|
|
=====================
|
|
|
|
@commands
|
|
|
|
EOT
|
2008-05-16 00:17:34 -04:00
|
|
|
}
|