Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

removed multi-command parsing (~pipe) in CommandExecutor

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