OSDN Git Service

Added NT modules.
[bluetank/bluetank.git] / firm / bare_metal / common / ntshell / vtrecv.h
1 /**
2  * @file vtrecv.h
3  * @brief VT100互換の受信用パーサの定義。
4  * @details
5  * An implementation of Paul Williams' DEC compatible state machine parser
6  * This code is in the public domain.
7  *
8  * @author Joshua Haberman <joshua@reverberate.org>
9  * @author Shinichiro Nakamura : Modified for Natural Tiny Shell (NT-Shell)
10  */
11
12 #ifndef VTRECV_H
13 #define VTRECV_H
14
15 #define MAX_INTERMEDIATE_CHARS 2
16 #define ACTION(state_change) (vtrecv_action_t)(state_change & 0x0F)
17 #define STATE(state_change)  (vtrecv_state_t)(state_change >> 4)
18
19 typedef enum {
20     VTRECV_STATE_ANYWHERE = 0,
21     VTRECV_STATE_CSI_ENTRY = 1,
22     VTRECV_STATE_CSI_IGNORE = 2,
23     VTRECV_STATE_CSI_INTERMEDIATE = 3,
24     VTRECV_STATE_CSI_PARAM = 4,
25     VTRECV_STATE_DCS_ENTRY = 5,
26     VTRECV_STATE_DCS_IGNORE = 6,
27     VTRECV_STATE_DCS_INTERMEDIATE = 7,
28     VTRECV_STATE_DCS_PARAM = 8,
29     VTRECV_STATE_DCS_PASSTHROUGH = 9,
30     VTRECV_STATE_ESCAPE = 10,
31     VTRECV_STATE_ESCAPE_INTERMEDIATE = 11,
32     VTRECV_STATE_GROUND = 12,
33     VTRECV_STATE_OSC_STRING = 13,
34     VTRECV_STATE_SOS_PM_APC_STRING = 14,
35 } vtrecv_state_t;
36
37 typedef enum {
38     VTRECV_ACTION_CLEAR = 1,
39     VTRECV_ACTION_COLLECT = 2,
40     VTRECV_ACTION_CSI_DISPATCH = 3,
41     VTRECV_ACTION_ESC_DISPATCH = 4,
42     VTRECV_ACTION_EXECUTE = 5,
43     VTRECV_ACTION_HOOK = 6,
44     VTRECV_ACTION_IGNORE = 7,
45     VTRECV_ACTION_OSC_END = 8,
46     VTRECV_ACTION_OSC_PUT = 9,
47     VTRECV_ACTION_OSC_START = 10,
48     VTRECV_ACTION_PARAM = 11,
49     VTRECV_ACTION_PRINT = 12,
50     VTRECV_ACTION_PUT = 13,
51     VTRECV_ACTION_UNHOOK = 14,
52 } vtrecv_action_t;
53
54 typedef unsigned char state_change_t;
55
56 struct vtrecv;
57
58 typedef void (*vtrecv_callback_t)(struct vtrecv*, vtrecv_action_t, unsigned char);
59
60 typedef struct vtrecv {
61     vtrecv_state_t    state;
62     vtrecv_callback_t cb;
63     unsigned char      intermediate_chars[MAX_INTERMEDIATE_CHARS+1];
64     char               ignore_flagged;
65     int                params[16];
66     int                num_params;
67     void*              user_data;
68 } vtrecv_t;
69
70 void vtrecv_init(vtrecv_t *parser, vtrecv_callback_t cb);
71 void vtrecv_execute(vtrecv_t *parser, unsigned char *data, int len);
72
73 #endif
74