core: use GRUB_TERM_ definitions when handling term characters

* Also use hex value for GRUB_TERM_ESC as '\e' is not in the C standard and is not understood by some compilers
This commit is contained in:
Pete Batard 2017-08-07 16:20:30 +01:00 committed by Vladimir Serbinenko
parent f826330683
commit bdd89d239c
13 changed files with 25 additions and 24 deletions

View File

@ -40,7 +40,7 @@ static struct grub_keyboard_layout layout_us = {
/* 0x10 */ 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', /* 0x10 */ 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
/* 0x18 */ 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', /* 0x18 */ 'u', 'v', 'w', 'x', 'y', 'z', '1', '2',
/* 0x20 */ '3', '4', '5', '6', '7', '8', '9', '0', /* 0x20 */ '3', '4', '5', '6', '7', '8', '9', '0',
/* 0x28 */ '\n', '\e', '\b', '\t', ' ', '-', '=', '[', /* 0x28 */ '\n', GRUB_TERM_ESC, GRUB_TERM_BACKSPACE, GRUB_TERM_TAB, ' ', '-', '=', '[',
/* According to usage table 0x31 should be mapped to '/' /* According to usage table 0x31 should be mapped to '/'
but testing with real keyboard shows that 0x32 is remapped to '/'. but testing with real keyboard shows that 0x32 is remapped to '/'.
Map 0x31 to 0. Map 0x31 to 0.
@ -82,8 +82,8 @@ static struct grub_keyboard_layout layout_us = {
/* 0x10 */ 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', /* 0x10 */ 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
/* 0x18 */ 'U', 'V', 'W', 'X', 'Y', 'Z', '!', '@', /* 0x18 */ 'U', 'V', 'W', 'X', 'Y', 'Z', '!', '@',
/* 0x20 */ '#', '$', '%', '^', '&', '*', '(', ')', /* 0x20 */ '#', '$', '%', '^', '&', '*', '(', ')',
/* 0x28 */ '\n' | GRUB_TERM_SHIFT, '\e' | GRUB_TERM_SHIFT, /* 0x28 */ '\n' | GRUB_TERM_SHIFT, GRUB_TERM_ESC | GRUB_TERM_SHIFT,
/* 0x2a */ '\b' | GRUB_TERM_SHIFT, '\t' | GRUB_TERM_SHIFT, /* 0x2a */ GRUB_TERM_BACKSPACE | GRUB_TERM_SHIFT, GRUB_TERM_TAB | GRUB_TERM_SHIFT,
/* 0x2c */ ' ' | GRUB_TERM_SHIFT, '_', '+', '{', /* 0x2c */ ' ' | GRUB_TERM_SHIFT, '_', '+', '{',
/* According to usage table 0x31 should be mapped to '/' /* According to usage table 0x31 should be mapped to '/'
but testing with real keyboard shows that 0x32 is remapped to '/'. but testing with real keyboard shows that 0x32 is remapped to '/'.

View File

@ -52,8 +52,8 @@ static struct
int key; int key;
} hotkey_aliases[] = } hotkey_aliases[] =
{ {
{"backspace", '\b'}, {"backspace", GRUB_TERM_BACKSPACE},
{"tab", '\t'}, {"tab", GRUB_TERM_TAB},
{"delete", GRUB_TERM_KEY_DC}, {"delete", GRUB_TERM_KEY_DC},
{"insert", GRUB_TERM_KEY_INSERT}, {"insert", GRUB_TERM_KEY_INSERT},
{"f1", GRUB_TERM_KEY_F1}, {"f1", GRUB_TERM_KEY_F1},

View File

@ -462,7 +462,7 @@ grub_password_get (char buf[], unsigned buf_size)
if (key == '\n' || key == '\r') if (key == '\n' || key == '\r')
break; break;
if (key == '\e') if (key == GRUB_TERM_ESC)
{ {
cur_len = 0; cur_len = 0;
break; break;
@ -487,7 +487,7 @@ grub_password_get (char buf[], unsigned buf_size)
grub_xputs ("\n"); grub_xputs ("\n");
grub_refresh (); grub_refresh ();
return (key != '\e'); return (key != GRUB_TERM_ESC);
} }
#endif #endif

View File

@ -166,13 +166,13 @@ grub_username_get (char buf[], unsigned buf_size)
if (key == '\n' || key == '\r') if (key == '\n' || key == '\r')
break; break;
if (key == '\e') if (key == GRUB_TERM_ESC)
{ {
cur_len = 0; cur_len = 0;
break; break;
} }
if (key == '\b') if (key == GRUB_TERM_BACKSPACE)
{ {
if (cur_len) if (cur_len)
{ {
@ -197,7 +197,7 @@ grub_username_get (char buf[], unsigned buf_size)
grub_xputs ("\n"); grub_xputs ("\n");
grub_refresh (); grub_refresh ();
return (key != '\e'); return (key != GRUB_TERM_ESC);
} }
grub_err_t grub_err_t

View File

@ -626,12 +626,12 @@ grub_cmdline_get (const char *prompt_translated)
cl_insert (cl_terms, nterms, &lpos, &llen, &max_len, &buf, kill_buf); cl_insert (cl_terms, nterms, &lpos, &llen, &max_len, &buf, kill_buf);
break; break;
case '\e': case GRUB_TERM_ESC:
grub_free (cl_terms); grub_free (cl_terms);
grub_free (buf); grub_free (buf);
return 0; return 0;
case '\b': case GRUB_TERM_BACKSPACE:
if (lpos > 0) if (lpos > 0)
{ {
lpos--; lpos--;

View File

@ -763,7 +763,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
*auto_boot = 0; *auto_boot = 0;
return current_entry; return current_entry;
case '\e': case GRUB_TERM_ESC:
if (nested) if (nested)
{ {
menu_fini (); menu_fini ();

View File

@ -1403,7 +1403,7 @@ grub_menu_entry_run (grub_menu_entry_t entry)
goto fail; goto fail;
break; break;
case '\e': case GRUB_TERM_ESC:
destroy_screen (screen); destroy_screen (screen);
return; return;

View File

@ -104,7 +104,7 @@ const unsigned efi_codes[] =
GRUB_TERM_KEY_DC, GRUB_TERM_KEY_PPAGE, GRUB_TERM_KEY_NPAGE, GRUB_TERM_KEY_F1, GRUB_TERM_KEY_DC, GRUB_TERM_KEY_PPAGE, GRUB_TERM_KEY_NPAGE, GRUB_TERM_KEY_F1,
GRUB_TERM_KEY_F2, GRUB_TERM_KEY_F3, GRUB_TERM_KEY_F4, GRUB_TERM_KEY_F5, GRUB_TERM_KEY_F2, GRUB_TERM_KEY_F3, GRUB_TERM_KEY_F4, GRUB_TERM_KEY_F5,
GRUB_TERM_KEY_F6, GRUB_TERM_KEY_F7, GRUB_TERM_KEY_F8, GRUB_TERM_KEY_F9, GRUB_TERM_KEY_F6, GRUB_TERM_KEY_F7, GRUB_TERM_KEY_F8, GRUB_TERM_KEY_F9,
GRUB_TERM_KEY_F10, GRUB_TERM_KEY_F11, GRUB_TERM_KEY_F12, '\e' GRUB_TERM_KEY_F10, GRUB_TERM_KEY_F11, GRUB_TERM_KEY_F12, GRUB_TERM_ESC
}; };
static int static int

View File

@ -204,7 +204,7 @@ static int
grub_console_getkey (struct grub_term_input *term __attribute__ ((unused))) grub_console_getkey (struct grub_term_input *term __attribute__ ((unused)))
{ {
const grub_uint16_t bypass_table[] = { const grub_uint16_t bypass_table[] = {
0x0100 | '\e', 0x0f00 | '\t', 0x0e00 | '\b', 0x1c00 | '\r', 0x1c00 | '\n' 0x0100 | GRUB_TERM_ESC, 0x0f00 | GRUB_TERM_TAB, 0x0e00 | GRUB_TERM_BACKSPACE, 0x1c00 | '\r', 0x1c00 | '\n'
}; };
struct grub_bios_int_registers regs; struct grub_bios_int_registers regs;
unsigned i; unsigned i;

View File

@ -426,12 +426,12 @@ grub_terminfo_readkey (struct grub_term_input *term, int *keys, int *len,
} }
*len = 1; *len = 1;
keys[0] = c; keys[0] = c;
if (c != ANSI_CSI && c != '\e') if (c != ANSI_CSI && c != GRUB_TERM_ESC)
{ {
/* Backspace: Ctrl-h. */ /* Backspace: Ctrl-h. */
if (c == 0x7f) if (c == 0x7f)
c = '\b'; c = GRUB_TERM_BACKSPACE;
if (c < 0x20 && c != '\t' && c!= '\b' && c != '\n' && c != '\r') if (c < 0x20 && c != GRUB_TERM_TAB && c!= GRUB_TERM_BACKSPACE && c != '\n' && c != '\r')
c = GRUB_TERM_CTRL | (c - 1 + 'a'); c = GRUB_TERM_CTRL | (c - 1 + 'a');
*len = 1; *len = 1;
keys[0] = c; keys[0] = c;
@ -487,7 +487,7 @@ grub_terminfo_readkey (struct grub_term_input *term, int *keys, int *len,
GRUB_TERM_KEY_HOME, GRUB_TERM_KEY_END }; GRUB_TERM_KEY_HOME, GRUB_TERM_KEY_END };
unsigned i; unsigned i;
if (c == '\e') if (c == GRUB_TERM_ESC)
{ {
CONTINUE_READ; CONTINUE_READ;
@ -606,7 +606,7 @@ grub_terminfo_getkey (struct grub_term_input *termi)
&data->npending, data->readkey); &data->npending, data->readkey);
#if defined(__powerpc__) && defined(GRUB_MACHINE_IEEE1275) #if defined(__powerpc__) && defined(GRUB_MACHINE_IEEE1275)
if (data->npending == 1 && data->input_buf[0] == '\e' if (data->npending == 1 && data->input_buf[0] == GRUB_TERM_ESC
&& grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_BROKEN_REPEAT) && grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_BROKEN_REPEAT)
&& grub_get_time_ms () - data->last_key_time < 1000 && grub_get_time_ms () - data->last_key_time < 1000
&& (data->last_key & GRUB_TERM_EXTENDED)) && (data->last_key & GRUB_TERM_EXTENDED))

