3
* GRUB -- GRand Unified Bootloader
4
* Copyright (C) 2005 Free Software Foundation, Inc.
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
#include <grub/misc.h>
22
#include <grub/script.h>
23
#include <grub/parser.h>
26
static grub_script_function_t grub_script_function_list;
28
grub_script_function_t
29
grub_script_function_create (char *functionname, struct grub_script *cmd)
31
grub_script_function_t func;
32
grub_script_function_t *p;
34
func = (grub_script_function_t) grub_malloc (sizeof (*func));
38
func->name = grub_strdup (functionname);
47
/* Keep the list sorted for simplicity. */
48
p = &grub_script_function_list;
51
if (grub_strcmp ((*p)->name, functionname) >= 0)
57
/* If the function already exists, overwrite the old function. */
58
if (*p && grub_strcmp ((*p)->name, functionname) == 0)
60
grub_script_function_t q;
63
grub_script_free (q->func);
78
grub_script_function_remove (const char *name)
80
grub_script_function_t *p, q;
82
for (p = &grub_script_function_list, q = *p; q; p = &(q->next), q = q->next)
83
if (grub_strcmp (name, q->name) == 0)
87
grub_script_free (q->func);
93
grub_script_function_t
94
grub_script_function_find (char *functionname)
96
grub_script_function_t func;
98
for (func = grub_script_function_list; func; func = func->next)
99
if (grub_strcmp (functionname, func->name) == 0)
103
grub_error (GRUB_ERR_UNKNOWN_COMMAND, "unknown command `%s'", functionname);
109
grub_script_function_iterate (int (*iterate) (grub_script_function_t))
111
grub_script_function_t func;
113
for (func = grub_script_function_list; func; func = func->next)
121
grub_script_function_call (grub_script_function_t func,
122
int argc __attribute__((unused)),
123
char **args __attribute__((unused)))
125
/* XXX: Arguments are not supported yet. */
126
return grub_script_execute (func->func);