merge with mainline

This commit is contained in:
BVK Chaitanya 2010-07-11 21:40:25 +05:30
commit 9ec82092f1
170 changed files with 34663 additions and 3738 deletions

View file

@ -184,13 +184,13 @@ grub_username_get (char buf[], unsigned buf_size)
if (cur_len + 2 < buf_size)
{
buf[cur_len++] = key;
grub_putchar (key);
grub_printf ("%c", key);
}
}
grub_memset (buf + cur_len, 0, buf_size - cur_len);
grub_putchar ('\n');
grub_xputs ("\n");
grub_refresh ();
return (key != '\e');

1294
normal/charset.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -362,6 +362,7 @@ grub_cmdline_get (const char *prompt)
grub_putcode ('\n', term);
}
grub_printf ("%s ", prompt_translated);
grub_normal_reset_more ();
{
struct cmdline_term *cl_term_cur;
@ -440,6 +441,8 @@ grub_cmdline_get (const char *prompt)
print_completion);
grub_free (bufu8);
grub_normal_reset_more ();
if (restore)
{
/* Restore the prompt. */
@ -614,7 +617,7 @@ grub_cmdline_get (const char *prompt)
grub_refresh ();
}
grub_putchar ('\n');
grub_xputs ("\n");
grub_refresh ();
/* Remove leading spaces. */

View file

@ -436,8 +436,9 @@ grub_normal_init_page (struct grub_term_output *term)
posx = (grub_term_width (term) - posx) / 2;
grub_term_gotoxy (term, posx, 1);
grub_print_ucs4 (unicode_msg, last_position, term);
grub_printf("\n\n");
grub_print_ucs4 (unicode_msg, last_position, 0, 0, term);
grub_putcode ('\n', term);
grub_putcode ('\n', term);
grub_free (unicode_msg);
}
@ -464,11 +465,15 @@ void
grub_normal_execute (const char *config, int nested, int batch)
{
grub_menu_t menu = 0;
const char *prefix = grub_env_get ("prefix");
const char *prefix;
read_lists (prefix);
grub_register_variable_hook ("prefix", NULL, read_lists_hook);
grub_command_execute ("parser.grub", 0, 0);
if (! nested)
{
prefix = grub_env_get ("prefix");
read_lists (prefix);
grub_register_variable_hook ("prefix", NULL, read_lists_hook);
grub_command_execute ("parser.grub", 0, 0);
}
if (config)
{
@ -563,9 +568,10 @@ grub_normal_reader_init (int nested)
{
grub_normal_init_page (term);
grub_term_setcursor (term, 1);
grub_print_message_indented (msg_formatted, 3, STANDARD_MARGIN, term);
grub_puts ("\n");
grub_putcode ('\n', term);
grub_putcode ('\n', term);
}
grub_free (msg_formatted);
@ -652,18 +658,38 @@ grub_env_write_pager (struct grub_env_var *var __attribute__ ((unused)),
return grub_strdup (val);
}
/* clear */
static grub_err_t
grub_mini_cmd_clear (struct grub_command *cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)),
char *argv[] __attribute__ ((unused)))
{
grub_cls ();
return 0;
}
static grub_command_t cmd_clear;
static void (*grub_xputs_saved) (const char *str);
GRUB_MOD_INIT(normal)
{
grub_context_init ();
grub_script_init ();
grub_xputs_saved = grub_xputs;
grub_xputs = grub_xputs_normal;
/* Normal mode shouldn't be unloaded. */
if (mod)
grub_dl_ref (mod);
cmd_clear =
grub_register_command ("clear", grub_mini_cmd_clear,
0, N_("Clear the screen."));
grub_set_history (GRUB_DEFAULT_HISTORY_SIZE);
grub_install_newline_hook ();
grub_register_variable_hook ("pager", 0, grub_env_write_pager);
/* Register a command "normal" for the rescue mode. */
@ -686,7 +712,10 @@ GRUB_MOD_FINI(normal)
grub_context_fini ();
grub_script_fini ();
grub_xputs = grub_xputs_saved;
grub_set_history (0);
grub_register_variable_hook ("pager", 0, 0);
grub_fs_autoload_hook = 0;
grub_unregister_command (cmd_clear);
}

View file

@ -29,6 +29,7 @@
#include <grub/auth.h>
#include <grub/i18n.h>
#include <grub/term.h>
#include <grub/script_sh.h>
/* Time to delay after displaying an error message about a default/fallback
entry failing to boot. */
@ -42,10 +43,10 @@ grub_err_t (*grub_gfxmenu_try_hook) (int entry, grub_menu_t menu,
void
grub_wait_after_message (void)
{
grub_putchar ('\n');
grub_xputs ("\n");
grub_printf_ (N_("Press any key to continue..."));
(void) grub_getkey ();
grub_putchar ('\n');
grub_xputs ("\n");
}
/* Get a menu entry by its index in the entry list. */
@ -141,6 +142,44 @@ get_and_remove_first_entry_number (const char *name)
return entry;
}
static void
grub_menu_execute_entry_real (grub_menu_entry_t entry)
{
const char *source;
auto grub_err_t getline (char **line, int cont);
grub_err_t getline (char **line, int cont __attribute__ ((unused)))
{
const char *p;
if (!source)
{
*line = 0;
return 0;
}
p = grub_strchr (source, '\n');
if (p)
*line = grub_strndup (source, p - source);
else
*line = grub_strdup (source);
source = p ? p + 1 : 0;
return 0;
}
source = entry->sourcecode;
while (source)
{
char *line;
getline (&line, 0);
grub_normal_parse_line (line, getline);
grub_free (line);
}
}
/* Run a menu entry. */
void
grub_menu_execute_entry(grub_menu_entry_t entry)
@ -159,7 +198,7 @@ grub_menu_execute_entry(grub_menu_entry_t entry)
grub_env_set ("chosen", entry->title);
grub_parser_execute ((char *) entry->sourcecode);
grub_menu_execute_entry_real (entry);
if (grub_errno == GRUB_ERR_NONE && grub_loader_is_loaded ())
/* Implicit execution of boot, only if something is loaded. */
@ -246,7 +285,6 @@ menu_init (int entry, grub_menu_t menu, int nested)
err = grub_gfxmenu_try_hook (entry, menu, nested);
if(!err)
continue;
grub_print_error ();
grub_errno = GRUB_ERR_NONE;
}
@ -571,13 +609,13 @@ show_menu (grub_menu_t menu, int nested)
}
else
{
int lines_before = grub_normal_get_line_counter ();
int chars_before = grub_normal_get_char_counter ();
grub_errno = GRUB_ERR_NONE;
grub_menu_execute_entry (e);
grub_print_error ();
grub_errno = GRUB_ERR_NONE;
if (lines_before != grub_normal_get_line_counter ())
if (chars_before != grub_normal_get_char_counter ())
grub_wait_after_message ();
}
}

View file

@ -26,6 +26,7 @@
#include <grub/script_sh.h>
#include <grub/auth.h>
#include <grub/i18n.h>
#include <grub/charset.h>
enum update_mode
{
@ -173,7 +174,7 @@ print_up (int flag, struct per_term_screen *term_screen)
GRUB_TERM_FIRST_ENTRY_Y);
if (flag)
grub_putcode (GRUB_TERM_DISP_UP, term_screen->term);
grub_putcode (GRUB_UNICODE_UPARROW, term_screen->term);
else
grub_putcode (' ', term_screen->term);
}
@ -188,7 +189,7 @@ print_down (int flag, struct per_term_screen *term_screen)
+ grub_term_num_entries (term_screen->term));
if (flag)
grub_putcode (GRUB_TERM_DISP_DOWN, term_screen->term);
grub_putcode (GRUB_UNICODE_DOWNARROW, term_screen->term);
else
grub_putcode (' ', term_screen->term);
}
@ -243,6 +244,9 @@ update_screen (struct screen *screen, struct per_term_screen *term_screen,
{
int column;
if (linep >= screen->lines + screen->num_lines)
break;
for (column = 0;
column <= linep->len
&& y < grub_term_num_entries (term_screen->term);
@ -337,7 +341,7 @@ insert_string (struct screen *screen, char *s, int update)
screen->num_lines++;
screen->lines = grub_realloc (screen->lines,
screen->num_lines
* sizeof (struct line));
* sizeof (screen->lines[0]));
if (! screen->lines)
return 0;
@ -1020,87 +1024,92 @@ complete (struct screen *screen, int continuous, int update)
insert = grub_normal_do_completion (linep->buf, &restore, store_completion);
linep->buf[screen->column] = saved_char;
buflen = grub_strlen (completion_buffer.buf);
ucs4 = grub_malloc (sizeof (grub_uint32_t) * (buflen + 1));
if (!ucs4)
if (completion_buffer.buf)
{
grub_print_error ();
grub_errno = GRUB_ERR_NONE;
return 1;
}
buflen = grub_strlen (completion_buffer.buf);
ucs4 = grub_malloc (sizeof (grub_uint32_t) * (buflen + 1));
if (!ucs4)
{
grub_print_error ();
grub_errno = GRUB_ERR_NONE;
return 1;
}
ucs4len = grub_utf8_to_ucs4 (ucs4, buflen,
(grub_uint8_t *) completion_buffer.buf,
buflen, 0);
ucs4[ucs4len] = 0;
ucs4len = grub_utf8_to_ucs4 (ucs4, buflen,
(grub_uint8_t *) completion_buffer.buf,
buflen, 0);
ucs4[ucs4len] = 0;
if (restore)
for (i = 0; i < screen->nterms; i++)
{
int num_sections = ((completion_buffer.len
+ grub_term_width (screen->terms[i].term) - 8 - 1)
/ (grub_term_width (screen->terms[i].term) - 8));
grub_uint32_t *endp;
grub_uint16_t pos;
grub_uint32_t *p = ucs4;
pos = grub_term_getxy (screen->terms[i].term);
grub_term_gotoxy (screen->terms[i].term, 0,
grub_term_height (screen->terms[i].term) - 3);
screen->completion_shown = 1;
grub_term_gotoxy (screen->terms[i].term, 0,
grub_term_height (screen->terms[i].term) - 3);
grub_puts_terminal (" ", screen->terms[i].term);
switch (completion_type)
if (restore)
for (i = 0; i < screen->nterms; i++)
{
case GRUB_COMPLETION_TYPE_COMMAND:
grub_puts_terminal (_("Possible commands are:"),
screen->terms[i].term);
break;
case GRUB_COMPLETION_TYPE_DEVICE:
grub_puts_terminal (_("Possible devices are:"),
screen->terms[i].term);
break;
case GRUB_COMPLETION_TYPE_FILE:
grub_puts_terminal (_("Possible files are:"),
screen->terms[i].term);
break;
case GRUB_COMPLETION_TYPE_PARTITION:
grub_puts_terminal (_("Possible partitions are:"),
screen->terms[i].term);
break;
case GRUB_COMPLETION_TYPE_ARGUMENT:
grub_puts_terminal (_("Possible arguments are:"),
screen->terms[i].term);
break;
default:
grub_puts_terminal (_("Possible things are:"),
screen->terms[i].term);
break;
int num_sections = ((completion_buffer.len
+ grub_term_width (screen->terms[i].term)
- 8 - 1)
/ (grub_term_width (screen->terms[i].term)
- 8));
grub_uint32_t *endp;
grub_uint16_t pos;
grub_uint32_t *p = ucs4;
pos = grub_term_getxy (screen->terms[i].term);
grub_term_gotoxy (screen->terms[i].term, 0,
grub_term_height (screen->terms[i].term) - 3);
screen->completion_shown = 1;
grub_term_gotoxy (screen->terms[i].term, 0,
grub_term_height (screen->terms[i].term) - 3);
grub_puts_terminal (" ", screen->terms[i].term);
switch (completion_type)
{
case GRUB_COMPLETION_TYPE_COMMAND:
grub_puts_terminal (_("Possible commands are:"),
screen->terms[i].term);
break;
case GRUB_COMPLETION_TYPE_DEVICE:
grub_puts_terminal (_("Possible devices are:"),
screen->terms[i].term);
break;
case GRUB_COMPLETION_TYPE_FILE:
grub_puts_terminal (_("Possible files are:"),
screen->terms[i].term);
break;
case GRUB_COMPLETION_TYPE_PARTITION:
grub_puts_terminal (_("Possible partitions are:"),
screen->terms[i].term);
break;
case GRUB_COMPLETION_TYPE_ARGUMENT:
grub_puts_terminal (_("Possible arguments are:"),
screen->terms[i].term);
break;
default:
grub_puts_terminal (_("Possible things are:"),
screen->terms[i].term);
break;
}
grub_puts_terminal ("\n ", screen->terms[i].term);
p += (count % num_sections)
* (grub_term_width (screen->terms[i].term) - 8);
endp = p + (grub_term_width (screen->terms[i].term) - 8);
if (p != ucs4)
grub_putcode (GRUB_UNICODE_LEFTARROW, screen->terms[i].term);
else
grub_putcode (' ', screen->terms[i].term);
grub_print_ucs4 (p, ucs4 + ucs4len < endp ? ucs4 + ucs4len : endp,
0, 0, screen->terms[i].term);
if (ucs4 + ucs4len > endp)
grub_putcode (GRUB_UNICODE_RIGHTARROW, screen->terms[i].term);
grub_term_gotoxy (screen->terms[i].term, pos >> 8, pos & 0xFF);
}
grub_puts_terminal ("\n ", screen->terms[i].term);
p += (count % num_sections)
* (grub_term_width (screen->terms[i].term) - 8);
endp = p + (grub_term_width (screen->terms[i].term) - 8);
if (p != ucs4)
grub_putcode (GRUB_TERM_DISP_LEFT, screen->terms[i].term);
else
grub_putcode (' ', screen->terms[i].term);
while (*p && p < endp)
grub_putcode (*p++, screen->terms[i].term);
if (*p)
grub_putcode (GRUB_TERM_DISP_RIGHT, screen->terms[i].term);
grub_term_gotoxy (screen->terms[i].term, pos >> 8, pos & 0xFF);
}
}
if (insert)
{
@ -1362,8 +1371,13 @@ grub_menu_entry_run (grub_menu_entry_t entry)
goto refresh;
case 24: /* C-x */
if (! run (screen))
goto fail;
{
int chars_before = grub_normal_get_char_counter ();
run (screen);
if (chars_before != grub_normal_get_char_counter ())
grub_wait_after_message ();
}
goto refresh;
case 18: /* C-r */
@ -1394,7 +1408,7 @@ grub_menu_entry_run (grub_menu_entry_t entry)
grub_cls ();
grub_print_error ();
grub_errno = GRUB_ERR_NONE;
grub_putchar ('\n');
grub_xputs ("\n");
grub_printf_ (N_("Press any key to continue..."));
(void) grub_getkey ();
}

View file

@ -38,26 +38,6 @@ struct menu_viewer_data
struct grub_term_output *term;
};
static void
print_spaces (int number_spaces, struct grub_term_output *term)
{
int i;
for (i = 0; i < number_spaces; i++)
grub_putcode (' ', term);
}
void
grub_print_ucs4 (const grub_uint32_t * str,
const grub_uint32_t * last_position,
struct grub_term_output *term)
{
while (str < last_position)
{
grub_putcode (*str, term);
str++;
}
}
grub_ssize_t
grub_getstringwidth (grub_uint32_t * str, const grub_uint32_t * last_position,
struct grub_term_output *term)
@ -66,8 +46,9 @@ grub_getstringwidth (grub_uint32_t * str, const grub_uint32_t * last_position,
while (str < last_position)
{
width += grub_term_getcharwidth (term, *str);
str++;
struct grub_unicode_glyph glyph;
str += grub_unicode_aglomerate_comb (str, last_position - str, &glyph);
width += grub_term_getcharwidth (term, &glyph);
}
return width;
}
@ -76,16 +57,11 @@ void
grub_print_message_indented (const char *msg, int margin_left, int margin_right,
struct grub_term_output *term)
{
int line_len;
grub_uint32_t *unicode_msg;
grub_uint32_t *last_position;
int msg_len;
line_len = grub_term_width (term) - grub_term_getcharwidth (term, 'm') *
(margin_left + margin_right);
msg_len = grub_utf8_to_ucs4_alloc (msg, &unicode_msg, &last_position);
if (msg_len < 0)
@ -93,40 +69,8 @@ grub_print_message_indented (const char *msg, int margin_left, int margin_right,
return;
}
grub_uint32_t *current_position = unicode_msg;
grub_print_ucs4 (unicode_msg, last_position, margin_left, margin_right, term);
grub_uint32_t *next_new_line = unicode_msg;
int first_loop = 1;
while (current_position < last_position)
{
if (! first_loop)
grub_putcode ('\n', term);
next_new_line = (grub_uint32_t *) last_position;
while (grub_getstringwidth (current_position, next_new_line,term)
> line_len
|| (next_new_line != last_position && *next_new_line != ' '
&& next_new_line > current_position))
{
next_new_line--;
}
if (next_new_line == current_position)
{
next_new_line = (next_new_line + line_len > last_position) ?
(grub_uint32_t *) last_position : next_new_line + line_len;
}
print_spaces (margin_left, term);
grub_print_ucs4 (current_position, next_new_line, term);
next_new_line++;
current_position = next_new_line;
first_loop = 0;
}
grub_free (unicode_msg);
}
@ -139,27 +83,27 @@ draw_border (struct grub_term_output *term)
grub_term_setcolorstate (term, GRUB_TERM_COLOR_NORMAL);
grub_term_gotoxy (term, GRUB_TERM_MARGIN, GRUB_TERM_TOP_BORDER_Y);
grub_putcode (GRUB_TERM_DISP_UL, term);
grub_putcode (GRUB_UNICODE_CORNER_UL, term);
for (i = 0; i < (unsigned) grub_term_border_width (term) - 2; i++)
grub_putcode (GRUB_TERM_DISP_HLINE, term);
grub_putcode (GRUB_TERM_DISP_UR, term);
grub_putcode (GRUB_UNICODE_HLINE, term);
grub_putcode (GRUB_UNICODE_CORNER_UR, term);
for (i = 0; i < (unsigned) grub_term_num_entries (term); i++)
{
grub_term_gotoxy (term, GRUB_TERM_MARGIN, GRUB_TERM_TOP_BORDER_Y + i + 1);
grub_putcode (GRUB_TERM_DISP_VLINE, term);
grub_putcode (GRUB_UNICODE_VLINE, term);
grub_term_gotoxy (term, GRUB_TERM_MARGIN + grub_term_border_width (term)
- 1,
GRUB_TERM_TOP_BORDER_Y + i + 1);
grub_putcode (GRUB_TERM_DISP_VLINE, term);
grub_putcode (GRUB_UNICODE_VLINE, term);
}
grub_term_gotoxy (term, GRUB_TERM_MARGIN,
GRUB_TERM_TOP_BORDER_Y + grub_term_num_entries (term) + 1);
grub_putcode (GRUB_TERM_DISP_LL, term);
grub_putcode (GRUB_UNICODE_CORNER_LL, term);
for (i = 0; i < (unsigned) grub_term_border_width (term) - 2; i++)
grub_putcode (GRUB_TERM_DISP_HLINE, term);
grub_putcode (GRUB_TERM_DISP_LR, term);
grub_putcode (GRUB_UNICODE_HLINE, term);
grub_putcode (GRUB_UNICODE_CORNER_LR, term);
grub_term_setcolorstate (term, GRUB_TERM_COLOR_NORMAL);
@ -194,11 +138,11 @@ command-line or ESC to discard edits and return to the GRUB menu."),
"entry is highlighted.\n");
char *msg_translated;
msg_translated = grub_xasprintf (msg, (grub_uint32_t) GRUB_TERM_DISP_UP,
(grub_uint32_t) GRUB_TERM_DISP_DOWN);
msg_translated = grub_xasprintf (msg, GRUB_UNICODE_UPARROW,
GRUB_UNICODE_DOWNARROW);
if (!msg_translated)
return;
grub_putchar ('\n');
grub_putcode ('\n', term);
grub_print_message_indented (msg_translated, STANDARD_MARGIN,
STANDARD_MARGIN, term);
@ -259,34 +203,55 @@ print_entry (int y, int highlight, grub_menu_entry_t entry,
grub_term_gotoxy (term, GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_MARGIN, y);
int last_printed = 0;
for (x = GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_MARGIN + 1, i = 0;
x < (int) (GRUB_TERM_LEFT_BORDER_X + grub_term_border_width (term)
- GRUB_TERM_MARGIN);
i++)
- GRUB_TERM_MARGIN);)
{
if (i < len
&& x <= (int) (GRUB_TERM_LEFT_BORDER_X + grub_term_border_width (term)
- GRUB_TERM_MARGIN - 1))
{
grub_ssize_t width;
struct grub_unicode_glyph glyph;
width = grub_term_getcharwidth (term, unicode_title[i]);
i += grub_unicode_aglomerate_comb (unicode_title + i,
len - i, &glyph);
if (x + width > (int) (GRUB_TERM_LEFT_BORDER_X
width = grub_term_getcharwidth (term, &glyph);
grub_free (glyph.combining);
if (x + width <= (int) (GRUB_TERM_LEFT_BORDER_X
+ grub_term_border_width (term)
- GRUB_TERM_MARGIN - 1))
grub_putcode (GRUB_TERM_DISP_RIGHT, term);
else
grub_putcode (unicode_title[i], term);
last_printed = i;
x += width;
}
else
{
grub_putcode (' ', term);
x++;
}
break;
}
grub_print_ucs4 (unicode_title,
unicode_title + last_printed, 0, 0, term);
if (last_printed != len)
{
grub_putcode (GRUB_UNICODE_RIGHTARROW, term);
struct grub_unicode_glyph pseudo_glyph = {
.base = GRUB_UNICODE_RIGHTARROW,
.variant = 0,
.attributes = 0,
.ncomb = 0,
.combining = 0,
.estimated_width = 1
};
x += grub_term_getcharwidth (term, &pseudo_glyph);
}
for (; x < (int) (GRUB_TERM_LEFT_BORDER_X + grub_term_border_width (term)
- GRUB_TERM_MARGIN); x++)
grub_putcode (' ', term);
grub_term_setcolorstate (term, GRUB_TERM_COLOR_NORMAL);
grub_putcode (' ', term);
@ -309,7 +274,7 @@ print_entries (grub_menu_t menu, int first, int offset,
GRUB_TERM_FIRST_ENTRY_Y);
if (first)
grub_putcode (GRUB_TERM_DISP_UP, term);
grub_putcode (GRUB_UNICODE_UPARROW, term);
else
grub_putcode (' ', term);
@ -327,7 +292,7 @@ print_entries (grub_menu_t menu, int first, int offset,
GRUB_TERM_TOP_BORDER_Y + grub_term_num_entries (term));
if (e)
grub_putcode (GRUB_TERM_DISP_DOWN, term);
grub_putcode (GRUB_UNICODE_DOWNARROW, term);
else
grub_putcode (' ', term);
@ -385,7 +350,7 @@ menu_text_print_timeout (int timeout, void *dataptr)
grub_print_message_indented (msg_translated, 3, 0, data->term);
posx = grub_term_getxy (data->term) >> 8;
print_spaces (grub_term_width (data->term) - posx - 1, data->term);
grub_print_spaces (data->term, grub_term_width (data->term) - posx - 1);
grub_term_gotoxy (data->term,
grub_term_cursor_x (data->term),
@ -443,7 +408,7 @@ menu_text_clear_timeout (void *dataptr)
struct menu_viewer_data *data = dataptr;
grub_term_gotoxy (data->term, 0, grub_term_height (data->term) - 3);
print_spaces (grub_term_width (data->term) - 1, data->term);
grub_print_spaces (data->term, grub_term_width (data->term) - 1);
grub_term_gotoxy (data->term, grub_term_cursor_x (data->term),
GRUB_TERM_FIRST_ENTRY_Y + data->offset);
grub_term_refresh (data->term);

View file

@ -37,14 +37,14 @@ grub_normal_print_device_info (const char *name)
p = grub_strchr (name, ',');
if (p)
{
grub_putchar ('\t');
grub_xputs ("\t");
grub_printf_ (N_("Partition %s:"), name);
grub_putchar (' ');
grub_xputs (" ");
}
else
{
grub_printf_ (N_("Device %s:"), name);
grub_putchar (' ');
grub_xputs (" ");
}
dev = grub_device_open (name);
@ -69,7 +69,7 @@ grub_normal_print_device_info (const char *name)
{
if (label && grub_strlen (label))
{
grub_putchar (' ');
grub_xputs (" ");
grub_printf_ (N_("- Label \"%s\""), label);
}
grub_free (label);
@ -84,7 +84,7 @@ grub_normal_print_device_info (const char *name)
if (grub_errno == GRUB_ERR_NONE)
{
grub_unixtime2datetime (tm, &datetime);
grub_putchar (' ');
grub_xputs (" ");
grub_printf_ (N_("- Last modification time %d-%02d-%02d "
"%02d:%02d:%02d %s"),
datetime.year, datetime.month, datetime.day,
@ -115,6 +115,6 @@ grub_normal_print_device_info (const char *name)
grub_device_close (dev);
}
grub_putchar ('\n');
grub_xputs ("\n");
return grub_errno;
}

View file

@ -23,57 +23,87 @@
#include <grub/dl.h>
#include <grub/env.h>
#include <grub/normal.h>
#include <grub/charset.h>
/* The amount of lines counted by the pager. */
static unsigned grub_more_lines;
struct term_state
{
struct term_state *next;
const struct grub_unicode_glyph *backlog_glyphs;
const grub_uint32_t *backlog_ucs4;
grub_size_t backlog_len;
void *free;
int num_lines;
char *term_name;
};
static struct term_state *term_states = NULL;
/* If the more pager is active. */
static int grub_more;
static int grub_normal_line_counter = 0;
static int grub_normal_char_counter = 0;
int
grub_normal_get_line_counter (void)
grub_normal_get_char_counter (void)
{
return grub_normal_line_counter;
return grub_normal_char_counter;
}
void
grub_normal_reset_more (void)
{
static struct term_state *state;
for (state = term_states; state; state = state->next)
state->num_lines = 0;
}
static void
process_newline (void)
print_more (void)
{
struct grub_term_output *cur;
unsigned height = -1;
char key;
grub_uint16_t *pos;
grub_term_output_t term;
grub_uint32_t *unicode_str, *unicode_last_position;
FOR_ACTIVE_TERM_OUTPUTS(cur)
if (grub_term_height (cur) < height)
height = grub_term_height (cur);
grub_more_lines++;
pos = grub_term_save_pos ();
grub_normal_line_counter++;
grub_utf8_to_ucs4_alloc ("--MORE--", &unicode_str,
&unicode_last_position);
if (grub_more && grub_more_lines >= height - 1)
if (!unicode_str)
{
char key;
grub_uint16_t *pos;
grub_errno = GRUB_ERR_NONE;
return;
}
pos = grub_term_save_pos ();
grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT);
grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT);
grub_printf ("--MORE--");
grub_setcolorstate (GRUB_TERM_COLOR_STANDARD);
FOR_ACTIVE_TERM_OUTPUTS(term)
{
grub_print_ucs4 (unicode_str, unicode_last_position, 0, 0, term);
}
grub_setcolorstate (GRUB_TERM_COLOR_STANDARD);
key = grub_getkey ();
grub_free (unicode_str);
key = grub_getkey ();
/* Remove the message. */
grub_term_restore_pos (pos);
grub_printf (" ");
grub_term_restore_pos (pos);
/* Remove the message. */
grub_term_restore_pos (pos);
FOR_ACTIVE_TERM_OUTPUTS(term)
grub_print_spaces (term, 8);
grub_term_restore_pos (pos);
/* Scroll one lines or an entire page, depending on the key. */
if (key == '\r' || key =='\n')
grub_more_lines = height - 2;
else
grub_more_lines = 0;
/* Scroll one lines or an entire page, depending on the key. */
if (key == '\r' || key =='\n')
grub_normal_reset_more ();
else
{
static struct term_state *state;
for (state = term_states; state; state = state->next)
state->num_lines -= 2;
}
}
@ -84,30 +114,99 @@ grub_set_more (int onoff)
grub_more++;
else
grub_more--;
grub_more_lines = 0;
grub_normal_reset_more ();
}
void
grub_install_newline_hook (void)
enum
{
GRUB_CP437_UPARROW = 0x18,
GRUB_CP437_DOWNARROW = 0x19,
GRUB_CP437_RIGHTARROW = 0x1a,
GRUB_CP437_LEFTARROW = 0x1b,
GRUB_CP437_VLINE = 0xb3,
GRUB_CP437_CORNER_UR = 0xbf,
GRUB_CP437_CORNER_LL = 0xc0,
GRUB_CP437_HLINE = 0xc4,
GRUB_CP437_CORNER_LR = 0xd9,
GRUB_CP437_CORNER_UL = 0xda,
};
static grub_uint32_t
map_code (grub_uint32_t in, struct grub_term_output *term)
{
grub_newline_hook = process_newline;
if (in <= 0x7f)
return in;
switch (term->flags & GRUB_TERM_CODE_TYPE_MASK)
{
case GRUB_TERM_CODE_TYPE_CP437:
switch (in)
{
case GRUB_UNICODE_LEFTARROW:
return GRUB_CP437_LEFTARROW;
case GRUB_UNICODE_UPARROW:
return GRUB_CP437_UPARROW;
case GRUB_UNICODE_RIGHTARROW:
return GRUB_CP437_RIGHTARROW;
case GRUB_UNICODE_DOWNARROW:
return GRUB_CP437_DOWNARROW;
case GRUB_UNICODE_HLINE:
return GRUB_CP437_HLINE;
case GRUB_UNICODE_VLINE:
return GRUB_CP437_VLINE;
case GRUB_UNICODE_CORNER_UL:
return GRUB_CP437_CORNER_UL;
case GRUB_UNICODE_CORNER_UR:
return GRUB_CP437_CORNER_UR;
case GRUB_UNICODE_CORNER_LL:
return GRUB_CP437_CORNER_LL;
case GRUB_UNICODE_CORNER_LR:
return GRUB_CP437_CORNER_LR;
}
return '?';
case GRUB_TERM_CODE_TYPE_ASCII:
/* Better than nothing. */
switch (in)
{
case GRUB_UNICODE_LEFTARROW:
return '<';
case GRUB_UNICODE_UPARROW:
return '^';
case GRUB_UNICODE_RIGHTARROW:
return '>';
case GRUB_UNICODE_DOWNARROW:
return 'v';
case GRUB_UNICODE_HLINE:
return '-';
case GRUB_UNICODE_VLINE:
return '|';
case GRUB_UNICODE_CORNER_UL:
case GRUB_UNICODE_CORNER_UR:
case GRUB_UNICODE_CORNER_LL:
case GRUB_UNICODE_CORNER_LR:
return '+';
}
return '?';
}
return in;
}
void
grub_puts_terminal (const char *str, struct grub_term_output *term)
{
grub_uint32_t code;
grub_ssize_t ret;
const grub_uint8_t *ptr = (const grub_uint8_t *) str;
const grub_uint8_t *end;
end = (const grub_uint8_t *) (str + grub_strlen (str));
grub_uint32_t *unicode_str, *unicode_last_position;
grub_utf8_to_ucs4_alloc (str, &unicode_str,
&unicode_last_position);
while (*ptr)
{
ret = grub_utf8_to_ucs4 (&code, 1, ptr, end - ptr, &ptr);
grub_putcode (code, term);
}
grub_print_ucs4 (unicode_str, unicode_last_position, 0, 0, term);
grub_free (unicode_str);
}
grub_uint16_t *
@ -262,3 +361,435 @@ read_terminal_list (const char *prefix)
grub_errno = GRUB_ERR_NONE;
}
static void
putglyph (const struct grub_unicode_glyph *c, struct grub_term_output *term)
{
struct grub_unicode_glyph c2 =
{
.variant = 0,
.attributes = 0,
.ncomb = 0,
.combining = 0,
.estimated_width = 1
};
grub_normal_char_counter++;
if (c->base == '\t' && term->getxy)
{
int n;
n = 8 - ((term->getxy (term) >> 8) & 7);
c2.base = ' ';
while (n--)
(term->putchar) (term, &c2);
return;
}
if ((term->flags & GRUB_TERM_CODE_TYPE_MASK)
== GRUB_TERM_CODE_TYPE_UTF8_LOGICAL
|| (term->flags & GRUB_TERM_CODE_TYPE_MASK)
== GRUB_TERM_CODE_TYPE_UTF8_VISUAL)
{
int i;
c2.estimated_width = grub_term_getcharwidth (term, c);
for (i = -1; i < (int) c->ncomb; i++)
{
grub_uint8_t u8[20], *ptr;
grub_uint32_t code;
if (i == -1)
{
code = c->base;
if ((term->flags & GRUB_TERM_CODE_TYPE_MASK)
== GRUB_TERM_CODE_TYPE_UTF8_VISUAL)
{
if ((c->attributes & GRUB_UNICODE_GLYPH_ATTRIBUTE_MIRROR))
code = grub_unicode_mirror_code (code);
code = grub_unicode_shape_code (code, c->attributes);
}
}
else
code = c->combining[i].code;
grub_ucs4_to_utf8 (&code, 1, u8, sizeof (u8));
for (ptr = u8; *ptr; ptr++)
{
c2.base = *ptr;
(term->putchar) (term, &c2);
c2.estimated_width = 0;
}
}
c2.estimated_width = 1;
}
else
(term->putchar) (term, c);
if (c->base == '\n')
{
c2.base = '\r';
(term->putchar) (term, &c2);
}
}
static void
putcode_real (grub_uint32_t code, struct grub_term_output *term)
{
struct grub_unicode_glyph c =
{
.variant = 0,
.attributes = 0,
.ncomb = 0,
.combining = 0,
.estimated_width = 1
};
c.base = map_code (code, term);
putglyph (&c, term);
}
/* Put a Unicode character. */
void
grub_putcode (grub_uint32_t code, struct grub_term_output *term)
{
/* Combining character by itself? */
if (grub_unicode_get_comb_type (code) != GRUB_UNICODE_COMB_NONE)
return;
putcode_real (code, term);
}
static grub_ssize_t
get_maxwidth (struct grub_term_output *term,
int margin_left, int margin_right)
{
struct grub_unicode_glyph space_glyph = {
.base = ' ',
.variant = 0,
.attributes = 0,
.ncomb = 0,
.combining = 0
};
return (grub_term_width (term)
- grub_term_getcharwidth (term, &space_glyph)
* (margin_left + margin_right) - 1);
}
static grub_ssize_t
get_startwidth (struct grub_term_output *term,
int margin_left)
{
return ((term->getxy (term) >> 8) & 0xff) - margin_left;
}
static int
print_ucs4_terminal (const grub_uint32_t * str,
const grub_uint32_t * last_position,
int margin_left, int margin_right,
struct grub_term_output *term,
struct term_state *state)
{
const grub_uint32_t *ptr;
grub_ssize_t startwidth = get_startwidth (term, margin_left);
grub_ssize_t line_width = startwidth;
grub_ssize_t lastspacewidth = 0;
grub_ssize_t max_width = get_maxwidth (term, margin_left, margin_right);
const grub_uint32_t *line_start = str, *last_space = str - 1;
for (ptr = str; ptr < last_position; ptr++)
{
grub_ssize_t last_width = 0;
if (grub_unicode_get_comb_type (*ptr) == GRUB_UNICODE_COMB_NONE)
{
struct grub_unicode_glyph c = {
.variant = 0,
.attributes = 0,
.ncomb = 0,
.combining = 0
};
c.base = *ptr;
line_width += last_width = grub_term_getcharwidth (term, &c);
}
if (*ptr == ' ')
{
lastspacewidth = line_width;
last_space = ptr;
}
if (line_width > max_width || *ptr == '\n')
{
const grub_uint32_t *ptr2;
if (line_width > max_width && last_space > line_start)
ptr = last_space;
else if (line_width > max_width
&& line_start == str && startwidth != 0)
{
ptr = str;
lastspacewidth = startwidth;
}
else
lastspacewidth = line_width - last_width;
for (ptr2 = line_start; ptr2 < ptr; ptr2++)
{
/* Skip combining characters on non-UTF8 terminals. */
if ((term->flags & GRUB_TERM_CODE_TYPE_MASK)
!= GRUB_TERM_CODE_TYPE_UTF8_LOGICAL
&& grub_unicode_get_comb_type (*ptr2)
!= GRUB_UNICODE_COMB_NONE)
continue;
putcode_real (*ptr2, term);
}
grub_print_spaces (term, margin_right);
grub_putcode ('\n', term);
if (state && ++state->num_lines
>= (grub_ssize_t) grub_term_height (term) - 2)
{
state->backlog_ucs4 = (ptr == last_space || *ptr == '\n')
? ptr + 1 : ptr;
state->backlog_len = last_position - state->backlog_ucs4;
return 1;
}
line_width -= lastspacewidth;
grub_print_spaces (term, margin_left);
if (ptr == last_space || *ptr == '\n')
ptr++;
line_start = ptr;
}
}
{
const grub_uint32_t *ptr2;
for (ptr2 = line_start; ptr2 < last_position; ptr2++)
{
/* Skip combining characters on non-UTF8 terminals. */
if ((term->flags & GRUB_TERM_CODE_TYPE_MASK)
!= GRUB_TERM_CODE_TYPE_UTF8_LOGICAL
&& grub_unicode_get_comb_type (*ptr2)
!= GRUB_UNICODE_COMB_NONE)
continue;
putcode_real (*ptr2, term);
}
}
return 0;
}
static struct term_state *
find_term_state (struct grub_term_output *term)
{
struct term_state *state;
for (state = term_states; state; state = state->next)
if (grub_strcmp (state->term_name, term->name) == 0)
return state;
state = grub_zalloc (sizeof (*state));
if (!state)
{
grub_errno = GRUB_ERR_NONE;
return NULL;
}
state->term_name = grub_strdup (term->name);
state->next = term_states;
term_states = state;
return state;
}
static int
put_glyphs_terminal (const struct grub_unicode_glyph *visual,
grub_ssize_t visual_len,
int margin_left, int margin_right,
struct grub_term_output *term,
struct term_state *state)
{
const struct grub_unicode_glyph *visual_ptr;
for (visual_ptr = visual; visual_ptr < visual + visual_len; visual_ptr++)
{
if (visual_ptr->base == '\n')
grub_print_spaces (term, margin_right);
putglyph (visual_ptr, term);
if (visual_ptr->base == '\n')
{
if (state && ++state->num_lines
>= (grub_ssize_t) grub_term_height (term) - 2)
{
state->backlog_glyphs = visual_ptr + 1;
state->backlog_len = visual_len - (visual - visual_ptr) - 1;
return 1;
}
grub_print_spaces (term, margin_left);
}
grub_free (visual_ptr->combining);
}
return 0;
}
static int
print_backlog (struct grub_term_output *term,
int margin_left, int margin_right)
{
struct term_state *state = find_term_state (term);
if (!state)
return 0;
if (state->backlog_ucs4)
{
int ret;
ret = print_ucs4_terminal (state->backlog_ucs4,
state->backlog_ucs4 + state->backlog_len,
margin_left, margin_right, term, state);
if (!ret)
{
grub_free (state->free);
state->free = NULL;
state->backlog_len = 0;
}
return ret;
}
if (state->backlog_glyphs)
{
int ret;
ret = put_glyphs_terminal (state->backlog_glyphs,
state->backlog_len,
margin_left, margin_right, term, state);
if (!ret)
{
grub_free (state->free);
state->free = NULL;
state->backlog_len = 0;
}
return ret;
}
return 0;
}
static int
print_ucs4_real (const grub_uint32_t * str,
const grub_uint32_t * last_position,
int margin_left, int margin_right,
struct grub_term_output *term, int backlog)
{
struct term_state *state = NULL;
if (backlog)
state = find_term_state (term);
if (((term->getxy (term) >> 8) & 0xff) < margin_left)
grub_print_spaces (term, margin_left - ((term->getxy (term) >> 8) & 0xff));
if ((term->flags & GRUB_TERM_CODE_TYPE_MASK)
== GRUB_TERM_CODE_TYPE_VISUAL_GLYPHS
|| (term->flags & GRUB_TERM_CODE_TYPE_MASK)
== GRUB_TERM_CODE_TYPE_UTF8_VISUAL)
{
grub_ssize_t visual_len;
struct grub_unicode_glyph *visual;
int ret;
auto grub_ssize_t getcharwidth (const struct grub_unicode_glyph *c);
grub_ssize_t getcharwidth (const struct grub_unicode_glyph *c)
{
return grub_term_getcharwidth (term, c);
}
visual_len = grub_bidi_logical_to_visual (str, last_position - str,
&visual, getcharwidth,
get_maxwidth (term,
margin_left,
margin_right),
get_startwidth (term,
margin_left));
if (visual_len < 0)
{
grub_print_error ();
return 0;
}
ret = put_glyphs_terminal (visual, visual_len, margin_left, margin_right,
term, state);
if (!ret)
grub_free (visual);
else
state->free = visual;
return ret;
}
return print_ucs4_terminal (str, last_position, margin_left, margin_right,
term, state);
}
void
grub_print_ucs4 (const grub_uint32_t * str,
const grub_uint32_t * last_position,
int margin_left, int margin_right,
struct grub_term_output *term)
{
print_ucs4_real (str, last_position, margin_left, margin_right,
term, 0);
}
void
grub_xputs_normal (const char *str)
{
grub_term_output_t term;
grub_uint32_t *unicode_str, *unicode_last_position;
int backlog = 0;
grub_utf8_to_ucs4_alloc (str, &unicode_str,
&unicode_last_position);
if (!unicode_str)
{
grub_errno = GRUB_ERR_NONE;
return;
}
FOR_ACTIVE_TERM_OUTPUTS(term)
{
int cur;
cur = print_ucs4_real (unicode_str, unicode_last_position, 0, 0,
term, grub_more);
if (cur)
backlog = 1;
}
while (backlog)
{
print_more ();
backlog = 0;
FOR_ACTIVE_TERM_OUTPUTS(term)
{
int cur;
cur = print_backlog (term, 0, 0);
if (cur)
backlog = 1;
}
}
grub_free (unicode_str);
}
void
grub_cls (void)
{
struct grub_term_output *term;
FOR_ACTIVE_TERM_OUTPUTS(term)
{
if ((term->flags & GRUB_TERM_DUMB) || (grub_env_get ("debug")))
{
grub_putcode ('\n', term);
grub_term_refresh (term);
}
else
(term->cls) (term);
}
}