mirror of
https://git.savannah.gnu.org/git/grub.git
synced 2026-10-27 01:29:27 +00:00
2002-06-12 Yoshinori K. Okuji <okuji@enbug.org>
The terminal handling code is rewritten radically. * stage2/console.c: New file. * stage2/term.h: Likewise. * stage2/Makefile.am (noinst_HEADERS): Added term.h. (libgrub_a_SOURCES): Added serial.c. (pre_stage2_exec_SOURCES): Added console.c. * stage2/asm.S (console_putchar): Rewritten from scratch. [!STAGE1_5] (translation_table): New variable. [!STAGE1_5] (translate_keycode): New function. [!STAGE1_5] (console_getkey): Call translate_keycode. [!STAGE1_5] (console_checkkey): Likewise. [!STAGE1_5] (nocursor): Renamed to ... [!STAGE1_5] (console_nocursor): ... this. [!STAGE1_5] (console_set_attrib): Removed. * stage2/builtins.c: Include term.h. (terminal): Removed. (normal_color): Likewise. (highlight_color): Likewise. (cat_func): Display a question mark when a non-printable character was read. (terminal_func): Rewritten almost from scratch. * stage2/char_io.c: Include term.h. [!STAGE1_5] (auto_fill): Removed. [!STAGE1_5] (term_table): New variable. [!STAGE1_5] (current_term): Likewise. [!STAGE1_5] (real_get_cmdline): New function. The code was stolen from the previous version of get_cmdline. [!STAGE1_5] (get_cmdline): Rewritten from scratch. [!STAGE1_5] (translate_keycode): Removed. [!STAGE1_5] (getkey): Rewritten from scratch. [!STAGE1_5] (checkkey): Likewise. (grub_putchar): Likewise. [!STAGE1_5] (gotoxy): Likewise. [!STAGE1_5] (getxy): Likewise. [!STAGE1_5] (cls): Likewise. [!STAGE1_5] (nocursor): New function. [SUPPORT_SERIAL] (serial_getxy): Removed. [SUPPORT_SERIAL] (serial_gotoxy): Likewise. [SUPPORT_SERIAL] (serial_cls): Likewise. [SUPPORT_SERIAL] (serial_getxy): Likewise. [!STAGE1_5] (set_attrib): Likewise. * stage2/cmdline.c (init_cmdline): Set COUNT_LINES to -1. * stage2/common.c [!STAGE1_5] (err_list): Removed ERR_NEED_SERIAL and added ERR_DEV_NEED_INIT. * stage2/hercules.c: Rewritten almost from scratch. * stage2/hercules.h (herc_putchar): Removed. (herc_cls): Likewise. (herc_getxy): Likewise. (herc_gotoxy): Likewise. (herc_set_attrib): Likewise. * stage2/serial.c: Rewritten almost from scratch. * stage2/serial.h: Likewise. * stage2/shared.h [GRUB_UTIL] (DISP_UL): Set to the same value as VGA's. [GRUB_UTIL] (DISP_UR): Likewise. [GRUB_UTIL] (DISP_LL): Likewise. [GRUB_UTIL] (DISP_LR): Likewise. [GRUB_UTIL] (DISP_HORIZ): Likewise. [GRUB_UTIL] (DISP_VERT): Likewise. [GRUB_UTIL] (DISP_LEFT): Likewise. [GRUB_UTIL] (DISP_RIGHT): Likewise. [GRUB_UTIL] (DISP_UP): Likewise. [GRUB_UTIL] (DISP_DOWN): Likewise. (grub_error_t): Removed ERR_NEED_SERIAL. Added ERR_DEV_NEED_INIT. (normal_color): Removed. (highlight_color): Likewise. (console_cls): Removed, because this is declared in term.h. (console_getxy): Likewise. (console_gotoxy): Likewise. (console_putchar): Likewise. (console_getkey): Likewise. (console_checkkey): Likewise. (console_set_attrib): Removed. (set_attrib): Likewise. [GRUB_UTIL] (nocursor): Declared. (auto_fill): Removed. (terminal): Likewise. (TERMINAL_CONSOLE): Likewise. (TERMINAL_SERIAL): Likewise. (TERMINAL_HERCULES): Likewise. (TERMINAL_DUMB): Likewise. (translate_keycode): Likewise. * stage2/stage2.c: Include term.h. (print_entry): Rewritten from scratch. (print_entries): Likewise. (print_border): Likewise. (set_line): Removed. (set_line_normal): Likewise. (set_line_highlight): Likewise. * grub/Makefile.am (AM_CFLAGS): Added -DSUPPORT_HERCULES=1. * grub/asmstub.c: Don't include hercules.h. Include term.h. (console_current_color): New variable. (console_translate_key): New function. (console_checkkey): Rewritten from scratch. (console_getkey): Likewise. (console_putchar): Likewise. (console_set_attrib): Removed. (console_highlight): New function. (console_setcolor): Likewise. (console_nocursor): Likewise. (serial_getkey): Removed. (serial_checkkey): Likewise. (serial_putchar): Likewise. (serial_exists): Likewise. (serial_get_port): Likewise. (serial_init): Likewise. (serial_hw_fetch): New function. (serial_hw_put): Likewise. (serial_hw_delay): Likewise. (serial_hw_get_port): Likewise. (serial_hw_init): Likewise. (set_serial_device): Renamed to ... (serial_set_device): ... this. (herc_putchar): Renamed to ... (hercules_putchar): ... this. (herc_cls): Renamed to ... (hercules_cls): ... this. (herc_getxy): Renamed to ... (hercules_getxy): ... this. (herc_gotoxy): Renamed to ... (hercules_gotoxy): ... this. (hercules_highlight): New function. (hercules_setcolor): Likewise. (hercules_nocursor): Likewise. (herc_set_attrib): Removed. * grub/main.c: Include term.h. (main): If USE_CURSES is false, set CURRENT_TERM->FLAGS to TERM_NO_EDIT | TERM_DUMB. TERMINAL is not used any longer.
This commit is contained in:
1 parent
9ab2360b15
commit
2369202e83
22 files changed
+1626
-1502
No files matched your search
+89
-96
@@ -26,6 +26,7 @@
|
||||
|
||||
#include <shared.h>
|
||||
#include <filesys.h>
|
||||
#include <term.h>
|
||||
|
||||
#ifdef SUPPORT_NETBOOT
|
||||
# define GRUB 1
|
||||
@@ -47,8 +48,6 @@
|
||||
# include <md5.h>
|
||||
#endif
|
||||
|
||||
/* Terminal types. */
|
||||
int terminal = TERMINAL_CONSOLE;
|
||||
/* The type of kernel loaded. */
|
||||
kernel_t kernel_type;
|
||||
/* The boot device. */
|
||||
@@ -70,9 +69,6 @@ char *password;
|
||||
password_t password_type;
|
||||
/* The flag for indicating that the user is authoritative. */
|
||||
int auth = 0;
|
||||
/* Color settings. */
|
||||
int normal_color;
|
||||
int highlight_color;
|
||||
/* The timeout. */
|
||||
int grub_timeout = -1;
|
||||
/* Whether to show the menu or not. */
|
||||
@@ -99,8 +95,6 @@ void
|
||||
init_config (void)
|
||||
{
|
||||
default_entry = 0;
|
||||
normal_color = A_NORMAL;
|
||||
highlight_color = A_REVERSE;
|
||||
password = 0;
|
||||
fallback_entry = -1;
|
||||
grub_timeout = -1;
|
||||
@@ -413,8 +407,15 @@ cat_func (char *arg, int flags)
|
||||
return 1;
|
||||
|
||||
while (grub_read (&c, 1))
|
||||
grub_putchar (c);
|
||||
|
||||
{
|
||||
/* Because running "cat" with a binary file can confuse the terminal,
|
||||
print only some characters as they are. */
|
||||
if (grub_isspace (c) || (c >= ' ' && c <= '~'))
|
||||
grub_putchar (c);
|
||||
else
|
||||
grub_putchar ('?');
|
||||
}
|
||||
|
||||
grub_close ();
|
||||
return 0;
|
||||
}
|
||||
@@ -696,8 +697,9 @@ color_func (char *arg, int flags)
|
||||
return 1;
|
||||
}
|
||||
|
||||
normal_color = new_normal_color;
|
||||
highlight_color = new_highlight_color;
|
||||
if (current_term->setcolor)
|
||||
current_term->setcolor (new_normal_color, new_highlight_color);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -3276,7 +3278,7 @@ static struct builtin builtin_savedefault =
|
||||
static int
|
||||
serial_func (char *arg, int flags)
|
||||
{
|
||||
unsigned short port = serial_get_port (0);
|
||||
unsigned short port = serial_hw_get_port (0);
|
||||
unsigned int speed = 9600;
|
||||
int word_len = UART_8BITS_WORD;
|
||||
int parity = UART_NO_PARITY;
|
||||
@@ -3301,7 +3303,7 @@ serial_func (char *arg, int flags)
|
||||
return 1;
|
||||
}
|
||||
|
||||
port = serial_get_port (unit);
|
||||
port = serial_hw_get_port (unit);
|
||||
}
|
||||
else if (grub_memcmp (arg, "--speed=", sizeof ("--speed=") - 1) == 0)
|
||||
{
|
||||
@@ -3388,7 +3390,7 @@ serial_func (char *arg, int flags)
|
||||
*q++ = *p++;
|
||||
|
||||
*q = 0;
|
||||
set_serial_device (dev);
|
||||
serial_set_device (dev);
|
||||
}
|
||||
# endif /* GRUB_UTIL */
|
||||
else
|
||||
@@ -3398,7 +3400,7 @@ serial_func (char *arg, int flags)
|
||||
}
|
||||
|
||||
/* Initialize the serial unit. */
|
||||
if (! serial_init (port, speed, word_len, parity, stop_bit_len))
|
||||
if (! serial_hw_init (port, speed, word_len, parity, stop_bit_len))
|
||||
{
|
||||
errnum = ERR_BAD_ARGUMENT;
|
||||
return 1;
|
||||
@@ -3981,18 +3983,26 @@ static struct builtin builtin_setup =
|
||||
static int
|
||||
terminal_func (char *arg, int flags)
|
||||
{
|
||||
int default_terminal = 0;
|
||||
/* The index of the default terminal in TERM_TABLE. */
|
||||
int default_term = -1;
|
||||
struct term_entry *prev_term = current_term;
|
||||
int to = -1;
|
||||
int dumb = 0;
|
||||
int saved_terminal = terminal;
|
||||
int lines = 0;
|
||||
int no_message = 0;
|
||||
unsigned long term_flags = 0;
|
||||
/* XXX: Assume less than 32 terminals. */
|
||||
unsigned long term_bitmap = 0;
|
||||
|
||||
/* Get GNU-style long options. */
|
||||
while (1)
|
||||
{
|
||||
if (grub_memcmp (arg, "--dumb", sizeof ("--dumb") - 1) == 0)
|
||||
dumb = 1;
|
||||
term_flags |= TERM_DUMB;
|
||||
else if (grub_memcmp (arg, "--no-echo", sizeof ("--no-echo") - 1) == 0)
|
||||
/* ``--no-echo'' implies ``--no-edit''. */
|
||||
term_flags |= (TERM_NO_ECHO | TERM_NO_EDIT);
|
||||
else if (grub_memcmp (arg, "--no-edit", sizeof ("--no-edit") - 1) == 0)
|
||||
term_flags |= TERM_NO_EDIT;
|
||||
else if (grub_memcmp (arg, "--timeout=", sizeof ("--timeout=") - 1) == 0)
|
||||
{
|
||||
char *val = arg + sizeof ("--timeout=") - 1;
|
||||
@@ -4025,72 +4035,51 @@ terminal_func (char *arg, int flags)
|
||||
/* If no argument is specified, show current setting. */
|
||||
if (! *arg)
|
||||
{
|
||||
if (terminal & TERMINAL_CONSOLE)
|
||||
grub_printf ("console%s\n",
|
||||
terminal & TERMINAL_DUMB ? " (dumb)" : "");
|
||||
#ifdef SUPPORT_HERCULES
|
||||
else if (terminal & TERMINAL_HERCULES)
|
||||
grub_printf ("hercules%s\n",
|
||||
terminal & TERMINAL_DUMB ? " (dumb)" : "");
|
||||
#endif /* SUPPORT_HERCULES */
|
||||
#ifdef SUPPORT_SERIAL
|
||||
else if (terminal & TERMINAL_SERIAL)
|
||||
grub_printf ("serial%s\n",
|
||||
terminal & TERMINAL_DUMB ? " (dumb)" : " (vt100)");
|
||||
#endif /* SUPPORT_SERIAL */
|
||||
|
||||
grub_printf ("%s%s%s%s\n",
|
||||
current_term->name,
|
||||
current_term->flags & TERM_DUMB ? " (dumb)" : "",
|
||||
current_term->flags & TERM_NO_EDIT ? " (no edit)" : "",
|
||||
current_term->flags & TERM_NO_ECHO ? " (no echo)" : "");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Clear current setting. */
|
||||
terminal = dumb ? TERMINAL_DUMB : 0;
|
||||
|
||||
while (*arg)
|
||||
{
|
||||
if (grub_memcmp (arg, "console", sizeof ("console") - 1) == 0)
|
||||
int i;
|
||||
char *next = skip_to (0, arg);
|
||||
|
||||
nul_terminate (arg);
|
||||
|
||||
for (i = 0; term_table[i].name; i++)
|
||||
{
|
||||
terminal |= TERMINAL_CONSOLE;
|
||||
if (! default_terminal)
|
||||
default_terminal = TERMINAL_CONSOLE;
|
||||
}
|
||||
#ifdef SUPPORT_HERCULES
|
||||
else if (grub_memcmp (arg, "hercules", sizeof ("hercules") - 1) == 0)
|
||||
{
|
||||
terminal |= TERMINAL_HERCULES;
|
||||
if (! default_terminal)
|
||||
default_terminal = TERMINAL_HERCULES;
|
||||
}
|
||||
#endif /* SUPPORT_HERCULES */
|
||||
#ifdef SUPPORT_SERIAL
|
||||
else if (grub_memcmp (arg, "serial", sizeof ("serial") - 1) == 0)
|
||||
{
|
||||
if (serial_exists ())
|
||||
if (grub_strcmp (arg, term_table[i].name) == 0)
|
||||
{
|
||||
terminal |= TERMINAL_SERIAL;
|
||||
if (! default_terminal)
|
||||
default_terminal = TERMINAL_SERIAL;
|
||||
}
|
||||
else
|
||||
{
|
||||
terminal = saved_terminal;
|
||||
errnum = ERR_NEED_SERIAL;
|
||||
return 1;
|
||||
if (term_table[i].flags & TERM_NEED_INIT)
|
||||
{
|
||||
errnum = ERR_DEV_NEED_INIT;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (default_term < 0)
|
||||
default_term = i;
|
||||
|
||||
term_bitmap |= (1 << i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif /* SUPPORT_SERIAL */
|
||||
else
|
||||
|
||||
if (! term_table[i].name)
|
||||
{
|
||||
terminal = saved_terminal;
|
||||
errnum = ERR_BAD_ARGUMENT;
|
||||
return 1;
|
||||
}
|
||||
|
||||
arg = skip_to (0, arg);
|
||||
arg = next;
|
||||
}
|
||||
|
||||
#ifdef SUPPORT_SERIAL
|
||||
/* If a seial console is turned on, wait until the user pushes any key. */
|
||||
if (terminal & TERMINAL_SERIAL)
|
||||
/* If multiple terminals are specified, wait until the user pushes any
|
||||
key on one of the terminals. */
|
||||
if (term_bitmap & ~(1 << default_term))
|
||||
{
|
||||
int time1, time2 = -1;
|
||||
|
||||
@@ -4104,25 +4093,22 @@ terminal_func (char *arg, int flags)
|
||||
/* Wait for a key input. */
|
||||
while (to)
|
||||
{
|
||||
if ((terminal & TERMINAL_CONSOLE) && console_checkkey () != -1)
|
||||
{
|
||||
terminal &= (TERMINAL_CONSOLE | TERMINAL_DUMB);
|
||||
(void) getkey ();
|
||||
return 0;
|
||||
}
|
||||
else if ((terminal & TERMINAL_SERIAL) && serial_checkkey () != -1)
|
||||
{
|
||||
terminal &= (TERMINAL_SERIAL | TERMINAL_DUMB);
|
||||
(void) getkey ();
|
||||
int i;
|
||||
|
||||
/* If the interface is currently the command-line, restart
|
||||
it to repaint the screen. */
|
||||
if (flags & BUILTIN_CMDLINE)
|
||||
grub_longjmp (restart_cmdline_env, 0);
|
||||
|
||||
return 0;
|
||||
for (i = 0; term_table[i].name; i++)
|
||||
{
|
||||
if (term_bitmap & (1 << i))
|
||||
{
|
||||
if (term_table[i].checkkey () >= 0)
|
||||
{
|
||||
(void) term_table[i].getkey ();
|
||||
default_term = i;
|
||||
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Prompt the user, once per sec. */
|
||||
if ((time1 = getrtsecs ()) != time2 && time1 != 0xFF)
|
||||
{
|
||||
@@ -4134,18 +4120,23 @@ terminal_func (char *arg, int flags)
|
||||
to--;
|
||||
}
|
||||
}
|
||||
|
||||
/* Expired. */
|
||||
terminal &= (default_terminal | TERMINAL_DUMB);
|
||||
}
|
||||
#endif /* SUPPORT_SERIAL */
|
||||
|
||||
end:
|
||||
current_term = term_table + default_term;
|
||||
current_term->flags = term_flags;
|
||||
|
||||
if (lines)
|
||||
max_lines = lines;
|
||||
else
|
||||
/* 24 would be a good default value. */
|
||||
max_lines = 24;
|
||||
|
||||
/* If the interface is currently the command-line,
|
||||
restart it to repaint the screen. */
|
||||
if (current_term != prev_term && (flags & BUILTIN_CMDLINE))
|
||||
grub_longjmp (restart_cmdline_env, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -4154,12 +4145,14 @@ static struct builtin builtin_terminal =
|
||||
"terminal",
|
||||
terminal_func,
|
||||
BUILTIN_MENU | BUILTIN_CMDLINE | BUILTIN_HELP_LIST,
|
||||
"terminal [--dumb] [--timeout=SECS] [--lines=LINES] [--silent] [console] [serial]",
|
||||
"Select a terminal. When serial is specified, wait until you push any key"
|
||||
" to continue. If both console and serial are specified, the terminal"
|
||||
" to which you input a key first will be selected. If no argument is"
|
||||
" specified, print current setting. The option --dumb specifies that"
|
||||
" your terminal is dumb, otherwise, vt100-compatibility is assumed."
|
||||
"terminal [--dumb] [--no-echo] [--no-edit] [--timeout=SECS] [--lines=LINES] [--silent] [console] [serial] [hercules]",
|
||||
"Select a terminal. When multiple terminals are specified, wait until"
|
||||
" you push any key to continue. If both console and serial are specified,"
|
||||
" the terminal to which you input a key first will be selected. If no"
|
||||
" argument is specified, print current setting. The option --dumb"
|
||||
" specifies that your terminal is dumb, otherwise, vt100-compatibility"
|
||||
" is assumed. If you specify --no-echo, input characters won't be echoed."
|
||||
" If you specify --no-edit, the BASH-like editing feature will be disabled."
|
||||
" If --timeout is present, this command will wait at most for SECS"
|
||||
" seconds. The option --lines specifies the maximum number of lines."
|
||||
" The option --silent is used to suppress messages."
|
||||
|
||||
Reference in new issue
Block a user