Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

some changes in commandexecutor and tclbind, but there's still a bug in the parameter evaluation

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