Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5105 in orxonox.OLD


Ignore:
Timestamp:
Aug 22, 2005, 7:29:27 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: some completion of ObjectNames

Location:
trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/lang/class_list.cc

    r5103 r5105  
    285285}
    286286
     287const char* ClassList::IDToString(ClassID classID)
     288{
     289  if(likely(ClassList::first != NULL))
     290  {
     291    ClassList* tmpCL = ClassList::first;
     292    while (likely(tmpCL != NULL))
     293    {
     294      if (tmpCL->classID == classID)
     295        return tmpCL->className;
     296      tmpCL = tmpCL->next;
     297    }
     298  }
     299  return NULL;
     300}
     301
     302long ClassList::StringToID(const char* className)
     303{
     304  if(likely(ClassList::first != NULL))
     305  {
     306    ClassList* tmpCL = ClassList::first;
     307    while (likely(tmpCL != NULL))
     308    {
     309      if (!strcasecmp(tmpCL->className, className))
     310        return tmpCL->classID;
     311      tmpCL = tmpCL->next;
     312    }
     313  }
     314  return CL_NULL;
     315}
     316
     317
     318
    287319/**
    288320 * Print out some very nice debug information
  • trunk/src/lib/lang/class_list.h

    r5103 r5105  
    4545
    4646    static void                     whatIs(const BaseObject* object);
     47
     48    static const char*              IDToString(ClassID classID = CL_NULL);
     49    static long                     StringToID(const char* className);
    4750    static void                     debug(unsigned int debugLevel = 0, long classID = CL_NULL);
     51
    4852
    4953  private:
  • trunk/src/util/shell.cc

    r5104 r5105  
    457457  strcpy(completionLine, this->inputLine);
    458458
    459    char* commandBegin = strrchr(completionLine, ' ');
     459  char* commandBegin = strrchr(completionLine, ' ');
    460460  if (commandBegin == NULL)
    461461    commandBegin = completionLine;
     
    468468  }
    469469
    470   this->classComplete(commandBegin);
     470  char* objectStart;
     471  if (objectStart = strstr(commandBegin, "::"))
     472  {
     473    char* classIdentity = new char[objectStart - commandBegin +1];
     474    strncpy(classIdentity, commandBegin, objectStart - commandBegin);
     475    classIdentity[objectStart - commandBegin] = '\0';
     476    this->objectComplete(objectStart+2, ClassList::StringToID(classIdentity));
     477    delete[] classIdentity;
     478  }
     479  else
     480    this->classComplete(commandBegin);
    471481
    472482  delete[] completionLine;
     
    482492  if (unlikely(classBegin == NULL))
    483493    return false;
    484   const tList<const char>* classList = this->createCompleteList(ClassList::getClassList(), classBegin);
    485   if (classList->getSize() == 0)
    486   {
    487      //PRINTF(0)("no completion found for %s\n", commandBegin);
     494  const tList<const char>* clList = ClassList::getClassList();
     495  if (clList != NULL)
     496  {
     497    const tList<const char>* classList = this->createCompleteList(clList, classBegin);
     498    if (classList != NULL)
     499      this->generalComplete(classList, classBegin, "%s::", "::");
     500    else
     501      return false;
     502  }
     503  else
    488504    return false;
    489   }
    490 
    491   const char* addString = classList->firstElement();
     505  return true;
     506}
     507
     508/**
     509 * autocompletes an ObjectName
     510 * @param objectBegin the beginning string of a Object
     511 * @param classID the ID of the Class to search for.
     512 * @return true on success, false otherwise
     513 */
     514bool Shell::objectComplete(const char* objectBegin, long classID)
     515{
     516  printf("%s\n", objectBegin);
     517
     518  if (unlikely(objectBegin == NULL))
     519    return false;
     520  tList<BaseObject>* boList = ClassList::getList(classID);
     521  if (boList != NULL)
     522  {
     523    printf("\n", boList->firstElement()->getName());
     524    const tList<const char>* objectList = this->createCompleteList(boList, objectBegin);
     525    if (objectList != NULL)
     526      this->generalComplete(objectList, objectBegin, "%s");
     527    else
     528      return false;
     529  }
     530  else
     531    return false;
     532  return true;
     533}
     534
     535bool Shell::functionComplete(const char* functionBegin)
     536{
     537}
     538
     539/**
     540 * completes the inputline on grounds of an inputList
     541 * @param stringList the List to parse through
     542 * @param begin the String to search in the inputList, and to extend with it.
     543 * @param displayAs how to display the found value to the user, printf-style, !!with only one %s!! ex.: "::%s::"
     544 * @param addBack what should be added at the end of the completion
     545 * @param addFront what should be added to the front of one finished completion
     546 * @return true if ok, false otherwise
     547 */
     548bool Shell::generalComplete(const tList<const char>* stringList, const char* begin, const char* displayAs, const char* addBack, const char* addFront)
     549{
     550  if (stringList->getSize() == 0)
     551    return false;
     552
     553  const char* addString = stringList->firstElement();
    492554  unsigned int addLength = 0;
    493   unsigned int inputLenght = strlen(classBegin);
     555  unsigned int inputLenght = strlen(begin);
    494556
    495557  if (addString != NULL)
    496558    addLength = strlen(addString);
    497   tIterator<const char>* charIterator = classList->getIterator();
     559  tIterator<const char>* charIterator = stringList->getIterator();
    498560  const char* charElem = charIterator->nextElement();
    499561  while (charElem != NULL)
    500562  {
    501     PRINTF(0)("%s:: ", charElem);
    502     {
    503       for (unsigned int i = inputLenght; i < addLength; i++)
    504         if (addString[i] != charElem[i])
    505       {
    506         addLength = i;
    507         break;
    508       }
    509     }
    510 
     563    PRINTF(0)(displayAs, charElem);
     564    for (unsigned int i = inputLenght; i < addLength; i++)
     565      if (addString[i] != charElem[i])
     566    {
     567      addLength = i;
     568      break;
     569    }
    511570    charElem = charIterator->nextElement();
    512571  }
     
    520579    this->removeCharacters(inputLenght);
    521580    this->addCharacters(adder);
    522 //    this->addCharacters("::");
     581    if (addBack != NULL && stringList->getSize() == 1)
     582      this->addCharacters("::");
    523583    delete[] adder;
    524584  }
    525 }
    526 
    527 bool Shell::objectComplete(const char* objectBegin, ClassID classID)
    528 {
    529 
    530 }
    531 
    532 bool Shell::functionComplete(const char* functionBegin)
    533 {
    534 }
     585  return true;
     586}
     587
    535588
    536589
    537590/**
    538591 * searches for classes, which beginn with classNameBegin
    539  * @param classNameBegin the beginning string of a Class
     592 * @param inputList the List to parse through
     593 * @param classNameBegin the beginning string
    540594 * @return a NEW char-array with ClassNames. The LIST should be deleted afterwards,
    541595 * !! The strings MUST NOT be deleted !!
     
    543597const tList<const char>* Shell::createCompleteList(const tList<const char>* inputList, const char* classNameBegin)
    544598{
     599  if (inputList == NULL || classNameBegin == NULL)
     600    return NULL;
    545601  unsigned int searchLength = strlen(classNameBegin);
    546602  if (this->completionList != NULL)
     
    566622}
    567623
     624/**
     625 * searches for classes, which beginn with classNameBegin
     626 * @param inputList the List to parse through
     627 * @param classNameBegin the beginning string
     628 * @return a NEW char-array with ClassNames. The LIST should be deleted afterwards,
     629 * !! The strings MUST NOT be deleted !!
     630 */
     631const tList<const char>* Shell::createCompleteList(const tList<BaseObject>* inputList, const char* classNameBegin)
     632{
     633  if (inputList == NULL || classNameBegin == NULL)
     634    return NULL;
     635  unsigned int searchLength = strlen(classNameBegin);
     636  if (this->completionList != NULL)
     637    delete this->completionList;
     638  this->completionList = new tList<const char>;
     639
     640  tIterator<BaseObject>* iterator = inputList->getIterator();
     641  BaseObject* enumBO = iterator->nextElement();
     642  while (enumBO != NULL)
     643  {
     644    if (enumBO->getName() != NULL &&
     645        strlen(enumBO->getName())>searchLength+1 &&
     646        !strncasecmp(enumBO->getName(), classNameBegin, searchLength))
     647    {
     648      this->completionList->add(enumBO->getName());
     649    }
     650    enumBO = iterator->nextElement();
     651  }
     652  delete iterator;
     653
     654  return this->completionList;
     655}
     656
    568657
    569658
  • trunk/src/util/shell.h

    r5104 r5105  
    6868    bool autoComplete();
    6969    bool classComplete(const char* classBegin);
    70     bool objectComplete(const char* objectBegin, ClassID classID);
     70    bool objectComplete(const char* objectBegin, long classID);
    7171    bool functionComplete(const char* functionBegin);
    7272
     73    bool generalComplete(const tList<const char>* stringList, const char* begin, const char* displayAs = "%s", const char* addBack = NULL, const char* addFront = NULL);
    7374
    7475    const tList<const char>* Shell::createCompleteList(const tList<const char>* inputList, const char* classNameBegin);
     76    const tList<const char>* Shell::createCompleteList(const tList<BaseObject>* inputList, const char* classNameBegin);
    7577
    7678
Note: See TracChangeset for help on using the changeset viewer.