On 10/14/2015 11:24 AM, Joseph Myers wrote:
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.
Thanks for the quick review.
I tweaked the patch to work around the .opt file inconsistency and
always print a period (the driver itself doesn't print one but that
can be fixed if/once we agree that this is a good way to deal with
it). I also annotated the "Same as" text so that it can be
translated.
IMO, printing the aliased option's help text makes using the output
easier for users who find the undocumented option first, in that
they don't then have to go look for the one that does have
documentation, so I left that part in place. If you or someone
feels strongly that it shouldn't be there I'll remove it.
Let me know your thoughts on this version.
Martin
2015-10-14 Martin Sebor <mse...@redhat.com>
* options.c (wrap_help): End last sentence in a period.
(print_filtered_help): Print help for aliased option and its name
instead of undocumented text for undocumented options.
--git a/gcc/opts.c b/gcc/opts.c
index 2bbf653..7debf33 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -960,9 +960,19 @@ wrap_help (const char *help,
{
unsigned int col_width = LEFT_COLUMN;
unsigned int remaining, room, len;
+ char *new_help = NULL;
remaining = strlen (help);
-
+ if (remaining && help [remaining - 1] != '.')
+ {
+ /* Help text in .opt files doesn't always end in a period. Make
+ it constistent by appending a period when it's missing. */
+ new_help = XNEWVEC (char, remaining + 2);
+ memcpy (new_help, help, remaining);
+ new_help [remaining++] = '.';
+ new_help [remaining] = '\0';
+ help = new_help;
+ }
do
{
room = columns - 3 - MAX (col_width, item_width);
@@ -995,6 +1005,9 @@ wrap_help (const char *help,
remaining -= len;
}
while (remaining);
+
+ /* Free the help text allocated by this function. */
+ XDELETEVEC (const_cast<char*>(new_help));
}
/* Print help for a specific front-end, etc. */
@@ -1010,7 +1023,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,9 +1099,41 @@ 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;
+
+ const char *alias_text =
+ cl_options [option->alias_target].opt_text;
+
+ /* End the alias help with a period if it doesn't. */
+ const char *maybe_period =
+ alias_text [strlen (alias_text) - 1] == '.' ? "" : ".";
+
+ snprintf (new_help, sizeof new_help, "%s", help);
+ snprintf (new_help + strlen (new_help),
+ sizeof new_help - strlen (new_help),
+ _("%s Same as %s"),
+ maybe_period,
+ cl_options [option->alias_target].opt_text);
+ help = new_help;
+ }
+ else
help = undocumented_msg;
}
+ if (option->warn_message)
+ {
+ snprintf (new_help, sizeof new_help, ">>>%s<<<",
+ option->warn_message);
+ help = new_help;
+ }
+
/* Get the translation. */
help = _(help);