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