Skip to content

Commit 889e37b

Browse files
Jakub Rzeszutkocarlescufi
authored andcommitted
shell: shell_utils internal api update
Add prefix z_ to internal functions provided by the shell_utils module. Signed-off-by: Jakub Rzeszutko <[email protected]>
1 parent 31bc7d2 commit 889e37b

File tree

8 files changed

+121
-118
lines changed

8 files changed

+121
-118
lines changed

subsys/shell/shell.c

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ static void tab_item_print(const struct shell *shell, const char *option,
125125
return;
126126
}
127127

128-
longest_option += shell_strlen(tab);
128+
longest_option += z_shell_strlen(tab);
129129

130130
columns = (shell->ctx->vt100_ctx.cons.terminal_wid
131-
- shell_strlen(tab)) / longest_option;
132-
diff = longest_option - shell_strlen(option);
131+
- z_shell_strlen(tab)) / longest_option;
132+
diff = longest_option - z_shell_strlen(option);
133133

134134
if (shell->ctx->vt100_ctx.printed_cmd++ % columns == 0U) {
135135
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)
196196
/* Backup command if history is entered */
197197
if (!z_shell_history_active(shell->history)) {
198198
if (up) {
199-
uint16_t cmd_len = shell_strlen(shell->ctx->cmd_buff);
199+
uint16_t cmd_len = z_shell_strlen(shell->ctx->cmd_buff);
200200

201201
if (cmd_len) {
202202
strcpy(shell->ctx->temp_buff,
@@ -217,7 +217,7 @@ static void history_handle(const struct shell *shell, bool up)
217217
/* On exiting history mode print backed up command. */
218218
if (!history_mode) {
219219
strcpy(shell->ctx->cmd_buff, shell->ctx->temp_buff);
220-
len = shell_strlen(shell->ctx->cmd_buff);
220+
len = z_shell_strlen(shell->ctx->cmd_buff);
221221
}
222222

223223
z_shell_op_cursor_home_move(shell);
@@ -255,8 +255,8 @@ static bool tab_prepare(const struct shell *shell,
255255
shell->ctx->temp_buff[shell->ctx->cmd_buff_pos] = '\0';
256256

257257
/* Create argument list. */
258-
(void)shell_make_argv(argc, *argv, shell->ctx->temp_buff,
259-
CONFIG_SHELL_ARGC_MAX);
258+
(void)z_shell_make_argv(argc, *argv, shell->ctx->temp_buff,
259+
CONFIG_SHELL_ARGC_MAX);
260260

261261
if (*argc > CONFIG_SHELL_ARGC_MAX) {
262262
return false;
@@ -267,7 +267,7 @@ static bool tab_prepare(const struct shell *shell,
267267

268268
if (IS_ENABLED(CONFIG_SHELL_CMDS_SELECT) && (*argc > 0) &&
269269
(strcmp("select", (*argv)[0]) == 0) &&
270-
!shell_in_select_mode(shell)) {
270+
!z_shell_in_select_mode(shell)) {
271271
*argv = *argv + 1;
272272
*argc = *argc - 1;
273273
}
@@ -287,8 +287,9 @@ static bool tab_prepare(const struct shell *shell,
287287

288288
search_argc = space ? *argc : *argc - 1;
289289

290-
*cmd = shell_get_last_command(selected_cmd_get(shell), search_argc,
291-
*argv, complete_arg_idx, d_entry, false);
290+
*cmd = z_shell_get_last_command(selected_cmd_get(shell), search_argc,
291+
*argv, complete_arg_idx, d_entry,
292+
false);
292293

293294
/* if search_argc == 0 (empty command line) shell_get_last_command will
294295
* return NULL tab is allowed, otherwise not.
@@ -317,11 +318,11 @@ static void find_completion_candidates(const struct shell *shell,
317318
size_t incompl_cmd_len;
318319
size_t idx = 0;
319320

320-
incompl_cmd_len = shell_strlen(incompl_cmd);
321+
incompl_cmd_len = z_shell_strlen(incompl_cmd);
321322
*longest = 0U;
322323
*cnt = 0;
323324

324-
while ((candidate = shell_cmd_get(cmd, idx, &dloc)) != NULL) {
325+
while ((candidate = z_shell_cmd_get(cmd, idx, &dloc)) != NULL) {
325326
bool is_candidate;
326327
is_candidate = is_completion_candidate(candidate->syntax,
327328
incompl_cmd, incompl_cmd_len);
@@ -344,14 +345,14 @@ static void autocomplete(const struct shell *shell,
344345
{
345346
const struct shell_static_entry *match;
346347
uint16_t cmd_len;
347-
uint16_t arg_len = shell_strlen(arg);
348+
uint16_t arg_len = z_shell_strlen(arg);
348349

349350
/* shell->ctx->active_cmd can be safely used outside of command context
350351
* to save stack
351352
*/
352-
match = shell_cmd_get(cmd, subcmd_idx, &shell->ctx->active_cmd);
353+
match = z_shell_cmd_get(cmd, subcmd_idx, &shell->ctx->active_cmd);
353354
__ASSERT_NO_MSG(match != NULL);
354-
cmd_len = shell_strlen(match->syntax);
355+
cmd_len = z_shell_strlen(match->syntax);
355356

356357
if (!IS_ENABLED(CONFIG_SHELL_TAB_AUTOCOMPLETION)) {
357358
/* 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,
412413
uint16_t longest)
413414
{
414415
const struct shell_static_entry *match;
415-
size_t str_len = shell_strlen(str);
416+
size_t str_len = z_shell_strlen(str);
416417
size_t idx = first;
417418

418419
/* Printing all matching commands (options). */
@@ -422,7 +423,7 @@ static void tab_options_print(const struct shell *shell,
422423
/* shell->ctx->active_cmd can be safely used outside of command
423424
* context to save stack
424425
*/
425-
match = shell_cmd_get(cmd, idx, &shell->ctx->active_cmd);
426+
match = z_shell_cmd_get(cmd, idx, &shell->ctx->active_cmd);
426427
__ASSERT_NO_MSG(match != NULL);
427428
idx++;
428429
if (str && match->syntax &&
@@ -450,7 +451,7 @@ static uint16_t common_beginning_find(const struct shell *shell,
450451

451452
__ASSERT_NO_MSG(cnt > 1);
452453

453-
match = shell_cmd_get(cmd, first, &dynamic_entry);
454+
match = z_shell_cmd_get(cmd, first, &dynamic_entry);
454455
__ASSERT_NO_MSG(match);
455456
strncpy(shell->ctx->temp_buff, match->syntax,
456457
sizeof(shell->ctx->temp_buff) - 1);
@@ -462,7 +463,7 @@ static uint16_t common_beginning_find(const struct shell *shell,
462463
const struct shell_static_entry *match2;
463464
int curr_common;
464465

465-
match2 = shell_cmd_get(cmd, idx++, &dynamic_entry2);
466+
match2 = z_shell_cmd_get(cmd, idx++, &dynamic_entry2);
466467
if (match2 == NULL) {
467468
break;
468469
}
@@ -484,7 +485,7 @@ static void partial_autocomplete(const struct shell *shell,
484485
size_t first, size_t cnt)
485486
{
486487
const char *completion;
487-
uint16_t arg_len = shell_strlen(arg);
488+
uint16_t arg_len = z_shell_strlen(arg);
488489
uint16_t common = common_beginning_find(shell, cmd, &completion, first,
489490
cnt, arg_len);
490491

@@ -624,7 +625,7 @@ static int execute(const struct shell *shell)
624625
memset(&shell->ctx->active_cmd, 0, sizeof(shell->ctx->active_cmd));
625626

626627
if (IS_ENABLED(CONFIG_SHELL_HISTORY)) {
627-
shell_cmd_trim(shell);
628+
z_shell_cmd_trim(shell);
628629
history_put(shell, shell->ctx->cmd_buff,
629630
shell->ctx->cmd_buff_len);
630631
}
@@ -649,7 +650,7 @@ static int execute(const struct shell *shell)
649650
/* Below loop is analyzing subcommands of found root command. */
650651
while ((argc != 1) && (cmd_lvl < CONFIG_SHELL_ARGC_MAX)
651652
&& args_left > 0) {
652-
quote = shell_make_argv(&argc, argvp, cmd_buf, 2);
653+
quote = z_shell_make_argv(&argc, argvp, cmd_buf, 2);
653654
cmd_buf = (char *)argvp[1];
654655

655656
if (argc == 0) {
@@ -700,7 +701,7 @@ static int execute(const struct shell *shell)
700701
}
701702

702703
if (has_last_handler == false) {
703-
entry = shell_find_cmd(parent, argvp[0], &dloc);
704+
entry = z_shell_find_cmd(parent, argvp[0], &dloc);
704705
}
705706

706707
argvp++;
@@ -717,7 +718,7 @@ static int execute(const struct shell *shell)
717718
parent = entry;
718719
} else {
719720
if (cmd_lvl == 0 &&
720-
(!shell_in_select_mode(shell) ||
721+
(!z_shell_in_select_mode(shell) ||
721722
shell->ctx->selected_cmd->handler == NULL)) {
722723
z_shell_fprintf(shell, SHELL_ERROR,
723724
"%s%s\n", argv[0],
@@ -752,10 +753,10 @@ static int execute(const struct shell *shell)
752753
* with all expanded commands. Hence shell_make_argv needs to
753754
* be called again.
754755
*/
755-
(void)shell_make_argv(&cmd_lvl,
756-
&argv[selected_cmd_get(shell) ? 1 : 0],
757-
shell->ctx->cmd_buff,
758-
CONFIG_SHELL_ARGC_MAX);
756+
(void)z_shell_make_argv(&cmd_lvl,
757+
&argv[selected_cmd_get(shell) ? 1 : 0],
758+
shell->ctx->cmd_buff,
759+
CONFIG_SHELL_ARGC_MAX);
759760

760761
if (selected_cmd_get(shell)) {
761762
/* Apart from what is in the command buffer, there is
@@ -1090,7 +1091,7 @@ static void state_collect(const struct shell *shell)
10901091
}
10911092
}
10921093

1093-
transport_buffer_flush(shell);
1094+
z_transport_buffer_flush(shell);
10941095
}
10951096

10961097
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,
11681169
CONFIG_SHELL_DEFAULT_TERMINAL_WIDTH;
11691170
shell->ctx->vt100_ctx.cons.terminal_hei =
11701171
CONFIG_SHELL_DEFAULT_TERMINAL_HEIGHT;
1171-
shell->ctx->vt100_ctx.cons.name_len = shell_strlen(shell->ctx->prompt);
1172+
shell->ctx->vt100_ctx.cons.name_len = z_shell_strlen(shell->ctx->prompt);
11721173
z_flag_use_colors_set(shell, IS_ENABLED(CONFIG_SHELL_VT100_COLORS));
11731174

11741175
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,
14271428
if (!z_flag_cmd_ctx_get(shell)) {
14281429
z_shell_print_prompt_and_cmd(shell);
14291430
}
1430-
transport_buffer_flush(shell);
1431+
z_transport_buffer_flush(shell);
14311432
k_mutex_unlock(&shell->ctx->wr_mtx);
14321433
}
14331434

@@ -1507,7 +1508,7 @@ int shell_prompt_change(const struct shell *shell, const char *prompt)
15071508
return -EINVAL;
15081509
}
15091510
shell->ctx->prompt = prompt;
1510-
shell->ctx->vt100_ctx.cons.name_len = shell_strlen(prompt);
1511+
shell->ctx->vt100_ctx.cons.name_len = z_shell_strlen(prompt);
15111512

15121513
return 0;
15131514
}
@@ -1521,7 +1522,7 @@ void shell_help(const struct shell *shell)
15211522

15221523
int shell_execute_cmd(const struct shell *shell, const char *cmd)
15231524
{
1524-
uint16_t cmd_len = shell_strlen(cmd);
1525+
uint16_t cmd_len = z_shell_strlen(cmd);
15251526
int ret_val;
15261527

15271528
if (cmd == NULL) {
@@ -1594,7 +1595,7 @@ static int cmd_help(const struct shell *shell, size_t argc, char **argv)
15941595
size_t idx = 0;
15951596

15961597
shell_print(shell, "\nAvailable commands:");
1597-
while ((entry = shell_cmd_get(NULL, idx++, NULL)) != NULL) {
1598+
while ((entry = z_shell_cmd_get(NULL, idx++, NULL)) != NULL) {
15981599
shell_print(shell, " %s", entry->syntax);
15991600
}
16001601
}

subsys/shell/shell_cmds.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static int cursor_position_get(const struct shell *shell, uint16_t *x, uint16_t
8181
/* fprintf buffer needs to be flushed to start sending prepared
8282
* escape code to the terminal.
8383
*/
84-
transport_buffer_flush(shell);
84+
z_transport_buffer_flush(shell);
8585

8686
/* timeout for terminal response = ~1s */
8787
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)
376376

377377
argc--;
378378
argv = argv + 1;
379-
candidate = shell_get_last_command(shell->ctx->selected_cmd,
380-
argc, (const char **)argv,
381-
&matching_argc, &entry, true);
379+
candidate = z_shell_get_last_command(shell->ctx->selected_cmd,
380+
argc, (const char **)argv,
381+
&matching_argc, &entry, true);
382382

383383
if ((candidate != NULL) && !no_args(candidate)
384384
&& (argc == matching_argc)) {

subsys/shell/shell_help.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ static void formatted_text_print(const struct shell *shell, const char *str,
3939
while (true) {
4040
size_t idx = 0;
4141

42-
length = shell_strlen(str) - offset;
42+
length = z_shell_strlen(str) - offset;
4343

4444
if (length <=
4545
shell->ctx->vt100_ctx.cons.terminal_wid - terminal_offset) {
4646
for (idx = 0; idx < length; idx++) {
4747
if (*(str + offset + idx) == '\n') {
48-
transport_buffer_flush(shell);
48+
z_transport_buffer_flush(shell);
4949
z_shell_write(shell, str + offset, idx);
5050
offset += idx + 1;
5151
z_cursor_next_line_move(shell);
@@ -88,7 +88,7 @@ static void formatted_text_print(const struct shell *shell, const char *str,
8888
/* Writing one line, fprintf IO buffer must be flushed
8989
* before calling shell_write.
9090
*/
91-
transport_buffer_flush(shell);
91+
z_transport_buffer_flush(shell);
9292
z_shell_write(shell, str + offset, length);
9393
offset += length;
9494

@@ -155,8 +155,8 @@ void z_shell_help_subcmd_print(const struct shell *shell,
155155
size_t idx = 0;
156156

157157
/* Searching for the longest subcommand to print. */
158-
while ((entry = shell_cmd_get(parent, idx++, &dloc)) != NULL) {
159-
longest = Z_MAX(longest, shell_strlen(entry->syntax));
158+
while ((entry = z_shell_cmd_get(parent, idx++, &dloc)) != NULL) {
159+
longest = Z_MAX(longest, z_shell_strlen(entry->syntax));
160160
};
161161

162162
/* No help to print */
@@ -171,7 +171,7 @@ void z_shell_help_subcmd_print(const struct shell *shell,
171171
/* Printing subcommands and help string (if exists). */
172172
idx = 0;
173173

174-
while ((entry = shell_cmd_get(parent, idx++, &dloc)) != NULL) {
174+
while ((entry = z_shell_cmd_get(parent, idx++, &dloc)) != NULL) {
175175
help_item_print(shell, entry->syntax, longest, entry->help);
176176
}
177177
}
@@ -182,7 +182,7 @@ void z_shell_help_cmd_print(const struct shell *shell,
182182
static const char cmd_sep[] = " - "; /* commands separator */
183183
uint16_t field_width;
184184

185-
field_width = shell_strlen(cmd->syntax) + shell_strlen(cmd_sep);
185+
field_width = z_shell_strlen(cmd->syntax) + z_shell_strlen(cmd_sep);
186186

187187
z_shell_fprintf(shell, SHELL_NORMAL, "%s%s", cmd->syntax, cmd_sep);
188188

subsys/shell/shell_log_backend.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,9 @@ static void panic(const struct log_backend *const backend)
274274
SHELL_LOG_BACKEND_PANIC;
275275

276276
/* Move to the start of next line. */
277-
shell_multiline_data_calc(&shell->ctx->vt100_ctx.cons,
278-
shell->ctx->cmd_buff_pos,
279-
shell->ctx->cmd_buff_len);
277+
z_shell_multiline_data_calc(&shell->ctx->vt100_ctx.cons,
278+
shell->ctx->cmd_buff_pos,
279+
shell->ctx->cmd_buff_len);
280280
z_shell_op_cursor_vert_move(shell, -1);
281281
z_shell_op_cursor_horiz_move(shell,
282282
-shell->ctx->vt100_ctx.cons.cur_x);

0 commit comments

Comments
 (0)