2008-11-09 Robert Millan <rmh@aybabtu.com>
[grub2/phcoder/solaris.git] / commands / terminal.c
blobfa73644561b385efef6b2ca87778f31673e547d9
1 /* terminal.c - command to show and select a terminal */
2 /*
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2003,2005,2007 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/>.
20 #include <grub/normal.h>
21 #include <grub/dl.h>
22 #include <grub/arg.h>
23 #include <grub/misc.h>
24 #include <grub/term.h>
26 static grub_err_t
27 grub_cmd_terminal_input (struct grub_arg_list *state __attribute__ ((unused)),
28 int argc, char **args)
30 grub_term_input_t term = 0;
32 auto int print_terminal (grub_term_input_t);
33 auto int find_terminal (grub_term_input_t);
35 int print_terminal (grub_term_input_t t)
37 grub_printf (" %s", t->name);
38 return 0;
41 int find_terminal (grub_term_input_t t)
43 if (grub_strcmp (t->name, args[0]) == 0)
45 term = t;
46 return 1;
49 return 0;
52 if (argc == 0)
54 grub_printf ("Available input terminal(s):");
55 grub_term_iterate_input (print_terminal);
56 grub_putchar ('\n');
58 grub_printf ("Current input terminal: %s\n", grub_term_get_current_input ()->name);
60 else
62 grub_term_iterate_input (find_terminal);
63 if (! term)
64 return grub_error (GRUB_ERR_BAD_ARGUMENT, "no such input terminal");
66 grub_term_set_current_input (term);
69 return GRUB_ERR_NONE;
72 static grub_err_t
73 grub_cmd_terminal_output (struct grub_arg_list *state __attribute__ ((unused)),
74 int argc, char **args)
76 grub_term_output_t term = 0;
78 auto int print_terminal (grub_term_output_t);
79 auto int find_terminal (grub_term_output_t);
81 int print_terminal (grub_term_output_t t)
83 grub_printf (" %s", t->name);
84 return 0;
87 int find_terminal (grub_term_output_t t)
89 if (grub_strcmp (t->name, args[0]) == 0)
91 term = t;
92 return 1;
95 return 0;
98 if (argc == 0)
100 grub_printf ("Available output terminal(s):");
101 grub_term_iterate_output (print_terminal);
102 grub_putchar ('\n');
104 grub_printf ("Current output terminal: %s\n", grub_term_get_current_output ()->name);
106 else
108 grub_term_iterate_output (find_terminal);
109 if (! term)
110 return grub_error (GRUB_ERR_BAD_ARGUMENT, "no such output terminal");
112 grub_term_set_current_output (term);
115 return GRUB_ERR_NONE;
119 GRUB_MOD_INIT(terminal)
121 (void)mod; /* To stop warning. */
122 grub_register_command ("terminal_input", grub_cmd_terminal_input, GRUB_COMMAND_FLAG_BOTH,
123 "terminal_input [TERM...]", "Select an input terminal.", 0);
124 grub_register_command ("terminal_output", grub_cmd_terminal_output, GRUB_COMMAND_FLAG_BOTH,
125 "terminal_output [TERM...]", "Select an output terminal.", 0);
128 GRUB_MOD_FINI(terminal)
130 grub_unregister_command ("terminal_input");
131 grub_unregister_command ("terminal_output");