Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core2/src/orxonox/core/CommandExecutor.cc @ 967

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

hum, i forgot what i was doing there… oh wait, i remember… it had something to do with executor evaluation. strange thing, no wonder my brain has a leak or something… what's that SVN thing all around my cursor? what's a cursor anyway? oh, and what am i doing here? i feel like having breakfast and it's all dark… stupid clock change…

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