Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1402


Ignore:
Timestamp:
May 24, 2008, 2:51:31 AM (16 years ago)
Author:
landauf
Message:

backup-commit

Location:
code/branches/console/src/core
Files:
6 edited

Legend:

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

    r1390 r1402  
    2727 */
    2828
     29#include <iostream>
     30
    2931#include "ArgumentCompletionFunctions.h"
    3032
     
    3537        const std::list<std::pair<std::string, std::string> >& fallback()
    3638        {
     39std::cout << "5_1\n";
    3740            static std::list<std::pair<std::string, std::string> > list;
     41std::cout << "5_2\n";
    3842            return list;
    3943        }
  • code/branches/console/src/core/CommandEvaluation.cc

    r1390 r1402  
    4545        this->originalCommand_ = command;
    4646        this->command_ = command;
    47         this->originalCommandTokens_.split(command, " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0');
    4847        this->commandTokens_.split(command, " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0');
    4948
     
    7978        }
    8079
    81         COUT(4) << "CE_execute: " << this->originalCommand_ << "\n";
     80        COUT(4) << "CE_execute: " << this->command_ << "\n";
    8281
    8382        unsigned int startindex = this->getStartindex();
    84         if (this->originalCommandTokens_.size() > startindex)
    85             return this->function_->parse(removeSlashes(this->originalCommandTokens_.subSet(startindex).join() + this->getAdditionalParameter()));
     83        if (this->commandTokens_.size() > startindex)
     84            return this->function_->parse(removeSlashes(this->commandTokens_.subSet(startindex).join() + this->getAdditionalParameter()));
    8685        else
    8786            return this->function_->parse(removeSlashes(this->additionalParameter_));
     
    9392        {
    9493            case CS_Uninitialized:
     94std::cout << "complete: state: CS_Uninitialized" << std::endl;
     95            case CS_Empty:
     96std::cout << "complete: state: CS_Empty" << std::endl;
     97            case CS_ShortcutOrIdentifier:
     98std::cout << "complete: state: CS_ShortcutOrIdentifier" << std::endl;
     99                {
     100                    std::list<std::pair<const std::string*, const std::string*> > temp;
     101                    temp.insert(temp.end(), this->listOfPossibleFunctions_.begin(), this->listOfPossibleFunctions_.end());
     102                    temp.insert(temp.end(), this->listOfPossibleIdentifiers_.begin(), this->listOfPossibleIdentifiers_.end());
     103                    if (temp.size() > 0)
     104                    {
     105std::cout << "complete: temp > 0" << std::endl;
     106                        return (CommandEvaluation::getCommonBegin(temp));
     107                    }
     108                }
     109                break;
     110            case CS_Shortcut_Params:
     111std::cout << "complete: state: CS_Shortcut_Params" << std::endl;
     112                if (this->function_)
     113                {
     114std::cout << "complete: function != 0" << std::endl;
     115                    if (this->commandTokens_.size() > 1)
     116                        return (this->function_->getName() + " " + this->commandTokens_.subSet(1, this->commandTokens_.size() - 1).join() + " " + CommandEvaluation::getCommonBegin(this->listOfPossibleArguments_));
     117                    else
     118                        return (this->function_->getName() + " ");
     119                }
     120                break;
     121            case CS_Shortcut_Finished:
     122std::cout << "complete: state: CS_Shortcut_Finished" << std::endl;
     123                if (this->function_)
     124                {
     125std::cout << "complete: function != 0" << std::endl;
     126                    if (this->commandTokens_.size() > 1)
     127                        return (this->function_->getName() + " " + this->commandTokens_.subSet(1, this->commandTokens_.size() - 1).join());
     128                    else
     129                        return (this->function_->getName());
     130                }
     131                break;
     132            case CS_Function:
     133std::cout << "complete: state: CS_Function" << std::endl;
     134                if (this->functionclass_)
     135                {
     136std::cout << "complete: functionclass != 0" << std::endl;
     137                    return (this->functionclass_->getName() + " " + CommandEvaluation::getCommonBegin(this->listOfPossibleFunctions_));
     138                }
     139                break;
     140            case CS_Function_Params:
     141std::cout << "complete: state: CS_Function_Params" << std::endl;
     142                if (this->functionclass_ && this->function_)
     143                {
     144std::cout << "complete: function und functionclass != 0" << std::endl;
     145                    if (this->commandTokens_.size() > 2)
     146                        return (this->functionclass_->getName() + " " + this->function_->getName() + " " + this->commandTokens_.subSet(2, this->commandTokens_.size()).join() + " " + CommandEvaluation::getCommonBegin(this->listOfPossibleArguments_));
     147                    else
     148                        return (this->functionclass_->getName() + " " + this->function_->getName() + " ");
     149                }
     150                break;
     151            case CS_Function_Finished:
     152std::cout << "complete: state: CS_Function_Finished" << std::endl;
     153                if (this->functionclass_ && this->function_)
     154                {
     155std::cout << "complete: function und functionclass != 0" << std::endl;
     156                    if (this->commandTokens_.size() > 2)
     157                        return (this->functionclass_->getName() + " " + this->function_->getName() + " " + this->commandTokens_.subSet(2, this->commandTokens_.size()).join());
     158                    else
     159                        return (this->functionclass_->getName() + " " + this->function_->getName());
     160                }
     161               break;
     162            case CS_Error:
     163std::cout << "complete: state: CS_Error" << std::endl;
     164                break;
     165        }
     166
     167        return this->originalCommand_;
     168    }
     169
     170    std::string CommandEvaluation::hint() const
     171    {
     172        switch (this->state_)
     173        {
     174            case CS_Uninitialized:
     175                break;
    95176            case CS_Empty:
    96177            case CS_ShortcutOrIdentifier:
    97                 {
    98                     std::list<std::pair<const std::string*, const std::string*> > temp;
    99                     if (this->state_ == CS_Empty)
    100                     {
    101                         temp.insert(temp.end(), this->listOfPossibleFunctions_.begin(), this->listOfPossibleFunctions_.end());
    102                         temp.insert(temp.end(), this->listOfPossibleIdentifiers_.begin(), this->listOfPossibleIdentifiers_.end());
    103                     }
    104                     return (CommandEvaluation::getCommonBegin(temp));
    105                 }
    106                 break;
    107             case CS_Shortcut_Params:
    108                 if (this->function_)
    109                 {
    110                     if (this->commandTokens_.size() > 1)
    111                         return (this->function_->getName() + " " + this->commandTokens_.subSet(1, this->commandTokens_.size() - 1).join() + " " + CommandEvaluation::getCommonBegin(this->listOfPossibleArguments_));
    112                     else
    113                         return (this->function_->getName() + " ");
    114                 }
    115                 break;
    116             case CS_Shortcut_Finished:
    117                 if (this->function_)
    118                 {
    119                     if (this->commandTokens_.size() > 1)
    120                         return (this->function_->getName() + " " + this->originalCommandTokens_.subSet(1, this->originalCommandTokens_.size() - 1).join());
    121                     else
    122                         return (this->function_->getName());
    123                 }
    124                 break;
    125             case CS_Function:
    126                 if (this->functionclass_)
    127                     return (this->functionclass_->getName() + " " + CommandEvaluation::getCommonBegin(this->listOfPossibleFunctions_));
    128                 break;
    129             case CS_Function_Params:
    130                 if (this->functionclass_ && this->function_)
    131                 {
    132                     if (this->commandTokens_.size() > 2)
    133                         return (this->functionclass_->getName() + " " + this->function_->getName() + " " + this->commandTokens_.subSet(2, this->commandTokens_.size() - 1).join() + " " + CommandEvaluation::getCommonBegin(this->listOfPossibleArguments_));
    134                     else
    135                         return (this->functionclass_->getName() + " " + this->function_->getName() + " ");
    136                 }
    137                 break;
    138             case CS_Function_Finished:
    139                 if (this->functionclass_ && this->function_)
    140                 {
    141                     if (this->commandTokens_.size() > 2)
    142                         return (this->functionclass_->getName() + " " + this->function_->getName() + " " + this->originalCommandTokens_.subSet(2, this->originalCommandTokens_.size() - 1).join());
    143                     else
    144                         return (this->functionclass_->getName() + " " + this->function_->getName());
    145                 }
    146                break;
    147             case CS_Error:
    148                 break;
    149         }
    150 
    151         return this->originalCommand_;
    152     }
    153 
    154     std::string CommandEvaluation::hint() const
    155     {
    156         switch (this->state_)
    157         {
    158             case CS_Uninitialized:
    159                 break;
    160             case CS_Empty:
    161             case CS_ShortcutOrIdentifier:
    162                 return (CommandEvaluation::dump(this->listOfPossibleFunctions_) + "\n" + CommandEvaluation::dump(this->listOfPossibleIdentifiers_));
     178                if (this->listOfPossibleFunctions_.size() == 0)
     179                    return CommandEvaluation::dump(this->listOfPossibleIdentifiers_);
     180                else if (this->listOfPossibleIdentifiers_.size() == 0)
     181                    return CommandEvaluation::dump(this->listOfPossibleFunctions_);
     182                else
     183                    return (CommandEvaluation::dump(this->listOfPossibleFunctions_) + "\n" + CommandEvaluation::dump(this->listOfPossibleIdentifiers_));
    163184                break;
    164185            case CS_Function:
     
    167188            case CS_Shortcut_Params:
    168189            case CS_Function_Params:
    169                 return CommandEvaluation::dump(this->listOfPossibleArguments_);
     190                if (this->listOfPossibleArguments_.size() > 0)
     191                    return CommandEvaluation::dump(this->listOfPossibleArguments_);
     192                else
     193                    return CommandEvaluation::dump(this->function_);
    170194            case CS_Shortcut_Finished:
    171195            case CS_Function_Finished:
     
    193217        unsigned int startindex = this->getStartindex();
    194218
    195         if (this->originalCommandTokens_.size() <= startindex)
     219        if (this->commandTokens_.size() <= startindex)
    196220        {
    197221            if (this->function_->evaluate(this->getAdditionalParameter(), this->param_, " "))
    198222                this->bEvaluatedParams_ = true;
    199223        }
    200         else if (this->originalCommandTokens_.size() > startindex)
    201         {
    202             if (this->function_->evaluate(this->originalCommandTokens_.subSet(startindex).join() + this->getAdditionalParameter(), this->param_, " "))
     224        else if (this->commandTokens_.size() > startindex)
     225        {
     226            if (this->function_->evaluate(this->commandTokens_.subSet(startindex).join() + this->getAdditionalParameter(), this->param_, " "))
    203227                this->bEvaluatedParams_ = true;
    204228        }
  • code/branches/console/src/core/CommandEvaluation.h

    r1390 r1402  
    8686            inline void setState(CommandState state)
    8787                { this->state_ = state; }
    88             inline SubString& getOriginalTokens()
    89                 { return this->originalCommandTokens_; }
    9088            inline SubString& getTokens()
    9189                { return this->commandTokens_; }
     
    130128            std::string originalCommand_;
    131129            std::string command_;
    132             SubString originalCommandTokens_;
    133130            SubString commandTokens_;
    134131            std::string additionalParameter_;
  • code/branches/console/src/core/CommandExecutor.cc

    r1390 r1402  
    101101            return TclBind::eval(command);
    102102
    103         if ((CommandExecutor::getEvaluation().getCommand() != command) || (CommandExecutor::getEvaluation().getState() == CS_Uninitialized))
    104             CommandExecutor::parse(command);
    105 
     103        CommandExecutor::parseIfNeeded(command);
    106104        return CommandExecutor::getEvaluation().execute();
    107105    }
     
    109107    std::string CommandExecutor::complete(const std::string& command)
    110108    {
    111         if ((CommandExecutor::getEvaluation().getCommand() != command) || (CommandExecutor::getEvaluation().getState() == CS_Uninitialized))
    112             CommandExecutor::parse(command);
    113 
     109        CommandExecutor::parseIfNeeded(command);
    114110        return CommandExecutor::getEvaluation().complete();
    115111    }
     
    117113    std::string CommandExecutor::hint(const std::string& command)
    118114    {
    119         if ((CommandExecutor::getEvaluation().getCommand() != command) || (CommandExecutor::getEvaluation().getState() == CS_Uninitialized))
    120             CommandExecutor::parse(command);
    121 
     115        CommandExecutor::parseIfNeeded(command);
    122116        return CommandExecutor::getEvaluation().hint();
    123117    }
     
    130124    }
    131125
     126    void CommandExecutor::parseIfNeeded(const std::string& command)
     127    {
     128        if ((CommandExecutor::getEvaluation().getCommand() != command) || (CommandExecutor::getEvaluation().getState() == CS_Uninitialized))
     129            CommandExecutor::parse(command);
     130        else if (!CommandExecutor::getEvaluation().isValid())
     131        {
     132            CommandExecutor::getEvaluation().setNewCommand(false);
     133            CommandExecutor::parse(command, false);
     134        }
     135    }
     136
    132137    void CommandExecutor::parse(const std::string& command, bool bInitialize)
    133138    {
     139std::cout << "parse: command: >" << command << "<" << std::endl;
    134140        if (bInitialize)
    135141            CommandExecutor::getEvaluation().initialize(command);
    136         else
    137             CommandExecutor::getEvaluation().setNewCommand(false);
    138 
    139         CommandExecutor::getEvaluation().setTokens(command + COMMAND_EXECUTOR_CURSOR);
     142
     143        CommandExecutor::getEvaluation().setTokens(command);
    140144        CommandExecutor::getEvaluation().setCommand(command);
    141145
     
    143147        {
    144148            case CS_Uninitialized:
     149            {
     150std::cout << "parse: state: CS_Uninitialized" << std::endl;
    145151                // Impossible
    146152                break;
     153            }
    147154            case CS_Empty:
     155            {
     156std::cout << "parse: state: CS_Empty" << std::endl;
    148157                CommandExecutor::createListOfPossibleIdentifiers(CommandExecutor::getArgument(0));
    149158                CommandExecutor::createListOfPossibleFunctions(CommandExecutor::getArgument(0));
     
    156165                }
    157166                break;
     167            }
    158168            case CS_ShortcutOrIdentifier:
     169            {
     170std::cout << "parse: state: CS_ShortcutOrIdentifier" << std::endl;
    159171                if (CommandExecutor::argumentsFinished() > 0 || !CommandExecutor::getEvaluation().isNewCommand())
    160172                {
     
    185197                }
    186198
     199                unsigned int numIdentifiers = CommandExecutor::getEvaluation().getListOfPossibleIdentifiers().size();
     200                unsigned int numCommands = CommandExecutor::getEvaluation().getListOfPossibleFunctions().size();
     201
    187202                if (CommandExecutor::argumentsFinished() == 0)
    188203                {
    189204                    // There is no finished first argument
    190                     unsigned int numIdentifiers = CommandExecutor::getEvaluation().getListOfPossibleIdentifiers().size();
    191                     unsigned int numCommands = CommandExecutor::getEvaluation().getListOfPossibleFunctions().size();
    192 
    193205                    if (numCommands == 1 && numIdentifiers == 0)
    194206                    {
     
    211223                }
    212224
    213                 // It's not a shortcut nor a classname
    214                 CommandExecutor::getEvaluation().setState(CS_Error);
    215                 AddLanguageEntry("commandexecutorunknownfirstargument", "is not a shortcut nor a classname");
    216                 CommandExecutor::getEvaluation().setError("Error: " + CommandExecutor::getArgument(0) + " " + GetLocalisation("commandexecutorunknownfirstargument") + ".");
    217                 break;
     225                if (numCommands == 0 && numIdentifiers == 0)
     226                {
     227                    // It's not a shortcut nor a classname
     228                    CommandExecutor::getEvaluation().setState(CS_Error);
     229                    AddLanguageEntry("commandexecutorunknownfirstargument", "is not a shortcut nor a classname");
     230                    CommandExecutor::getEvaluation().setError("Error: " + CommandExecutor::getArgument(0) + " " + GetLocalisation("commandexecutorunknownfirstargument") + ".");
     231                }
     232                break;
     233            }
    218234            case CS_Function:
    219                 if (CommandExecutor::getEvaluation().getIdentifier() && CommandExecutor::argumentsGiven() > 1)
     235std::cout << "parse: state: CS_Function" << std::endl;
     236            {
     237                if (CommandExecutor::getEvaluation().getIdentifier() && CommandExecutor::argumentsGiven() > 0)
    220238                {
    221239                    if (CommandExecutor::argumentsFinished() > 1 || !CommandExecutor::getEvaluation().isNewCommand())
     
    234252                            return;
    235253                        }
    236                     }
     254                        else if (CommandExecutor::argumentsFinished() > 1)
     255                        {
     256                            // It's not a function
     257                            AddLanguageEntry("commandexecutorunknowncommand", "is not a valid commandname");
     258                            CommandExecutor::getEvaluation().setError("Error: " + CommandExecutor::getArgument(1) + " " + GetLocalisation("commandexecutorunknowncommand") + ".");
     259                            CommandExecutor::getEvaluation().setState(CS_Error);
     260                        }
     261                    }
     262
     263                    CommandExecutor::createListOfPossibleFunctions(CommandExecutor::getArgument(1), CommandExecutor::getEvaluation().getIdentifier());
    237264
    238265                    if (CommandExecutor::argumentsFinished() <= 1)
    239266                    {
    240267                        // There is no finished second argument
    241                         CommandExecutor::createListOfPossibleFunctions(CommandExecutor::getArgument(0), CommandExecutor::getEvaluation().getIdentifier());
    242268                        unsigned int numFunctions = CommandExecutor::getEvaluation().getListOfPossibleFunctions().size();
    243269
     
    247273                            const std::string* possibleCommand = (*CommandExecutor::getEvaluation().getListOfPossibleFunctions().begin()).second;
    248274                            CommandExecutor::getEvaluation().setState(CS_Function_Params);
    249                             CommandExecutor::getEvaluation().setFunction(CommandExecutor::getPossibleCommand(*possibleCommand));
    250                             CommandExecutor::parse(*possibleCommand + " ", false);
     275                            CommandExecutor::getEvaluation().setFunction(CommandExecutor::getPossibleCommand(*possibleCommand, CommandExecutor::getEvaluation().getIdentifier()));
     276                            CommandExecutor::parse(CommandExecutor::getArgument(0) + " " + *possibleCommand + " ", false);
    251277                            return;
    252278                        }
    253                     }
    254 
    255                     // It's not a function
    256                     AddLanguageEntry("commandexecutorunknowncommand", "is not a valid commandname");
    257                     CommandExecutor::getEvaluation().setError("Error: " + CommandExecutor::getArgument(1) + " " + GetLocalisation("commandexecutorunknowncommand") + ".");
     279                        else if (numFunctions == 0)
     280                        {
     281                            // It's not a function
     282                            AddLanguageEntry("commandexecutorunknowncommand", "is not a valid commandname");
     283                            CommandExecutor::getEvaluation().setError("Error: " + CommandExecutor::getArgument(1) + " " + GetLocalisation("commandexecutorunknowncommand") + ".");
     284                            CommandExecutor::getEvaluation().setState(CS_Error);
     285                        }
     286                    }
     287
     288                    // It's ambiguous
     289                    return;
    258290                }
    259291
     
    261293                CommandExecutor::getEvaluation().setState(CS_Error);
    262294                break;
     295            }
    263296            case CS_Shortcut_Params:
     297std::cout << "parse: state: CS_Shortcut_Params" << std::endl;
    264298            case CS_Function_Params:
     299            {
     300std::cout << "parse: state: CS_Function_Params" << std::endl;
    265301                if (CommandExecutor::getEvaluation().getFunction())
    266302                {
     303std::cout << "1\n";
    267304                    unsigned int startindex = 0;
    268305                    if (CommandExecutor::getEvaluation().getState() == CS_Shortcut_Params)
     
    270307                    else if (CommandExecutor::getEvaluation().getState() == CS_Function_Params)
    271308                        startindex = 2;
     309std::cout << "2\n";
    272310
    273311                    if (CommandExecutor::argumentsGiven() >= startindex)
    274312                    {
     313std::cout << "3\n";
    275314                        if (CommandExecutor::enoughArgumentsGiven(CommandExecutor::getEvaluation().getFunction()))
    276315                        {
     316std::cout << "4\n";
    277317                            if (CommandExecutor::getEvaluation().getState() == CS_Shortcut_Params)
    278318                                CommandExecutor::getEvaluation().setState(CS_Shortcut_Finished);
    279319                            else if (CommandExecutor::getEvaluation().getState() == CS_Function_Params)
    280320                                CommandExecutor::getEvaluation().setState(CS_Function_Finished);
     321
    281322                            return;
    282323                        }
    283324                        else
    284325                        {
    285                             CommandExecutor::createListOfPossibleArguments(CommandExecutor::getLastArgument(), CommandExecutor::getEvaluation().getFunction(), CommandExecutor::getEvaluation().getOriginalTokens().size() - startindex);
     326std::cout << "5\n";
     327std::cout << "last argument: " << CommandExecutor::getLastArgument() << std::endl;
     328std::cout << "function: " << CommandExecutor::getEvaluation().getFunction() << std::endl;
     329std::cout << "functionname: " << CommandExecutor::getEvaluation().getFunction()->getName() << std::endl;
     330std::cout << "param nr: " << CommandExecutor::getEvaluation().getTokens().size() - startindex << std::endl;
     331                            CommandExecutor::createListOfPossibleArguments(CommandExecutor::getLastArgument(), CommandExecutor::getEvaluation().getFunction(), CommandExecutor::getEvaluation().getTokens().size() - startindex);
     332std::cout << "6\n";
    286333                            unsigned int numArguments = CommandExecutor::getEvaluation().getListOfPossibleArguments().size();
    287334
    288335                            if (numArguments == 1)
    289336                            {
     337std::cout << "7\n";
    290338                                // There is exactly one possible argument
    291339                                const std::string* possibleArgument = (*CommandExecutor::getEvaluation().getListOfPossibleArguments().begin()).second;
     
    294342                            }
    295343
    296                             if (!CommandExecutor::getEvaluation().isNewCommand())
     344std::cout << "8\n";
     345                            if ((CommandExecutor::argumentsGiven() > CommandExecutor::argumentsFinished()) && (!CommandExecutor::getEvaluation().isNewCommand()))
    297346                            {
     347std::cout << "9\n";
    298348                                // There is more than one argument, but the user wants to use this - check if there is a perfect match
    299                                 const std::string* possibleArgument = CommandExecutor::getPossibleArgument(CommandExecutor::getLastArgument(), CommandExecutor::getEvaluation().getFunction(), CommandExecutor::getEvaluation().getOriginalTokens().size() - startindex);
     349                                const std::string* possibleArgument = CommandExecutor::getPossibleArgument(CommandExecutor::getLastArgument(), CommandExecutor::getEvaluation().getFunction(), CommandExecutor::getEvaluation().getTokens().size() - startindex);
    300350                                if (possibleArgument)
    301351                                {
     352std::cout << "10\n";
    302353                                    // There is such an argument - use it
    303354                                    CommandExecutor::parse(command + " ", false);
    304355                                    return;
    305356                                }
     357std::cout << "11\n";
    306358                            }
     359std::cout << "12\n";
    307360                        }
     361std::cout << "13\n";
     362
     363                        // Nothing to do
     364                        return;
    308365                    }
    309366                }
     
    312369                CommandExecutor::getEvaluation().setState(CS_Error);
    313370                break;
     371            }
    314372            case CS_Shortcut_Finished:
     373std::cout << "parse: state: CS_Shortcut_Finished" << std::endl;
     374                break;
    315375            case CS_Function_Finished:
     376std::cout << "parse: state: CS_Function_Finished" << std::endl;
     377                break;
    316378            case CS_Error:
     379std::cout << "parse: state: CS_Error" << std::endl;
    317380                break;
    318381        }
     
    321384    unsigned int CommandExecutor::argumentsFinished()
    322385    {
    323         // Because we added a cursor we have +1 arguments
    324         if (CommandExecutor::getEvaluation().getTokens().size() >= 1)
    325             return (CommandExecutor::getEvaluation().getTokens().size() - 1);
    326         else
    327             return 0;
     386        if (CommandExecutor::getEvaluation().getCommand().size() > 0)
     387        {
     388            if (CommandExecutor::getEvaluation().getCommand()[CommandExecutor::getEvaluation().getCommand().size() - 1] == ' ')
     389                return CommandExecutor::getEvaluation().getTokens().size();
     390            else if (CommandExecutor::getEvaluation().getTokens().size() > 0)
     391                return CommandExecutor::getEvaluation().getTokens().size() - 1;
     392        }
     393        return 0;
    328394    }
    329395
    330396    unsigned int CommandExecutor::argumentsGiven()
    331397    {
    332         return CommandExecutor::getEvaluation().getOriginalTokens().size();
     398        return CommandExecutor::getEvaluation().getTokens().size();
    333399    }
    334400
     
    343409    std::string CommandExecutor::getArgument(unsigned int index)
    344410    {
    345         if ((index >= 0) && index < (CommandExecutor::getEvaluation().getOriginalTokens().size()))
    346             return CommandExecutor::getEvaluation().getOriginalTokens()[index];
     411        if ((index >= 0) && index < (CommandExecutor::getEvaluation().getTokens().size()))
     412            return CommandExecutor::getEvaluation().getTokens()[index];
    347413        else
    348414            return "";
     
    351417    std::string CommandExecutor::getLastArgument()
    352418    {
    353         if (CommandExecutor::getEvaluation().getOriginalTokens().size() > 0)
    354             return CommandExecutor::getEvaluation().getOriginalTokens()[0];
    355         else
    356             return "";
     419        if (CommandExecutor::getEvaluation().getTokens().size() > 0)
     420            if (CommandExecutor::getEvaluation().getCommand().size() > 0 && CommandExecutor::getEvaluation().getCommand()[CommandExecutor::getEvaluation().getCommand().size() - 1] != ' ')
     421                return CommandExecutor::getEvaluation().getTokens()[CommandExecutor::getEvaluation().getTokens().size() - 1];
     422
     423        return "";
    357424    }
    358425
    359426    void CommandExecutor::createListOfPossibleIdentifiers(const std::string& fragment)
    360427    {
     428        std::string lowercase = getLowercase(fragment);
    361429        for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseIdentifierMapBegin(); it != Identifier::getLowercaseIdentifierMapEnd(); ++it)
    362430            if ((*it).second->hasConsoleCommands())
    363                 if ((*it).first.find(getLowercase(fragment)) == 0 || fragment == "")
     431                if ((*it).first.find(lowercase) == 0 || fragment == "")
    364432                    CommandExecutor::getEvaluation().getListOfPossibleIdentifiers().push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName()));
    365433
     
    369437    void CommandExecutor::createListOfPossibleFunctions(const std::string& fragment, Identifier* identifier)
    370438    {
     439        std::string lowercase = getLowercase(fragment);
    371440        if (!identifier)
    372441        {
    373442            for (std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMapBegin(); it != CommandExecutor::getLowercaseConsoleCommandShortcutMapEnd(); ++it)
    374                 if ((*it).first.find(getLowercase(fragment)) == 0 || fragment == "")
     443                if ((*it).first.find(lowercase) == 0 || fragment == "")
    375444                    CommandExecutor::getEvaluation().getListOfPossibleFunctions().push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName()));
    376445        }
     
    378447        {
    379448            for (std::map<std::string, ConsoleCommand*>::const_iterator it = identifier->getLowercaseConsoleCommandMapBegin(); it != identifier->getLowercaseConsoleCommandMapEnd(); ++it)
    380                 if ((*it).first.find(getLowercase(fragment)) == 0 || fragment == "")
     449                if ((*it).first.find(lowercase) == 0 || fragment == "")
    381450                    CommandExecutor::getEvaluation().getListOfPossibleFunctions().push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName()));
    382451        }
     452
    383453        CommandExecutor::getEvaluation().getListOfPossibleFunctions().sort(CommandExecutor::compareStringsInList);
    384454    }
     
    386456    void CommandExecutor::createListOfPossibleArguments(const std::string& fragment, ConsoleCommand* command, unsigned int param)
    387457    {
     458std::cout << "2_1\n";
     459        std::string lowercase = getLowercase(fragment);
     460std::cout << "2_2\n";
    388461        for (std::list<std::pair<std::string, std::string> >::const_iterator it = command->getArgumentCompletionListBegin(param); it != command->getArgumentCompletionListEnd(param); ++it)
    389             if ((*it).first.find(getLowercase(fragment)) == 0 || fragment == "")
     462        {
     463std::cout << "2_3\n";
     464            if ((*it).first.find(lowercase) == 0 || fragment == "")
     465            {
     466std::cout << "2_4\n";
    390467                CommandExecutor::getEvaluation().getListOfPossibleArguments().push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second));
    391 
    392         CommandExecutor::getEvaluation().getListOfPossibleIdentifiers().sort(CommandExecutor::compareStringsInList);
    393 
     468std::cout << "2_5\n";
     469            }
     470        }
     471
     472std::cout << "2_6\n";
     473        CommandExecutor::getEvaluation().getListOfPossibleArguments().sort(CommandExecutor::compareStringsInList);
     474std::cout << "2_7\n";
    394475    }
    395476
    396477    Identifier* CommandExecutor::getPossibleIdentifier(const std::string& name)
    397478    {
    398         std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseIdentifierMap().find(getLowercase(name));
     479        std::string lowercase = getLowercase(name);
     480        std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseIdentifierMap().find(lowercase);
    399481        if ((it != Identifier::getLowercaseIdentifierMapEnd()) && (*it).second->hasConsoleCommands())
    400482            return (*it).second;
     
    405487    ConsoleCommand* CommandExecutor::getPossibleCommand(const std::string& name, Identifier* identifier)
    406488    {
     489        std::string lowercase = getLowercase(name);
    407490        if (!identifier)
    408491        {
    409             std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMap().find(getLowercase(name));
     492            std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMap().find(lowercase);
    410493            if (it != CommandExecutor::getLowercaseConsoleCommandShortcutMapEnd())
    411494                return (*it).second;
     
    413496        else
    414497        {
    415             std::map<std::string, ConsoleCommand*>::const_iterator it = identifier->getLowercaseConsoleCommandMap().find(getLowercase(name));
     498            std::map<std::string, ConsoleCommand*>::const_iterator it = identifier->getLowercaseConsoleCommandMap().find(lowercase);
    416499            if (it != identifier->getLowercaseConsoleCommandMapEnd())
    417500                return (*it).second;
     
    422505    const std::string* CommandExecutor::getPossibleArgument(const std::string& name, ConsoleCommand* command, unsigned int param)
    423506    {
    424         std::string lowercasename = getLowercase(name);
     507        std::string lowercase = getLowercase(name);
    425508        for (std::list<std::pair<std::string, std::string> >::const_iterator it = command->getArgumentCompletionListBegin(param); it != command->getArgumentCompletionListEnd(param); ++it)
    426             if ((*it).first == lowercasename)
     509            if ((*it).first == lowercase)
    427510                return &(*it).second;
    428511
  • code/branches/console/src/core/CommandExecutor.h

    r1390 r1402  
    7676            static CommandEvaluation& getEvaluation();
    7777
     78            static void parseIfNeeded(const std::string& command);
    7879            static void parse(const std::string& command, bool bInitialize = true);
    7980
  • code/branches/console/src/core/ConsoleCommand.cc

    r1390 r1402  
    4343    ConsoleCommand& ConsoleCommand::setArgumentCompletionList(unsigned int param, const std::list<std::pair<std::string, std::string> >& (*function) (void))
    4444    {
    45         if (param >= 0 && param < 5)
     45        if (param < 5)
    4646            this->autocompletionFunction_[param] = function;
    4747        else
     
    5454    const std::list<std::pair<std::string, std::string> >& ConsoleCommand::getArgumentCompletionList(unsigned int param) const
    5555    {
    56         if (param >= 0 && param < 5)
     56        if (param < 5)
    5757            return (*this->autocompletionFunction_[param])();
    5858        else
     
    6262    std::list<std::pair<std::string, std::string> >::const_iterator ConsoleCommand::getArgumentCompletionListBegin(unsigned int param) const
    6363    {
    64         if (param >= 0 && param < 5)
     64std::cout << "3_1: param: " << param << "\n";
     65        if (param < 5)
     66        {
     67std::cout << "3_2: >" << this->autocompletionFunction_[param] << "<\n";
    6568            return (*this->autocompletionFunction_[param])().begin();
     69        }
    6670        else
     71        {
     72std::cout << "3_3\n";
    6773            return autocompletion::fallback().begin();
     74        }
    6875    }
    6976
    7077    std::list<std::pair<std::string, std::string> >::const_iterator ConsoleCommand::getArgumentCompletionListEnd(unsigned int param) const
    7178    {
    72         if (param >= 0 && param < 5)
     79std::cout << "4_1: param: " << param << "\n";
     80        if (param < 5)
     81        {
     82std::cout << "4_2: >" << this->autocompletionFunction_[param] << "<\n";
    7383            return (*this->autocompletionFunction_[param])().end();
     84        }
    7485        else
     86        {
     87std::cout << "4_3\n";
    7588            return autocompletion::fallback().end();
     89        }
    7690    }
    7791}
Note: See TracChangeset for help on using the changeset viewer.