]> sjero.net Git - wget/blobdiff - util/paramcheck.pl
mass change: update copyright years.
[wget] / util / paramcheck.pl
index bc6b8cfdfb8efcda88404f60020ab587638c449a..832f5dc7d6093e1f86e2020c83c816b7ab22258a 100755 (executable)
@@ -1,6 +1,6 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
 
-# Copyright (C) 2008, 2009 Free Software Foundation, Inc.
+# Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
 
 # 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
@@ -23,23 +23,29 @@ use constant false => 0;
 use FindBin qw($Bin);
 use File::Spec ();
 
+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');
+my $tex_file    = File::Spec->catfile($Bin, File::Spec->updir, 'doc', 'wget.texi');
+
+my $main_content = read_file($main_c_file);
+my $init_content = read_file($init_c_file);
+my $tex_content  = read_file($tex_file);
+
 my @args = ([
-    File::Spec->catfile($Bin, File::Spec->updir, 'src', 'main.c'),
+    $main_content,
     qr/static \s+? struct \s+? cmdline_option \s+? option_data\[\] \s+? = \s+? \{ (.*?) \}\;/sx,
     [ qw(long_name short_name type data argtype) ],
 ], [
-    File::Spec->catfile($Bin, File::Spec->updir, 'src', 'init.c'),
+    $init_content,
     qr/commands\[\] \s+? = \s+? \{ (.*?) \}\;/sx,
     [ qw(name place action) ],
 ]);
-my $tex_file = File::Spec->catfile($Bin, File::Spec->updir, 'doc', 'wget.texi');
 
 {
     my @data;
 
     foreach my $arg (@args) {
-        my ($file, $regex, $names) = @$arg;
-        my $source = read_file($file);
+        my ($source, $regex, $names) = @$arg;
         my @chunks = extract_chunks($source, $regex);
         push @data, extract_entries(\@chunks, $names);
     }
@@ -122,11 +128,9 @@ sub output_results
     emit_deprecated_cmds($cmds);
     print "\n";
 
-    my $tex = read_file($tex_file);
-
-    emit_undocumented_opts($tex, $opts);
+    emit_undocumented_opts($tex_content, $main_content, $opts);
     print "\n";
-    emit_undocumented_cmds($tex, $opts, $cmds, \%index);
+    emit_undocumented_cmds($tex_content, $opts, $cmds, \%index);
     print "\n";
 }
 
@@ -239,34 +243,74 @@ Deprecated commands
 EOT
 }
 
+sub find_documentation
+{
+    my ($options, $opt, $tex_items, $main_items) = @_;
+
+    my %found_in;
+    my %items = (
+        tex  => $tex_items,
+        main => $main_items,
+    );
+    my $opt_name = $opt->{long_name};
+
+    foreach my $doc_type (qw(tex main)) {
+        my $doc = $items{$doc_type};
+        if ($doc->{$opt_name}
+            || ($opt_name !~ /^no/ && $doc->{"no-$opt_name"})) {
+            $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},
+        }
+    }
+}
+
 sub emit_undocumented_opts
 {
-    my ($tex, $opts) = @_;
+    my ($tex, $main, $opts) = @_;
 
-    my %items;
-    while ($tex =~ /^\@item\w*? \s+? --([\w\-]+)/gmx) {
-        my $opt = $1;
-        $items{$opt} = true;
+    my (%tex_items, %main_items);
+    while ($tex =~ /^\@item\w*? \s+? --([-a-z0-9]+)/gmx) {
+        $tex_items{$1} = true;
     }
+    my ($help) = $main =~ /\n print_help .*? \{\n (.*) \n\} \n/sx;
+    while ($help =~ /--([-a-z0-9]+)/g) {
+        $main_items{$1} = true;
+    }
+
     my @options;
     foreach my $opt (@$opts) {
-        my $opt_name = $opt->{long_name};
-        if (not $items{$opt_name}
-          || ($opt_name !~ /^no/
-            ? $items{"no-$opt_name"}
-            : false)
-          || $opt->{deprecated})
-        {
-            push @options, $opt_name;
-        }
+        next if $opt->{deprecated};
+        find_documentation(\@options, $opt, \%tex_items, \%main_items);
     }
 
-    local $" = "\n";
-    print <<EOT;
-Undocumented options
-====================
-@options
-EOT
+    my ($opt, $not_found_in);
+
+format STDOUT_TOP =
+Undocumented options          Not In:
+====================          ==================
+.
+
+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;
+    }
 }
 
 sub emit_undocumented_cmds
@@ -274,7 +318,7 @@ sub emit_undocumented_cmds
     my ($tex, $opts, $cmds, $index) = @_;
 
     my %items;
-    while ($tex =~ /^\@item\w*? \s+? ([\w\_]+) \s+? = \s+? \S+?/gmx) {
+    while ($tex =~ /^\@item\w*? \s+? ([_a-z0-9]+) \s+? = \s+? \S+?/gmx) {
         my $cmd = $1;
         $cmd =~ tr/_//d;
         $items{$cmd} = true;