1
/* dyncmd.c - support dynamic command */
3
* GRUB -- GRand Unified Bootloader
4
* Copyright (C) 2009 Free Software Foundation, Inc.
6
* GRUB 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 3 of the License, or
9
* (at your option) any later version.
11
* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
23
#include <grub/misc.h>
24
#include <grub/command.h>
25
#include <grub/normal.h>
26
#include <grub/extcmd.h>
27
#include <grub/script_sh.h>
28
#include <grub/i18n.h>
31
grub_dyncmd_dispatcher (struct grub_extcmd_context *ctxt,
32
int argc, char **args)
37
grub_extcmd_t extcmd = ctxt->extcmd;
38
grub_command_t cmd = extcmd->cmd;
40
modname = extcmd->data;
41
mod = grub_dl_load (modname);
49
name = (char *) cmd->name;
50
grub_unregister_extcmd (extcmd);
52
cmd = grub_command_find (name);
55
if (cmd->flags & GRUB_COMMAND_FLAG_BLOCKS &&
56
cmd->flags & GRUB_COMMAND_FLAG_EXTCMD)
57
ret = grub_extcmd_dispatcher (cmd, argc, args, ctxt->script);
59
ret = (cmd->func) (cmd, argc, args);
72
/* Read the file command.lst for auto-loading. */
74
read_command_list (const char *prefix)
80
filename = grub_xasprintf ("%s/command.lst", prefix);
85
file = grub_file_open (filename);
89
grub_command_t ptr, last = 0, next;
91
/* Override previous commands.lst. */
92
for (ptr = grub_command_list; ptr; ptr = next)
95
if (ptr->flags & GRUB_COMMAND_FLAG_DYNCMD)
98
last->next = ptr->next;
100
grub_command_list = ptr->next;
102
grub_free (ptr->data); /* extcmd struct */
108
for (;; grub_free (buf))
110
char *p, *name, *modname;
114
buf = grub_file_getline (file);
126
if (! grub_isgraph (name[0]))
129
p = grub_strchr (name, ':');
137
if (! grub_isgraph (*p))
143
name = grub_strdup (name);
147
modname = grub_strdup (p);
154
cmd = grub_register_extcmd_prio (name,
155
grub_dyncmd_dispatcher,
156
GRUB_COMMAND_FLAG_BLOCKS
157
| GRUB_COMMAND_FLAG_EXTCMD
158
| GRUB_COMMAND_FLAG_DYNCMD,
159
0, N_("not loaded"), 0,
169
/* Update the active flag. */
170
grub_command_find (name);
173
grub_file_close (file);
176
grub_free (filename);
181
grub_errno = GRUB_ERR_NONE;