1
/* extcmd.c - support extended 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/>.
21
#include <grub/list.h>
22
#include <grub/misc.h>
23
#include <grub/extcmd.h>
24
#include <grub/script_sh.h>
27
grub_extcmd_dispatcher (struct grub_command *cmd, int argc, char **args,
28
struct grub_script *script)
32
struct grub_arg_list *state;
33
struct grub_extcmd_context context;
35
grub_extcmd_t ext = cmd->data;
39
context.script = script;
43
ret = (ext->func) (&context, argc, args);
47
state = grub_arg_list_alloc (ext, argc, args);
48
if (grub_arg_parse (ext, argc, args, state, &new_args, &new_argc))
50
context.state = state;
51
ret = (ext->func) (&context, new_argc, new_args);
62
grub_extcmd_dispatch (struct grub_command *cmd, int argc, char **args)
64
return grub_extcmd_dispatcher (cmd, argc, args, 0);
68
grub_register_extcmd_prio (const char *name, grub_extcmd_func_t func,
69
grub_command_flags_t flags, const char *summary,
70
const char *description,
71
const struct grub_arg_option *parser,
77
ext = (grub_extcmd_t) grub_malloc (sizeof (*ext));
81
cmd = grub_register_command_prio (name, grub_extcmd_dispatch,
82
summary, description, prio);
89
cmd->flags = (flags | GRUB_COMMAND_FLAG_EXTCMD);
94
ext->options = parser;
101
grub_register_extcmd (const char *name, grub_extcmd_func_t func,
102
grub_command_flags_t flags, const char *summary,
103
const char *description,
104
const struct grub_arg_option *parser)
106
return grub_register_extcmd_prio (name, func, flags,
107
summary, description, parser, 1);
111
grub_unregister_extcmd (grub_extcmd_t ext)
113
grub_unregister_command (ext->cmd);