Changeset 1424 for code/branches/console
- Timestamp:
- May 25, 2008, 9:58:14 PM (17 years ago)
- Location:
- code/branches/console/src
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/console/src/core/CommandEvaluation.cc
r1416 r1424 42 42 { 43 43 this->bNewCommand_ = true; 44 44 this->bCommandChanged_ = false; 45 45 this->originalCommand_ = command; 46 46 this->command_ = command; … … 79 79 } 80 80 81 COUT(4) << "CE_execute: " << this->command_ << "\n"; 82 83 unsigned int startindex = this->getStartindex(); 84 if (this->commandTokens_.size() > startindex) 85 return this->function_->parse(removeSlashes(this->commandTokens_.subSet(startindex).join() + this->getAdditionalParameter())); 86 else 87 return this->function_->parse(removeSlashes(this->additionalParameter_)); 88 } 89 90 std::string CommandEvaluation::complete() const 91 { 92 switch (this->state_) 93 { 94 case CS_Uninitialized: 95 std::cout << "complete: state: CS_Uninitialized" << std::endl; 96 case CS_Empty: 97 std::cout << "complete: state: CS_Empty" << std::endl; 98 case CS_ShortcutOrIdentifier: 99 std::cout << "complete: state: CS_ShortcutOrIdentifier" << std::endl; 100 { 101 std::list<std::pair<const std::string*, const std::string*> > temp; 102 temp.insert(temp.end(), this->listOfPossibleFunctions_.begin(), this->listOfPossibleFunctions_.end()); 103 temp.insert(temp.end(), this->listOfPossibleIdentifiers_.begin(), this->listOfPossibleIdentifiers_.end()); 104 if (temp.size() > 0) 105 { 106 std::cout << "complete: temp > 0" << std::endl; 107 return (CommandEvaluation::getCommonBegin(temp)); 108 } 109 } 110 break; 111 case CS_Shortcut_Params: 112 std::cout << "complete: state: CS_Shortcut_Params" << std::endl; 113 if (this->function_) 114 { 115 std::cout << "complete: function != 0" << std::endl; 116 if (this->commandTokens_.size() > 1) 117 { 118 if ((this->commandTokens_.size() - 1) >= this->function_->getParamCount()) 119 return (this->function_->getName() + " " + this->commandTokens_.subSet(1, this->commandTokens_.size()).join()); 120 else 121 return (this->function_->getName() + " " + this->commandTokens_.subSet(1, this->commandTokens_.size()).join() + " " + CommandEvaluation::getCommonBegin(this->listOfPossibleArguments_)); 122 } 123 else 124 return (this->function_->getName() + " "); 125 } 126 break; 127 case CS_Shortcut_Finished: 128 std::cout << "complete: state: CS_Shortcut_Finished" << std::endl; 129 if (this->function_) 130 { 131 std::cout << "complete: function != 0" << std::endl; 132 if (this->commandTokens_.size() > 1) 133 return (this->function_->getName() + " " + this->commandTokens_.subSet(1, this->commandTokens_.size()).join()); 134 else 135 return (this->function_->getName()); 136 } 137 break; 138 case CS_Function: 139 std::cout << "complete: state: CS_Function" << std::endl; 140 if (this->functionclass_) 141 { 142 std::cout << "complete: functionclass != 0" << std::endl; 143 return (this->functionclass_->getName() + " " + CommandEvaluation::getCommonBegin(this->listOfPossibleFunctions_)); 144 } 145 break; 146 case CS_Function_Params: 147 std::cout << "complete: state: CS_Function_Params" << std::endl; 148 if (this->functionclass_ && this->function_) 149 { 150 std::cout << "complete: function und functionclass != 0" << std::endl; 151 if (this->commandTokens_.size() > 2) 152 { 153 if ((this->commandTokens_.size() - 2) >= this->function_->getParamCount()) 154 return (this->functionclass_->getName() + " " + this->function_->getName() + " " + this->commandTokens_.subSet(2, this->commandTokens_.size()).join()); 155 else 156 return (this->functionclass_->getName() + " " + this->function_->getName() + " " + this->commandTokens_.subSet(2, this->commandTokens_.size()).join() + " " + CommandEvaluation::getCommonBegin(this->listOfPossibleArguments_)); 157 } 158 else 159 return (this->functionclass_->getName() + " " + this->function_->getName() + " "); 160 } 161 break; 162 case CS_Function_Finished: 163 std::cout << "complete: state: CS_Function_Finished" << std::endl; 164 if (this->functionclass_ && this->function_) 165 { 166 std::cout << "complete: function und functionclass != 0" << std::endl; 167 if (this->commandTokens_.size() > 2) 168 return (this->functionclass_->getName() + " " + this->function_->getName() + " " + this->commandTokens_.subSet(2, this->commandTokens_.size()).join()); 169 else 170 return (this->functionclass_->getName() + " " + this->function_->getName()); 171 } 172 break; 173 case CS_Error: 174 std::cout << "complete: state: CS_Error" << std::endl; 175 break; 176 } 177 178 return this->originalCommand_; 81 if (!this->bCommandChanged_) 82 { 83 COUT(4) << "CE_execute: " << this->command_ << "\n"; 84 85 unsigned int startindex = this->getStartindex(); 86 if (this->commandTokens_.size() > startindex) 87 return this->function_->parse(removeSlashes(this->commandTokens_.subSet(startindex).join() + this->getAdditionalParameter())); 88 else 89 return this->function_->parse(removeSlashes(this->additionalParameter_)); 90 } 91 92 return false; 93 } 94 95 std::string CommandEvaluation::complete() 96 { 97 if (!this->bNewCommand_) 98 { 99 std::cout << "ASDF" << std::endl; 100 switch (this->state_) 101 { 102 case CS_Uninitialized: 103 break; 104 case CS_Empty: 105 break; 106 case CS_ShortcutOrIdentifier: 107 if (this->function_) 108 return CommandExecutor::complete(this->function_->getName() + " "); 109 else if (this->functionclass_) 110 return CommandExecutor::complete(this->functionclass_->getName() + " "); 111 break; 112 case CS_Function: 113 if (this->function_) 114 return CommandExecutor::complete(this->functionclass_->getName() + " " + this->function_->getName() + " "); 115 break; 116 case CS_Params: 117 break; 118 case CS_Finished: 119 break; 120 case CS_Error: 121 break; 122 } 123 } 124 this->bNewCommand_ = false; 125 return this->command_; 179 126 } 180 127 … … 197 144 return CommandEvaluation::dump(this->listOfPossibleFunctions_); 198 145 break; 199 case CS_Shortcut_Params: 200 case CS_Function_Params: 146 case CS_Params: 201 147 if (this->listOfPossibleArguments_.size() > 0) 202 148 return CommandEvaluation::dump(this->listOfPossibleArguments_); 203 149 else 204 150 return CommandEvaluation::dump(this->function_); 205 case CS_Shortcut_Finished: 206 case CS_Function_Finished: 151 case CS_Finished: 207 152 if (this->function_) 208 153 return CommandEvaluation::dump(this->function_); … … 273 218 unsigned int CommandEvaluation::getStartindex() const 274 219 { 275 if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished) 220 if (this->functionclass_ && this->function_) 221 return 2; 222 else if (this->function_) 276 223 return 1; 277 else if (this->state_ == CS_Function || this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished)278 return 2;279 224 else 280 225 return 0; 281 226 } 282 227 283 std::string CommandEvaluation::getCommonBegin(const std::list<std::pair<const std::string*, const std::string*> >& list)284 {285 if (list.size() == 0)286 {287 return "";288 }289 else if (list.size() == 1)290 {291 return ((*(*list.begin()).first) + " ");292 }293 else294 {295 std::string output = "";296 for (unsigned int i = 0; true; i++)297 {298 char temp = 0;299 for (std::list<std::pair<const std::string*, const std::string*> >::const_iterator it = list.begin(); it != list.end(); ++it)300 {301 if ((*(*it).first).size() > i)302 {303 if (it == list.begin())304 {305 temp = (*(*it).first)[i];306 }307 else308 {309 if (temp != (*(*it).first)[i])310 return output;311 }312 }313 else314 {315 return output;316 }317 }318 output += temp;319 }320 return output;321 }322 }323 324 228 std::string CommandEvaluation::dump(const std::list<std::pair<const std::string*, const std::string*> >& list) 325 229 { … … 337 241 std::string CommandEvaluation::dump(const ConsoleCommand* command) 338 242 { 339 std::string output = "";243 std::string output = command->getName() + ": "; 340 244 for (unsigned int i = 0; i < command->getParamCount(); i++) 341 245 { -
code/branches/console/src/core/CommandEvaluation.h
r1417 r1424 45 45 CS_Empty, 46 46 CS_ShortcutOrIdentifier, 47 CS_Shortcut_Params,48 CS_Shortcut_Finished,49 47 CS_Function, 50 CS_ Function_Params,51 CS_F unction_Finished,48 CS_Params, 49 CS_Finished, 52 50 CS_Error 53 51 }; … … 63 61 64 62 bool execute() const; 65 std::string complete() const;63 std::string complete(); 66 64 std::string hint() const; 67 65 void evaluateParams(); … … 82 80 private: 83 81 unsigned int getStartindex() const; 84 static std::string getCommonBegin(const std::list<std::pair<const std::string*, const std::string*> >& list);85 82 static std::string dump(const std::list<std::pair<const std::string*, const std::string*> >& list); 86 83 static std::string dump(const ConsoleCommand* command); … … 88 85 89 86 bool bNewCommand_; 87 bool bCommandChanged_; 90 88 91 89 std::string originalCommand_; -
code/branches/console/src/core/CommandExecutor.cc
r1417 r1424 108 108 { 109 109 CommandExecutor::parseIfNeeded(command); 110 111 if (!CommandExecutor::getEvaluation().bNewCommand_)112 CommandExecutor::parse(CommandExecutor::getEvaluation().command_, false);113 else114 CommandExecutor::getEvaluation().bNewCommand_ = false;115 116 110 return CommandExecutor::getEvaluation().complete(); 117 111 } … … 132 126 void CommandExecutor::parseIfNeeded(const std::string& command) 133 127 { 134 if ((CommandExecutor::getEvaluation().originalCommand_ != command) || (CommandExecutor::getEvaluation().state_ == CS_Uninitialized)) 128 if (CommandExecutor::getEvaluation().state_ == CS_Uninitialized) 129 { 135 130 CommandExecutor::parse(command); 131 } 132 else if (CommandExecutor::getEvaluation().originalCommand_ != command) 133 { 134 if (CommandExecutor::getEvaluation().command_ == command) 135 { 136 CommandExecutor::parse(command); 137 CommandExecutor::getEvaluation().bNewCommand_ = false; 138 } 139 else 140 { 141 CommandExecutor::parse(command); 142 } 143 } 136 144 } 137 145 … … 149 157 case CS_Uninitialized: 150 158 { 151 std::cout << "parse: state: CS_Uninitialized" << std::endl;152 159 // Impossible 153 160 break; … … 155 162 case CS_Empty: 156 163 { 157 std::cout << "parse: state: CS_Empty" << std::endl; 158 CommandExecutor::createListOfPossibleIdentifiers(CommandExecutor::getArgument(0)); 159 CommandExecutor::createListOfPossibleFunctions(CommandExecutor::getArgument(0)); 160 161 if (CommandExecutor::argumentsGiven() > 0) 164 if (CommandExecutor::argumentsGiven() == 0) 165 { 166 CommandExecutor::createListOfPossibleFunctions(""); 167 CommandExecutor::createListOfPossibleIdentifiers(""); 168 break; 169 } 170 else 162 171 { 163 172 CommandExecutor::getEvaluation().state_ = CS_ShortcutOrIdentifier; 164 CommandExecutor::parse(command, false); 165 return; 166 } 173 // Move on to next case 174 } 175 } 176 case CS_ShortcutOrIdentifier: 177 { 178 if (CommandExecutor::argumentsGiven() > 1) 179 { 180 // There's a finished first argument - check if it's a shortcut or a classname 181 CommandExecutor::getEvaluation().function_ = CommandExecutor::getPossibleCommand(CommandExecutor::getArgument(0)); 182 CommandExecutor::getEvaluation().functionclass_ = CommandExecutor::getPossibleIdentifier(CommandExecutor::getArgument(0)); 183 184 if (CommandExecutor::getEvaluation().function_) 185 { 186 // It's a shortcut 187 CommandExecutor::getEvaluation().state_ = CS_Params; 188 CommandExecutor::getEvaluation().functionclass_ = 0; 189 // Move on to next case 190 } 191 else if (CommandExecutor::getEvaluation().functionclass_) 192 { 193 // It's a functionname 194 CommandExecutor::getEvaluation().state_ = CS_Function; 195 CommandExecutor::getEvaluation().function_ = 0; 196 // Move on to next case 197 } 198 else 199 { 200 // The first argument is bad 201 CommandExecutor::getEvaluation().state_ = CS_Error; 202 AddLanguageEntry("commandexecutorunknownfirstargument", "is not a shortcut nor a classname"); 203 CommandExecutor::getEvaluation().errorMessage_ = "Error: " + CommandExecutor::getArgument(0) + " " + GetLocalisation("commandexecutorunknownfirstargument") + "."; 204 return; 205 } 206 } 207 else 208 { 209 // There's no finished first argument - search possible shortcuts or classnames 210 CommandExecutor::createListOfPossibleFunctions(CommandExecutor::getArgument(0)); 211 CommandExecutor::createListOfPossibleIdentifiers(CommandExecutor::getArgument(0)); 212 213 unsigned int num_functions = CommandExecutor::getEvaluation().listOfPossibleFunctions_.size(); 214 unsigned int num_identifiers = CommandExecutor::getEvaluation().listOfPossibleIdentifiers_.size(); 215 216 if (num_functions == 1 && num_identifiers == 0) 217 { 218 // It's a shortcut 219 std::string functionname = *(*CommandExecutor::getEvaluation().listOfPossibleFunctions_.begin()).first; 220 CommandExecutor::getEvaluation().function_ = CommandExecutor::getPossibleCommand(functionname); 221 if (getLowercase(functionname) != getLowercase(CommandExecutor::getArgument(0))) 222 { 223 // Unfinished shortcut 224 CommandExecutor::getEvaluation().bCommandChanged_ = true; 225 } 226 CommandExecutor::getEvaluation().state_ = CS_Params; 227 CommandExecutor::getEvaluation().functionclass_ = 0; 228 CommandExecutor::getEvaluation().command_ = CommandExecutor::getEvaluation().function_->getName(); 229 if (CommandExecutor::getEvaluation().function_->getParamCount() > 0) 230 CommandExecutor::getEvaluation().command_ += " "; 231 // Move on to next case 232 } 233 else if (num_identifiers == 1 && num_functions == 0) 234 { 235 // It's a classname 236 std::string classname = *(*CommandExecutor::getEvaluation().listOfPossibleIdentifiers_.begin()).first; 237 CommandExecutor::getEvaluation().functionclass_ = CommandExecutor::getPossibleIdentifier(classname); 238 if (getLowercase(classname) != getLowercase(CommandExecutor::getArgument(0))) 239 { 240 // Unfinished classname 241 CommandExecutor::getEvaluation().bCommandChanged_ = true; 242 } 243 CommandExecutor::getEvaluation().state_ = CS_Function; 244 CommandExecutor::getEvaluation().function_ = 0; 245 CommandExecutor::getEvaluation().command_ = CommandExecutor::getEvaluation().functionclass_->getName() + " "; 246 // Move on to next case 247 } 248 else if (num_identifiers == 0 && num_functions == 0) 249 { 250 // No possibilities 251 CommandExecutor::getEvaluation().state_ = CS_Error; 252 AddLanguageEntry("commandexecutorunknownfirstargumentstart", "There is no command or classname starting with"); 253 CommandExecutor::getEvaluation().errorMessage_ = "Error: " + GetLocalisation("commandexecutorunknownfirstargumentstart") + " " + CommandExecutor::getArgument(0) + "."; 254 return; 255 } 256 else 257 { 258 // There are several possiblilities 259 std::list<std::pair<const std::string*, const std::string*> > temp; 260 temp.insert(temp.end(), CommandExecutor::getEvaluation().listOfPossibleFunctions_.begin(), CommandExecutor::getEvaluation().listOfPossibleFunctions_.end()); 261 temp.insert(temp.end(), CommandExecutor::getEvaluation().listOfPossibleIdentifiers_.begin(), CommandExecutor::getEvaluation().listOfPossibleIdentifiers_.end()); 262 CommandExecutor::getEvaluation().command_ = CommandExecutor::getCommonBegin(temp); 263 CommandExecutor::getEvaluation().function_ = CommandExecutor::getPossibleCommand(CommandExecutor::getArgument(0)); 264 CommandExecutor::getEvaluation().functionclass_ = CommandExecutor::getPossibleIdentifier(CommandExecutor::getArgument(0)); 265 return; 266 } 267 } 268 } 269 case CS_Function: 270 { 271 if (CommandExecutor::getEvaluation().functionclass_) 272 { 273 // There is a classname - search for the commandname 274 if (CommandExecutor::argumentsGiven() > 2) 275 { 276 // There is a finished second argument - check if it's a commandname 277 CommandExecutor::getEvaluation().function_ = CommandExecutor::getPossibleCommand(CommandExecutor::getArgument(1), CommandExecutor::getEvaluation().functionclass_); 278 279 if (CommandExecutor::getEvaluation().function_) 280 { 281 // It's a function 282 CommandExecutor::getEvaluation().state_ = CS_Params; 283 // Move on to next case 284 } 285 else 286 { 287 // The second argument is bad 288 CommandExecutor::getEvaluation().state_ = CS_Error; 289 AddLanguageEntry("commandexecutorunknownsecondargument", "is not a function of"); 290 CommandExecutor::getEvaluation().errorMessage_ = "Error: " + CommandExecutor::getArgument(1) + " " + GetLocalisation("commandexecutorunknownsecondargument") + " " + CommandExecutor::getEvaluation().functionclass_->getName() + "."; 291 return; 292 } 293 } 294 else 295 { 296 // There is no finished second argument - search for possibilities 297 CommandExecutor::createListOfPossibleFunctions(CommandExecutor::getArgument(1), CommandExecutor::getEvaluation().functionclass_); 298 unsigned int num_functions = CommandExecutor::getEvaluation().listOfPossibleFunctions_.size(); 299 300 if (num_functions == 1) 301 { 302 // It's a function 303 std::string functionname = *(*CommandExecutor::getEvaluation().listOfPossibleFunctions_.begin()).first; 304 CommandExecutor::getEvaluation().function_ = CommandExecutor::getPossibleCommand(functionname, CommandExecutor::getEvaluation().functionclass_); 305 if (getLowercase(functionname) != getLowercase(CommandExecutor::getArgument(1))) 306 { 307 // Unfinished function 308 CommandExecutor::getEvaluation().bCommandChanged_ = true; 309 } 310 CommandExecutor::getEvaluation().state_ = CS_Params; 311 CommandExecutor::getEvaluation().command_ = CommandExecutor::getEvaluation().functionclass_->getName() + " " + CommandExecutor::getEvaluation().function_->getName(); 312 if (CommandExecutor::getEvaluation().function_->getParamCount() > 0) 313 CommandExecutor::getEvaluation().command_ += " "; 314 // Move on to next case 315 } 316 else if (num_functions == 0) 317 { 318 // No possibilities 319 CommandExecutor::getEvaluation().state_ = CS_Error; 320 AddLanguageEntry("commandexecutorunknownsecondargumentstart", "has no function starting with"); 321 CommandExecutor::getEvaluation().errorMessage_ = "Error: " + CommandExecutor::getEvaluation().functionclass_->getName() + " " + GetLocalisation("commandexecutorunknownsecondargumentstart") + " " + CommandExecutor::getArgument(1) + "."; 322 return; 323 } 324 else 325 { 326 // There are several possibilities 327 CommandExecutor::getEvaluation().command_ = CommandExecutor::getEvaluation().functionclass_->getName() + " " + CommandExecutor::getCommonBegin(CommandExecutor::getEvaluation().listOfPossibleFunctions_); 328 CommandExecutor::getEvaluation().function_ = CommandExecutor::getPossibleCommand(CommandExecutor::getArgument(1), CommandExecutor::getEvaluation().functionclass_); 329 return; 330 } 331 } 332 } 333 else 334 { 335 // There is no classname - move on to CS_Shortcut_Params 336 } 337 } 338 std::cout << "Waiting for arguments" << std::endl; 339 case CS_Params: 340 { 341 } 342 case CS_Finished: 343 { 344 // Nothing more to do 167 345 break; 168 346 } 169 case CS_ShortcutOrIdentifier: 170 { 171 std::cout << "parse: state: CS_ShortcutOrIdentifier" << std::endl; 172 if (CommandExecutor::argumentsFinished() > 0 || !CommandExecutor::getEvaluation().bNewCommand_) 173 { 174 // There's already a finished first argument - check if it's function or a classname 175 CommandExecutor::getEvaluation().functionclass_ = CommandExecutor::getPossibleIdentifier(CommandExecutor::getArgument(0)); 176 CommandExecutor::getEvaluation().function_ = CommandExecutor::getPossibleCommand(CommandExecutor::getArgument(0)); 177 178 if (CommandExecutor::getEvaluation().function_) 179 { 180 // It's a shortcut - continue parsing 181 CommandExecutor::getEvaluation().state_ = CS_Shortcut_Params; 182 if (CommandExecutor::argumentsFinished() > 0 ) 183 CommandExecutor::parse(command, false); 184 else 185 CommandExecutor::parse(command + " ", false); 186 return; 187 } 188 else if (CommandExecutor::getEvaluation().functionclass_) 189 { 190 // It's a classname - continue parsing 191 CommandExecutor::getEvaluation().state_ = CS_Function; 192 if (CommandExecutor::argumentsFinished() > 0 ) 193 CommandExecutor::parse(command, false); 194 else 195 CommandExecutor::parse(command + " ", false); 196 return; 197 } 198 } 199 200 unsigned int numIdentifiers = CommandExecutor::getEvaluation().listOfPossibleIdentifiers_.size(); 201 unsigned int numCommands = CommandExecutor::getEvaluation().listOfPossibleFunctions_.size(); 202 203 if (CommandExecutor::argumentsFinished() == 0) 204 { 205 // There is no finished first argument 206 if (numCommands == 1 && numIdentifiers == 0) 207 { 208 // It must be this command 209 const std::string* possibleCommand = (*CommandExecutor::getEvaluation().listOfPossibleFunctions_.begin()).second; 210 CommandExecutor::getEvaluation().state_ = CS_Shortcut_Params; 211 CommandExecutor::getEvaluation().function_ = CommandExecutor::getPossibleCommand(*possibleCommand); 212 CommandExecutor::parse(*possibleCommand + " ", false); 213 return; 214 } 215 else if (numIdentifiers == 1 && numCommands == 0) 216 { 217 // It must be this classname 218 const std::string* possibleIdentifier = (*CommandExecutor::getEvaluation().listOfPossibleIdentifiers_.begin()).second; 219 CommandExecutor::getEvaluation().state_ = CS_Function; 220 CommandExecutor::getEvaluation().functionclass_ = CommandExecutor::getPossibleIdentifier(*possibleIdentifier); 221 CommandExecutor::parse(*possibleIdentifier + " ", false); 222 return; 223 } 224 } 225 226 if (numCommands == 0 && numIdentifiers == 0) 227 { 228 // It's not a shortcut nor a classname 229 CommandExecutor::getEvaluation().state_ = CS_Error; 230 AddLanguageEntry("commandexecutorunknownfirstargument", "is not a shortcut nor a classname"); 231 CommandExecutor::getEvaluation().errorMessage_ = "Error: " + CommandExecutor::getArgument(0) + " " + GetLocalisation("commandexecutorunknownfirstargument") + "."; 232 } 347 case CS_Error: 348 { 349 // Bad, very bad 233 350 break; 234 351 } 235 case CS_Function:236 std::cout << "parse: state: CS_Function" << std::endl;237 {238 if (CommandExecutor::getEvaluation().functionclass_ && CommandExecutor::argumentsGiven() > 0)239 {240 if (CommandExecutor::argumentsFinished() > 1 || !CommandExecutor::getEvaluation().bNewCommand_)241 {242 // There is already a second argument - check if it's a valid function243 CommandExecutor::getEvaluation().function_ = CommandExecutor::getPossibleCommand(CommandExecutor::getArgument(1), CommandExecutor::getEvaluation().functionclass_);244 245 if (CommandExecutor::getEvaluation().function_)246 {247 // It's a shortcut - continue parsing248 CommandExecutor::getEvaluation().state_ = CS_Function_Params;249 if (CommandExecutor::argumentsFinished() > 1 )250 CommandExecutor::parse(command, false);251 else252 CommandExecutor::parse(command + " ", false);253 return;254 }255 else if (CommandExecutor::argumentsFinished() > 1)256 {257 // It's not a function258 AddLanguageEntry("commandexecutorunknowncommand", "is not a valid commandname");259 CommandExecutor::getEvaluation().errorMessage_ = "Error: " + CommandExecutor::getArgument(1) + " " + GetLocalisation("commandexecutorunknowncommand") + ".";260 CommandExecutor::getEvaluation().state_ = CS_Error;261 }262 }263 264 CommandExecutor::createListOfPossibleFunctions(CommandExecutor::getArgument(1), CommandExecutor::getEvaluation().functionclass_);265 266 if (CommandExecutor::argumentsFinished() <= 1)267 {268 // There is no finished second argument269 unsigned int numFunctions = CommandExecutor::getEvaluation().listOfPossibleFunctions_.size();270 271 if (numFunctions == 1)272 {273 // It must be this command274 const std::string* possibleCommand = (*CommandExecutor::getEvaluation().listOfPossibleFunctions_.begin()).second;275 CommandExecutor::getEvaluation().state_ = CS_Function_Params;276 CommandExecutor::getEvaluation().function_ = CommandExecutor::getPossibleCommand(*possibleCommand, CommandExecutor::getEvaluation().functionclass_);277 CommandExecutor::parse(CommandExecutor::getArgument(0) + " " + *possibleCommand + " ", false);278 return;279 }280 else if (numFunctions == 0)281 {282 // It's not a function283 AddLanguageEntry("commandexecutorunknowncommand", "is not a valid commandname");284 CommandExecutor::getEvaluation().errorMessage_ = "Error: " + CommandExecutor::getArgument(1) + " " + GetLocalisation("commandexecutorunknowncommand") + ".";285 CommandExecutor::getEvaluation().state_ = CS_Error;286 }287 }288 289 // It's ambiguous290 return;291 }292 293 // Bad state294 CommandExecutor::getEvaluation().state_ = CS_Error;295 break;296 }297 case CS_Shortcut_Params:298 std::cout << "parse: state: CS_Shortcut_Params" << std::endl;299 case CS_Function_Params:300 {301 std::cout << "parse: state: CS_Function_Params" << std::endl;302 if (CommandExecutor::getEvaluation().function_)303 {304 unsigned int startindex = 0;305 if (CommandExecutor::getEvaluation().state_ == CS_Shortcut_Params)306 startindex = 1;307 else if (CommandExecutor::getEvaluation().state_ == CS_Function_Params)308 startindex = 2;309 310 if (CommandExecutor::argumentsGiven() >= startindex)311 {312 if ((CommandExecutor::argumentsGiven() == CommandExecutor::argumentsFinished() || !CommandExecutor::getEvaluation().bNewCommand_) && CommandExecutor::enoughArgumentsGiven(CommandExecutor::getEvaluation().function_))313 {314 if (CommandExecutor::getEvaluation().state_ == CS_Shortcut_Params)315 CommandExecutor::getEvaluation().state_ = CS_Shortcut_Finished;316 else if (CommandExecutor::getEvaluation().state_ == CS_Function_Params)317 CommandExecutor::getEvaluation().state_ = CS_Function_Finished;318 319 return;320 }321 else322 {323 CommandExecutor::createListOfPossibleArguments(CommandExecutor::getLastArgument(), CommandExecutor::getEvaluation().function_, CommandExecutor::getEvaluation().commandTokens_.size() - startindex);324 unsigned int numArguments = CommandExecutor::getEvaluation().listOfPossibleArguments_.size();325 326 if (numArguments == 1)327 {328 // There is exactly one possible argument329 const std::string* possibleArgument = (*CommandExecutor::getEvaluation().listOfPossibleArguments_.begin()).second;330 if (CommandExecutor::argumentsGiven() > CommandExecutor::argumentsFinished())331 CommandExecutor::parse(CommandExecutor::getEvaluation().commandTokens_.subSet(0, CommandExecutor::getEvaluation().commandTokens_.size() - 1).join() + " " + (*possibleArgument) + " ", false);332 else333 CommandExecutor::parse(CommandExecutor::getEvaluation().commandTokens_.subSet(0, CommandExecutor::getEvaluation().commandTokens_.size()).join() + " " + (*possibleArgument) + " ", false);334 335 return;336 }337 338 if ((CommandExecutor::argumentsGiven() > CommandExecutor::argumentsFinished()) && (!CommandExecutor::getEvaluation().bNewCommand_))339 {340 // There is more than one argument, but the user wants to use this - check if there is a perfect match341 const std::string* possibleArgument = CommandExecutor::getPossibleArgument(CommandExecutor::getLastArgument(), CommandExecutor::getEvaluation().function_, CommandExecutor::getEvaluation().commandTokens_.size() - startindex);342 if (possibleArgument)343 {344 // There is such an argument - use it345 CommandExecutor::parse(command + " ", false);346 return;347 }348 }349 }350 351 // Nothing to do352 return;353 }354 }355 356 // Bad state357 CommandExecutor::getEvaluation().state_ = CS_Error;358 break;359 }360 case CS_Shortcut_Finished:361 std::cout << "parse: state: CS_Shortcut_Finished" << std::endl;362 break;363 case CS_Function_Finished:364 std::cout << "parse: state: CS_Function_Finished" << std::endl;365 break;366 case CS_Error:367 std::cout << "parse: state: CS_Error" << std::endl;368 break;369 352 } 370 353 } … … 372 355 unsigned int CommandExecutor::argumentsFinished() 373 356 { 374 if (CommandExecutor::getEvaluation().command_.size() > 0) 375 { 376 if (CommandExecutor::getEvaluation().command_[CommandExecutor::getEvaluation().command_.size() - 1] == ' ') 377 return CommandExecutor::getEvaluation().commandTokens_.size(); 378 else if (CommandExecutor::getEvaluation().commandTokens_.size() > 0) 379 return CommandExecutor::getEvaluation().commandTokens_.size() - 1; 380 } 381 return 0; 357 unsigned int argumentsGiven = CommandExecutor::argumentsGiven(); 358 if (argumentsGiven > 0) 359 return argumentsGiven - 1; 360 else 361 return 0; 382 362 } 383 363 384 364 unsigned int CommandExecutor::argumentsGiven() 385 365 { 386 return CommandExecutor::getEvaluation().commandTokens_.size(); 366 if (CommandExecutor::getEvaluation().command_.size() > 0 && CommandExecutor::getEvaluation().command_[CommandExecutor::getEvaluation().command_.size() - 1] == ' ') 367 return CommandExecutor::getEvaluation().commandTokens_.size() + 1; 368 else 369 return CommandExecutor::getEvaluation().commandTokens_.size(); 387 370 } 388 371 … … 390 373 { 391 374 if (CommandExecutor::getEvaluation().functionclass_) 392 return (CommandExecutor:: argumentsGiven() >= (2 + command->getParamCount()));393 else 394 return (CommandExecutor:: argumentsGiven() >= (1 + command->getParamCount()));375 return (CommandExecutor::getEvaluation().commandTokens_.size() >= (2 + command->getParamCount())); 376 else 377 return (CommandExecutor::getEvaluation().commandTokens_.size() >= (1 + command->getParamCount())); 395 378 } 396 379 397 380 std::string CommandExecutor::getArgument(unsigned int index) 398 381 { 399 if ( (index >= 0) &&index < (CommandExecutor::getEvaluation().commandTokens_.size()))382 if (index < (CommandExecutor::getEvaluation().commandTokens_.size())) 400 383 return CommandExecutor::getEvaluation().commandTokens_[index]; 401 384 else … … 405 388 std::string CommandExecutor::getLastArgument() 406 389 { 407 if (CommandExecutor::getEvaluation().commandTokens_.size() > 0) 408 if (CommandExecutor::getEvaluation().commandTokens_.size() > 0 && CommandExecutor::getEvaluation().command_[CommandExecutor::getEvaluation().command_.size() - 1] != ' ') 409 return CommandExecutor::getEvaluation().commandTokens_[CommandExecutor::getEvaluation().commandTokens_.size() - 1]; 410 411 return ""; 390 return CommandExecutor::getArgument(CommandExecutor::argumentsGiven()); 412 391 } 413 392 … … 493 472 } 494 473 474 std::string CommandExecutor::getCommonBegin(const std::list<std::pair<const std::string*, const std::string*> >& list) 475 { 476 if (list.size() == 0) 477 { 478 return ""; 479 } 480 else if (list.size() == 1) 481 { 482 return ((*(*list.begin()).first) + " "); 483 } 484 else 485 { 486 std::string output = ""; 487 for (unsigned int i = 0; true; i++) 488 { 489 char temp = 0; 490 for (std::list<std::pair<const std::string*, const std::string*> >::const_iterator it = list.begin(); it != list.end(); ++it) 491 { 492 if ((*(*it).first).size() > i) 493 { 494 if (it == list.begin()) 495 { 496 temp = (*(*it).first)[i]; 497 } 498 else 499 { 500 if (temp != (*(*it).first)[i]) 501 return output; 502 } 503 } 504 else 505 { 506 return output; 507 } 508 } 509 output += temp; 510 } 511 return output; 512 } 513 } 514 495 515 bool CommandExecutor::compareStringsInList(const std::pair<const std::string*, const std::string*>& first, const std::pair<const std::string*, const std::string*>& second) 496 516 { -
code/branches/console/src/core/CommandExecutor.h
r1402 r1424 93 93 static const std::string* getPossibleArgument(const std::string& name, ConsoleCommand* command, unsigned int param); 94 94 95 static std::string getCommonBegin(const std::list<std::pair<const std::string*, const std::string*> >& list); 95 96 static bool compareStringsInList(const std::pair<const std::string*, const std::string*>& first, const std::pair<const std::string*, const std::string*>& second); 96 97 -
code/branches/console/src/core/OutputBuffer.h
r1322 r1424 42 42 friend class OutputBuffer; 43 43 44 virtual void outputChanged() = 0; 44 public: 45 virtual ~OutputBufferListener() {} 46 47 private: 48 virtual void outputChanged() = 0; 45 49 }; 46 50 -
code/branches/console/src/core/Shell.cc
r1334 r1424 32 32 #include "ConfigValueIncludes.h" 33 33 #include "CoreSettings.h" 34 #include "ConsoleCommand.h" 34 35 35 36 #define SHELL_UPDATE_LISTENERS(function) \ … … 39 40 namespace orxonox 40 41 { 42 SetConsoleCommand(Shell, clearShell, true); 43 SetConsoleCommand(Shell, history, true); 44 41 45 Shell::Shell() 42 46 { … … 104 108 } 105 109 110 void Shell::clearShell() 111 { 112 Shell::getInstance().clearLines(); 113 } 114 115 void Shell::history() 116 { 117 Shell& instance = Shell::getInstance(); 118 119 for (int i = instance.historyOffset_; i < (int)instance.commandHistory_.size(); ++i) 120 instance.addLine(instance.commandHistory_[i], -1); 121 for (int i = 0; i < (int)instance.historyOffset_; ++i) 122 instance.addLine(instance.commandHistory_[i], -1); 123 } 124 106 125 void Shell::registerListener(ShellListener* listener) 107 126 { … … 243 262 void Shell::hintandcomplete() 244 263 { 264 this->inputBuffer_.set(CommandExecutor::complete(this->inputBuffer_.get())); 245 265 this->addLine(CommandExecutor::hint(this->inputBuffer_.get()), -1); 246 this->inputBuffer_.set(CommandExecutor::complete(this->inputBuffer_.get()));247 266 248 267 this->inputChanged(); -
code/branches/console/src/core/Shell.h
r1334 r1424 45 45 friend class Shell; 46 46 47 virtual void linesChanged() {} 48 virtual void onlyLastLineChanged() {} 49 virtual void lineAdded() {} 50 virtual void inputChanged() {} 51 virtual void cursorChanged() {} 52 virtual void exit() {} 47 public: 48 virtual ~ShellListener() {} 49 50 private: 51 virtual void linesChanged() {} 52 virtual void onlyLastLineChanged() {} 53 virtual void lineAdded() {} 54 virtual void inputChanged() {} 55 virtual void cursorChanged() {} 56 virtual void exit() {} 53 57 }; 54 58 … … 58 62 static Shell& getInstance(); 59 63 static Shell& createShell(); 64 65 static void clearShell(); 66 static void history(); 60 67 61 68 virtual void setConfigValues(); … … 83 90 std::list<std::string>::const_iterator getEndIterator() const; 84 91 85 void addLine(const std::string& line, int level );92 void addLine(const std::string& line, int level = 0); 86 93 void clearLines(); 87 94 -
code/branches/console/src/core/TclThreadManager.cc
r1416 r1424 223 223 else 224 224 { 225 if ( bundle = TclThreadManager::getInstance().getInterpreterBundle(threadID))225 if ((bundle = TclThreadManager::getInstance().getInterpreterBundle(threadID))) 226 226 { 227 227 COUT(0) << "Queue dump of Tcl-thread " << threadID << ":" << std::endl; -
code/branches/console/src/orxonox/console/InGameConsole.cc
r1416 r1424 186 186 { 187 187 this->deactivate(); 188 InputManager::getSingleton().setInputMode(IM_INGAME);189 188 } 190 189 … … 364 363 this->scroll_ = -1; 365 364 // the rest is done by tick 365 InputManager::getSingleton().setInputMode(IM_INGAME); 366 366 } 367 367
Note: See TracChangeset
for help on using the changeset viewer.