Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5192 in orxonox.OLD


Ignore:
Timestamp:
Sep 18, 2005, 12:49:27 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: more completion issues

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

Legend:

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

    r5190 r5192  
    6363bool ShellCommandClass::getCommandListOfClass(const char* className, tList<const char>* stringList)
    6464{
    65   if (stringList == NULL)
     65  if (stringList == NULL || className == NULL)
    6666    return false;
    6767
  • trunk/src/lib/shell/shell_completion.cc

    r5191 r5192  
    6969  tList<BaseObject>* objectList;   //< the list of Objects stored in classID
    7070  bool emptyComplete = false;      //< if the completion input is empty string. e.g ""
     71  SHELLC_TYPE firstType = SHELLC_NONE;
     72  SHELLC_TYPE secondType = SHELLC_NONE;
    7173
    7274
     
    101103    PRINTF(5)("Listing all Classes\n");
    102104    this->objectComplete("", CL_SHELL_COMMAND_CLASS);
    103     return false;
    104105  }
    105106  else if (inputSplits.getCount() == 1 && emptyComplete == false)
     
    110111
    111112  // OBJECT/FUNCTION COMPLETIONS
    112   else if ( (inputSplits.getCount() == 1 && emptyComplete == true ) ||
    113              (inputSplits.getCount() == 2 && emptyComplete == false))
     113  else if ((inputSplits.getCount() == 1 && emptyComplete == true) ||
     114            (inputSplits.getCount() == 2 && emptyComplete == false))
    114115  {
    115116    classID = ClassList::StringToID(inputSplits.getString(0));
    116117    if (classID == CL_NULL)
     118    {
    117119      return false;
    118     if (inputSplits.getCount()==2)
    119     {
    120       if  (completionLine[strlen(completionLine)-1] != ' ')
    121        this->objectComplete(inputSplits.getString(1), classID);
    122120    }
    123121    else
    124       this->objectComplete("", classID);
    125   }
    126 //  else if (inputSplits.getCount() <= 3 )
    127 
    128 /*  completionLine = new char[strlen(this->input->getText())+1];
    129   strcpy(completionLine, this->input->getText());
    130 
    131   char* commandBegin = strrchr(completionLine, ' ');
    132   if (commandBegin == NULL)
    133     commandBegin = completionLine;
     122    {
     123      firstType = SHELLC_CLASS;
     124      if (inputSplits.getCount() == 2)
     125      {
     126        if  (completionLine[strlen(completionLine)-1] != ' ')
     127          this->objectComplete(inputSplits.getString(1), classID);
     128      }
     129      else
     130        this->objectComplete("", classID);
     131    }
     132  }
     133
     134  if (emptyComplete == false)
     135    this->generalComplete(inputSplits.getString(inputSplits.getCount()-1));
    134136  else
    135   {
    136     if(commandBegin >= completionLine + strlen(completionLine))
    137       commandBegin = completionLine + strlen(completionLine);
    138     else
    139       commandBegin++;
    140   }
    141 
    142   char* objectStart;
    143   if (objectStart = strstr(commandBegin, "::"))
    144   {
    145     char* classIdentity = new char[objectStart - commandBegin +1];
    146     strncpy(classIdentity, commandBegin, objectStart - commandBegin);
    147     classIdentity[objectStart - commandBegin] = '\0';
    148     this->objectComplete(objectStart+2, ClassList::StringToID(classIdentity));
    149     delete[] classIdentity;
    150   }
    151   else
    152     this->classComplete(commandBegin);
    153 
    154   delete[] completionLine;*/
     137    this->generalComplete("");
    155138}
    156139
     
    167150  if (clList != NULL)
    168151  {
    169     const tList<ShellC_Element>* classList = this->addToCompleteList(clList, classBegin);
    170     if (classList != NULL)
    171       this->generalComplete(classList, classBegin, "CL: %s ");
    172     else
     152    if (!this->addToCompleteList(clList, classBegin))
    173153      return false;
    174     delete classList;
    175154  }
    176155  else
     
    193172  {
    194173    //printf("%s\n", boList->firstElement()->getName());
    195     const tList<ShellC_Element>* objectList = this->addToCompleteList(boList, objectBegin);
    196     if (objectList != NULL)
    197       this->generalComplete(objectList, objectBegin, "%s ");
    198     else
     174    if (!this->addToCompleteList(boList, objectBegin))
    199175      return false;
    200176  }
     
    214190/**
    215191 * completes the inputline on grounds of an inputList
    216  * @param stringList the List to parse through
    217192 * @param begin the String to search in the inputList, and to extend with it.
    218193 * @param displayAs how to display the found value to the user, printf-style, !!with only one %s!! ex.: "::%s::"
     
    221196 * @return true if ok, false otherwise
    222197 */
    223 bool ShellCompletion::generalComplete(const tList<ShellC_Element>* stringList, const char* begin, const char* displayAs, const char* addBack, const char* addFront)
    224 {
    225   if (stringList == NULL || this->input == NULL )
    226     return false;
    227   if (stringList->getSize() == 0)
    228     return false;
    229 
    230   ShellC_Element* addElem = stringList->firstElement();
     198bool ShellCompletion::generalComplete(const char* begin, const char* displayAs, const char* addBack, const char* addFront)
     199{
     200  if (completionList == NULL || this->input == NULL )
     201    return false;
     202  if (completionList->getSize() == 0)
     203    return false;
     204
     205  ShellC_Element* addElem = completionList->firstElement();
    231206  const char* addString = addElem->name;
    232207  unsigned int addLength = 0;
     
    236211  if (addString != NULL)
    237212    addLength = strlen(addString);
    238   tIterator<ShellC_Element>* charIterator = stringList->getIterator();
     213  tIterator<ShellC_Element>* charIterator = completionList->getIterator();
    239214  ShellC_Element* charElem = charIterator->firstElement();
    240215  while (charElem != NULL)
     
    262237     this->input->addCharacters(adder);
    263238
    264       if (stringList->getSize() == 1)
     239      if (completionList->getSize() == 1)
    265240      {
    266241        if ( addBack != NULL )
     
    280255 * !! The strings MUST NOT be deleted !!
    281256 */
    282 const tList<ShellC_Element>* ShellCompletion::addToCompleteList(const tList<const char>* inputList, const char* completionBegin)
     257bool ShellCompletion::addToCompleteList(const tList<const char>* inputList, const char* completionBegin)
    283258{
    284259  if (inputList == NULL || completionBegin == NULL)
    285     return NULL;
     260    return false;
    286261  unsigned int searchLength = strlen(completionBegin);
    287262
     
    302277  delete iterator;
    303278
    304   return this->completionList;
     279  return true;
    305280}
    306281
     
    311286 * !! The strings MUST NOT be deleted !!
    312287 */
    313 const tList<ShellC_Element>* ShellCompletion::addToCompleteList(const tList<BaseObject>* inputList, const char* completionBegin)
     288bool ShellCompletion::addToCompleteList(const tList<BaseObject>* inputList, const char* completionBegin)
    314289{
    315290  if (inputList == NULL || completionBegin == NULL)
    316     return NULL;
     291    return false;
    317292  unsigned int searchLength = strlen(completionBegin);
    318293
     
    334309  delete iterator;
    335310
    336   return this->completionList;
     311  return true;
    337312}
    338313
  • trunk/src/lib/shell/shell_completion.h

    r5187 r5192  
    1616
    1717typedef enum {
     18  SHELLC_NONE,
    1819  SHELLC_CLASS,
    1920  SHELLC_OBJECT,
    2021  SHELLC_FUNCTION,
    2122  SHELLC_ALIAS,
    22 } SHELL_CTYPE;
     23} SHELLC_TYPE;
    2324
    2425struct ShellC_Element{
    2526  const char*     name;     //!<
    26   SHELL_CTYPE     type;
     27  SHELLC_TYPE     type;
    2728};
    2829
     
    4243  bool functionMatch(const char* functionBegin, long classID, unsigned int* length);
    4344
    44   bool generalComplete(const tList<ShellC_Element>* stringList, const char* begin, const char* displayAs = "%s", const char* addBack = NULL, const char* addFront = NULL);
     45  bool generalComplete(const char* begin, const char* displayAs = "%s", const char* addBack = NULL, const char* addFront = NULL);
    4546
    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);
     47  bool addToCompleteList(const tList<const char>* inputList, const char* completionBegin);
     48  bool addToCompleteList(const tList<BaseObject>* inputList, const char* completionBegin);
    4849  void emptyCompletionList();
    4950//    const tList<const char>* createCompleteList(const tList<ShellCommandBase>* inputList, const char* completionBegin);
Note: See TracChangeset for help on using the changeset viewer.