Пример #1
0
/* Extend the argument arg with a variable or string of text.  If ARG
   is zero a new list is created.  */
struct grub_script_arg *
grub_script_arg_add (struct grub_parser_param *state,
		     struct grub_script_arg *arg, grub_script_arg_type_t type,
		     char *str)
{
  struct grub_script_arg *argpart;
  struct grub_script_arg *ll;
  int len;

  argpart =
    (struct grub_script_arg *) grub_script_malloc (state, sizeof (*arg));
  if (!argpart)
    return arg;

  argpart->type = type;
  argpart->script = 0;

  len = grub_strlen (str) + 1;
  argpart->str = grub_script_malloc (state, len);
  if (!argpart->str)
    return arg; /* argpart is freed later, during grub_script_free.  */

  grub_memcpy (argpart->str, str, len);
  argpart->next = 0;

  if (!arg)
    return argpart;

  for (ll = arg; ll->next; ll = ll->next);
  ll->next = argpart;

  return arg;
}
Пример #2
0
/* Create a chain of commands.  LAST contains the command that should
   be added at the end of LIST's list.  If LIST is zero, a new list
   will be created.  */
struct grub_script_cmd *
grub_script_append_cmd (struct grub_parser_param *state,
			struct grub_script_cmd *list,
			struct grub_script_cmd *last)
{
  struct grub_script_cmd *ptr;

  grub_dprintf ("scripting", "append command\n");

  if (! last)
    return list;

  if (! list)
    {
      list = grub_script_malloc (state, sizeof (*list));
      if (! list)
	return 0;

      list->exec = grub_script_execute_cmdlist;
      list->next = last;
    }
  else
    {
      ptr = list;
      while (ptr->next)
	ptr = ptr->next;

      ptr->next = last;
    }

  return list;
}
Пример #3
0
/* Add the argument ARG to the end of the argument list LIST.  If LIST
   is zero, a new list will be created.  */
struct grub_script_arglist *
grub_script_add_arglist (struct grub_parser_param *state,
			 struct grub_script_arglist *list,
			 struct grub_script_arg *arg)
{
  struct grub_script_arglist *link;
  struct grub_script_arglist *ll;

  grub_dprintf ("scripting", "arglist\n");

  link =
    (struct grub_script_arglist *) grub_script_malloc (state, sizeof (*link));
  if (!link)
    return list;

  link->next = 0;
  link->arg = arg;
  link->argcount = 0;

  if (!list)
    {
      link->argcount++;
      return link;
    }

  list->argcount++;

  /* Look up the last link in the chain.  */
  for (ll = list; ll->next; ll = ll->next);
  ll->next = link;

  return list;
}
Пример #4
0
/* Create a command that describes a single command line.  CMDLINE
   contains the name of the command that should be executed.  ARGLIST
   holds all arguments for this command.  */
struct grub_script_cmd *
grub_script_create_cmdline (struct grub_parser_param *state,
			    struct grub_script_arglist *arglist)
{
  struct grub_script_cmdline *cmd;

  grub_dprintf ("scripting", "cmdline\n");

  cmd = grub_script_malloc (state, sizeof (*cmd));
  if (!cmd)
    return 0;

  cmd->cmd.exec = grub_script_execute_cmdline;
  cmd->cmd.next = 0;
  cmd->arglist = arglist;

  return (struct grub_script_cmd *) cmd;
}
Пример #5
0
/* Create a command that adds a menu entry to the menu.  Title is an
   argument that is parsed to generate a string that can be used as
   the title.  The sourcecode for this entry is passed in SOURCECODE.
   The options for this entry are passed in OPTIONS.  */
