27 lines
687 B
C++
27 lines
687 B
C++
|
#include <cstdlib>
|
||
|
|
||
|
#include "simpleCommand.hh"
|
||
|
|
||
|
SimpleCommand::SimpleCommand() {
|
||
|
// Create available space for 5 arguments
|
||
|
_numOfAvailableArguments = 5;
|
||
|
_numOfArguments = 0;
|
||
|
_arguments = (char **) malloc( _numOfAvailableArguments * sizeof( char * ) );
|
||
|
}
|
||
|
|
||
|
void SimpleCommand::insertArgument( char * argument ) {
|
||
|
if ( _numOfAvailableArguments == _numOfArguments + 1 ) {
|
||
|
// Double the available space
|
||
|
_numOfAvailableArguments *= 2;
|
||
|
_arguments = (char **) realloc( _arguments,
|
||
|
_numOfAvailableArguments * sizeof( char * ) );
|
||
|
}
|
||
|
|
||
|
_arguments[ _numOfArguments ] = argument;
|
||
|
|
||
|
// Add NULL argument at the end
|
||
|
_arguments[ _numOfArguments + 1] = NULL;
|
||
|
|
||
|
_numOfArguments++;
|
||
|
}
|