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