merge mainline into asprintf
This commit is contained in:
commit
2d49abe9e7
342 changed files with 14569 additions and 4699 deletions
225
normal/main.c
225
normal/main.c
|
@ -30,9 +30,13 @@
|
|||
#include <grub/menu_viewer.h>
|
||||
#include <grub/auth.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/charset.h>
|
||||
|
||||
#define GRUB_DEFAULT_HISTORY_SIZE 50
|
||||
|
||||
static int nested_level = 0;
|
||||
int grub_normal_exit_level = 0;
|
||||
|
||||
/* Read a line from the file FILE. */
|
||||
char *
|
||||
grub_file_getline (grub_file_t file)
|
||||
|
@ -372,7 +376,21 @@ read_config_file (const char *config)
|
|||
if (! file)
|
||||
return 0;
|
||||
|
||||
grub_reader_loop (getline);
|
||||
while (1)
|
||||
{
|
||||
char *line;
|
||||
|
||||
/* Print an error, if any. */
|
||||
grub_print_error ();
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
|
||||
if ((getline (&line, 0)) || (! line))
|
||||
break;
|
||||
|
||||
grub_parser_get_current ()->parse_line (line, getline);
|
||||
grub_free (line);
|
||||
}
|
||||
|
||||
grub_file_close (file);
|
||||
|
||||
if (old_parser)
|
||||
|
@ -383,18 +401,16 @@ read_config_file (const char *config)
|
|||
|
||||
/* Initialize the screen. */
|
||||
void
|
||||
grub_normal_init_page (void)
|
||||
grub_normal_init_page (struct grub_term_output *term)
|
||||
{
|
||||
int msg_len;
|
||||
int posx;
|
||||
const char *msg = _("GNU GRUB version %s");
|
||||
|
||||
char *msg_formatted;
|
||||
|
||||
grub_uint32_t *unicode_msg;
|
||||
grub_uint32_t *last_position;
|
||||
|
||||
grub_cls ();
|
||||
grub_term_cls (term);
|
||||
|
||||
msg_formatted = grub_asprintf (msg, PACKAGE_VERSION);
|
||||
if (!msg_formatted)
|
||||
|
@ -408,16 +424,25 @@ grub_normal_init_page (void)
|
|||
return;
|
||||
}
|
||||
|
||||
posx = grub_getstringwidth (unicode_msg, last_position);
|
||||
posx = (GRUB_TERM_WIDTH - posx) / 2;
|
||||
grub_gotoxy (posx, 1);
|
||||
posx = grub_getstringwidth (unicode_msg, last_position, term);
|
||||
posx = (grub_term_width (term) - posx) / 2;
|
||||
grub_term_gotoxy (term, posx, 1);
|
||||
|
||||
grub_print_ucs4 (unicode_msg, last_position);
|
||||
grub_print_ucs4 (unicode_msg, last_position, term);
|
||||
grub_printf("\n\n");
|
||||
grub_free (unicode_msg);
|
||||
}
|
||||
|
||||
static int reader_nested;
|
||||
static char *
|
||||
read_lists (struct grub_env_var *var __attribute__ ((unused)),
|
||||
const char *val)
|
||||
{
|
||||
read_command_list ();
|
||||
read_fs_list ();
|
||||
read_crypto_list ();
|
||||
read_terminal_list ();
|
||||
return val ? grub_strdup (val) : NULL;
|
||||
}
|
||||
|
||||
/* Read the config file CONFIG and execute the menu interface or
|
||||
the command line interface if BATCH is false. */
|
||||
|
@ -426,13 +451,11 @@ grub_normal_execute (const char *config, int nested, int batch)
|
|||
{
|
||||
grub_menu_t menu = 0;
|
||||
|
||||
read_command_list ();
|
||||
read_fs_list ();
|
||||
read_lists (NULL, NULL);
|
||||
read_handler_list ();
|
||||
grub_register_variable_hook ("prefix", NULL, read_lists);
|
||||
grub_command_execute ("parser.grub", 0, 0);
|
||||
|
||||
reader_nested = nested;
|
||||
|
||||
if (config)
|
||||
{
|
||||
menu = read_config_file (config);
|
||||
|
@ -445,7 +468,7 @@ grub_normal_execute (const char *config, int nested, int batch)
|
|||
{
|
||||
if (menu && menu->size)
|
||||
{
|
||||
grub_menu_viewer_show_menu (menu, nested);
|
||||
grub_show_menu (menu, nested);
|
||||
if (nested)
|
||||
free_menu (menu);
|
||||
}
|
||||
|
@ -456,21 +479,24 @@ grub_normal_execute (const char *config, int nested, int batch)
|
|||
void
|
||||
grub_enter_normal_mode (const char *config)
|
||||
{
|
||||
nested_level++;
|
||||
grub_normal_execute (config, 0, 0);
|
||||
grub_cmdline_run (0);
|
||||
nested_level--;
|
||||
if (grub_normal_exit_level)
|
||||
grub_normal_exit_level--;
|
||||
}
|
||||
|
||||
/* Enter normal mode from rescue mode. */
|
||||
static grub_err_t
|
||||
grub_cmd_normal (struct grub_command *cmd,
|
||||
grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)),
|
||||
int argc, char *argv[])
|
||||
{
|
||||
grub_unregister_command (cmd);
|
||||
|
||||
if (argc == 0)
|
||||
{
|
||||
/* Guess the config filename. It is necessary to make CONFIG static,
|
||||
so that it won't get broken by longjmp. */
|
||||
static char *config;
|
||||
char *config;
|
||||
const char *prefix;
|
||||
|
||||
prefix = grub_env_get ("prefix");
|
||||
|
@ -493,10 +519,83 @@ quit:
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* Exit from normal mode to rescue mode. */
|
||||
static grub_err_t
|
||||
grub_cmd_normal_exit (struct grub_command *cmd __attribute__ ((unused)),
|
||||
int argc __attribute__ ((unused)),
|
||||
char *argv[] __attribute__ ((unused)))
|
||||
{
|
||||
if (nested_level <= grub_normal_exit_level)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "not in normal environment");
|
||||
grub_normal_exit_level++;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_normal_reader_init (int nested)
|
||||
{
|
||||
struct grub_term_output *term;
|
||||
const char *msg = _("Minimal BASH-like line editing is supported. For "
|
||||
"the first word, TAB lists possible command completions. Anywhere "
|
||||
"else TAB lists possible device or file completions. %s");
|
||||
const char *msg_esc = _("ESC at any time exits.");
|
||||
char *msg_formatted;
|
||||
|
||||
msg_formatted = grub_asprintf (msg, nested ? msg_esc : "");
|
||||
if (!msg_formatted)
|
||||
return grub_errno;
|
||||
|
||||
FOR_ACTIVE_TERM_OUTPUTS(term)
|
||||
{
|
||||
grub_normal_init_page (term);
|
||||
grub_term_setcursor (term, 1);
|
||||
|
||||
grub_print_message_indented (msg_formatted, 3, STANDARD_MARGIN, term);
|
||||
grub_puts ("\n");
|
||||
}
|
||||
grub_free (msg_formatted);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static grub_err_t
|
||||
grub_normal_read_line_real (char **line, int cont, int nested)
|
||||
{
|
||||
grub_parser_t parser = grub_parser_get_current ();
|
||||
char *prompt;
|
||||
|
||||
if (cont)
|
||||
prompt = grub_asprintf (">");
|
||||
else
|
||||
prompt = grub_asprintf ("%s>", parser->name);
|
||||
|
||||
while (1)
|
||||
{
|
||||
*line = grub_cmdline_get (prompt);
|
||||
if (*line)
|
||||
break;
|
||||
|
||||
if (cont || nested)
|
||||
{
|
||||
grub_free (*line);
|
||||
*line = 0;
|
||||
return grub_errno;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_normal_read_line (char **line, int cont)
|
||||
{
|
||||
return grub_normal_read_line_real (line, cont, 0);
|
||||
}
|
||||
|
||||
void
|
||||
grub_cmdline_run (int nested)
|
||||
{
|
||||
grub_reader_t reader;
|
||||
grub_err_t err = GRUB_ERR_NONE;
|
||||
|
||||
err = grub_auth_check_authentication (NULL);
|
||||
|
@ -508,75 +607,28 @@ grub_cmdline_run (int nested)
|
|||
return;
|
||||
}
|
||||
|
||||
reader = grub_reader_get_current ();
|
||||
|
||||
reader_nested = nested;
|
||||
if (reader->init)
|
||||
reader->init ();
|
||||
grub_reader_loop (0);
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_normal_reader_init (void)
|
||||
{
|
||||
grub_normal_init_page ();
|
||||
grub_setcursor (1);
|
||||
|
||||
const char *msg = _("Minimal BASH-like line editing is supported. For "
|
||||
"the first word, TAB lists possible command completions. Anywhere "
|
||||
"else TAB lists possible device or file completions. %s");
|
||||
|
||||
const char *msg_esc = _("ESC at any time exits.");
|
||||
|
||||
char *msg_formatted;
|
||||
|
||||
msg_formatted = grub_asprintf (msg, reader_nested ? msg_esc : "");
|
||||
if (!msg_formatted)
|
||||
return grub_errno;
|
||||
grub_print_message_indented (msg_formatted, 3, STANDARD_MARGIN);
|
||||
grub_puts ("\n");
|
||||
|
||||
grub_free (msg_formatted);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char cmdline[GRUB_MAX_CMDLINE];
|
||||
|
||||
static grub_err_t
|
||||
grub_normal_read_line (char **line, int cont)
|
||||
{
|
||||
grub_parser_t parser = grub_parser_get_current ();
|
||||
char *prompt;
|
||||
|
||||
prompt = grub_asprintf ("%s>", parser->name);
|
||||
if (!prompt)
|
||||
return grub_errno;
|
||||
grub_normal_reader_init (nested);
|
||||
|
||||
while (1)
|
||||
{
|
||||
cmdline[0] = 0;
|
||||
if (grub_cmdline_get (prompt, cmdline, sizeof (cmdline), 0, 1, 1))
|
||||
char *line;
|
||||
|
||||
if (grub_normal_exit_level)
|
||||
break;
|
||||
|
||||
if ((reader_nested) || (cont))
|
||||
{
|
||||
*line = 0;
|
||||
return grub_errno;
|
||||
}
|
||||
/* Print an error, if any. */
|
||||
grub_print_error ();
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
|
||||
grub_normal_read_line_real (&line, 0, nested);
|
||||
if (! line)
|
||||
break;
|
||||
|
||||
grub_parser_get_current ()->parse_line (line, grub_normal_read_line);
|
||||
grub_free (line);
|
||||
}
|
||||
|
||||
*line = grub_strdup (cmdline);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct grub_reader grub_normal_reader =
|
||||
{
|
||||
.name = "normal",
|
||||
.init = grub_normal_reader_init,
|
||||
.read_line = grub_normal_read_line
|
||||
};
|
||||
|
||||
static char *
|
||||
grub_env_write_pager (struct grub_env_var *var __attribute__ ((unused)),
|
||||
const char *val)
|
||||
|
@ -591,17 +643,15 @@ GRUB_MOD_INIT(normal)
|
|||
if (mod)
|
||||
grub_dl_ref (mod);
|
||||
|
||||
grub_menu_viewer_register (&grub_normal_text_menu_viewer);
|
||||
|
||||
grub_set_history (GRUB_DEFAULT_HISTORY_SIZE);
|
||||
|
||||
grub_reader_register ("normal", &grub_normal_reader);
|
||||
grub_reader_set_current (&grub_normal_reader);
|
||||
grub_register_variable_hook ("pager", 0, grub_env_write_pager);
|
||||
|
||||
/* Register a command "normal" for the rescue mode. */
|
||||
grub_register_command_prio ("normal", grub_cmd_normal,
|
||||
0, "Enter normal mode.", 0);
|
||||
grub_register_command ("normal", grub_cmd_normal,
|
||||
0, "Enter normal mode.");
|
||||
grub_register_command ("normal_exit", grub_cmd_normal_exit,
|
||||
0, "Exit from normal mode.");
|
||||
|
||||
/* Reload terminal colors when these variables are written to. */
|
||||
grub_register_variable_hook ("color_normal", NULL, grub_env_write_color_normal);
|
||||
|
@ -615,7 +665,6 @@ GRUB_MOD_INIT(normal)
|
|||
GRUB_MOD_FINI(normal)
|
||||
{
|
||||
grub_set_history (0);
|
||||
grub_reader_unregister (&grub_normal_reader);
|
||||
grub_register_variable_hook ("pager", 0, 0);
|
||||
grub_fs_autoload_hook = 0;
|
||||
free_handler_list ();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue