1 /* handler.c - commands to list or select handlers */
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/>.
22 #include <grub/misc.h>
23 #include <grub/term.h>
24 #include <grub/handler.h>
25 #include <grub/command.h>
28 grub_cmd_handler (struct grub_command
*cmd
,
29 int argc
, char **args
)
33 grub_handler_class_t head
;
35 auto int list_item (grub_named_list_t item
);
36 int list_item (grub_named_list_t item
)
38 if (item
== curr_item
)
41 grub_printf ("%s\n", item
->name
);
46 class_name
= (grub_strcmp (cmd
->name
, "handler")) ? (char *) cmd
->name
: 0;
48 head
= grub_handler_class_list
;
49 if ((argc
== 0) && (class_name
== 0))
51 grub_list_iterate (GRUB_AS_LIST (head
), (grub_list_hook_t
) list_item
);
55 grub_handler_class_t
class;
64 class = grub_named_list_find (GRUB_AS_NAMED_LIST (head
), class_name
);
66 return grub_error (GRUB_ERR_FILE_NOT_FOUND
, "class not found");
70 curr_item
= class->cur_handler
;
71 grub_list_iterate (GRUB_AS_LIST (class->handler_list
),
72 (grub_list_hook_t
) list_item
);
76 grub_handler_t handler
;
79 grub_named_list_find (GRUB_AS_NAMED_LIST (class->handler_list
),
83 return grub_error (GRUB_ERR_FILE_NOT_FOUND
, "handler not found");
85 grub_handler_set_current (class, handler
);
92 static grub_command_t cmd_handler
, cmd_terminal_input
, cmd_terminal_output
;
94 GRUB_MOD_INIT(handler
)
97 grub_register_command ("handler", grub_cmd_handler
,
98 "handler [class [handler]]",
99 "List or select a handler");
101 grub_register_command ("terminal_input", grub_cmd_handler
,
102 "terminal_input [handler]",
103 "List or select a handler");
104 cmd_terminal_output
=
105 grub_register_command ("terminal_output", grub_cmd_handler
,
106 "terminal_output [handler]",
107 "List or select a handler");
110 GRUB_MOD_FINI(handler
)
112 grub_unregister_command (cmd_handler
);
113 grub_unregister_command (cmd_terminal_input
);
114 grub_unregister_command (cmd_terminal_output
);