Fix cross compilation (e.g. on Darwin). Following changes to make.tmpl,
[AROS.git] / arch / all-pc / boot / grub2-aros / include / grub / command.h
blobeee4e847ee456ec1a225f9bdb9957e00083da7ea
1 /*
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>
23 #include <grub/err.h>
24 #include <grub/list.h>
25 #include <grub/misc.h>
27 typedef enum grub_command_flags
29 /* This is an extended command. */
30 GRUB_COMMAND_FLAG_EXTCMD = 0x10,
31 /* This is an dynamic command. */
32 GRUB_COMMAND_FLAG_DYNCMD = 0x20,
33 /* This command accepts block arguments. */
34 GRUB_COMMAND_FLAG_BLOCKS = 0x40,
35 /* This command accepts unknown arguments as direct parameters. */
36 GRUB_COMMAND_ACCEPT_DASH = 0x80,
37 /* This command accepts only options preceding direct arguments. */
38 GRUB_COMMAND_OPTIONS_AT_START = 0x100,
39 /* Can be executed in an entries extractor. */
40 GRUB_COMMAND_FLAG_EXTRACTOR = 0x200
41 } grub_command_flags_t;
43 struct grub_command;
45 typedef grub_err_t (*grub_command_func_t) (struct grub_command *cmd,
46 int argc, char **argv);
48 #define GRUB_COMMAND_PRIO_MASK 0xff
49 #define GRUB_COMMAND_FLAG_ACTIVE 0x100
51 /* The command description. */
52 struct grub_command
54 /* The next element. */
55 struct grub_command *next;
56 struct grub_command **prev;
58 /* The name. */
59 const char *name;
61 /* The priority. */
62 int prio;
64 /* The callback function. */
65 grub_command_func_t func;
67 /* The flags. */
68 grub_command_flags_t flags;
70 /* The summary of the command usage. */
71 const char *summary;
73 /* The description of the command. */
74 const char *description;
76 /* Arbitrary data. */
77 void *data;
79 typedef struct grub_command *grub_command_t;
81 extern grub_command_t EXPORT_VAR(grub_command_list);
83 grub_command_t
84 EXPORT_FUNC(grub_register_command_prio) (const char *name,
85 grub_command_func_t func,
86 const char *summary,
87 const char *description,
88 int prio);
89 void EXPORT_FUNC(grub_unregister_command) (grub_command_t cmd);
91 static inline grub_command_t
92 grub_register_command (const char *name,
93 grub_command_func_t func,
94 const char *summary,
95 const char *description)
97 return grub_register_command_prio (name, func, summary, description, 0);
100 static inline grub_command_t
101 grub_register_command_p1 (const char *name,
102 grub_command_func_t func,
103 const char *summary,
104 const char *description)
106 return grub_register_command_prio (name, func, summary, description, 1);
109 static inline grub_command_t
110 grub_command_find (const char *name)
112 return grub_named_list_find (GRUB_AS_NAMED_LIST (grub_command_list), name);
115 static inline grub_err_t
116 grub_command_execute (const char *name, int argc, char **argv)
118 grub_command_t cmd;
120 cmd = grub_command_find (name);
121 return (cmd) ? cmd->func (cmd, argc, argv) : GRUB_ERR_FILE_NOT_FOUND;
124 #define FOR_COMMANDS(var) FOR_LIST_ELEMENTS((var), grub_command_list)
125 #define FOR_COMMANDS_SAFE(var, next) FOR_LIST_ELEMENTS_SAFE((var), (next), grub_command_list)
127 void grub_register_core_commands (void);
129 #endif /* ! GRUB_COMMAND_HEADER */