Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5203 in orxonox.OLD for trunk/src/lib/shell/shell_command.cc


Ignore:
Timestamp:
Sep 18, 2005, 12:50:52 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: now all commands are executeable again

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/shell/shell_command.cc

    r5200 r5203  
    385385
    386386
    387   long classID;                    //< the classID retrieved from the Class.
    388   tList<BaseObject>* objectList;   //< the list of Objects stored in classID
    389   BaseObject* objectPointer;       //< a pointer to th Object to Execute the command on
    390   bool emptyComplete = false;      //< if the completion input is empty string. e.g ""
    391 //  long completeType = SHELLC_NONE; //< the Type we'd like to complete.
     387  long classID = CL_NULL;                 //< the classID retrieved from the Class.
     388  ShellCommandClass* commandClass = NULL; //< the command class this command applies to.
     389  tList<BaseObject>* objectList = NULL;   //< the list of Objects stored in classID
     390  BaseObject* objectPointer = NULL;       //< a pointer to th Object to Execute the command on
     391  bool emptyComplete = false;             //< if the completion input is empty string. e.g ""
     392  unsigned int fktPos = 1;                //< the position of the function (needed for finding it)
     393//  long completeType = SHELLC_NONE;      //< the Type we'd like to complete.
    392394  SubString inputSplits(executionString, true);
    393395
     
    420422      delete itAL;
    421423    }
    422 
    423   }
    424 
    425 
    426    //
    427 //   tIterator<ShellCommandBase>* iterator = ShellCommandBase::commandList->getIterator();
    428 //   ShellCommandBase* elem = iterator->firstElement();
    429 //   while(elem != NULL)
    430 //   {
    431 //     printf("%s::%s\n", elem->className, elem->getName());
    432 //     if (!strncasecmp (executionString, elem->className, strlen(elem->className)) &&
    433 //          (*(executionString+strlen(elem->className)) == ' ' ||
    434 //           *(executionString+strlen(elem->className)) == ':' ))
    435 //     {
    436 //       const char* commandBegin = executionString + strlen(elem->className);
    437 //
    438 //       PRINTF(4)("Class %s matches\n", elem->className);
    439 //       BaseObject* objectPointer = NULL;
    440 //       if (ClassList::StringToID(elem->className) & CL_MASK_SINGLETON == CL_MASK_SINGLETON)
    441 //       {
    442 //         while(*commandBegin == ' ')
    443 //           commandBegin++;
    444 //         if (strncmp (commandBegin, elem->getName(), strlen(elem->getName())) ||
    445 //             *(commandBegin + strlen(elem->getName())) != ' ' &&
    446 //             *(commandBegin + strlen(elem->getName())) != '\0')
    447 //         {
    448 //           elem = iterator->nextElement();
    449 //           continue;
    450 //         }
    451 //         PRINTF(4)("Command %s matches\n", elem->getName());
    452 //         // getting singleton-reference
    453 //         tList<BaseObject>* list =  ClassList::getList(elem->className);
    454 //         if (list != NULL)
    455 //           objectPointer = list->firstElement();
    456 //       }
    457 //       else
    458 //       {
    459 //         // checking for the Object
    460 //         while(*commandBegin == ' ')
    461 //           commandBegin++;
    462 //         tList<BaseObject>* list = ClassList::getList(elem->className);
    463 //         if (list == NULL)
    464 //           break;
    465 //         tIterator<BaseObject>* iterBO = list->getIterator();
    466 //         BaseObject* enumBO = iterBO->firstElement();
    467 //         while(enumBO != NULL)
    468 //         {
    469 //           if(!strncmp(commandBegin, enumBO->getName(), strlen(enumBO->getName())))
    470 //           {
    471 //             PRINTF(4)("Object %s matches\n", enumBO->getName());
    472 //             objectPointer = enumBO;
    473 //             break;
    474 //           }
    475 //           enumBO = iterBO->nextElement();
    476 //         }
    477 //         delete iterBO;
    478 //
    479 //         // break on no object Found. We cannot operate on Classes, but on Objects
    480 //         if (objectPointer == NULL)
    481 //           break;
    482 //         commandBegin = commandBegin + strlen(objectPointer->getName());
    483 //         while(*commandBegin == ' ')
    484 //           commandBegin++;
    485 //         // checking for the requested function.
    486 //         if (strncmp (commandBegin, elem->getName(), strlen(elem->getName())))
    487 //         {
    488 //           elem = iterator->nextElement();
    489 //           continue;
    490 //         }
    491 //         PRINTF(4)("Function '%s' found\n", commandBegin);
    492 //       }
    493 //       const char* paramBegin = strchr(commandBegin, ' ');
    494 //       if (paramBegin == NULL)
    495 //         paramBegin = commandBegin + strlen(elem->getName());
    496 //       while (*paramBegin == ' ')
    497 //         paramBegin++;
    498 //
    499 //       PRINTF(3)("Parameters to Pass: %s\n", paramBegin);
    500 //       if (objectPointer != NULL && paramBegin != NULL)
    501 //       {
    502 //         elem->executeCommand(objectPointer, paramBegin);
    503 //         delete iterator;
    504 //         return true;
    505 //       }
    506 //     }
    507 //     elem = iterator->nextElement();
    508 //   }
    509 //   delete iterator;
    510 //   return true;
     424    // looking for a Matching Class
     425    if (likely(ShellCommandClass::commandClassList != NULL))
     426    {
     427      tIterator<ShellCommandClass>* itCL = ShellCommandClass::commandClassList->getIterator();
     428      ShellCommandClass* elemCL = itCL->firstElement();
     429      while(elemCL != NULL)
     430      {
     431        if (elemCL->getName() && !strcasecmp(inputSplits.getString(0), elemCL->getName()))
     432        {
     433          //elemCL->getName();
     434          classID = ClassList::StringToID(elemCL->getName());
     435          commandClass = elemCL;
     436          objectList = ClassList::getList(classID);
     437          break;
     438        }
     439        elemCL = itCL->nextElement();
     440      }
     441      delete itCL;
     442    }
     443
     444
     445    if (classID != CL_NULL && inputSplits.getCount() >= 2 && objectList != NULL)
     446    {
     447      // Checking for a Match in the Objects of classID (else take the first)
     448      tIterator<BaseObject>* itBO = objectList->getIterator();
     449      BaseObject* enumBO = itBO->firstElement();
     450      while(enumBO)
     451      {
     452        if (enumBO->getName() != NULL && !strcasecmp(enumBO->getName(), inputSplits.getString(1)))
     453        {
     454          objectPointer = enumBO;
     455          fktPos++;
     456          break;
     457        }
     458        enumBO = itBO->nextElement();
     459      }
     460      delete itBO;
     461
     462      //
     463      if (objectPointer == NULL)
     464        objectPointer = objectList->firstElement();
     465
     466      // match a function.
     467      if (commandClass != NULL && objectPointer != NULL && (fktPos == 1 || (fktPos == 2 && inputSplits.getCount() >= 3)))
     468      {
     469        tIterator<ShellCommandBase>* itCMD = commandClass->commandList->getIterator();
     470        ShellCommandBase* enumCMD = itCMD->firstElement();
     471        while (enumCMD != NULL)
     472        {
     473          if (!strcmp(enumCMD->getName(), inputSplits.getString(fktPos)))
     474          {
     475            if (inputSplits.getCount() > fktPos+1)
     476              enumCMD->executeCommand(objectPointer, executionString+inputSplits.getOffset(fktPos +1));
     477            else
     478              enumCMD->executeCommand(objectPointer, "");
     479            delete itCMD;
     480            return true;
     481          }
     482
     483          enumCMD = itCMD->nextElement();
     484        }
     485        delete itCMD;
     486
     487      }
     488
     489    }
     490
     491
     492  }
     493
    511494}
    512495
Note: See TracChangeset for help on using the changeset viewer.