Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions sys/include/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,31 @@ int shell_handle_input_line(const shell_command_t *commands, char *line);
int shell_parse_file(const shell_command_t *commands,
const char *filename, unsigned *line_nr);

/**
* @brief Read a single line from standard input into a buffer.
*
* In addition to copying characters, this routine echoes the line back to
* stdout and also supports primitive line editing.
*
* If the input line is too long, the input will still be consumed until the end
* to prevent the next line from containing garbage.
*
* We allow Unix (`\n`), DOS (`\r\n`), and Mac linebreaks (`\r`).
* QEMU transmits only a single `\r` == 13 on hitting enter ("-serial stdio").
* DOS newlines are handled like hitting enter twice.
*
* @param buf Buffer where the input will be placed.
* @param size Size of the buffer. The maximum line length will be one less
* than size, to accommodate for the null terminator.
* The minimum buffer size is 1.
*
* @return length of the read line, excluding the terminator, if reading was
* successful.
* @return EOF, if the end of the input stream was reached.
* @return -ENOBUFS if the buffer size was exceeded.
*/
int readline(char *buf, size_t size);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int readline(char *buf, size_t size);
int shell_read_line(char *buf, size_t size);

as we usually prefix all functions with their module name?


#ifndef __cplusplus
/**
* @brief Define shell command
Expand Down
25 changes: 1 addition & 24 deletions sys/shell/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,30 +439,7 @@ static inline void new_line(void)
}
}

/**
* @brief Read a single line from standard input into a buffer.
*
* In addition to copying characters, this routine echoes the line back to
* stdout and also supports primitive line editing.
*
* If the input line is too long, the input will still be consumed until the end
* to prevent the next line from containing garbage.
*
* We allow Unix (\n), DOS (\r\n), and Mac linebreaks (\r).
* QEMU transmits only a single '\r' == 13 on hitting enter ("-serial stdio").
* DOS newlines are handled like hitting enter twice.
*
* @param buf Buffer where the input will be placed.
* @param size Size of the buffer. The maximum line length will be one less
* than size, to accommodate for the null terminator.
* The minimum buffer size is 1.
*
* @return length of the read line, excluding the terminator, if reading was
* successful.
* @return EOF, if the end of the input stream was reached.
* @return -ENOBUFS if the buffer size was exceeded.
*/
int readline(char *buf, size_t size) /* needed externally by module shell_lock */
int readline(char *buf, size_t size)
{
int curr_pos = 0;
bool length_exceeded = false;
Expand Down
3 changes: 0 additions & 3 deletions sys/shell_lock/shell_lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ static bool _shell_is_locked = true;
static ztimer_t _shell_auto_lock_ztimer;
#endif

/* defined in shell.c */
extern int readline(char *buf, size_t size);

static int _lock_handler(int argc, char **argv)
{
(void) argc;
Expand Down