Changeset 1402 for code/branches/console/src
- Timestamp:
- May 24, 2008, 2:51:31 AM (16 years ago)
- Location:
- code/branches/console/src/core
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/console/src/core/ArgumentCompletionFunctions.cc
r1390 r1402 27 27 */ 28 28 29 #include <iostream> 30 29 31 #include "ArgumentCompletionFunctions.h" 30 32 … … 35 37 const std::list<std::pair<std::string, std::string> >& fallback() 36 38 { 39 std::cout << "5_1\n"; 37 40 static std::list<std::pair<std::string, std::string> > list; 41 std::cout << "5_2\n"; 38 42 return list; 39 43 } -
code/branches/console/src/core/CommandEvaluation.cc
r1390 r1402 45 45 this->originalCommand_ = command; 46 46 this->command_ = command; 47 this->originalCommandTokens_.split(command, " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0');48 47 this->commandTokens_.split(command, " ", SubString::WhiteSpaces, false, '\\', false, '"', false, '(', ')', false, '\0'); 49 48 … … 79 78 } 80 79 81 COUT(4) << "CE_execute: " << this-> originalCommand_ << "\n";80 COUT(4) << "CE_execute: " << this->command_ << "\n"; 82 81 83 82 unsigned int startindex = this->getStartindex(); 84 if (this-> originalCommandTokens_.size() > startindex)85 return this->function_->parse(removeSlashes(this-> originalCommandTokens_.subSet(startindex).join() + this->getAdditionalParameter()));83 if (this->commandTokens_.size() > startindex) 84 return this->function_->parse(removeSlashes(this->commandTokens_.subSet(startindex).join() + this->getAdditionalParameter())); 86 85 else 87 86 return this->function_->parse(removeSlashes(this->additionalParameter_)); … … 93 92 { 94 93 case CS_Uninitialized: 94 std::cout << "complete: state: CS_Uninitialized" << std::endl; 95 case CS_Empty: 96 std::cout << "complete: state: CS_Empty" << std::endl; 97 case CS_ShortcutOrIdentifier: 98 std::cout << "complete: state: CS_ShortcutOrIdentifier" << std::endl; 99 { 100 std::list<std::pair<const std::string*, const std::string*> > temp; 101 temp.insert(temp.end(), this->listOfPossibleFunctions_.begin(), this->listOfPossibleFunctions_.end()); 102 temp.insert(temp.end(), this->listOfPossibleIdentifiers_.begin(), this->listOfPossibleIdentifiers_.end()); 103 if (temp.size() > 0) 104 { 105 std::cout << "complete: temp > 0" << std::endl; 106 return (CommandEvaluation::getCommonBegin(temp)); 107 } 108 } 109 break; 110 case CS_Shortcut_Params: 111 std::cout << "complete: state: CS_Shortcut_Params" << std::endl; 112 if (this->function_) 113 { 114 std::cout << "complete: function != 0" << std::endl; 115 if (this->commandTokens_.size() > 1) 116 return (this->function_->getName() + " " + this->commandTokens_.subSet(1, this->commandTokens_.size() - 1).join() + " " + CommandEvaluation::getCommonBegin(this->listOfPossibleArguments_)); 117 else 118 return (this->function_->getName() + " "); 119 } 120 break; 121 case CS_Shortcut_Finished: 122 std::cout << "complete: state: CS_Shortcut_Finished" << std::endl; 123 if (this->function_) 124 { 125 std::cout << "complete: function != 0" << std::endl; 126 if (this->commandTokens_.size() > 1) 127 return (this->function_->getName() + " " + this->commandTokens_.subSet(1, this->commandTokens_.size() - 1).join()); 128 else 129 return (this->function_->getName()); 130 } 131 break; 132 case CS_Function: 133 std::cout << "complete: state: CS_Function" << std::endl; 134 if (this->functionclass_) 135 { 136 std::cout << "complete: functionclass != 0" << std::endl; 137 return (this->functionclass_->getName() + " " + CommandEvaluation::getCommonBegin(this->listOfPossibleFunctions_)); 138 } 139 break; 140 case CS_Function_Params: 141 std::cout << "complete: state: CS_Function_Params" << std::endl; 142 if (this->functionclass_ && this->function_) 143 { 144 std::cout << "complete: function und functionclass != 0" << std::endl; 145 if (this->commandTokens_.size() > 2) 146 return (this->functionclass_->getName() + " " + this->function_->getName() + " " + this->commandTokens_.subSet(2, this->commandTokens_.size()).join() + " " + CommandEvaluation::getCommonBegin(this->listOfPossibleArguments_)); 147 else 148 return (this->functionclass_->getName() + " " + this->function_->getName() + " "); 149 } 150 break; 151 case CS_Function_Finished: 152 std::cout << "complete: state: CS_Function_Finished" << std::endl; 153 if (this->functionclass_ && this->function_) 154 { 155 std::cout << "complete: function und functionclass != 0" << std::endl; 156 if (this->commandTokens_.size() > 2) 157 return (this->functionclass_->getName() + " " + this->function_->getName() + " " + this->commandTokens_.subSet(2, this->commandTokens_.size()).join()); 158 else 159 return (this->functionclass_->getName() + " " + this->function_->getName()); 160 } 161 break; 162 case CS_Error: 163 std::cout << "complete: state: CS_Error" << std::endl; 164 break; 165 } 166 167 return this->originalCommand_; 168 } 169 170 std::string CommandEvaluation::hint() const 171 { 172 switch (this->state_) 173 { 174 case CS_Uninitialized: 175 break; 95 176 case CS_Empty: 96 177 case CS_ShortcutOrIdentifier: 97 { 98 std::list<std::pair<const std::string*, const std::string*> > temp; 99 if (this->state_ == CS_Empty) 100 { 101 temp.insert(temp.end(), this->listOfPossibleFunctions_.begin(), this->listOfPossibleFunctions_.end()); 102 temp.insert(temp.end(), this->listOfPossibleIdentifiers_.begin(), this->listOfPossibleIdentifiers_.end()); 103 } 104 return (CommandEvaluation::getCommonBegin(temp)); 105 } 106 break; 107 case CS_Shortcut_Params: 108 if (this->function_) 109 { 110 if (this->commandTokens_.size() > 1) 111 return (this->function_->getName() + " " + this->commandTokens_.subSet(1, this->commandTokens_.size() - 1).join() + " " + CommandEvaluation::getCommonBegin(this->listOfPossibleArguments_)); 112 else 113 return (this->function_->getName() + " "); 114 } 115 break; 116 case CS_Shortcut_Finished: 117 if (this->function_) 118 { 119 if (this->commandTokens_.size() > 1) 120 return (this->function_->getName() + " " + this->originalCommandTokens_.subSet(1, this->originalCommandTokens_.size() - 1).join()); 121 else 122 return (this->function_->getName()); 123 } 124 break; 125 case CS_Function: 126 if (this->functionclass_) 127 return (this->functionclass_->getName() + " " + CommandEvaluation::getCommonBegin(this->listOfPossibleFunctions_)); 128 break; 129 case CS_Function_Params: 130 if (this->functionclass_ && this->function_) 131 { 132 if (this->commandTokens_.size() > 2) 133 return (this->functionclass_->getName() + " " + this->function_->getName() + " " + this->commandTokens_.subSet(2, this->commandTokens_.size() - 1).join() + " " + CommandEvaluation::getCommonBegin(this->listOfPossibleArguments_)); 134 else 135 return (this->functionclass_->getName() + " " + this->function_->getName() + " "); 136 } 137 break; 138 case CS_Function_Finished: 139 if (this->functionclass_ && this->function_) 140 { 141 if (this->commandTokens_.size() > 2) 142 return (this->functionclass_->getName() + " " + this->function_->getName() + " " + this->originalCommandTokens_.subSet(2, this->originalCommandTokens_.size() - 1).join()); 143 else 144 return (this->functionclass_->getName() + " " + this->function_->getName()); 145 } 146 break; 147 case CS_Error: 148 break; 149 } 150 151 return this->originalCommand_; 152 } 153 154 std::string CommandEvaluation::hint() const 155 { 156 switch (this->state_) 157 { 158 case CS_Uninitialized: 159 break; 160 case CS_Empty: 161 case CS_ShortcutOrIdentifier: 162 return (CommandEvaluation::dump(this->listOfPossibleFunctions_) + "\n" + CommandEvaluation::dump(this->listOfPossibleIdentifiers_)); 178 if (this->listOfPossibleFunctions_.size() == 0) 179 return CommandEvaluation::dump(this->listOfPossibleIdentifiers_); 180 else if (this->listOfPossibleIdentifiers_.size() == 0) 181 return CommandEvaluation::dump(this->listOfPossibleFunctions_); 182 else 183 return (CommandEvaluation::dump(this->listOfPossibleFunctions_) + "\n" + CommandEvaluation::dump(this->listOfPossibleIdentifiers_)); 163 184 break; 164 185 case CS_Function: … … 167 188 case CS_Shortcut_Params: 168 189 case CS_Function_Params: 169 return CommandEvaluation::dump(this->listOfPossibleArguments_); 190 if (this->listOfPossibleArguments_.size() > 0) 191 return CommandEvaluation::dump(this->listOfPossibleArguments_); 192 else 193 return CommandEvaluation::dump(this->function_); 170 194 case CS_Shortcut_Finished: 171 195 case CS_Function_Finished: … … 193 217 unsigned int startindex = this->getStartindex(); 194 218 195 if (this-> originalCommandTokens_.size() <= startindex)219 if (this->commandTokens_.size() <= startindex) 196 220 { 197 221 if (this->function_->evaluate(this->getAdditionalParameter(), this->param_, " ")) 198 222 this->bEvaluatedParams_ = true; 199 223 } 200 else if (this-> originalCommandTokens_.size() > startindex)201 { 202 if (this->function_->evaluate(this-> originalCommandTokens_.subSet(startindex).join() + this->getAdditionalParameter(), this->param_, " "))224 else if (this->commandTokens_.size() > startindex) 225 { 226 if (this->function_->evaluate(this->commandTokens_.subSet(startindex).join() + this->getAdditionalParameter(), this->param_, " ")) 203 227 this->bEvaluatedParams_ = true; 204 228 } -
code/branches/console/src/core/CommandEvaluation.h
r1390 r1402 86 86 inline void setState(CommandState state) 87 87 { this->state_ = state; } 88 inline SubString& getOriginalTokens()89 { return this->originalCommandTokens_; }90 88 inline SubString& getTokens() 91 89 { return this->commandTokens_; } … … 130 128 std::string originalCommand_; 131 129 std::string command_; 132 SubString originalCommandTokens_;133 130 SubString commandTokens_; 134 131 std::string additionalParameter_; -
code/branches/console/src/core/CommandExecutor.cc
r1390 r1402 101 101 return TclBind::eval(command); 102 102 103 if ((CommandExecutor::getEvaluation().getCommand() != command) || (CommandExecutor::getEvaluation().getState() == CS_Uninitialized)) 104 CommandExecutor::parse(command); 105 103 CommandExecutor::parseIfNeeded(command); 106 104 return CommandExecutor::getEvaluation().execute(); 107 105 } … … 109 107 std::string CommandExecutor::complete(const std::string& command) 110 108 { 111 if ((CommandExecutor::getEvaluation().getCommand() != command) || (CommandExecutor::getEvaluation().getState() == CS_Uninitialized)) 112 CommandExecutor::parse(command); 113 109 CommandExecutor::parseIfNeeded(command); 114 110 return CommandExecutor::getEvaluation().complete(); 115 111 } … … 117 113 std::string CommandExecutor::hint(const std::string& command) 118 114 { 119 if ((CommandExecutor::getEvaluation().getCommand() != command) || (CommandExecutor::getEvaluation().getState() == CS_Uninitialized)) 120 CommandExecutor::parse(command); 121 115 CommandExecutor::parseIfNeeded(command); 122 116 return CommandExecutor::getEvaluation().hint(); 123 117 } … … 130 124 } 131 125 126 void CommandExecutor::parseIfNeeded(const std::string& command) 127 { 128 if ((CommandExecutor::getEvaluation().getCommand() != command) || (CommandExecutor::getEvaluation().getState() == CS_Uninitialized)) 129 CommandExecutor::parse(command); 130 else if (!CommandExecutor::getEvaluation().isValid()) 131 { 132 CommandExecutor::getEvaluation().setNewCommand(false); 133 CommandExecutor::parse(command, false); 134 } 135 } 136 132 137 void CommandExecutor::parse(const std::string& command, bool bInitialize) 133 138 { 139 std::cout << "parse: command: >" << command << "<" << std::endl; 134 140 if (bInitialize) 135 141 CommandExecutor::getEvaluation().initialize(command); 136 else 137 CommandExecutor::getEvaluation().setNewCommand(false); 138 139 CommandExecutor::getEvaluation().setTokens(command + COMMAND_EXECUTOR_CURSOR); 142 143 CommandExecutor::getEvaluation().setTokens(command); 140 144 CommandExecutor::getEvaluation().setCommand(command); 141 145 … … 143 147 { 144 148 case CS_Uninitialized: 149 { 150 std::cout << "parse: state: CS_Uninitialized" << std::endl; 145 151 // Impossible 146 152 break; 153 } 147 154 case CS_Empty: 155 { 156 std::cout << "parse: state: CS_Empty" << std::endl; 148 157 CommandExecutor::createListOfPossibleIdentifiers(CommandExecutor::getArgument(0)); 149 158 CommandExecutor::createListOfPossibleFunctions(CommandExecutor::getArgument(0)); … … 156 165 } 157 166 break; 167 } 158 168 case CS_ShortcutOrIdentifier: 169 { 170 std::cout << "parse: state: CS_ShortcutOrIdentifier" << std::endl; 159 171 if (CommandExecutor::argumentsFinished() > 0 || !CommandExecutor::getEvaluation().isNewCommand()) 160 172 { … … 185 197 } 186 198 199 unsigned int numIdentifiers = CommandExecutor::getEvaluation().getListOfPossibleIdentifiers().size(); 200 unsigned int numCommands = CommandExecutor::getEvaluation().getListOfPossibleFunctions().size(); 201 187 202 if (CommandExecutor::argumentsFinished() == 0) 188 203 { 189 204 // There is no finished first argument 190 unsigned int numIdentifiers = CommandExecutor::getEvaluation().getListOfPossibleIdentifiers().size();191 unsigned int numCommands = CommandExecutor::getEvaluation().getListOfPossibleFunctions().size();192 193 205 if (numCommands == 1 && numIdentifiers == 0) 194 206 { … … 211 223 } 212 224 213 // It's not a shortcut nor a classname 214 CommandExecutor::getEvaluation().setState(CS_Error); 215 AddLanguageEntry("commandexecutorunknownfirstargument", "is not a shortcut nor a classname"); 216 CommandExecutor::getEvaluation().setError("Error: " + CommandExecutor::getArgument(0) + " " + GetLocalisation("commandexecutorunknownfirstargument") + "."); 217 break; 225 if (numCommands == 0 && numIdentifiers == 0) 226 { 227 // It's not a shortcut nor a classname 228 CommandExecutor::getEvaluation().setState(CS_Error); 229 AddLanguageEntry("commandexecutorunknownfirstargument", "is not a shortcut nor a classname"); 230 CommandExecutor::getEvaluation().setError("Error: " + CommandExecutor::getArgument(0) + " " + GetLocalisation("commandexecutorunknownfirstargument") + "."); 231 } 232 break; 233 } 218 234 case CS_Function: 219 if (CommandExecutor::getEvaluation().getIdentifier() && CommandExecutor::argumentsGiven() > 1) 235 std::cout << "parse: state: CS_Function" << std::endl; 236 { 237 if (CommandExecutor::getEvaluation().getIdentifier() && CommandExecutor::argumentsGiven() > 0) 220 238 { 221 239 if (CommandExecutor::argumentsFinished() > 1 || !CommandExecutor::getEvaluation().isNewCommand()) … … 234 252 return; 235 253 } 236 } 254 else if (CommandExecutor::argumentsFinished() > 1) 255 { 256 // It's not a function 257 AddLanguageEntry("commandexecutorunknowncommand", "is not a valid commandname"); 258 CommandExecutor::getEvaluation().setError("Error: " + CommandExecutor::getArgument(1) + " " + GetLocalisation("commandexecutorunknowncommand") + "."); 259 CommandExecutor::getEvaluation().setState(CS_Error); 260 } 261 } 262 263 CommandExecutor::createListOfPossibleFunctions(CommandExecutor::getArgument(1), CommandExecutor::getEvaluation().getIdentifier()); 237 264 238 265 if (CommandExecutor::argumentsFinished() <= 1) 239 266 { 240 267 // There is no finished second argument 241 CommandExecutor::createListOfPossibleFunctions(CommandExecutor::getArgument(0), CommandExecutor::getEvaluation().getIdentifier());242 268 unsigned int numFunctions = CommandExecutor::getEvaluation().getListOfPossibleFunctions().size(); 243 269 … … 247 273 const std::string* possibleCommand = (*CommandExecutor::getEvaluation().getListOfPossibleFunctions().begin()).second; 248 274 CommandExecutor::getEvaluation().setState(CS_Function_Params); 249 CommandExecutor::getEvaluation().setFunction(CommandExecutor::getPossibleCommand(*possibleCommand ));250 CommandExecutor::parse( *possibleCommand + " ", false);275 CommandExecutor::getEvaluation().setFunction(CommandExecutor::getPossibleCommand(*possibleCommand, CommandExecutor::getEvaluation().getIdentifier())); 276 CommandExecutor::parse(CommandExecutor::getArgument(0) + " " + *possibleCommand + " ", false); 251 277 return; 252 278 } 253 } 254 255 // It's not a function 256 AddLanguageEntry("commandexecutorunknowncommand", "is not a valid commandname"); 257 CommandExecutor::getEvaluation().setError("Error: " + CommandExecutor::getArgument(1) + " " + GetLocalisation("commandexecutorunknowncommand") + "."); 279 else if (numFunctions == 0) 280 { 281 // It's not a function 282 AddLanguageEntry("commandexecutorunknowncommand", "is not a valid commandname"); 283 CommandExecutor::getEvaluation().setError("Error: " + CommandExecutor::getArgument(1) + " " + GetLocalisation("commandexecutorunknowncommand") + "."); 284 CommandExecutor::getEvaluation().setState(CS_Error); 285 } 286 } 287 288 // It's ambiguous 289 return; 258 290 } 259 291 … … 261 293 CommandExecutor::getEvaluation().setState(CS_Error); 262 294 break; 295 } 263 296 case CS_Shortcut_Params: 297 std::cout << "parse: state: CS_Shortcut_Params" << std::endl; 264 298 case CS_Function_Params: 299 { 300 std::cout << "parse: state: CS_Function_Params" << std::endl; 265 301 if (CommandExecutor::getEvaluation().getFunction()) 266 302 { 303 std::cout << "1\n"; 267 304 unsigned int startindex = 0; 268 305 if (CommandExecutor::getEvaluation().getState() == CS_Shortcut_Params) … … 270 307 else if (CommandExecutor::getEvaluation().getState() == CS_Function_Params) 271 308 startindex = 2; 309 std::cout << "2\n"; 272 310 273 311 if (CommandExecutor::argumentsGiven() >= startindex) 274 312 { 313 std::cout << "3\n"; 275 314 if (CommandExecutor::enoughArgumentsGiven(CommandExecutor::getEvaluation().getFunction())) 276 315 { 316 std::cout << "4\n"; 277 317 if (CommandExecutor::getEvaluation().getState() == CS_Shortcut_Params) 278 318 CommandExecutor::getEvaluation().setState(CS_Shortcut_Finished); 279 319 else if (CommandExecutor::getEvaluation().getState() == CS_Function_Params) 280 320 CommandExecutor::getEvaluation().setState(CS_Function_Finished); 321 281 322 return; 282 323 } 283 324 else 284 325 { 285 CommandExecutor::createListOfPossibleArguments(CommandExecutor::getLastArgument(), CommandExecutor::getEvaluation().getFunction(), CommandExecutor::getEvaluation().getOriginalTokens().size() - startindex); 326 std::cout << "5\n"; 327 std::cout << "last argument: " << CommandExecutor::getLastArgument() << std::endl; 328 std::cout << "function: " << CommandExecutor::getEvaluation().getFunction() << std::endl; 329 std::cout << "functionname: " << CommandExecutor::getEvaluation().getFunction()->getName() << std::endl; 330 std::cout << "param nr: " << CommandExecutor::getEvaluation().getTokens().size() - startindex << std::endl; 331 CommandExecutor::createListOfPossibleArguments(CommandExecutor::getLastArgument(), CommandExecutor::getEvaluation().getFunction(), CommandExecutor::getEvaluation().getTokens().size() - startindex); 332 std::cout << "6\n"; 286 333 unsigned int numArguments = CommandExecutor::getEvaluation().getListOfPossibleArguments().size(); 287 334 288 335 if (numArguments == 1) 289 336 { 337 std::cout << "7\n"; 290 338 // There is exactly one possible argument 291 339 const std::string* possibleArgument = (*CommandExecutor::getEvaluation().getListOfPossibleArguments().begin()).second; … … 294 342 } 295 343 296 if (!CommandExecutor::getEvaluation().isNewCommand()) 344 std::cout << "8\n"; 345 if ((CommandExecutor::argumentsGiven() > CommandExecutor::argumentsFinished()) && (!CommandExecutor::getEvaluation().isNewCommand())) 297 346 { 347 std::cout << "9\n"; 298 348 // There is more than one argument, but the user wants to use this - check if there is a perfect match 299 const std::string* possibleArgument = CommandExecutor::getPossibleArgument(CommandExecutor::getLastArgument(), CommandExecutor::getEvaluation().getFunction(), CommandExecutor::getEvaluation().get OriginalTokens().size() - startindex);349 const std::string* possibleArgument = CommandExecutor::getPossibleArgument(CommandExecutor::getLastArgument(), CommandExecutor::getEvaluation().getFunction(), CommandExecutor::getEvaluation().getTokens().size() - startindex); 300 350 if (possibleArgument) 301 351 { 352 std::cout << "10\n"; 302 353 // There is such an argument - use it 303 354 CommandExecutor::parse(command + " ", false); 304 355 return; 305 356 } 357 std::cout << "11\n"; 306 358 } 359 std::cout << "12\n"; 307 360 } 361 std::cout << "13\n"; 362 363 // Nothing to do 364 return; 308 365 } 309 366 } … … 312 369 CommandExecutor::getEvaluation().setState(CS_Error); 313 370 break; 371 } 314 372 case CS_Shortcut_Finished: 373 std::cout << "parse: state: CS_Shortcut_Finished" << std::endl; 374 break; 315 375 case CS_Function_Finished: 376 std::cout << "parse: state: CS_Function_Finished" << std::endl; 377 break; 316 378 case CS_Error: 379 std::cout << "parse: state: CS_Error" << std::endl; 317 380 break; 318 381 } … … 321 384 unsigned int CommandExecutor::argumentsFinished() 322 385 { 323 // Because we added a cursor we have +1 arguments 324 if (CommandExecutor::getEvaluation().getTokens().size() >= 1) 325 return (CommandExecutor::getEvaluation().getTokens().size() - 1); 326 else 327 return 0; 386 if (CommandExecutor::getEvaluation().getCommand().size() > 0) 387 { 388 if (CommandExecutor::getEvaluation().getCommand()[CommandExecutor::getEvaluation().getCommand().size() - 1] == ' ') 389 return CommandExecutor::getEvaluation().getTokens().size(); 390 else if (CommandExecutor::getEvaluation().getTokens().size() > 0) 391 return CommandExecutor::getEvaluation().getTokens().size() - 1; 392 } 393 return 0; 328 394 } 329 395 330 396 unsigned int CommandExecutor::argumentsGiven() 331 397 { 332 return CommandExecutor::getEvaluation().get OriginalTokens().size();398 return CommandExecutor::getEvaluation().getTokens().size(); 333 399 } 334 400 … … 343 409 std::string CommandExecutor::getArgument(unsigned int index) 344 410 { 345 if ((index >= 0) && index < (CommandExecutor::getEvaluation().get OriginalTokens().size()))346 return CommandExecutor::getEvaluation().get OriginalTokens()[index];411 if ((index >= 0) && index < (CommandExecutor::getEvaluation().getTokens().size())) 412 return CommandExecutor::getEvaluation().getTokens()[index]; 347 413 else 348 414 return ""; … … 351 417 std::string CommandExecutor::getLastArgument() 352 418 { 353 if (CommandExecutor::getEvaluation().getOriginalTokens().size() > 0) 354 return CommandExecutor::getEvaluation().getOriginalTokens()[0]; 355 else 356 return ""; 419 if (CommandExecutor::getEvaluation().getTokens().size() > 0) 420 if (CommandExecutor::getEvaluation().getCommand().size() > 0 && CommandExecutor::getEvaluation().getCommand()[CommandExecutor::getEvaluation().getCommand().size() - 1] != ' ') 421 return CommandExecutor::getEvaluation().getTokens()[CommandExecutor::getEvaluation().getTokens().size() - 1]; 422 423 return ""; 357 424 } 358 425 359 426 void CommandExecutor::createListOfPossibleIdentifiers(const std::string& fragment) 360 427 { 428 std::string lowercase = getLowercase(fragment); 361 429 for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseIdentifierMapBegin(); it != Identifier::getLowercaseIdentifierMapEnd(); ++it) 362 430 if ((*it).second->hasConsoleCommands()) 363 if ((*it).first.find( getLowercase(fragment)) == 0 || fragment == "")431 if ((*it).first.find(lowercase) == 0 || fragment == "") 364 432 CommandExecutor::getEvaluation().getListOfPossibleIdentifiers().push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName())); 365 433 … … 369 437 void CommandExecutor::createListOfPossibleFunctions(const std::string& fragment, Identifier* identifier) 370 438 { 439 std::string lowercase = getLowercase(fragment); 371 440 if (!identifier) 372 441 { 373 442 for (std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMapBegin(); it != CommandExecutor::getLowercaseConsoleCommandShortcutMapEnd(); ++it) 374 if ((*it).first.find( getLowercase(fragment)) == 0 || fragment == "")443 if ((*it).first.find(lowercase) == 0 || fragment == "") 375 444 CommandExecutor::getEvaluation().getListOfPossibleFunctions().push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName())); 376 445 } … … 378 447 { 379 448 for (std::map<std::string, ConsoleCommand*>::const_iterator it = identifier->getLowercaseConsoleCommandMapBegin(); it != identifier->getLowercaseConsoleCommandMapEnd(); ++it) 380 if ((*it).first.find( getLowercase(fragment)) == 0 || fragment == "")449 if ((*it).first.find(lowercase) == 0 || fragment == "") 381 450 CommandExecutor::getEvaluation().getListOfPossibleFunctions().push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName())); 382 451 } 452 383 453 CommandExecutor::getEvaluation().getListOfPossibleFunctions().sort(CommandExecutor::compareStringsInList); 384 454 } … … 386 456 void CommandExecutor::createListOfPossibleArguments(const std::string& fragment, ConsoleCommand* command, unsigned int param) 387 457 { 458 std::cout << "2_1\n"; 459 std::string lowercase = getLowercase(fragment); 460 std::cout << "2_2\n"; 388 461 for (std::list<std::pair<std::string, std::string> >::const_iterator it = command->getArgumentCompletionListBegin(param); it != command->getArgumentCompletionListEnd(param); ++it) 389 if ((*it).first.find(getLowercase(fragment)) == 0 || fragment == "") 462 { 463 std::cout << "2_3\n"; 464 if ((*it).first.find(lowercase) == 0 || fragment == "") 465 { 466 std::cout << "2_4\n"; 390 467 CommandExecutor::getEvaluation().getListOfPossibleArguments().push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second)); 391 392 CommandExecutor::getEvaluation().getListOfPossibleIdentifiers().sort(CommandExecutor::compareStringsInList); 393 468 std::cout << "2_5\n"; 469 } 470 } 471 472 std::cout << "2_6\n"; 473 CommandExecutor::getEvaluation().getListOfPossibleArguments().sort(CommandExecutor::compareStringsInList); 474 std::cout << "2_7\n"; 394 475 } 395 476 396 477 Identifier* CommandExecutor::getPossibleIdentifier(const std::string& name) 397 478 { 398 std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseIdentifierMap().find(getLowercase(name)); 479 std::string lowercase = getLowercase(name); 480 std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseIdentifierMap().find(lowercase); 399 481 if ((it != Identifier::getLowercaseIdentifierMapEnd()) && (*it).second->hasConsoleCommands()) 400 482 return (*it).second; … … 405 487 ConsoleCommand* CommandExecutor::getPossibleCommand(const std::string& name, Identifier* identifier) 406 488 { 489 std::string lowercase = getLowercase(name); 407 490 if (!identifier) 408 491 { 409 std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMap().find( getLowercase(name));492 std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getLowercaseConsoleCommandShortcutMap().find(lowercase); 410 493 if (it != CommandExecutor::getLowercaseConsoleCommandShortcutMapEnd()) 411 494 return (*it).second; … … 413 496 else 414 497 { 415 std::map<std::string, ConsoleCommand*>::const_iterator it = identifier->getLowercaseConsoleCommandMap().find( getLowercase(name));498 std::map<std::string, ConsoleCommand*>::const_iterator it = identifier->getLowercaseConsoleCommandMap().find(lowercase); 416 499 if (it != identifier->getLowercaseConsoleCommandMapEnd()) 417 500 return (*it).second; … … 422 505 const std::string* CommandExecutor::getPossibleArgument(const std::string& name, ConsoleCommand* command, unsigned int param) 423 506 { 424 std::string lowercase name= getLowercase(name);507 std::string lowercase = getLowercase(name); 425 508 for (std::list<std::pair<std::string, std::string> >::const_iterator it = command->getArgumentCompletionListBegin(param); it != command->getArgumentCompletionListEnd(param); ++it) 426 if ((*it).first == lowercase name)509 if ((*it).first == lowercase) 427 510 return &(*it).second; 428 511 -
code/branches/console/src/core/CommandExecutor.h
r1390 r1402 76 76 static CommandEvaluation& getEvaluation(); 77 77 78 static void parseIfNeeded(const std::string& command); 78 79 static void parse(const std::string& command, bool bInitialize = true); 79 80 -
code/branches/console/src/core/ConsoleCommand.cc
r1390 r1402 43 43 ConsoleCommand& ConsoleCommand::setArgumentCompletionList(unsigned int param, const std::list<std::pair<std::string, std::string> >& (*function) (void)) 44 44 { 45 if (param >= 0 && param< 5)45 if (param < 5) 46 46 this->autocompletionFunction_[param] = function; 47 47 else … … 54 54 const std::list<std::pair<std::string, std::string> >& ConsoleCommand::getArgumentCompletionList(unsigned int param) const 55 55 { 56 if (param >= 0 && param< 5)56 if (param < 5) 57 57 return (*this->autocompletionFunction_[param])(); 58 58 else … … 62 62 std::list<std::pair<std::string, std::string> >::const_iterator ConsoleCommand::getArgumentCompletionListBegin(unsigned int param) const 63 63 { 64 if (param >= 0 && param < 5) 64 std::cout << "3_1: param: " << param << "\n"; 65 if (param < 5) 66 { 67 std::cout << "3_2: >" << this->autocompletionFunction_[param] << "<\n"; 65 68 return (*this->autocompletionFunction_[param])().begin(); 69 } 66 70 else 71 { 72 std::cout << "3_3\n"; 67 73 return autocompletion::fallback().begin(); 74 } 68 75 } 69 76 70 77 std::list<std::pair<std::string, std::string> >::const_iterator ConsoleCommand::getArgumentCompletionListEnd(unsigned int param) const 71 78 { 72 if (param >= 0 && param < 5) 79 std::cout << "4_1: param: " << param << "\n"; 80 if (param < 5) 81 { 82 std::cout << "4_2: >" << this->autocompletionFunction_[param] << "<\n"; 73 83 return (*this->autocompletionFunction_[param])().end(); 84 } 74 85 else 86 { 87 std::cout << "4_3\n"; 75 88 return autocompletion::fallback().end(); 89 } 76 90 } 77 91 }
Note: See TracChangeset
for help on using the changeset viewer.