Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 25, 2008, 1:11:51 AM (16 years ago)
Author:
landauf
Message:
  • fixed a bug in CommandExecutor
  • InGameConsole wraps now too long output lines and does something similar for the input line
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/console/src/core/CommandExecutor.cc

    r1402 r1416  
    108108    {
    109109        CommandExecutor::parseIfNeeded(command);
     110
     111        if (!CommandExecutor::getEvaluation().isNewCommand())
     112            CommandExecutor::parse(CommandExecutor::getEvaluation().getCommand(), false);
     113        else
     114            CommandExecutor::getEvaluation().setNewCommand(false);
     115
    110116        return CommandExecutor::getEvaluation().complete();
    111117    }
     
    119125    CommandEvaluation CommandExecutor::evaluate(const std::string& command)
    120126    {
    121         CommandExecutor::parse(command, true);
     127        CommandExecutor::parse(command);
    122128        CommandExecutor::getEvaluation().evaluateParams();
    123129        return CommandExecutor::getEvaluation();
     
    126132    void CommandExecutor::parseIfNeeded(const std::string& command)
    127133    {
    128         if ((CommandExecutor::getEvaluation().getCommand() != command) || (CommandExecutor::getEvaluation().getState() == CS_Uninitialized))
     134        if ((CommandExecutor::getEvaluation().getOriginalCommand() != command) || (CommandExecutor::getEvaluation().getState() == CS_Uninitialized))
    129135            CommandExecutor::parse(command);
    130         else if (!CommandExecutor::getEvaluation().isValid())
    131         {
    132             CommandExecutor::getEvaluation().setNewCommand(false);
    133             CommandExecutor::parse(command, false);
    134         }
    135136    }
    136137
     
    301302                if (CommandExecutor::getEvaluation().getFunction())
    302303                {
    303 std::cout << "1\n";
    304304                    unsigned int startindex = 0;
    305305                    if (CommandExecutor::getEvaluation().getState() == CS_Shortcut_Params)
     
    307307                    else if (CommandExecutor::getEvaluation().getState() == CS_Function_Params)
    308308                        startindex = 2;
    309 std::cout << "2\n";
    310309
    311310                    if (CommandExecutor::argumentsGiven() >= startindex)
    312311                    {
    313 std::cout << "3\n";
    314                         if (CommandExecutor::enoughArgumentsGiven(CommandExecutor::getEvaluation().getFunction()))
    315                         {
    316 std::cout << "4\n";
     312                        if ((CommandExecutor::argumentsGiven() == CommandExecutor::argumentsFinished() || !CommandExecutor::getEvaluation().isNewCommand()) && CommandExecutor::enoughArgumentsGiven(CommandExecutor::getEvaluation().getFunction()))
     313                        {
    317314                            if (CommandExecutor::getEvaluation().getState() == CS_Shortcut_Params)
    318315                                CommandExecutor::getEvaluation().setState(CS_Shortcut_Finished);
     
    324321                        else
    325322                        {
    326 std::cout << "5\n";
    327 std::cout << "last argument: " << CommandExecutor::getLastArgument() << std::endl;
    328 std::cout << "function: " << CommandExecutor::getEvaluation().getFunction() << std::endl;
    329 std::cout << "functionname: " << CommandExecutor::getEvaluation().getFunction()->getName() << std::endl;
    330 std::cout << "param nr: " << CommandExecutor::getEvaluation().getTokens().size() - startindex << std::endl;
    331323                            CommandExecutor::createListOfPossibleArguments(CommandExecutor::getLastArgument(), CommandExecutor::getEvaluation().getFunction(), CommandExecutor::getEvaluation().getTokens().size() - startindex);
    332 std::cout << "6\n";
    333324                            unsigned int numArguments = CommandExecutor::getEvaluation().getListOfPossibleArguments().size();
    334325
    335326                            if (numArguments == 1)
    336327                            {
    337 std::cout << "7\n";
    338328                                // There is exactly one possible argument
    339329                                const std::string* possibleArgument = (*CommandExecutor::getEvaluation().getListOfPossibleArguments().begin()).second;
    340                                 CommandExecutor::parse(CommandExecutor::getEvaluation().getTokens().subSet(0, CommandExecutor::getEvaluation().getTokens().size() - 1 - startindex).join() + " " + (*possibleArgument) + " ");
     330                                if (CommandExecutor::argumentsGiven() > CommandExecutor::argumentsFinished())
     331                                    CommandExecutor::parse(CommandExecutor::getEvaluation().getTokens().subSet(0, CommandExecutor::getEvaluation().getTokens().size() - 1).join() + " " + (*possibleArgument) + " ", false);
     332                                else
     333                                    CommandExecutor::parse(CommandExecutor::getEvaluation().getTokens().subSet(0, CommandExecutor::getEvaluation().getTokens().size()).join() + " " + (*possibleArgument) + " ", false);
     334
    341335                                return;
    342336                            }
    343337
    344 std::cout << "8\n";
    345338                            if ((CommandExecutor::argumentsGiven() > CommandExecutor::argumentsFinished()) && (!CommandExecutor::getEvaluation().isNewCommand()))
    346339                            {
    347 std::cout << "9\n";
    348340                                // There is more than one argument, but the user wants to use this - check if there is a perfect match
    349341                                const std::string* possibleArgument = CommandExecutor::getPossibleArgument(CommandExecutor::getLastArgument(), CommandExecutor::getEvaluation().getFunction(), CommandExecutor::getEvaluation().getTokens().size() - startindex);
    350342                                if (possibleArgument)
    351343                                {
    352 std::cout << "10\n";
    353344                                    // There is such an argument - use it
    354345                                    CommandExecutor::parse(command + " ", false);
    355346                                    return;
    356347                                }
    357 std::cout << "11\n";
    358348                            }
    359 std::cout << "12\n";
    360                         }
    361 std::cout << "13\n";
     349                        }
    362350
    363351                        // Nothing to do
     
    426414    void CommandExecutor::createListOfPossibleIdentifiers(const std::string& fragment)
    427415    {
     416        CommandExecutor::getEvaluation().getListOfPossibleIdentifiers().clear();
    428417        std::string lowercase = getLowercase(fragment);
    429418        for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseIdentifierMapBegin(); it != Identifier::getLowercaseIdentifierMapEnd(); ++it)
     
    437426    void CommandExecutor::createListOfPossibleFunctions(const std::string& fragment, Identifier* identifier)
    438427    {
     428        CommandExecutor::getEvaluation().getListOfPossibleFunctions().clear();
    439429        std::string lowercase = getLowercase(fragment);
    440430        if (!identifier)
     
    456446    void CommandExecutor::createListOfPossibleArguments(const std::string& fragment, ConsoleCommand* command, unsigned int param)
    457447    {
    458 std::cout << "2_1\n";
     448        CommandExecutor::getEvaluation().getListOfPossibleArguments().clear();
    459449        std::string lowercase = getLowercase(fragment);
    460 std::cout << "2_2\n";
    461450        for (std::list<std::pair<std::string, std::string> >::const_iterator it = command->getArgumentCompletionListBegin(param); it != command->getArgumentCompletionListEnd(param); ++it)
    462         {
    463 std::cout << "2_3\n";
    464451            if ((*it).first.find(lowercase) == 0 || fragment == "")
    465             {
    466 std::cout << "2_4\n";
    467452                CommandExecutor::getEvaluation().getListOfPossibleArguments().push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second));
    468 std::cout << "2_5\n";
    469             }
    470         }
    471 
    472 std::cout << "2_6\n";
     453
    473454        CommandExecutor::getEvaluation().getListOfPossibleArguments().sort(CommandExecutor::compareStringsInList);
    474 std::cout << "2_7\n";
    475455    }
    476456
Note: See TracChangeset for help on using the changeset viewer.