123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- #ifndef SHELL_H
- #define SHELL_H
- #if defined(SHELL_CONFIG_FILE)
- #include "shellconf.h"
- #endif
- #define SHELL_HIST_DIR_BK 0
- #define SHELL_HIST_DIR_FW 1
- #if !defined(SHELL_MAX_LINE_LENGTH) || defined(__DOXYGEN__)
- #define SHELL_MAX_LINE_LENGTH 64
- #endif
- #if !defined(SHELL_MAX_ARGUMENTS) || defined(__DOXYGEN__)
- #define SHELL_MAX_ARGUMENTS 4
- #endif
- #if !defined(SHELL_MAX_HIST_BUFF) || defined(__DOXYGEN__)
- #define SHELL_MAX_HIST_BUFF 8 * SHELL_MAX_LINE_LENGTH
- #endif
- #if !defined(SHELL_USE_HISTORY) || defined(__DOXYGEN__)
- #define SHELL_USE_HISTORY FALSE
- #endif
- #if !defined(SHELL_USE_COMPLETION) || defined(__DOXYGEN__)
- #define SHELL_USE_COMPLETION FALSE
- #endif
- #if !defined(SHELL_MAX_COMPLETIONS) || defined(__DOXYGEN__)
- #define SHELL_MAX_COMPLETIONS 8
- #endif
- #if !defined(SHELL_USE_ESC_SEQ) || defined(__DOXYGEN__)
- #define SHELL_USE_ESC_SEQ FALSE
- #endif
- #if !defined(SHELL_PROMPT_STR) || defined(__DOXYGEN__)
- #define SHELL_PROMPT_STR "ch> "
- #endif
- #if !defined(SHELL_NEWLINE_STR) || defined(__DOXYGEN__)
- #define SHELL_NEWLINE_STR "\r\n"
- #endif
- typedef void (*shellcmd_t)(BaseSequentialStream *chp, int argc, char *argv[]);
- typedef struct {
- const char *sc_name;
- shellcmd_t sc_function;
- } ShellCommand;
- typedef struct {
- char *sh_buffer;
- const int sh_size;
- int sh_beg;
- int sh_end;
- int sh_cur;
- } ShellHistory;
- typedef struct {
- BaseSequentialStream *sc_channel;
- const ShellCommand *sc_commands;
- #if (SHELL_USE_HISTORY == TRUE) || defined(__DOXYGEN__)
- char *sc_histbuf;
- const int sc_histsize;
- #endif
- #if (SHELL_USE_COMPLETION == TRUE) || defined(__DOXYGEN__)
- char **sc_completion;
- #endif
- } ShellConfig;
- #define _shell_reset_cur(stream) chprintf(stream, "\033[%dD\033[%dC", \
- SHELL_MAX_LINE_LENGTH + \
- strlen(SHELL_PROMPT_STR) + 2, \
- strlen(SHELL_PROMPT_STR))
- #define _shell_clr_line(stream) chprintf(stream, "\033[K")
- #define shellUsage(stream, message) \
- chprintf(stream, "Usage: %s" SHELL_NEWLINE_STR, message)
- #if !defined(__DOXYGEN__)
- extern event_source_t shell_terminated;
- #endif
- #ifdef __cplusplus
- extern "C" {
- #endif
- void shellInit(void);
- THD_FUNCTION(shellThread, p);
- void shellExit(msg_t msg);
- bool shellGetLine(ShellConfig *scfg, char *line,
- unsigned size, ShellHistory *shp);
- #ifdef __cplusplus
- }
- #endif
- #endif
|