~ubuntu-branches/ubuntu/trusty/grub2/trusty-updates

« back to all changes in this revision

Viewing changes to script/function.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2011-02-08 11:39:26 UTC
  • mfrom: (17.6.26 experimental)
  • mto: (17.6.27 experimental)
  • mto: This revision was merged to the branch mainline in revision 104.
  • Revision ID: james.westby@ubuntu.com-20110208113926-clfs90haboyk9zip
Tags: 1.99~rc1-2
* Merge 1.98+20100804-13 and 1.98+20100804-14, updating translations:
  - Kazakh (Baurzhan Muftakhidinov / Timur Birsh).
* mkconfig_skip_dmcrypt.patch: Refer to GRUB_PRELOAD_MODULES rather than
  suggesting people write a /etc/grub.d/01_modules script (thanks, Jordan
  Uggla).
* Handle empty dir passed to grub_find_root_device_from_mountinfo; fixes
  grub-mkrelpath on btrfs subvolumes (LP: #712029).
* Add rootflags=subvol=<name> if / is on a btrfs subvolume (LP: #712029).
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  GRUB  --  GRand Unified Bootloader
3
 
 *  Copyright (C) 2005,2007,2009,2010  Free Software Foundation, Inc.
4
 
 *
5
 
 *  GRUB is free software: you can redistribute it and/or modify
6
 
 *  it under the terms of the GNU General Public License as published by
7
 
 *  the Free Software Foundation, either version 3 of the License, or
8
 
 *  (at your option) any later version.
9
 
 *
10
 
 *  GRUB is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
17
 
 */
18
 
 
19
 
#include <grub/misc.h>
20
 
#include <grub/script_sh.h>
21
 
#include <grub/parser.h>
22
 
#include <grub/mm.h>
23
 
 
24
 
grub_script_function_t grub_script_function_list;
25
 
 
26
 
grub_script_function_t
27
 
grub_script_function_create (struct grub_script_arg *functionname_arg,
28
 
                             struct grub_script *cmd)
29
 
{
30
 
  grub_script_function_t func;
31
 
  grub_script_function_t *p;
32
 
 
33
 
  func = (grub_script_function_t) grub_malloc (sizeof (*func));
34
 
  if (! func)
35
 
    return 0;
36
 
 
37
 
  func->name = grub_strdup (functionname_arg->str);
38
 
  if (! func->name)
39
 
    {
40
 
      grub_free (func);
41
 
      return 0;
42
 
    }
43
 
 
44
 
  func->func = cmd;
45
 
 
46
 
  /* Keep the list sorted for simplicity.  */
47
 
  p = &grub_script_function_list;
48
 
  while (*p)
49
 
    {
50
 
      if (grub_strcmp ((*p)->name, func->name) >= 0)
51
 
        break;
52
 
 
53
 
      p = &((*p)->next);
54
 
    }
55
 
 
56
 
  /* If the function already exists, overwrite the old function.  */
57
 
  if (*p && grub_strcmp ((*p)->name, func->name) == 0)
58
 
    {
59
 
      grub_script_function_t q;
60
 
 
61
 
      q = *p;
62
 
      grub_script_free (q->func);
63
 
      q->func = cmd;
64
 
      grub_free (func);
65
 
      func = q;
66
 
    }
67
 
  else
68
 
    {
69
 
      func->next = *p;
70
 
      *p = func;
71
 
    }
72
 
 
73
 
  return func;
74
 
}
75
 
 
76
 
void
77
 
grub_script_function_remove (const char *name)
78
 
{
79
 
  grub_script_function_t *p, q;
80
 
 
81
 
  for (p = &grub_script_function_list, q = *p; q; p = &(q->next), q = q->next)
82
 
    if (grub_strcmp (name, q->name) == 0)
83
 
      {
84
 
        *p = q->next;
85
 
        grub_free (q->name);
86
 
        grub_script_free (q->func);
87
 
        grub_free (q);
88
 
        break;
89
 
      }
90
 
}
91
 
 
92
 
grub_script_function_t
93
 
grub_script_function_find (char *functionname)
94
 
{
95
 
  grub_script_function_t func;
96
 
 
97
 
  for (func = grub_script_function_list; func; func = func->next)
98
 
    if (grub_strcmp (functionname, func->name) == 0)
99
 
      break;
100
 
 
101
 
  if (! func)
102
 
    grub_error (GRUB_ERR_UNKNOWN_COMMAND, "unknown command `%.20s'", functionname);
103
 
 
104
 
  return func;
105
 
}
106
 
 
107
 
int
108
 
grub_script_function_call (grub_script_function_t func,
109
 
                           int argc __attribute__((unused)),
110
 
                           char **args __attribute__((unused)))
111
 
{
112
 
  /* XXX: Arguments are not supported yet.  */
113
 
  return grub_script_execute (func->func);
114
 
}