2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2005,2007 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.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 (char *functionname
, struct grub_script
*cmd
)
29 grub_script_function_t func
;
30 grub_script_function_t
*p
;
32 func
= (grub_script_function_t
) grub_malloc (sizeof (*func
));
36 func
->name
= grub_strdup (functionname
);
45 /* Keep the list sorted for simplicity. */
46 p
= &grub_script_function_list
;
49 if (grub_strcmp ((*p
)->name
, functionname
) >= 0)
55 /* If the function already exists, overwrite the old function. */
56 if (*p
&& grub_strcmp ((*p
)->name
, functionname
) == 0)
58 grub_script_function_t q
;
61 grub_script_free (q
->func
);
76 grub_script_function_remove (const char *name
)
78 grub_script_function_t
*p
, q
;
80 for (p
= &grub_script_function_list
, q
= *p
; q
; p
= &(q
->next
), q
= q
->next
)
81 if (grub_strcmp (name
, q
->name
) == 0)
85 grub_script_free (q
->func
);
91 grub_script_function_t
92 grub_script_function_find (char *functionname
)
94 grub_script_function_t func
;
96 for (func
= grub_script_function_list
; func
; func
= func
->next
)
97 if (grub_strcmp (functionname
, func
->name
) == 0)
101 grub_error (GRUB_ERR_UNKNOWN_COMMAND
, "unknown command `%s'", functionname
);
107 grub_script_function_iterate (int (*iterate
) (grub_script_function_t
))
109 grub_script_function_t func
;
111 for (func
= grub_script_function_list
; func
; func
= func
->next
)
119 grub_script_function_call (grub_script_function_t func
,
120 int argc
__attribute__((unused
)),
121 char **args
__attribute__((unused
)))
123 /* XXX: Arguments are not supported yet. */
124 return grub_script_execute (func
->func
);