| 291 | } |
| 292 | |
| 293 | bool Console::findBestCommand(char* best_command, const char* text, PxU32& tabIndex) const |
| 294 | { |
| 295 | if(!text || !best_command) |
| 296 | return false; |
| 297 | |
| 298 | const size_t length = strlen(text); |
| 299 | if(length>1023) |
| 300 | return false; |
| 301 | |
| 302 | char tmp[1024]; |
| 303 | strcpy(tmp, text); |
| 304 | Ps::strlwr(tmp); |
| 305 | |
| 306 | const unsigned char i = tmp[0]; |
| 307 | |
| 308 | ConsoleCommand* FirstCommand = NULL; |
| 309 | ConsoleCommand* BestCommand = NULL; |
| 310 | ConsoleCommand* pcmd = mCmds[i]; |
| 311 | PxU32 currentIndex = 0; |
| 312 | while(pcmd && !BestCommand) |
| 313 | { |
| 314 | char tmp2[1024]; |
| 315 | strcpy(tmp2, pcmd->fullcmd); |
| 316 | Ps::strlwr(tmp2); |
| 317 | if(Ps::strncmp(tmp, tmp2, length)== 0) |
| 318 | { |
| 319 | if(!currentIndex) |
| 320 | FirstCommand = pcmd; |
| 321 | |
| 322 | if(currentIndex>=tabIndex) |
| 323 | BestCommand = pcmd; |
| 324 | currentIndex++; |
| 325 | } |
| 326 | pcmd = pcmd->next; |
| 327 | } |
| 328 | |
| 329 | if(BestCommand) |
| 330 | { |
| 331 | tabIndex++; |
| 332 | strcpy(best_command, BestCommand->fullcmd); |
| 333 | return true; |
| 334 | } |
| 335 | |
| 336 | tabIndex = 0; |
| 337 | if(currentIndex && FirstCommand) |
| 338 | { |
| 339 | tabIndex++; |
| 340 | strcpy(best_command, FirstCommand->fullcmd); |
| 341 | return true; |
| 342 | } |
| 343 | return false; |
| 344 | } |
| 345 | |
| 346 | // Try to execute a command |
| 347 | bool Console::execCmd(const char* cmd, const char* param) |