zephyr/subsys/shell/shell_utils.h
Gerard Marull-Paretas 79e6b0e0f6 includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.

The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.

NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-09-05 16:31:47 +02:00

100 lines
2.8 KiB
C

/*
* Copyright (c) 2018 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef SHELL_UTILS_H__
#define SHELL_UTILS_H__
#include <zephyr/kernel.h>
#include <zephyr/shell/shell.h>
#ifdef __cplusplus
extern "C" {
#endif
#define SHELL_MSG_SPECIFY_SUBCOMMAND "Please specify a subcommand.\n"
int32_t z_row_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 z_shell_multiline_data_calc(struct shell_multiline_cons *cons,
uint16_t buff_pos, uint16_t buff_len);
static inline uint16_t z_shell_strlen(const char *str)
{
return str == NULL ? 0U : (uint16_t)strlen(str);
}
char z_shell_make_argv(size_t *argc, const char **argv,
char *cmd, uint8_t max_argc);
/** @brief Removes pattern and following space
*
*/
void z_shell_pattern_remove(char *buff, uint16_t *buff_len,
const char *pattern);
/** @brief Get subcommand with given index from the root.
*
* @param parent Parent entry. Null to get root command from index.
* @param idx Command index.
* @param dloc Location used to write dynamic entry.
*
* @return Fetched command or null if command with that index does not exist.
*/
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 *z_shell_find_cmd(
const struct shell_static_entry *parent,
const char *cmd_str,
struct shell_static_entry *dloc);
/* @internal @brief Function returns pointer to a shell's subcommands array
* for a level given by argc and matching command patter provided in argv.
*
* @param shell Entry. NULL for root entry.
* @param argc Number of arguments.
* @param argv Pointer to an array with arguments.
* @param match_arg Subcommand level of last matching argument.
* @param d_entry Shell static command descriptor.
* @param only_static If true search only for static commands.
*
* @return Pointer to found command.
*/
const struct shell_static_entry *z_shell_get_last_command(
const struct shell_static_entry *entry,
size_t argc,
const char *argv[],
size_t *match_arg,
struct shell_static_entry *dloc,
bool only_static);
void z_shell_spaces_trim(char *str);
void z_shell_cmd_trim(const struct shell *shell);
const struct shell_static_entry *root_cmd_find(const char *syntax);
static inline void z_transport_buffer_flush(const struct shell *shell)
{
z_shell_fprintf_buffer_flush(shell->fprintf_ctx);
}
static inline bool z_shell_in_select_mode(const struct shell *shell)
{
return shell->ctx->selected_cmd == NULL ? false : true;
}
#ifdef __cplusplus
}
#endif
#endif /* SHELL_UTILS_H__ */