Пример #1
0
grub_script_function_t
grub_script_function_create (struct grub_script_arg *functionname_arg,
			     struct grub_script *cmd)
{
  grub_script_function_t func;
  grub_script_function_t *p;

  func = (grub_script_function_t) grub_malloc (sizeof (*func));
  if (! func)
    return 0;

  func->name = grub_strdup (functionname_arg->str);
  if (! func->name)
    {
      grub_free (func);
      return 0;
    }

  func->func = cmd;

  /* Keep the list sorted for simplicity.  */
  p = &grub_script_function_list;
  while (*p)
    {
      if (grub_strcmp ((*p)->name, func->name) >= 0)
	break;

      p = &((*p)->next);
    }

  /* If the function already exists, overwrite the old function.  */
  if (*p && grub_strcmp ((*p)->name, func->name) == 0)
    {
      grub_script_function_t q;

      q = *p;
      grub_script_free (q->func);
      q->func = cmd;
      grub_free (func);
      func = q;
    }
  else
    {
      func->next = *p;
      *p = func;
    }

  return func;
}
Пример #2
0
void
grub_script_function_remove (const char *name)
{
  grub_script_function_t *p, q;

  for (p = &grub_script_function_list, q = *p; q; p = &(q->next), q = q->next)
    if (grub_strcmp (name, q->name) == 0)
      {
        *p = q->next;
	grub_free (q->name);
	grub_script_free (q->func);
        grub_free (q);
        break;
      }
}
Пример #3
0
static void
free_menu (grub_menu_t menu)
{
  grub_menu_entry_t entry = menu->entry_list;

  while (entry)
    {
      grub_menu_entry_t next_entry = entry->next;

      grub_script_free (entry->commands);
      grub_free ((void *) entry->title);
      grub_free ((void *) entry->sourcecode);
      entry = next_entry;
    }

  grub_free (menu);
  grub_env_unset_data_slot ("menu");
}
Пример #4
0
static grub_err_t
grub_normal_parse_line (char *line, grub_reader_getline_t getline)
{
  struct grub_script *parsed_script;

  /* Parse the script.  */
  parsed_script = grub_script_parse (line, getline);

  if (parsed_script)
    {
      /* Execute the command(s).  */
      grub_script_execute (parsed_script);

      /* The parsed script was executed, throw it away.  */
      grub_script_free (parsed_script);
    }

  return grub_errno;
}