Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5187 in orxonox.OLD for trunk/src


Ignore:
Timestamp:
Sep 16, 2005, 7:56:39 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: some restructure of the Completion. now one can supply a Type to each completion

Location:
trunk/src/lib/shell
Files:
2 edited

Legend:

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

    r5186 r5187  
    6565  const char* completionLine;
    6666
    67   long classID;         //< the classID retrieved from the Class.
    68   char* classBegin;     //< the beginn of the slass string
    69   char* classEnd;       //< the end of the class string
    70   char* objectBegin;    //< the begin of the object string
    71   char* objectEnd;      //< the end of the object string
    72   char* functionBegin;  //< the begin of the function string
    73   char* functionEnd;    //< the end of the function string
     67  long classID;                    //< the classID retrieved from the Class.
     68  tList<BaseObject>* objectList;   //< the list of Objects stored in classID
     69  char* classBegin;                //< the beginn of the slass string
     70  char* classEnd;                  //< the end of the class string
     71  char* objectBegin;               //< the begin of the object string
     72  char* objectEnd;                 //< the end of the object string
     73  char* functionBegin;             //< the begin of the function string
     74  char* functionEnd;               //< the end of the function string
    7475
    7576  PRINTF(4)("AutoComplete on input\n");
     77  this->emptyCompletionList();
    7678
    7779  if (input != NULL)
     
    118120      this->objectComplete("", classID);
    119121  }
     122//  else if (inputSplits.getCount() <= 3 )
    120123
    121124/*  completionLine = new char[strlen(this->input->getText())+1];
     
    160163  if (clList != NULL)
    161164  {
    162     const tList<const char>* classList = this->createCompleteList(clList, classBegin);
     165    const tList<ShellC_Element>* classList = this->addToCompleteList(clList, classBegin);
    163166    if (classList != NULL)
    164167      this->generalComplete(classList, classBegin, "CL: %s ");
     
    187190  {
    188191    printf("\n", boList->firstElement()->getName());
    189     const tList<const char>* objectList = this->createCompleteList(boList, objectBegin);
     192    const tList<ShellC_Element>* objectList = this->addToCompleteList(boList, objectBegin);
    190193    if (objectList != NULL)
    191194      this->generalComplete(objectList, objectBegin, "%s ");
     
    215218 * @return true if ok, false otherwise
    216219 */
    217 bool ShellCompletion::generalComplete(const tList<const char>* stringList, const char* begin, const char* displayAs, const char* addBack, const char* addFront)
     220bool ShellCompletion::generalComplete(const tList<ShellC_Element>* stringList, const char* begin, const char* displayAs, const char* addBack, const char* addFront)
    218221{
    219222  if (stringList == NULL || this->input == NULL )
     
    222225    return false;
    223226
    224   const char* addString = stringList->firstElement();
     227  ShellC_Element* addElem = stringList->firstElement();
     228  const char* addString = addElem->name;
    225229  unsigned int addLength = 0;
    226230  unsigned int inputLenght = strlen(begin);
    227231
     232  // Determin the longest Match
    228233  if (addString != NULL)
    229234    addLength = strlen(addString);
    230   tIterator<const char>* charIterator = stringList->getIterator();
    231   const char* charElem = charIterator->firstElement();
     235  tIterator<ShellC_Element>* charIterator = stringList->getIterator();
     236  ShellC_Element* charElem = charIterator->firstElement();
    232237  while (charElem != NULL)
    233238  {
    234     PRINTF(0)(displayAs, charElem);
     239    PRINTF(0)(displayAs, charElem->name);
    235240    for (unsigned int i = inputLenght; i < addLength; i++)
    236       if (addString[i] != charElem[i])
     241      if (addString[i] != charElem->name[i])
    237242      {
    238243       addLength = i;
     
    267272
    268273/**
    269  * searches for classes, which beginn with classNameBegin
     274 * searches for classes, which beginn with completionBegin
    270275 * @param inputList the List to parse through
    271  * @param classNameBegin the beginning string
    272  * @return a NEW char-array with ClassNames. The LIST should be deleted afterwards,
     276 * @param completionBegin the beginning string
    273277 * !! The strings MUST NOT be deleted !!
    274278 */
    275 const tList<const char>* ShellCompletion::createCompleteList(const tList<const char>* inputList, const char* classNameBegin)
    276 {
    277   if (inputList == NULL || classNameBegin == NULL)
     279const tList<ShellC_Element>* ShellCompletion::addToCompleteList(const tList<const char>* inputList, const char* completionBegin)
     280{
     281  if (inputList == NULL || completionBegin == NULL)
    278282    return NULL;
    279   unsigned int searchLength = strlen(classNameBegin);
    280   if (this->completionList != NULL)
    281     delete this->completionList;
    282   this->completionList = new tList<const char>;
    283 
    284 //  tList<const char>* classList = ClassList::getClassList();
     283  unsigned int searchLength = strlen(completionBegin);
    285284
    286285  tIterator<const char>* iterator = inputList->getIterator();
     
    289288  {
    290289    if (strlen(enumString) >= searchLength &&
    291         !strncasecmp(enumString, classNameBegin, searchLength))
     290        !strncasecmp(enumString, completionBegin, searchLength))
    292291    {
    293292      printf("%s\n", enumString);
    294       this->completionList->add(enumString);
     293      ShellC_Element* newElem = new ShellC_Element;
     294      newElem->name = enumString;
     295      this->completionList->add(newElem);
    295296    }
    296297    enumString = iterator->nextElement();
     
    302303
    303304/**
    304  * searches for classes, which beginn with classNameBegin
     305 * searches for classes, which beginn with completionBegin
    305306 * @param inputList the List to parse through
    306  * @param classNameBegin the beginning string
    307  * @return a NEW char-array with ClassNames. The LIST should be deleted afterwards,
     307 * @param completionBegin the beginning string
    308308 * !! The strings MUST NOT be deleted !!
    309309 */
    310 const tList<const char>* ShellCompletion::createCompleteList(const tList<BaseObject>* inputList, const char* classNameBegin)
    311 {
    312   if (inputList == NULL || classNameBegin == NULL)
     310const tList<ShellC_Element>* ShellCompletion::addToCompleteList(const tList<BaseObject>* inputList, const char* completionBegin)
     311{
     312  if (inputList == NULL || completionBegin == NULL)
    313313    return NULL;
    314   unsigned int searchLength = strlen(classNameBegin);
    315   if (this->completionList != NULL)
    316     delete this->completionList;
    317   this->completionList = new tList<const char>;
     314  unsigned int searchLength = strlen(completionBegin);
    318315
    319316  tIterator<BaseObject>* iterator = inputList->getIterator();
     
    323320    if (enumBO->getName() != NULL &&
    324321        strlen(enumBO->getName()) >= searchLength &&
    325         !strncasecmp(enumBO->getName(), classNameBegin, searchLength))
    326     {
    327       this->completionList->add(enumBO->getName());
     322        !strncasecmp(enumBO->getName(), completionBegin, searchLength))
     323    {
     324      ShellC_Element* newElem = new ShellC_Element;
     325      newElem->name = enumBO->getName();
     326      this->completionList->add(newElem);
    328327    }
    329328    enumBO = iterator->nextElement();
     
    333332  return this->completionList;
    334333}
     334
     335void ShellCompletion::emptyCompletionList()
     336{
     337  if (this->completionList != NULL)
     338  {
     339    tIterator<ShellC_Element>* elemIT = this->completionList->getIterator();
     340    ShellC_Element* elem = elemIT->firstElement();
     341    while (elem != NULL)
     342    {
     343      delete elem;
     344      elem = elemIT->nextElement();
     345    }
     346    delete this->completionList;
     347  }
     348  this->completionList = new tList<ShellC_Element>;
     349}
  • trunk/src/lib/shell/shell_completion.h

    r5184 r5187  
    1515#endif
    1616
     17typedef enum {
     18  SHELLC_CLASS,
     19  SHELLC_OBJECT,
     20  SHELLC_FUNCTION,
     21  SHELLC_ALIAS,
     22} SHELL_CTYPE;
     23
     24struct ShellC_Element{
     25  const char*     name;     //!<
     26  SHELL_CTYPE     type;
     27};
     28
    1729//! A class for ...
    1830class ShellCompletion {
     
    3042  bool functionMatch(const char* functionBegin, long classID, unsigned int* length);
    3143
    32   bool generalComplete(const tList<const char>* stringList, const char* begin, const char* displayAs = "%s", const char* addBack = NULL, const char* addFront = NULL);
     44  bool generalComplete(const tList<ShellC_Element>* stringList, const char* begin, const char* displayAs = "%s", const char* addBack = NULL, const char* addFront = NULL);
    3345
    34   const tList<const char>* createCompleteList(const tList<const char>* inputList, const char* classNameBegin);
    35   const tList<const char>* createCompleteList(const tList<BaseObject>* inputList, const char* classNameBegin);
    36 //    const tList<const char>* createCompleteList(const tList<ShellCommandBase>* inputList, const char* classNameBegin);
     46  const tList<ShellC_Element>* addToCompleteList(const tList<const char>* inputList, const char* completionBegin);
     47  const tList<ShellC_Element>* addToCompleteList(const tList<BaseObject>* inputList, const char* completionBegin);
     48  void emptyCompletionList();
     49//    const tList<const char>* createCompleteList(const tList<ShellCommandBase>* inputList, const char* completionBegin);
    3750
    3851
    3952 private:
    40    tList<const char>*       completionList;          //!< A list of completions, that are io.
     53   tList<ShellC_Element>*   completionList;          //!< A list of completions, that are io.
    4154   ShellInput*              input;
    4255};
Note: See TracChangeset for help on using the changeset viewer.