Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/console/src/core/CommandExecutor.cc @ 1189

Last change on this file since 1189 was 1189, checked in by landauf, 17 years ago

removed some debug output

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