Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core2/src/orxonox/core/CommandExecutor.cc @ 967

Last change on this file since 967 was 967, checked in by landauf, 16 years ago

hum, i forgot what i was doing there… oh wait, i remember… it had something to do with executor evaluation. strange thing, no wonder my brain has a leak or something… what's that SVN thing all around my cursor? what's a cursor anyway? oh, and what am i doing here? i feel like having breakfast and it's all dark… stupid clock change…

File size: 53.9 KB
RevLine 
[947]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *
4 *
5 *   License notice:
6 *
7 *   This program is free software; you can redistribute it and/or
8 *   modify it under the terms of the GNU General Public License
9 *   as published by the Free Software Foundation; either version 2
10 *   of the License, or (at your option) any later version.
11 *
12 *   This program is distributed in the hope that it will be useful,
13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 *   GNU General Public License for more details.
16 *
17 *   You should have received a copy of the GNU General Public License
18 *   along with this program; if not, write to the Free Software
19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 *
21 *   Author:
22 *      Fabian 'x3n' Landau
23 *   Co-authors:
24 *      ...
25 *
26 */
27
28#include "CommandExecutor.h"
29#include "ConsoleCommand.h"
30#include "util/String.h"
31#include "Identifier.h"
32#include "Language.h"
33#include "Debug.h"
34#include "Executor.h"
35#include "ConfigValueContainer.h"
36
37#define COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE "set"
38#define COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY "tset"
39#define COMMAND_EXECUTOR_KEYWORD_SET_KEYBIND "bind"
40
41namespace orxonox
42{
43    ConsoleCommandShortcutGeneric(keyword1, createExecutor((FunctorStatic*)0, "set", AccessLevel::User));
44    ConsoleCommandShortcutGeneric(keyword2, createExecutor((FunctorStatic*)0, "tset", AccessLevel::User));
45    ConsoleCommandShortcutGeneric(keyword3, createExecutor((FunctorStatic*)0, "bind", AccessLevel::User));
46
[953]47
48    ///////////////////////
49    // CommandEvaluation //
50    ///////////////////////
[955]51    CommandEvaluation::CommandEvaluation()
52    {
53        this->processedCommand_ = "";
54        this->additionalParameter_ = "";
55
56        this->functionclass_ = 0;
57        this->configvalueclass_ = 0;
58        this->shortcut_ = 0;
59        this->function_ = 0;
60        this->configvalue_ = 0;
61        this->key_ = 0;
62
63        this->errorMessage_ = "";
64        this->state_ = CS_Uninitialized;
[967]65
66        this->bEvaluatedParams_ = false;
67        this->evaluatedExecutor_ = 0;
[955]68    }
69
[953]70    KeybindMode CommandEvaluation::getKeybindMode()
71    {
72        if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished)
73        {
74//            if (this->shortcut_ != 0)
75//                return this->shortcut_->getKeybindMode();
76        }
77        else if (this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished)
78        {
79//            if (this->function_ != 0)
80//                return this->function_->getKeybindMode();
81        }
82        else if (this->state_ == CS_ConfigValueType || this->state_ == CS_ConfigValueFinished)
83        {
84//            return KeybindMode::onPress;
85        }
86        else if (this->state_ == CS_KeybindCommand || this->state_ == CS_KeybindFinished)
87        {
88//            return KeybindMode::onPress;
89        }
90        else
91        {
92//            return KeybindMode::onPress;
93        }
94    }
95
96    bool CommandEvaluation::isValid() const
97    {
98        if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished)
99        {
100            return (this->shortcut_ != 0);
101        }
102        else if (this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished)
103        {
104            return ((this->functionclass_ != 0) && (this->function_ != 0));
105        }
106        else if (this->state_ == CS_ConfigValueType || this->state_ == CS_ConfigValueFinished)
107        {
108            return ((this->configvalueclass_ != 0) && (this->configvalue_ != 0));
109        }
110        else if (this->state_ == CS_KeybindCommand || this->state_ == CS_KeybindFinished)
111        {
112            return (this->key_ != 0);
113        }
114        else
115        {
116            return false;
117        }
118    }
119
[967]120    void CommandEvaluation::evaluateParams()
121    {
122        this->bEvaluatedParams_ = false;
123        this->evaluatedExecutor_ = 0;
[953]124
[967]125        for (unsigned int i = 0; i < MAX_FUNCTOR_ARGUMENTS; i++)
126            this->param_[i] = MT_null;
127
128        if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished)
129        {
130            if (this->shortcut_ != 0)
131            {
132                if (this->shortcut_->evaluate(this->processedCommand_ + this->getAdditionalParameter(), this->param_, " "))
133                {
134                    this->bEvaluatedParams_ = true;
135                    this->evaluatedExecutor_ = this->shortcut_;
136                }
137            }
138        }
139        else if (this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished)
140        {
141            if (this->function_ != 0)
142            {
143                if (this->function_->evaluate(this->processedCommand_ + this->getAdditionalParameter(), this->param_, " "))
144                {
145                    this->bEvaluatedParams_ = true;
146                    this->evaluatedExecutor_ = this->function_;
147                }
148            }
149        }
150    }
151
152    void CommandEvaluation::setEvaluatedParameter(unsigned int index, MultiTypeMath param)
153    {
154        if (index >= 0 && index < MAX_FUNCTOR_ARGUMENTS)
155            this->param_[index] = param;
156    }
157
158    MultiTypeMath CommandEvaluation::getEvaluatedParameter(unsigned int index) const
159    {
160        if (index >= 0 && index < MAX_FUNCTOR_ARGUMENTS)
161            return this->param_[index];
162
163        return MT_null;
164    }
165
166
[953]167    /////////////////////
168    // CommandExecutor //
169    /////////////////////
[949]170    CommandExecutor& CommandExecutor::getInstance()
171    {
172        static CommandExecutor instance;
173        return instance;
174    }
[947]175
[952]176    CommandEvaluation& CommandExecutor::getEvaluation()
177    {
178        return CommandExecutor::getInstance().evaluation_;
179    }
180
[947]181    bool CommandExecutor::addConsoleCommandShortcut(ExecutorStatic* executor)
182    {
[951]183        CommandExecutor::getInstance().consoleCommandShortcuts_[executor->getName()] = executor;
184        CommandExecutor::getInstance().consoleCommandShortcuts_LC_[getLowercase(executor->getName())] = executor;
[947]185        return true;
186    }
187
188    /**
189        @brief Returns the executor of a console command shortcut with given name.
190        @brief name The name of the requested console command shortcut
191        @return The executor of the requested console command shortcut
192    */
193    ExecutorStatic* CommandExecutor::getConsoleCommandShortcut(const std::string& name)
194    {
[951]195        std::map<std::string, ExecutorStatic*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_.find(name);
196        if (it != CommandExecutor::getInstance().consoleCommandShortcuts_.end())
[947]197            return (*it).second;
198        else
199            return 0;
200    }
201
202    /**
203        @brief Returns the executor of a console command shortcut with given name in lowercase.
204        @brief name The name of the requested console command shortcut in lowercase
205        @return The executor of the requested console command shortcut
206    */
207    ExecutorStatic* CommandExecutor::getLowercaseConsoleCommandShortcut(const std::string& name)
208    {
[951]209        std::map<std::string, ExecutorStatic*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_LC_.find(name);
210        if (it != CommandExecutor::getInstance().consoleCommandShortcuts_LC_.end())
[947]211            return (*it).second;
212        else
213            return 0;
214    }
215
216    bool CommandExecutor::execute(const std::string& command)
217    {
[955]218        if ((CommandExecutor::getEvaluation().processedCommand_ != command) || (CommandExecutor::getEvaluation().state_ == CS_Uninitialized))
[947]219            CommandExecutor::parse(command);
220
[952]221        return CommandExecutor::execute(CommandExecutor::getEvaluation());
222    }
[948]223
[952]224
225    bool CommandExecutor::execute(const CommandEvaluation& evaluation)
226    {
227        SubString tokens(evaluation.processedCommand_, " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0');
228
[967]229        if (evaluation.bEvaluatedParams_ && evaluation.evaluatedExecutor_ != 0)
230        {
231            (*evaluation.evaluatedExecutor_)(evaluation.param_[0], evaluation.param_[1], evaluation.param_[2], evaluation.param_[3], evaluation.param_[4]);
232        }
233
[952]234        switch (evaluation.state_)
[947]235        {
[955]236            case CS_Uninitialized:
237                break;
[947]238            case CS_Empty:
239                break;
240            case CS_FunctionClass_Or_Shortcut_Or_Keyword:
241                break;
242            case CS_Shortcut_Params:
[957]243                // not enough parameters but lets hope there are some additional parameters and go on
[947]244            case CS_Shortcut_Finished:
245                // call the shortcut
[952]246                if (evaluation.shortcut_ != 0)
[957]247                {
248                    if (tokens.size() >= 2)
[965]249                        return evaluation.shortcut_->parse(tokens.subSet(1).join() + evaluation.getAdditionalParameter());
[957]250                    else
251                        return evaluation.shortcut_->parse(evaluation.additionalParameter_);
252                }
[947]253                break;
254            case CS_Function:
255                break;
256            case CS_Function_Params:
[957]257                // not enough parameters but lets hope there are some additional parameters and go on
[947]258            case CS_Function_Finished:
259                // call the shortcut
[952]260                if (evaluation.function_ != 0)
[957]261                {
262                    if (tokens.size() >= 3)
[965]263                        return evaluation.function_->parse(tokens.subSet(2).join() + evaluation.getAdditionalParameter());
[957]264                    else
265                        return evaluation.function_->parse(evaluation.additionalParameter_);
266                }
[947]267                break;
268            case CS_ConfigValueClass:
269                break;
270            case CS_ConfigValue:
271                break;
272            case CS_ConfigValueType:
[957]273                // not enough parameters but lets hope there are some additional parameters and go on
[947]274            case CS_ConfigValueFinished:
275                // set the config value
[952]276                if (evaluation.configvalue_ != 0)
[957]277                {
278                    if ((tokens.size() >= 1) && (tokens[0] == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE))
279                    {
280                        if (tokens.size() >= 4)
[965]281                            return evaluation.configvalue_->set(tokens.subSet(3).join() + evaluation.getAdditionalParameter());
[957]282                        else
283                            return evaluation.configvalue_->set(evaluation.additionalParameter_);
284                    }
285                    else if ((tokens.size() >= 1) && (tokens[0] == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY))
286                    {
287                        if (tokens.size() >= 4)
[965]288                            return evaluation.configvalue_->tset(tokens.subSet(3).join() + evaluation.getAdditionalParameter());
[957]289                        else
290                            return evaluation.configvalue_->tset(evaluation.additionalParameter_);
291                    }
292                }
[947]293                break;
294            case CS_KeybindKey:
295                break;
296            case CS_KeybindCommand:
[957]297                // not enough parameters but lets hope there are some additional parameters and go on
[947]298            case CS_KeybindFinished:
299                // set the keybind
300                // ...todo
301                break;
302            case CS_Error:
303                break;
304        }
305
306        return false;
307    }
308
309    std::string CommandExecutor::complete(const std::string& command)
310    {
[955]311        if ((CommandExecutor::getEvaluation().processedCommand_ != command) || (CommandExecutor::getEvaluation().state_ == CS_Uninitialized))
[947]312            CommandExecutor::parse(command);
313
[952]314        return CommandExecutor::complete(CommandExecutor::getEvaluation());
315    }
[948]316
[952]317    std::string CommandExecutor::complete(const CommandEvaluation& evaluation)
318    {
319        SubString tokens(evaluation.processedCommand_, " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0');
320
[948]321        std::list<const std::string*> temp;
[952]322        if (evaluation.state_ == CS_Empty)
[948]323        {
[952]324            temp.insert(temp.end(), evaluation.listOfPossibleShortcuts_.begin(), evaluation.listOfPossibleShortcuts_.end());
325            temp.insert(temp.end(), evaluation.listOfPossibleFunctionClasses_.begin(), evaluation.listOfPossibleFunctionClasses_.end());
[948]326        }
327
[952]328        switch (evaluation.state_)
[947]329        {
[955]330            case CS_Uninitialized:
331                break;
[947]332            case CS_Empty:
[955]333                return (CommandExecutor::getCommonBegin(temp));
[947]334                break;
335            case CS_FunctionClass_Or_Shortcut_Or_Keyword:
336                break;
337            case CS_Shortcut_Params:
[952]338                if ((evaluation.processedCommand_.size() >= 1) && (evaluation.processedCommand_[evaluation.processedCommand_.size() - 1] != ' '))
339                    return (evaluation.processedCommand_ + " ");
[947]340                break;
341            case CS_Shortcut_Finished:
342                break;
343            case CS_Function:
[955]344                if (tokens.size() >= 1)
345                    return tokens[0] + " " + CommandExecutor::getCommonBegin(evaluation.listOfPossibleFunctions_);
[947]346                break;
347            case CS_Function_Params:
[952]348                if ((evaluation.processedCommand_.size() >= 1) && (evaluation.processedCommand_[evaluation.processedCommand_.size() - 1] != ' '))
349                    return (evaluation.processedCommand_ + " ");
[947]350                break;
351            case CS_Function_Finished:
352                break;
353            case CS_ConfigValueClass:
[955]354                if (tokens.size() >= 1)
355                    return tokens[0] + " " + CommandExecutor::getCommonBegin(evaluation.listOfPossibleConfigValueClasses_);
[947]356                break;
357            case CS_ConfigValue:
[955]358                if (tokens.size() >= 2)
359                    return tokens[0] + " " + tokens[1] + " " + CommandExecutor::getCommonBegin(evaluation.listOfPossibleConfigValues_);
[947]360                break;
361            case CS_ConfigValueType:
[952]362                if ((evaluation.processedCommand_.size() >= 1) && (evaluation.processedCommand_[evaluation.processedCommand_.size() - 1] != ' '))
363                    return (evaluation.processedCommand_ + " ");
[947]364                break;
365            case CS_ConfigValueFinished:
366                break;
367            case CS_KeybindKey:
[955]368                if (tokens.size() >= 1)
369                    return tokens[0] + " " + CommandExecutor::getCommonBegin(evaluation.listOfPossibleKeys_);
[947]370                break;
371            case CS_KeybindCommand:
[952]372                if ((evaluation.processedCommand_.size() >= 1) && (evaluation.processedCommand_[evaluation.processedCommand_.size() - 1] != ' '))
373                    return (evaluation.processedCommand_ + " ");
[947]374                break;
375            case CS_KeybindFinished:
376                break;
377            case CS_Error:
378                break;
379        }
380
[952]381        return evaluation.processedCommand_;
[947]382    }
383
384    std::string CommandExecutor::hint(const std::string& command)
385    {
[955]386        if ((CommandExecutor::getEvaluation().processedCommand_ != command) || (CommandExecutor::getEvaluation().state_ == CS_Uninitialized))
[947]387            CommandExecutor::parse(command);
388
[952]389        return CommandExecutor::hint(CommandExecutor::getEvaluation());
390    }
[948]391
[952]392    std::string CommandExecutor::hint(const CommandEvaluation& evaluation)
393    {
394        SubString tokens(evaluation.processedCommand_, " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0');
395
396        switch (evaluation.state_)
[947]397        {
[955]398            case CS_Uninitialized:
399                break;
[947]400            case CS_Empty:
[952]401                return (CommandExecutor::dump(evaluation.listOfPossibleShortcuts_) + "\n" + CommandExecutor::dump(evaluation.listOfPossibleFunctionClasses_));
[947]402                break;
403            case CS_FunctionClass_Or_Shortcut_Or_Keyword:
404                break;
405            case CS_Shortcut_Params:
[952]406                if (evaluation.shortcut_ != 0)
407                    return CommandExecutor::dump(evaluation.shortcut_);
[947]408                break;
409            case CS_Shortcut_Finished:
[952]410                if (evaluation.shortcut_ != 0)
411                    return CommandExecutor::dump(evaluation.shortcut_);
[947]412                break;
413            case CS_Function:
[952]414                return CommandExecutor::dump(evaluation.listOfPossibleFunctions_);
[947]415                break;
416            case CS_Function_Params:
[952]417                if (evaluation.function_ != 0)
418                    return CommandExecutor::dump(evaluation.function_);
[947]419                break;
420            case CS_Function_Finished:
[952]421                if (evaluation.function_ != 0)
422                    return CommandExecutor::dump(evaluation.function_);
[947]423                break;
424            case CS_ConfigValueClass:
[952]425                return CommandExecutor::dump(evaluation.listOfPossibleConfigValueClasses_);
[947]426                break;
427            case CS_ConfigValue:
[952]428                return CommandExecutor::dump(evaluation.listOfPossibleConfigValues_);
[947]429                break;
430            case CS_ConfigValueType:
[952]431                if (evaluation.configvalue_ != 0)
432                    return CommandExecutor::dump(evaluation.configvalue_);
[947]433                break;
434            case CS_ConfigValueFinished:
[952]435                if (evaluation.configvalue_ != 0)
436                    return CommandExecutor::dump(evaluation.configvalue_);
[947]437                break;
438            case CS_KeybindKey:
[952]439                return CommandExecutor::dump(evaluation.listOfPossibleKeys_);
[947]440                break;
441            case CS_KeybindCommand:
[952]442                if (evaluation.key_ != 0)
443                    return CommandExecutor::dump(evaluation.key_);
[947]444                break;
445            case CS_KeybindFinished:
[952]446                if (evaluation.key_ != 0)
447                    return CommandExecutor::dump(evaluation.key_);
[947]448                break;
449            case CS_Error:
[955]450                return CommandExecutor::getEvaluation().errorMessage_;
[947]451                break;
452        }
453
454        return "";
455    }
456
[953]457    CommandEvaluation CommandExecutor::evaluate(const std::string& command)
[952]458    {
459        CommandExecutor::parse(command, true);
[967]460        CommandExecutor::getEvaluation().evaluateParams();
[952]461        return CommandExecutor::getEvaluation();
462    }
463
[947]464    void CommandExecutor::parse(const std::string& command, bool bInitialize)
465    {
[952]466        CommandExecutor::getEvaluation().tokens_.split((command + COMMAND_EXECUTOR_CURSOR), " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0');
467        CommandExecutor::getEvaluation().processedCommand_ = command;
[947]468
469        if (bInitialize)
[953]470            CommandExecutor::initialize(command);
[947]471
[952]472        switch (CommandExecutor::getEvaluation().state_)
[947]473        {
[955]474            case CS_Uninitialized:
475                // Impossible
476                break;
[947]477            case CS_Empty:
478                if (CommandExecutor::argumentsGiven() == 0)
479                {
480                    // We want a hint for the first token
481                    // Check if there is already a perfect match
[952]482                    CommandExecutor::getEvaluation().functionclass_ = CommandExecutor::getIdentifierOfPossibleFunctionClass(CommandExecutor::getToken(0));
483                    CommandExecutor::getEvaluation().shortcut_ = CommandExecutor::getExecutorOfPossibleShortcut(CommandExecutor::getToken(0));
[947]484
[952]485                    if ((CommandExecutor::getEvaluation().functionclass_ != 0) || (CommandExecutor::getEvaluation().shortcut_ != 0))
[947]486                    {
487                        // Yes, there is a class or a shortcut with the searched name
488                        // Add a whitespace and continue parsing
[952]489                        CommandExecutor::getEvaluation().state_ = CS_FunctionClass_Or_Shortcut_Or_Keyword;
[947]490                        CommandExecutor::parse(command + " ", false);
491                        return;
492                    }
493
494                    // No perfect match: Create the lists of all possible classes and shortcuts and return
495                    CommandExecutor::createListOfPossibleFunctionClasses(CommandExecutor::getToken(0));
496                    CommandExecutor::createListOfPossibleShortcuts(CommandExecutor::getToken(0));
[965]497
498                    // Check if there's only one possiblility
499                    if ((CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.size() == 1) && (CommandExecutor::getEvaluation().listOfPossibleShortcuts_.size() == 0))
500                    {
501                        // There's only one possible class
502                        CommandExecutor::getEvaluation().state_ = CS_Function;
503                        CommandExecutor::getEvaluation().functionclass_ = CommandExecutor::getIdentifierOfPossibleFunctionClass(**CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.begin());
504                        CommandExecutor::parse(**CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.begin() + " ", false);
505                        return;
506                    }
507                    else if ((CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.size() == 0) && (CommandExecutor::getEvaluation().listOfPossibleShortcuts_.size() == 1))
508                    {
509                        if ((**CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin() != COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE)
510                         && (**CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin() != COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY)
511                         && (**CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin() != COMMAND_EXECUTOR_KEYWORD_SET_KEYBIND))
512                        {
513                            // There's only one possible shortcut
514                            CommandExecutor::getEvaluation().state_ = CS_Shortcut_Params;
515                            CommandExecutor::getEvaluation().shortcut_ = CommandExecutor::getExecutorOfPossibleShortcut(**CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin());
516                        }
517                        else if ((**CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin() == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE)
518                              || (**CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin() == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY))
519                        {
520                            // It's the 'set' or 'tset' keyword
521                            CommandExecutor::getEvaluation().state_ = CS_ConfigValueClass;
522                        }
523                        else if (**CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin() != COMMAND_EXECUTOR_KEYWORD_SET_KEYBIND)
524                        {
525                            // It's the 'bind' keyword
526                            CommandExecutor::getEvaluation().state_ = CS_KeybindKey;
527                        }
528
529                        CommandExecutor::parse(**CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin() + " ", false);
530                        return;
531                    }
532
533                    // It's ambiguous
[947]534                    return;
535                }
536                else
537                {
538                    // There is at least one argument: Check if it's a shortcut, a classname or a special keyword
[952]539                    CommandExecutor::getEvaluation().state_ = CS_FunctionClass_Or_Shortcut_Or_Keyword;
[947]540                    CommandExecutor::parse(command, false);
541                    return;
542                }
543                break;
544            case CS_FunctionClass_Or_Shortcut_Or_Keyword:
545                if (CommandExecutor::argumentsGiven() >= 1)
546                {
547                    if ((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE) || (CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY))
548                    {
549                        // We want to set a config value
[952]550                        CommandExecutor::getEvaluation().state_ = CS_ConfigValueClass;
[947]551                        CommandExecutor::parse(command, false);
552                        return;
553                    }
554                    else if (CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_KEYBIND)
555                    {
556                        // We want to set a keybinding
[952]557                        CommandExecutor::getEvaluation().state_ = CS_KeybindKey;
[947]558                        CommandExecutor::parse(command, false);
559                        return;
560                    }
561
[952]562                    if (CommandExecutor::getEvaluation().functionclass_ == 0)
563                        CommandExecutor::getEvaluation().functionclass_ = CommandExecutor::getIdentifierOfPossibleFunctionClass(CommandExecutor::getToken(0));
564                    if (CommandExecutor::getEvaluation().shortcut_ == 0)
565                        CommandExecutor::getEvaluation().shortcut_ = CommandExecutor::getExecutorOfPossibleShortcut(CommandExecutor::getToken(0));
[947]566
[952]567                    if ((CommandExecutor::getEvaluation().functionclass_ == 0) && (CommandExecutor::getEvaluation().shortcut_ == 0))
[947]568                    {
569                        // Argument 1 seems to be wrong
570                        AddLanguageEntry("CommandExecutor::NoSuchCommandOrClassName", "No such command or classname");
[952]571                        CommandExecutor::getEvaluation().errorMessage_ = (CommandExecutor::getToken(0) + ": " + GetLocalisation("CommandExecutor::NoSuchCommandOrClassName"));
572                        CommandExecutor::getEvaluation().state_ = CS_Error;
[947]573                        return;
574                    }
[952]575                    else if (CommandExecutor::getEvaluation().shortcut_ != 0)
[947]576                    {
577                        // Argument 1 is a shortcut: Return the needed parameter types
[952]578                        CommandExecutor::getEvaluation().state_ = CS_Shortcut_Params;
[947]579                        CommandExecutor::parse(command, false);
580                        return;
581                    }
582                    else
583                    {
584                        // Argument 1 is a classname: Return the possible functions
[952]585                        CommandExecutor::getEvaluation().state_ = CS_Function;
[947]586                        CommandExecutor::parse(command, false);
587                        return;
588                    }
589                }
590                else
591                {
[952]592                    CommandExecutor::getEvaluation().state_ = CS_Error;
[947]593                    return;
594                }
595                break;
596            case CS_Shortcut_Params:
[952]597                if (CommandExecutor::getEvaluation().shortcut_ != 0)
[947]598                {
599                    // Valid command
600                    // Check if there are enough parameters
[952]601                    if (CommandExecutor::enoughParametersGiven(1, CommandExecutor::getEvaluation().shortcut_))
[947]602                    {
[952]603                        CommandExecutor::getEvaluation().state_ = CS_Shortcut_Finished;
[947]604                        return;
605                    }
606                }
607                else
608                {
609                    // Something is wrong
[952]610                    CommandExecutor::getEvaluation().state_ = CS_Error;
[947]611                    return;
612                }
613                break;
614            case CS_Function:
[952]615                if (CommandExecutor::getEvaluation().functionclass_ != 0)
[947]616                {
617                    // We have a valid classname
618                    // Check if there is a second argument
619                    if (CommandExecutor::argumentsGiven() >= 2)
620                    {
621                        // There is a second argument: Check if it's a valid functionname
[952]622                        CommandExecutor::getEvaluation().function_ = CommandExecutor::getExecutorOfPossibleFunction(CommandExecutor::getToken(1), CommandExecutor::getEvaluation().functionclass_);
623                        if (CommandExecutor::getEvaluation().function_ == 0)
[947]624                        {
625                            // Argument 2 seems to be wrong
626                            AddLanguageEntry("CommandExecutor::NoSuchFunctionnameIn", "No such functionname in");
[952]627                            CommandExecutor::getEvaluation().errorMessage_ = (CommandExecutor::getToken(1) + ": " + GetLocalisation("CommandExecutor::NoSuchFunctionnameIn") + " " + CommandExecutor::getEvaluation().functionclass_->getName());
628                            CommandExecutor::getEvaluation().state_ = CS_Error;
[947]629                            return;
630                        }
631                        else
632                        {
633                            // Argument 2 seems to be a valid functionname: Get the parameters
[952]634                            CommandExecutor::getEvaluation().state_ = CS_Function_Params;
[947]635                            CommandExecutor::parse(command, false);
636                            return;
637                        }
638                    }
639                    else
640                    {
641                        // There is no finished second argument
642                        // Check if there's already a perfect match
[952]643                        if (CommandExecutor::getEvaluation().tokens_.size() >= 2)
[947]644                        {
[952]645                            CommandExecutor::getEvaluation().function_ = CommandExecutor::getExecutorOfPossibleFunction(CommandExecutor::getToken(1), CommandExecutor::getEvaluation().functionclass_);
646                            if (CommandExecutor::getEvaluation().function_ != 0)
[947]647                            {
648                                // There is a perfect match: Add a whitespace and continue parsing
[952]649                                CommandExecutor::getEvaluation().state_ = CS_Function_Params;
[947]650                                CommandExecutor::parse(command + " ", false);
651                                return;
652                            }
653                        }
654
655                        // No perfect match: Create the list of all possible functions and return
[952]656                        CommandExecutor::createListOfPossibleFunctions(CommandExecutor::getToken(1), CommandExecutor::getEvaluation().functionclass_);
[965]657
658                        // Check if there's only one possiblility
659                        if (CommandExecutor::getEvaluation().listOfPossibleFunctions_.size() == 1)
660                        {
661                            // There's only one possible function
662                            CommandExecutor::getEvaluation().state_ = CS_Function_Params;
663                            CommandExecutor::getEvaluation().function_ = CommandExecutor::getExecutorOfPossibleFunction(**CommandExecutor::getEvaluation().listOfPossibleFunctions_.begin(), CommandExecutor::getEvaluation().functionclass_);
664                            CommandExecutor::parse(CommandExecutor::getToken(0) + " " + **CommandExecutor::getEvaluation().listOfPossibleFunctions_.begin() + " ", false);
665                            return;
666                        }
667
668                        // It's ambiguous
[947]669                        return;
670                    }
671                }
672                else
673                {
[952]674                    CommandExecutor::getEvaluation().state_ = CS_Error;
[947]675                    return;
676                }
677                break;
678            case CS_Function_Params:
[952]679                if ((CommandExecutor::getEvaluation().functionclass_ != 0) && (CommandExecutor::getEvaluation().function_ != 0))
[947]680                {
681                    // Valid command
682                    // Check if there are enough parameters
[952]683                    if (CommandExecutor::enoughParametersGiven(2, CommandExecutor::getEvaluation().function_))
[947]684                    {
[952]685                        CommandExecutor::getEvaluation().state_ = CS_Function_Finished;
[947]686                        return;
687                    }
688                }
689                else
690                {
691                    // Something is wrong
[952]692                    CommandExecutor::getEvaluation().state_ = CS_Error;
[947]693                    return;
694                }
695                break;
696            case CS_ConfigValueClass:
697                if (((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE) || (CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY)))
698                {
699                    // We want to set a config value
700                    // Check if there is a second argument
701                    if (CommandExecutor::argumentsGiven() >= 2)
702                    {
703                        // There is a second argument: Check if it's a valid classname
[952]704                        CommandExecutor::getEvaluation().configvalueclass_ = CommandExecutor::getIdentifierOfPossibleConfigValueClass(CommandExecutor::getToken(1));
705                        if (CommandExecutor::getEvaluation().configvalueclass_ == 0)
[947]706                        {
707                            // Argument 2 seems to be wrong
708                            AddLanguageEntry("CommandExecutor::NoSuchClassWithConfigValues", "No such class with config values");
[952]709                            CommandExecutor::getEvaluation().errorMessage_ = (CommandExecutor::getToken(1) + ": " + GetLocalisation("CommandExecutor::NoSuchClassWithConfigValues"));
710                            CommandExecutor::getEvaluation().state_ = CS_Error;
[947]711                            return;
712                        }
713                        else
714                        {
715                            // Argument 2 seems to be a valid classname: Search for possible config values
[952]716                            CommandExecutor::getEvaluation().state_ = CS_ConfigValue;
[947]717                            CommandExecutor::parse(command, false);
718                            return;
719                        }
720                    }
721                    else
722                    {
723                        // There's no finished second argument
724                        // Check if there's already a perfect match
[952]725                        if (CommandExecutor::getEvaluation().tokens_.size() >= 2)
[947]726                        {
[952]727                            CommandExecutor::getEvaluation().configvalueclass_ = CommandExecutor::getIdentifierOfPossibleConfigValueClass(CommandExecutor::getToken(1));
728                            if (CommandExecutor::getEvaluation().configvalueclass_ != 0)
[947]729                            {
730                                // There is a perfect match: Add a whitespace and continue parsing
[952]731                                CommandExecutor::getEvaluation().state_ = CS_ConfigValue;
[947]732                                CommandExecutor::parse(command + " ", false);
733                                return;
734                            }
735                        }
736
737                        // No perfect match: Create the list of all possible classnames and return
738                        CommandExecutor::createListOfPossibleConfigValueClasses(CommandExecutor::getToken(1));
[965]739
740                        // Check if there's only one possiblility
741                        if (CommandExecutor::getEvaluation().listOfPossibleConfigValueClasses_.size() == 1)
742                        {
743                            // There's only one possible classname
744                            CommandExecutor::getEvaluation().state_ = CS_ConfigValue;
745                            CommandExecutor::getEvaluation().configvalueclass_ = CommandExecutor::getIdentifierOfPossibleConfigValueClass(**CommandExecutor::getEvaluation().listOfPossibleConfigValueClasses_.begin());
746                            CommandExecutor::parse(CommandExecutor::getToken(0) + " " + **CommandExecutor::getEvaluation().listOfPossibleConfigValueClasses_.begin() + " ", false);
747                            return;
748                        }
749
750                        // It's ambiguous
[947]751                        return;
752                    }
753                }
754                else
755                {
756                    // Something is wrong
[952]757                    CommandExecutor::getEvaluation().state_ = CS_Error;
[947]758                    return;
759                }
760                break;
761            case CS_ConfigValue:
[952]762                if (((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE) || (CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY)) && (CommandExecutor::getEvaluation().configvalueclass_ != 0))
[947]763                {
764                    // Check if there is a third argument
765                    if (CommandExecutor::argumentsGiven() >= 3)
766                    {
767                        // There is a third argument: Check if it's a valid config value
[952]768                        CommandExecutor::getEvaluation().configvalue_ = CommandExecutor::getContainerOfPossibleConfigValue(CommandExecutor::getToken(2), CommandExecutor::getEvaluation().configvalueclass_);
769                        if (CommandExecutor::getEvaluation().configvalue_ == 0)
[947]770                        {
771                            // Argument 3 seems to be wrong
772                            AddLanguageEntry("CommandExecutor::NoSuchConfigValueIn", "No such config value in");
[952]773                            CommandExecutor::getEvaluation().errorMessage_ = (CommandExecutor::getToken(2) + ": " + GetLocalisation("CommandExecutor::NoSuchConfigValueIn") + " " + CommandExecutor::getEvaluation().configvalueclass_->getName());
774                            CommandExecutor::getEvaluation().state_ = CS_Error;
[947]775                            return;
776                        }
777                        else
778                        {
779                            // Argument 3 seems to be a valid config value: Get the type
[952]780                            CommandExecutor::getEvaluation().state_ = CS_ConfigValueType;
[947]781                            CommandExecutor::parse(command, false);
782                            return;
783                        }
784                    }
785                    else
786                    {
787                        // There is no finished third argument
788                        // Check if there's already a perfect match
[952]789                        if (CommandExecutor::getEvaluation().tokens_.size() >= 3)
[947]790                        {
[952]791                            CommandExecutor::getEvaluation().configvalue_ = CommandExecutor::getContainerOfPossibleConfigValue(CommandExecutor::getToken(2), CommandExecutor::getEvaluation().configvalueclass_);
[955]792                            if (CommandExecutor::getEvaluation().configvalue_ != 0)
[947]793                            {
794                                // There is a perfect match: Add a whitespace and continue parsing
[952]795                                CommandExecutor::getEvaluation().state_ = CS_ConfigValueType;
[947]796                                CommandExecutor::parse(command + " ", false);
797                                return;
798                            }
799                        }
800
801                        // No perfect match: Create the list of all possible config values
[952]802                        CommandExecutor::createListOfPossibleConfigValues(CommandExecutor::getToken(2), CommandExecutor::getEvaluation().configvalueclass_);
[965]803
804                        // Check if there's only one possiblility
805                        if (CommandExecutor::getEvaluation().listOfPossibleConfigValues_.size() == 1)
806                        {
807                            // There's only one possible config value
808                            CommandExecutor::getEvaluation().state_ = CS_ConfigValueType;
809                            CommandExecutor::getEvaluation().configvalue_ = CommandExecutor::getContainerOfPossibleConfigValue(**CommandExecutor::getEvaluation().listOfPossibleConfigValues_.begin(), CommandExecutor::getEvaluation().configvalueclass_);
810                            CommandExecutor::parse(CommandExecutor::getToken(0) + " " + CommandExecutor::getToken(1) + " " + **CommandExecutor::getEvaluation().listOfPossibleConfigValues_.begin() + " ", false);
811                            return;
812                        }
813
814                        // It's ambiguous
[947]815                        return;
816                    }
817                }
818                else
819                {
820                    // Something is wrong
[952]821                    CommandExecutor::getEvaluation().state_ = CS_Error;
[947]822                    return;
823                }
824                break;
825            case CS_ConfigValueType:
[952]826                if (((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE) || (CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY)) && (CommandExecutor::getEvaluation().configvalueclass_ != 0) && (CommandExecutor::getEvaluation().configvalue_ != 0))
[947]827                {
828                    // Valid command
829                    // Check if there are enough parameters
[952]830                    if (CommandExecutor::getEvaluation().tokens_.size() >= 4)
[947]831                    {
[952]832                        CommandExecutor::getEvaluation().state_ = CS_ConfigValueFinished;
[947]833                        return;
834                    }
835                }
836                else
837                {
838                    // Something is wrong
[952]839                    CommandExecutor::getEvaluation().state_ = CS_Error;
[947]840                    return;
841                }
842                break;
843            case CS_KeybindKey:
844                if ((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_KEYBIND))
845                {
846                    // todo
847                }
848                else
849                {
850                    // Something is wrong
[952]851                    CommandExecutor::getEvaluation().state_ = CS_Error;
[947]852                    return;
853                }
854                break;
855            case CS_KeybindCommand:
856                if ((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_KEYBIND) && (false)) // todo
857                {
858                    // Valid command
859                    // Check if there are enough parameters
[952]860                    if (CommandExecutor::getEvaluation().tokens_.size() >= 3)
[947]861                    {
[952]862                        CommandExecutor::getEvaluation().state_ = CS_KeybindFinished;
[947]863                        return;
864                    }
865
866                }
867                else
868                {
869                    // Something is wrong
[952]870                    CommandExecutor::getEvaluation().state_ = CS_Error;
[947]871                    return;
872                }
873                break;
874            case CS_Shortcut_Finished:
875                // Nothing to do
876                break;
877            case CS_Function_Finished:
878                // Nothing to do
879                break;
880            case CS_ConfigValueFinished:
881                // Nothing to do
882                break;
883            case CS_KeybindFinished:
884                // Nothing to do
885                break;
886            case CS_Error:
887                // This is bad
888                break;
889        }
890    }
891
[953]892    void CommandExecutor::initialize(const std::string& command)
[947]893    {
[953]894        CommandExecutor::getEvaluation().processedCommand_ = command;
895        CommandExecutor::getEvaluation().additionalParameter_ = "";
896
[952]897        CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.clear();
898        CommandExecutor::getEvaluation().listOfPossibleShortcuts_.clear();
899        CommandExecutor::getEvaluation().listOfPossibleFunctions_.clear();
900        CommandExecutor::getEvaluation().listOfPossibleConfigValueClasses_.clear();
901        CommandExecutor::getEvaluation().listOfPossibleConfigValues_.clear();
902        CommandExecutor::getEvaluation().listOfPossibleKeys_.clear();
[947]903
[952]904        CommandExecutor::getEvaluation().functionclass_ = 0;
905        CommandExecutor::getEvaluation().configvalueclass_ = 0;
906        CommandExecutor::getEvaluation().shortcut_ = 0;
907        CommandExecutor::getEvaluation().function_ = 0;
908        CommandExecutor::getEvaluation().configvalue_ = 0;
909        CommandExecutor::getEvaluation().key_ = 0;
[947]910
[952]911        CommandExecutor::getEvaluation().errorMessage_ = "";
912        CommandExecutor::getEvaluation().state_ = CS_Empty;
[947]913    }
914
915    bool CommandExecutor::argumentsGiven(unsigned int num)
916    {
917        // Because we added a cursor we have +1 arguments
918        // There are num arguments given if there are at least num arguments + one cursor
[952]919        return (CommandExecutor::getEvaluation().tokens_.size() >= (num + 1));
[947]920    }
921
922    unsigned int CommandExecutor::argumentsGiven()
923    {
924        // Because we added a cursor we have +1 arguments
[952]925        if (CommandExecutor::getEvaluation().tokens_.size() >= 1)
926            return (CommandExecutor::getEvaluation().tokens_.size() - 1);
[947]927        else
928            return 0;
929    }
930
931    std::string CommandExecutor::getToken(unsigned int index)
932    {
[952]933        if ((index >= 0) && (index < (CommandExecutor::getEvaluation().tokens_.size() - 1)))
934            return CommandExecutor::getEvaluation().tokens_[index];
935        else if (index == (CommandExecutor::getEvaluation().tokens_.size() - 1))
936            return CommandExecutor::getEvaluation().tokens_[index].substr(0, CommandExecutor::getEvaluation().tokens_[index].size() - 1);
[947]937        else
938            return "";
939    }
940
941    bool CommandExecutor::enoughParametersGiven(unsigned int head, Executor* executor)
942    {
943        unsigned int neededParams = head + executor->getParamCount();
944        for (unsigned int i = executor->getParamCount() - 1; i >= 0; i--)
945        {
946            if (executor->defaultValueSet(i))
947                neededParams--;
948            else
949                break;
950        }
[952]951        return (CommandExecutor::getEvaluation().tokens_.size() >= neededParams);
[947]952    }
953
954    void CommandExecutor::createListOfPossibleFunctionClasses(const std::string& fragment)
955    {
956        for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseIdentifierMapBegin(); it != Identifier::getLowercaseIdentifierMapEnd(); ++it)
957        {
958            if ((*it).second->hasConsoleCommands())
959            {
[955]960                if ((*it).first.find(getLowercase(fragment)) == 0 || fragment == "")
[947]961                {
[952]962                    CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.push_back(&(*it).first);
[947]963                }
964            }
965        }
966
[952]967        CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.sort(CommandExecutor::compareStringsInList);
[947]968    }
969
970    void CommandExecutor::createListOfPossibleShortcuts(const std::string& fragment)
971    {
972        for (std::map<std::string, ExecutorStatic*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMapBegin(); it != CommandExecutor::getLowercaseConsoleCommandShortcutMapEnd(); ++it)
973        {
[955]974            if ((*it).first.find(getLowercase(fragment)) == 0 || fragment == "")
[947]975            {
[952]976                CommandExecutor::getEvaluation().listOfPossibleShortcuts_.push_back(&(*it).first);
[947]977            }
978        }
979
[952]980        CommandExecutor::getEvaluation().listOfPossibleShortcuts_.sort(CommandExecutor::compareStringsInList);
[947]981    }
982
983    void CommandExecutor::createListOfPossibleFunctions(const std::string& fragment, Identifier* identifier)
984    {
985        for (std::map<std::string, ExecutorStatic*>::const_iterator it = identifier->getLowercaseConsoleCommandMapBegin(); it != identifier->getLowercaseConsoleCommandMapEnd(); ++it)
986        {
[955]987            if ((*it).first.find(getLowercase(fragment)) == 0 || fragment == "")
[947]988            {
[952]989                CommandExecutor::getEvaluation().listOfPossibleFunctions_.push_back(&(*it).first);
[947]990            }
991        }
992
[952]993        CommandExecutor::getEvaluation().listOfPossibleFunctions_.sort(CommandExecutor::compareStringsInList);
[947]994    }
995
996    void CommandExecutor::createListOfPossibleConfigValueClasses(const std::string& fragment)
997    {
998        for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseIdentifierMapBegin(); it != Identifier::getLowercaseIdentifierMapEnd(); ++it)
999        {
1000            if ((*it).second->hasConfigValues())
1001            {
[955]1002                if ((*it).first.find(getLowercase(fragment)) == 0 || fragment == "")
[947]1003                {
[952]1004                    CommandExecutor::getEvaluation().listOfPossibleConfigValueClasses_.push_back(&(*it).first);
[947]1005                }
1006            }
1007        }
1008
[952]1009        CommandExecutor::getEvaluation().listOfPossibleConfigValueClasses_.sort(CommandExecutor::compareStringsInList);
[947]1010    }
1011
1012    void CommandExecutor::createListOfPossibleConfigValues(const std::string& fragment, Identifier* identifier)
1013    {
1014        for (std::map<std::string, ConfigValueContainer*>::const_iterator it = identifier->getLowercaseConfigValueMapBegin(); it != identifier->getLowercaseConfigValueMapEnd(); ++it)
1015        {
[955]1016            if ((*it).first.find(getLowercase(fragment)) == 0 || fragment == "")
[947]1017            {
[952]1018                CommandExecutor::getEvaluation().listOfPossibleConfigValues_.push_back(&(*it).first);
[947]1019            }
1020        }
1021
[952]1022        CommandExecutor::getEvaluation().listOfPossibleConfigValues_.sort(CommandExecutor::compareStringsInList);
[947]1023    }
1024
1025    void CommandExecutor::createListOfPossibleKeys(const std::string& fragment)
1026    {
1027        // todo
1028
[952]1029        CommandExecutor::getEvaluation().listOfPossibleKeys_.sort(CommandExecutor::compareStringsInList);
[947]1030    }
1031
1032    bool CommandExecutor::compareStringsInList(const std::string* first, const std::string* second)
1033    {
1034        return ((*first) < (*second));
1035    }
1036
1037    Identifier* CommandExecutor::getIdentifierOfPossibleFunctionClass(const std::string& name)
1038    {
1039        std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseIdentifierMap().find(getLowercase(name));
1040        if ((it != Identifier::getLowercaseIdentifierMapEnd()) && (*it).second->hasConsoleCommands())
1041            return (*it).second;
1042
1043        return 0;
1044    }
1045
1046    ExecutorStatic* CommandExecutor::getExecutorOfPossibleShortcut(const std::string& name)
1047    {
1048        std::map<std::string, ExecutorStatic*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMap().find(getLowercase(name));
1049        if (it != CommandExecutor::getLowercaseConsoleCommandShortcutMapEnd())
1050            return (*it).second;
1051
1052        return 0;
1053    }
1054
1055    ExecutorStatic* CommandExecutor::getExecutorOfPossibleFunction(const std::string& name, Identifier* identifier)
1056    {
1057        std::map<std::string, ExecutorStatic*>::const_iterator it = identifier->getLowercaseConsoleCommandMap().find(getLowercase(name));
1058        if (it != identifier->getLowercaseConsoleCommandMapEnd())
1059            return (*it).second;
1060
1061        return 0;
1062    }
1063
1064    Identifier* CommandExecutor::getIdentifierOfPossibleConfigValueClass(const std::string& name)
1065    {
1066        std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseIdentifierMap().find(getLowercase(name));
1067        if ((it != Identifier::getLowercaseIdentifierMapEnd()) && (*it).second->hasConfigValues())
1068            return (*it).second;
1069
1070        return 0;
1071    }
1072
1073    ConfigValueContainer* CommandExecutor::getContainerOfPossibleConfigValue(const std::string& name, Identifier* identifier)
1074    {
1075        std::map<std::string, ConfigValueContainer*>::const_iterator it = identifier->getLowercaseConfigValueMap().find(getLowercase(name));
1076        if (it != identifier->getLowercaseConfigValueMapEnd())
[955]1077        {
[947]1078            return (*it).second;
[955]1079        }
[947]1080
1081        return 0;
1082    }
1083
1084    ConfigValueContainer* CommandExecutor::getContainerOfPossibleKey(const std::string& name)
1085    {
1086        // todo
1087
1088        return 0;
1089    }
1090
1091    std::string CommandExecutor::dump(const std::list<const std::string*>& list)
1092    {
1093        std::string output = "";
1094        for (std::list<const std::string*>::const_iterator it = list.begin(); it != list.end(); ++it)
1095        {
1096            if (it != list.begin())
1097                output += " ";
1098
1099            output += (**it);
1100        }
1101        return output;
1102    }
1103
1104    std::string CommandExecutor::dump(const ExecutorStatic* executor)
1105    {
1106        std::string output = "";
1107        for (unsigned int i = 0; i < executor->getParamCount(); i++)
1108        {
1109            if (i != 0)
1110                output += " ";
1111
1112            if (executor->defaultValueSet(i))
1113                output += "[";
1114            else
1115                output += "{";
1116
1117            output += executor->getTypenameParam(i);
1118
1119            if (executor->defaultValueSet(i))
[957]1120                output += "=" + executor->getDefaultValue(i).toString() + "]";
[947]1121            else
1122                output += "}";
1123        }
1124        return output;
1125    }
1126
1127    std::string CommandExecutor::dump(const ConfigValueContainer* container)
1128    {
[957]1129        AddLanguageEntry("CommandExecutor::oldvalue", "old value");
1130        return "{" + container->getTypename() + "} (" + GetLocalisation("CommandExecutor::oldvalue") + ": " + container->toString() + ")";
[947]1131    }
[948]1132
1133    std::string CommandExecutor::getCommonBegin(const std::list<const std::string*>& list)
1134    {
1135        if (list.size() == 0)
1136        {
1137            return "";
1138        }
1139        else if (list.size() == 1)
1140        {
1141            return ((**list.begin()) + " ");
1142        }
1143        else
1144        {
1145            std::string output = "";
1146            for (unsigned int i = 0; true; i++)
1147            {
1148                char temp = 0;
1149                for (std::list<const std::string*>::const_iterator it = list.begin(); it != list.end(); ++it)
1150                {
1151                    if ((**it).size() > i)
1152                    {
1153                        if (it == list.begin())
1154                        {
1155                            temp = (**it)[i];
1156                        }
1157                        else
1158                        {
1159                            if (temp != (**it)[i])
1160                                return output;
1161                        }
1162                    }
1163                    else
1164                    {
1165                        return output;
1166                    }
1167                }
1168                output += temp;
1169            }
1170            return output;
1171        }
1172    }
[947]1173}
Note: See TracBrowser for help on using the repository browser.