|
30 | 30 | #include "compat.h"
|
31 | 31 | #include "linenoise/linenoise.h"
|
32 | 32 |
|
33 |
| -/* This function can be called in user completion callback to fill |
34 |
| - * path completion for them. hint parameter is actually the whole path |
35 |
| - * and buf is unused, but included to match the completion callback prototype. */ |
| 33 | +/** |
| 34 | + * @brief Fill path completion. |
| 35 | + * |
| 36 | + * @param[in] hint Path to directory. |
| 37 | + * @param[in] lc For adding completions. |
| 38 | + */ |
36 | 39 | static void
|
37 |
| -path_completion(const char *buf, const char *hint, linenoiseCompletions *lc) |
| 40 | +path_completion(const char *hint, linenoiseCompletions *lc) |
38 | 41 | {
|
39 | 42 | const char *ptr;
|
40 | 43 | char *full_path, *hint_ptr, match[FILENAME_MAX + 2];
|
41 | 44 | DIR *dir;
|
42 | 45 | struct dirent *ent;
|
43 | 46 | struct stat st;
|
44 | 47 |
|
45 |
| - (void)buf; |
46 |
| - |
47 | 48 | lc->path = 1;
|
48 | 49 |
|
49 | 50 | ptr = strrchr(hint, '/');
|
@@ -495,29 +496,28 @@ complete_cmd(const char *buf, const char *hint, linenoiseCompletions *lc)
|
495 | 496 | struct autocomplete {
|
496 | 497 | enum COMMAND_INDEX ci; /**< command index to global variable 'commands' */
|
497 | 498 | const char *opt; /**< optional option */
|
498 |
| - void (*ln_cb)(const char *, const char *, linenoiseCompletions *); /**< linenoise callback to call */ |
499 |
| - void (*yl_cb)(const char *, char ***, unsigned int *); /**< yanglint callback to call */ |
| 499 | + void (*yl_cb)(const char *, char ***, unsigned int *); /**< yanglint callback to call */ |
500 | 500 | } ac[] = {
|
501 |
| - {CMD_ADD, NULL, path_completion, NULL}, |
502 |
| - {CMD_PRINT, "-f", NULL, get_print_format_arg}, |
503 |
| - {CMD_PRINT, "-P", NULL, get_schema_completion}, |
504 |
| - {CMD_PRINT, "-o", path_completion, NULL}, |
505 |
| - {CMD_PRINT, NULL, NULL, get_model_completion}, |
506 |
| - {CMD_SEARCHPATH, NULL, path_completion, NULL}, |
507 |
| - {CMD_EXTDATA, NULL, path_completion, NULL}, |
508 |
| - {CMD_CLEAR, "-Y", path_completion, NULL}, |
509 |
| - {CMD_DATA, "-t", NULL, get_data_type_arg}, |
510 |
| - {CMD_DATA, "-O", path_completion, NULL}, |
511 |
| - {CMD_DATA, "-R", path_completion, NULL}, |
512 |
| - {CMD_DATA, "-f", NULL, get_data_in_format_arg}, |
513 |
| - {CMD_DATA, "-F", NULL, get_data_in_format_arg}, |
514 |
| - {CMD_DATA, "-d", NULL, get_data_default_arg}, |
515 |
| - {CMD_DATA, "-o", path_completion, NULL}, |
516 |
| - {CMD_DATA, NULL, path_completion, NULL}, |
517 |
| - {CMD_LIST, NULL, NULL, get_list_format_arg}, |
518 |
| - {CMD_FEATURE, NULL, NULL, get_model_completion}, |
519 |
| - {CMD_VERB, NULL, NULL, get_verb_arg}, |
520 |
| - {CMD_DEBUG, NULL, NULL, get_debug_arg}, |
| 501 | + {CMD_ADD, NULL, NULL}, |
| 502 | + {CMD_PRINT, "-f", get_print_format_arg}, |
| 503 | + {CMD_PRINT, "-P", get_schema_completion}, |
| 504 | + {CMD_PRINT, "-o", NULL}, |
| 505 | + {CMD_PRINT, NULL, get_model_completion}, |
| 506 | + {CMD_SEARCHPATH, NULL, NULL}, |
| 507 | + {CMD_EXTDATA, NULL, NULL}, |
| 508 | + {CMD_CLEAR, "-Y", NULL}, |
| 509 | + {CMD_DATA, "-t", get_data_type_arg}, |
| 510 | + {CMD_DATA, "-O", NULL}, |
| 511 | + {CMD_DATA, "-R", NULL}, |
| 512 | + {CMD_DATA, "-f", get_data_in_format_arg}, |
| 513 | + {CMD_DATA, "-F", get_data_in_format_arg}, |
| 514 | + {CMD_DATA, "-d", get_data_default_arg}, |
| 515 | + {CMD_DATA, "-o", NULL}, |
| 516 | + {CMD_DATA, NULL, NULL}, |
| 517 | + {CMD_LIST, NULL, get_list_format_arg}, |
| 518 | + {CMD_FEATURE, NULL, get_model_completion}, |
| 519 | + {CMD_VERB, NULL, get_verb_arg}, |
| 520 | + {CMD_DEBUG, NULL, get_debug_arg}, |
521 | 521 | };
|
522 | 522 | size_t name_len;
|
523 | 523 | const char *last, *name, *getoptstr;
|
@@ -555,10 +555,10 @@ complete_cmd(const char *buf, const char *hint, linenoiseCompletions *lc)
|
555 | 555 | }
|
556 | 556 |
|
557 | 557 | /* callback */
|
558 |
| - if (ac[i].ln_cb) { |
559 |
| - ac[i].ln_cb(buf, hint, lc); |
560 |
| - } else { |
| 558 | + if (ac[i].yl_cb) { |
561 | 559 | ac[i].yl_cb(hint, &matches, &match_count);
|
| 560 | + } else { |
| 561 | + path_completion(hint, lc); |
562 | 562 | }
|
563 | 563 | break;
|
564 | 564 | }
|
|
0 commit comments