2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 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 #ifndef GRUB_COMMAND_HEADER
20 #define GRUB_COMMAND_HEADER 1
22 #include <grub/symbol.h>
24 #include <grub/list.h>
26 typedef enum grub_command_flags
28 /* This is an extended command. */
29 GRUB_COMMAND_FLAG_EXTCMD
= 0x10,
30 /* This is an dynamic command. */
31 GRUB_COMMAND_FLAG_DYNCMD
= 0x20,
32 /* This command accepts block arguments. */
33 GRUB_COMMAND_FLAG_BLOCKS
= 0x40,
34 /* This command accepts unknown arguments as direct parameters. */
35 GRUB_COMMAND_ACCEPT_DASH
= 0x80,
36 /* This command accepts only options preceding direct arguments. */
37 GRUB_COMMAND_OPTIONS_AT_START
= 0x100,
38 /* Can be executed in an entries extractor. */
39 GRUB_COMMAND_FLAG_EXTRACTOR
= 0x200
40 } grub_command_flags_t
;
44 typedef grub_err_t (*grub_command_func_t
) (struct grub_command
*cmd
,
45 int argc
, char **argv
);
47 #define GRUB_COMMAND_PRIO_MASK 0xff
48 #define GRUB_COMMAND_FLAG_ACTIVE 0x100
50 /* The command description. */
53 /* The next element. */
54 struct grub_command
*next
;
55 struct grub_command
**prev
;
63 /* The callback function. */
64 grub_command_func_t func
;
67 grub_command_flags_t flags
;
69 /* The summary of the command usage. */
72 /* The description of the command. */
73 const char *description
;
78 typedef struct grub_command
*grub_command_t
;
80 extern grub_command_t
EXPORT_VAR(grub_command_list
);
83 EXPORT_FUNC(grub_register_command_prio
) (const char *name
,
84 grub_command_func_t func
,
86 const char *description
,
88 void EXPORT_FUNC(grub_unregister_command
) (grub_command_t cmd
);
90 static inline grub_command_t
91 grub_register_command (const char *name
,
92 grub_command_func_t func
,
94 const char *description
)
96 return grub_register_command_prio (name
, func
, summary
, description
, 0);
99 static inline grub_command_t
100 grub_register_command_p1 (const char *name
,
101 grub_command_func_t func
,
103 const char *description
)
105 return grub_register_command_prio (name
, func
, summary
, description
, 1);
108 static inline grub_command_t
109 grub_command_find (const char *name
)
111 return grub_named_list_find (GRUB_AS_NAMED_LIST (grub_command_list
), name
);
114 static inline grub_err_t
115 grub_command_execute (const char *name
, int argc
, char **argv
)
119 cmd
= grub_command_find (name
);
120 return (cmd
) ? cmd
->func (cmd
, argc
, argv
) : GRUB_ERR_FILE_NOT_FOUND
;
123 #define FOR_COMMANDS(var) FOR_LIST_ELEMENTS((var), grub_command_list)
125 void grub_register_core_commands (void);
127 #endif /* ! GRUB_COMMAND_HEADER */