Remove grub_commands_iterate

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2010-03-26 19:14:24 +01:00
parent e4ff66281a
commit d85da27cc0
3 changed files with 82 additions and 99 deletions

View file

@ -33,10 +33,10 @@ grub_cmd_help (grub_extcmd_t ext __attribute__ ((unused)), int argc,
int cnt = 0;
char *currarg;
auto int print_command_info (grub_command_t cmd);
auto int print_command_help (grub_command_t cmd);
int print_command_info (grub_command_t cmd)
if (argc == 0)
{
grub_command_t cmd;
FOR_COMMANDS(cmd)
{
if ((cmd->prio & GRUB_PRIO_LIST_FLAG_ACTIVE) &&
(cmd->flags & GRUB_COMMAND_FLAG_CMDLINE))
@ -49,7 +49,7 @@ grub_cmd_help (grub_extcmd_t ext __attribute__ ((unused)), int argc,
command_help = grub_xasprintf ("%s %s", cmd->name, summary_translated);
if (!command_help)
return 1;
break;
grub_utf8_to_ucs4_alloc (command_help, &unicode_command_help,
&unicode_last_position);
@ -85,10 +85,19 @@ grub_cmd_help (grub_extcmd_t ext __attribute__ ((unused)), int argc,
grub_free (command_help);
grub_free (unicode_command_help);
}
return 0;
}
if (!(cnt % 2))
grub_printf ("\n");
}
else
{
int i;
grub_command_t cmd;
int print_command_help (grub_command_t cmd)
for (i = 0; i < argc; i++)
{
currarg = args[i];
FOR_COMMANDS(cmd)
{
if (cmd->prio & GRUB_PRIO_LIST_FLAG_ACTIVE)
{
@ -104,23 +113,7 @@ grub_cmd_help (grub_extcmd_t ext __attribute__ ((unused)), int argc,
_(cmd->description));
}
}
return 0;
}
if (argc == 0)
{
grub_command_iterate (print_command_info);
if (!(cnt % 2))
grub_printf ("\n");
}
else
{
int i;
for (i = 0; i < argc; i++)
{
currarg = args[i];
grub_command_iterate (print_command_help);
}
}

View file

@ -115,12 +115,7 @@ grub_command_execute (const char *name, int argc, char **argv)
return (cmd) ? cmd->func (cmd, argc, argv) : GRUB_ERR_FILE_NOT_FOUND;
}
static inline int
grub_command_iterate (int (*func) (grub_command_t))
{
return grub_list_iterate (GRUB_AS_LIST (grub_command_list),
(grub_list_hook_t) func);
}
#define FOR_COMMANDS(var) for ((var) = grub_command_list; (var); (var) = (var)->next)
void grub_register_core_commands (void);

View file

@ -176,21 +176,6 @@ iterate_dev (const char *devname)
return 0;
}
static int
iterate_command (grub_command_t cmd)
{
if (cmd->prio & GRUB_PRIO_LIST_FLAG_ACTIVE)
{
if (cmd->flags & GRUB_COMMAND_FLAG_CMDLINE)
{
if (add_completion (cmd->name, " ", GRUB_COMPLETION_TYPE_COMMAND))
return 1;
}
}
return 0;
}
/* Complete a device. */
static int
complete_device (void)
@ -421,9 +406,19 @@ grub_normal_do_completion (char *buf, int *restore,
if (argc == 1 || argc == 0)
{
/* Complete a command. */
if (grub_command_iterate (iterate_command))
grub_command_t cmd;
FOR_COMMANDS(cmd)
{
if (cmd->prio & GRUB_PRIO_LIST_FLAG_ACTIVE)
{
if (cmd->flags & GRUB_COMMAND_FLAG_CMDLINE)
{
if (add_completion (cmd->name, " ", GRUB_COMPLETION_TYPE_COMMAND))
goto fail;
}
}
}
}
else if (*current_word == '-')
{
if (complete_arguments (buf))