/* main.c - the normal mode main routine */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2000,2001,2002,2003,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
*
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/menu_viewer.h>
#include <grub/script_sh.h>
GRUB_MOD_LICENSE ("GPLv3+");
static int need_load_gzio = 0;
static int nested_level = 0;
int grub_normal_exit_level = 0;
/* Read a line from the file FILE. */
char *
{
char c;
int pos = 0;
int literal = 0;
char *cmdline;
/* Initially locate some space. */
if (! cmdline)
return 0;
while (1)
{
break;
/* Skip all carriage returns. */
if (c == '\r')
continue;
/* Replace tabs with spaces. */
if (c == '\t')
c = ' ';
/* The previous is a backslash, then... */
if (literal)
{
/* If it is a newline, replace it with a space and continue. */
if (c == '\n')
{
c = ' ';
/* Go back to overwrite the backslash. */
if (pos > 0)
pos--;
}
literal = 0;
}
if (c == '\\')
literal = 1;
if (pos == 0)
{
if (! grub_isspace (c))
}
else
{
{
if (! cmdline)
{
return 0;
}
}
if (c == '\n')
break;
}
}
/* If the buffer is empty, don't return anything at all. */
if (pos == 0)
{
cmdline = 0;
}
return cmdline;
}
void
{
while (entry)
{
entry = next_entry;
}
}
static grub_menu_t
{
{
while (1)
{
char *buf;
if (! buf)
return grub_errno;
if (buf[0] == '#')
else
break;
}
return GRUB_ERR_NONE;
}
newmenu = grub_env_get_menu ();
if (! newmenu)
{
if (! newmenu)
return 0;
}
/* Try to open the config file. */
if (! file)
return 0;
while (1)
{
char *line;
/* Print an error, if any. */
grub_print_error ();
break;
}
return newmenu;
}
/* Initialize the screen. */
void
{
int msg_len;
int posx;
char *msg_formatted;
if (!msg_formatted)
return;
&unicode_msg, &last_position);
if (msg_len < 0)
{
return;
}
}
static void
{
if (! grub_no_autoload)
{
read_fs_list (val);
}
}
static char *
const char *val)
{
need_load_gzio = 0;
read_lists (val);
}
/* Read the config file CONFIG and execute the menu interface or
the command line interface if BATCH is false. */
void
{
const char *prefix;
if (! nested)
{
read_lists (prefix);
}
if (config)
{
/* Ignore any error. */
}
if (! batch)
{
{
if (nested)
}
}
}
/* This starts the normal mode. */
void
{
nested_level++;
grub_normal_execute (config, 0, 0);
grub_cmdline_run (0);
nested_level--;
}
/* Enter normal mode from rescue mode. */
static grub_err_t
{
if (argc == 0)
{
/* Guess the config filename. It is necessary to make CONFIG static,
so that it won't get broken by longjmp. */
char *config;
const char *prefix;
if (prefix)
{
if (! config)
goto quit;
}
else
}
else
grub_enter_normal_mode (argv[0]);
quit:
return 0;
}
/* Exit from normal mode to rescue mode. */
static grub_err_t
{
if (nested_level <= grub_normal_exit_level)
return GRUB_ERR_NONE;
}
static grub_err_t
{
"the first word, TAB lists possible command completions. Anywhere "
"else TAB lists possible device or file completions. %s");
char *msg_formatted;
if (!msg_formatted)
return grub_errno;
{
}
return 0;
}
static grub_err_t
{
const char *prompt;
if (cont)
prompt = ">";
else
prompt = "grub>";
if (!prompt)
return grub_errno;
while (1)
{
if (*line)
break;
{
*line = 0;
return grub_errno;
}
}
return 0;
}
static grub_err_t
{
}
void
{
if (err)
{
grub_print_error ();
return;
}
while (1)
{
char *line;
break;
/* Print an error, if any. */
grub_print_error ();
if (! line)
break;
}
}
static char *
const char *val)
{
return grub_strdup (val);
}
/* clear */
static grub_err_t
{
grub_cls ();
return 0;
}
static const char *features[] = {
"feature_chainloader_bpb", "feature_ntldr", "feature_platform_search_hint"
};
{
unsigned i;
/* Previously many modules depended on gzio. Be nice to user and load it. */
need_load_gzio = 1;
grub_script_init ();
grub_menu_init ();
/* Normal mode shouldn't be unloaded. */
if (mod)
grub_dl_ref (mod);
0, N_("Clear the screen."));
grub_env_export ("pager");
/* Register a command "normal" for the rescue mode. */
0, N_("Enter normal mode."));
0, N_("Exit from normal mode."));
/* Reload terminal colors when these variables are written to. */
/* Preserve hooks after context changes. */
grub_env_export ("color_normal");
grub_env_export ("color_highlight");
/* Set default color names. */
for (i = 0; i < ARRAY_SIZE (features); i++)
{
grub_env_export (features[i]);
}
}
{
grub_script_fini ();
grub_menu_fini ();
grub_set_history (0);
grub_register_variable_hook ("pager", 0, 0);
}