Changeset 994 for code/branches/core2/src/orxonox/core
- Timestamp:
- Apr 5, 2008, 5:54:24 PM (17 years ago)
- Location:
- code/branches/core2/src/orxonox/core
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core2/src/orxonox/core/CommandExecutor.cc
r993 r994 46 46 47 47 ConsoleCommandShortcutExtern(exec, AccessLevel::None); 48 ConsoleCommandShortcutExtern(echo, AccessLevel::None); 49 50 ConsoleCommandShortcutExtern(read, AccessLevel::None); 51 ConsoleCommandShortcutExtern(append, AccessLevel::None); 52 ConsoleCommandShortcutExtern(write, AccessLevel::None); 48 53 49 54 void exec(const std::string& filename) … … 79 84 80 85 executingFiles.erase(filename); 86 file.close(); 87 } 88 89 std::string echo(const std::string& text) 90 { 91 return text; 92 } 93 94 void write(const std::string& filename, const std::string& text) 95 { 96 std::ofstream file; 97 file.open(filename.c_str(), std::fstream::out); 98 99 if (!file.is_open()) 100 { 101 COUT(1) << "Error: Couldn't write to file \"" << filename << "\"." << std::endl; 102 return; 103 } 104 105 file << text << std::endl; 106 file.close(); 107 } 108 109 void append(const std::string& filename, const std::string& text) 110 { 111 std::ofstream file; 112 file.open(filename.c_str(), std::fstream::app); 113 114 if (!file.is_open()) 115 { 116 COUT(1) << "Error: Couldn't append to file \"" << filename << "\"." << std::endl; 117 return; 118 } 119 120 file << text << std::endl; 121 file.close(); 122 } 123 124 std::string read(const std::string& filename) 125 { 126 std::ifstream file; 127 file.open(filename.c_str(), std::fstream::in); 128 129 if (!file.is_open()) 130 { 131 COUT(1) << "Error: Couldn't read from file \"" << filename << "\"." << std::endl; 132 return ""; 133 } 134 135 std::string output = ""; 136 char line[1024]; 137 while (file.good() && !file.eof()) 138 { 139 file.getline(line, 1024); 140 output += line; 141 output += "\n"; 142 } 143 144 file.close(); 145 146 return output; 81 147 } 82 148 … … 200 266 } 201 267 268 MultiTypeMath CommandEvaluation::getReturnvalue() const 269 { 270 if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished) 271 { 272 if (this->shortcut_) 273 return this->shortcut_->getReturnvalue(); 274 } 275 else if (this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished) 276 { 277 if (this->function_) 278 return this->function_->getReturnvalue(); 279 } 280 281 return MT_null; 282 } 283 202 284 203 285 ///////////////////// … … 252 334 bool CommandExecutor::execute(const std::string& command) 253 335 { 254 if ((CommandExecutor::getEvaluation().processedCommand_ != command) || (CommandExecutor::getEvaluation().state_ == CS_Uninitialized)) 255 CommandExecutor::parse(command); 336 std::string strippedCommand = getStrippedEnclosingQuotes(command); 337 338 SubString tokensIO(strippedCommand, " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0'); 339 if (tokensIO.size() >= 2) 340 { 341 if (tokensIO[tokensIO.size() - 2] == ">") 342 { 343 bool success = CommandExecutor::execute(tokensIO.subSet(0, tokensIO.size() - 2).join()); 344 write(tokensIO[tokensIO.size() - 1], CommandExecutor::getEvaluation().getReturnvalue()); 345 return success; 346 } 347 else if (tokensIO[tokensIO.size() - 2] == "<") 348 { 349 std::string input = read(tokensIO[tokensIO.size() - 1]); 350 if (input == "" || input.size() == 0) 351 return CommandExecutor::execute(tokensIO.subSet(0, tokensIO.size() - 2).join()); 352 else 353 return CommandExecutor::execute(tokensIO.subSet(0, tokensIO.size() - 2).join() + " " + input); 354 } 355 } 356 357 358 SubString tokensPipeline(strippedCommand, "|", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0'); 359 if (tokensPipeline.size() > 1) 360 { 361 bool success = true; 362 std::string returnValue = ""; 363 for (int i = tokensPipeline.size() - 1; i >= 0; i--) 364 { 365 if (returnValue == "" || returnValue.size() == 0) 366 { 367 //CommandEvaluation evaluation = CommandExecutor::evaluate(tokens[i]); 368 if (!CommandExecutor::execute(tokensPipeline[i])) 369 success = false; 370 } 371 else 372 { 373 //CommandEvaluation evaluation = CommandExecutor::evaluate(tokens[i] + " " + returnValue); 374 if (!CommandExecutor::execute(tokensPipeline[i] + " " + returnValue)) 375 success = false; 376 } 377 378 //CommandExecutor::execute(evaluation); 379 //returnValue = evaluation.getReturnvalue(); 380 returnValue = CommandExecutor::getEvaluation().getReturnvalue().toString(); 381 } 382 return success; 383 } 384 385 if ((CommandExecutor::getEvaluation().processedCommand_ != strippedCommand) || (CommandExecutor::getEvaluation().state_ == CS_Uninitialized)) 386 CommandExecutor::parse(strippedCommand); 256 387 257 388 return CommandExecutor::execute(CommandExecutor::getEvaluation()); … … 261 392 bool CommandExecutor::execute(const CommandEvaluation& evaluation) 262 393 { 263 SubString tokens(evaluation.processedCommand_, " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0');394 SubString tokens(evaluation.processedCommand_, " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0'); 264 395 265 396 if (evaluation.bEvaluatedParams_ && evaluation.evaluatedExecutor_) … … 353 484 std::string CommandExecutor::complete(const CommandEvaluation& evaluation) 354 485 { 355 SubString tokens(evaluation.processedCommand_, " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0');486 SubString tokens(evaluation.processedCommand_, " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0'); 356 487 357 488 std::list<std::pair<const std::string*, const std::string*> > temp; … … 444 575 std::string CommandExecutor::hint(const CommandEvaluation& evaluation) 445 576 { 446 SubString tokens(evaluation.processedCommand_, " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0');577 SubString tokens(evaluation.processedCommand_, " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0'); 447 578 448 579 switch (evaluation.state_) … … 516 647 void CommandExecutor::parse(const std::string& command, bool bInitialize) 517 648 { 518 CommandExecutor::getEvaluation().tokens_.split((command + COMMAND_EXECUTOR_CURSOR), " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0');649 CommandExecutor::getEvaluation().tokens_.split((command + COMMAND_EXECUTOR_CURSOR), " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0'); 519 650 CommandExecutor::getEvaluation().processedCommand_ = command; 520 651 -
code/branches/core2/src/orxonox/core/CommandExecutor.h
r993 r994 62 62 63 63 void exec(const std::string& filename); 64 std::string echo(const std::string& text); 65 66 void write(const std::string& filename, const std::string& text); 67 void append(const std::string& filename, const std::string& text); 68 std::string read(const std::string& filename); 64 69 65 70 enum KeybindMode {}; // temporary … … 87 92 88 93 void evaluateParams(); 94 95 MultiTypeMath getReturnvalue() const; 89 96 90 97 private: -
code/branches/core2/src/orxonox/core/Executor.cc
r967 r994 90 90 { 91 91 // more than one param 92 SubString tokens(params, delimiter, SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0');92 SubString tokens(params, delimiter, SubString::WhiteSpaces, false, '\\', true, '"', true, '(', ')', true, '\0'); 93 93 94 94 // if there are not enough params given, check if there are default values -
code/branches/core2/src/orxonox/core/Executor.h
r967 r994 76 76 else \ 77 77 { \ 78 SubString tokens(params, delimiter, SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0'); \79 \78 SubString tokens(params, delimiter, SubString::WhiteSpaces, false, '\\', true, '"', true, '(', ')', true, '\0'); \ 79 \ 80 80 for (unsigned int i = tokens.size(); i < this->functor_->getParamCount(); i++) \ 81 81 { \ … … 86 86 } \ 87 87 } \ 88 \89 MultiTypeMath param[ paramCount]; \88 \ 89 MultiTypeMath param[MAX_FUNCTOR_ARGUMENTS]; \ 90 90 COUT(5) << "Calling Executor " << this->name_ << " through parser with " << paramCount << " parameters, using " << tokens.size() << " tokens ("; \ 91 91 for (unsigned int i = 0; i < tokens.size() && i < MAX_FUNCTOR_ARGUMENTS; i++) \ … … 109 109 } \ 110 110 COUT(5) << ")." << std::endl; \ 111 \ 111 \ 112 if ((tokens.size() > paramCount) && (this->functor_->getTypenameParam(paramCount - 1) == "string")) \ 113 param[paramCount - 1] = tokens.subSet(paramCount - 1).join(); \ 114 \ 112 115 switch(paramCount) \ 113 116 { \ -
code/branches/core2/src/orxonox/core/InputBuffer.cc
r972 r994 36 36 { 37 37 this->bActivated_ = false; 38 this->allowedChars_ = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZäöüÄÖÜ0123456789 \"().:,;_-+*/=!? ";38 this->allowedChars_ = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZäöüÄÖÜ0123456789 \"().:,;_-+*/=!?<>[|]"; 39 39 this->keyboard_ = keyboard; 40 40 this->buffer_ = ""; -
code/branches/core2/src/orxonox/core/Namespace.cc
r902 r994 72 72 while ((pos = name.find('\t')) != std::string::npos) 73 73 name.replace(pos, 1, " "); 74 SubString tokens(name, " ", "", false, '\\', '"', '\0', '\0', '\0');74 SubString tokens(name, " ", "", false, '\\', true, '"', true, '\0', '\0', true, '\0'); 75 75 if (this->bRoot_) 76 76 { -
code/branches/core2/src/orxonox/core/OutputHandler.h
r955 r994 60 60 61 61 /** @brief Puts some text on the outstream. @param text The text */ 62 static inline voidlog(const std::string& text)63 { OutputHandler::getOutStream().setOutputLevel(0); OutputHandler::getOutStream().output(text + "\n"); }62 static inline std::string log(const std::string& text) 63 { OutputHandler::getOutStream().setOutputLevel(0); OutputHandler::getOutStream().output(text + "\n"); return text; } 64 64 65 65 /** @brief Returns a reference to the logfile. @return The logfile */ -
code/branches/core2/src/orxonox/core/XMLPort.h
r947 r994 32 32 #include "util/MultiTypeMath.h" 33 33 #include "util/tinyxml/ticpp.h" 34 #include "util/SubString.h"35 34 #include "Executor.h" 36 35 #include "Debug.h"
Note: See TracChangeset
for help on using the changeset viewer.