grub/grub-core/normal/color.c

146 lines
3.4 KiB
C
Raw Normal View History

2008-01-05 13:03:34 +00:00
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2004,2008 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/>.
*/
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/normal.h>
#include <grub/term.h>
#include <grub/i18n.h>
2008-01-05 13:03:34 +00:00
/* Borrowed from GRUB Legacy */
Add missing const qualifiers. * grub-core/commands/i386/pc/sendkey.c (keysym): Add missing const. * grub-core/commands/lspci.c (grub_pci_classname): Likewise. * grub-core/commands/menuentry.c (hotkey_aliases): Likewise. * grub-core/disk/lvm.c (grub_lvm_getvalue): Likewise. (grub_lvm_check_flag): Likewise. * grub-core/efiemu/i386/coredetect.c (grub_efiemu_get_default_core_name): Likewise * grub-core/efiemu/main.c (grub_efiemu_autocore): Likewise. * grub-core/fs/hfsplus.c (grub_hfsplus_catkey_internal): Likewise. * grub-core/fs/ntfs.c (fixup): Likewise. * grub-core/fs/xfs.c (grub_xfs_iterate_dir): Likewise. * grub-core/fs/zfs/zfs.c (decomp_entry): Likewise. (fzap_lookup): Likewise. (zap_lookup): Likewise. * grub-core/gnulib/regcomp.c (init_dfa): Likewise. * grub-core/lib/legacy_parse.c (check_option): Likewise. * grub-core/lib/posix_wrap/langinfo.h (nl_langinfo): Likewise. * grub-core/loader/i386/bsd.c (grub_bsd_add_meta): Likewise. (grub_freebsd_add_meta_module): Likewise. (grub_cmd_freebsd_module): Likewise. * grub-core/loader/i386/xnu.c (tbl_alias): Likewise. * grub-core/loader/xnu.c (grub_xnu_register_memory): Likewise. (grub_xnu_writetree_get_size): Likewise. (grub_xnu_writetree_toheap_real): Likewise. (grub_xnu_find_key): Likewise. (grub_xnu_create_key): Likewise. (grub_xnu_create_value): Likewise. (grub_xnu_register_memory): Likewise. (grub_xnu_check_os_bundle_required): Likewise. (grub_xnu_scan_dir_for_kexts): Likewise. (grub_xnu_load_kext_from_dir): Likewise. * grub-core/normal/color.c (color_list): Likewise. * grub-core/normal/completion.c (current_word): Likewise. * grub-core/normal/menu_entry.c (insert_string): Likewise. * grub-core/term/serial.c (grub_serial_find): Likewise. * grub-core/term/tparm.c (grub_terminfo_tparm): Likewise. * include/grub/efiemu/efiemu.h (grub_efiemu_get_default_core_name): Likewise. * include/grub/i386/bsd.h (grub_bsd_add_meta): Likewise. (grub_freebsd_add_meta_module): Likewise. * include/grub/lib/arg.h (grub_arg_option): Likewise. * include/grub/net.h (grub_net_card_driver): Likewise. (grub_net_card): Likewise. (grub_net_app_protocol): Likewise. * include/grub/parttool.h (grub_parttool_argdesc): Likewise. * include/grub/serial.h (grub_serial_find): Likewise. * include/grub/tparm.h (grub_terminfo_tparm): Likewise. * include/grub/xnu.h (grub_xnu_create_key): Likewise. (grub_xnu_create_value): Likewise. (grub_xnu_find_key): Likewise. (grub_xnu_scan_dir_for_kexts): Likewise. (grub_xnu_load_kext_from_dir): Likewise. * include/grub/zfs/zio_checksum.h (zio_checksum_t): Moved from here ... * grub-core/fs/zfs/zfs.c (zio_checksum_t): ...here. * include/grub/zfs/zio_checksum.h (zio_checksum_info): Moved from here ... * grub-core/fs/zfs/zfs.c (zio_checksum_info): ... here. Added missing const.
2011-11-30 15:20:13 +00:00
static const char *color_list[16] =
2008-01-05 13:03:34 +00:00
{
"black",
"blue",
"green",
"cyan",
"red",
"magenta",
"brown",
"light-gray",
"dark-gray",
"light-blue",
"light-green",
"light-cyan",
"light-red",
"light-magenta",
"yellow",
"white"
};
static int
parse_color_name (grub_uint8_t *ret, char *name)
{
grub_uint8_t i;
for (i = 0; i < ARRAY_SIZE(color_list); i++)
2008-01-05 13:03:34 +00:00
if (! grub_strcmp (name, color_list[i]))
{
*ret = i;
return 0;
}
return -1;
}
2010-08-12 15:15:55 +00:00
int
grub_parse_color_name_pair (grub_uint8_t *color, const char *name)
2008-01-05 13:03:34 +00:00
{
2010-08-12 15:15:55 +00:00
int result = 1;
2008-01-05 13:03:34 +00:00
grub_uint8_t fg, bg;
char *fg_name, *bg_name;
/* nothing specified by user */
if (name == NULL)
2010-08-12 15:15:55 +00:00
return result;
2008-01-05 13:03:34 +00:00
fg_name = grub_strdup (name);
if (fg_name == NULL)
{
/* "out of memory" message was printed by grub_strdup() */
grub_wait_after_message ();
2010-08-12 15:15:55 +00:00
return result;
2008-01-05 13:03:34 +00:00
}
bg_name = grub_strchr (fg_name, '/');
if (bg_name == NULL)
{
grub_printf_ (N_("Warning: syntax error (missing slash) in `%s'\n"), fg_name);
2008-01-05 13:03:34 +00:00
grub_wait_after_message ();
goto free_and_return;
}
*(bg_name++) = '\0';
if (parse_color_name (&fg, fg_name) == -1)
{
grub_printf_ (N_("Warning: invalid foreground color `%s'\n"), fg_name);
2008-01-05 13:03:34 +00:00
grub_wait_after_message ();
goto free_and_return;
}
if (parse_color_name (&bg, bg_name) == -1)
{
grub_printf_ (N_("Warning: invalid background color `%s'\n"), bg_name);
2008-01-05 13:03:34 +00:00
grub_wait_after_message ();
goto free_and_return;
}
2010-08-12 15:15:55 +00:00
*color = (bg << 4) | fg;
result = 0;
2008-01-05 13:03:34 +00:00
free_and_return:
grub_free (fg_name);
2010-08-12 15:15:55 +00:00
return result;
2008-01-05 13:03:34 +00:00
}
2009-12-23 23:37:11 +00:00
static void
set_colors (void)
{
struct grub_term_output *term;
2009-12-24 16:51:43 +00:00
FOR_ACTIVE_TERM_OUTPUTS(term)
{
/* Propagates `normal' color to terminal current color. */
grub_term_setcolorstate (term, GRUB_TERM_COLOR_NORMAL);
}
2009-12-23 23:37:11 +00:00
}
2008-01-05 13:03:34 +00:00
/* Replace default `normal' colors with the ones specified by user (if any). */
char *
grub_env_write_color_normal (struct grub_env_var *var __attribute__ ((unused)),
const char *val)
2008-01-05 13:03:34 +00:00
{
if (grub_parse_color_name_pair (&grub_term_normal_color, val))
return NULL;
2008-01-05 13:03:34 +00:00
2009-12-23 23:37:11 +00:00
set_colors ();
2008-01-05 13:03:34 +00:00
return grub_strdup (val);
}
/* Replace default `highlight' colors with the ones specified by user (if any). */
char *
grub_env_write_color_highlight (struct grub_env_var *var __attribute__ ((unused)),
const char *val)
2008-01-05 13:03:34 +00:00
{
if (grub_parse_color_name_pair (&grub_term_highlight_color, val))
return NULL;
2008-01-05 13:03:34 +00:00
2009-12-23 23:37:11 +00:00
set_colors ();
2008-01-05 13:03:34 +00:00
return grub_strdup (val);
}