2003-01-20 04:13:46 +00:00
|
|
|
/*
|
2004-04-04 13:46:03 +00:00
|
|
|
* GRUB -- GRand Unified Bootloader
|
2009-12-20 23:32:15 +00:00
|
|
|
* Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2009 Free Software Foundation, Inc.
|
2003-01-20 04:13:46 +00:00
|
|
|
*
|
2007-07-21 23:32:33 +00:00
|
|
|
* GRUB is free software: you can redistribute it and/or modify
|
2003-01-20 04:13:46 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2007-07-21 23:32:33 +00:00
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
2003-01-20 04:13:46 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2007-07-21 23:32:33 +00:00
|
|
|
* GRUB is distributed in the hope that it will be useful,
|
2003-01-20 04:13:46 +00:00
|
|
|
* 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
|
2007-07-21 23:32:33 +00:00
|
|
|
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
2003-01-20 04:13:46 +00:00
|
|
|
*/
|
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
#include <grub/normal.h>
|
|
|
|
#include <grub/misc.h>
|
|
|
|
#include <grub/term.h>
|
|
|
|
#include <grub/err.h>
|
|
|
|
#include <grub/types.h>
|
|
|
|
#include <grub/mm.h>
|
2004-12-04 Marco Gerards <metgerards@student.han.nl>
Modulize the partition map support and add support for the amiga
partition map.
* commands/ls.c: Include <grub/partition.h> instead of
<grub/machine/partition.h>.
* kern/disk.c: Likewise.
* kern/rescue.c: Likewise.
* loader/i386/pc/chainloader.c: Likewise.
* normal/cmdline.c: Likewise.
* kern/powerpc/ieee1275/init.c: Likewise.
(grub_machine_init): Call `grub_pc_partition_map_init',
`grub_amiga_partition_map_init' and
`grub_apple_partition_map_init'.
* conf/i386-pc.rmk (kernel_img_SOURCES): Remove
`disk/i386/pc/partition.c'. Add `kern/partition.c'.
(kernel_img_HEADERS): Remove `machine/partition.h'. Add
`partition.h' and `pc_partition.h'.
(grub_setup_SOURCES): Remove
`disk/i386/pc/partition.c'. Add `kern/partition.c',
`partmap/amiga.c', `partmap/apple.c' and `partmap/pc.c'.
(grub_emu_SOURCES): Likewise.
(pkgdata_MODULES): Add `amiga.mod', `apple.mod' and `pc.mod'.
(amiga_mod_SOURCES, amiga_mod_CFLAGS, apple_mod_SOURCES)
(apple_mod_CFLAGS, pc_mod_SOURCES, pc_mod_CFLAGS): New variables.
* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Remove
`disk/powerpc/ieee1275/partition.c'. Add `kern/partition.c',
`partmap/amiga.c', `partmap/apple.c' and `partmap/pc.c'.
(grubof_SOURCES): Likewise.
* disk/i386/pc/partition.c: File removed.
* disk/powerpc/ieee1275/partition.c: Likewise.
* include/grub/powerpc/ieee1275/partition.h: Likewise.
* include/grub/i386/pc/partition.h: Likewise.
* kern/partition.c: New file.
* partmap/amiga.c: Likewise.
* partmap/apple.c: Likewise.
* partmap/pc.c: Likewise.
* include/grub/partition.h: Likewise..
* include/grub/pc_partition.h: Likewise.
* util/grub-emu.c: Include <grub/partition.h> instead of
<grub/machine/partition.h>.
(main): Call `grub_pc_partition_map_init',
`grub_amiga_partition_map_init' and
`grub_apple_partition_map_init' and deinitialize afterwards.
* util/i386/pc/biosdisk.c: Include `#include
<grub/partition.h>' and `include <grub/pc_partition.h>' instead of
`<grub/machine/partition.h>'.
* util/i386/pc/grub-setup.c: Likewise.
* util/i386/pc/biosdisk.c: Likewise.
(grub_util_biosdisk_get_grub_dev): Only access the PC specific
partition information in case of a PC partition.
* util/i386/pc/grub-setup.c: Include `#include
<grub/partition.h>' and `include <grub/pc_partition.h>' instead of
`<grub/machine/partition.h>'.
(setup): Only access the PC specific partition information in case
of a PC partition.
2004-12-04 18:45:46 +00:00
|
|
|
#include <grub/partition.h>
|
2004-04-04 13:46:03 +00:00
|
|
|
#include <grub/disk.h>
|
|
|
|
#include <grub/file.h>
|
|
|
|
#include <grub/env.h>
|
2009-12-20 23:32:15 +00:00
|
|
|
#include <grub/i18n.h>
|
2009-12-24 14:34:33 +00:00
|
|
|
#include <grub/charset.h>
|
2003-01-20 04:13:46 +00:00
|
|
|
|
2009-12-23 23:37:11 +00:00
|
|
|
static grub_uint32_t *kill_buf;
|
2003-01-20 04:13:46 +00:00
|
|
|
|
2003-12-03 19:17:27 +00:00
|
|
|
static int hist_size;
|
2009-12-23 23:37:11 +00:00
|
|
|
static grub_uint32_t **hist_lines = 0;
|
2003-12-03 19:17:27 +00:00
|
|
|
static int hist_pos = 0;
|
|
|
|
static int hist_end = 0;
|
|
|
|
static int hist_used = 0;
|
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_err_t
|
|
|
|
grub_set_history (int newsize)
|
2003-12-03 19:17:27 +00:00
|
|
|
{
|
2009-12-23 23:37:11 +00:00
|
|
|
grub_uint32_t **old_hist_lines = hist_lines;
|
2009-12-24 21:55:06 +00:00
|
|
|
hist_lines = grub_malloc (sizeof (grub_uint32_t *) * newsize);
|
2003-12-03 19:17:27 +00:00
|
|
|
|
|
|
|
/* Copy the old lines into the new buffer. */
|
|
|
|
if (old_hist_lines)
|
|
|
|
{
|
|
|
|
/* Remove the lines that don't fit in the new buffer. */
|
|
|
|
if (newsize < hist_used)
|
|
|
|
{
|
2012-02-24 11:30:32 +00:00
|
|
|
grub_size_t i;
|
|
|
|
grub_size_t delsize = hist_used - newsize;
|
2003-12-03 19:17:27 +00:00
|
|
|
hist_used = newsize;
|
|
|
|
|
2012-02-24 11:30:32 +00:00
|
|
|
for (i = 1; i < delsize + 1; i++)
|
2003-12-03 19:17:27 +00:00
|
|
|
{
|
2012-02-24 11:30:32 +00:00
|
|
|
grub_ssize_t pos = hist_end - i;
|
2004-06-27 11:03:24 +00:00
|
|
|
if (pos < 0)
|
|
|
|
pos += hist_size;
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_free (old_hist_lines[pos]);
|
2003-12-03 19:17:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
hist_end -= delsize;
|
|
|
|
if (hist_end < 0)
|
2004-06-27 11:03:24 +00:00
|
|
|
hist_end += hist_size;
|
2003-12-03 19:17:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (hist_pos < hist_end)
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_memmove (hist_lines, old_hist_lines + hist_pos,
|
2009-12-24 21:55:06 +00:00
|
|
|
(hist_end - hist_pos) * sizeof (grub_uint32_t *));
|
2004-06-27 11:03:24 +00:00
|
|
|
else if (hist_used)
|
2003-12-03 19:17:27 +00:00
|
|
|
{
|
2004-06-27 11:03:24 +00:00
|
|
|
/* Copy the older part. */
|
|
|
|
grub_memmove (hist_lines, old_hist_lines + hist_pos,
|
2009-12-24 21:55:06 +00:00
|
|
|
(hist_size - hist_pos) * sizeof (grub_uint32_t *));
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2004-06-27 11:03:24 +00:00
|
|
|
/* Copy the newer part. */
|
|
|
|
grub_memmove (hist_lines + hist_size - hist_pos, old_hist_lines,
|
2009-12-24 21:55:06 +00:00
|
|
|
hist_end * sizeof (grub_uint32_t *));
|
2003-12-03 19:17:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_free (old_hist_lines);
|
2003-12-03 19:17:27 +00:00
|
|
|
|
|
|
|
hist_size = newsize;
|
|
|
|
hist_pos = 0;
|
|
|
|
hist_end = hist_used;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the entry POS from the history where `0' is the newest
|
|
|
|
entry. */
|
2009-12-23 23:37:11 +00:00
|
|
|
static grub_uint32_t *
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_history_get (int pos)
|
2003-12-03 19:17:27 +00:00
|
|
|
{
|
|
|
|
pos = (hist_pos + pos) % hist_size;
|
|
|
|
return hist_lines[pos];
|
|
|
|
}
|
|
|
|
|
2009-12-23 23:37:11 +00:00
|
|
|
static grub_size_t
|
|
|
|
strlen_ucs4 (const grub_uint32_t *s)
|
|
|
|
{
|
|
|
|
const grub_uint32_t *p = s;
|
|
|
|
|
|
|
|
while (*p)
|
|
|
|
p++;
|
|
|
|
|
|
|
|
return p - s;
|
|
|
|
}
|
|
|
|
|
2009-12-24 21:55:06 +00:00
|
|
|
/* Replace the history entry on position POS with the string S. */
|
|
|
|
static void
|
|
|
|
grub_history_set (int pos, grub_uint32_t *s, grub_size_t len)
|
2009-12-23 23:37:11 +00:00
|
|
|
{
|
2009-12-24 21:55:06 +00:00
|
|
|
grub_free (hist_lines[pos]);
|
|
|
|
hist_lines[pos] = grub_malloc ((len + 1) * sizeof (grub_uint32_t));
|
|
|
|
if (!hist_lines[pos])
|
|
|
|
{
|
|
|
|
grub_print_error ();
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
grub_memcpy (hist_lines[pos], s, len * sizeof (grub_uint32_t));
|
|
|
|
hist_lines[pos][len] = 0;
|
2009-12-23 23:37:11 +00:00
|
|
|
}
|
2003-12-03 19:17:27 +00:00
|
|
|
|
|
|
|
/* Insert a new history line S on the top of the history. */
|
|
|
|
static void
|
2009-12-24 21:55:06 +00:00
|
|
|
grub_history_add (grub_uint32_t *s, grub_size_t len)
|
2003-12-03 19:17:27 +00:00
|
|
|
{
|
|
|
|
/* Remove the oldest entry in the history to make room for a new
|
|
|
|
entry. */
|
|
|
|
if (hist_used + 1 > hist_size)
|
|
|
|
{
|
|
|
|
hist_end--;
|
|
|
|
if (hist_end < 0)
|
|
|
|
hist_end = hist_size + hist_end;
|
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_free (hist_lines[hist_end]);
|
2003-12-03 19:17:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
hist_used++;
|
|
|
|
|
|
|
|
/* Move to the next position. */
|
|
|
|
hist_pos--;
|
|
|
|
if (hist_pos < 0)
|
|
|
|
hist_pos = hist_size + hist_pos;
|
|
|
|
|
|
|
|
/* Insert into history. */
|
2009-12-24 21:55:06 +00:00
|
|
|
hist_lines[hist_pos] = NULL;
|
|
|
|
grub_history_set (hist_pos, s, len);
|
2003-12-03 19:17:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Replace the history entry on position POS with the string S. */
|
|
|
|
static void
|
2009-12-24 21:55:06 +00:00
|
|
|
grub_history_replace (int pos, grub_uint32_t *s, grub_size_t len)
|
2003-12-03 19:17:27 +00:00
|
|
|
{
|
2009-12-24 21:55:06 +00:00
|
|
|
grub_history_set ((hist_pos + pos) % hist_size, s, len);
|
2003-12-03 19:17:27 +00:00
|
|
|
}
|
|
|
|
|
2005-08-18 03:14:39 +00:00
|
|
|
/* A completion hook to print items. */
|
|
|
|
static void
|
|
|
|
print_completion (const char *item, grub_completion_type_t type, int count)
|
|
|
|
{
|
|
|
|
if (count == 0)
|
|
|
|
{
|
|
|
|
/* If this is the first time, print a label. */
|
2010-01-14 23:07:44 +00:00
|
|
|
|
|
|
|
grub_puts ("");
|
2005-08-18 03:14:39 +00:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case GRUB_COMPLETION_TYPE_COMMAND:
|
2010-01-14 23:07:44 +00:00
|
|
|
grub_puts_ (N_("Possible commands are:"));
|
2005-08-18 03:14:39 +00:00
|
|
|
break;
|
|
|
|
case GRUB_COMPLETION_TYPE_DEVICE:
|
2010-01-14 23:07:44 +00:00
|
|
|
grub_puts_ (N_("Possible devices are:"));
|
2005-08-18 03:14:39 +00:00
|
|
|
break;
|
|
|
|
case GRUB_COMPLETION_TYPE_FILE:
|
2010-01-14 23:07:44 +00:00
|
|
|
grub_puts_ (N_("Possible files are:"));
|
2005-08-18 03:14:39 +00:00
|
|
|
break;
|
|
|
|
case GRUB_COMPLETION_TYPE_PARTITION:
|
2010-01-14 23:07:44 +00:00
|
|
|
grub_puts_ (N_("Possible partitions are:"));
|
2005-08-18 03:14:39 +00:00
|
|
|
break;
|
2005-08-28 17:01:16 +00:00
|
|
|
case GRUB_COMPLETION_TYPE_ARGUMENT:
|
2010-01-14 23:07:44 +00:00
|
|
|
grub_puts_ (N_("Possible arguments are:"));
|
2005-08-28 17:01:16 +00:00
|
|
|
break;
|
2005-08-18 03:14:39 +00:00
|
|
|
default:
|
2012-03-05 15:42:26 +00:00
|
|
|
/* TRANSLATORS: this message is used if none of above matches.
|
|
|
|
This shouldn't happen but please use the general term for
|
|
|
|
"thing" or "object". */
|
2010-01-14 23:07:44 +00:00
|
|
|
grub_puts_ (N_("Possible things are:"));
|
2005-08-18 03:14:39 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-01-14 23:07:44 +00:00
|
|
|
grub_puts ("");
|
2005-08-18 03:14:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (type == GRUB_COMPLETION_TYPE_PARTITION)
|
|
|
|
{
|
|
|
|
grub_normal_print_device_info (item);
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
grub_printf (" %s", item);
|
|
|
|
}
|
|
|
|
|
2009-12-23 23:37:11 +00:00
|
|
|
struct cmdline_term
|
|
|
|
{
|
|
|
|
unsigned xpos, ypos, ystart, width, height;
|
2012-04-01 19:25:17 +00:00
|
|
|
unsigned prompt_len;
|
2009-12-23 23:37:11 +00:00
|
|
|
struct grub_term_output *term;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Get a command-line. If ESC is pushed, return zero,
|
|
|
|
otherwise return command line. */
|
2003-01-20 04:13:46 +00:00
|
|
|
/* FIXME: The dumb interface is not supported yet. */
|
2009-12-23 23:37:11 +00:00
|
|
|
char *
|
2012-02-12 18:24:23 +00:00
|
|
|
grub_cmdline_get (const char *prompt_translated)
|
2003-01-20 04:13:46 +00:00
|
|
|
{
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_size_t lpos, llen;
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_uint32_t *buf;
|
|
|
|
grub_size_t max_len = 256;
|
2003-01-20 04:13:46 +00:00
|
|
|
int key;
|
2003-12-03 19:17:27 +00:00
|
|
|
int histpos = 0;
|
2009-12-23 23:37:11 +00:00
|
|
|
auto void cl_insert (const grub_uint32_t *str);
|
2003-01-20 04:13:46 +00:00
|
|
|
auto void cl_delete (unsigned len);
|
2009-12-29 12:03:22 +00:00
|
|
|
auto inline void __attribute__ ((always_inline)) cl_print (struct cmdline_term *cl_term, int pos,
|
|
|
|
grub_uint32_t c);
|
2009-12-23 23:37:11 +00:00
|
|
|
auto void cl_set_pos (struct cmdline_term *cl_term);
|
|
|
|
auto void cl_print_all (int pos, grub_uint32_t c);
|
|
|
|
auto void cl_set_pos_all (void);
|
2009-12-29 16:54:27 +00:00
|
|
|
auto void init_clterm (struct cmdline_term *cl_term_cur);
|
|
|
|
auto void init_clterm_all (void);
|
2009-12-23 23:37:11 +00:00
|
|
|
struct cmdline_term *cl_terms;
|
2009-12-24 14:34:33 +00:00
|
|
|
char *ret;
|
2009-12-23 23:37:11 +00:00
|
|
|
unsigned nterms;
|
|
|
|
|
|
|
|
void cl_set_pos (struct cmdline_term *cl_term)
|
|
|
|
{
|
2013-05-14 06:54:18 +00:00
|
|
|
cl_term->xpos = (cl_term->prompt_len + lpos) % cl_term->width;
|
2012-04-01 19:25:17 +00:00
|
|
|
cl_term->ypos = cl_term->ystart
|
2013-05-14 06:54:18 +00:00
|
|
|
+ (cl_term->prompt_len + lpos) / cl_term->width;
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_term_gotoxy (cl_term->term, cl_term->xpos, cl_term->ypos);
|
2009-12-23 23:37:11 +00:00
|
|
|
}
|
|
|
|
|
2011-03-23 11:08:33 +00:00
|
|
|
void cl_set_pos_all (void)
|
2009-12-23 23:37:11 +00:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
for (i = 0; i < nterms; i++)
|
|
|
|
cl_set_pos (&cl_terms[i]);
|
|
|
|
}
|
|
|
|
|
2009-12-29 12:03:22 +00:00
|
|
|
inline void __attribute__ ((always_inline)) cl_print (struct cmdline_term *cl_term, int pos, grub_uint32_t c)
|
2003-01-20 04:13:46 +00:00
|
|
|
{
|
2009-12-23 23:37:11 +00:00
|
|
|
grub_uint32_t *p;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
for (p = buf + pos; p < buf + llen; p++)
|
2003-01-20 04:13:46 +00:00
|
|
|
{
|
2010-01-10 21:34:25 +00:00
|
|
|
if (c)
|
|
|
|
grub_putcode (c, cl_term->term);
|
|
|
|
else
|
|
|
|
grub_putcode (*p, cl_term->term);
|
|
|
|
cl_term->xpos++;
|
|
|
|
if (cl_term->xpos >= cl_term->width - 1)
|
2003-01-20 04:13:46 +00:00
|
|
|
{
|
2010-01-10 21:34:25 +00:00
|
|
|
cl_term->xpos = 0;
|
|
|
|
if (cl_term->ypos >= (unsigned) (cl_term->height - 1))
|
2009-12-23 23:37:11 +00:00
|
|
|
cl_term->ystart--;
|
2003-01-20 04:13:46 +00:00
|
|
|
else
|
2009-12-23 23:37:11 +00:00
|
|
|
cl_term->ypos++;
|
2010-01-10 21:34:25 +00:00
|
|
|
grub_putcode ('\n', cl_term->term);
|
2003-01-20 04:13:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2009-12-23 23:37:11 +00:00
|
|
|
void cl_print_all (int pos, grub_uint32_t c)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
for (i = 0; i < nterms; i++)
|
|
|
|
cl_print (&cl_terms[i], pos, c);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cl_insert (const grub_uint32_t *str)
|
2003-01-20 04:13:46 +00:00
|
|
|
{
|
2009-12-23 23:37:11 +00:00
|
|
|
grub_size_t len = strlen_ucs4 (str);
|
2003-01-20 04:13:46 +00:00
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
if (len + llen >= max_len)
|
|
|
|
{
|
|
|
|
grub_uint32_t *nbuf;
|
|
|
|
max_len *= 2;
|
|
|
|
nbuf = grub_realloc (buf, sizeof (grub_uint32_t) * max_len);
|
|
|
|
if (nbuf)
|
|
|
|
buf = nbuf;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
grub_print_error ();
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
max_len /= 2;
|
|
|
|
}
|
|
|
|
}
|
2003-01-20 04:13:46 +00:00
|
|
|
|
|
|
|
if (len + llen < max_len)
|
|
|
|
{
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_memmove (buf + lpos + len, buf + lpos,
|
|
|
|
(llen - lpos + 1) * sizeof (grub_uint32_t));
|
|
|
|
grub_memmove (buf + lpos, str, len * sizeof (grub_uint32_t));
|
2003-01-20 04:13:46 +00:00
|
|
|
|
|
|
|
llen += len;
|
2010-03-06 16:48:15 +00:00
|
|
|
cl_set_pos_all ();
|
|
|
|
cl_print_all (lpos, 0);
|
2003-01-20 04:13:46 +00:00
|
|
|
lpos += len;
|
2009-12-23 23:37:11 +00:00
|
|
|
cl_set_pos_all ();
|
2003-01-20 04:13:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cl_delete (unsigned len)
|
|
|
|
{
|
|
|
|
if (lpos + len <= llen)
|
|
|
|
{
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_size_t saved_lpos = lpos;
|
2003-01-20 04:13:46 +00:00
|
|
|
|
|
|
|
lpos = llen - len;
|
2009-12-23 23:37:11 +00:00
|
|
|
cl_set_pos_all ();
|
|
|
|
cl_print_all (lpos, ' ');
|
2003-01-20 04:13:46 +00:00
|
|
|
lpos = saved_lpos;
|
2009-12-23 23:37:11 +00:00
|
|
|
cl_set_pos_all ();
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2009-12-24 21:55:06 +00:00
|
|
|
grub_memmove (buf + lpos, buf + lpos + len,
|
|
|
|
sizeof (grub_uint32_t) * (llen - lpos + 1));
|
2003-01-20 04:13:46 +00:00
|
|
|
llen -= len;
|
2009-12-24 14:34:33 +00:00
|
|
|
cl_print_all (lpos, 0);
|
2009-12-23 23:37:11 +00:00
|
|
|
cl_set_pos_all ();
|
2003-01-20 04:13:46 +00:00
|
|
|
}
|
|
|
|
}
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2009-12-23 23:37:11 +00:00
|
|
|
void init_clterm (struct cmdline_term *cl_term_cur)
|
|
|
|
{
|
2012-04-01 19:25:17 +00:00
|
|
|
cl_term_cur->xpos = cl_term_cur->prompt_len;
|
2009-12-24 14:34:33 +00:00
|
|
|
cl_term_cur->ypos = (grub_term_getxy (cl_term_cur->term) & 0xFF);
|
2009-12-23 23:37:11 +00:00
|
|
|
cl_term_cur->ystart = cl_term_cur->ypos;
|
|
|
|
cl_term_cur->width = grub_term_width (cl_term_cur->term);
|
|
|
|
cl_term_cur->height = grub_term_height (cl_term_cur->term);
|
|
|
|
}
|
|
|
|
|
|
|
|
void init_clterm_all (void)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
for (i = 0; i < nterms; i++)
|
|
|
|
init_clterm (&cl_terms[i]);
|
|
|
|
}
|
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
buf = grub_malloc (max_len * sizeof (grub_uint32_t));
|
|
|
|
if (!buf)
|
|
|
|
return 0;
|
|
|
|
|
2003-01-20 04:13:46 +00:00
|
|
|
lpos = llen = 0;
|
|
|
|
buf[0] = '\0';
|
|
|
|
|
2009-12-24 22:19:54 +00:00
|
|
|
{
|
|
|
|
grub_term_output_t term;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2009-12-24 22:19:54 +00:00
|
|
|
FOR_ACTIVE_TERM_OUTPUTS(term)
|
|
|
|
if ((grub_term_getxy (term) >> 8) != 0)
|
|
|
|
grub_putcode ('\n', term);
|
|
|
|
}
|
2012-04-01 19:25:17 +00:00
|
|
|
grub_xputs (prompt_translated);
|
|
|
|
grub_xputs (" ");
|
2010-03-23 17:06:49 +00:00
|
|
|
grub_normal_reset_more ();
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2009-12-23 23:37:11 +00:00
|
|
|
{
|
|
|
|
struct cmdline_term *cl_term_cur;
|
|
|
|
struct grub_term_output *cur;
|
2012-04-01 19:25:17 +00:00
|
|
|
grub_uint32_t *unicode_msg;
|
|
|
|
grub_size_t msg_len = grub_strlen (prompt_translated) + 3;
|
|
|
|
|
2009-12-23 23:37:11 +00:00
|
|
|
nterms = 0;
|
2009-12-24 16:51:43 +00:00
|
|
|
FOR_ACTIVE_TERM_OUTPUTS(cur)
|
|
|
|
nterms++;
|
2009-12-23 23:37:11 +00:00
|
|
|
|
|
|
|
cl_terms = grub_malloc (sizeof (cl_terms[0]) * nterms);
|
|
|
|
if (!cl_terms)
|
2009-12-24 14:34:33 +00:00
|
|
|
return 0;
|
2009-12-23 23:37:11 +00:00
|
|
|
cl_term_cur = cl_terms;
|
2012-04-01 19:25:17 +00:00
|
|
|
|
|
|
|
unicode_msg = grub_malloc (msg_len * sizeof (grub_uint32_t));
|
|
|
|
if (!unicode_msg)
|
|
|
|
return 0;;
|
|
|
|
msg_len = grub_utf8_to_ucs4 (unicode_msg, msg_len - 1,
|
|
|
|
(grub_uint8_t *) prompt_translated, -1, 0);
|
|
|
|
unicode_msg[msg_len++] = ' ';
|
|
|
|
|
2009-12-24 16:51:43 +00:00
|
|
|
FOR_ACTIVE_TERM_OUTPUTS(cur)
|
|
|
|
{
|
|
|
|
cl_term_cur->term = cur;
|
2012-04-01 19:25:17 +00:00
|
|
|
cl_term_cur->prompt_len = grub_getstringwidth (unicode_msg,
|
|
|
|
unicode_msg + msg_len,
|
|
|
|
cur);
|
2009-12-24 16:51:43 +00:00
|
|
|
init_clterm (cl_term_cur);
|
|
|
|
cl_term_cur++;
|
|
|
|
}
|
2012-04-01 19:25:17 +00:00
|
|
|
grub_free (unicode_msg);
|
2009-12-23 23:37:11 +00:00
|
|
|
}
|
2003-01-20 04:13:46 +00:00
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
if (hist_used == 0)
|
2009-12-24 21:55:06 +00:00
|
|
|
grub_history_add (buf, llen);
|
2003-12-03 19:17:27 +00:00
|
|
|
|
2009-11-14 16:00:39 +00:00
|
|
|
grub_refresh ();
|
|
|
|
|
2010-05-10 12:54:51 +00:00
|
|
|
while ((key = grub_getkey ()) != '\n' && key != '\r')
|
2003-01-20 04:13:46 +00:00
|
|
|
{
|
2009-12-23 23:37:11 +00:00
|
|
|
switch (key)
|
2003-01-20 04:13:46 +00:00
|
|
|
{
|
2010-05-10 12:54:51 +00:00
|
|
|
case GRUB_TERM_CTRL | 'a':
|
|
|
|
case GRUB_TERM_KEY_HOME:
|
2009-12-23 23:37:11 +00:00
|
|
|
lpos = 0;
|
|
|
|
cl_set_pos_all ();
|
|
|
|
break;
|
|
|
|
|
2010-05-10 12:54:51 +00:00
|
|
|
case GRUB_TERM_CTRL | 'b':
|
|
|
|
case GRUB_TERM_KEY_LEFT:
|
2009-12-23 23:37:11 +00:00
|
|
|
if (lpos > 0)
|
2003-01-20 04:13:46 +00:00
|
|
|
{
|
2009-12-23 23:37:11 +00:00
|
|
|
lpos--;
|
|
|
|
cl_set_pos_all ();
|
|
|
|
}
|
|
|
|
break;
|
2003-01-20 04:13:46 +00:00
|
|
|
|
2010-05-10 12:54:51 +00:00
|
|
|
case GRUB_TERM_CTRL | 'e':
|
|
|
|
case GRUB_TERM_KEY_END:
|
2009-12-23 23:37:11 +00:00
|
|
|
lpos = llen;
|
|
|
|
cl_set_pos_all ();
|
|
|
|
break;
|
2003-01-20 04:13:46 +00:00
|
|
|
|
2010-05-10 12:54:51 +00:00
|
|
|
case GRUB_TERM_CTRL | 'f':
|
|
|
|
case GRUB_TERM_KEY_RIGHT:
|
2009-12-23 23:37:11 +00:00
|
|
|
if (lpos < llen)
|
|
|
|
{
|
|
|
|
lpos++;
|
|
|
|
cl_set_pos_all ();
|
|
|
|
}
|
|
|
|
break;
|
2003-01-20 04:13:46 +00:00
|
|
|
|
2010-05-10 12:54:51 +00:00
|
|
|
case GRUB_TERM_CTRL | 'i':
|
|
|
|
case '\t':
|
2009-12-23 23:37:11 +00:00
|
|
|
{
|
|
|
|
int restore;
|
2009-12-24 21:55:06 +00:00
|
|
|
char *insertu8;
|
|
|
|
char *bufu8;
|
2010-01-27 16:47:36 +00:00
|
|
|
grub_uint32_t c;
|
2003-01-20 04:13:46 +00:00
|
|
|
|
2010-01-27 16:47:36 +00:00
|
|
|
c = buf[lpos];
|
2009-12-23 23:37:11 +00:00
|
|
|
buf[lpos] = '\0';
|
2003-01-20 04:13:46 +00:00
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
bufu8 = grub_ucs4_to_utf8_alloc (buf, lpos);
|
2010-01-27 16:47:36 +00:00
|
|
|
buf[lpos] = c;
|
2009-12-24 14:34:33 +00:00
|
|
|
if (!bufu8)
|
2003-12-03 19:17:27 +00:00
|
|
|
{
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_print_error ();
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
break;
|
|
|
|
}
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
insertu8 = grub_normal_do_completion (bufu8, &restore,
|
|
|
|
print_completion);
|
|
|
|
grub_free (bufu8);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2010-03-23 17:06:49 +00:00
|
|
|
grub_normal_reset_more ();
|
|
|
|
|
2009-12-23 23:37:11 +00:00
|
|
|
if (restore)
|
2003-12-03 19:17:27 +00:00
|
|
|
{
|
2009-12-23 23:37:11 +00:00
|
|
|
/* Restore the prompt. */
|
2012-04-01 19:25:17 +00:00
|
|
|
grub_xputs ("\n");
|
|
|
|
grub_xputs (prompt_translated);
|
|
|
|
grub_xputs (" ");
|
2009-12-23 23:37:11 +00:00
|
|
|
init_clterm_all ();
|
|
|
|
cl_print_all (0, 0);
|
2003-12-03 19:17:27 +00:00
|
|
|
}
|
|
|
|
|
2009-12-24 21:55:06 +00:00
|
|
|
if (insertu8)
|
2009-12-23 23:37:11 +00:00
|
|
|
{
|
2009-12-24 21:55:06 +00:00
|
|
|
grub_size_t insertlen;
|
|
|
|
grub_ssize_t t;
|
|
|
|
grub_uint32_t *insert;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2009-12-24 21:55:06 +00:00
|
|
|
insertlen = grub_strlen (insertu8);
|
|
|
|
insert = grub_malloc ((insertlen + 1) * sizeof (grub_uint32_t));
|
|
|
|
if (!insert)
|
2003-12-03 19:17:27 +00:00
|
|
|
{
|
2009-12-24 21:55:06 +00:00
|
|
|
grub_free (insertu8);
|
|
|
|
grub_print_error ();
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
break;
|
2003-12-03 19:17:27 +00:00
|
|
|
}
|
2009-12-24 21:55:06 +00:00
|
|
|
t = grub_utf8_to_ucs4 (insert, insertlen,
|
|
|
|
(grub_uint8_t *) insertu8,
|
|
|
|
insertlen, 0);
|
|
|
|
if (t > 0)
|
2003-12-03 19:17:27 +00:00
|
|
|
{
|
2010-01-27 16:47:36 +00:00
|
|
|
if (insert[t-1] == ' ' && buf[lpos] == ' ')
|
|
|
|
{
|
|
|
|
insert[t-1] = 0;
|
|
|
|
if (t != 1)
|
|
|
|
cl_insert (insert);
|
|
|
|
lpos++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
insert[t] = 0;
|
|
|
|
cl_insert (insert);
|
|
|
|
}
|
2003-12-03 19:17:27 +00:00
|
|
|
}
|
2009-12-24 21:55:06 +00:00
|
|
|
|
|
|
|
grub_free (insertu8);
|
2009-12-23 23:37:11 +00:00
|
|
|
grub_free (insert);
|
2003-12-03 19:17:27 +00:00
|
|
|
}
|
2010-03-06 16:48:15 +00:00
|
|
|
cl_set_pos_all ();
|
2009-12-23 23:37:11 +00:00
|
|
|
}
|
|
|
|
break;
|
2003-01-20 04:13:46 +00:00
|
|
|
|
2010-05-10 12:54:51 +00:00
|
|
|
case GRUB_TERM_CTRL | 'k':
|
2009-12-23 23:37:11 +00:00
|
|
|
if (lpos < llen)
|
|
|
|
{
|
2011-06-26 15:17:41 +00:00
|
|
|
grub_free (kill_buf);
|
2003-01-20 04:13:46 +00:00
|
|
|
|
2009-12-24 21:55:06 +00:00
|
|
|
kill_buf = grub_malloc ((llen - lpos + 1)
|
|
|
|
* sizeof (grub_uint32_t));
|
2009-12-24 14:34:33 +00:00
|
|
|
if (grub_errno)
|
|
|
|
{
|
|
|
|
grub_print_error ();
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_errno = GRUB_ERR_NONE;
|
2003-01-20 04:13:46 +00:00
|
|
|
}
|
2009-12-24 21:55:06 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
grub_memcpy (kill_buf, buf + lpos,
|
|
|
|
(llen - lpos + 1) * sizeof (grub_uint32_t));
|
|
|
|
kill_buf[llen - lpos] = 0;
|
|
|
|
}
|
2003-01-20 04:13:46 +00:00
|
|
|
|
2009-12-23 23:37:11 +00:00
|
|
|
cl_delete (llen - lpos);
|
|
|
|
}
|
|
|
|
break;
|
2003-12-03 19:17:27 +00:00
|
|
|
|
2010-05-10 12:54:51 +00:00
|
|
|
case GRUB_TERM_CTRL | 'n':
|
|
|
|
case GRUB_TERM_KEY_DOWN:
|
2009-12-23 23:37:11 +00:00
|
|
|
{
|
|
|
|
grub_uint32_t *hist;
|
2003-12-03 19:17:27 +00:00
|
|
|
|
2009-12-23 23:37:11 +00:00
|
|
|
lpos = 0;
|
2003-12-03 19:17:27 +00:00
|
|
|
|
2009-12-23 23:37:11 +00:00
|
|
|
if (histpos > 0)
|
2003-12-03 19:17:27 +00:00
|
|
|
{
|
2009-12-24 21:55:06 +00:00
|
|
|
grub_history_replace (histpos, buf, llen);
|
2009-12-23 23:37:11 +00:00
|
|
|
histpos--;
|
|
|
|
}
|
2003-12-03 19:17:27 +00:00
|
|
|
|
2009-12-23 23:37:11 +00:00
|
|
|
cl_delete (llen);
|
|
|
|
hist = grub_history_get (histpos);
|
|
|
|
cl_insert (hist);
|
2003-12-03 19:17:27 +00:00
|
|
|
|
2009-12-23 23:37:11 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-05-10 12:54:51 +00:00
|
|
|
|
|
|
|
case GRUB_TERM_KEY_UP:
|
|
|
|
case GRUB_TERM_CTRL | 'p':
|
2009-12-23 23:37:11 +00:00
|
|
|
{
|
|
|
|
grub_uint32_t *hist;
|
2003-12-03 19:17:27 +00:00
|
|
|
|
2009-12-23 23:37:11 +00:00
|
|
|
lpos = 0;
|
2003-12-03 19:17:27 +00:00
|
|
|
|
2009-12-23 23:37:11 +00:00
|
|
|
if (histpos < hist_used - 1)
|
2003-12-03 19:17:27 +00:00
|
|
|
{
|
2009-12-24 21:55:06 +00:00
|
|
|
grub_history_replace (histpos, buf, llen);
|
2009-12-23 23:37:11 +00:00
|
|
|
histpos++;
|
2003-12-03 19:17:27 +00:00
|
|
|
}
|
2003-01-20 04:13:46 +00:00
|
|
|
|
2009-12-23 23:37:11 +00:00
|
|
|
cl_delete (llen);
|
|
|
|
hist = grub_history_get (histpos);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2009-12-23 23:37:11 +00:00
|
|
|
cl_insert (hist);
|
|
|
|
}
|
|
|
|
break;
|
2003-01-20 04:13:46 +00:00
|
|
|
|
2010-05-10 12:54:51 +00:00
|
|
|
case GRUB_TERM_CTRL | 'u':
|
2009-12-23 23:37:11 +00:00
|
|
|
if (lpos > 0)
|
|
|
|
{
|
|
|
|
grub_size_t n = lpos;
|
2003-12-03 19:17:27 +00:00
|
|
|
|
2011-06-26 15:17:41 +00:00
|
|
|
grub_free (kill_buf);
|
2003-01-20 04:13:46 +00:00
|
|
|
|
2009-12-23 23:37:11 +00:00
|
|
|
kill_buf = grub_malloc (n + 1);
|
2009-12-24 14:34:33 +00:00
|
|
|
if (grub_errno)
|
|
|
|
{
|
|
|
|
grub_print_error ();
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_errno = GRUB_ERR_NONE;
|
2003-01-20 04:13:46 +00:00
|
|
|
}
|
|
|
|
if (kill_buf)
|
|
|
|
{
|
2009-12-23 23:37:11 +00:00
|
|
|
grub_memcpy (kill_buf, buf, n);
|
|
|
|
kill_buf[n] = '\0';
|
2003-01-20 04:13:46 +00:00
|
|
|
}
|
|
|
|
|
2009-12-23 23:37:11 +00:00
|
|
|
lpos = 0;
|
|
|
|
cl_set_pos_all ();
|
|
|
|
cl_delete (n);
|
2003-01-20 04:13:46 +00:00
|
|
|
}
|
2009-12-23 23:37:11 +00:00
|
|
|
break;
|
|
|
|
|
2010-05-10 12:54:51 +00:00
|
|
|
case GRUB_TERM_CTRL | 'y':
|
2009-12-23 23:37:11 +00:00
|
|
|
if (kill_buf)
|
|
|
|
cl_insert (kill_buf);
|
|
|
|
break;
|
2003-01-20 04:13:46 +00:00
|
|
|
|
|
|
|
case '\e':
|
2010-08-28 13:29:44 +00:00
|
|
|
grub_free (cl_terms);
|
2003-01-20 04:13:46 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case '\b':
|
|
|
|
if (lpos > 0)
|
|
|
|
{
|
|
|
|
lpos--;
|
2009-12-23 23:37:11 +00:00
|
|
|
cl_set_pos_all ();
|
2003-01-20 04:13:46 +00:00
|
|
|
}
|
2005-07-04 13:50:10 +00:00
|
|
|
else
|
|
|
|
break;
|
2003-01-20 04:13:46 +00:00
|
|
|
/* fall through */
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2010-05-10 12:54:51 +00:00
|
|
|
case GRUB_TERM_CTRL | 'd':
|
|
|
|
case GRUB_TERM_KEY_DC:
|
2003-01-20 04:13:46 +00:00
|
|
|
if (lpos < llen)
|
|
|
|
cl_delete (1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2004-04-04 13:46:03 +00:00
|
|
|
if (grub_isprint (key))
|
2003-01-20 04:13:46 +00:00
|
|
|
{
|
2009-12-23 23:37:11 +00:00
|
|
|
grub_uint32_t str[2];
|
2003-01-20 04:13:46 +00:00
|
|
|
|
|
|
|
str[0] = key;
|
|
|
|
str[1] = '\0';
|
|
|
|
cl_insert (str);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-11-14 16:00:39 +00:00
|
|
|
|
|
|
|
grub_refresh ();
|
2003-01-20 04:13:46 +00:00
|
|
|
}
|
|
|
|
|
2010-03-15 10:49:27 +00:00
|
|
|
grub_xputs ("\n");
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_refresh ();
|
2003-01-20 04:13:46 +00:00
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
histpos = 0;
|
|
|
|
if (strlen_ucs4 (buf) > 0)
|
2004-12-29 22:43:48 +00:00
|
|
|
{
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_uint32_t empty[] = { 0 };
|
2009-12-24 21:55:06 +00:00
|
|
|
grub_history_replace (histpos, buf, llen);
|
|
|
|
grub_history_add (empty, 0);
|
2004-12-29 22:43:48 +00:00
|
|
|
}
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2012-03-11 13:43:18 +00:00
|
|
|
ret = grub_ucs4_to_utf8_alloc (buf, llen + 1);
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_free (buf);
|
2010-08-28 13:29:44 +00:00
|
|
|
grub_free (cl_terms);
|
2009-12-24 14:34:33 +00:00
|
|
|
return ret;
|
2003-01-20 04:13:46 +00:00
|
|
|
}
|