shell.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 FILE_LICENCE ( GPL2_OR_LATER );
00020
00021 #include <stdint.h>
00022 #include <stdlib.h>
00023 #include <stdio.h>
00024 #include <readline/readline.h>
00025 #include <gpxe/command.h>
00026 #include <gpxe/shell.h>
00027
00028
00029
00030
00031
00032
00033
00034
00035 static const char shell_prompt[] = "gPXE> ";
00036
00037
00038 static int exit_flag = 0;
00039
00040
00041 static int exit_exec ( int argc, char **argv __unused ) {
00042
00043 if ( argc == 1 ) {
00044 exit_flag = 1;
00045 } else {
00046 printf ( "Usage: exit\n"
00047 "Exits the command shell\n" );
00048 }
00049
00050 return 0;
00051 }
00052
00053
00054 struct command exit_command __command = {
00055 .name = "exit",
00056 .exec = exit_exec,
00057 };
00058
00059
00060 static int help_exec ( int argc __unused, char **argv __unused ) {
00061 struct command *command;
00062 unsigned int hpos = 0;
00063
00064 printf ( "\nAvailable commands:\n\n" );
00065 for_each_table_entry ( command, COMMANDS ) {
00066 hpos += printf ( " %s", command->name );
00067 if ( hpos > ( 16 * 4 ) ) {
00068 printf ( "\n" );
00069 hpos = 0;
00070 } else {
00071 while ( hpos % 16 ) {
00072 printf ( " " );
00073 hpos++;
00074 }
00075 }
00076 }
00077 printf ( "\n\nType \"<command> --help\" for further information\n\n" );
00078 return 0;
00079 }
00080
00081
00082 struct command help_command __command = {
00083 .name = "help",
00084 .exec = help_exec,
00085 };
00086
00087
00088
00089
00090
00091 void shell ( void ) {
00092 char *line;
00093
00094 exit_flag = 0;
00095 while ( ! exit_flag ) {
00096 line = readline ( shell_prompt );
00097 if ( line ) {
00098 system ( line );
00099 free ( line );
00100 }
00101 }
00102 }