cmdline.c revision 1b8adde7ba7d5e04395c141c5400dc2cffd7d809
/* cmdline.c - the device-independent GRUB text command line */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2004 Free Software Foundation, Inc.
*
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <shared.h>
#include <term.h>
extern struct term_entry *current_term;
#ifdef SUPPORT_DISKLESS
# include <grub.h>
#endif
/* Find the next word from CMDLINE and return the pointer. If
AFTER_EQUAL is non-zero, assume that the character `=' is treated as
a space. Caution: this assumption is for backward compatibility. */
char *
{
/* Skip until we hit whitespace, or maybe an equal sign. */
cmdline ++;
/* Skip whitespace, and maybe equal signs. */
cmdline ++;
return cmdline;
}
/* Print a helpful message for the command-line interface. */
void
print_cmdline_message (int forever)
{
printf (" [ Minimal BASH-like line editing is supported. For the first word, TAB\n"
" lists possible command completions. Anywhere else TAB lists the possible\n"
}
/* Find the builtin whose command name is COMMAND and return the
pointer. If not found, return 0. */
struct builtin *
find_command (char *command)
{
char *ptr;
char c;
/* Find the first space and terminate the command name. */
ptr ++;
c = *ptr;
*ptr = 0;
/* Seek out the builtin whose command name is COMMAND. */
{
if (ret == 0)
{
/* Find the builtin for COMMAND. */
*ptr = c;
return *builtin;
}
else if (ret < 0)
break;
}
/* Cannot find COMMAND. */
*ptr = c;
return 0;
}
/* Initialize the data for the command-line. */
static void
init_cmdline (void)
{
/* Initialization. */
errnum = 0;
count_lines = -1;
/* Restore memory probe state. */
if (mbi.mmap_length)
/* Initialize the data for the builtin commands. */
init_builtins ();
}
/* Enter the command-line interface. HEAP is used for the command-line
buffer. Return only if FOREVER is nonzero and get_cmdline returns
nonzero (ESC is pushed). */
void
{
/* Initialize the data and print a message. */
init_cmdline ();
init_page ();
#ifdef SUPPORT_DISKLESS
grub_putchar ('\n');
#endif
while (1)
{
char *arg;
*heap = 0;
print_error ();
/* Get the command-line with the minimal BASH-like interface. */
return;
/* If there was no command, grab a new one. */
if (! heap[0])
continue;
/* Find a builtin. */
if (! builtin)
continue;
/* If BUILTIN cannot be run in the command-line, skip it. */
{
continue;
}
/* Invalidate the cache, because the user may exchange removable
disks. */
buf_drive = -1;
/* Start to count lines, only if the internal pager is in use. */
if (use_pager)
count_lines = 0;
/* Run BUILTIN->FUNC. */
/* Finish the line count. */
count_lines = -1;
}
}
/* Run an entry from the script SCRIPT. HEAP is used for the
command-line buffer. If an error occurs, return non-zero, otherwise
return zero. */
int
{
char *old_entry;
/* Initialize the data. */
init_cmdline ();
while (1)
{
char *arg;
print_error ();
if (errnum)
{
/*
* At this point something must have gone wrong, so dump the
* buffer and flip output back on.
*/
/* If a fallback entry is defined, don't prompt a user's
intervention. */
if (fallback_entryno < 0)
{
grub_printf ("\nPress any key to continue...");
(void) getkey ();
}
return 1;
}
/* Copy the first string in CUR_ENTRY to HEAP. */
while (*cur_entry++)
;
if (! *heap)
{
/* If there is no more command in SCRIPT... */
/* If any kernel is not loaded, just exit successfully. */
if (kernel_type == KERNEL_TYPE_NONE)
return 0;
if (reset_term)
if (current_term->shutdown) {
(*current_term->shutdown)();
}
/* Otherwise, the command boot is run implicitly. */
}
/* Find a builtin. */
if (! builtin)
{
continue;
}
/* If BUILTIN cannot be run in the command-line, skip it. */
{
continue;
}
/* Invalidate the cache, because the user may exchange removable
disks. */
buf_drive = -1;
/* Run BUILTIN->FUNC. */
}
}