2006-01-17 Marco Gerards <marco@gnu.org>

* include/grub/normal.h: Include <grub/script.h>.
	(grub_command_list): Removed struct.
	(grub_command_list_t): Removed type.
	(grub_menu_entry): Remove members `num' and `command_list'.  Add
	members `commands' and `sourcecode'.
	* include/grub/script.h: Add inclusion guards.
	(grub_script_cmd_menuentry): New struct.
	(grub_script_execute_menuentry): New prototype.
	(grub_script_lexer_record_start): Likewise.
	(grub_script_lexer_record_stop): Likewise.
	* normal/execute.c (grub_script_execute_menuentry): New function.
	* normal/lexer.c (record, recording, recordpos, recordlen): New
	variables.
	(grub_script_lexer_record_start): New function.
	(grub_script_lexer_record_stop): Likewise.
	(recordchar): Likewise.
	(nextchar): Likewise.
	(grub_script_yylex): Use `nextchar' to fetch new characters.  Use
	2048 as the buffer size.  Add the tokens `menuentry' and `@'.
	* normal/main.c: Include <grub/parser.h> and <grub/script.h>
	(current_menu): New variable.
	(free_menu): Mainly rewritten.
	(grub_normal_menu_addentry): New function.
	(read_config_file): Rewritten.
	* normal/menu.c (run_menu_entry): Mainly rewritten.
	* normal/menu_entry.c (make_screen): Rewritten te code to insert
	the menu entry.
	(run): Mainly rewritten.
	* normal/parser.y (menu_entry): New variable.
	(GRUB_PARSER_TOKEN_MENUENTRY): New token.
	(menuentry): New rule.
	(command): Add `menuentry'.
	(if_statement): Allow additional returns before `fi'.
	* normal/script.c (grub_script_create_cmdmenu): New function.
This commit is contained in:
marco_g 2006-01-17 09:50:47 +00:00
parent 144f1f986f
commit 77c4a3939d
10 changed files with 378 additions and 221 deletions

View file

@ -25,6 +25,7 @@
#include <grub/symbol.h>
#include <grub/err.h>
#include <grub/arg.h>
#include <grub/script.h>
/* The maximum size of a command-line. */
#define GRUB_MAX_CMDLINE 1600
@ -84,28 +85,17 @@ struct grub_command
};
typedef struct grub_command *grub_command_t;
/* The command list. */
struct grub_command_list
{
/* The string of a command. */
char *command;
/* The next element. */
struct grub_command_list *next;
};
typedef struct grub_command_list *grub_command_list_t;
/* The menu entry. */
struct grub_menu_entry
{
/* The title name. */
const char *title;
/* The number of commands. */
int num;
/* The commands associated with this menu entry. */
struct grub_script *commands;
/* The list of commands. */
grub_command_list_t command_list;
/* The sourcecode of the menu entry, used by the editor. */
const char *sourcecode;
/* The next element. */
struct grub_menu_entry *next;
@ -192,6 +182,9 @@ void grub_context_pop_menu (void);
char *grub_normal_do_completion (char *buf, int *restore,
void (*hook) (const char *item, grub_completion_type_t type, int count));
grub_err_t grub_normal_print_device_info (const char *name);
grub_err_t grub_normal_menu_addentry (const char *title,
struct grub_script *script,
const char *sourcecode);
#ifdef GRUB_UTIL
void grub_normal_init (void);

View file

@ -17,6 +17,10 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef GRUB_SCRIPT_HEADER
#define GRUB_SCRIPT_HEADER 1
#include <grub/types.h>
#include <grub/err.h>
@ -104,6 +108,21 @@ struct grub_script_cmdif
struct grub_script_cmd *false;
};
/* A menu entry generate statement. */
struct grub_script_cmd_menuentry
{
struct grub_script_cmd cmd;
/* The title of the menu entry. */
struct grub_script_arg *title;
/* The sourcecode the entry will be generated from. */
const char *sourcecode;
/* Options. XXX: Not used yet. */
int options;
};
struct grub_script_arglist *
grub_script_create_arglist (void);
@ -120,6 +139,12 @@ struct grub_script_cmd *
grub_script_create_cmdif (struct grub_script_cmd *bool,
struct grub_script_cmd *true,
struct grub_script_cmd *false);
struct grub_script_cmd *
grub_script_create_cmdmenu (struct grub_script_arg *title,
char *sourcecode,
int options);
struct grub_script_cmd *
grub_script_add_cmd (struct grub_script_cmdblock *cmdblock,
struct grub_script_cmd *cmd);
@ -136,6 +161,8 @@ struct grub_script *grub_script_create (struct grub_script_cmd *cmd,
void grub_script_lexer_init (char *s, grub_err_t (*getline) (char **));
void grub_script_lexer_ref (void);
void grub_script_lexer_deref (void);
void grub_script_lexer_record_start (void);
char *grub_script_lexer_record_stop (void);
/* Functions to track allocated memory. */
void *grub_script_malloc (grub_size_t size);
@ -151,6 +178,7 @@ void grub_script_yyerror (char const *err);
grub_err_t grub_script_execute_cmdline (struct grub_script_cmd *cmd);
grub_err_t grub_script_execute_cmdblock (struct grub_script_cmd *cmd);
grub_err_t grub_script_execute_cmdif (struct grub_script_cmd *cmd);
grub_err_t grub_script_execute_menuentry (struct grub_script_cmd *cmd);
/* Execute any GRUB pre-parsed command or script. */
grub_err_t grub_script_execute (struct grub_script *script);
@ -187,3 +215,5 @@ grub_script_function_t grub_script_function_find (char *functionname);
int grub_script_function_iterate (int (*iterate) (grub_script_function_t));
int grub_script_function_call (grub_script_function_t func,
int argc, char **args);
#endif /* ! GRUB_SCRIPT_HEADER */