Changeset 7238 for code/branches/consolecommands3/src/libraries/core
- Timestamp:
- Aug 28, 2010, 4:48:48 PM (14 years ago)
- Location:
- code/branches/consolecommands3/src/libraries/core/command
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/consolecommands3/src/libraries/core/command/CommandEvaluation.cc
r7236 r7238 124 124 } 125 125 } 126 else 127 { 128 COUT(5) << "CE_execute: " << this->string_ << "\n"; 129 return this->execCommand_->getExecutor()->parse(this->tokens_.subSet(this->execArgumentsOffset_), error, " "); 130 } 131 } 132 else 133 return MT_Type::Null; 126 else if (error) 127 *error = CommandExecutor::Incomplete; 128 } 129 130 return MT_Type::Null; 134 131 } 135 132 … … 213 210 { 214 211 std::string groupLC = getLowercase(this->getToken(0)); 215 std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommand::getCommands().begin(); 216 for ( ; it_group != ConsoleCommand::getCommands().end(); ++it_group) 217 if (getLowercase(it_group->first) == groupLC) 212 for (std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommand::getCommandsLC().begin(); it_group != ConsoleCommand::getCommandsLC().end(); ++it_group) 213 if (it_group->first == groupLC) 218 214 return std::string("Error: There is no command in group \"") + this->getToken(0) + "\" starting with \"" + this->getToken(1) + "\"."; 219 215 … … 221 217 } 222 218 } 219 } 220 221 std::string CommandEvaluation::getCommandSuggestion() const 222 { 223 std::string token0_LC = getLowercase(this->getToken(0)); 224 std::string token1_LC = getLowercase(this->getToken(1)); 225 226 std::string nearestCommand; 227 unsigned int nearestDistance = (unsigned int)-1; 228 229 for (std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommand::getCommandsLC().begin(); it_group != ConsoleCommand::getCommandsLC().end(); ++it_group) 230 { 231 if (it_group->first != "") 232 { 233 for (std::map<std::string, ConsoleCommand*>::const_iterator it_name = it_group->second.begin(); it_name != it_group->second.end(); ++it_name) 234 { 235 std::string command = it_group->first + " " + it_name->first; 236 unsigned int distance = getLevenshteinDistance(command, token0_LC + " " + token1_LC); 237 if (distance < nearestDistance) 238 { 239 nearestCommand = command; 240 nearestDistance = distance; 241 } 242 } 243 } 244 } 245 246 std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommand::getCommandsLC().find(""); 247 if (it_group != ConsoleCommand::getCommandsLC().end()) 248 { 249 for (std::map<std::string, ConsoleCommand*>::const_iterator it_name = it_group->second.begin(); it_name != it_group->second.end(); ++it_name) 250 { 251 std::string command = it_name->first; 252 unsigned int distance = getLevenshteinDistance(command, token0_LC); 253 if (distance < nearestDistance) 254 { 255 nearestCommand = command; 256 nearestDistance = distance; 257 } 258 } 259 } 260 261 return nearestCommand; 223 262 } 224 263 -
code/branches/consolecommands3/src/libraries/core/command/CommandEvaluation.h
r7236 r7238 54 54 std::string hint(); 55 55 56 std::string getCommandSuggestion() const; 57 56 58 int evaluateParams(bool bPrintError = false); 57 59 -
code/branches/consolecommands3/src/libraries/core/command/TclBind.cc
r7236 r7238 135 135 136 136 int error; 137 const std::string& result = CommandExecutor::query(command, &error, false); 137 CommandEvaluation evaluation = CommandExecutor::evaluate(command); 138 const std::string& result = evaluation.query(&error); 138 139 switch (error) 139 140 { … … 143 144 case CommandExecutor::Denied: COUT(1) << "Error: Can't execute command \"" << command << "\", access denied. (B)" << std::endl; break; 144 145 } 146 147 if (error == CommandExecutor::Error) 148 COUT(3) << "Did you mean \"" << evaluation.getCommandSuggestion() << "\"?" << std::endl; 145 149 146 150 return result;
Note: See TracChangeset
for help on using the changeset viewer.