Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/core/CommandExecutor.cc @ 1056

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

don't panic, no codechanges!
added a link to www.orxonox.net

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