diff mbox

print help for undocumented options

Message ID 561E8DF1.7070909@gmail.com
State New
Headers show

Commit Message

Martin Sebor Oct. 14, 2015, 5:16 p.m. UTC
Gcc's online help (the output of gcc --help -v) includes a large
number of undocumented options (197 in 5.1.0).  For example, the
section listing language-related options starts with the following
and another 44 or so undocumented options:

   The following options are language-related:
     --all-warnings           This switch lacks documentation
     --ansi                   This switch lacks documentation
     --assert                 This switch lacks documentation
     ...

It turns out that all of those in the section above and a good
number of others are synonyms for other options that are in fact
documented.  Rather than duplicating the documentation for the
alternate options, the small patchlet below modifies the
print_filtered_help function to print the help for the documented
alias along with its name.  With it applied, the number of options
that "lack documentation" drops to 114, and the section above looks
like this:

   The following options are language-related:
     --all-warnings           Enable most warning messages.  Same
                              as -Wall
     --ansi                   A synonym for -std=c89 (for C) or
                              -std=c++98 (for C++).  Same as -ansi
     -A<question>=<answer>    Assert the <answer> to <question>.
                              Putting '-' before <question> disables
                              the <answer> to <question>.  Same as -A
     -A<question>=<answer>    Assert the <answer> to <question>.
                              Putting '-' before <question> disables
                              the <answer> to <question>.  Same as -A

2015-10-14  Martin Sebor  <msebor@redhat.com>

	* options.c (print_filtered_help): Print help for aliased
	option and its name instead of undocumented text for
	undocumented options.

Comments

Joseph Myers Oct. 14, 2015, 5:24 p.m. UTC | #1
On Wed, 14 Oct 2015, Martin Sebor wrote:

> +             /* For undocumented options that are aliases for other
> +                options that are documented, print the other option's
> +                help and name.  */
> +             help = cl_options [option->alias_target].help;
> +
> +             snprintf (new_help, sizeof new_help, "%s", help);
> +             snprintf (new_help + strlen (new_help),
> +                       sizeof new_help - strlen (new_help),
> +                       ".  Same as %s",
> +                       cl_options [option->alias_target].opt_text);

Obviously this English string needs to be marked for translation.

There is no consistency about whether option descriptions in .opt files 
end with ".", so this might produce "..  Same as" in some cases.  While I 
think the .opt files should be made consistent, I also think it would be 
better just to give the "Same as" message without also repeating the 
description of the canonical option.
diff mbox

Patch

diff --git a/gcc/opts.c b/gcc/opts.c
index 2bbf653..e441924 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -1010,7 +1010,7 @@  print_filtered_help (unsigned int include_flags,
    const char *help;
    bool found = false;
    bool displayed = false;
-  char new_help[128];
+  char new_help[256];

    if (include_flags == CL_PARAMS)
      {
@@ -1086,6 +1086,23 @@  print_filtered_help (unsigned int include_flags,
         {
           if (exclude_flags & CL_UNDOCUMENTED)
             continue;
+
+         if (option->alias_target < N_OPTS
+             && cl_options [option->alias_target].help)
+           {
+             /* For undocumented options that are aliases for other
+                options that are documented, print the other option's
+                help and name.  */
+             help = cl_options [option->alias_target].help;
+
+             snprintf (new_help, sizeof new_help, "%s", help);
+             snprintf (new_help + strlen (new_help),
+                       sizeof new_help - strlen (new_help),
+                       ".  Same as %s",
+                       cl_options [option->alias_target].opt_text);
+             help = new_help;
+           }
+         else
             help = undocumented_msg;
         }