struct grub_script_cmd *
grub_script_create_cmdmenu (struct grub_parser_param *state,
			    struct grub_script_arglist *arglist,
			    char *sourcecode, int options)
{
  struct grub_script_cmd_menuentry *cmd;

  cmd = grub_script_malloc (state, sizeof (*cmd));
  if (!cmd)
    return 0;

  cmd->cmd.exec = grub_script_execute_menuentry;
  cmd->cmd.next = 0;
  cmd->sourcecode = sourcecode;
  cmd->arglist = arglist;
  cmd->options = options;

  return (struct grub_script_cmd *) cmd;
}
Пример #6
0
/* Create a "while" or "until" command.  */
struct grub_script_cmd *
grub_script_create_cmdwhile (struct grub_parser_param *state,
			     struct grub_script_cmd *cond,
			     struct grub_script_cmd *list,
			     int is_an_until_loop)
{
  struct grub_script_cmdwhile *cmd;

  cmd = grub_script_malloc (state, sizeof (*cmd));
  if (! cmd)
    return 0;

  cmd->cmd.exec = grub_script_execute_cmdwhile;
  cmd->cmd.next = 0;
  cmd->cond = cond;
  cmd->list = list;
  cmd->until = is_an_until_loop;

  return (struct grub_script_cmd *) cmd;
}
Пример #7
0
/* Create a command that functions as a for statement.  */
struct grub_script_cmd *
grub_script_create_cmdfor (struct grub_parser_param *state,
			   struct grub_script_arg *name,
			   struct grub_script_arglist *words,
			   struct grub_script_cmd *list)
{
  struct grub_script_cmdfor *cmd;

  grub_dprintf ("scripting", "cmdfor\n");

  cmd = grub_script_malloc (state, sizeof (*cmd));
  if (! cmd)
    return 0;

  cmd->cmd.exec = grub_script_execute_cmdfor;
  cmd->cmd.next = 0;
  cmd->name = name;
  cmd->words = words;
  cmd->list = list;

  return (struct grub_script_cmd *) cmd;
}
Пример #8
0
/* Create a command that functions as an if statement.  If BOOL is
   evaluated to true (the value is returned in envvar '?'), the
   interpreter will run the command TRUE, otherwise the interpreter
   runs the command FALSE.  */
struct grub_script_cmd *
grub_script_create_cmdif (struct grub_parser_param *state,
			  struct grub_script_cmd *exec_to_evaluate,
			  struct grub_script_cmd *exec_on_true,
			  struct grub_script_cmd *exec_on_false)
{
  struct grub_script_cmdif *cmd;

  grub_dprintf ("scripting", "cmdif\n");

  cmd = grub_script_malloc (state, sizeof (*cmd));
  if (!cmd)
    return 0;

  cmd->cmd.exec = grub_script_execute_cmdif;
  cmd->cmd.next = 0;
  cmd->exec_to_evaluate = exec_to_evaluate;
  cmd->exec_on_true = exec_on_true;
  cmd->exec_on_false = exec_on_false;

  return (struct grub_script_cmd *) cmd;
}
Пример #9
0
/* Create a block of commands.  CMD contains the command that should
   be added at the end of CMDBLOCK's list.  If CMDBLOCK is zero, a new
   cmdblock will be created.  */
struct grub_script_cmd *
grub_script_add_cmd (struct grub_parser_param *state,
		     struct grub_script_cmdblock *cmdblock,
		     struct grub_script_cmd *cmd)
{
  struct grub_script_cmd *ptr;

  grub_dprintf ("scripting", "cmdblock\n");

  if (!cmd)
    return (struct grub_script_cmd *) cmdblock;

  if (!cmdblock)
    {
      cmdblock = grub_script_malloc (state, sizeof (*cmdblock));
      if (!cmdblock)
	return 0;

      cmdblock->cmd.exec = grub_script_execute_cmdblock;
      cmdblock->cmd.next = 0;
      cmdblock->cmdlist = cmd;
      cmd->next = 0;
    }
  else
    {
      if (!cmdblock->cmdlist)
	cmdblock->cmdlist = cmd;
      else
	{
	  ptr = cmdblock->cmdlist;
	  while (ptr->next)
	    ptr = ptr->next;
	  ptr->next = cmd;
	}
    }

  return (struct grub_script_cmd *) cmdblock;
}