shell: make shell_run run shell forever
This change is in preparation to [PR 10788]. PR 10788 will make the shell exitable which may lead to unexpected behavior in comparison to previous usage of the shell. To prevent this, this PR introduces two "new" functions to the shell's API: `shell_run_once()` and `shell_run_forever()`. `shell_run_once()` basically has the same behavior as `shell_run()` in current master: Start a shell and continue reading lines until EOF is reached. `shell_run_forever()` wraps around `shell_run_once()` and restarts the shell if it exits. `shell_run()` is re-introduced as a back-porting alias for `shell_run_forever()`. As a consequence all current calls to `shell_run()` won't exit even with [PR 10788] merged (which would add EOT as additional exit condition for `shell_run_once()`). [PR 10788]: https://github.com/RIOT-OS/RIOT/pull/10788
This commit is contained in:
parent
5631b698db
commit
2c1a2863ce
@ -64,13 +64,41 @@ typedef struct shell_command_t {
|
||||
} shell_command_t;
|
||||
|
||||
/**
|
||||
* @brief Start a shell.
|
||||
* @brief Start a shell and exit once EOF is reached.
|
||||
*
|
||||
* @param[in] commands ptr to array of command structs
|
||||
* @param[in] line_buf Buffer that will be used for reading a line
|
||||
* @param[in] len nr of bytes that fit in line_buf
|
||||
*/
|
||||
void shell_run(const shell_command_t *commands, char *line_buf, int len);
|
||||
void shell_run_once(const shell_command_t *commands, char *line_buf, int len);
|
||||
|
||||
/**
|
||||
* @brief Start a shell and restart it if it exits
|
||||
*
|
||||
* @param[in] commands ptr to array of command structs
|
||||
* @param[in] line_buf Buffer that will be used for reading a line
|
||||
* @param[in] len nr of bytes that fit in line_buf
|
||||
*/
|
||||
static inline void shell_run_forever(const shell_command_t *commands,
|
||||
char *line_buf, int len)
|
||||
{
|
||||
while (1) {
|
||||
shell_run_once(commands, line_buf, len);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Back-porting alias for @ref shell_run_forever
|
||||
*
|
||||
* @param[in] commands ptr to array of command structs
|
||||
* @param[in] line_buf Buffer that will be used for reading a line
|
||||
* @param[in] len nr of bytes that fit in line_buf
|
||||
*/
|
||||
static inline void shell_run(const shell_command_t *commands,
|
||||
char *line_buf, int len)
|
||||
{
|
||||
shell_run_forever(commands, line_buf, len);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@ -290,7 +290,8 @@ static inline void print_prompt(void)
|
||||
flush_if_needed();
|
||||
}
|
||||
|
||||
void shell_run(const shell_command_t *shell_commands, char *line_buf, int len)
|
||||
void shell_run_once(const shell_command_t *shell_commands,
|
||||
char *line_buf, int len)
|
||||
{
|
||||
print_prompt();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user