[isa] Fix a small typo in isa.c.
[ipxe.git] / src / hci / shell.c
1 /*
2 * Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19 #include <stdint.h>
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <readline/readline.h>
23 #include <gpxe/command.h>
24 #include <gpxe/shell.h>
25
26 /** @file
27 *
28 * Minimal command shell
29 *
30 */
31
32 static struct command commands[0]
33 __table_start ( struct command, commands );
34 static struct command commands_end[0]
35 __table_end ( struct command, commands );
36
37 /** The shell prompt string */
38 static const char shell_prompt[] = "gPXE> ";
39
40 /** Flag set in order to exit shell */
41 static int exit_flag = 0;
42
43 /** "exit" command body */
44 static int exit_exec ( int argc, char **argv __unused ) {
45
46 if ( argc == 1 ) {
47 exit_flag = 1;
48 } else {
49 printf ( "Usage: exit\n"
50 "Exits the command shell\n" );
51 }
52
53 return 0;
54 }
55
56 /** "exit" command definition */
57 struct command exit_command __command = {
58 .name = "exit",
59 .exec = exit_exec,
60 };
61
62 /** "help" command body */
63 static int help_exec ( int argc __unused, char **argv __unused ) {
64 struct command *command;
65 unsigned int hpos = 0;
66
67 printf ( "\nAvailable commands:\n\n" );
68 for ( command = commands ; command < commands_end ; command++ ) {
69 hpos += printf ( " %s", command->name );
70 if ( hpos > ( 16 * 4 ) ) {
71 printf ( "\n" );
72 hpos = 0;
73 } else {
74 while ( hpos % 16 ) {
75 printf ( " " );
76 hpos++;
77 }
78 }
79 }
80 printf ( "\n\nType \"<command> --help\" for further information\n\n" );
81 return 0;
82 }
83
84 /** "help" command definition */
85 struct command help_command __command = {
86 .name = "help",
87 .exec = help_exec,
88 };
89
90 /**
91 * Start command shell
92 *
93 */
94 void shell ( void ) {
95 char *line;
96
97 exit_flag = 0;
98 while ( ! exit_flag ) {
99 line = readline ( shell_prompt );
100 if ( line ) {
101 system ( line );
102 free ( line );
103 }
104 }
105 }