rshell  1.2
Command Class Reference

Instantiated by Command_Set or Command_List to run user defined single commands. More...

#include <Command_Element.h>

Inheritance diagram for Command:
Command_Element

Public Member Functions

 Command (string c)
 Constructor. More...
 
int execute ()
 Executes a single command by fork and execvp. More...
 
int file_check ()
 Attempts to call stat on a given path and returns the response. More...
 
int redirect_handler ()
 manages any command with pipes or redirects More...
 
char ** to_char_array (vector< string > cmd)
 converts the c++ vector<string> into c function friendly char** More...
 
string str ()
 Returns a string representing a formatted version of the single command. More...
 

Protected Attributes

vector< string > parameters
 

Detailed Description

Instantiated by Command_Set or Command_List to run user defined single commands.

Constructor & Destructor Documentation

Command::Command ( string  c)

Constructor.

Contains the executable at index=0 and parameters after

Parameters
sinput string to be parsed

Constructor takes the string passed in and sends it to Parse_Single_Command. The result of the parsing is a vector of strings stored in 'parameters'

Member Function Documentation

int Command::execute ( )
virtual

Executes a single command by fork and execvp.

Returns
exit code

First check for the 'exit' command ignoring any parameters passed with it. Return EXIT if the 'exit' command is passed. This return type is handled by the Command_Set which instatiated this. The vector of strings is then converted in O(n) time to a char** to be passed to execvp. The process is then forked and the PID is analyzed to determine success of the forking and which process is which. Finally when the child process is resolved (by fail or success) its return code is passed to the parent and then back to Command_Set.

Implements Command_Element.

int Command::file_check ( )

Attempts to call stat on a given path and returns the response.

Returns
exit code of the stat() call

This method determines if the the second element in parameters is a path or a flag, and then calls stat and stat macros to determine the return code.

int Command::redirect_handler ( )

manages any command with pipes or redirects

Returns
exit code

This method handles and command that contains pipes or redirects. It first separates | > < >> from the commands. If a < is found it is expected to be the first of all pipes and redirects. Likewise if a > or >> is found it is expected to be the last. Pipes are only acceptable in between.

string Command::str ( )
virtual

Returns a string representing a formatted version of the single command.

Returns
string representing the command line data structure

Return a string of the 'parameters' vector seperated by a space

Implements Command_Element.

char ** Command::to_char_array ( vector< string >  cmd)

converts the c++ vector<string> into c function friendly char**

Returns
char** identical to input vector<string>

The documentation for this class was generated from the following files: