]>
Commit | Line | Data |
---|---|---|
7e9ca17a | 1 | /* handler.c - commands to list or select handlers */ |
71b9f361 | 2 | /* |
3 | * GRUB -- GRand Unified Bootloader | |
4 | * Copyright (C) 2009 Free Software Foundation, Inc. | |
5 | * | |
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. | |
10 | * | |
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. | |
15 | * | |
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/>. | |
18 | */ | |
19 | ||
71b9f361 | 20 | #include <grub/dl.h> |
21 | #include <grub/err.h> | |
22 | #include <grub/misc.h> | |
23 | #include <grub/term.h> | |
24 | #include <grub/handler.h> | |
b1b797cb | 25 | #include <grub/command.h> |
77a79592 | 26 | #include <grub/i18n.h> |
71b9f361 | 27 | |
28 | static grub_err_t | |
0aa63398 | 29 | grub_cmd_handler (struct grub_command *cmd __attribute__ ((unused)), |
b1b797cb | 30 | int argc, char **args) |
71b9f361 | 31 | { |
71b9f361 | 32 | void *curr_item = 0; |
33 | grub_handler_class_t head; | |
34 | ||
35 | auto int list_item (grub_named_list_t item); | |
36 | int list_item (grub_named_list_t item) | |
37 | { | |
38 | if (item == curr_item) | |
39 | grub_putchar ('*'); | |
40 | ||
41 | grub_printf ("%s\n", item->name); | |
42 | ||
43 | return 0; | |
44 | } | |
45 | ||
46 | head = grub_handler_class_list; | |
0aa63398 | 47 | if (argc == 0) |
71b9f361 | 48 | { |
b1b797cb | 49 | grub_list_iterate (GRUB_AS_LIST (head), (grub_list_hook_t) list_item); |
71b9f361 | 50 | } |
51 | else | |
52 | { | |
0aa63398 | 53 | char *class_name; |
71b9f361 | 54 | grub_handler_class_t class; |
55 | ||
0aa63398 VS |
56 | class_name = args[0]; |
57 | argc--; | |
58 | args++; | |
71b9f361 | 59 | |
60 | class = grub_named_list_find (GRUB_AS_NAMED_LIST (head), class_name); | |
61 | if (! class) | |
62 | return grub_error (GRUB_ERR_FILE_NOT_FOUND, "class not found"); | |
63 | ||
64 | if (argc == 0) | |
65 | { | |
66 | curr_item = class->cur_handler; | |
b1b797cb | 67 | grub_list_iterate (GRUB_AS_LIST (class->handler_list), |
71b9f361 | 68 | (grub_list_hook_t) list_item); |
69 | } | |
70 | else | |
71 | { | |
72 | grub_handler_t handler; | |
73 | ||
74 | handler = | |
75 | grub_named_list_find (GRUB_AS_NAMED_LIST (class->handler_list), | |
76 | args[0]); | |
77 | ||
78 | if (! handler) | |
79 | return grub_error (GRUB_ERR_FILE_NOT_FOUND, "handler not found"); | |
80 | ||
81 | grub_handler_set_current (class, handler); | |
82 | } | |
83 | } | |
84 | ||
85 | return 0; | |
86 | } | |
87 | ||
0aa63398 | 88 | static grub_command_t cmd_handler; |
71b9f361 | 89 | |
90 | GRUB_MOD_INIT(handler) | |
91 | { | |
b1b797cb | 92 | cmd_handler = |
93 | grub_register_command ("handler", grub_cmd_handler, | |
77a79592 | 94 | N_("[class [handler]]"), |
95 | N_("List or select a handler.")); | |
71b9f361 | 96 | } |
97 | ||
98 | GRUB_MOD_FINI(handler) | |
99 | { | |
b1b797cb | 100 | grub_unregister_command (cmd_handler); |
71b9f361 | 101 | } |