| 435 | } |
| 436 | |
| 437 | inline void CLI_tabCompletion() |
| 438 | { |
| 439 | // Ignore command if buffer is 0 length |
| 440 | if ( CLILineBufferCurrent == 0 ) |
| 441 | return; |
| 442 | |
| 443 | // Set the last+1 character of the buffer to NULL for string processing |
| 444 | CLILineBuffer[CLILineBufferCurrent] = '\0'; |
| 445 | |
| 446 | // Retrieve pointers to command and beginning of arguments |
| 447 | // Places a NULL at the first space after the command |
| 448 | char* cmdPtr; |
| 449 | char* argPtr; |
| 450 | CLI_argumentIsolation( CLILineBuffer, &cmdPtr, &argPtr ); |
| 451 | |
| 452 | // Tab match pointer |
| 453 | char* tabMatch = 0; |
| 454 | uint8_t matches = 0; |
| 455 | |
| 456 | // Scan array of dictionaries for a valid command match |
| 457 | for ( uint8_t dict = 0; dict < CLIDictionariesUsed; dict++ ) |
| 458 | { |
| 459 | // Parse each cmd until a null command entry is found, or an argument match |
| 460 | for ( uint8_t cmd = 0; CLIDict[dict][cmd].name != 0; cmd++ ) |
| 461 | { |
| 462 | // Compare the first argument piece to each command entry to see if it is "like" |
| 463 | // NOTE: To save on processing, we only care about the commands and ignore the arguments |
| 464 | // If there are arguments, and a valid tab match is found, buffer is cleared (args lost) |
| 465 | // Also ignores full matches |
| 466 | if ( eqStr( cmdPtr, (char*)CLIDict[dict][cmd].name ) == 0 ) |
| 467 | { |
| 468 | // TODO Make list of commands if multiple matches |
| 469 | matches++; |
| 470 | tabMatch = (char*)CLIDict[dict][cmd].name; |
| 471 | } |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | // Only tab complete if there was 1 match |
| 476 | if ( matches == 1 ) |
| 477 | { |
| 478 | // Reset the buffer |
| 479 | CLILineBufferCurrent = 0; |
| 480 | |
| 481 | // Reprint the prompt (automatically clears the line) |
| 482 | prompt(); |
| 483 | |
| 484 | // Display the command |
| 485 | dPrint( tabMatch ); |
| 486 | |
| 487 | // There are no index counts, so just copy the whole string to the input buffer |
| 488 | while ( *tabMatch != '\0' ) |
| 489 | { |
| 490 | CLILineBuffer[CLILineBufferCurrent++] = *tabMatch++; |
| 491 | } |
| 492 | } |
| 493 | } |
| 494 |
no test coverage detected
searching dependent graphs…