]> git.proxmox.com Git - grub2.git/blob - commands/terminal.c
2004-03-14 Marco Gerards <metgerards@student.han.nl>
[grub2.git] / commands / terminal.c
1 /* terminal.c - command to show and select a terminal */
2 /*
3 * PUPA -- Preliminary Universal Programming Architecture for GRUB
4 * Copyright (C) 2003 Free Software Foundation, Inc.
5 *
6 * PUPA 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 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program 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 PUPA; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include <pupa/normal.h>
22 #include <pupa/dl.h>
23 #include <pupa/arg.h>
24 #include <pupa/misc.h>
25 #include <pupa/term.h>
26
27 static pupa_err_t
28 pupa_cmd_terminal (struct pupa_arg_list *state __attribute__ ((unused)),
29 int argc, char **args)
30 {
31 pupa_term_t term = 0;
32
33 auto int print_terminal (pupa_term_t);
34 auto int find_terminal (pupa_term_t);
35
36 int print_terminal (pupa_term_t t)
37 {
38 pupa_printf (" %s", t->name);
39 return 0;
40 }
41
42 int find_terminal (pupa_term_t t)
43 {
44 if (pupa_strcmp (t->name, args[0]) == 0)
45 {
46 term = t;
47 return 1;
48 }
49
50 return 0;
51 }
52
53 if (argc == 0)
54 {
55 pupa_printf ("Available terminal(s):");
56 pupa_term_iterate (print_terminal);
57 pupa_putchar ('\n');
58
59 pupa_printf ("Current terminal: %s\n", pupa_term_get_current ()->name);
60 }
61 else
62 {
63 pupa_term_iterate (find_terminal);
64 if (! term)
65 return pupa_error (PUPA_ERR_BAD_ARGUMENT, "no such terminal");
66
67 pupa_term_set_current (term);
68 }
69
70 return PUPA_ERR_NONE;
71 }
72
73 \f
74 #ifdef PUPA_UTIL
75 void
76 pupa_terminal_init (void)
77 {
78 pupa_register_command ("terminal", pupa_cmd_terminal, PUPA_COMMAND_FLAG_BOTH,
79 "terminal [TERM...]", "Select a terminal.", 0);
80 }
81
82 void
83 pupa_terminal_fini (void)
84 {
85 pupa_unregister_command ("terminal");
86 }
87 #else /* ! PUPA_UTIL */
88 PUPA_MOD_INIT
89 {
90 (void)mod; /* To stop warning. */
91 pupa_register_command ("terminal", pupa_cmd_terminal, PUPA_COMMAND_FLAG_BOTH,
92 "terminal [TERM...]", "Select a terminal.", 0);
93 }
94
95 PUPA_MOD_FINI
96 {
97 pupa_unregister_command ("terminal");
98 }
99 #endif /* ! PUPA_UTIL */