1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/sys/include/shell.h

88 lines
3.6 KiB
C
Raw Normal View History

2014-04-22 08:02:56 +02:00
/*
* Copyright (C) 2009-2013 Freie Universität Berlin
*
2013-11-22 20:47:05 +01:00
* This file is subject to the terms and conditions of the GNU Lesser General
* Public License. See the file LICENSE in the top level directory for more
* details.
2014-04-22 08:02:56 +02:00
*/
2010-09-22 17:25:19 +02:00
/**
* @defgroup sys_shell Shell
* @ingroup sys
* @brief Simple shell interpreter
2010-09-22 17:25:19 +02:00
*/
#ifndef __SHELL_H
#define __SHELL_H
2014-04-22 08:02:56 +02:00
#include <stdint.h>
2014-04-22 08:02:56 +02:00
#include "attributes.h"
/**
* @brief Protype of a shell callback handler.
* @details The functions supplied to shell_init() must use this signature.
* The argument list is terminated with a NULL, i.e ``argv[argc] == NULL`.
* ``argv[0]`` is the function name.
*
* Escape sequences are removed before the function is called.
*
* The called function may edit `argv` and the contained strings,
* but it must be taken care of not to leave the boundaries of the array.
* This functionality can be used by getopt() or a similar function.
* @param[in] argc Number of arguments supplied to the function invocation.
* @param[in] argv The supplied argument list.
*/
typedef void (*shell_command_handler_t)(int argc, char **argv);
2014-04-22 08:02:56 +02:00
/**
* @brief A single command in the list of the supported commands.
* @details The list of commands is NULL terminated,
* i.e. the last element must be ``{ NULL, NULL, NULL }``.
*/
2010-11-02 17:23:10 +01:00
typedef struct shell_command_t {
const char *name; /**< Name of the function */
const char *desc; /**< Description to print in the "help" command. */
2014-04-22 08:02:56 +02:00
shell_command_handler_t handler; /**< The callback function. */
} shell_command_t;
2010-09-22 17:25:19 +02:00
2014-04-22 08:02:56 +02:00
/**
* @brief The internal state of a shell session.
* @details Use shell_init() to initialize the datum,
* and shell_run() to run the REPL session.
*/
2010-09-22 17:25:19 +02:00
typedef struct shell_t {
const shell_command_t *command_list; /**< The commandlist supplied to shell_init(). */
uint16_t shell_buffer_size; /**< The maximum line length supplied to shell_init(). */
int (*readchar)(void); /**< The read function supplied to shell_init(). */
void (*put_char)(int); /**< The write function supplied to shell_init(). */
2010-09-22 17:25:19 +02:00
} shell_t;
/**
2014-04-22 08:02:56 +02:00
* @brief Initialize a shell session state.
* @param[out] shell The datum to initialize.
* @param[in] shell_commands Null-terminated list of commands to understand.
* Supply `NULL` to only feature the default commands.
* @param shell_buffer_size The backing buffer for the command line.
* Allocated on the stack!
* @param read_char A blocking function that reads one 8-bit character at a time.
* The valid code range is [0;255].
* A value of `< 0` denotes a read error.
* @param put_char Function used to print back the last read character.
* Only valid unsigned chars in [0;255] will be supplied.
2010-09-22 17:25:19 +02:00
*/
2014-04-22 08:02:56 +02:00
void shell_init(shell_t *shell,
const shell_command_t *shell_commands,
uint16_t shell_buffer_size,
int (*read_char)(void),
void (*put_char)(int));
2010-09-22 17:25:19 +02:00
/**
2014-04-22 08:02:56 +02:00
* @brief Start the shell session.
* @param[in] shell The session that was previously initialized with shell_init().
* @returns This function does not return.
2010-09-22 17:25:19 +02:00
*/
2014-04-22 08:02:56 +02:00
void shell_run(shell_t *shell) NORETURN;
2010-09-28 13:39:59 +02:00
2010-09-30 15:10:39 +02:00
#endif /* __SHELL_H */