Skip to content

Commit 584e14b

Browse files
authored
Merge pull request #21505 from derMihai/mir/export_readline
sys/shell: expose readline()
2 parents a81adc4 + b149bfb commit 584e14b

File tree

3 files changed

+26
-27
lines changed

3 files changed

+26
-27
lines changed

sys/include/shell.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,31 @@ int shell_handle_input_line(const shell_command_t *commands, char *line);
270270
int shell_parse_file(const shell_command_t *commands,
271271
const char *filename, unsigned *line_nr);
272272

273+
/**
274+
* @brief Read a single line from standard input into a buffer.
275+
*
276+
* In addition to copying characters, this routine echoes the line back to
277+
* stdout and also supports primitive line editing.
278+
*
279+
* If the input line is too long, the input will still be consumed until the end
280+
* to prevent the next line from containing garbage.
281+
*
282+
* We allow Unix (`\n`), DOS (`\r\n`), and Mac linebreaks (`\r`).
283+
* QEMU transmits only a single `\r` == 13 on hitting enter ("-serial stdio").
284+
* DOS newlines are handled like hitting enter twice.
285+
*
286+
* @param buf Buffer where the input will be placed.
287+
* @param size Size of the buffer. The maximum line length will be one less
288+
* than size, to accommodate for the null terminator.
289+
* The minimum buffer size is 1.
290+
*
291+
* @return length of the read line, excluding the terminator, if reading was
292+
* successful.
293+
* @return EOF, if the end of the input stream was reached.
294+
* @return -ENOBUFS if the buffer size was exceeded.
295+
*/
296+
int readline(char *buf, size_t size);
297+
273298
#ifndef __cplusplus
274299
/**
275300
* @brief Define shell command

sys/shell/shell.c

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -439,30 +439,7 @@ static inline void new_line(void)
439439
}
440440
}
441441

442-
/**
443-
* @brief Read a single line from standard input into a buffer.
444-
*
445-
* In addition to copying characters, this routine echoes the line back to
446-
* stdout and also supports primitive line editing.
447-
*
448-
* If the input line is too long, the input will still be consumed until the end
449-
* to prevent the next line from containing garbage.
450-
*
451-
* We allow Unix (\n), DOS (\r\n), and Mac linebreaks (\r).
452-
* QEMU transmits only a single '\r' == 13 on hitting enter ("-serial stdio").
453-
* DOS newlines are handled like hitting enter twice.
454-
*
455-
* @param buf Buffer where the input will be placed.
456-
* @param size Size of the buffer. The maximum line length will be one less
457-
* than size, to accommodate for the null terminator.
458-
* The minimum buffer size is 1.
459-
*
460-
* @return length of the read line, excluding the terminator, if reading was
461-
* successful.
462-
* @return EOF, if the end of the input stream was reached.
463-
* @return -ENOBUFS if the buffer size was exceeded.
464-
*/
465-
int readline(char *buf, size_t size) /* needed externally by module shell_lock */
442+
int readline(char *buf, size_t size)
466443
{
467444
int curr_pos = 0;
468445
bool length_exceeded = false;

sys/shell_lock/shell_lock.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ static bool _shell_is_locked = true;
5252
static ztimer_t _shell_auto_lock_ztimer;
5353
#endif
5454

55-
/* defined in shell.c */
56-
extern int readline(char *buf, size_t size);
57-
5855
static int _lock_handler(int argc, char **argv)
5956
{
6057
(void) argc;

0 commit comments

Comments
 (0)