2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2005,2007,2009 Free Software Foundation, Inc.
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.
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.
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/>.
19 #include <grub/misc.h>
20 #include <grub/script_sh.h>
21 #include <grub/parser.h>
24 static grub_script_function_t grub_script_function_list
;
26 grub_script_function_t
27 grub_script_function_create (struct grub_script_arg
*functionname_arg
,
28 struct grub_script
*cmd
)
30 grub_script_function_t func
;
31 grub_script_function_t
*p
;
33 func
= (grub_script_function_t
) grub_malloc (sizeof (*func
));
37 func
->name
= grub_script_execute_argument_to_string (functionname_arg
);
46 /* Keep the list sorted for simplicity. */
47 p
= &grub_script_function_list
;
50 if (grub_strcmp ((*p
)->name
, func
->name
) >= 0)
56 /* If the function already exists, overwrite the old function. */
57 if (*p
&& grub_strcmp ((*p
)->name
, func
->name
) == 0)
59 grub_script_function_t q
;
62 grub_script_free (q
->func
);
77 grub_script_function_remove (const char *name
)
79 grub_script_function_t
*p
, q
;
81 for (p
= &grub_script_function_list
, q
= *p
; q
; p
= &(q
->next
), q
= q
->next
)
82 if (grub_strcmp (name
, q
->name
) == 0)
86 grub_script_free (q
->func
);
92 grub_script_function_t
93 grub_script_function_find (char *functionname
)
95 grub_script_function_t func
;
97 for (func
= grub_script_function_list
; func
; func
= func
->next
)
98 if (grub_strcmp (functionname
, func
->name
) == 0)
102 grub_error (GRUB_ERR_UNKNOWN_COMMAND
, "unknown command `%.20s'", functionname
);
108 grub_script_function_iterate (int (*iterate
) (grub_script_function_t
))
110 grub_script_function_t func
;
112 for (func
= grub_script_function_list
; func
; func
= func
->next
)
120 grub_script_function_call (grub_script_function_t func
,
121 int argc
__attribute__((unused
)),
122 char **args
__attribute__((unused
)))
124 /* XXX: Arguments are not supported yet. */
125 return grub_script_execute (func
->func
);