Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5135 in orxonox.OLD for trunk/src/util/shell_command.cc


Ignore:
Timestamp:
Aug 26, 2005, 12:51:27 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: it is now possible to execute Commands registered to the ShellCommandBase with no arguments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/util/shell_command.cc

    r5130 r5135  
    2828using namespace std;
    2929
    30 ShellCommandBase::ShellCommandBase(const char* commandName, ClassID classID, void* functionPointer, unsigned int paramCount, va_list parameters)
     30ShellCommandBase::ShellCommandBase(const char* commandName, ClassID classID, unsigned int paramCount, ...)
    3131{
     32  va_list parameters;
     33  va_start(parameters, paramCount);
     34
    3235  this->classID = classID;
    33   this->functionPointer = functionPointer;
    3436  this->commandName = new char[strlen(commandName)+1];
    3537  strcpy(this->commandName, commandName);
     
    3739  // handling parameters, and storing them:
    3840  this->paramCount = paramCount;
    39   this->parameters = new ShellParameterType[paramCount];
     41  this->parameters = new ParameterType[paramCount];
    4042
    4143  for (unsigned int i = 0; i < paramCount; i++)
     
    5557tList<ShellCommandBase>* ShellCommandBase::commandList = NULL;
    5658
    57 bool ShellCommandBase::isRegistered(const char* commandName, ClassID classID, unsigned int paramCount, va_list parameters)
     59bool ShellCommandBase::isRegistered(const char* commandName, ClassID classID, unsigned int paramCount, ...)
    5860{
     61
     62  va_list parameters;
     63  va_start(parameters, paramCount);
     64
    5965  if (ShellCommandBase::commandList == NULL)
    6066  {
     
    8086
    8187
     88bool ShellCommandBase::execute(const char* executionString)
     89{
     90  if (ShellCommandBase::commandList == NULL)
     91    return false;
     92
     93  const char* commandEnd = strchr(executionString, ' ');
     94  if (commandEnd == NULL)
     95    commandEnd = executionString + strlen(executionString);
     96
     97  tIterator<ShellCommandBase>* iterator = ShellCommandBase::commandList->getIterator();
     98  ShellCommandBase* elem = iterator->firstElement();
     99  while(elem != NULL)
     100  {
     101    if (!strncmp(executionString, elem->commandName, commandEnd - executionString))
     102    {
     103      elem->executeCommand(commandEnd);
     104      delete iterator;
     105      return true;
     106    }
     107    elem = iterator->nextElement();
     108  }
     109  delete iterator;
     110  return true;
     111}
     112
Note: See TracChangeset for help on using the changeset viewer.