Changeset 1434 for code/branches/console/src/core/CommandExecutor.cc
- Timestamp:
- May 27, 2008, 12:27:13 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/console/src/core/CommandExecutor.cc
r1430 r1434 126 126 void CommandExecutor::parseIfNeeded(const std::string& command) 127 127 { 128 std::cout << "parse if needed: command: >" << command << "<" << std::endl; 129 std::cout << " old original: >" << CommandExecutor::getEvaluation().originalCommand_ << "<" << std::endl; 130 std::cout << " old modified: >" << CommandExecutor::getEvaluation().command_ << "<" << std::endl; 128 131 if (CommandExecutor::getEvaluation().state_ == CS_Uninitialized) 129 132 { 133 std::cout << "parse if needed: parse!" << std::endl; 130 134 CommandExecutor::parse(command); 131 135 } 132 else if ( CommandExecutor::getEvaluation().originalCommand_ != command)136 else if (/*removeTrailingWhitespaces*/(CommandExecutor::getEvaluation().originalCommand_) != /*removeTrailingWhitespaces*/(command)) 133 137 { 134 138 if (CommandExecutor::getEvaluation().command_ == command) 135 139 { 140 std::cout << "parse if needed: parse and set bNewCommand_ to false" << std::endl; 136 141 CommandExecutor::parse(command); 137 142 CommandExecutor::getEvaluation().bNewCommand_ = false; … … 139 144 else 140 145 { 146 std::cout << "parse if needed: parse!" << std::endl; 141 147 CommandExecutor::parse(command); 142 148 } 143 149 } 150 std::cout << "parse if needed: don't parse" << std::endl; 144 151 } 145 152 … … 156 163 { 157 164 case CS_Uninitialized: 165 std::cout << "0: Uninitialized\n"; 158 166 { 159 167 // Impossible … … 161 169 } 162 170 case CS_Empty: 171 std::cout << "0: Empty\n"; 163 172 { 164 173 if (CommandExecutor::argumentsGiven() == 0) … … 175 184 } 176 185 case CS_ShortcutOrIdentifier: 186 std::cout << "0: ShortcutOrIdentifier\n"; 177 187 { 178 188 if (CommandExecutor::argumentsGiven() > 1) … … 191 201 else if (CommandExecutor::getEvaluation().functionclass_) 192 202 { 203 std::cout << "MEP" << std::endl; 193 204 // It's a functionname 194 205 CommandExecutor::getEvaluation().state_ = CS_Function; … … 272 283 } 273 284 case CS_Function: 285 std::cout << "0: Function\n"; 274 286 { 275 287 if (CommandExecutor::getEvaluation().functionclass_) … … 283 295 if (CommandExecutor::getEvaluation().function_) 284 296 { 297 std::cout << "MEP2" << std::endl; 285 298 // It's a function 286 299 CommandExecutor::getEvaluation().state_ = CS_ParamPreparation; … … 377 390 std::cout << "3_1\n"; 378 391 // There is exactly one possible argument 379 CommandExecutor::getEvaluation().argument_ = *(*CommandExecutor::getEvaluation().listOfPossibleArguments_.begin()).second; 392 CommandExecutor::getEvaluation().argument_ = (*CommandExecutor::getEvaluation().listOfPossibleArguments_.begin()).second; 393 CommandExecutor::getEvaluation().possibleArgument_ = (*CommandExecutor::getEvaluation().listOfPossibleArguments_.begin()).second; 380 394 CommandExecutor::getEvaluation().state_ = CS_ParamPreparation; 381 395 return; … … 393 407 std::cout << "3_3\n"; 394 408 // There are several possibilities 395 unsigned int argumentNumber = CommandExecutor::argumentsGiven() - 1; 396 if (CommandExecutor::getEvaluation().functionclass_) 397 argumentNumber -= 1; 398 409 unsigned int argumentNumber = CommandExecutor::argumentsGiven(); 410 if (argumentNumber > 0) 411 --argumentNumber; 412 std::cout << "3_3_1\n"; 413 if (CommandExecutor::getEvaluation().functionclass_ && argumentNumber > 0) 414 --argumentNumber; 415 416 std::cout << "3_3_2\n"; 399 417 CommandExecutor::getEvaluation().argument_ = CommandExecutor::getCommonBegin(CommandExecutor::getEvaluation().listOfPossibleArguments_); 418 std::cout << "3_3_3\n"; 400 419 CommandExecutor::getEvaluation().possibleArgument_ = CommandExecutor::getPossibleArgument(CommandExecutor::getLastArgument(), CommandExecutor::getEvaluation().function_, argumentNumber); 420 std::cout << "3_3_4\n"; 401 421 CommandExecutor::getEvaluation().state_ = CS_ParamPreparation; 422 std::cout << "3_3_5\n"; 402 423 return; 403 424 } … … 495 516 for (std::list<std::pair<std::string, std::string> >::const_iterator it = command->getArgumentCompletionListBegin(); it != command->getArgumentCompletionListEnd(); ++it) 496 517 if ((*it).first.find(lowercase) == 0 || fragment == "") 497 CommandExecutor::getEvaluation().listOfPossibleArguments_.push_back(std::pair< const std::string*, const std::string*>(&(*it).first, &(*it).second));498 499 CommandExecutor::getEvaluation().listOfPossibleArguments_.sort(CommandExecutor::compareStringsInList );518 CommandExecutor::getEvaluation().listOfPossibleArguments_.push_back(std::pair<std::string, std::string>((*it).first, (*it).second)); 519 520 CommandExecutor::getEvaluation().listOfPossibleArguments_.sort(CommandExecutor::compareStringsInList2); 500 521 } 501 522 … … 530 551 std::string CommandExecutor::getPossibleArgument(const std::string& name, ConsoleCommand* command, unsigned int param) 531 552 { 553 std::cout << "4_1\n"; 532 554 CommandExecutor::createArgumentCompletionList(command, param); 533 555 556 std::cout << "4_2\n"; 534 557 std::string lowercase = getLowercase(name); 558 std::cout << "4_3\n"; 535 559 for (std::list<std::pair<std::string, std::string> >::const_iterator it = command->getArgumentCompletionListBegin(); it != command->getArgumentCompletionListEnd(); ++it) 560 { 561 std::cout << "4_4\n"; 536 562 if ((*it).first == lowercase) 537 563 return (*it).second; 538 539 return 0; 564 } 565 566 std::cout << "4_5\n"; 567 return ""; 540 568 } 541 569 … … 599 627 } 600 628 629 std::string CommandExecutor::getCommonBegin(const std::list<std::pair<std::string, std::string> >& list) 630 { 631 if (list.size() == 0) 632 { 633 return ""; 634 } 635 else if (list.size() == 1) 636 { 637 return ((*list.begin()).first + " "); 638 } 639 else 640 { 641 std::string output = ""; 642 for (unsigned int i = 0; true; i++) 643 { 644 char temp = 0; 645 for (std::list<std::pair<std::string, std::string> >::const_iterator it = list.begin(); it != list.end(); ++it) 646 { 647 if ((*it).first.size() > i) 648 { 649 if (it == list.begin()) 650 { 651 temp = (*it).first[i]; 652 } 653 else 654 { 655 if (temp != (*it).first[i]) 656 return output; 657 } 658 } 659 else 660 { 661 return output; 662 } 663 } 664 output += temp; 665 } 666 return output; 667 } 668 } 669 601 670 bool CommandExecutor::compareStringsInList(const std::pair<const std::string*, const std::string*>& first, const std::pair<const std::string*, const std::string*>& second) 602 671 { 603 672 return ((*first.first) < (*second.first)); 604 673 } 674 675 bool CommandExecutor::compareStringsInList2(const std::pair<std::string, std::string>& first, const std::pair<std::string, std::string>& second) 676 { 677 return (first.first < second.first); 678 } 605 679 }
Note: See TracChangeset
for help on using the changeset viewer.