[RFAv7 1/3] default-args: allow to define default arguments for aliases
Simon Marchi
simark@simark.ca
Sat Jun 20 19:26:18 GMT 2020
Some random comments I noted before I thought about the "set default-args"
problem which I talked about in my response to [0/3].
I got:
Applying: default-args: allow to define default arguments for aliases
.git/rebase-apply/patch:680: trailing whitespace.
if DEFAULT_ARGS is not null, *DEFAULT_ARGS is set to the found command
warning: 1 line adds whitespace errors.
> @@ -1046,6 +1046,32 @@ fput_command_name_styled (struct cmd_list_element *c, struct ui_file *stream)
> If one or more names are printed, POSTFIX is printed after the last name.
> */
>
> +/* Print the definition of alias C using title style for alias
> + and aliased command. */
The comment just above this (we see the end in this hunk) should stay with function fput_command_names_styled.
> +
> +static void
> +fput_alias_definition_styled (struct cmd_list_element *c, struct ui_file *stream)
> +{
> + gdb_assert (c->cmd_pointer != nullptr);
> + fputs_filtered (" alias ", stream);
> + fput_command_name_styled (c, stream);
> + fprintf_filtered (stream, " = ");
> + fput_command_name_styled (c->cmd_pointer, stream);
> + fprintf_filtered (stream, " %s\n", c->default_args.c_str ());
> +}
> +
> +/* Print the definition of the aliases of CMD that have default args. */
> +
> +static void
> +fput_aliases_definition_styled (struct cmd_list_element *cmd, struct ui_file *stream)
> +{
> + if (cmd->aliases != nullptr)
> + for (cmd_list_element *iter = cmd->aliases; iter; iter = iter->alias_chain)
> + if (!iter->default_args.empty ())
> + fput_alias_definition_styled (iter, stream);
When we have nested control structures, the GNU coding style recommends to
use braces for the outer ones:
https://www.gnu.org/prep/standards/html_node/Syntactic-Conventions.html#Syntactic-Conventions
I'd suggest following it, so:
if (...)
{
for (...)
{
if (...)
..
}
}
> @@ -1205,9 +1240,43 @@ help_cmd (const char *command, struct ui_file *stream)
> /* If the user asked 'help somecommand' and there is no alias,
> the false indicates to not output the (single) command name. */
> fput_command_names_styled (c, false, "\n", stream);
> + fput_aliases_definition_styled (c, stream);
> fputs_filtered (c->doc, stream);
> fputs_filtered ("\n", stream);
>
> + if (c->func != nullptr)
> + {
> + /* Print the default args of the command if it has some. Use the
> + lookup_cmd_composition result to find if help was requested for an
> + alias. In this case, rather print the alias default_args. */
> +
> + const char *name;
> + std::string default_args;
Use pointer to std::string to avoid an unnecessary copy?
Simon
More information about the Gdb-patches
mailing list