2005-03-08 Yoshinori Okuji <okuji@enbug.org>
Automatic loading of commands is supported. * normal/main.c (read_command_list): New function. (grub_normal_execute): Call read_command_list. * normal/command.c (grub_register_command): Return zero or CMD. Allocate CMD->NAME from the heap. Initialize CMD->MODULE_NAME to zero. Find the same name as well. If the same command is found and it is a dummy command, overwrite members. If it is not a dummy command, return zero. (grub_unregister_command): Free Q->NAME and Q->MODULE_NAME. (grub_command_find): If a dummy command is found, load a module and retry to find a command only once. * normal/cmdline.c (grub_tab_complete): Call grub_command_find to make sure that each command is loaded. * include/grub/normal.h (GRUB_COMMAND_FLAG_NOT_LOADED): New macro. (struct grub_command): Remove const from the member `name'. Add a new member `module_name'. (grub_register_command): Return grub_command_t. * commands/help.c (grub_cmd_help): Call grub_command_find to make sure that each command is loaded. * genmk.rb (PModule::rule): Specify a module name without the suffix ".mod" to gencmdlist.sh.
This commit is contained in:
parent
7b1f4b5715
commit
5822ff87a2
9 changed files with 297 additions and 115 deletions
|
@ -304,6 +304,69 @@ grub_normal_init_page (void)
|
|||
PACKAGE_VERSION);
|
||||
}
|
||||
|
||||
/* Read the file command.lst for auto-loading. */
|
||||
static void
|
||||
read_command_list (void)
|
||||
{
|
||||
const char *prefix;
|
||||
|
||||
prefix = grub_env_get ("prefix");
|
||||
if (prefix)
|
||||
{
|
||||
char *filename;
|
||||
|
||||
filename = grub_malloc (grub_strlen (prefix) + sizeof ("/command.lst"));
|
||||
if (filename)
|
||||
{
|
||||
grub_file_t file;
|
||||
|
||||
grub_sprintf (filename, "%s/command.lst", prefix);
|
||||
file = grub_file_open (filename);
|
||||
if (file)
|
||||
{
|
||||
char buf[80]; /* XXX arbitrary */
|
||||
|
||||
while (get_line (file, buf, sizeof (buf)))
|
||||
{
|
||||
char *p;
|
||||
grub_command_t cmd;
|
||||
|
||||
if (! grub_isgraph (buf[0]))
|
||||
continue;
|
||||
|
||||
p = grub_strchr (buf, ':');
|
||||
if (! p)
|
||||
continue;
|
||||
|
||||
*p = '\0';
|
||||
while (*++p == ' ')
|
||||
;
|
||||
|
||||
if (! grub_isgraph (*p))
|
||||
continue;
|
||||
|
||||
cmd = grub_register_command (buf, 0,
|
||||
GRUB_COMMAND_FLAG_NOT_LOADED,
|
||||
0, 0, 0);
|
||||
if (! cmd)
|
||||
continue;
|
||||
|
||||
cmd->module_name = grub_strdup (p);
|
||||
if (! cmd->module_name)
|
||||
grub_unregister_command (buf);
|
||||
}
|
||||
|
||||
grub_file_close (file);
|
||||
}
|
||||
|
||||
grub_free (filename);
|
||||
}
|
||||
}
|
||||
|
||||
/* Ignore errors. */
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
/* Read the config file CONFIG and execute the menu interface or
|
||||
the command-line interface. */
|
||||
void
|
||||
|
@ -319,6 +382,8 @@ grub_normal_execute (const char *config, int nested)
|
|||
grub_errno = GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
read_command_list ();
|
||||
|
||||
if (menu)
|
||||
{
|
||||
grub_menu_run (menu, nested);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue