2009-12-23 23:37:11 +00:00
|
|
|
/*
|
|
|
|
* GRUB -- GRand Unified Bootloader
|
|
|
|
* Copyright (C) 2002,2003,2005,2007,2008,2009 Free Software Foundation, Inc.
|
|
|
|
*
|
|
|
|
* GRUB is free software: you can redistribute it and/or modify
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
#include <grub/term.h>
|
|
|
|
#include <grub/misc.h>
|
|
|
|
#include <grub/mm.h>
|
2009-12-25 02:37:20 +00:00
|
|
|
#include <grub/file.h>
|
|
|
|
#include <grub/dl.h>
|
|
|
|
#include <grub/env.h>
|
|
|
|
#include <grub/normal.h>
|
2010-03-15 10:49:27 +00:00
|
|
|
#include <grub/charset.h>
|
2011-11-11 20:44:56 +00:00
|
|
|
#include <grub/i18n.h>
|
2009-12-24 14:34:33 +00:00
|
|
|
|
2010-03-23 15:51:53 +00:00
|
|
|
struct term_state
|
|
|
|
{
|
|
|
|
struct term_state *next;
|
2013-05-04 20:23:23 +00:00
|
|
|
struct grub_unicode_glyph *backlog_glyphs;
|
2010-03-23 16:54:31 +00:00
|
|
|
const grub_uint32_t *backlog_ucs4;
|
2012-03-27 15:07:26 +00:00
|
|
|
int backlog_fixed_tab;
|
2010-03-23 16:54:31 +00:00
|
|
|
grub_size_t backlog_len;
|
|
|
|
|
2013-01-16 12:41:16 +00:00
|
|
|
int bidi_stack_depth;
|
|
|
|
grub_uint8_t bidi_stack[GRUB_BIDI_MAX_EXPLICIT_LEVEL];
|
|
|
|
int invalid_pushes;
|
|
|
|
|
2010-03-23 16:54:31 +00:00
|
|
|
void *free;
|
|
|
|
int num_lines;
|
2010-03-23 15:51:53 +00:00
|
|
|
char *term_name;
|
|
|
|
};
|
|
|
|
|
2012-03-27 15:07:26 +00:00
|
|
|
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,
|
2013-01-16 12:41:16 +00:00
|
|
|
int dry_run, int fixed_tab, unsigned skip_lines,
|
|
|
|
unsigned max_lines,
|
|
|
|
grub_uint32_t contchar, struct grub_term_pos *pos);
|
2012-03-27 15:07:26 +00:00
|
|
|
|
2010-03-23 16:54:31 +00:00
|
|
|
static struct term_state *term_states = NULL;
|
|
|
|
|
2009-12-23 23:37:11 +00:00
|
|
|
/* If the more pager is active. */
|
|
|
|
static int grub_more;
|
|
|
|
|
2010-08-28 13:39:34 +00:00
|
|
|
static void
|
2012-03-27 15:07:26 +00:00
|
|
|
putcode_real (grub_uint32_t code, struct grub_term_output *term, int fixed_tab);
|
2010-08-28 13:39:34 +00:00
|
|
|
|
2010-03-23 17:06:49 +00:00
|
|
|
void
|
|
|
|
grub_normal_reset_more (void)
|
|
|
|
{
|
|
|
|
static struct term_state *state;
|
|
|
|
for (state = term_states; state; state = state->next)
|
|
|
|
state->num_lines = 0;
|
|
|
|
}
|
|
|
|
|
2009-12-23 23:37:11 +00:00
|
|
|
static void
|
2010-03-23 16:54:31 +00:00
|
|
|
print_more (void)
|
2009-12-23 23:37:11 +00:00
|
|
|
{
|
2010-03-23 16:54:31 +00:00
|
|
|
char key;
|
|
|
|
grub_uint16_t *pos;
|
|
|
|
grub_term_output_t term;
|
|
|
|
grub_uint32_t *unicode_str, *unicode_last_position;
|
2009-12-24 14:34:33 +00:00
|
|
|
|
2010-03-23 16:54:31 +00:00
|
|
|
pos = grub_term_save_pos ();
|
|
|
|
|
2011-11-11 20:44:56 +00:00
|
|
|
/* TRANSLATORS: This has to fit on one line. It's ok to include few
|
|
|
|
words but don't write poems. */
|
|
|
|
grub_utf8_to_ucs4_alloc (_("--MORE--"), &unicode_str,
|
2010-03-23 16:54:31 +00:00
|
|
|
&unicode_last_position);
|
2009-12-24 14:34:33 +00:00
|
|
|
|
2010-03-23 16:54:31 +00:00
|
|
|
if (!unicode_str)
|
2009-12-23 23:37:11 +00:00
|
|
|
{
|
2010-03-23 16:54:31 +00:00
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
return;
|
|
|
|
}
|
2009-12-24 14:34:33 +00:00
|
|
|
|
2010-03-23 16:54:31 +00:00
|
|
|
grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT);
|
|
|
|
|
|
|
|
FOR_ACTIVE_TERM_OUTPUTS(term)
|
|
|
|
{
|
|
|
|
grub_print_ucs4 (unicode_str, unicode_last_position, 0, 0, term);
|
|
|
|
}
|
2010-08-29 23:11:12 +00:00
|
|
|
grub_setcolorstate (GRUB_TERM_COLOR_NORMAL);
|
2009-12-24 14:34:33 +00:00
|
|
|
|
2010-03-23 16:54:31 +00:00
|
|
|
grub_free (unicode_str);
|
|
|
|
|
|
|
|
key = grub_getkey ();
|
2009-12-24 14:34:33 +00:00
|
|
|
|
2010-03-23 16:54:31 +00:00
|
|
|
/* Remove the message. */
|
|
|
|
grub_term_restore_pos (pos);
|
|
|
|
FOR_ACTIVE_TERM_OUTPUTS(term)
|
|
|
|
grub_print_spaces (term, 8);
|
|
|
|
grub_term_restore_pos (pos);
|
2010-08-28 13:39:34 +00:00
|
|
|
grub_free (pos);
|
2009-12-24 14:34:33 +00:00
|
|
|
|
2010-12-18 17:37:48 +00:00
|
|
|
/* Scroll one line or an entire page, depending on the key. */
|
2009-12-24 14:34:33 +00:00
|
|
|
|
2010-03-23 17:06:49 +00:00
|
|
|
if (key == '\r' || key =='\n')
|
|
|
|
{
|
|
|
|
static struct term_state *state;
|
|
|
|
for (state = term_states; state; state = state->next)
|
2010-12-18 17:37:48 +00:00
|
|
|
state->num_lines--;
|
2010-03-23 17:06:49 +00:00
|
|
|
}
|
2010-12-18 17:37:48 +00:00
|
|
|
else
|
|
|
|
grub_normal_reset_more ();
|
2009-12-23 23:37:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
grub_set_more (int onoff)
|
|
|
|
{
|
|
|
|
if (onoff == 1)
|
|
|
|
grub_more++;
|
|
|
|
else
|
|
|
|
grub_more--;
|
2010-03-23 17:06:49 +00:00
|
|
|
grub_normal_reset_more ();
|
2010-03-01 19:58:45 +00:00
|
|
|
}
|
|
|
|
|
2010-05-09 11:37:32 +00:00
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2010-03-17 07:57:23 +00:00
|
|
|
static grub_uint32_t
|
|
|
|
map_code (grub_uint32_t in, struct grub_term_output *term)
|
|
|
|
{
|
|
|
|
if (in <= 0x7f)
|
|
|
|
return in;
|
|
|
|
|
|
|
|
switch (term->flags & GRUB_TERM_CODE_TYPE_MASK)
|
|
|
|
{
|
2010-05-09 11:26:52 +00:00
|
|
|
case GRUB_TERM_CODE_TYPE_CP437:
|
2010-03-17 07:57:23 +00:00
|
|
|
switch (in)
|
|
|
|
{
|
2010-05-09 10:56:32 +00:00
|
|
|
case GRUB_UNICODE_LEFTARROW:
|
2010-05-09 11:37:32 +00:00
|
|
|
return GRUB_CP437_LEFTARROW;
|
2010-05-09 10:56:32 +00:00
|
|
|
case GRUB_UNICODE_UPARROW:
|
2010-05-09 11:37:32 +00:00
|
|
|
return GRUB_CP437_UPARROW;
|
2010-05-09 10:56:32 +00:00
|
|
|
case GRUB_UNICODE_RIGHTARROW:
|
2010-05-09 11:37:32 +00:00
|
|
|
return GRUB_CP437_RIGHTARROW;
|
2010-05-09 10:56:32 +00:00
|
|
|
case GRUB_UNICODE_DOWNARROW:
|
2010-05-09 11:37:32 +00:00
|
|
|
return GRUB_CP437_DOWNARROW;
|
2010-05-09 10:56:32 +00:00
|
|
|
case GRUB_UNICODE_HLINE:
|
2010-05-09 11:37:32 +00:00
|
|
|
return GRUB_CP437_HLINE;
|
2010-05-09 10:56:32 +00:00
|
|
|
case GRUB_UNICODE_VLINE:
|
2010-05-09 11:37:32 +00:00
|
|
|
return GRUB_CP437_VLINE;
|
2010-05-09 10:56:32 +00:00
|
|
|
case GRUB_UNICODE_CORNER_UL:
|
2010-05-09 11:37:32 +00:00
|
|
|
return GRUB_CP437_CORNER_UL;
|
2010-05-09 10:56:32 +00:00
|
|
|
case GRUB_UNICODE_CORNER_UR:
|
2010-05-09 11:37:32 +00:00
|
|
|
return GRUB_CP437_CORNER_UR;
|
2010-05-09 10:56:32 +00:00
|
|
|
case GRUB_UNICODE_CORNER_LL:
|
2010-05-09 11:37:32 +00:00
|
|
|
return GRUB_CP437_CORNER_LL;
|
2010-05-09 10:56:32 +00:00
|
|
|
case GRUB_UNICODE_CORNER_LR:
|
2010-05-09 11:37:32 +00:00
|
|
|
return GRUB_CP437_CORNER_LR;
|
2010-03-17 07:57:23 +00:00
|
|
|
}
|
|
|
|
return '?';
|
|
|
|
case GRUB_TERM_CODE_TYPE_ASCII:
|
|
|
|
/* Better than nothing. */
|
|
|
|
switch (in)
|
|
|
|
{
|
2010-05-09 10:56:32 +00:00
|
|
|
case GRUB_UNICODE_LEFTARROW:
|
2010-03-17 07:57:23 +00:00
|
|
|
return '<';
|
|
|
|
|
2010-05-09 10:56:32 +00:00
|
|
|
case GRUB_UNICODE_UPARROW:
|
2010-03-17 07:57:23 +00:00
|
|
|
return '^';
|
|
|
|
|
2010-05-09 10:56:32 +00:00
|
|
|
case GRUB_UNICODE_RIGHTARROW:
|
2010-03-17 07:57:23 +00:00
|
|
|
return '>';
|
|
|
|
|
2010-05-09 10:56:32 +00:00
|
|
|
case GRUB_UNICODE_DOWNARROW:
|
2010-03-17 07:57:23 +00:00
|
|
|
return 'v';
|
|
|
|
|
2010-05-09 10:56:32 +00:00
|
|
|
case GRUB_UNICODE_HLINE:
|
2010-03-17 07:57:23 +00:00
|
|
|
return '-';
|
|
|
|
|
2010-05-09 10:56:32 +00:00
|
|
|
case GRUB_UNICODE_VLINE:
|
2010-03-17 07:57:23 +00:00
|
|
|
return '|';
|
|
|
|
|
2010-05-09 10:56:32 +00:00
|
|
|
case GRUB_UNICODE_CORNER_UL:
|
|
|
|
case GRUB_UNICODE_CORNER_UR:
|
|
|
|
case GRUB_UNICODE_CORNER_LL:
|
|
|
|
case GRUB_UNICODE_CORNER_LR:
|
2010-03-17 07:57:23 +00:00
|
|
|
return '+';
|
|
|
|
|
|
|
|
}
|
|
|
|
return '?';
|
|
|
|
}
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
2009-12-23 23:37:11 +00:00
|
|
|
void
|
|
|
|
grub_puts_terminal (const char *str, struct grub_term_output *term)
|
|
|
|
{
|
2010-03-23 15:28:35 +00:00
|
|
|
grub_uint32_t *unicode_str, *unicode_last_position;
|
2010-08-29 19:57:37 +00:00
|
|
|
grub_error_push ();
|
2010-03-23 15:28:35 +00:00
|
|
|
grub_utf8_to_ucs4_alloc (str, &unicode_str,
|
|
|
|
&unicode_last_position);
|
2010-08-29 19:57:37 +00:00
|
|
|
grub_error_pop ();
|
2010-08-28 13:39:34 +00:00
|
|
|
if (!unicode_str)
|
|
|
|
{
|
2010-08-29 19:57:37 +00:00
|
|
|
for (; *str; str++)
|
2010-08-28 13:39:34 +00:00
|
|
|
{
|
2010-08-29 19:57:37 +00:00
|
|
|
struct grub_unicode_glyph c =
|
|
|
|
{
|
|
|
|
.variant = 0,
|
|
|
|
.attributes = 0,
|
|
|
|
.ncomb = 0,
|
|
|
|
.estimated_width = 1,
|
|
|
|
.base = *str
|
|
|
|
};
|
2010-08-28 13:39:34 +00:00
|
|
|
|
2010-08-29 19:57:37 +00:00
|
|
|
FOR_ACTIVE_TERM_OUTPUTS(term)
|
|
|
|
{
|
|
|
|
(term->putchar) (term, &c);
|
|
|
|
}
|
|
|
|
if (*str == '\n')
|
|
|
|
{
|
|
|
|
c.base = '\r';
|
|
|
|
FOR_ACTIVE_TERM_OUTPUTS(term)
|
|
|
|
{
|
|
|
|
(term->putchar) (term, &c);
|
|
|
|
}
|
|
|
|
}
|
2010-08-28 13:39:34 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2009-12-23 23:37:11 +00:00
|
|
|
|
2013-01-16 12:41:16 +00:00
|
|
|
print_ucs4_real (unicode_str, unicode_last_position, 0, 0, term,
|
|
|
|
0, 0, 0, 0, -1, 0, 0);
|
2010-03-23 15:28:35 +00:00
|
|
|
grub_free (unicode_str);
|
2009-12-23 23:37:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
grub_uint16_t *
|
|
|
|
grub_term_save_pos (void)
|
|
|
|
{
|
|
|
|
struct grub_term_output *cur;
|
|
|
|
unsigned cnt = 0;
|
|
|
|
grub_uint16_t *ret, *ptr;
|
|
|
|
|
2009-12-24 16:51:43 +00:00
|
|
|
FOR_ACTIVE_TERM_OUTPUTS(cur)
|
|
|
|
cnt++;
|
2009-12-23 23:37:11 +00:00
|
|
|
|
|
|
|
ret = grub_malloc (cnt * sizeof (ret[0]));
|
|
|
|
if (!ret)
|
|
|
|
return NULL;
|
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
ptr = ret;
|
2009-12-24 16:51:43 +00:00
|
|
|
FOR_ACTIVE_TERM_OUTPUTS(cur)
|
|
|
|
*ptr++ = grub_term_getxy (cur);
|
2009-12-23 23:37:11 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
grub_term_restore_pos (grub_uint16_t *pos)
|
|
|
|
{
|
|
|
|
struct grub_term_output *cur;
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_uint16_t *ptr = pos;
|
2009-12-23 23:37:11 +00:00
|
|
|
|
|
|
|
if (!pos)
|
|
|
|
return;
|
|
|
|
|
2009-12-24 16:51:43 +00:00
|
|
|
FOR_ACTIVE_TERM_OUTPUTS(cur)
|
|
|
|
{
|
|
|
|
grub_term_gotoxy (cur, (*ptr & 0xff00) >> 8, *ptr & 0xff);
|
|
|
|
ptr++;
|
|
|
|
}
|
2009-12-23 23:37:11 +00:00
|
|
|
}
|
2009-12-25 02:37:20 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
grub_terminal_autoload_free (void)
|
|
|
|
{
|
|
|
|
struct grub_term_autoload *cur, *next;
|
|
|
|
unsigned i;
|
|
|
|
for (i = 0; i < 2; i++)
|
|
|
|
for (cur = i ? grub_term_input_autoload : grub_term_output_autoload;
|
|
|
|
cur; cur = next)
|
|
|
|
{
|
|
|
|
next = cur->next;
|
|
|
|
grub_free (cur->name);
|
|
|
|
grub_free (cur->modname);
|
|
|
|
grub_free (cur);
|
|
|
|
}
|
|
|
|
grub_term_input_autoload = NULL;
|
|
|
|
grub_term_output_autoload = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the file terminal.lst for auto-loading. */
|
|
|
|
void
|
2010-04-09 19:07:24 +00:00
|
|
|
read_terminal_list (const char *prefix)
|
2009-12-25 02:37:20 +00:00
|
|
|
{
|
|
|
|
char *filename;
|
|
|
|
grub_file_t file;
|
|
|
|
char *buf = NULL;
|
|
|
|
|
|
|
|
if (!prefix)
|
|
|
|
{
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-04 20:47:29 +00:00
|
|
|
filename = grub_xasprintf ("%s/" GRUB_TARGET_CPU "-" GRUB_PLATFORM
|
|
|
|
"/terminal.lst", prefix);
|
2009-12-25 02:37:20 +00:00
|
|
|
if (!filename)
|
|
|
|
{
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
file = grub_file_open (filename);
|
2010-02-24 14:24:21 +00:00
|
|
|
grub_free (filename);
|
2009-12-25 02:37:20 +00:00
|
|
|
if (!file)
|
|
|
|
{
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Override previous terminal.lst. */
|
|
|
|
grub_terminal_autoload_free ();
|
|
|
|
|
|
|
|
for (;; grub_free (buf))
|
|
|
|
{
|
|
|
|
char *p, *name;
|
|
|
|
struct grub_term_autoload *cur;
|
|
|
|
struct grub_term_autoload **target = NULL;
|
|
|
|
|
|
|
|
buf = grub_file_getline (file);
|
|
|
|
|
|
|
|
if (! buf)
|
|
|
|
break;
|
|
|
|
|
2012-03-11 13:43:18 +00:00
|
|
|
p = buf;
|
|
|
|
while (grub_isspace (p[0]))
|
|
|
|
p++;
|
|
|
|
|
|
|
|
switch (p[0])
|
2009-12-25 02:37:20 +00:00
|
|
|
{
|
|
|
|
case 'i':
|
|
|
|
target = &grub_term_input_autoload;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'o':
|
|
|
|
target = &grub_term_output_autoload;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!target)
|
|
|
|
continue;
|
|
|
|
|
2012-03-11 13:43:18 +00:00
|
|
|
name = p + 1;
|
2009-12-25 02:37:20 +00:00
|
|
|
|
|
|
|
p = grub_strchr (name, ':');
|
|
|
|
if (! p)
|
|
|
|
continue;
|
2012-05-23 07:09:36 +00:00
|
|
|
*p = 0;
|
2012-03-11 13:43:18 +00:00
|
|
|
|
|
|
|
p++;
|
|
|
|
while (*p == ' ' || *p == '\t')
|
|
|
|
p++;
|
2009-12-25 02:37:20 +00:00
|
|
|
|
|
|
|
cur = grub_malloc (sizeof (*cur));
|
|
|
|
if (!cur)
|
|
|
|
{
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
cur->name = grub_strdup (name);
|
2013-03-07 07:41:27 +00:00
|
|
|
if (! cur->name)
|
2009-12-25 02:37:20 +00:00
|
|
|
{
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
grub_free (cur);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
cur->modname = grub_strdup (p);
|
|
|
|
if (! cur->modname)
|
|
|
|
{
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
grub_free (cur->name);
|
2010-09-30 19:04:09 +00:00
|
|
|
grub_free (cur);
|
2009-12-25 02:37:20 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
cur->next = *target;
|
|
|
|
*target = cur;
|
|
|
|
}
|
|
|
|
|
|
|
|
grub_file_close (file);
|
|
|
|
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
}
|
2010-03-17 07:57:23 +00:00
|
|
|
|
|
|
|
static void
|
2012-03-27 15:07:26 +00:00
|
|
|
putglyph (const struct grub_unicode_glyph *c, struct grub_term_output *term,
|
|
|
|
int fixed_tab)
|
2010-03-17 07:57:23 +00:00
|
|
|
{
|
|
|
|
struct grub_unicode_glyph c2 =
|
|
|
|
{
|
|
|
|
.variant = 0,
|
|
|
|
.attributes = 0,
|
|
|
|
.ncomb = 0,
|
|
|
|
.estimated_width = 1
|
|
|
|
};
|
|
|
|
|
2012-03-27 15:07:26 +00:00
|
|
|
if (c->base == '\t' && fixed_tab)
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
|
|
|
|
n = GRUB_TERM_TAB_WIDTH;
|
|
|
|
c2.base = ' ';
|
|
|
|
while (n--)
|
|
|
|
(term->putchar) (term, &c2);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-03-17 07:57:23 +00:00
|
|
|
if (c->base == '\t' && term->getxy)
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
|
2012-03-27 15:07:26 +00:00
|
|
|
n = GRUB_TERM_TAB_WIDTH - ((term->getxy (term) >> 8)
|
|
|
|
% GRUB_TERM_TAB_WIDTH);
|
2010-03-17 07:57:23 +00:00
|
|
|
c2.base = ' ';
|
|
|
|
while (n--)
|
2010-05-07 00:30:44 +00:00
|
|
|
(term->putchar) (term, &c2);
|
2010-03-17 07:57:23 +00:00
|
|
|
|
|
|
|
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)
|
2010-03-29 01:37:24 +00:00
|
|
|
== 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);
|
|
|
|
}
|
2010-03-17 07:57:23 +00:00
|
|
|
}
|
|
|
|
else
|
2013-05-04 20:23:23 +00:00
|
|
|
code = grub_unicode_get_comb (c) [i].code;
|
2010-03-17 07:57:23 +00:00
|
|
|
|
|
|
|
grub_ucs4_to_utf8 (&code, 1, u8, sizeof (u8));
|
|
|
|
|
|
|
|
for (ptr = u8; *ptr; ptr++)
|
|
|
|
{
|
|
|
|
c2.base = *ptr;
|
2010-05-07 00:30:44 +00:00
|
|
|
(term->putchar) (term, &c2);
|
2010-03-17 07:57:23 +00:00
|
|
|
c2.estimated_width = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c2.estimated_width = 1;
|
|
|
|
}
|
|
|
|
else
|
2010-05-07 00:30:44 +00:00
|
|
|
(term->putchar) (term, c);
|
2010-03-17 07:57:23 +00:00
|
|
|
|
|
|
|
if (c->base == '\n')
|
|
|
|
{
|
|
|
|
c2.base = '\r';
|
2010-05-07 00:30:44 +00:00
|
|
|
(term->putchar) (term, &c2);
|
2010-03-17 07:57:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-03-27 15:07:26 +00:00
|
|
|
putcode_real (grub_uint32_t code, struct grub_term_output *term, int fixed_tab)
|
2010-03-17 07:57:23 +00:00
|
|
|
{
|
|
|
|
struct grub_unicode_glyph c =
|
|
|
|
{
|
|
|
|
.variant = 0,
|
|
|
|
.attributes = 0,
|
|
|
|
.ncomb = 0,
|
|
|
|
.estimated_width = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
c.base = map_code (code, term);
|
2012-03-27 15:07:26 +00:00
|
|
|
putglyph (&c, term, fixed_tab);
|
2010-03-17 07:57:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
2012-03-27 15:07:26 +00:00
|
|
|
putcode_real (code, term, 0);
|
2010-03-17 07:57:23 +00:00
|
|
|
}
|
|
|
|
|
2010-03-23 16:54:31 +00:00
|
|
|
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,
|
|
|
|
};
|
|
|
|
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)
|
2010-03-17 07:57:23 +00:00
|
|
|
{
|
2010-05-07 00:30:44 +00:00
|
|
|
return ((term->getxy (term) >> 8) & 0xff) - margin_left;
|
2010-03-23 16:54:31 +00:00
|
|
|
}
|
|
|
|
|
2013-01-16 12:41:16 +00:00
|
|
|
static void
|
|
|
|
fill_margin (struct grub_term_output *term, int r)
|
|
|
|
{
|
|
|
|
int sp = (term->getwh (term) >> 8)
|
|
|
|
- (term->getxy (term) >> 8) - r;
|
|
|
|
if (sp > 0)
|
|
|
|
grub_print_spaces (term, sp);
|
|
|
|
}
|
|
|
|
|
2010-03-23 16:54:31 +00:00
|
|
|
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,
|
2011-04-10 11:56:23 +00:00
|
|
|
struct term_state *state,
|
2013-01-16 12:41:16 +00:00
|
|
|
int dry_run, int fixed_tab, unsigned skip_lines,
|
|
|
|
unsigned max_lines,
|
|
|
|
grub_uint32_t contchar,
|
|
|
|
int primitive_wrap, struct grub_term_pos *pos)
|
2010-03-23 16:54:31 +00:00
|
|
|
{
|
|
|
|
const grub_uint32_t *ptr;
|
2011-04-10 11:56:23 +00:00
|
|
|
grub_ssize_t startwidth = dry_run ? 0 : get_startwidth (term, margin_left);
|
2010-03-23 16:54:31 +00:00
|
|
|
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;
|
2011-04-10 11:56:23 +00:00
|
|
|
int lines = 0;
|
2013-01-16 12:41:16 +00:00
|
|
|
int i;
|
|
|
|
struct term_state local_state;
|
|
|
|
|
|
|
|
if (!state)
|
|
|
|
{
|
|
|
|
grub_memset (&local_state, 0, sizeof (local_state));
|
|
|
|
state = &local_state;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < state->bidi_stack_depth; i++)
|
|
|
|
putcode_real (state->bidi_stack[i] | (GRUB_UNICODE_LRE & ~0xff),
|
|
|
|
term, fixed_tab);
|
2010-03-23 16:54:31 +00:00
|
|
|
|
|
|
|
for (ptr = str; ptr < last_position; ptr++)
|
|
|
|
{
|
|
|
|
grub_ssize_t last_width = 0;
|
2013-01-16 12:41:16 +00:00
|
|
|
switch (*ptr)
|
|
|
|
{
|
|
|
|
case GRUB_UNICODE_LRE:
|
|
|
|
case GRUB_UNICODE_RLE:
|
|
|
|
case GRUB_UNICODE_LRO:
|
|
|
|
case GRUB_UNICODE_RLO:
|
|
|
|
if (state->bidi_stack_depth >= (int) ARRAY_SIZE (state->bidi_stack))
|
|
|
|
state->invalid_pushes++;
|
|
|
|
else
|
|
|
|
state->bidi_stack[state->bidi_stack_depth++] = *ptr;
|
|
|
|
break;
|
|
|
|
case GRUB_UNICODE_PDF:
|
|
|
|
if (state->invalid_pushes)
|
|
|
|
state->invalid_pushes--;
|
|
|
|
else if (state->bidi_stack_depth)
|
|
|
|
state->bidi_stack_depth--;
|
|
|
|
break;
|
|
|
|
}
|
2010-03-23 16:54:31 +00:00
|
|
|
if (grub_unicode_get_comb_type (*ptr) == GRUB_UNICODE_COMB_NONE)
|
|
|
|
{
|
|
|
|
struct grub_unicode_glyph c = {
|
|
|
|
.variant = 0,
|
|
|
|
.attributes = 0,
|
|
|
|
.ncomb = 0,
|
|
|
|
};
|
|
|
|
c.base = *ptr;
|
2013-01-16 12:41:16 +00:00
|
|
|
if (pos)
|
|
|
|
{
|
|
|
|
pos[ptr - str].x = line_width;
|
|
|
|
pos[ptr - str].y = lines;
|
|
|
|
pos[ptr - str].valid = 1;
|
|
|
|
}
|
2010-03-23 16:54:31 +00:00
|
|
|
line_width += last_width = grub_term_getcharwidth (term, &c);
|
|
|
|
}
|
|
|
|
|
2013-01-16 12:41:16 +00:00
|
|
|
if (*ptr == ' ' && !primitive_wrap)
|
2010-03-23 16:54:31 +00:00
|
|
|
{
|
|
|
|
lastspacewidth = line_width;
|
|
|
|
last_space = ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (line_width > max_width || *ptr == '\n')
|
|
|
|
{
|
|
|
|
const grub_uint32_t *ptr2;
|
2013-01-16 12:41:16 +00:00
|
|
|
int wasn = (*ptr == '\n');
|
|
|
|
|
|
|
|
if (wasn)
|
|
|
|
{
|
|
|
|
state->bidi_stack_depth = 0;
|
|
|
|
state->invalid_pushes = 0;
|
|
|
|
}
|
2010-03-23 16:54:31 +00:00
|
|
|
|
|
|
|
if (line_width > max_width && last_space > line_start)
|
|
|
|
ptr = last_space;
|
|
|
|
else if (line_width > max_width
|
2011-04-08 12:25:44 +00:00
|
|
|
&& line_start == str && line_width - lastspacewidth < max_width - 5)
|
2010-03-23 16:54:31 +00:00
|
|
|
{
|
|
|
|
ptr = str;
|
|
|
|
lastspacewidth = startwidth;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
lastspacewidth = line_width - last_width;
|
|
|
|
|
2011-04-10 11:56:23 +00:00
|
|
|
lines++;
|
2010-03-23 16:54:31 +00:00
|
|
|
|
2013-01-16 12:41:16 +00:00
|
|
|
if (!skip_lines && !dry_run)
|
2010-03-23 16:54:31 +00:00
|
|
|
{
|
2011-04-10 11:56:23 +00:00
|
|
|
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;
|
2012-03-27 15:07:26 +00:00
|
|
|
putcode_real (*ptr2, term, fixed_tab);
|
2011-04-10 11:56:23 +00:00
|
|
|
}
|
|
|
|
|
2013-01-16 12:41:16 +00:00
|
|
|
if (!wasn && contchar)
|
|
|
|
putcode_real (contchar, term, fixed_tab);
|
2013-01-21 19:03:15 +00:00
|
|
|
if (contchar)
|
|
|
|
fill_margin (term, margin_right);
|
2013-01-16 12:41:16 +00:00
|
|
|
|
2011-04-10 11:56:23 +00:00
|
|
|
grub_putcode ('\n', term);
|
2013-01-16 12:41:16 +00:00
|
|
|
if (state != &local_state && ++state->num_lines
|
2011-04-10 11:56:23 +00:00
|
|
|
>= (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;
|
2012-03-27 15:07:26 +00:00
|
|
|
state->backlog_fixed_tab = fixed_tab;
|
2011-04-10 11:56:23 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2010-03-23 16:54:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
line_width -= lastspacewidth;
|
|
|
|
if (ptr == last_space || *ptr == '\n')
|
|
|
|
ptr++;
|
2013-04-03 13:19:34 +00:00
|
|
|
else if (pos)
|
|
|
|
{
|
|
|
|
pos[ptr - str].x = line_width - last_width;
|
|
|
|
pos[ptr - str].y = lines;
|
|
|
|
pos[ptr - str].valid = 1;
|
|
|
|
}
|
|
|
|
|
2010-03-23 16:54:31 +00:00
|
|
|
line_start = ptr;
|
2013-01-16 12:41:16 +00:00
|
|
|
|
|
|
|
if (skip_lines)
|
|
|
|
skip_lines--;
|
|
|
|
else if (max_lines != (unsigned) -1)
|
|
|
|
{
|
|
|
|
max_lines--;
|
|
|
|
if (!max_lines)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!skip_lines && !dry_run)
|
|
|
|
{
|
|
|
|
if (!contchar)
|
|
|
|
grub_print_spaces (term, margin_left);
|
|
|
|
else
|
|
|
|
grub_term_gotoxy (term, margin_left,
|
|
|
|
grub_term_getxy (term) & 0xff);
|
|
|
|
for (i = 0; i < state->bidi_stack_depth; i++)
|
|
|
|
putcode_real (state->bidi_stack[i] | (GRUB_UNICODE_LRE & ~0xff),
|
|
|
|
term, fixed_tab);
|
|
|
|
}
|
2010-03-23 16:54:31 +00:00
|
|
|
}
|
|
|
|
}
|
2010-03-17 07:57:23 +00:00
|
|
|
|
2013-01-16 12:41:16 +00:00
|
|
|
if (pos)
|
|
|
|
{
|
|
|
|
pos[ptr - str].x = line_width;
|
|
|
|
pos[ptr - str].y = lines;
|
|
|
|
pos[ptr - str].valid = 1;
|
|
|
|
}
|
|
|
|
|
2011-04-10 11:56:23 +00:00
|
|
|
if (line_start < last_position)
|
|
|
|
lines++;
|
2013-01-16 12:41:16 +00:00
|
|
|
if (!dry_run && !skip_lines && max_lines)
|
2011-04-10 11:56:23 +00:00
|
|
|
{
|
|
|
|
const grub_uint32_t *ptr2;
|
2013-04-03 13:19:34 +00:00
|
|
|
int sp;
|
|
|
|
|
2011-04-10 11:56:23 +00:00
|
|
|
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;
|
2012-03-27 15:07:26 +00:00
|
|
|
putcode_real (*ptr2, term, fixed_tab);
|
2011-04-10 11:56:23 +00:00
|
|
|
}
|
2013-04-03 13:19:34 +00:00
|
|
|
|
2013-04-07 15:48:22 +00:00
|
|
|
if (contchar)
|
|
|
|
{
|
|
|
|
sp = max_width - pos[last_position - str].x + 1;
|
|
|
|
if (sp > 0)
|
|
|
|
grub_print_spaces (term, sp);
|
|
|
|
}
|
2011-04-10 11:56:23 +00:00
|
|
|
}
|
|
|
|
return dry_run ? lines : 0;
|
2010-03-23 16:54:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2013-05-04 20:23:23 +00:00
|
|
|
put_glyphs_terminal (struct grub_unicode_glyph *visual,
|
2010-03-23 16:54:31 +00:00
|
|
|
grub_ssize_t visual_len,
|
|
|
|
int margin_left, int margin_right,
|
|
|
|
struct grub_term_output *term,
|
2013-04-07 15:48:22 +00:00
|
|
|
struct term_state *state, int fixed_tab,
|
|
|
|
grub_uint32_t contchar)
|
2010-03-23 16:54:31 +00:00
|
|
|
{
|
2013-05-04 20:23:23 +00:00
|
|
|
struct grub_unicode_glyph *visual_ptr;
|
2013-04-08 12:35:26 +00:00
|
|
|
int since_last_nl = 1;
|
2010-03-23 16:54:31 +00:00
|
|
|
for (visual_ptr = visual; visual_ptr < visual + visual_len; visual_ptr++)
|
|
|
|
{
|
2013-04-08 12:35:26 +00:00
|
|
|
if (visual_ptr->base == '\n' && contchar)
|
|
|
|
fill_margin (term, margin_right);
|
|
|
|
|
2012-03-27 15:07:26 +00:00
|
|
|
putglyph (visual_ptr, term, fixed_tab);
|
2013-04-08 12:35:26 +00:00
|
|
|
since_last_nl++;
|
2010-03-23 16:54:31 +00:00
|
|
|
if (visual_ptr->base == '\n')
|
2010-07-10 00:23:48 +00:00
|
|
|
{
|
2013-04-08 12:35:26 +00:00
|
|
|
since_last_nl = 0;
|
2010-07-10 00:23:48 +00:00
|
|
|
if (state && ++state->num_lines
|
|
|
|
>= (grub_ssize_t) grub_term_height (term) - 2)
|
|
|
|
{
|
|
|
|
state->backlog_glyphs = visual_ptr + 1;
|
2010-09-12 20:05:27 +00:00
|
|
|
state->backlog_len = visual_len - (visual_ptr - visual) - 1;
|
2012-03-27 15:07:26 +00:00
|
|
|
state->backlog_fixed_tab = fixed_tab;
|
2010-07-10 00:23:48 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-04-07 15:48:22 +00:00
|
|
|
if (!contchar)
|
|
|
|
grub_print_spaces (term, margin_left);
|
|
|
|
else
|
|
|
|
grub_term_gotoxy (term, margin_left,
|
|
|
|
grub_term_getxy (term) & 0xff);
|
2010-07-10 00:23:48 +00:00
|
|
|
}
|
2013-05-04 20:23:23 +00:00
|
|
|
grub_unicode_destroy_glyph (visual_ptr);
|
2010-03-23 16:54:31 +00:00
|
|
|
}
|
2013-04-08 12:35:26 +00:00
|
|
|
if (contchar && since_last_nl)
|
|
|
|
fill_margin (term, margin_right);
|
|
|
|
|
2010-03-23 16:54:31 +00:00
|
|
|
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,
|
2012-03-27 15:07:26 +00:00
|
|
|
margin_left, margin_right, term, state, 0,
|
2013-01-16 12:41:16 +00:00
|
|
|
state->backlog_fixed_tab, 0, -1, 0, 0,
|
|
|
|
0);
|
2010-03-23 16:54:31 +00:00
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
grub_free (state->free);
|
|
|
|
state->free = NULL;
|
|
|
|
state->backlog_len = 0;
|
2010-09-12 20:05:27 +00:00
|
|
|
state->backlog_ucs4 = 0;
|
2010-03-23 16:54:31 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state->backlog_glyphs)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
ret = put_glyphs_terminal (state->backlog_glyphs,
|
|
|
|
state->backlog_len,
|
2012-03-27 15:07:26 +00:00
|
|
|
margin_left, margin_right, term, state,
|
2013-04-07 15:48:22 +00:00
|
|
|
state->backlog_fixed_tab, 0);
|
2010-03-23 16:54:31 +00:00
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
grub_free (state->free);
|
|
|
|
state->free = NULL;
|
|
|
|
state->backlog_len = 0;
|
2010-09-12 20:05:27 +00:00
|
|
|
state->backlog_glyphs = 0;
|
2010-03-23 16:54:31 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-02 10:47:59 +00:00
|
|
|
static grub_ssize_t
|
|
|
|
getcharwidth (const struct grub_unicode_glyph *c, void *term)
|
|
|
|
{
|
|
|
|
return grub_term_getcharwidth (term, c);
|
|
|
|
}
|
|
|
|
|
2010-03-23 16:54:31 +00:00
|
|
|
static int
|
|
|
|
print_ucs4_real (const grub_uint32_t * str,
|
|
|
|
const grub_uint32_t * last_position,
|
|
|
|
int margin_left, int margin_right,
|
2011-04-10 11:56:23 +00:00
|
|
|
struct grub_term_output *term, int backlog,
|
2013-01-16 12:41:16 +00:00
|
|
|
int dry_run, int fixed_tab, unsigned skip_lines,
|
|
|
|
unsigned max_lines,
|
|
|
|
grub_uint32_t contchar, struct grub_term_pos *pos)
|
2010-03-23 16:54:31 +00:00
|
|
|
{
|
|
|
|
struct term_state *state = NULL;
|
|
|
|
|
2011-04-10 11:56:23 +00:00
|
|
|
if (!dry_run)
|
|
|
|
{
|
2013-01-16 12:41:16 +00:00
|
|
|
int xy;
|
2011-04-10 11:56:23 +00:00
|
|
|
if (backlog)
|
|
|
|
state = find_term_state (term);
|
2010-03-17 07:57:23 +00:00
|
|
|
|
2013-01-16 12:41:16 +00:00
|
|
|
xy = term->getxy (term);
|
|
|
|
|
|
|
|
if (((xy >> 8) & 0xff) < margin_left)
|
|
|
|
{
|
|
|
|
if (!contchar)
|
|
|
|
grub_print_spaces (term, margin_left - ((xy >> 8) & 0xff));
|
|
|
|
else
|
|
|
|
grub_term_gotoxy (term, margin_left,
|
|
|
|
xy & 0xff);
|
|
|
|
}
|
2011-04-10 11:56:23 +00:00
|
|
|
}
|
2010-03-17 07:57:23 +00:00
|
|
|
|
|
|
|
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;
|
2013-01-16 12:41:16 +00:00
|
|
|
grub_ssize_t visual_len_show;
|
|
|
|
struct grub_unicode_glyph *visual_show;
|
2010-03-23 16:54:31 +00:00
|
|
|
int ret;
|
2013-01-16 12:41:16 +00:00
|
|
|
struct grub_unicode_glyph *vptr;
|
2010-03-17 07:57:23 +00:00
|
|
|
|
|
|
|
visual_len = grub_bidi_logical_to_visual (str, last_position - str,
|
2013-03-02 10:47:59 +00:00
|
|
|
&visual, getcharwidth, term,
|
2010-03-23 16:54:31 +00:00
|
|
|
get_maxwidth (term,
|
|
|
|
margin_left,
|
|
|
|
margin_right),
|
2013-05-03 11:56:45 +00:00
|
|
|
dry_run ? 0 : get_startwidth (term,
|
|
|
|
margin_left),
|
2013-01-16 12:41:16 +00:00
|
|
|
contchar, pos, !!contchar);
|
2010-03-17 07:57:23 +00:00
|
|
|
if (visual_len < 0)
|
|
|
|
{
|
|
|
|
grub_print_error ();
|
2010-03-23 16:54:31 +00:00
|
|
|
return 0;
|
2010-03-17 07:57:23 +00:00
|
|
|
}
|
2013-01-16 12:41:16 +00:00
|
|
|
visual_show = visual;
|
|
|
|
for (; skip_lines && visual_show < visual + visual_len; visual_show++)
|
|
|
|
if (visual_show->base == '\n')
|
|
|
|
skip_lines--;
|
|
|
|
if (max_lines != (unsigned) -1)
|
|
|
|
{
|
|
|
|
for (vptr = visual_show;
|
|
|
|
max_lines && vptr < visual + visual_len; vptr++)
|
2013-04-03 13:19:34 +00:00
|
|
|
if (vptr->base == '\n')
|
2013-01-16 12:41:16 +00:00
|
|
|
max_lines--;
|
|
|
|
|
|
|
|
visual_len_show = vptr - visual_show;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
visual_len_show = visual + visual_len - visual_show;
|
|
|
|
|
2011-04-10 11:56:23 +00:00
|
|
|
if (dry_run)
|
|
|
|
{
|
|
|
|
ret = 0;
|
2013-01-16 12:41:16 +00:00
|
|
|
for (vptr = visual_show; vptr < visual_show + visual_len_show; vptr++)
|
2011-04-10 11:56:23 +00:00
|
|
|
if (vptr->base == '\n')
|
|
|
|
ret++;
|
2013-01-16 12:41:16 +00:00
|
|
|
if (visual_len_show && visual[visual_len_show - 1].base != '\n')
|
2011-04-10 11:56:23 +00:00
|
|
|
ret++;
|
2013-05-04 11:47:10 +00:00
|
|
|
for (vptr = visual; vptr < visual + visual_len; vptr++)
|
2013-05-04 20:23:23 +00:00
|
|
|
grub_unicode_destroy_glyph (vptr);
|
2011-04-10 11:56:23 +00:00
|
|
|
grub_free (visual);
|
|
|
|
}
|
2010-03-23 16:54:31 +00:00
|
|
|
else
|
2011-04-10 11:56:23 +00:00
|
|
|
{
|
2013-01-16 12:41:16 +00:00
|
|
|
ret = put_glyphs_terminal (visual_show, visual_len_show, margin_left,
|
2013-04-08 12:35:26 +00:00
|
|
|
margin_right,
|
2013-04-07 15:48:22 +00:00
|
|
|
term, state, fixed_tab, contchar);
|
2013-01-16 12:41:16 +00:00
|
|
|
|
2011-04-10 11:56:23 +00:00
|
|
|
if (!ret)
|
|
|
|
grub_free (visual);
|
|
|
|
else
|
|
|
|
state->free = visual;
|
|
|
|
}
|
2010-03-23 16:54:31 +00:00
|
|
|
return ret;
|
2010-03-17 07:57:23 +00:00
|
|
|
}
|
2010-03-23 16:54:31 +00:00
|
|
|
return print_ucs4_terminal (str, last_position, margin_left, margin_right,
|
2013-01-16 12:41:16 +00:00
|
|
|
term, state, dry_run, fixed_tab, skip_lines,
|
|
|
|
max_lines, contchar, !!contchar, pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
grub_print_ucs4_menu (const grub_uint32_t * str,
|
|
|
|
const grub_uint32_t * last_position,
|
|
|
|
int margin_left, int margin_right,
|
|
|
|
struct grub_term_output *term,
|
|
|
|
int skip_lines, int max_lines,
|
|
|
|
grub_uint32_t contchar,
|
|
|
|
struct grub_term_pos *pos)
|
|
|
|
{
|
|
|
|
print_ucs4_real (str, last_position, margin_left, margin_right,
|
|
|
|
term, 0, 0, 1, skip_lines, max_lines,
|
|
|
|
contchar, pos);
|
2010-03-23 16:54:31 +00:00
|
|
|
}
|
2010-03-17 07:57:23 +00:00
|
|
|
|
2010-03-23 16:54:31 +00:00
|
|
|
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,
|
2013-01-16 12:41:16 +00:00
|
|
|
term, 0, 0, 1, 0, -1, 0, 0);
|
2010-03-17 07:57:23 +00:00
|
|
|
}
|
|
|
|
|
2011-04-10 11:56:23 +00:00
|
|
|
int
|
|
|
|
grub_ucs4_count_lines (const grub_uint32_t * str,
|
|
|
|
const grub_uint32_t * last_position,
|
|
|
|
int margin_left, int margin_right,
|
|
|
|
struct grub_term_output *term)
|
|
|
|
{
|
|
|
|
return print_ucs4_real (str, last_position, margin_left, margin_right,
|
2013-01-16 12:41:16 +00:00
|
|
|
term, 0, 1, 1, 0, -1, 0, 0);
|
2011-04-10 11:56:23 +00:00
|
|
|
}
|
2010-03-23 16:54:31 +00:00
|
|
|
|
2010-03-17 07:57:23 +00:00
|
|
|
void
|
2013-03-20 16:13:31 +00:00
|
|
|
grub_xnputs (const char *str, grub_size_t msg_len)
|
2010-03-17 07:57:23 +00:00
|
|
|
{
|
2010-08-29 19:57:37 +00:00
|
|
|
grub_uint32_t *unicode_str = NULL, *unicode_last_position;
|
2010-03-23 16:54:31 +00:00
|
|
|
int backlog = 0;
|
2010-08-29 19:57:37 +00:00
|
|
|
grub_term_output_t term;
|
|
|
|
|
|
|
|
grub_error_push ();
|
2013-03-20 16:13:31 +00:00
|
|
|
|
|
|
|
unicode_str = grub_malloc (msg_len * sizeof (grub_uint32_t));
|
|
|
|
|
2010-08-29 19:57:37 +00:00
|
|
|
grub_error_pop ();
|
2010-03-17 07:57:23 +00:00
|
|
|
|
2010-03-23 16:54:31 +00:00
|
|
|
if (!unicode_str)
|
|
|
|
{
|
2013-03-20 16:13:31 +00:00
|
|
|
for (; msg_len--; str++, msg_len++)
|
2010-08-28 13:39:34 +00:00
|
|
|
{
|
2010-08-29 19:57:37 +00:00
|
|
|
struct grub_unicode_glyph c =
|
|
|
|
{
|
|
|
|
.variant = 0,
|
|
|
|
.attributes = 0,
|
|
|
|
.ncomb = 0,
|
|
|
|
.estimated_width = 1,
|
|
|
|
.base = *str
|
|
|
|
};
|
2010-08-28 13:39:34 +00:00
|
|
|
|
|
|
|
FOR_ACTIVE_TERM_OUTPUTS(term)
|
|
|
|
{
|
2010-08-29 19:57:37 +00:00
|
|
|
(term->putchar) (term, &c);
|
2010-08-28 13:39:34 +00:00
|
|
|
}
|
2010-08-29 19:57:37 +00:00
|
|
|
if (*str == '\n')
|
|
|
|
{
|
|
|
|
c.base = '\r';
|
|
|
|
FOR_ACTIVE_TERM_OUTPUTS(term)
|
|
|
|
{
|
|
|
|
(term->putchar) (term, &c);
|
|
|
|
}
|
|
|
|
}
|
2010-08-28 13:39:34 +00:00
|
|
|
}
|
|
|
|
|
2010-03-23 16:54:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-20 16:13:31 +00:00
|
|
|
msg_len = grub_utf8_to_ucs4 (unicode_str, msg_len,
|
|
|
|
(grub_uint8_t *) str, -1, 0);
|
|
|
|
unicode_last_position = unicode_str + msg_len;
|
|
|
|
|
2010-03-17 07:57:23 +00:00
|
|
|
FOR_ACTIVE_TERM_OUTPUTS(term)
|
|
|
|
{
|
2010-03-23 16:54:31 +00:00
|
|
|
int cur;
|
|
|
|
cur = print_ucs4_real (unicode_str, unicode_last_position, 0, 0,
|
2013-01-16 12:41:16 +00:00
|
|
|
term, grub_more, 0, 0, 0, -1, 0, 0);
|
2010-03-23 16:54:31 +00:00
|
|
|
if (cur)
|
|
|
|
backlog = 1;
|
2010-03-17 07:57:23 +00:00
|
|
|
}
|
2010-03-23 16:54:31 +00:00
|
|
|
while (backlog)
|
|
|
|
{
|
|
|
|
print_more ();
|
|
|
|
backlog = 0;
|
|
|
|
FOR_ACTIVE_TERM_OUTPUTS(term)
|
|
|
|
{
|
|
|
|
int cur;
|
|
|
|
cur = print_backlog (term, 0, 0);
|
|
|
|
if (cur)
|
|
|
|
backlog = 1;
|
|
|
|
}
|
|
|
|
}
|
2010-03-23 15:28:35 +00:00
|
|
|
grub_free (unicode_str);
|
2010-03-17 07:57:23 +00:00
|
|
|
}
|
2010-07-02 16:20:48 +00:00
|
|
|
|
2013-03-20 16:13:31 +00:00
|
|
|
void
|
|
|
|
grub_xputs_normal (const char *str)
|
|
|
|
{
|
|
|
|
grub_xnputs (str, grub_strlen (str));
|
|
|
|
}
|
|
|
|
|
2010-07-02 16:20:48 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|