From 889e37b8d9918f28287a2b0dda2529910dd0c068 Mon Sep 17 00:00:00 2001 From: Jakub Rzeszutko Date: Mon, 7 Dec 2020 16:10:11 +0100 Subject: [PATCH] shell: shell_utils internal api update Add prefix z_ to internal functions provided by the shell_utils module. Signed-off-by: Jakub Rzeszutko --- subsys/shell/shell.c | 69 ++++++++++++++++---------------- subsys/shell/shell_cmds.c | 8 ++-- subsys/shell/shell_help.c | 14 +++---- subsys/shell/shell_log_backend.c | 6 +-- subsys/shell/shell_ops.c | 33 +++++++-------- subsys/shell/shell_utils.c | 53 ++++++++++++------------ subsys/shell/shell_utils.h | 40 +++++++++--------- subsys/shell/shell_wildcard.c | 16 ++++---- 8 files changed, 121 insertions(+), 118 deletions(-) diff --git a/subsys/shell/shell.c b/subsys/shell/shell.c index 0fc69b25209..2bf5e136ae7 100644 --- a/subsys/shell/shell.c +++ b/subsys/shell/shell.c @@ -125,11 +125,11 @@ static void tab_item_print(const struct shell *shell, const char *option, return; } - longest_option += shell_strlen(tab); + longest_option += z_shell_strlen(tab); columns = (shell->ctx->vt100_ctx.cons.terminal_wid - - shell_strlen(tab)) / longest_option; - diff = longest_option - shell_strlen(option); + - z_shell_strlen(tab)) / longest_option; + diff = longest_option - z_shell_strlen(option); if (shell->ctx->vt100_ctx.printed_cmd++ % columns == 0U) { z_shell_fprintf(shell, SHELL_OPTION, "\n%s%s", tab, option); @@ -196,7 +196,7 @@ static void history_handle(const struct shell *shell, bool up) /* Backup command if history is entered */ if (!z_shell_history_active(shell->history)) { if (up) { - uint16_t cmd_len = shell_strlen(shell->ctx->cmd_buff); + uint16_t cmd_len = z_shell_strlen(shell->ctx->cmd_buff); if (cmd_len) { strcpy(shell->ctx->temp_buff, @@ -217,7 +217,7 @@ static void history_handle(const struct shell *shell, bool up) /* On exiting history mode print backed up command. */ if (!history_mode) { strcpy(shell->ctx->cmd_buff, shell->ctx->temp_buff); - len = shell_strlen(shell->ctx->cmd_buff); + len = z_shell_strlen(shell->ctx->cmd_buff); } z_shell_op_cursor_home_move(shell); @@ -255,8 +255,8 @@ static bool tab_prepare(const struct shell *shell, shell->ctx->temp_buff[shell->ctx->cmd_buff_pos] = '\0'; /* Create argument list. */ - (void)shell_make_argv(argc, *argv, shell->ctx->temp_buff, - CONFIG_SHELL_ARGC_MAX); + (void)z_shell_make_argv(argc, *argv, shell->ctx->temp_buff, + CONFIG_SHELL_ARGC_MAX); if (*argc > CONFIG_SHELL_ARGC_MAX) { return false; @@ -267,7 +267,7 @@ static bool tab_prepare(const struct shell *shell, if (IS_ENABLED(CONFIG_SHELL_CMDS_SELECT) && (*argc > 0) && (strcmp("select", (*argv)[0]) == 0) && - !shell_in_select_mode(shell)) { + !z_shell_in_select_mode(shell)) { *argv = *argv + 1; *argc = *argc - 1; } @@ -287,8 +287,9 @@ static bool tab_prepare(const struct shell *shell, search_argc = space ? *argc : *argc - 1; - *cmd = shell_get_last_command(selected_cmd_get(shell), search_argc, - *argv, complete_arg_idx, d_entry, false); + *cmd = z_shell_get_last_command(selected_cmd_get(shell), search_argc, + *argv, complete_arg_idx, d_entry, + false); /* if search_argc == 0 (empty command line) shell_get_last_command will * return NULL tab is allowed, otherwise not. @@ -317,11 +318,11 @@ static void find_completion_candidates(const struct shell *shell, size_t incompl_cmd_len; size_t idx = 0; - incompl_cmd_len = shell_strlen(incompl_cmd); + incompl_cmd_len = z_shell_strlen(incompl_cmd); *longest = 0U; *cnt = 0; - while ((candidate = shell_cmd_get(cmd, idx, &dloc)) != NULL) { + while ((candidate = z_shell_cmd_get(cmd, idx, &dloc)) != NULL) { bool is_candidate; is_candidate = is_completion_candidate(candidate->syntax, incompl_cmd, incompl_cmd_len); @@ -344,14 +345,14 @@ static void autocomplete(const struct shell *shell, { const struct shell_static_entry *match; uint16_t cmd_len; - uint16_t arg_len = shell_strlen(arg); + uint16_t arg_len = z_shell_strlen(arg); /* shell->ctx->active_cmd can be safely used outside of command context * to save stack */ - match = shell_cmd_get(cmd, subcmd_idx, &shell->ctx->active_cmd); + match = z_shell_cmd_get(cmd, subcmd_idx, &shell->ctx->active_cmd); __ASSERT_NO_MSG(match != NULL); - cmd_len = shell_strlen(match->syntax); + cmd_len = z_shell_strlen(match->syntax); if (!IS_ENABLED(CONFIG_SHELL_TAB_AUTOCOMPLETION)) { /* Add a space if the Tab button is pressed when command is @@ -412,7 +413,7 @@ static void tab_options_print(const struct shell *shell, uint16_t longest) { const struct shell_static_entry *match; - size_t str_len = shell_strlen(str); + size_t str_len = z_shell_strlen(str); size_t idx = first; /* Printing all matching commands (options). */ @@ -422,7 +423,7 @@ static void tab_options_print(const struct shell *shell, /* shell->ctx->active_cmd can be safely used outside of command * context to save stack */ - match = shell_cmd_get(cmd, idx, &shell->ctx->active_cmd); + match = z_shell_cmd_get(cmd, idx, &shell->ctx->active_cmd); __ASSERT_NO_MSG(match != NULL); idx++; if (str && match->syntax && @@ -450,7 +451,7 @@ static uint16_t common_beginning_find(const struct shell *shell, __ASSERT_NO_MSG(cnt > 1); - match = shell_cmd_get(cmd, first, &dynamic_entry); + match = z_shell_cmd_get(cmd, first, &dynamic_entry); __ASSERT_NO_MSG(match); strncpy(shell->ctx->temp_buff, match->syntax, sizeof(shell->ctx->temp_buff) - 1); @@ -462,7 +463,7 @@ static uint16_t common_beginning_find(const struct shell *shell, const struct shell_static_entry *match2; int curr_common; - match2 = shell_cmd_get(cmd, idx++, &dynamic_entry2); + match2 = z_shell_cmd_get(cmd, idx++, &dynamic_entry2); if (match2 == NULL) { break; } @@ -484,7 +485,7 @@ static void partial_autocomplete(const struct shell *shell, size_t first, size_t cnt) { const char *completion; - uint16_t arg_len = shell_strlen(arg); + uint16_t arg_len = z_shell_strlen(arg); uint16_t common = common_beginning_find(shell, cmd, &completion, first, cnt, arg_len); @@ -624,7 +625,7 @@ static int execute(const struct shell *shell) memset(&shell->ctx->active_cmd, 0, sizeof(shell->ctx->active_cmd)); if (IS_ENABLED(CONFIG_SHELL_HISTORY)) { - shell_cmd_trim(shell); + z_shell_cmd_trim(shell); history_put(shell, shell->ctx->cmd_buff, shell->ctx->cmd_buff_len); } @@ -649,7 +650,7 @@ static int execute(const struct shell *shell) /* Below loop is analyzing subcommands of found root command. */ while ((argc != 1) && (cmd_lvl < CONFIG_SHELL_ARGC_MAX) && args_left > 0) { - quote = shell_make_argv(&argc, argvp, cmd_buf, 2); + quote = z_shell_make_argv(&argc, argvp, cmd_buf, 2); cmd_buf = (char *)argvp[1]; if (argc == 0) { @@ -700,7 +701,7 @@ static int execute(const struct shell *shell) } if (has_last_handler == false) { - entry = shell_find_cmd(parent, argvp[0], &dloc); + entry = z_shell_find_cmd(parent, argvp[0], &dloc); } argvp++; @@ -717,7 +718,7 @@ static int execute(const struct shell *shell) parent = entry; } else { if (cmd_lvl == 0 && - (!shell_in_select_mode(shell) || + (!z_shell_in_select_mode(shell) || shell->ctx->selected_cmd->handler == NULL)) { z_shell_fprintf(shell, SHELL_ERROR, "%s%s\n", argv[0], @@ -752,10 +753,10 @@ static int execute(const struct shell *shell) * with all expanded commands. Hence shell_make_argv needs to * be called again. */ - (void)shell_make_argv(&cmd_lvl, - &argv[selected_cmd_get(shell) ? 1 : 0], - shell->ctx->cmd_buff, - CONFIG_SHELL_ARGC_MAX); + (void)z_shell_make_argv(&cmd_lvl, + &argv[selected_cmd_get(shell) ? 1 : 0], + shell->ctx->cmd_buff, + CONFIG_SHELL_ARGC_MAX); if (selected_cmd_get(shell)) { /* Apart from what is in the command buffer, there is @@ -1090,7 +1091,7 @@ static void state_collect(const struct shell *shell) } } - transport_buffer_flush(shell); + z_transport_buffer_flush(shell); } static void transport_evt_handler(enum shell_transport_evt evt_type, void *ctx) @@ -1168,7 +1169,7 @@ static int instance_init(const struct shell *shell, const void *p_config, CONFIG_SHELL_DEFAULT_TERMINAL_WIDTH; shell->ctx->vt100_ctx.cons.terminal_hei = CONFIG_SHELL_DEFAULT_TERMINAL_HEIGHT; - shell->ctx->vt100_ctx.cons.name_len = shell_strlen(shell->ctx->prompt); + shell->ctx->vt100_ctx.cons.name_len = z_shell_strlen(shell->ctx->prompt); z_flag_use_colors_set(shell, IS_ENABLED(CONFIG_SHELL_VT100_COLORS)); int ret = shell->iface->api->init(shell->iface, p_config, @@ -1427,7 +1428,7 @@ void shell_vfprintf(const struct shell *shell, enum shell_vt100_color color, if (!z_flag_cmd_ctx_get(shell)) { z_shell_print_prompt_and_cmd(shell); } - transport_buffer_flush(shell); + z_transport_buffer_flush(shell); k_mutex_unlock(&shell->ctx->wr_mtx); } @@ -1507,7 +1508,7 @@ int shell_prompt_change(const struct shell *shell, const char *prompt) return -EINVAL; } shell->ctx->prompt = prompt; - shell->ctx->vt100_ctx.cons.name_len = shell_strlen(prompt); + shell->ctx->vt100_ctx.cons.name_len = z_shell_strlen(prompt); return 0; } @@ -1521,7 +1522,7 @@ void shell_help(const struct shell *shell) int shell_execute_cmd(const struct shell *shell, const char *cmd) { - uint16_t cmd_len = shell_strlen(cmd); + uint16_t cmd_len = z_shell_strlen(cmd); int ret_val; if (cmd == NULL) { @@ -1594,7 +1595,7 @@ static int cmd_help(const struct shell *shell, size_t argc, char **argv) size_t idx = 0; shell_print(shell, "\nAvailable commands:"); - while ((entry = shell_cmd_get(NULL, idx++, NULL)) != NULL) { + while ((entry = z_shell_cmd_get(NULL, idx++, NULL)) != NULL) { shell_print(shell, " %s", entry->syntax); } } diff --git a/subsys/shell/shell_cmds.c b/subsys/shell/shell_cmds.c index 57a8c06ecbe..ba7c298727b 100644 --- a/subsys/shell/shell_cmds.c +++ b/subsys/shell/shell_cmds.c @@ -81,7 +81,7 @@ static int cursor_position_get(const struct shell *shell, uint16_t *x, uint16_t /* fprintf buffer needs to be flushed to start sending prepared * escape code to the terminal. */ - transport_buffer_flush(shell); + z_transport_buffer_flush(shell); /* timeout for terminal response = ~1s */ for (uint16_t i = 0; i < 1000; i++) { @@ -376,9 +376,9 @@ static int cmd_select(const struct shell *shell, size_t argc, char **argv) argc--; argv = argv + 1; - candidate = shell_get_last_command(shell->ctx->selected_cmd, - argc, (const char **)argv, - &matching_argc, &entry, true); + candidate = z_shell_get_last_command(shell->ctx->selected_cmd, + argc, (const char **)argv, + &matching_argc, &entry, true); if ((candidate != NULL) && !no_args(candidate) && (argc == matching_argc)) { diff --git a/subsys/shell/shell_help.c b/subsys/shell/shell_help.c index ba9125b78e1..640d56a29b0 100644 --- a/subsys/shell/shell_help.c +++ b/subsys/shell/shell_help.c @@ -39,13 +39,13 @@ static void formatted_text_print(const struct shell *shell, const char *str, while (true) { size_t idx = 0; - length = shell_strlen(str) - offset; + length = z_shell_strlen(str) - offset; if (length <= shell->ctx->vt100_ctx.cons.terminal_wid - terminal_offset) { for (idx = 0; idx < length; idx++) { if (*(str + offset + idx) == '\n') { - transport_buffer_flush(shell); + z_transport_buffer_flush(shell); z_shell_write(shell, str + offset, idx); offset += idx + 1; z_cursor_next_line_move(shell); @@ -88,7 +88,7 @@ static void formatted_text_print(const struct shell *shell, const char *str, /* Writing one line, fprintf IO buffer must be flushed * before calling shell_write. */ - transport_buffer_flush(shell); + z_transport_buffer_flush(shell); z_shell_write(shell, str + offset, length); offset += length; @@ -155,8 +155,8 @@ void z_shell_help_subcmd_print(const struct shell *shell, size_t idx = 0; /* Searching for the longest subcommand to print. */ - while ((entry = shell_cmd_get(parent, idx++, &dloc)) != NULL) { - longest = Z_MAX(longest, shell_strlen(entry->syntax)); + while ((entry = z_shell_cmd_get(parent, idx++, &dloc)) != NULL) { + longest = Z_MAX(longest, z_shell_strlen(entry->syntax)); }; /* No help to print */ @@ -171,7 +171,7 @@ void z_shell_help_subcmd_print(const struct shell *shell, /* Printing subcommands and help string (if exists). */ idx = 0; - while ((entry = shell_cmd_get(parent, idx++, &dloc)) != NULL) { + while ((entry = z_shell_cmd_get(parent, idx++, &dloc)) != NULL) { help_item_print(shell, entry->syntax, longest, entry->help); } } @@ -182,7 +182,7 @@ void z_shell_help_cmd_print(const struct shell *shell, static const char cmd_sep[] = " - "; /* commands separator */ uint16_t field_width; - field_width = shell_strlen(cmd->syntax) + shell_strlen(cmd_sep); + field_width = z_shell_strlen(cmd->syntax) + z_shell_strlen(cmd_sep); z_shell_fprintf(shell, SHELL_NORMAL, "%s%s", cmd->syntax, cmd_sep); diff --git a/subsys/shell/shell_log_backend.c b/subsys/shell/shell_log_backend.c index ae67a81cd2e..e88518ff879 100644 --- a/subsys/shell/shell_log_backend.c +++ b/subsys/shell/shell_log_backend.c @@ -274,9 +274,9 @@ static void panic(const struct log_backend *const backend) SHELL_LOG_BACKEND_PANIC; /* Move to the start of next line. */ - shell_multiline_data_calc(&shell->ctx->vt100_ctx.cons, - shell->ctx->cmd_buff_pos, - shell->ctx->cmd_buff_len); + z_shell_multiline_data_calc(&shell->ctx->vt100_ctx.cons, + shell->ctx->cmd_buff_pos, + shell->ctx->cmd_buff_len); z_shell_op_cursor_vert_move(shell, -1); z_shell_op_cursor_horiz_move(shell, -shell->ctx->vt100_ctx.cons.cur_x); diff --git a/subsys/shell/shell_ops.c b/subsys/shell/shell_ops.c index 5b75c9ee2d4..ec694f8334c 100644 --- a/subsys/shell/shell_ops.c +++ b/subsys/shell/shell_ops.c @@ -30,14 +30,14 @@ void z_shell_op_cursor_horiz_move(const struct shell *shell, int32_t delta) */ static inline bool full_line_cmd(const struct shell *shell) { - return ((shell->ctx->cmd_buff_len + shell_strlen(shell->ctx->prompt)) + return ((shell->ctx->cmd_buff_len + z_shell_strlen(shell->ctx->prompt)) % shell->ctx->vt100_ctx.cons.terminal_wid == 0U); } /* Function returns true if cursor is at beginning of an empty line. */ bool z_shell_cursor_in_empty_line(const struct shell *shell) { - return ((shell->ctx->cmd_buff_pos + shell_strlen(shell->ctx->prompt)) + return ((shell->ctx->cmd_buff_pos + z_shell_strlen(shell->ctx->prompt)) % shell->ctx->vt100_ctx.cons.terminal_wid == 0U); } @@ -53,8 +53,8 @@ void z_shell_op_cursor_position_synchronize(const struct shell *shell) struct shell_multiline_cons *cons = &shell->ctx->vt100_ctx.cons; bool last_line; - shell_multiline_data_calc(cons, shell->ctx->cmd_buff_pos, - shell->ctx->cmd_buff_len); + z_shell_multiline_data_calc(cons, shell->ctx->cmd_buff_pos, + shell->ctx->cmd_buff_len); last_line = (cons->cur_y == cons->cur_y_end); /* In case cursor reaches the bottom line of a terminal, it will @@ -81,17 +81,18 @@ void z_shell_op_cursor_move(const struct shell *shell, int16_t val) int32_t row_span; int32_t col_span; - shell_multiline_data_calc(cons, shell->ctx->cmd_buff_pos, - shell->ctx->cmd_buff_len); + z_shell_multiline_data_calc(cons, shell->ctx->cmd_buff_pos, + shell->ctx->cmd_buff_len); /* Calculate the new cursor. */ - row_span = row_span_with_buffer_offsets_get(&shell->ctx->vt100_ctx.cons, - shell->ctx->cmd_buff_pos, - new_pos); - col_span = column_span_with_buffer_offsets_get( - &shell->ctx->vt100_ctx.cons, - shell->ctx->cmd_buff_pos, - new_pos); + row_span = z_row_span_with_buffer_offsets_get( + &shell->ctx->vt100_ctx.cons, + shell->ctx->cmd_buff_pos, + new_pos); + col_span = z_column_span_with_buffer_offsets_get( + &shell->ctx->vt100_ctx.cons, + shell->ctx->cmd_buff_pos, + new_pos); z_shell_op_cursor_vert_move(shell, -row_span); z_shell_op_cursor_horiz_move(shell, col_span); @@ -323,9 +324,9 @@ void z_shell_op_completion_insert(const struct shell *shell, void z_shell_cmd_line_erase(const struct shell *shell) { - shell_multiline_data_calc(&shell->ctx->vt100_ctx.cons, - shell->ctx->cmd_buff_pos, - shell->ctx->cmd_buff_len); + z_shell_multiline_data_calc(&shell->ctx->vt100_ctx.cons, + shell->ctx->cmd_buff_pos, + shell->ctx->cmd_buff_len); z_shell_op_cursor_horiz_move(shell, -(shell->ctx->vt100_ctx.cons.cur_x - 1)); z_shell_op_cursor_vert_move(shell, shell->ctx->vt100_ctx.cons.cur_y - 1); diff --git a/subsys/shell/shell_utils.c b/subsys/shell/shell_utils.c index e28ae47b794..21acedd1c93 100644 --- a/subsys/shell/shell_utils.c +++ b/subsys/shell/shell_utils.c @@ -31,24 +31,24 @@ static uint32_t col_num_with_buffer_offset_get(struct shell_multiline_cons *cons return (1 + ((buffer_pos + cons->name_len) % cons->terminal_wid)); } -int32_t column_span_with_buffer_offsets_get(struct shell_multiline_cons *cons, - uint16_t offset1, - uint16_t offset2) +int32_t z_column_span_with_buffer_offsets_get(struct shell_multiline_cons *cons, + uint16_t offset1, + uint16_t offset2) { return col_num_with_buffer_offset_get(cons, offset2) - col_num_with_buffer_offset_get(cons, offset1); } -int32_t row_span_with_buffer_offsets_get(struct shell_multiline_cons *cons, - uint16_t offset1, - uint16_t offset2) +int32_t z_row_span_with_buffer_offsets_get(struct shell_multiline_cons *cons, + uint16_t offset1, + uint16_t offset2) { return line_num_with_buffer_offset_get(cons, offset2) - line_num_with_buffer_offset_get(cons, offset1); } -void shell_multiline_data_calc(struct shell_multiline_cons *cons, - uint16_t buff_pos, uint16_t buff_len) +void z_shell_multiline_data_calc(struct shell_multiline_cons *cons, + uint16_t buff_pos, uint16_t buff_len) { /* Current cursor position in command. * +1 -> because home position is (1, 1) @@ -77,14 +77,14 @@ static char make_argv(char **ppcmd, uint8_t c) switch (c) { case '\\': memmove(cmd, cmd + 1, - shell_strlen(cmd)); + z_shell_strlen(cmd)); cmd += 1; continue; case '\'': case '\"': memmove(cmd, cmd + 1, - shell_strlen(cmd)); + z_shell_strlen(cmd)); quote = c; continue; default: @@ -93,7 +93,7 @@ static char make_argv(char **ppcmd, uint8_t c) } if (quote == c) { - memmove(cmd, cmd + 1, shell_strlen(cmd)); + memmove(cmd, cmd + 1, z_shell_strlen(cmd)); quote = 0; continue; } @@ -103,7 +103,7 @@ static char make_argv(char **ppcmd, uint8_t c) if (t == quote) { memmove(cmd, cmd + 1, - shell_strlen(cmd)); + z_shell_strlen(cmd)); cmd += 1; continue; } @@ -124,7 +124,7 @@ static char make_argv(char **ppcmd, uint8_t c) if (i > 2) { memmove(cmd, cmd + (i - 1), - shell_strlen(cmd) - (i - 2)); + z_shell_strlen(cmd) - (i - 2)); *cmd++ = v; continue; } @@ -151,7 +151,7 @@ static char make_argv(char **ppcmd, uint8_t c) if (i > 2) { memmove(cmd, cmd + (i - 1), - shell_strlen(cmd) - (i - 2)); + z_shell_strlen(cmd) - (i - 2)); *cmd++ = v; continue; } @@ -170,7 +170,8 @@ static char make_argv(char **ppcmd, uint8_t c) } -char shell_make_argv(size_t *argc, const char **argv, char *cmd, uint8_t max_argc) +char z_shell_make_argv(size_t *argc, const char **argv, char *cmd, + uint8_t max_argc) { char quote = 0; char c; @@ -197,11 +198,11 @@ char shell_make_argv(size_t *argc, const char **argv, char *cmd, uint8_t max_arg return quote; } -void shell_pattern_remove(char *buff, uint16_t *buff_len, const char *pattern) +void z_shell_pattern_remove(char *buff, uint16_t *buff_len, const char *pattern) { char *pattern_addr = strstr(buff, pattern); uint16_t shift; - uint16_t pattern_len = shell_strlen(pattern); + uint16_t pattern_len = z_shell_strlen(pattern); if (!pattern_addr) { return; @@ -214,7 +215,7 @@ void shell_pattern_remove(char *buff, uint16_t *buff_len, const char *pattern) } } - shift = shell_strlen(pattern_addr) - pattern_len + 1; /* +1 for EOS */ + shift = z_shell_strlen(pattern_addr) - pattern_len + 1; /* +1 for EOS */ *buff_len -= pattern_len; memmove(pattern_addr, pattern_addr + pattern_len, shift); @@ -243,7 +244,7 @@ static const struct shell_static_entry *root_cmd_find(const char *syntax) return NULL; } -const struct shell_static_entry *shell_cmd_get( +const struct shell_static_entry *z_shell_cmd_get( const struct shell_static_entry *parent, size_t idx, struct shell_static_entry *dloc) @@ -283,7 +284,7 @@ const struct shell_static_entry *shell_cmd_get( * * @return Pointer to found command. */ -const struct shell_static_entry *shell_find_cmd( +const struct shell_static_entry *z_shell_find_cmd( const struct shell_static_entry *parent, const char *cmd_str, struct shell_static_entry *dloc) @@ -291,7 +292,7 @@ const struct shell_static_entry *shell_find_cmd( const struct shell_static_entry *entry; size_t idx = 0; - while ((entry = shell_cmd_get(parent, idx++, dloc)) != NULL) { + while ((entry = z_shell_cmd_get(parent, idx++, dloc)) != NULL) { if (strcmp(cmd_str, entry->syntax) == 0) { return entry; } @@ -300,7 +301,7 @@ const struct shell_static_entry *shell_find_cmd( return NULL; } -const struct shell_static_entry *shell_get_last_command( +const struct shell_static_entry *z_shell_get_last_command( const struct shell_static_entry *entry, size_t argc, const char *argv[], @@ -323,7 +324,7 @@ const struct shell_static_entry *shell_get_last_command( } prev_entry = entry; - entry = shell_find_cmd(entry, argv[*match_arg], dloc); + entry = z_shell_find_cmd(entry, argv[*match_arg], dloc); if (entry) { (*match_arg)++; } else { @@ -360,9 +361,9 @@ int shell_set_root_cmd(const char *cmd) -void shell_spaces_trim(char *str) +void z_shell_spaces_trim(char *str) { - uint16_t len = shell_strlen(str); + uint16_t len = z_shell_strlen(str); uint16_t shift = 0U; if (!str) { @@ -427,7 +428,7 @@ static void buffer_trim(char *buff, uint16_t *buff_len) } } -void shell_cmd_trim(const struct shell *shell) +void z_shell_cmd_trim(const struct shell *shell) { buffer_trim(shell->ctx->cmd_buff, &shell->ctx->cmd_buff_len); shell->ctx->cmd_buff_pos = shell->ctx->cmd_buff_len; diff --git a/subsys/shell/shell_utils.h b/subsys/shell/shell_utils.h index ad5709c67ac..b64e6cd6bb4 100644 --- a/subsys/shell/shell_utils.h +++ b/subsys/shell/shell_utils.h @@ -15,29 +15,30 @@ extern "C" { #define SHELL_MSG_SPECIFY_SUBCOMMAND "Please specify a subcommand.\n" -int32_t row_span_with_buffer_offsets_get(struct shell_multiline_cons *cons, - uint16_t offset1, - uint16_t offset2); +int32_t z_row_span_with_buffer_offsets_get(struct shell_multiline_cons *cons, + uint16_t offset1, + uint16_t offset2); -int32_t column_span_with_buffer_offsets_get(struct shell_multiline_cons *cons, - uint16_t offset1, - uint16_t offset2); +int32_t z_column_span_with_buffer_offsets_get(struct shell_multiline_cons *cons, + uint16_t offset1, + uint16_t offset2); -void shell_multiline_data_calc(struct shell_multiline_cons *cons, - uint16_t buff_pos, uint16_t buff_len); +void z_shell_multiline_data_calc(struct shell_multiline_cons *cons, + uint16_t buff_pos, uint16_t buff_len); -static inline uint16_t shell_strlen(const char *str) +static inline uint16_t z_shell_strlen(const char *str) { return str == NULL ? 0U : (uint16_t)strlen(str); } -char shell_make_argv(size_t *argc, const char **argv, - char *cmd, uint8_t max_argc); +char z_shell_make_argv(size_t *argc, const char **argv, + char *cmd, uint8_t max_argc); /** @brief Removes pattern and following space * */ -void shell_pattern_remove(char *buff, uint16_t *buff_len, const char *pattern); +void z_shell_pattern_remove(char *buff, uint16_t *buff_len, + const char *pattern); /** @brief Get subcommand with given index from the root. * @@ -47,12 +48,12 @@ void shell_pattern_remove(char *buff, uint16_t *buff_len, const char *pattern); * * @return Fetched command or null if command with that index does not exist. */ -const struct shell_static_entry *shell_cmd_get( +const struct shell_static_entry *z_shell_cmd_get( const struct shell_static_entry *parent, size_t idx, struct shell_static_entry *dloc); -const struct shell_static_entry *shell_find_cmd( +const struct shell_static_entry *z_shell_find_cmd( const struct shell_static_entry *parent, const char *cmd_str, struct shell_static_entry *dloc); @@ -69,7 +70,7 @@ const struct shell_static_entry *shell_find_cmd( * * @return Pointer to found command. */ -const struct shell_static_entry *shell_get_last_command( +const struct shell_static_entry *z_shell_get_last_command( const struct shell_static_entry *entry, size_t argc, const char *argv[], @@ -77,16 +78,15 @@ const struct shell_static_entry *shell_get_last_command( struct shell_static_entry *dloc, bool only_static); -void shell_spaces_trim(char *str); +void z_shell_spaces_trim(char *str); +void z_shell_cmd_trim(const struct shell *shell); -static inline void transport_buffer_flush(const struct shell *shell) +static inline void z_transport_buffer_flush(const struct shell *shell) { z_shell_fprintf_buffer_flush(shell->fprintf_ctx); } -void shell_cmd_trim(const struct shell *shell); - -static inline bool shell_in_select_mode(const struct shell *shell) +static inline bool z_shell_in_select_mode(const struct shell *shell) { return shell->ctx->selected_cmd == NULL ? false : true; } diff --git a/subsys/shell/shell_wildcard.c b/subsys/shell/shell_wildcard.c index 8a63b084c62..47f422b15c6 100644 --- a/subsys/shell/shell_wildcard.c +++ b/subsys/shell/shell_wildcard.c @@ -14,7 +14,7 @@ static enum shell_wildcard_status command_add(char *buff, uint16_t *buff_len, char const *cmd, char const *pattern) { - uint16_t cmd_len = shell_strlen(cmd); + uint16_t cmd_len = z_shell_strlen(cmd); char *completion_addr; uint16_t shift; @@ -29,7 +29,7 @@ static enum shell_wildcard_status command_add(char *buff, uint16_t *buff_len, return SHELL_WILDCARD_CMD_NO_MATCH_FOUND; } - shift = shell_strlen(completion_addr); + shift = z_shell_strlen(completion_addr); /* make place for new command: + 1 for space + 1 for EOS */ memmove(completion_addr + cmd_len + 1, completion_addr, shift + 1); @@ -76,7 +76,7 @@ static enum shell_wildcard_status commands_expand(const struct shell *shell, size_t cmd_idx = 0; size_t cnt = 0; - while ((entry = shell_cmd_get(cmd, cmd_idx++, &dloc)) != NULL) { + while ((entry = z_shell_cmd_get(cmd, cmd_idx++, &dloc)) != NULL) { if (fnmatch(pattern, entry->syntax, 0) == 0) { ret_val = command_add(shell->ctx->temp_buff, @@ -96,8 +96,8 @@ static enum shell_wildcard_status commands_expand(const struct shell *shell, }; if (cnt > 0) { - shell_pattern_remove(shell->ctx->temp_buff, - &shell->ctx->cmd_tmp_buff_len, pattern); + z_shell_pattern_remove(shell->ctx->temp_buff, + &shell->ctx->cmd_tmp_buff_len, pattern); } return ret_val; @@ -105,7 +105,7 @@ static enum shell_wildcard_status commands_expand(const struct shell *shell, bool z_shell_has_wildcard(const char *str) { - uint16_t str_len = shell_strlen(str); + uint16_t str_len = z_shell_strlen(str); for (size_t i = 0; i < str_len; i++) { if ((str[i] == '?') || (str[i] == '*')) { @@ -149,10 +149,10 @@ void z_shell_wildcard_prepare(const struct shell *shell) * At this point it is important to keep temp_buff as one string. * It will allow to find wildcard commands easily with strstr function. */ - shell_spaces_trim(shell->ctx->temp_buff); + z_shell_spaces_trim(shell->ctx->temp_buff); /* +1 for EOS*/ - shell->ctx->cmd_tmp_buff_len = shell_strlen(shell->ctx->temp_buff) + 1; + shell->ctx->cmd_tmp_buff_len = z_shell_strlen(shell->ctx->temp_buff) + 1; }