2014-04-22 08:02:56 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2009-2013 Freie Universität Berlin
|
2013-08-16 10:20:23 +02:00
|
|
|
*
|
2014-08-23 15:43:13 +02:00
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. 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
|
|
|
|
|
|
|
/**
|
2013-11-27 17:54:30 +01:00
|
|
|
* @defgroup sys_shell Shell
|
|
|
|
* @ingroup sys
|
|
|
|
* @brief Simple shell interpreter
|
2015-02-12 18:06:34 +01:00
|
|
|
*
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief Shell interface definition
|
2010-09-22 17:25:19 +02:00
|
|
|
*/
|
|
|
|
|
2013-11-27 16:28:31 +01:00
|
|
|
#ifndef __SHELL_H
|
|
|
|
#define __SHELL_H
|
2014-04-22 08:02:56 +02:00
|
|
|
|
2013-12-19 17:11:06 +01:00
|
|
|
#include <stdint.h>
|
2013-11-27 16:28:31 +01:00
|
|
|
|
2014-04-22 08:02:56 +02:00
|
|
|
#include "attributes.h"
|
|
|
|
|
2014-10-10 11:51:11 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2015-07-14 18:18:28 +02:00
|
|
|
/**
|
|
|
|
* @brief Default shell buffer size (maximum line length shell can handle)
|
|
|
|
*/
|
|
|
|
#define SHELL_DEFAULT_BUFSIZE (128)
|
|
|
|
|
2014-04-22 08:02:56 +02:00
|
|
|
/**
|
|
|
|
* @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.
|
2015-03-20 08:51:45 +01:00
|
|
|
*
|
|
|
|
* @return 0 on success
|
|
|
|
* @return Anything else on failure
|
2014-04-22 08:02:56 +02:00
|
|
|
*/
|
2015-03-20 08:51:45 +01:00
|
|
|
typedef int (*shell_command_handler_t)(int argc, char **argv);
|
2014-02-21 19:10:24 +01:00
|
|
|
|
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 {
|
2014-04-27 14:37:54 +02:00
|
|
|
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. */
|
2010-10-01 15:24:43 +02:00
|
|
|
} shell_command_t;
|
2010-09-22 17:25:19 +02:00
|
|
|
|
2014-04-22 08:02:56 +02:00
|
|
|
/**
|
2015-07-14 18:18:28 +02:00
|
|
|
* @brief Start a shell.
|
|
|
|
*
|
|
|
|
* @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
|
|
|
|
*
|
2014-04-22 08:02:56 +02:00
|
|
|
* @returns This function does not return.
|
2010-09-22 17:25:19 +02:00
|
|
|
*/
|
2015-07-14 18:18:28 +02:00
|
|
|
void shell_run(const shell_command_t *commands, char *line_buf, int len) NORETURN;
|
2010-09-28 13:39:59 +02:00
|
|
|
|
2014-10-10 11:51:11 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-09-30 15:10:39 +02:00
|
|
|
#endif /* __SHELL_H */
|
2015-02-12 18:06:34 +01:00
|
|
|
/** @} */
|