Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


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

orxonox/trunk: Shell Completes some Parameters nicely now

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.