shell.c File Reference

Minimal command shell. More...

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <readline/readline.h>
#include <gpxe/command.h>
#include <gpxe/shell.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER)
static int exit_exec (int argc, char **argv __unused)
 "exit" command body
static int help_exec (int argc __unused, char **argv __unused)
 "help" command body
void shell (void)
 Start command shell.

Variables

static const char shell_prompt [] = "gPXE> "
 The shell prompt string.
static int exit_flag = 0
 Flag set in order to exit shell.
struct command exit_command __command
 "exit" command definition


Detailed Description

Minimal command shell.

Definition in file shell.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER   ) 

static int exit_exec ( int  argc,
char **argv  __unused 
) [static]

"exit" command body

Definition at line 41 of file shell.c.

References exit_flag, and printf().

00041                                                         {
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 }

static int help_exec ( int argc  __unused,
char **argv  __unused 
) [static]

"help" command body

Definition at line 60 of file shell.c.

References COMMANDS, for_each_table_entry, command::name, and printf().

00060                                                                  {
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 }

void shell ( void   ) 

Start command shell.

Definition at line 91 of file shell.c.

References exit_flag, free(), readline(), shell_prompt, and system().

Referenced by main().

00091                     {
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 }


Variable Documentation

const char shell_prompt[] = "gPXE> " [static]

The shell prompt string.

Definition at line 35 of file shell.c.

Referenced by shell().

int exit_flag = 0 [static]

Flag set in order to exit shell.

Definition at line 38 of file shell.c.

Referenced by exit_exec(), and shell().

struct command help_command __command [read]

Initial value:

 {
        .name = "exit",
        .exec = exit_exec,
}
"exit" command definition

"help" command definition

Definition at line 54 of file shell.c.


Generated on Tue Apr 6 20:01:47 2010 for gPXE by  doxygen 1.5.7.1