Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

CommandExecutor autocompletes now to correct casing (even if you're writing all lowercase or UPPERCASE or sOMethINg eLSe)

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