Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7413 in orxonox.OLD


Ignore:
Timestamp:
Apr 28, 2006, 12:54:04 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: Shell Completes some Parameters nicely now

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

Legend:

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

    r7412 r7413  
    102102  }
    103103
    104 
    105104  /**
    106105   * @brief gets a command if it has already been registered.
    107106   * @param commandName the name of the Command
    108    * @param className the name of the Class the command should apply to.
     107   * @param cmdClass the CommandClass of the Class the command is in.
     108   * @returns The Registered Command, or NULL if it does not exist.
     109   */
     110  const ShellCommand* const ShellCommand::getCommand(const std::string& commandName, const ShellCommandClass* cmdClass)
     111  {
     112    assert(cmdClass != NULL);
     113
     114    std::vector<ShellCommand*>::const_iterator elem;
     115    for (elem = cmdClass->commandList.begin(); elem != cmdClass->commandList.end(); elem++)
     116      if (commandName == (*elem)->getName())
     117        return (*elem);
     118    return NULL;
     119  }
     120
     121
     122  /**
     123   * @brief gets a command if it has already been registered.
     124   * @param commandName the name of the Command
     125   * @param className the name of the Class the command is in.
    109126   * @returns The Registered Command, or NULL if it does not exist.
    110127   */
     
    113130    const ShellCommandClass* checkClass = ShellCommandClass::getCommandClass(className);
    114131    if (likely(checkClass != NULL))
    115     {
    116       std::vector<ShellCommand*>::const_iterator elem;
    117       for (elem = checkClass->commandList.begin(); elem != checkClass->commandList.end(); elem++)
    118         if (commandName == (*elem)->getName())
    119         {
    120           PRINTF(2)("Command '%s::%s' already registered\n", className.c_str(), commandName.c_str());
    121           return (*elem);
    122         }
    123     }
     132      return ShellCommand::getCommand(commandName, checkClass);
    124133    return NULL;
    125134  }
     135
     136  /**
     137   * @brief takes out an InputLine, searching for a Command.
     138   * @param inputLine: the Input to analyse.
     139   * @returns: The ShellCommand if found.
     140   */
     141  const ShellCommand* const ShellCommand::getCommandFromInput(const std::string& inputLine)
     142  {
     143    SubString strings(inputLine, SubString::WhiteSpaces);
     144    // no input, no Command.
     145    if (strings.size() == 0)
     146      return NULL;
     147
     148    // CHECK FOR ALIAS
     149    std::vector<ShellCommandAlias*>::const_iterator alias;
     150    for (alias = ShellCommandAlias::getAliases().begin(); alias != ShellCommandAlias::getAliases().end(); alias++ )
     151    {
     152      if (strings[0] == (*alias)->getName())
     153      {
     154        assert ((*alias)->getCommand() != NULL && (*alias)->getCommand()->shellClass != NULL);
     155        return (*alias)->getCommand();
     156      }
     157    }
     158
     159    const ShellCommandClass* cmdClass = ShellCommandClass::getCommandClass(strings[0]);
     160    if (cmdClass != NULL)
     161    {
     162      const ShellCommand* retCmd;
     163      if (strings.size() >= 1)
     164        retCmd = ShellCommand::getCommand(strings[1], cmdClass);
     165      if (retCmd == NULL && strings.size() >= 2)
     166        retCmd = ShellCommand::getCommand(strings[2], cmdClass);
     167      return retCmd;
     168
     169    }
     170  }
     171
    126172
    127173  /**
     
    303349    {
    304350      PRINTF(1)("Parameter %d not inside of valid ParameterCount %d of Command %s::%s\n",
    305     parameter, this->executor->getParamCount(), this->getName(), this->shellClass->getName());
     351                parameter, this->executor->getParamCount(), this->getName(), this->shellClass->getName());
    306352    }
    307353    else
  • trunk/src/lib/shell/shell_command.h

    r7412 r7413  
    7474    static void unregisterCommand(const std::string& commandName, const std::string& className);
    7575    static const ShellCommand* const getCommand(const std::string& commandName, const std::string& className);
     76    static const ShellCommand* const getCommand(const std::string& commandName, const ShellCommandClass* cmdClass);
    7677    static bool exists(const std::string& commandName, const std::string& className);
     78    static const ShellCommand* const getCommandFromInput(const std::string& inputLine);
    7779
    7880    const ShellCommandClass* const getCommandClass() const { return this->shellClass; };
  • trunk/src/lib/shell/shell_completion.cc

    r7412 r7413  
    5757    std::string completeString = "";                 //< the string to complete.
    5858    unsigned int parameterBegin = 0;                 //< The SubString-entry, the Parameters begin.
     59    const ShellCommand* command = NULL;              //< The Command.
    5960
    6061
     
    8283    // OBJECT/FUNCTION COMPLETIONS
    8384    else if ((emptyComplete && inputSplits.size() == 1) ||
    84               (!emptyComplete && inputSplits.size() == 2))
     85             (!emptyComplete && inputSplits.size() == 2))
    8586    {
    8687      classID = ClassList::StringToID(inputSplits.getString(0));
     
    99100
    100101    // Looking for ParameterCompletions.
     102    if (completeType == NullCompletion)
     103    {
     104      if ((command = ShellCommand::getCommandFromInput(input)) != NULL)
     105        completeType |= ParamCompletion;
     106    }
    101107
    102108    if (completeType & ClassCompletion)
     
    108114    if (completeType & AliasCompletion)
    109115      this->aliasComplete(completeString);
    110 
    111     if (completeType == NullCompletion)
    112     {
    113       const ShellCommand* sc = ShellCommand::getCommand(inputSplits[2], inputSplits[0]);
    114       if (sc != NULL)
    115       {
    116         std::vector<std::string> completed;
    117         sc->getCompletorPlugin(0)->addToCompleteList(completed, inputSplits[inputSplits.size()-1]);
    118         for (unsigned int i = 0; i < completed.size(); i++)
    119           this->completionList.push_back(CompletionElement(completed[i], ParamCompletion));
    120       }
    121     }
     116    if (completeType & ParamCompletion)
     117      this->paramComplete(completeString, command);
     118
    122119
    123120
     
    157154    std::list<std::string> fktList;
    158155    ShellCommandClass::getCommandListOfClass(className, fktList);
    159     //printf("%s\n", boList->firstElement()->getName());
    160156    if (!this->addToCompleteList(fktList, commandBegin, FunctionCompletion))
    161157      return false;
     
    172168    std::list<std::string> aliasList;
    173169    ShellCommandAlias::getCommandListOfAlias(aliasList);
    174     //printf("%s\n", boList->firstElement()->getName());
    175170    if (!this->addToCompleteList(aliasList, aliasBegin, AliasCompletion))
    176171      return false;
    177172    return true;
     173  }
     174
     175  /**
     176   * @brief completes Parameters.
     177   * @param paramBegin: Begin of the Parameters.
     178   * @returns true on succes, false if something went wrong
     179   */
     180  bool ShellCompletion::paramComplete(const std::string& paramBegin, const ShellCommand* command)
     181  {
     182    std::vector<std::string> completed;
     183    command->getCompletorPlugin(0)->addToCompleteList(completed, paramBegin);
     184      for (unsigned int i = 0; i < completed.size(); i++)
     185        this->completionList.push_back(CompletionElement(completed[i], ParamCompletion));
    178186  }
    179187
     
    197205    CompletionElement addElem = completionList.front();
    198206    const std::string& addString = addElem.name;
    199     unsigned int addLength = 0;
     207    unsigned int addLength = addString.size();
    200208    unsigned int inputLenght = begin.size();
    201209
    202     // Determin the longest Match
    203     addLength = addString.size();
    204 
     210    // Determin the longest Match (starting with the first candidate in full length).
    205211    CompletionType changeType = NullCompletion;
    206212    std::vector<CompletionElement>::iterator charIT;
    207213    for (charIT = completionList.begin(); charIT != completionList.end(); charIT++)
    208214    {
     215      printf("== %s\n", (*charIT).name.c_str());
    209216      if ((*charIT).type != changeType)
    210217      {
     
    217224      for (unsigned int i = inputLenght; i < addLength; i++)
    218225        if (addString[i] != (*charIT).name[i])
    219         {
    220226          addLength = i;
    221           //       break;
    222         }
    223227    }
    224228    PRINT(0)("\n");
  • trunk/src/lib/shell/shell_completion.h

    r7412 r7413  
    1919namespace OrxShell
    2020{
     21  class ShellCommand;
     22
    2123  //! A class for Completing the an InputString.
    2224  class ShellCompletion
     
    5456      bool commandComplete(const std::string& commandBegin, const std::string& className);
    5557      bool aliasComplete(const std::string& aliasBegin);
     58      bool paramComplete(const std::string& paramBegin, const ShellCommand* command);
    5659
    5760      // Generally Completes.
Note: See TracChangeset for help on using the changeset viewer.