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