|  | @@ -0,0 +1,86 @@
 | 
		
	
		
			
			|  | 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 <console.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] __table_start ( commands );
 | 
		
	
		
			
			|  | 33 | +static struct command commands_end[0] __table_end ( commands );
 | 
		
	
		
			
			|  | 34 | +
 | 
		
	
		
			
			|  | 35 | +/** The shell prompt string */
 | 
		
	
		
			
			|  | 36 | +static const char shell_prompt[] = "gPXE> ";
 | 
		
	
		
			
			|  | 37 | +
 | 
		
	
		
			
			|  | 38 | +/** Flag set in order to exit shell */
 | 
		
	
		
			
			|  | 39 | +static int exit_flag = 0;
 | 
		
	
		
			
			|  | 40 | +
 | 
		
	
		
			
			|  | 41 | +/** "exit" command body */
 | 
		
	
		
			
			|  | 42 | +static int exit_exec ( int argc __unused, char **argv __unused ) {
 | 
		
	
		
			
			|  | 43 | +	exit_flag = 1;
 | 
		
	
		
			
			|  | 44 | +	return 0;
 | 
		
	
		
			
			|  | 45 | +}
 | 
		
	
		
			
			|  | 46 | +
 | 
		
	
		
			
			|  | 47 | +/** "exit" command definition */
 | 
		
	
		
			
			|  | 48 | +struct command exit_command __command = {
 | 
		
	
		
			
			|  | 49 | +	.name = "exit",
 | 
		
	
		
			
			|  | 50 | +	.exec = exit_exec,
 | 
		
	
		
			
			|  | 51 | +};
 | 
		
	
		
			
			|  | 52 | +
 | 
		
	
		
			
			|  | 53 | +/** "help" command body */
 | 
		
	
		
			
			|  | 54 | +static int help_exec ( int argc __unused, char **argv __unused ) {
 | 
		
	
		
			
			|  | 55 | +	struct command *command;
 | 
		
	
		
			
			|  | 56 | +
 | 
		
	
		
			
			|  | 57 | +	printf ( "\nAvailable commands:\n\n" );
 | 
		
	
		
			
			|  | 58 | +	for ( command = commands ; command < commands_end ; command++ ) {
 | 
		
	
		
			
			|  | 59 | +		printf ( "  %s\n", command->name );
 | 
		
	
		
			
			|  | 60 | +	}
 | 
		
	
		
			
			|  | 61 | +	printf ( "\nType \"<command> --help\" for further information\n\n" );
 | 
		
	
		
			
			|  | 62 | +	return 0;
 | 
		
	
		
			
			|  | 63 | +}
 | 
		
	
		
			
			|  | 64 | +
 | 
		
	
		
			
			|  | 65 | +/** "help" command definition */
 | 
		
	
		
			
			|  | 66 | +struct command help_command __command = {
 | 
		
	
		
			
			|  | 67 | +	.name = "help",
 | 
		
	
		
			
			|  | 68 | +	.exec = help_exec,
 | 
		
	
		
			
			|  | 69 | +};
 | 
		
	
		
			
			|  | 70 | +
 | 
		
	
		
			
			|  | 71 | +/**
 | 
		
	
		
			
			|  | 72 | + * Start command shell
 | 
		
	
		
			
			|  | 73 | + *
 | 
		
	
		
			
			|  | 74 | + */
 | 
		
	
		
			
			|  | 75 | +void shell ( void ) {
 | 
		
	
		
			
			|  | 76 | +	char *line;
 | 
		
	
		
			
			|  | 77 | +
 | 
		
	
		
			
			|  | 78 | +	exit_flag = 0;
 | 
		
	
		
			
			|  | 79 | +	while ( ! exit_flag ) {
 | 
		
	
		
			
			|  | 80 | +		line = readline ( shell_prompt );
 | 
		
	
		
			
			|  | 81 | +		if ( line ) {
 | 
		
	
		
			
			|  | 82 | +			system ( line );
 | 
		
	
		
			
			|  | 83 | +			free ( line );
 | 
		
	
		
			
			|  | 84 | +		}
 | 
		
	
		
			
			|  | 85 | +	}
 | 
		
	
		
			
			|  | 86 | +}
 |