Changeset 1214 for code/trunk/src/core/CommandExecutor.cc
- Timestamp:
- May 2, 2008, 9:23:30 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/core/CommandExecutor.cc
r1059 r1214 36 36 #include "Executor.h" 37 37 #include "ConfigValueContainer.h" 38 #include "TclBind.h" 38 39 39 40 #define COMMAND_EXECUTOR_KEYWORD_SET_CONFIG_VALUE "set" … … 236 237 if (this->shortcut_) 237 238 { 238 if (this->shortcut_->evaluate(this->processedCommand_ + this->getAdditionalParameter(), this->param_, " ")) 239 { 240 this->bEvaluatedParams_ = true; 241 this->evaluatedExecutor_ = this->shortcut_; 239 if (this->tokens_.size() <= 1) 240 { 241 if (this->shortcut_->evaluate(this->getAdditionalParameter(), this->param_, " ")) 242 { 243 this->bEvaluatedParams_ = true; 244 this->evaluatedExecutor_ = this->shortcut_; 245 } 246 } 247 else if (this->tokens_.size() > 1) 248 { 249 if (this->shortcut_->evaluate(this->tokens_.subSet(1).join() + this->getAdditionalParameter(), this->param_, " ")) 250 { 251 this->bEvaluatedParams_ = true; 252 this->evaluatedExecutor_ = this->shortcut_; 253 } 242 254 } 243 255 } … … 247 259 if (this->function_) 248 260 { 249 if (this->function_->evaluate(this->processedCommand_ + this->getAdditionalParameter(), this->param_, " ")) 250 { 251 this->bEvaluatedParams_ = true; 252 this->evaluatedExecutor_ = this->function_; 261 if (this->tokens_.size() <= 2) 262 { 263 if (this->function_->evaluate(this->getAdditionalParameter(), this->param_, " ")) 264 { 265 this->bEvaluatedParams_ = true; 266 this->evaluatedExecutor_ = this->function_; 267 } 268 } 269 else if (this->tokens_.size() > 2) 270 { 271 if (this->function_->evaluate(this->tokens_.subSet(2).join() + this->getAdditionalParameter(), this->param_, " ")) 272 { 273 this->bEvaluatedParams_ = true; 274 this->evaluatedExecutor_ = this->function_; 275 } 253 276 } 254 277 } … … 266 289 if (index >= 0 && index < MAX_FUNCTOR_ARGUMENTS) 267 290 return this->param_[index]; 291 292 return MT_null; 293 } 294 295 bool CommandEvaluation::hasReturnvalue() const 296 { 297 if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished) 298 { 299 if (this->shortcut_) 300 return this->shortcut_->hasReturnvalue(); 301 } 302 else if (this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished) 303 { 304 if (this->function_) 305 return this->function_->hasReturnvalue(); 306 } 268 307 269 308 return MT_null; … … 297 336 298 337 CommandEvaluation& CommandExecutor::getEvaluation() 338 { 339 return CommandExecutor::getInstance().evaluation_; 340 } 341 342 const CommandEvaluation& CommandExecutor::getLastEvaluation() 299 343 { 300 344 return CommandExecutor::getInstance().evaluation_; … … 336 380 } 337 381 338 bool CommandExecutor::execute(const std::string& command) 339 { 340 std::string strippedCommand = stripEnclosingQuotes(command); 341 342 SubString tokensIO(strippedCommand, " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0'); 343 if (tokensIO.size() >= 2) 344 { 345 if (tokensIO[tokensIO.size() - 2] == ">") 346 { 347 bool success = CommandExecutor::execute(tokensIO.subSet(0, tokensIO.size() - 2).join()); 348 write(tokensIO[tokensIO.size() - 1], CommandExecutor::getEvaluation().getReturnvalue()); 349 return success; 350 } 351 else if (tokensIO[tokensIO.size() - 2] == "<") 352 { 353 std::string input = read(tokensIO[tokensIO.size() - 1]); 354 if (input == "" || input.size() == 0) 355 return CommandExecutor::execute(tokensIO.subSet(0, tokensIO.size() - 2).join()); 356 else 357 return CommandExecutor::execute(tokensIO.subSet(0, tokensIO.size() - 2).join() + " " + input); 358 } 359 } 360 361 362 SubString tokensPipeline(strippedCommand, "|", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0'); 363 if (tokensPipeline.size() > 1) 364 { 365 bool success = true; 366 std::string returnValue = ""; 367 for (int i = tokensPipeline.size() - 1; i >= 0; i--) 368 { 369 if (returnValue == "" || returnValue.size() == 0) 370 { 371 //CommandEvaluation evaluation = CommandExecutor::evaluate(tokens[i]); 372 if (!CommandExecutor::execute(tokensPipeline[i])) 373 success = false; 374 } 375 else 376 { 377 //CommandEvaluation evaluation = CommandExecutor::evaluate(tokens[i] + " " + returnValue); 378 if (!CommandExecutor::execute(tokensPipeline[i] + " " + returnValue)) 379 success = false; 380 } 381 382 //CommandExecutor::execute(evaluation); 383 //returnValue = evaluation.getReturnvalue(); 384 returnValue = CommandExecutor::getEvaluation().getReturnvalue().toString(); 385 } 386 return success; 387 } 388 389 if ((CommandExecutor::getEvaluation().processedCommand_ != strippedCommand) || (CommandExecutor::getEvaluation().state_ == CS_Uninitialized)) 390 CommandExecutor::parse(strippedCommand); 391 392 return CommandExecutor::execute(CommandExecutor::getEvaluation()); 382 bool CommandExecutor::execute(const std::string& command, bool useTcl) 383 { 384 if (useTcl) 385 { 386 return TclBind::eval(command); 387 } 388 else 389 { 390 if ((CommandExecutor::getEvaluation().processedCommand_ != command) || (CommandExecutor::getEvaluation().state_ == CS_Uninitialized)) 391 CommandExecutor::parse(command); 392 393 return CommandExecutor::execute(CommandExecutor::getEvaluation()); 394 } 393 395 } 394 396 … … 400 402 if (evaluation.bEvaluatedParams_ && evaluation.evaluatedExecutor_) 401 403 { 404 std::cout << "CE_execute (evaluation): " << evaluation.evaluatedExecutor_->getName() << " " << evaluation.param_[0] << " " << evaluation.param_[1] << " " << evaluation.param_[2] << " " << evaluation.param_[3] << " " << evaluation.param_[4] << std::endl; 402 405 (*evaluation.evaluatedExecutor_)(evaluation.param_[0], evaluation.param_[1], evaluation.param_[2], evaluation.param_[3], evaluation.param_[4]); 403 } 404 406 return true; 407 } 408 409 std::cout << "CE_execute: " << evaluation.processedCommand_ << "\n"; 405 410 switch (evaluation.state_) 406 411 { … … 645 650 { 646 651 CommandExecutor::parse(command, true); 652 653 if (CommandExecutor::getEvaluation().tokens_.size() > 0) 654 { 655 std::string lastToken; 656 lastToken = CommandExecutor::getEvaluation().tokens_[CommandExecutor::getEvaluation().tokens_.size() - 1]; 657 lastToken = lastToken.substr(0, lastToken.size() - 1); 658 CommandExecutor::getEvaluation().tokens_.pop_back(); 659 CommandExecutor::getEvaluation().tokens_.append(SubString(lastToken, " ", "", true, '\0', false, '\0', false, '\0', '\0', false, '\0')); 660 } 661 647 662 CommandExecutor::getEvaluation().evaluateParams(); 648 663 return CommandExecutor::getEvaluation(); … … 1082 1097 CommandExecutor::getEvaluation().additionalParameter_ = ""; 1083 1098 1099 CommandExecutor::getEvaluation().bEvaluatedParams_ = false; 1100 CommandExecutor::getEvaluation().evaluatedExecutor_ = 0; 1101 1084 1102 CommandExecutor::getEvaluation().listOfPossibleFunctionClasses_.clear(); 1085 1103 CommandExecutor::getEvaluation().listOfPossibleShortcuts_.clear();
Note: See TracChangeset
for help on using the changeset viewer.