View File

@ -103,7 +103,7 @@ cmdline_cat_test (void)
'/', 't', 'e', 's', 't', '.', '/', 't', 'e', 's', 't', '.',
't', 'x', 't', '\n', 't', 'x', 't', '\n',
GRUB_TERM_NO_KEY, GRUB_TERM_NO_KEY,
GRUB_TERM_NO_KEY, '\e'}, GRUB_TERM_NO_KEY, GRUB_TERM_ESC},
23); 23);
grub_video_checksum ("cmdline_cat"); grub_video_checksum ("cmdline_cat");

View File

@ -146,7 +146,7 @@ gfxterm_menu (void)
return; return;
} }
grub_terminal_input_fake_sequence ((int []) { -1, -1, -1, GRUB_TERM_KEY_DOWN, -1, 'e', grub_terminal_input_fake_sequence ((int []) { -1, -1, -1, GRUB_TERM_KEY_DOWN, -1, 'e',
-1, GRUB_TERM_KEY_RIGHT, -1, 'x', -1, '\e', -1, '\e' }, 14); -1, GRUB_TERM_KEY_RIGHT, -1, 'x', -1, GRUB_TERM_ESC, -1, GRUB_TERM_ESC }, 14);
grub_video_checksum (tests[j].name); grub_video_checksum (tests[j].name);

View File

@ -55,7 +55,8 @@
#define GRUB_TERM_KEY_INSERT (GRUB_TERM_EXTENDED | 0x52) #define GRUB_TERM_KEY_INSERT (GRUB_TERM_EXTENDED | 0x52)
#define GRUB_TERM_KEY_CENTER (GRUB_TERM_EXTENDED | 0x4c) #define GRUB_TERM_KEY_CENTER (GRUB_TERM_EXTENDED | 0x4c)
#define GRUB_TERM_ESC '\e' /* Hex value is used for ESC, since '\e' is nonstandard */
#define GRUB_TERM_ESC 0x1b
#define GRUB_TERM_TAB '\t' #define GRUB_TERM_TAB '\t'
#define GRUB_TERM_BACKSPACE '\b' #define GRUB_TERM_BACKSPACE '\b'