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:
okuji 2005-03-08 01:01:06 +00:00
parent 7b1f4b5715
commit 5822ff87a2
9 changed files with 297 additions and 115 deletions

View file

@ -1,7 +1,7 @@
/* normal.h - prototypes for the normal mode */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2003 Free Software Foundation, Inc.
* Copyright (C) 2002,2003,2005 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -41,12 +41,14 @@
#define GRUB_COMMAND_FLAG_NO_ECHO 0x8
/* Don't print the command on booting. */
#define GRUB_COMMAND_FLAG_NO_ARG_PARSE 0x10
/* Not loaded yet. Used for auto-loading. */
#define GRUB_COMMAND_FLAG_NOT_LOADED 0x20
/* The command description. */
struct grub_command
{
/* The name. */
const char *name;
char *name;
/* The callback function. */
grub_err_t (*func) (struct grub_arg_list *state, int argc, char **args);
@ -63,6 +65,9 @@ struct grub_command
/* The argument parser optionlist. */
const struct grub_arg_option *options;
/* The name of a module. Used for auto-loading. */
char *module_name;
/* The next element. */
struct grub_command *next;
};
@ -142,13 +147,14 @@ void grub_menu_entry_run (grub_menu_entry_t entry);
void grub_cmdline_run (int nested);
int grub_cmdline_get (const char *prompt, char cmdline[], unsigned max_len,
int echo_char, int readline);
void grub_register_command (const char *name,
grub_err_t (*func) (struct grub_arg_list *state,
int argc, char **args),
unsigned flags,
const char *summary,
const char *description,
const struct grub_arg_option *parser);
grub_command_t grub_register_command (const char *name,
grub_err_t (*func) (struct grub_arg_list *state,
int argc,
char **args),
unsigned flags,
const char *summary,
const char *description,
const struct grub_arg_option *parser);
void grub_unregister_command (const char *name);
grub_command_t grub_command_find (char *cmdline);
grub_err_t grub_set_history (int newsize);