diff options
author | Richard Braun <rbraun@sceen.net> | 2018-07-25 01:15:13 +0200 |
---|---|---|
committer | Richard Braun <rbraun@sceen.net> | 2018-07-25 01:15:13 +0200 |
commit | ba0f421610fc9b87964cf30fee67d1834e62b431 (patch) | |
tree | fddb2761bf0e6c8c3ca6db23a5d6220565be9f36 /src | |
parent | 0a49b1c332625fa0fbda40e56e859e19ea8411ea (diff) |
shell: add the shell_get_cmd_set and shell_vprintf functions
Diffstat (limited to 'src')
-rw-r--r-- | src/shell.c | 29 | ||||
-rw-r--r-- | src/shell.h | 9 |
2 files changed, 31 insertions, 7 deletions
diff --git a/src/shell.c b/src/shell.c index 16bca1c..81d3c88 100644 --- a/src/shell.c +++ b/src/shell.c @@ -316,7 +316,8 @@ shell_history_print(struct shell_history *history, struct shell *shell) /* Mind integer overflows */ for (size_t i = history->oldest; i != history->newest; i++) { line = shell_history_get(history, i); - shell_printf(shell, "%6lu %s\n", i - history->oldest, + shell_printf(shell, "%6lu %s\n", + (unsigned long)(i - history->oldest), shell_line_str(line)); } } @@ -469,13 +470,25 @@ shell_cmd_set_complete(struct shell_cmd_set *cmd_set, const char *str, return EAGAIN; } +struct shell_cmd_set * +shell_get_cmd_set(struct shell *shell) +{ + return shell->cmd_set; +} + +static struct shell_history * +shell_get_history(struct shell *shell) +{ + return &shell->history; +} + static void shell_cb_help(struct shell *shell, int argc, char *argv[]) { struct shell_cmd_set *cmd_set; const struct shell_cmd *cmd; - cmd_set = shell->cmd_set; + cmd_set = shell_get_cmd_set(shell); if (argc > 2) { argc = 2; @@ -512,12 +525,10 @@ shell_cb_help(struct shell *shell, int argc, char *argv[]) static void shell_cb_history(struct shell *shell, int argc, char *argv[]) { - unsigned long i; - (void)argc; (void)argv; - shell_history_print(&shell->history, shell); + shell_history_print(shell_get_history(shell), shell); } static struct shell_cmd shell_default_cmds[] = { @@ -1163,6 +1174,12 @@ shell_printf(struct shell *shell, const char *format, ...) va_list ap; va_start(ap, format); - shell->vfprintf_fn(shell->io_object, format, ap); + shell_vprintf(shell, format, ap); va_end(ap); } + +void +shell_vprintf(struct shell *shell, const char *format, va_list ap) +{ + shell->vfprintf_fn(shell->io_object, format, ap); +} diff --git a/src/shell.h b/src/shell.h index ddf7396..caf8d4e 100644 --- a/src/shell.h +++ b/src/shell.h @@ -132,9 +132,16 @@ void shell_init(struct shell *shell, struct shell_cmd_set *cmd_set, void shell_run(struct shell *shell); /* - * Printf-like function specific to the given shell instance. + * Obtain the command set associated with a shell. + */ +struct shell_cmd_set * shell_get_cmd_set(struct shell *shell); + +/* + * Printf-like functions specific to the given shell instance. */ void shell_printf(struct shell *shell, const char *format, ...) __attribute__((format(printf, 2, 3))); +void shell_vprintf(struct shell *shell, const char *format, va_list ap) + __attribute__((format(printf, 2, 0))); #endif /* SHELL_H */ |