Beispiel #1
0
int
grub_parse_color_name_pair (grub_uint8_t *color, const char *name)
{
  int result = 1;
  grub_uint8_t fg, bg;
  char *fg_name, *bg_name;

  /* nothing specified by user */
  if (name == NULL)
    return result;

  fg_name = grub_strdup (name);
  if (fg_name == NULL)
    {
      /* "out of memory" message was printed by grub_strdup() */
      grub_wait_after_message ();
      return result;
    }

  bg_name = grub_strchr (fg_name, '/');
  if (bg_name == NULL)
    {
      grub_printf_ (N_("Warning: syntax error (missing slash) in `%s'\n"), fg_name);
      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);
      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);
      grub_wait_after_message ();
      goto free_and_return;
    }

  *color = (bg << 4) | fg;
  result = 0;

free_and_return:
  grub_free (fg_name);
  return result;
}
Beispiel #2
0
static grub_err_t
grub_cmd_time (grub_command_t ctxt __attribute__ ((unused)),
	       int argc, char **args)
{
  grub_command_t cmd;
  grub_uint32_t start;
  grub_uint32_t end;

  if (argc == 0)
    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("no command is specified"));

  cmd = grub_command_find (args[0]);

  if (!cmd)
    return grub_error (GRUB_ERR_UNKNOWN_COMMAND, N_("can't find command `%s'"),
		       args[0]);

  start = grub_get_time_ms ();
  (cmd->func) (cmd, argc - 1, &args[1]);
  end = grub_get_time_ms ();

  grub_printf_ (N_("Elapsed time: %d.%03d seconds \n"), (end - start) / 1000,
		(end - start) % 1000);

  return grub_errno;
}
Beispiel #3
0
/* Wait until the user pushes any key so that the user
   can see what happened.  */
void
grub_wait_after_message (void)
{
  grub_putchar ('\n');
  grub_printf_ (N_("Press any key to continue..."));
  (void) grub_getkey ();
  grub_putchar ('\n');
}
grub_err_t
grub_rescue_parse_line (char *line,
			grub_reader_getline_t getline, void *getline_data)
{
  char *name;
  int n;
  grub_command_t cmd;
  char **args;

  if (grub_parser_split_cmdline (line, getline, getline_data, &n, &args)
      || n < 0)
    return grub_errno;

  if (n == 0)
    return GRUB_ERR_NONE;

  /* In case of an assignment set the environment accordingly
     instead of calling a function.  */
  if (n == 1)
    {
      char *val = grub_strchr (args[0], '=');

      if (val)
	{
	  val[0] = 0;
	  grub_env_set (args[0], val + 1);
	  val[0] = '=';
	  goto quit;
	}
    }

  /* Get the command name.  */
  name = args[0];

  /* If nothing is specified, restart.  */
  if (*name == '\0')
    goto quit;

  cmd = grub_command_find (name);
  if (cmd)
    {
      (cmd->func) (cmd, n - 1, &args[1]);
    }
  else
    {
      grub_printf_ (N_("Unknown command `%s'.\n"), name);
      if (grub_command_find ("help"))
	grub_printf ("Try `help' for usage\n");
    }

 quit:
  /* Arguments are returned in single memory chunk separated by zeroes */
  grub_free (args[0]);
  grub_free (args);

  return grub_errno;
}
Beispiel #5
0
/* Wait until the user pushes any key so that the user
   can see what happened.  */
void
grub_wait_after_message (void)
{
  grub_uint64_t endtime;
  grub_xputs ("\n");
  grub_printf_ (N_("Press any key to continue..."));
  grub_refresh ();

  endtime = grub_get_time_ms () + 10000;

  while (grub_get_time_ms () < endtime
	 && grub_getkey_noblock () == GRUB_TERM_NO_KEY);

  grub_xputs ("\n");
}
Beispiel #6
0
/* Wait until the user pushes any key so that the user
   can see what happened.  */
void
grub_wait_after_message (void)
{
  grub_uint64_t endtime;
  grub_xputs ("\n");
  grub_printf_ (N_("Press any key to continue..."));
  grub_refresh ();

  endtime = grub_get_time_ms () + 10000;

  while (grub_get_time_ms () < endtime)
    if (grub_checkkey () >= 0)
      {
	grub_getkey ();
	break;
      }

  grub_xputs ("\n");
}
Beispiel #7
0
/* Print the information on the device NAME.  */
grub_err_t
grub_normal_print_device_info (const char *name)
{
    grub_device_t dev;
    char *p;

    p = grub_strchr (name, ',');
    if (p)
    {
        grub_xputs ("\t");
        grub_printf_ (N_("Partition %s:"), name);
        grub_xputs (" ");
    }
    else
    {
        grub_printf_ (N_("Device %s:"), name);
        grub_xputs (" ");
    }

    dev = grub_device_open (name);
    if (! dev)
        grub_printf ("%s", _("Filesystem cannot be accessed"));
    else if (dev->disk)
    {
        grub_fs_t fs;

        fs = grub_fs_probe (dev);
        /* Ignore all errors.  */
        grub_errno = 0;

        if (fs)
        {
            grub_printf_ (N_("Filesystem type %s"), fs->name);
            if (fs->label)
            {
                char *label;
                (fs->label) (dev, &label);
                if (grub_errno == GRUB_ERR_NONE)
                {
                    if (label && grub_strlen (label))
                    {
                        grub_xputs (" ");
                        grub_printf_ (N_("- Label \"%s\""), label);
                    }
                    grub_free (label);
                }
                grub_errno = GRUB_ERR_NONE;
            }
            if (fs->mtime)
            {
                grub_int32_t tm;
                struct grub_datetime datetime;
                (fs->mtime) (dev, &tm);
                if (grub_errno == GRUB_ERR_NONE)
                {
                    grub_unixtime2datetime (tm, &datetime);
                    grub_xputs (" ");
                    grub_printf_ (N_("- Last modification time %d-%02d-%02d "
                                     "%02d:%02d:%02d %s"),
                                  datetime.year, datetime.month, datetime.day,
                                  datetime.hour, datetime.minute, datetime.second,
                                  grub_get_weekday_name (&datetime));

                }
                grub_errno = GRUB_ERR_NONE;
            }
            if (fs->uuid)
            {
                char *uuid;
                (fs->uuid) (dev, &uuid);
                if (grub_errno == GRUB_ERR_NONE)
                {
                    if (uuid && grub_strlen (uuid))
                        grub_printf (", UUID %s", uuid);
                    grub_free (uuid);
                }
                grub_errno = GRUB_ERR_NONE;
            }
        }
        else if (! dev->disk->has_partitions || dev->disk->partition)
            grub_printf ("%s", _("Unknown filesystem"));
        else
            grub_printf ("%s", _("Partition table"));

        grub_device_close (dev);
    }

    grub_xputs ("\n");
    return grub_errno;
}