Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

tcl can now initialize itself by loading the *.tcl files from media/tcl

File size: 62.2 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    const CommandEvaluation& CommandExecutor::getLastEvaluation()
342    {
343        return CommandExecutor::getInstance().evaluation_;
344    }
345
346    Executor& CommandExecutor::addConsoleCommandShortcut(ExecutorStatic* executor)
347    {
348        CommandExecutor::getInstance().consoleCommandShortcuts_[executor->getName()] = executor;
349        CommandExecutor::getInstance().consoleCommandShortcuts_LC_[getLowercase(executor->getName())] = executor;
350        return (*executor);
351    }
352
353    /**
354        @brief Returns the executor of a console command shortcut with given name.
355        @brief name The name of the requested console command shortcut
356        @return The executor of the requested console command shortcut
357    */
358    ExecutorStatic* CommandExecutor::getConsoleCommandShortcut(const std::string& name)
359    {
360        std::map<std::string, ExecutorStatic*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_.find(name);
361        if (it != CommandExecutor::getInstance().consoleCommandShortcuts_.end())
362            return (*it).second;
363        else
364            return 0;
365    }
366
367    /**
368        @brief Returns the executor of a console command shortcut with given name in lowercase.
369        @brief name The name of the requested console command shortcut in lowercase
370        @return The executor of the requested console command shortcut
371    */
372    ExecutorStatic* CommandExecutor::getLowercaseConsoleCommandShortcut(const std::string& name)
373    {
374        std::map<std::string, ExecutorStatic*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_LC_.find(name);
375        if (it != CommandExecutor::getInstance().consoleCommandShortcuts_LC_.end())
376            return (*it).second;
377        else
378            return 0;
379    }
380
381    bool CommandExecutor::execute(const std::string& command)
382    {
383        if ((CommandExecutor::getEvaluation().processedCommand_ != command) || (CommandExecutor::getEvaluation().state_ == CS_Uninitialized))
384            CommandExecutor::parse(command);
385
386        return CommandExecutor::execute(CommandExecutor::getEvaluation());
387    }
388
389
390    bool CommandExecutor::execute(const CommandEvaluation& evaluation)
391    {
392        SubString tokens(evaluation.processedCommand_, " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0');
393
394        if (evaluation.bEvaluatedParams_ && evaluation.evaluatedExecutor_)
395        {
396std::cout << "CE_execute (evaluation): " << evaluation.evaluatedExecutor_->getName() << " " << evaluation.param_[0] << " " << evaluation.param_[1] << " " << evaluation.param_[2] << " " << evaluation.param_[3] << " " << evaluation.param_[4] << std::endl;
397            (*evaluation.evaluatedExecutor_)(evaluation.param_[0], evaluation.param_[1], evaluation.param_[2], evaluation.param_[3], evaluation.param_[4]);
398            return true;
399        }
400
401std::cout << "CE_execute: " << evaluation.processedCommand_ << "\n";
402        switch (evaluation.state_)
403        {
404            case CS_Uninitialized:
405                break;
406            case CS_Empty:
407                break;
408            case CS_FunctionClass_Or_Shortcut_Or_Keyword:
409                break;
410            case CS_Shortcut_Params:
411                // not enough parameters but lets hope there are some additional parameters and go on
412            case CS_Shortcut_Finished:
413                // call the shortcut
414                if (evaluation.shortcut_)
415                {
416                    if (tokens.size() >= 2)
417                        return evaluation.shortcut_->parse(removeSlashes(tokens.subSet(1).join() + evaluation.getAdditionalParameter()));
418                    else
419                        return evaluation.shortcut_->parse(removeSlashes(evaluation.additionalParameter_));
420                }
421                break;
422            case CS_Function:
423                break;
424            case CS_Function_Params:
425                // not enough parameters but lets hope there are some additional parameters and go on
426            case CS_Function_Finished:
427                // call the shortcut
428                if (evaluation.function_)
429                {
430                    if (tokens.size() >= 3)
431                        return evaluation.function_->parse(removeSlashes(tokens.subSet(2).join() + evaluation.getAdditionalParameter()));
432                    else
433                        return evaluation.function_->parse(removeSlashes(evaluation.additionalParameter_));
434                }
435                break;
436            case CS_ConfigValueClass:
437                break;
438            case CS_ConfigValue:
439                break;
440            case CS_ConfigValueType:
441                // not enough parameters but lets hope there are some additional parameters and go on
442            case CS_ConfigValueFinished:
443                // set the config value
444                if (evaluation.configvalue_)
445                {
446                    if ((tokens.size() >= 1) && (tokens[0] == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE))
447                    {
448                        if (tokens.size() >= 4)
449                            return evaluation.configvalue_->set(removeSlashes(tokens.subSet(3).join() + evaluation.getAdditionalParameter()));
450                        else
451                            return evaluation.configvalue_->set(removeSlashes(evaluation.additionalParameter_));
452                    }
453                    else if ((tokens.size() >= 1) && (tokens[0] == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY))
454                    {
455                        if (tokens.size() >= 4)
456                            return evaluation.configvalue_->tset(removeSlashes(tokens.subSet(3).join() + evaluation.getAdditionalParameter()));
457                        else
458                            return evaluation.configvalue_->tset(removeSlashes(evaluation.additionalParameter_));
459                    }
460                }
461                break;
462            case CS_KeybindKey:
463                break;
464            case CS_KeybindCommand:
465                // not enough parameters but lets hope there are some additional parameters and go on
466            case CS_KeybindFinished:
467                // set the keybind
468                // ...todo
469                break;
470            case CS_Error:
471                break;
472        }
473
474        return false;
475    }
476
477    std::string CommandExecutor::complete(const std::string& command)
478    {
479        if ((CommandExecutor::getEvaluation().processedCommand_ != command) || (CommandExecutor::getEvaluation().state_ == CS_Uninitialized))
480            CommandExecutor::parse(command);
481
482        return CommandExecutor::complete(CommandExecutor::getEvaluation());
483    }
484
485    std::string CommandExecutor::complete(const CommandEvaluation& evaluation)
486    {
487        SubString tokens(evaluation.processedCommand_, " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0');
488
489        std::list<std::pair<const std::string*, const std::string*> > temp;
490        if (evaluation.state_ == CS_Empty)
491        {
492            temp.insert(temp.end(), evaluation.listOfPossibleShortcuts_.begin(), evaluation.listOfPossibleShortcuts_.end());
493            temp.insert(temp.end(), evaluation.listOfPossibleFunctionClasses_.begin(), evaluation.listOfPossibleFunctionClasses_.end());
494        }
495
496        switch (evaluation.state_)
497        {
498            case CS_Uninitialized:
499                break;
500            case CS_Empty:
501                return (CommandExecutor::getCommonBegin(temp));
502                break;
503            case CS_FunctionClass_Or_Shortcut_Or_Keyword:
504                break;
505            case CS_Shortcut_Params:
506                if (evaluation.shortcut_)
507                    return (evaluation.shortcut_->getName() + " ");
508                break;
509            case CS_Shortcut_Finished:
510                if (evaluation.shortcut_)
511                {
512                    if (evaluation.shortcut_->getParamCount() == 0)
513                        return (evaluation.shortcut_->getName());
514                    else if (tokens.size() >= 2)
515                        return (evaluation.shortcut_->getName() + " " + tokens.subSet(1).join());
516                }
517                break;
518            case CS_Function:
519                if (evaluation.functionclass_)
520                    return (evaluation.functionclass_->getName() + " " + CommandExecutor::getCommonBegin(evaluation.listOfPossibleFunctions_));
521                break;
522            case CS_Function_Params:
523                if (evaluation.functionclass_ && evaluation.function_)
524                    return (evaluation.functionclass_->getName() + " " + evaluation.function_->getName() + " ");
525                break;
526            case CS_Function_Finished:
527                if (evaluation.functionclass_ && evaluation.function_)
528                {
529                    if (evaluation.function_->getParamCount() == 0)
530                        return (evaluation.functionclass_->getName() + " " + evaluation.function_->getName());
531                    else if (tokens.size() >= 3)
532                        return (evaluation.functionclass_->getName() + " " + evaluation.function_->getName() + " " + tokens.subSet(2).join());
533                }
534                break;
535            case CS_ConfigValueClass:
536                if (tokens.size() >= 1)
537                    return (tokens[0] + " " + CommandExecutor::getCommonBegin(evaluation.listOfPossibleConfigValueClasses_));
538                break;
539            case CS_ConfigValue:
540                if ((tokens.size() >= 1) && evaluation.configvalueclass_)
541                    return (tokens[0] + " " + evaluation.configvalueclass_->getName() + " " + CommandExecutor::getCommonBegin(evaluation.listOfPossibleConfigValues_));
542                break;
543            case CS_ConfigValueType:
544                if ((tokens.size() >= 1) && evaluation.configvalueclass_ && evaluation.configvalue_)
545                    return (tokens[0] + " " + evaluation.configvalueclass_->getName() + " " + evaluation.configvalue_->getName() + " ");
546                break;
547            case CS_ConfigValueFinished:
548                if ((tokens.size() >= 1) && evaluation.configvalueclass_ && evaluation.configvalue_ && (tokens.size() >= 4))
549                    return (tokens[0] + " " + evaluation.configvalueclass_->getName() + " " + evaluation.configvalue_->getName() + " " + tokens.subSet(3).join());
550                break;
551            case CS_KeybindKey:
552                if (tokens.size() >= 1)
553                    return (tokens[0] + " " + CommandExecutor::getCommonBegin(evaluation.listOfPossibleKeys_));
554                break;
555            case CS_KeybindCommand:
556                if ((evaluation.processedCommand_.size() >= 1) && (evaluation.processedCommand_[evaluation.processedCommand_.size() - 1] != ' '))
557                    return (evaluation.processedCommand_ + " ");
558                break;
559            case CS_KeybindFinished:
560                break;
561            case CS_Error:
562                break;
563        }
564
565        return evaluation.processedCommand_;
566    }
567
568    std::string CommandExecutor::hint(const std::string& command)
569    {
570        if ((CommandExecutor::getEvaluation().processedCommand_ != command) || (CommandExecutor::getEvaluation().state_ == CS_Uninitialized))
571            CommandExecutor::parse(command);
572
573        return CommandExecutor::hint(CommandExecutor::getEvaluation());
574    }
575
576    std::string CommandExecutor::hint(const CommandEvaluation& evaluation)
577    {
578        SubString tokens(evaluation.processedCommand_, " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0');
579
580        switch (evaluation.state_)
581        {
582            case CS_Uninitialized:
583                break;
584            case CS_Empty:
585                return (CommandExecutor::dump(evaluation.listOfPossibleShortcuts_) + "\n" + CommandExecutor::dump(evaluation.listOfPossibleFunctionClasses_));
586                break;
587            case CS_FunctionClass_Or_Shortcut_Or_Keyword:
588                break;
589            case CS_Shortcut_Params:
590                if (evaluation.shortcut_)
591                    return CommandExecutor::dump(evaluation.shortcut_);
592                break;
593            case CS_Shortcut_Finished:
594                if (evaluation.shortcut_)
595                    return CommandExecutor::dump(evaluation.shortcut_);
596                break;
597            case CS_Function:
598                return CommandExecutor::dump(evaluation.listOfPossibleFunctions_);
599                break;
600            case CS_Function_Params:
601                if (evaluation.function_)
602                    return CommandExecutor::dump(evaluation.function_);
603                break;
604            case CS_Function_Finished:
605                if (evaluation.function_)
606                    return CommandExecutor::dump(evaluation.function_);
607                break;
608            case CS_ConfigValueClass:
609                return CommandExecutor::dump(evaluation.listOfPossibleConfigValueClasses_);
610                break;
611            case CS_ConfigValue:
612                return CommandExecutor::dump(evaluation.listOfPossibleConfigValues_);
613                break;
614            case CS_ConfigValueType:
615                if (evaluation.configvalue_)
616                    return CommandExecutor::dump(evaluation.configvalue_);
617                break;
618            case CS_ConfigValueFinished:
619                if (evaluation.configvalue_)
620                    return CommandExecutor::dump(evaluation.configvalue_);
621                break;
622            case CS_KeybindKey:
623                return CommandExecutor::dump(evaluation.listOfPossibleKeys_);
624                break;
625            case CS_KeybindCommand:
626                if (evaluation.key_)
627                    return CommandExecutor::dump(evaluation.key_);
628                break;
629            case CS_KeybindFinished:
630                if (evaluation.key_)
631                    return CommandExecutor::dump(evaluation.key_);
632                break;
633            case CS_Error:
634                return CommandExecutor::getEvaluation().errorMessage_;
635                break;
636        }
637
638        return "";
639    }
640
641    CommandEvaluation CommandExecutor::evaluate(const std::string& command)
642    {
643        CommandExecutor::parse(command, true);
644
645        if (CommandExecutor::getEvaluation().tokens_.size() > 0)
646        {
647            std::string lastToken;
648            lastToken = CommandExecutor::getEvaluation().tokens_[CommandExecutor::getEvaluation().tokens_.size() - 1];
649            lastToken = lastToken.substr(0, lastToken.size() - 1);
650            CommandExecutor::getEvaluation().tokens_.pop_back();
651            CommandExecutor::getEvaluation().tokens_.append(SubString(lastToken, " ", "", true, '\0', false, '\0', false, '\0', '\0', false, '\0'));
652        }
653
654        CommandExecutor::getEvaluation().evaluateParams();
655        return CommandExecutor::getEvaluation();
656    }
657
658    void CommandExecutor::parse(const std::string& command, bool bInitialize)
659    {
660        CommandExecutor::getEvaluation().tokens_.split((command + COMMAND_EXECUTOR_CURSOR), " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0');
661        CommandExecutor::getEvaluation().processedCommand_ = command;
662
663        if (bInitialize)
664            CommandExecutor::initialize(command);
665
666        switch (CommandExecutor::getEvaluation().state_)
667        {
668            case CS_Uninitialized:
669                // Impossible
670                break;
671            case CS_Empty:
672                if (CommandExecutor::argumentsGiven() == 0)
673                {
674                    // We want a hint for the first token
675                    // Check if there is already a perfect match
676                    CommandExecutor::getEvaluation().functionclass_ = CommandExecutor::getIdentifierOfPossibleFunctionClass(CommandExecutor::getToken(0));
677                    CommandExecutor::getEvaluation().shortcut_ = CommandExecutor::getExecutorOfPossibleShortcut(CommandExecutor::getToken(0));
678
679                    if ((CommandExecutor::getEvaluation().functionclass_) || (CommandExecutor::getEvaluation().shortcut_))
680                    {
681                        // Yes, there is a class or a shortcut with the searched name
682                        // Add a whitespace and continue parsing
683                        CommandExecutor::getEvaluation().state_ = CS_FunctionClass_Or_Shortcut_Or_Keyword;
684                        CommandExecutor::parse(command + " ", false);
685                        return;
686                    }
687
688                    // No perfect match: Create the lists of all possible classes and shortcuts and return
689                    CommandExecutor::createListOfPossibleFunctionClasses(CommandExecutor::getToken(0));
690                    CommandExecutor::createListOfPossibleShortcuts(CommandExecutor::getToken(0));
691
692                    // Check if there's only one possiblility
693                    if ((CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.size() == 1) && (CommandExecutor::getEvaluation().listOfPossibleShortcuts_.size() == 0))
694                    {
695                        // There's only one possible class
696                        CommandExecutor::getEvaluation().state_ = CS_Function;
697                        CommandExecutor::getEvaluation().functionclass_ = CommandExecutor::getIdentifierOfPossibleFunctionClass(*(*CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.begin()).first);
698                        CommandExecutor::parse(*(*CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.begin()).first + " ", false);
699                        return;
700                    }
701                    else if ((CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.size() == 0) && (CommandExecutor::getEvaluation().listOfPossibleShortcuts_.size() == 1))
702                    {
703                        if ((*(*CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin()).first != COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE)
704                         && (*(*CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin()).first != COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY)
705                         && (*(*CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin()).first != COMMAND_EXECUTOR_KEYWORD_SET_KEYBIND))
706                        {
707                            // There's only one possible shortcut
708                            CommandExecutor::getEvaluation().state_ = CS_Shortcut_Params;
709                            CommandExecutor::getEvaluation().shortcut_ = CommandExecutor::getExecutorOfPossibleShortcut(*(*CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin()).first);
710                        }
711                        else if ((*(*CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin()).first == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE)
712                              || (*(*CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin()).first == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY))
713                        {
714                            // It's the 'set' or 'tset' keyword
715                            CommandExecutor::getEvaluation().state_ = CS_ConfigValueClass;
716                        }
717                        else if (*(*CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin()).first != COMMAND_EXECUTOR_KEYWORD_SET_KEYBIND)
718                        {
719                            // It's the 'bind' keyword
720                            CommandExecutor::getEvaluation().state_ = CS_KeybindKey;
721                        }
722
723                        CommandExecutor::parse(*(*CommandExecutor::getEvaluation().listOfPossibleShortcuts_.begin()).first + " ", false);
724                        return;
725                    }
726
727                    // It's ambiguous
728                    return;
729                }
730                else
731                {
732                    // There is at least one argument: Check if it's a shortcut, a classname or a special keyword
733                    CommandExecutor::getEvaluation().state_ = CS_FunctionClass_Or_Shortcut_Or_Keyword;
734                    CommandExecutor::parse(command, false);
735                    return;
736                }
737                break;
738            case CS_FunctionClass_Or_Shortcut_Or_Keyword:
739                if (CommandExecutor::argumentsGiven() >= 1)
740                {
741                    if ((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE) || (CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY))
742                    {
743                        // We want to set a config value
744                        CommandExecutor::getEvaluation().state_ = CS_ConfigValueClass;
745                        CommandExecutor::parse(command, false);
746                        return;
747                    }
748                    else if (CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_KEYBIND)
749                    {
750                        // We want to set a keybinding
751                        CommandExecutor::getEvaluation().state_ = CS_KeybindKey;
752                        CommandExecutor::parse(command, false);
753                        return;
754                    }
755
756                    if (!CommandExecutor::getEvaluation().functionclass_)
757                        CommandExecutor::getEvaluation().functionclass_ = CommandExecutor::getIdentifierOfPossibleFunctionClass(CommandExecutor::getToken(0));
758                    if (!CommandExecutor::getEvaluation().shortcut_)
759                        CommandExecutor::getEvaluation().shortcut_ = CommandExecutor::getExecutorOfPossibleShortcut(CommandExecutor::getToken(0));
760
761                    if ((!CommandExecutor::getEvaluation().functionclass_) && (!CommandExecutor::getEvaluation().shortcut_))
762                    {
763                        // Argument 1 seems to be wrong
764                        AddLanguageEntry("CommandExecutor::NoSuchCommandOrClassName", "No such command or classname");
765                        CommandExecutor::getEvaluation().errorMessage_ = (CommandExecutor::getToken(0) + ": " + GetLocalisation("CommandExecutor::NoSuchCommandOrClassName"));
766                        CommandExecutor::getEvaluation().state_ = CS_Error;
767                        return;
768                    }
769                    else if (CommandExecutor::getEvaluation().shortcut_)
770                    {
771                        // Argument 1 is a shortcut: Return the needed parameter types
772                        CommandExecutor::getEvaluation().state_ = CS_Shortcut_Params;
773                        CommandExecutor::parse(command, false);
774                        return;
775                    }
776                    else
777                    {
778                        // Argument 1 is a classname: Return the possible functions
779                        CommandExecutor::getEvaluation().state_ = CS_Function;
780                        CommandExecutor::parse(command, false);
781                        return;
782                    }
783                }
784                else
785                {
786                    CommandExecutor::getEvaluation().state_ = CS_Error;
787                    return;
788                }
789                break;
790            case CS_Shortcut_Params:
791                if (CommandExecutor::getEvaluation().shortcut_)
792                {
793                    // Valid command
794                    // Check if there are enough parameters
795                    if (CommandExecutor::enoughParametersGiven(1, CommandExecutor::getEvaluation().shortcut_))
796                    {
797                        CommandExecutor::getEvaluation().state_ = CS_Shortcut_Finished;
798                        return;
799                    }
800                }
801                else
802                {
803                    // Something is wrong
804                    CommandExecutor::getEvaluation().state_ = CS_Error;
805                    return;
806                }
807                break;
808            case CS_Function:
809                if (CommandExecutor::getEvaluation().functionclass_)
810                {
811                    // We have a valid classname
812                    // Check if there is a second argument
813                    if (CommandExecutor::argumentsGiven() >= 2)
814                    {
815                        // There is a second argument: Check if it's a valid functionname
816                        CommandExecutor::getEvaluation().function_ = CommandExecutor::getExecutorOfPossibleFunction(CommandExecutor::getToken(1), CommandExecutor::getEvaluation().functionclass_);
817                        if (!CommandExecutor::getEvaluation().function_)
818                        {
819                            // Argument 2 seems to be wrong
820                            AddLanguageEntry("CommandExecutor::NoSuchFunctionnameIn", "No such functionname in");
821                            CommandExecutor::getEvaluation().errorMessage_ = (CommandExecutor::getToken(1) + ": " + GetLocalisation("CommandExecutor::NoSuchFunctionnameIn") + " " + CommandExecutor::getEvaluation().functionclass_->getName());
822                            CommandExecutor::getEvaluation().state_ = CS_Error;
823                            return;
824                        }
825                        else
826                        {
827                            // Argument 2 seems to be a valid functionname: Get the parameters
828                            CommandExecutor::getEvaluation().state_ = CS_Function_Params;
829                            CommandExecutor::parse(command, false);
830                            return;
831                        }
832                    }
833                    else
834                    {
835                        // There is no finished second argument
836                        // Check if there's already a perfect match
837                        if (CommandExecutor::getEvaluation().tokens_.size() >= 2)
838                        {
839                            CommandExecutor::getEvaluation().function_ = CommandExecutor::getExecutorOfPossibleFunction(CommandExecutor::getToken(1), CommandExecutor::getEvaluation().functionclass_);
840                            if (CommandExecutor::getEvaluation().function_)
841                            {
842                                // There is a perfect match: Add a whitespace and continue parsing
843                                CommandExecutor::getEvaluation().state_ = CS_Function_Params;
844                                CommandExecutor::parse(command + " ", false);
845                                return;
846                            }
847                        }
848
849                        // No perfect match: Create the list of all possible functions and return
850                        CommandExecutor::createListOfPossibleFunctions(CommandExecutor::getToken(1), CommandExecutor::getEvaluation().functionclass_);
851
852                        // Check if there's only one possiblility
853                        if (CommandExecutor::getEvaluation().listOfPossibleFunctions_.size() == 1)
854                        {
855                            // There's only one possible function
856                            CommandExecutor::getEvaluation().state_ = CS_Function_Params;
857                            CommandExecutor::getEvaluation().function_ = CommandExecutor::getExecutorOfPossibleFunction(*(*CommandExecutor::getEvaluation().listOfPossibleFunctions_.begin()).first, CommandExecutor::getEvaluation().functionclass_);
858                            CommandExecutor::parse(CommandExecutor::getToken(0) + " " + *(*CommandExecutor::getEvaluation().listOfPossibleFunctions_.begin()).first + " ", false);
859                            return;
860                        }
861
862                        // It's ambiguous
863                        return;
864                    }
865                }
866                else
867                {
868                    CommandExecutor::getEvaluation().state_ = CS_Error;
869                    return;
870                }
871                break;
872            case CS_Function_Params:
873                if (CommandExecutor::getEvaluation().functionclass_ && CommandExecutor::getEvaluation().function_)
874                {
875                    // Valid command
876                    // Check if there are enough parameters
877                    if (CommandExecutor::enoughParametersGiven(2, CommandExecutor::getEvaluation().function_))
878                    {
879                        CommandExecutor::getEvaluation().state_ = CS_Function_Finished;
880                        return;
881                    }
882                }
883                else
884                {
885                    // Something is wrong
886                    CommandExecutor::getEvaluation().state_ = CS_Error;
887                    return;
888                }
889                break;
890            case CS_ConfigValueClass:
891                if (((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE) || (CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY)))
892                {
893                    // We want to set a config value
894                    // Check if there is a second argument
895                    if (CommandExecutor::argumentsGiven() >= 2)
896                    {
897                        // There is a second argument: Check if it's a valid classname
898                        CommandExecutor::getEvaluation().configvalueclass_ = CommandExecutor::getIdentifierOfPossibleConfigValueClass(CommandExecutor::getToken(1));
899                        if (!CommandExecutor::getEvaluation().configvalueclass_)
900                        {
901                            // Argument 2 seems to be wrong
902                            AddLanguageEntry("CommandExecutor::NoSuchClassWithConfigValues", "No such class with config values");
903                            CommandExecutor::getEvaluation().errorMessage_ = (CommandExecutor::getToken(1) + ": " + GetLocalisation("CommandExecutor::NoSuchClassWithConfigValues"));
904                            CommandExecutor::getEvaluation().state_ = CS_Error;
905                            return;
906                        }
907                        else
908                        {
909                            // Argument 2 seems to be a valid classname: Search for possible config values
910                            CommandExecutor::getEvaluation().state_ = CS_ConfigValue;
911                            CommandExecutor::parse(command, false);
912                            return;
913                        }
914                    }
915                    else
916                    {
917                        // There's no finished second argument
918                        // Check if there's already a perfect match
919                        if (CommandExecutor::getEvaluation().tokens_.size() >= 2)
920                        {
921                            CommandExecutor::getEvaluation().configvalueclass_ = CommandExecutor::getIdentifierOfPossibleConfigValueClass(CommandExecutor::getToken(1));
922                            if (CommandExecutor::getEvaluation().configvalueclass_)
923                            {
924                                // There is a perfect match: Add a whitespace and continue parsing
925                                CommandExecutor::getEvaluation().state_ = CS_ConfigValue;
926                                CommandExecutor::parse(command + " ", false);
927                                return;
928                            }
929                        }
930
931                        // No perfect match: Create the list of all possible classnames and return
932                        CommandExecutor::createListOfPossibleConfigValueClasses(CommandExecutor::getToken(1));
933
934                        // Check if there's only one possiblility
935                        if (CommandExecutor::getEvaluation().listOfPossibleConfigValueClasses_.size() == 1)
936                        {
937                            // There's only one possible classname
938                            CommandExecutor::getEvaluation().state_ = CS_ConfigValue;
939                            CommandExecutor::getEvaluation().configvalueclass_ = CommandExecutor::getIdentifierOfPossibleConfigValueClass(*(*CommandExecutor::getEvaluation().listOfPossibleConfigValueClasses_.begin()).first);
940                            CommandExecutor::parse(CommandExecutor::getToken(0) + " " + *(*CommandExecutor::getEvaluation().listOfPossibleConfigValueClasses_.begin()).first + " ", false);
941                            return;
942                        }
943
944                        // It's ambiguous
945                        return;
946                    }
947                }
948                else
949                {
950                    // Something is wrong
951                    CommandExecutor::getEvaluation().state_ = CS_Error;
952                    return;
953                }
954                break;
955            case CS_ConfigValue:
956                if (((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE) || (CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE_TEMPORARY)) && (CommandExecutor::getEvaluation().configvalueclass_))
957                {
958                    // Check if there is a third argument
959                    if (CommandExecutor::argumentsGiven() >= 3)
960                    {
961                        // There is a third argument: Check if it's a valid config value
962                        CommandExecutor::getEvaluation().configvalue_ = CommandExecutor::getContainerOfPossibleConfigValue(CommandExecutor::getToken(2), CommandExecutor::getEvaluation().configvalueclass_);
963                        if (!CommandExecutor::getEvaluation().configvalue_)
964                        {
965                            // Argument 3 seems to be wrong
966                            AddLanguageEntry("CommandExecutor::NoSuchConfigValueIn", "No such config value in");
967                            CommandExecutor::getEvaluation().errorMessage_ = (CommandExecutor::getToken(2) + ": " + GetLocalisation("CommandExecutor::NoSuchConfigValueIn") + " " + CommandExecutor::getEvaluation().configvalueclass_->getName());
968                            CommandExecutor::getEvaluation().state_ = CS_Error;
969                            return;
970                        }
971                        else
972                        {
973                            // Argument 3 seems to be a valid config value: Get the type
974                            CommandExecutor::getEvaluation().state_ = CS_ConfigValueType;
975                            CommandExecutor::parse(command, false);
976                            return;
977                        }
978                    }
979                    else
980                    {
981                        // There is no finished third argument
982                        // Check if there's already a perfect match
983                        if (CommandExecutor::getEvaluation().tokens_.size() >= 3)
984                        {
985                            CommandExecutor::getEvaluation().configvalue_ = CommandExecutor::getContainerOfPossibleConfigValue(CommandExecutor::getToken(2), CommandExecutor::getEvaluation().configvalueclass_);
986                            if (CommandExecutor::getEvaluation().configvalue_)
987                            {
988                                // There is a perfect match: Add a whitespace and continue parsing
989                                CommandExecutor::getEvaluation().state_ = CS_ConfigValueType;
990                                CommandExecutor::parse(command + " ", false);
991                                return;
992                            }
993                        }
994
995                        // No perfect match: Create the list of all possible config values
996                        CommandExecutor::createListOfPossibleConfigValues(CommandExecutor::getToken(2), CommandExecutor::getEvaluation().configvalueclass_);
997
998                        // Check if there's only one possiblility
999                        if (CommandExecutor::getEvaluation().listOfPossibleConfigValues_.size() == 1)
1000                        {
1001                            // There's only one possible config value
1002                            CommandExecutor::getEvaluation().state_ = CS_ConfigValueType;
1003                            CommandExecutor::getEvaluation().configvalue_ = CommandExecutor::getContainerOfPossibleConfigValue(*(*CommandExecutor::getEvaluation().listOfPossibleConfigValues_.begin()).first, CommandExecutor::getEvaluation().configvalueclass_);
1004                            CommandExecutor::parse(CommandExecutor::getToken(0) + " " + CommandExecutor::getToken(1) + " " + *(*CommandExecutor::getEvaluation().listOfPossibleConfigValues_.begin()).first + " ", false);
1005                            return;
1006                        }
1007
1008                        // It's ambiguous
1009                        return;
1010                    }
1011                }
1012                else
1013                {
1014                    // Something is wrong
1015                    CommandExecutor::getEvaluation().state_ = CS_Error;
1016                    return;
1017                }
1018                break;
1019            case CS_ConfigValueType:
1020                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_)
1021                {
1022                    // Valid command
1023                    // Check if there are enough parameters
1024                    if ((CommandExecutor::getEvaluation().tokens_.size() >= 4) && (CommandExecutor::getEvaluation().tokens_[3] != COMMAND_EXECUTOR_CURSOR))
1025                    {
1026                        CommandExecutor::getEvaluation().state_ = CS_ConfigValueFinished;
1027                        return;
1028                    }
1029                }
1030                else
1031                {
1032                    // Something is wrong
1033                    CommandExecutor::getEvaluation().state_ = CS_Error;
1034                    return;
1035                }
1036                break;
1037            case CS_KeybindKey:
1038                if ((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_KEYBIND))
1039                {
1040                    // todo
1041                }
1042                else
1043                {
1044                    // Something is wrong
1045                    CommandExecutor::getEvaluation().state_ = CS_Error;
1046                    return;
1047                }
1048                break;
1049            case CS_KeybindCommand:
1050                if ((CommandExecutor::getToken(0) == COMMAND_EXECUTOR_KEYWORD_SET_KEYBIND) && (false)) // todo
1051                {
1052                    // Valid command
1053                    // Check if there are enough parameters
1054                    if (CommandExecutor::getEvaluation().tokens_.size() >= 3)
1055                    {
1056                        CommandExecutor::getEvaluation().state_ = CS_KeybindFinished;
1057                        return;
1058                    }
1059
1060                }
1061                else
1062                {
1063                    // Something is wrong
1064                    CommandExecutor::getEvaluation().state_ = CS_Error;
1065                    return;
1066                }
1067                break;
1068            case CS_Shortcut_Finished:
1069                // Nothing to do
1070                break;
1071            case CS_Function_Finished:
1072                // Nothing to do
1073                break;
1074            case CS_ConfigValueFinished:
1075                // Nothing to do
1076                break;
1077            case CS_KeybindFinished:
1078                // Nothing to do
1079                break;
1080            case CS_Error:
1081                // This is bad
1082                break;
1083        }
1084    }
1085
1086    void CommandExecutor::initialize(const std::string& command)
1087    {
1088        CommandExecutor::getEvaluation().processedCommand_ = command;
1089        CommandExecutor::getEvaluation().additionalParameter_ = "";
1090
1091        CommandExecutor::getEvaluation().bEvaluatedParams_ = false;
1092        CommandExecutor::getEvaluation().evaluatedExecutor_ = 0;
1093
1094        CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.clear();
1095        CommandExecutor::getEvaluation().listOfPossibleShortcuts_.clear();
1096        CommandExecutor::getEvaluation().listOfPossibleFunctions_.clear();
1097        CommandExecutor::getEvaluation().listOfPossibleConfigValueClasses_.clear();
1098        CommandExecutor::getEvaluation().listOfPossibleConfigValues_.clear();
1099        CommandExecutor::getEvaluation().listOfPossibleKeys_.clear();
1100
1101        CommandExecutor::getEvaluation().functionclass_ = 0;
1102        CommandExecutor::getEvaluation().configvalueclass_ = 0;
1103        CommandExecutor::getEvaluation().shortcut_ = 0;
1104        CommandExecutor::getEvaluation().function_ = 0;
1105        CommandExecutor::getEvaluation().configvalue_ = 0;
1106        CommandExecutor::getEvaluation().key_ = 0;
1107
1108        CommandExecutor::getEvaluation().errorMessage_ = "";
1109        CommandExecutor::getEvaluation().state_ = CS_Empty;
1110    }
1111
1112    bool CommandExecutor::argumentsGiven(unsigned int num)
1113    {
1114        // Because we added a cursor we have +1 arguments
1115        // There are num arguments given if there are at least num arguments + one cursor
1116        return (CommandExecutor::getEvaluation().tokens_.size() >= (num + 1));
1117    }
1118
1119    unsigned int CommandExecutor::argumentsGiven()
1120    {
1121        // Because we added a cursor we have +1 arguments
1122        if (CommandExecutor::getEvaluation().tokens_.size() >= 1)
1123            return (CommandExecutor::getEvaluation().tokens_.size() - 1);
1124        else
1125            return 0;
1126    }
1127
1128    std::string CommandExecutor::getToken(unsigned int index)
1129    {
1130        if ((index >= 0) && (index < (CommandExecutor::getEvaluation().tokens_.size() - 1)))
1131            return CommandExecutor::getEvaluation().tokens_[index];
1132        else if (index == (CommandExecutor::getEvaluation().tokens_.size() - 1))
1133            return CommandExecutor::getEvaluation().tokens_[index].substr(0, CommandExecutor::getEvaluation().tokens_[index].size() - 1);
1134        else
1135            return "";
1136    }
1137
1138    bool CommandExecutor::enoughParametersGiven(unsigned int head, Executor* executor)
1139    {
1140        unsigned int neededParams = head + executor->getParamCount();
1141        /*
1142        for (unsigned int i = executor->getParamCount() - 1; i >= 0; i--)
1143        {
1144            if (executor->defaultValueSet(i))
1145                neededParams--;
1146            else
1147                break;
1148        }
1149        */
1150        return ((CommandExecutor::getEvaluation().tokens_.size() >= neededParams) && (CommandExecutor::getEvaluation().tokens_[neededParams - 1] != COMMAND_EXECUTOR_CURSOR));
1151    }
1152
1153    void CommandExecutor::createListOfPossibleFunctionClasses(const std::string& fragment)
1154    {
1155        for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseIdentifierMapBegin(); it != Identifier::getLowercaseIdentifierMapEnd(); ++it)
1156        {
1157            if ((*it).second->hasConsoleCommands())
1158            {
1159                if ((*it).first.find(getLowercase(fragment)) == 0 || fragment == "")
1160                {
1161                    CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName()));
1162                }
1163            }
1164        }
1165
1166        CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.sort(CommandExecutor::compareStringsInList);
1167    }
1168
1169    void CommandExecutor::createListOfPossibleShortcuts(const std::string& fragment)
1170    {
1171        for (std::map<std::string, ExecutorStatic*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMapBegin(); it != CommandExecutor::getLowercaseConsoleCommandShortcutMapEnd(); ++it)
1172        {
1173            if ((*it).first.find(getLowercase(fragment)) == 0 || fragment == "")
1174            {
1175                CommandExecutor::getEvaluation().listOfPossibleShortcuts_.push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName()));
1176            }
1177        }
1178
1179        CommandExecutor::getEvaluation().listOfPossibleShortcuts_.sort(CommandExecutor::compareStringsInList);
1180    }
1181
1182    void CommandExecutor::createListOfPossibleFunctions(const std::string& fragment, Identifier* identifier)
1183    {
1184        for (std::map<std::string, ExecutorStatic*>::const_iterator it = identifier->getLowercaseConsoleCommandMapBegin(); it != identifier->getLowercaseConsoleCommandMapEnd(); ++it)
1185        {
1186            if ((*it).first.find(getLowercase(fragment)) == 0 || fragment == "")
1187            {
1188                CommandExecutor::getEvaluation().listOfPossibleFunctions_.push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName()));
1189            }
1190        }
1191
1192        CommandExecutor::getEvaluation().listOfPossibleFunctions_.sort(CommandExecutor::compareStringsInList);
1193    }
1194
1195    void CommandExecutor::createListOfPossibleConfigValueClasses(const std::string& fragment)
1196    {
1197        for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseIdentifierMapBegin(); it != Identifier::getLowercaseIdentifierMapEnd(); ++it)
1198        {
1199            if ((*it).second->hasConfigValues())
1200            {
1201                if ((*it).first.find(getLowercase(fragment)) == 0 || fragment == "")
1202                {
1203                    CommandExecutor::getEvaluation().listOfPossibleConfigValueClasses_.push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName()));
1204                }
1205            }
1206        }
1207
1208        CommandExecutor::getEvaluation().listOfPossibleConfigValueClasses_.sort(CommandExecutor::compareStringsInList);
1209    }
1210
1211    void CommandExecutor::createListOfPossibleConfigValues(const std::string& fragment, Identifier* identifier)
1212    {
1213        for (std::map<std::string, ConfigValueContainer*>::const_iterator it = identifier->getLowercaseConfigValueMapBegin(); it != identifier->getLowercaseConfigValueMapEnd(); ++it)
1214        {
1215            if ((*it).first.find(getLowercase(fragment)) == 0 || fragment == "")
1216            {
1217                CommandExecutor::getEvaluation().listOfPossibleConfigValues_.push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName()));
1218            }
1219        }
1220
1221        CommandExecutor::getEvaluation().listOfPossibleConfigValues_.sort(CommandExecutor::compareStringsInList);
1222    }
1223
1224    void CommandExecutor::createListOfPossibleKeys(const std::string& fragment)
1225    {
1226        // todo
1227
1228        CommandExecutor::getEvaluation().listOfPossibleKeys_.sort(CommandExecutor::compareStringsInList);
1229    }
1230
1231    bool CommandExecutor::compareStringsInList(const std::pair<const std::string*, const std::string*>& first, const std::pair<const std::string*, const std::string*>& second)
1232    {
1233        return ((*first.first) < (*second.first));
1234    }
1235
1236    Identifier* CommandExecutor::getIdentifierOfPossibleFunctionClass(const std::string& name)
1237    {
1238        std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseIdentifierMap().find(getLowercase(name));
1239        if ((it != Identifier::getLowercaseIdentifierMapEnd()) && (*it).second->hasConsoleCommands())
1240            return (*it).second;
1241
1242        return 0;
1243    }
1244
1245    ExecutorStatic* CommandExecutor::getExecutorOfPossibleShortcut(const std::string& name)
1246    {
1247        std::map<std::string, ExecutorStatic*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMap().find(getLowercase(name));
1248        if (it != CommandExecutor::getLowercaseConsoleCommandShortcutMapEnd())
1249            return (*it).second;
1250
1251        return 0;
1252    }
1253
1254    ExecutorStatic* CommandExecutor::getExecutorOfPossibleFunction(const std::string& name, Identifier* identifier)
1255    {
1256        std::map<std::string, ExecutorStatic*>::const_iterator it = identifier->getLowercaseConsoleCommandMap().find(getLowercase(name));
1257        if (it != identifier->getLowercaseConsoleCommandMapEnd())
1258            return (*it).second;
1259
1260        return 0;
1261    }
1262
1263    Identifier* CommandExecutor::getIdentifierOfPossibleConfigValueClass(const std::string& name)
1264    {
1265        std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseIdentifierMap().find(getLowercase(name));
1266        if ((it != Identifier::getLowercaseIdentifierMapEnd()) && (*it).second->hasConfigValues())
1267            return (*it).second;
1268
1269        return 0;
1270    }
1271
1272    ConfigValueContainer* CommandExecutor::getContainerOfPossibleConfigValue(const std::string& name, Identifier* identifier)
1273    {
1274        std::map<std::string, ConfigValueContainer*>::const_iterator it = identifier->getLowercaseConfigValueMap().find(getLowercase(name));
1275        if (it != identifier->getLowercaseConfigValueMapEnd())
1276        {
1277            return (*it).second;
1278        }
1279
1280        return 0;
1281    }
1282
1283    ConfigValueContainer* CommandExecutor::getContainerOfPossibleKey(const std::string& name)
1284    {
1285        // todo
1286
1287        return 0;
1288    }
1289
1290    std::string CommandExecutor::dump(const std::list<std::pair<const std::string*, const std::string*> >& list)
1291    {
1292        std::string output = "";
1293        for (std::list<std::pair<const std::string*, const std::string*> >::const_iterator it = list.begin(); it != list.end(); ++it)
1294        {
1295            if (it != list.begin())
1296                output += " ";
1297
1298            output += *(*it).second;
1299        }
1300        return output;
1301    }
1302
1303    std::string CommandExecutor::dump(const ExecutorStatic* executor)
1304    {
1305        std::string output = "";
1306        for (unsigned int i = 0; i < executor->getParamCount(); i++)
1307        {
1308            if (i != 0)
1309                output += " ";
1310
1311            if (executor->defaultValueSet(i))
1312                output += "[";
1313            else
1314                output += "{";
1315
1316            output += executor->getTypenameParam(i);
1317
1318            if (executor->defaultValueSet(i))
1319                output += "=" + executor->getDefaultValue(i).toString() + "]";
1320            else
1321                output += "}";
1322        }
1323        return output;
1324    }
1325
1326    std::string CommandExecutor::dump(const ConfigValueContainer* container)
1327    {
1328        AddLanguageEntry("CommandExecutor::oldvalue", "old value");
1329        if (!container->isVector())
1330            return ("{" + container->getTypename() + "} (" + GetLocalisation("CommandExecutor::oldvalue") + ": " + container->toString() + ")");
1331        else
1332            return ("(vector<" + container->getTypename() + ">) (size: " + getConvertedValue<unsigned int, std::string>(container->getVectorSize()) + ")");
1333    }
1334
1335    std::string CommandExecutor::getCommonBegin(const std::list<std::pair<const std::string*, const std::string*> >& list)
1336    {
1337        if (list.size() == 0)
1338        {
1339            return "";
1340        }
1341        else if (list.size() == 1)
1342        {
1343            return ((*(*list.begin()).first) + " ");
1344        }
1345        else
1346        {
1347            std::string output = "";
1348            for (unsigned int i = 0; true; i++)
1349            {
1350                char temp = 0;
1351                for (std::list<std::pair<const std::string*, const std::string*> >::const_iterator it = list.begin(); it != list.end(); ++it)
1352                {
1353                    if ((*(*it).first).size() > i)
1354                    {
1355                        if (it == list.begin())
1356                        {
1357                            temp = (*(*it).first)[i];
1358                        }
1359                        else
1360                        {
1361                            if (temp != (*(*it).first)[i])
1362                                return output;
1363                        }
1364                    }
1365                    else
1366                    {
1367                        return output;
1368                    }
1369                }
1370                output += temp;
1371            }
1372            return output;
1373        }
1374    }
1375}
Note: See TracBrowser for help on using the repository browser.