Changeset 1427 for code/branches/console/src/core/CommandExecutor.cc
- Timestamp:
- May 26, 2008, 3:08:39 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/console/src/core/CommandExecutor.cc
r1424 r1427 146 146 void CommandExecutor::parse(const std::string& command, bool bInitialize) 147 147 { 148 std::cout << "parse : command: >" << command << "<" << std::endl;148 std::cout << "parse (" << bInitialize << "): command: >" << command << "<" << std::endl; 149 149 if (bInitialize) 150 150 CommandExecutor::getEvaluation().initialize(command); … … 185 185 { 186 186 // It's a shortcut 187 CommandExecutor::getEvaluation().state_ = CS_Param s;187 CommandExecutor::getEvaluation().state_ = CS_ParamPreparation; 188 188 CommandExecutor::getEvaluation().functionclass_ = 0; 189 189 // Move on to next case … … 224 224 CommandExecutor::getEvaluation().bCommandChanged_ = true; 225 225 } 226 CommandExecutor::getEvaluation().state_ = CS_Param s;226 CommandExecutor::getEvaluation().state_ = CS_ParamPreparation; 227 227 CommandExecutor::getEvaluation().functionclass_ = 0; 228 228 CommandExecutor::getEvaluation().command_ = CommandExecutor::getEvaluation().function_->getName(); 229 229 if (CommandExecutor::getEvaluation().function_->getParamCount() > 0) 230 { 230 231 CommandExecutor::getEvaluation().command_ += " "; 232 CommandExecutor::getEvaluation().bCommandChanged_ = true; 233 } 231 234 // Move on to next case 232 235 } … … 263 266 CommandExecutor::getEvaluation().function_ = CommandExecutor::getPossibleCommand(CommandExecutor::getArgument(0)); 264 267 CommandExecutor::getEvaluation().functionclass_ = CommandExecutor::getPossibleIdentifier(CommandExecutor::getArgument(0)); 268 CommandExecutor::getEvaluation().bCommandChanged_ = true; 265 269 return; 266 270 } … … 280 284 { 281 285 // It's a function 282 CommandExecutor::getEvaluation().state_ = CS_Param s;286 CommandExecutor::getEvaluation().state_ = CS_ParamPreparation; 283 287 // Move on to next case 284 288 } … … 308 312 CommandExecutor::getEvaluation().bCommandChanged_ = true; 309 313 } 310 CommandExecutor::getEvaluation().state_ = CS_Param s;314 CommandExecutor::getEvaluation().state_ = CS_ParamPreparation; 311 315 CommandExecutor::getEvaluation().command_ = CommandExecutor::getEvaluation().functionclass_->getName() + " " + CommandExecutor::getEvaluation().function_->getName(); 312 316 if (CommandExecutor::getEvaluation().function_->getParamCount() > 0) 317 { 313 318 CommandExecutor::getEvaluation().command_ += " "; 319 CommandExecutor::getEvaluation().bCommandChanged_ = true; 320 } 314 321 // Move on to next case 315 322 } … … 327 334 CommandExecutor::getEvaluation().command_ = CommandExecutor::getEvaluation().functionclass_->getName() + " " + CommandExecutor::getCommonBegin(CommandExecutor::getEvaluation().listOfPossibleFunctions_); 328 335 CommandExecutor::getEvaluation().function_ = CommandExecutor::getPossibleCommand(CommandExecutor::getArgument(1), CommandExecutor::getEvaluation().functionclass_); 336 CommandExecutor::getEvaluation().bCommandChanged_ = true; 329 337 return; 330 338 } … … 333 341 else 334 342 { 335 // There is no classname - move on to CS_Shortcut_Params 336 } 337 } 338 std::cout << "Waiting for arguments" << std::endl; 343 // There is no classname - move on to CS_ParamPreparation 344 } 345 } 346 std::cout << "1\n"; 347 case CS_ParamPreparation: 348 std::cout << "2\n"; 349 { 350 if (CommandExecutor::getEvaluation().function_->getParamCount() == 0 || CommandExecutor::enoughArgumentsGiven(CommandExecutor::getEvaluation().function_)) 351 { 352 CommandExecutor::getEvaluation().state_ = CS_Finished; 353 return; 354 } 355 else 356 { 357 unsigned int argumentNumber = CommandExecutor::argumentsGiven() - 1; 358 if (CommandExecutor::getEvaluation().functionclass_) 359 argumentNumber -= 1; 360 361 CommandExecutor::createListOfPossibleArguments(CommandExecutor::getLastArgument(), CommandExecutor::getEvaluation().function_, argumentNumber); 362 CommandExecutor::getEvaluation().state_ = CS_Params; 363 364 if (CommandExecutor::getEvaluation().bCommandChanged_) 365 { 366 // Don't do more than one change 367 return; 368 } 369 } 370 } 339 371 case CS_Params: 340 { 372 std::cout << "3\n"; 373 { 374 if (CommandExecutor::getEvaluation().listOfPossibleArguments_.size() == 1) 375 { 376 std::cout << "3_1\n"; 377 // There is exactly one possible argument 378 CommandExecutor::getEvaluation().argument_ = *(*CommandExecutor::getEvaluation().listOfPossibleArguments_.begin()).second; 379 CommandExecutor::getEvaluation().state_ = CS_ParamPreparation; 380 return; 381 } 382 else if (CommandExecutor::getEvaluation().listOfPossibleArguments_.size() == 0) 383 { 384 std::cout << "3_2\n"; 385 // The user tries something new - we let him do 386 CommandExecutor::getEvaluation().state_ = CS_ParamPreparation; 387 CommandExecutor::getEvaluation().argument_ = CommandExecutor::getLastArgument(); 388 return; 389 } 390 else 391 { 392 std::cout << "3_3\n"; 393 // There are several possibilities 394 unsigned int argumentNumber = CommandExecutor::argumentsGiven() - 1; 395 if (CommandExecutor::getEvaluation().functionclass_) 396 argumentNumber -= 1; 397 398 CommandExecutor::getEvaluation().argument_ = CommandExecutor::getCommonBegin(CommandExecutor::getEvaluation().listOfPossibleArguments_); 399 CommandExecutor::getEvaluation().possibleArgument_ = CommandExecutor::getPossibleArgument(CommandExecutor::getLastArgument(), CommandExecutor::getEvaluation().function_, argumentNumber); 400 CommandExecutor::getEvaluation().state_ = CS_ParamPreparation; 401 return; 402 } 341 403 } 342 404 case CS_Finished: 405 std::cout << "4\n"; 343 406 { 344 407 // Nothing more to do … … 373 436 { 374 437 if (CommandExecutor::getEvaluation().functionclass_) 375 return (CommandExecutor:: getEvaluation().commandTokens_.size() >=(2 + command->getParamCount()));376 else 377 return (CommandExecutor:: getEvaluation().commandTokens_.size() >=(1 + command->getParamCount()));438 return (CommandExecutor::argumentsGiven() > (2 + command->getParamCount())); 439 else 440 return (CommandExecutor::argumentsGiven() > (1 + command->getParamCount())); 378 441 } 379 442 … … 388 451 std::string CommandExecutor::getLastArgument() 389 452 { 390 return CommandExecutor::getArgument(CommandExecutor::argumentsGiven() );453 return CommandExecutor::getArgument(CommandExecutor::argumentsGiven() - 1); 391 454 } 392 455 … … 462 525 } 463 526 464 const std::string*CommandExecutor::getPossibleArgument(const std::string& name, ConsoleCommand* command, unsigned int param)527 std::string CommandExecutor::getPossibleArgument(const std::string& name, ConsoleCommand* command, unsigned int param) 465 528 { 466 529 std::string lowercase = getLowercase(name); 467 530 for (std::list<std::pair<std::string, std::string> >::const_iterator it = command->getArgumentCompletionListBegin(param); it != command->getArgumentCompletionListEnd(param); ++it) 468 531 if ((*it).first == lowercase) 469 return &(*it).second;532 return (*it).second; 470 533 471 534 return 0;
Note: See TracChangeset
for help on using the changeset viewer.