shell: Support output using a va_list

At present it is not possible to write a printf()-like function in
board code which outputs to the shell. Add shell_vfprintf() to permit
this.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass 2020-04-30 15:25:04 -06:00 committed by Ioannis Glaropoulos
commit fc0e10d064
3 changed files with 59 additions and 9 deletions

View file

@ -1304,8 +1304,8 @@ void shell_process(const struct shell *shell)
/* This function mustn't be used from shell context to avoid deadlock.
* However it can be used in shell command handlers.
*/
void shell_fprintf(const struct shell *shell, enum shell_vt100_color color,
const char *fmt, ...)
void shell_vfprintf(const struct shell *shell, enum shell_vt100_color color,
const char *fmt, va_list args)
{
__ASSERT_NO_MSG(shell);
__ASSERT(!k_is_in_isr(), "Thread context required.");
@ -1315,17 +1315,11 @@ void shell_fprintf(const struct shell *shell, enum shell_vt100_color color,
__ASSERT_NO_MSG(shell->fprintf_ctx);
__ASSERT_NO_MSG(fmt);
va_list args;
k_mutex_lock(&shell->ctx->wr_mtx, K_FOREVER);
if (!flag_cmd_ctx_get(shell)) {
shell_cmd_line_erase(shell);
}
va_start(args, fmt);
shell_internal_vfprintf(shell, color, fmt, args);
va_end(args);
if (!flag_cmd_ctx_get(shell)) {
shell_print_prompt_and_cmd(shell);
}
@ -1333,6 +1327,19 @@ void shell_fprintf(const struct shell *shell, enum shell_vt100_color color,
k_mutex_unlock(&shell->ctx->wr_mtx);
}
/* This function mustn't be used from shell context to avoid deadlock.
* However it can be used in shell command handlers.
*/
void shell_fprintf(const struct shell *shell, enum shell_vt100_color color,
const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
shell_vfprintf(shell, color, fmt, args);
va_end(args);
}
static void shell_hexdump_line(const struct shell *shell, unsigned int offset,
const u8_t *data, size_t len)
{