[388] | 1 | /**
|
---|
| 2 | * @file ntshell.h
|
---|
| 3 | * @author CuBeatSystems
|
---|
| 4 | * @author Shinichiro Nakamura
|
---|
| 5 | * @copyright
|
---|
| 6 | * ===============================================================
|
---|
| 7 | * Natural Tiny Shell (NT-Shell) Version 0.3.1
|
---|
| 8 | * ===============================================================
|
---|
| 9 | * Copyright (c) 2010-2016 Shinichiro Nakamura
|
---|
| 10 | *
|
---|
| 11 | * Permission is hereby granted, free of charge, to any person
|
---|
| 12 | * obtaining a copy of this software and associated documentation
|
---|
| 13 | * files (the "Software"), to deal in the Software without
|
---|
| 14 | * restriction, including without limitation the rights to use,
|
---|
| 15 | * copy, modify, merge, publish, distribute, sublicense, and/or
|
---|
| 16 | * sell copies of the Software, and to permit persons to whom the
|
---|
| 17 | * Software is furnished to do so, subject to the following
|
---|
| 18 | * conditions:
|
---|
| 19 | *
|
---|
| 20 | * The above copyright notice and this permission notice shall be
|
---|
| 21 | * included in all copies or substantial portions of the Software.
|
---|
| 22 | *
|
---|
| 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
---|
| 24 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
---|
| 25 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
---|
| 26 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
---|
| 27 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
---|
| 28 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
---|
| 29 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
---|
| 30 | * OTHER DEALINGS IN THE SOFTWARE.
|
---|
| 31 | */
|
---|
| 32 |
|
---|
| 33 | #ifndef NTSHELL_H
|
---|
| 34 | #define NTSHELL_H
|
---|
| 35 |
|
---|
| 36 | #include "vtrecv.h"
|
---|
| 37 | #include "vtsend.h"
|
---|
| 38 | #include "text_editor.h"
|
---|
| 39 | #include "text_history.h"
|
---|
| 40 |
|
---|
| 41 | #define NTSHELL_PROMPT_MAXLEN (32)
|
---|
| 42 | #define NTSHELL_PROMPT_DEFAULT ">"
|
---|
| 43 | #define NTSHELL_PROMPT_NEWLINE "\r\n"
|
---|
| 44 |
|
---|
| 45 | typedef int (*NTSHELL_SERIAL_READ)(char *buf, int cnt, void *extobj);
|
---|
| 46 | typedef int (*NTSHELL_SERIAL_WRITE)(const char *buf, int cnt, void *extobj);
|
---|
| 47 | typedef int (*NTSHELL_USER_CALLBACK)(const char *text, void *extobj);
|
---|
| 48 |
|
---|
| 49 | /**
|
---|
| 50 | * @brief The handler of NT-Shell.
|
---|
| 51 | * @details
|
---|
| 52 | * The best way to provide a handler, We should hide the implementation from the library users.
|
---|
| 53 | * But some small embedded environments can not use memory allocation dynamically.
|
---|
| 54 | * So this implementation open the fields of the handler in this header.
|
---|
| 55 | * You can use this handler on the stacks.
|
---|
| 56 | */
|
---|
| 57 | typedef struct {
|
---|
| 58 | unsigned int initcode; /**< Initialization flag. */
|
---|
| 59 | vtsend_t vtsend; /**< The handler of vtsend. */
|
---|
| 60 | vtrecv_t vtrecv; /**< The handler of vtrecv. */
|
---|
| 61 | text_editor_t editor; /**< The handler of text_editor. */
|
---|
| 62 | text_history_t history; /**< The handler of text_history. */
|
---|
| 63 | int suggest_index;
|
---|
| 64 | char suggest_source[TEXTEDITOR_MAXLEN];
|
---|
| 65 | NTSHELL_SERIAL_READ func_read;
|
---|
| 66 | NTSHELL_SERIAL_WRITE func_write;
|
---|
| 67 | NTSHELL_USER_CALLBACK func_callback;
|
---|
| 68 | void *extobj;
|
---|
| 69 | char prompt[NTSHELL_PROMPT_MAXLEN];
|
---|
| 70 | } ntshell_t;
|
---|
| 71 |
|
---|
| 72 | #ifdef __cplusplus
|
---|
| 73 | extern "C" {
|
---|
| 74 | #endif
|
---|
| 75 |
|
---|
| 76 | void ntshell_init(ntshell_t *p,
|
---|
| 77 | NTSHELL_SERIAL_READ func_read,
|
---|
| 78 | NTSHELL_SERIAL_WRITE func_write,
|
---|
| 79 | NTSHELL_USER_CALLBACK func_callback,
|
---|
| 80 | void *extobj);
|
---|
| 81 | void ntshell_execute(ntshell_t *p);
|
---|
| 82 | void ntshell_set_prompt(ntshell_t *p, const char *prompt);
|
---|
| 83 | void ntshell_version(int *major, int *minor, int *release);
|
---|
| 84 |
|
---|
| 85 | #ifdef __cplusplus
|
---|
| 86 | }
|
---|
| 87 | #endif
|
---|
| 88 |
|
---|
| 89 | #endif
|
---|
| 90 |
|
---|