shell: shell_utils internal api update

Add prefix z_ to internal functions provided by the shell_utils
module.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
This commit is contained in:
Jakub Rzeszutko 2020-12-07 16:10:11 +01:00 committed by Carles Cufí
commit 889e37b8d9
8 changed files with 121 additions and 118 deletions

View file

@ -125,11 +125,11 @@ static void tab_item_print(const struct shell *shell, const char *option,
return; return;
} }
longest_option += shell_strlen(tab); longest_option += z_shell_strlen(tab);
columns = (shell->ctx->vt100_ctx.cons.terminal_wid columns = (shell->ctx->vt100_ctx.cons.terminal_wid
- shell_strlen(tab)) / longest_option; - z_shell_strlen(tab)) / longest_option;
diff = longest_option - shell_strlen(option); diff = longest_option - z_shell_strlen(option);
if (shell->ctx->vt100_ctx.printed_cmd++ % columns == 0U) { if (shell->ctx->vt100_ctx.printed_cmd++ % columns == 0U) {
z_shell_fprintf(shell, SHELL_OPTION, "\n%s%s", tab, option); 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 */ /* Backup command if history is entered */
if (!z_shell_history_active(shell->history)) { if (!z_shell_history_active(shell->history)) {
if (up) { 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) { if (cmd_len) {
strcpy(shell->ctx->temp_buff, 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. */ /* On exiting history mode print backed up command. */
if (!history_mode) { if (!history_mode) {
strcpy(shell->ctx->cmd_buff, shell->ctx->temp_buff); 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); 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'; shell->ctx->temp_buff[shell->ctx->cmd_buff_pos] = '\0';
/* Create argument list. */ /* Create argument list. */
(void)shell_make_argv(argc, *argv, shell->ctx->temp_buff, (void)z_shell_make_argv(argc, *argv, shell->ctx->temp_buff,
CONFIG_SHELL_ARGC_MAX); CONFIG_SHELL_ARGC_MAX);
if (*argc > CONFIG_SHELL_ARGC_MAX) { if (*argc > CONFIG_SHELL_ARGC_MAX) {
return false; return false;
@ -267,7 +267,7 @@ static bool tab_prepare(const struct shell *shell,
if (IS_ENABLED(CONFIG_SHELL_CMDS_SELECT) && (*argc > 0) && if (IS_ENABLED(CONFIG_SHELL_CMDS_SELECT) && (*argc > 0) &&
(strcmp("select", (*argv)[0]) == 0) && (strcmp("select", (*argv)[0]) == 0) &&
!shell_in_select_mode(shell)) { !z_shell_in_select_mode(shell)) {
*argv = *argv + 1; *argv = *argv + 1;
*argc = *argc - 1; *argc = *argc - 1;
} }
@ -287,8 +287,9 @@ static bool tab_prepare(const struct shell *shell,
search_argc = space ? *argc : *argc - 1; search_argc = space ? *argc : *argc - 1;
*cmd = shell_get_last_command(selected_cmd_get(shell), search_argc, *cmd = z_shell_get_last_command(selected_cmd_get(shell), search_argc,
*argv, complete_arg_idx, d_entry, false); *argv, complete_arg_idx, d_entry,
false);
/* if search_argc == 0 (empty command line) shell_get_last_command will /* if search_argc == 0 (empty command line) shell_get_last_command will
* return NULL tab is allowed, otherwise not. * 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 incompl_cmd_len;
size_t idx = 0; size_t idx = 0;
incompl_cmd_len = shell_strlen(incompl_cmd); incompl_cmd_len = z_shell_strlen(incompl_cmd);
*longest = 0U; *longest = 0U;
*cnt = 0; *cnt = 0;
while ((candidate = shell_cmd_get(cmd, idx, &dloc)) != NULL) { while ((candidate = z_shell_cmd_get(cmd, idx, &dloc)) != NULL) {
bool is_candidate; bool is_candidate;
is_candidate = is_completion_candidate(candidate->syntax, is_candidate = is_completion_candidate(candidate->syntax,
incompl_cmd, incompl_cmd_len); incompl_cmd, incompl_cmd_len);
@ -344,14 +345,14 @@ static void autocomplete(const struct shell *shell,
{ {
const struct shell_static_entry *match; const struct shell_static_entry *match;
uint16_t cmd_len; 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 /* shell->ctx->active_cmd can be safely used outside of command context
* to save stack * 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); __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)) { if (!IS_ENABLED(CONFIG_SHELL_TAB_AUTOCOMPLETION)) {
/* Add a space if the Tab button is pressed when command is /* 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) uint16_t longest)
{ {
const struct shell_static_entry *match; 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; size_t idx = first;
/* Printing all matching commands (options). */ /* 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 /* shell->ctx->active_cmd can be safely used outside of command
* context to save stack * 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); __ASSERT_NO_MSG(match != NULL);
idx++; idx++;
if (str && match->syntax && if (str && match->syntax &&
@ -450,7 +451,7 @@ static uint16_t common_beginning_find(const struct shell *shell,
__ASSERT_NO_MSG(cnt > 1); __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); __ASSERT_NO_MSG(match);
strncpy(shell->ctx->temp_buff, match->syntax, strncpy(shell->ctx->temp_buff, match->syntax,
sizeof(shell->ctx->temp_buff) - 1); 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; const struct shell_static_entry *match2;
int curr_common; int curr_common;
match2 = shell_cmd_get(cmd, idx++, &dynamic_entry2); match2 = z_shell_cmd_get(cmd, idx++, &dynamic_entry2);
if (match2 == NULL) { if (match2 == NULL) {
break; break;
} }
@ -484,7 +485,7 @@ static void partial_autocomplete(const struct shell *shell,
size_t first, size_t cnt) size_t first, size_t cnt)
{ {
const char *completion; 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, uint16_t common = common_beginning_find(shell, cmd, &completion, first,
cnt, arg_len); 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)); memset(&shell->ctx->active_cmd, 0, sizeof(shell->ctx->active_cmd));
if (IS_ENABLED(CONFIG_SHELL_HISTORY)) { if (IS_ENABLED(CONFIG_SHELL_HISTORY)) {
shell_cmd_trim(shell); z_shell_cmd_trim(shell);
history_put(shell, shell->ctx->cmd_buff, history_put(shell, shell->ctx->cmd_buff,
shell->ctx->cmd_buff_len); 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. */ /* Below loop is analyzing subcommands of found root command. */
while ((argc != 1) && (cmd_lvl < CONFIG_SHELL_ARGC_MAX) while ((argc != 1) && (cmd_lvl < CONFIG_SHELL_ARGC_MAX)
&& args_left > 0) { && 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]; cmd_buf = (char *)argvp[1];
if (argc == 0) { if (argc == 0) {
@ -700,7 +701,7 @@ static int execute(const struct shell *shell)
} }
if (has_last_handler == false) { if (has_last_handler == false) {
entry = shell_find_cmd(parent, argvp[0], &dloc); entry = z_shell_find_cmd(parent, argvp[0], &dloc);
} }
argvp++; argvp++;
@ -717,7 +718,7 @@ static int execute(const struct shell *shell)
parent = entry; parent = entry;
} else { } else {
if (cmd_lvl == 0 && if (cmd_lvl == 0 &&
(!shell_in_select_mode(shell) || (!z_shell_in_select_mode(shell) ||
shell->ctx->selected_cmd->handler == NULL)) { shell->ctx->selected_cmd->handler == NULL)) {
z_shell_fprintf(shell, SHELL_ERROR, z_shell_fprintf(shell, SHELL_ERROR,
"%s%s\n", argv[0], "%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 * with all expanded commands. Hence shell_make_argv needs to
* be called again. * be called again.
*/ */
(void)shell_make_argv(&cmd_lvl, (void)z_shell_make_argv(&cmd_lvl,
&argv[selected_cmd_get(shell) ? 1 : 0], &argv[selected_cmd_get(shell) ? 1 : 0],
shell->ctx->cmd_buff, shell->ctx->cmd_buff,
CONFIG_SHELL_ARGC_MAX); CONFIG_SHELL_ARGC_MAX);
if (selected_cmd_get(shell)) { if (selected_cmd_get(shell)) {
/* Apart from what is in the command buffer, there is /* 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) 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; CONFIG_SHELL_DEFAULT_TERMINAL_WIDTH;
shell->ctx->vt100_ctx.cons.terminal_hei = shell->ctx->vt100_ctx.cons.terminal_hei =
CONFIG_SHELL_DEFAULT_TERMINAL_HEIGHT; 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)); z_flag_use_colors_set(shell, IS_ENABLED(CONFIG_SHELL_VT100_COLORS));
int ret = shell->iface->api->init(shell->iface, p_config, 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)) { if (!z_flag_cmd_ctx_get(shell)) {
z_shell_print_prompt_and_cmd(shell); z_shell_print_prompt_and_cmd(shell);
} }
transport_buffer_flush(shell); z_transport_buffer_flush(shell);
k_mutex_unlock(&shell->ctx->wr_mtx); k_mutex_unlock(&shell->ctx->wr_mtx);
} }
@ -1507,7 +1508,7 @@ int shell_prompt_change(const struct shell *shell, const char *prompt)
return -EINVAL; return -EINVAL;
} }
shell->ctx->prompt = prompt; 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; return 0;
} }
@ -1521,7 +1522,7 @@ void shell_help(const struct shell *shell)
int shell_execute_cmd(const struct shell *shell, const char *cmd) 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; int ret_val;
if (cmd == NULL) { if (cmd == NULL) {
@ -1594,7 +1595,7 @@ static int cmd_help(const struct shell *shell, size_t argc, char **argv)
size_t idx = 0; size_t idx = 0;
shell_print(shell, "\nAvailable commands:"); 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); shell_print(shell, " %s", entry->syntax);
} }
} }

View file

@ -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 /* fprintf buffer needs to be flushed to start sending prepared
* escape code to the terminal. * escape code to the terminal.
*/ */
transport_buffer_flush(shell); z_transport_buffer_flush(shell);
/* timeout for terminal response = ~1s */ /* timeout for terminal response = ~1s */
for (uint16_t i = 0; i < 1000; i++) { 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--; argc--;
argv = argv + 1; argv = argv + 1;
candidate = shell_get_last_command(shell->ctx->selected_cmd, candidate = z_shell_get_last_command(shell->ctx->selected_cmd,
argc, (const char **)argv, argc, (const char **)argv,
&matching_argc, &entry, true); &matching_argc, &entry, true);
if ((candidate != NULL) && !no_args(candidate) if ((candidate != NULL) && !no_args(candidate)
&& (argc == matching_argc)) { && (argc == matching_argc)) {

View file

@ -39,13 +39,13 @@ static void formatted_text_print(const struct shell *shell, const char *str,
while (true) { while (true) {
size_t idx = 0; size_t idx = 0;
length = shell_strlen(str) - offset; length = z_shell_strlen(str) - offset;
if (length <= if (length <=
shell->ctx->vt100_ctx.cons.terminal_wid - terminal_offset) { shell->ctx->vt100_ctx.cons.terminal_wid - terminal_offset) {
for (idx = 0; idx < length; idx++) { for (idx = 0; idx < length; idx++) {
if (*(str + offset + idx) == '\n') { if (*(str + offset + idx) == '\n') {
transport_buffer_flush(shell); z_transport_buffer_flush(shell);
z_shell_write(shell, str + offset, idx); z_shell_write(shell, str + offset, idx);
offset += idx + 1; offset += idx + 1;
z_cursor_next_line_move(shell); 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 /* Writing one line, fprintf IO buffer must be flushed
* before calling shell_write. * before calling shell_write.
*/ */
transport_buffer_flush(shell); z_transport_buffer_flush(shell);
z_shell_write(shell, str + offset, length); z_shell_write(shell, str + offset, length);
offset += length; offset += length;
@ -155,8 +155,8 @@ void z_shell_help_subcmd_print(const struct shell *shell,
size_t idx = 0; size_t idx = 0;
/* Searching for the longest subcommand to print. */ /* Searching for the longest subcommand to print. */
while ((entry = shell_cmd_get(parent, idx++, &dloc)) != NULL) { while ((entry = z_shell_cmd_get(parent, idx++, &dloc)) != NULL) {
longest = Z_MAX(longest, shell_strlen(entry->syntax)); longest = Z_MAX(longest, z_shell_strlen(entry->syntax));
}; };
/* No help to print */ /* 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). */ /* Printing subcommands and help string (if exists). */
idx = 0; 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); 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 */ static const char cmd_sep[] = " - "; /* commands separator */
uint16_t field_width; 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); z_shell_fprintf(shell, SHELL_NORMAL, "%s%s", cmd->syntax, cmd_sep);

View file

@ -274,9 +274,9 @@ static void panic(const struct log_backend *const backend)
SHELL_LOG_BACKEND_PANIC; SHELL_LOG_BACKEND_PANIC;
/* Move to the start of next line. */ /* Move to the start of next line. */
shell_multiline_data_calc(&shell->ctx->vt100_ctx.cons, z_shell_multiline_data_calc(&shell->ctx->vt100_ctx.cons,
shell->ctx->cmd_buff_pos, shell->ctx->cmd_buff_pos,
shell->ctx->cmd_buff_len); shell->ctx->cmd_buff_len);
z_shell_op_cursor_vert_move(shell, -1); z_shell_op_cursor_vert_move(shell, -1);
z_shell_op_cursor_horiz_move(shell, z_shell_op_cursor_horiz_move(shell,
-shell->ctx->vt100_ctx.cons.cur_x); -shell->ctx->vt100_ctx.cons.cur_x);

View file

@ -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) 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); % shell->ctx->vt100_ctx.cons.terminal_wid == 0U);
} }
/* Function returns true if cursor is at beginning of an empty line. */ /* Function returns true if cursor is at beginning of an empty line. */
bool z_shell_cursor_in_empty_line(const struct shell *shell) 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); % 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; struct shell_multiline_cons *cons = &shell->ctx->vt100_ctx.cons;
bool last_line; bool last_line;
shell_multiline_data_calc(cons, shell->ctx->cmd_buff_pos, z_shell_multiline_data_calc(cons, shell->ctx->cmd_buff_pos,
shell->ctx->cmd_buff_len); shell->ctx->cmd_buff_len);
last_line = (cons->cur_y == cons->cur_y_end); last_line = (cons->cur_y == cons->cur_y_end);
/* In case cursor reaches the bottom line of a terminal, it will /* 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 row_span;
int32_t col_span; int32_t col_span;
shell_multiline_data_calc(cons, shell->ctx->cmd_buff_pos, z_shell_multiline_data_calc(cons, shell->ctx->cmd_buff_pos,
shell->ctx->cmd_buff_len); shell->ctx->cmd_buff_len);
/* Calculate the new cursor. */ /* Calculate the new cursor. */
row_span = row_span_with_buffer_offsets_get(&shell->ctx->vt100_ctx.cons, row_span = z_row_span_with_buffer_offsets_get(
shell->ctx->cmd_buff_pos, &shell->ctx->vt100_ctx.cons,
new_pos); shell->ctx->cmd_buff_pos,
col_span = column_span_with_buffer_offsets_get( new_pos);
&shell->ctx->vt100_ctx.cons, col_span = z_column_span_with_buffer_offsets_get(
shell->ctx->cmd_buff_pos, &shell->ctx->vt100_ctx.cons,
new_pos); shell->ctx->cmd_buff_pos,
new_pos);
z_shell_op_cursor_vert_move(shell, -row_span); z_shell_op_cursor_vert_move(shell, -row_span);
z_shell_op_cursor_horiz_move(shell, col_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) void z_shell_cmd_line_erase(const struct shell *shell)
{ {
shell_multiline_data_calc(&shell->ctx->vt100_ctx.cons, z_shell_multiline_data_calc(&shell->ctx->vt100_ctx.cons,
shell->ctx->cmd_buff_pos, shell->ctx->cmd_buff_pos,
shell->ctx->cmd_buff_len); shell->ctx->cmd_buff_len);
z_shell_op_cursor_horiz_move(shell, z_shell_op_cursor_horiz_move(shell,
-(shell->ctx->vt100_ctx.cons.cur_x - 1)); -(shell->ctx->vt100_ctx.cons.cur_x - 1));
z_shell_op_cursor_vert_move(shell, shell->ctx->vt100_ctx.cons.cur_y - 1); z_shell_op_cursor_vert_move(shell, shell->ctx->vt100_ctx.cons.cur_y - 1);

View file

@ -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)); return (1 + ((buffer_pos + cons->name_len) % cons->terminal_wid));
} }
int32_t column_span_with_buffer_offsets_get(struct shell_multiline_cons *cons, int32_t z_column_span_with_buffer_offsets_get(struct shell_multiline_cons *cons,
uint16_t offset1, uint16_t offset1,
uint16_t offset2) uint16_t offset2)
{ {
return col_num_with_buffer_offset_get(cons, offset2) return col_num_with_buffer_offset_get(cons, offset2)
- col_num_with_buffer_offset_get(cons, offset1); - col_num_with_buffer_offset_get(cons, offset1);
} }
int32_t row_span_with_buffer_offsets_get(struct shell_multiline_cons *cons, int32_t z_row_span_with_buffer_offsets_get(struct shell_multiline_cons *cons,
uint16_t offset1, uint16_t offset1,
uint16_t offset2) uint16_t offset2)
{ {
return line_num_with_buffer_offset_get(cons, offset2) return line_num_with_buffer_offset_get(cons, offset2)
- line_num_with_buffer_offset_get(cons, offset1); - line_num_with_buffer_offset_get(cons, offset1);
} }
void shell_multiline_data_calc(struct shell_multiline_cons *cons, void z_shell_multiline_data_calc(struct shell_multiline_cons *cons,
uint16_t buff_pos, uint16_t buff_len) uint16_t buff_pos, uint16_t buff_len)
{ {
/* Current cursor position in command. /* Current cursor position in command.
* +1 -> because home position is (1, 1) * +1 -> because home position is (1, 1)
@ -77,14 +77,14 @@ static char make_argv(char **ppcmd, uint8_t c)
switch (c) { switch (c) {
case '\\': case '\\':
memmove(cmd, cmd + 1, memmove(cmd, cmd + 1,
shell_strlen(cmd)); z_shell_strlen(cmd));
cmd += 1; cmd += 1;
continue; continue;
case '\'': case '\'':
case '\"': case '\"':
memmove(cmd, cmd + 1, memmove(cmd, cmd + 1,
shell_strlen(cmd)); z_shell_strlen(cmd));
quote = c; quote = c;
continue; continue;
default: default:
@ -93,7 +93,7 @@ static char make_argv(char **ppcmd, uint8_t c)
} }
if (quote == c) { if (quote == c) {
memmove(cmd, cmd + 1, shell_strlen(cmd)); memmove(cmd, cmd + 1, z_shell_strlen(cmd));
quote = 0; quote = 0;
continue; continue;
} }
@ -103,7 +103,7 @@ static char make_argv(char **ppcmd, uint8_t c)
if (t == quote) { if (t == quote) {
memmove(cmd, cmd + 1, memmove(cmd, cmd + 1,
shell_strlen(cmd)); z_shell_strlen(cmd));
cmd += 1; cmd += 1;
continue; continue;
} }
@ -124,7 +124,7 @@ static char make_argv(char **ppcmd, uint8_t c)
if (i > 2) { if (i > 2) {
memmove(cmd, cmd + (i - 1), memmove(cmd, cmd + (i - 1),
shell_strlen(cmd) - (i - 2)); z_shell_strlen(cmd) - (i - 2));
*cmd++ = v; *cmd++ = v;
continue; continue;
} }
@ -151,7 +151,7 @@ static char make_argv(char **ppcmd, uint8_t c)
if (i > 2) { if (i > 2) {
memmove(cmd, cmd + (i - 1), memmove(cmd, cmd + (i - 1),
shell_strlen(cmd) - (i - 2)); z_shell_strlen(cmd) - (i - 2));
*cmd++ = v; *cmd++ = v;
continue; 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 quote = 0;
char c; char c;
@ -197,11 +198,11 @@ char shell_make_argv(size_t *argc, const char **argv, char *cmd, uint8_t max_arg
return quote; 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); char *pattern_addr = strstr(buff, pattern);
uint16_t shift; uint16_t shift;
uint16_t pattern_len = shell_strlen(pattern); uint16_t pattern_len = z_shell_strlen(pattern);
if (!pattern_addr) { if (!pattern_addr) {
return; 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; *buff_len -= pattern_len;
memmove(pattern_addr, pattern_addr + pattern_len, shift); 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; 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, const struct shell_static_entry *parent,
size_t idx, size_t idx,
struct shell_static_entry *dloc) struct shell_static_entry *dloc)
@ -283,7 +284,7 @@ const struct shell_static_entry *shell_cmd_get(
* *
* @return Pointer to found command. * @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 struct shell_static_entry *parent,
const char *cmd_str, const char *cmd_str,
struct shell_static_entry *dloc) struct shell_static_entry *dloc)
@ -291,7 +292,7 @@ const struct shell_static_entry *shell_find_cmd(
const struct shell_static_entry *entry; const struct shell_static_entry *entry;
size_t idx = 0; 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) { if (strcmp(cmd_str, entry->syntax) == 0) {
return entry; return entry;
} }
@ -300,7 +301,7 @@ const struct shell_static_entry *shell_find_cmd(
return NULL; 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, const struct shell_static_entry *entry,
size_t argc, size_t argc,
const char *argv[], const char *argv[],
@ -323,7 +324,7 @@ const struct shell_static_entry *shell_get_last_command(
} }
prev_entry = entry; prev_entry = entry;
entry = shell_find_cmd(entry, argv[*match_arg], dloc); entry = z_shell_find_cmd(entry, argv[*match_arg], dloc);
if (entry) { if (entry) {
(*match_arg)++; (*match_arg)++;
} else { } 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; uint16_t shift = 0U;
if (!str) { 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); buffer_trim(shell->ctx->cmd_buff, &shell->ctx->cmd_buff_len);
shell->ctx->cmd_buff_pos = shell->ctx->cmd_buff_len; shell->ctx->cmd_buff_pos = shell->ctx->cmd_buff_len;

View file

@ -15,29 +15,30 @@ extern "C" {
#define SHELL_MSG_SPECIFY_SUBCOMMAND "Please specify a subcommand.\n" #define SHELL_MSG_SPECIFY_SUBCOMMAND "Please specify a subcommand.\n"
int32_t row_span_with_buffer_offsets_get(struct shell_multiline_cons *cons, int32_t z_row_span_with_buffer_offsets_get(struct shell_multiline_cons *cons,
uint16_t offset1, uint16_t offset1,
uint16_t offset2); uint16_t offset2);
int32_t column_span_with_buffer_offsets_get(struct shell_multiline_cons *cons, int32_t z_column_span_with_buffer_offsets_get(struct shell_multiline_cons *cons,
uint16_t offset1, uint16_t offset1,
uint16_t offset2); uint16_t offset2);
void shell_multiline_data_calc(struct shell_multiline_cons *cons, void z_shell_multiline_data_calc(struct shell_multiline_cons *cons,
uint16_t buff_pos, uint16_t buff_len); 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); return str == NULL ? 0U : (uint16_t)strlen(str);
} }
char shell_make_argv(size_t *argc, const char **argv, char z_shell_make_argv(size_t *argc, const char **argv,
char *cmd, uint8_t max_argc); char *cmd, uint8_t max_argc);
/** @brief Removes pattern and following space /** @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. /** @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. * @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, const struct shell_static_entry *parent,
size_t idx, size_t idx,
struct shell_static_entry *dloc); 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 struct shell_static_entry *parent,
const char *cmd_str, const char *cmd_str,
struct shell_static_entry *dloc); struct shell_static_entry *dloc);
@ -69,7 +70,7 @@ const struct shell_static_entry *shell_find_cmd(
* *
* @return Pointer to found command. * @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, const struct shell_static_entry *entry,
size_t argc, size_t argc,
const char *argv[], const char *argv[],
@ -77,16 +78,15 @@ const struct shell_static_entry *shell_get_last_command(
struct shell_static_entry *dloc, struct shell_static_entry *dloc,
bool only_static); 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); z_shell_fprintf_buffer_flush(shell->fprintf_ctx);
} }
void shell_cmd_trim(const struct shell *shell); static inline bool z_shell_in_select_mode(const struct shell *shell)
static inline bool shell_in_select_mode(const struct shell *shell)
{ {
return shell->ctx->selected_cmd == NULL ? false : true; return shell->ctx->selected_cmd == NULL ? false : true;
} }

View file

@ -14,7 +14,7 @@ static enum shell_wildcard_status command_add(char *buff, uint16_t *buff_len,
char const *cmd, char const *cmd,
char const *pattern) char const *pattern)
{ {
uint16_t cmd_len = shell_strlen(cmd); uint16_t cmd_len = z_shell_strlen(cmd);
char *completion_addr; char *completion_addr;
uint16_t shift; 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; 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 */ /* make place for new command: + 1 for space + 1 for EOS */
memmove(completion_addr + cmd_len + 1, completion_addr, shift + 1); 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 cmd_idx = 0;
size_t cnt = 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) { if (fnmatch(pattern, entry->syntax, 0) == 0) {
ret_val = command_add(shell->ctx->temp_buff, 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) { if (cnt > 0) {
shell_pattern_remove(shell->ctx->temp_buff, z_shell_pattern_remove(shell->ctx->temp_buff,
&shell->ctx->cmd_tmp_buff_len, pattern); &shell->ctx->cmd_tmp_buff_len, pattern);
} }
return ret_val; 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) 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++) { for (size_t i = 0; i < str_len; i++) {
if ((str[i] == '?') || (str[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. * At this point it is important to keep temp_buff as one string.
* It will allow to find wildcard commands easily with strstr function. * 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*/ /* +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;
} }