Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

removed some bugs
tcl knows now orxonox

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