1 | /**
|
---|
2 | * @file vtrecv.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 | /*
|
---|
34 | * @note
|
---|
35 | * An implementation of Paul Williams' DEC compatible state machine parser.
|
---|
36 | * This code is in the public domain.
|
---|
37 | *
|
---|
38 | * @author Joshua Haberman <joshua@reverberate.org>
|
---|
39 | * @author Shinichiro Nakamura : Modified for Natural Tiny Shell (NT-Shell)
|
---|
40 | */
|
---|
41 |
|
---|
42 | #ifndef VTRECV_H
|
---|
43 | #define VTRECV_H
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * @brief ãªãªã¸ãã«ã«å«ã¾ããLUTã使ããã©ããã決å®ããã
|
---|
47 | * @details
|
---|
48 | * ãªãªã¸ãã«ã§ã¯ãã·ã¼ã±ã³ã¹ã®é·ç§»ããã¼ãã«åç
|
---|
49 | §ã§å®è£
|
---|
50 | ãã¦ãã£ãã
|
---|
51 | * 15ã®ã¹ãã¼ãã§åããã256ãã¿ã¼ã³ã®å
|
---|
52 | ¥åãå
|
---|
53 | ¨ç¶²ç¾
|
---|
54 | ãããã¼ãã«ã§ããã
|
---|
55 | * ããã¯3840åã®ãã¼ãã«ãã¼ã¿ãæã¤ãã¨ã«ãªãã
|
---|
56 | *
|
---|
57 | * ãã¼ãã«åç
|
---|
58 | §ã¯ã¡ã¢ãªã«å¯¾ãã¦ãªãã¢ã¢ã¯ã»ã¹å¯è½ãªããã»ããµã«ããã¦
|
---|
59 | * åºå®æéã§åä½ããããã¼ãã«åç
|
---|
60 | §ã®ã¡ãªããã¯åºå®æéã§ã®å¦çã§ããã
|
---|
61 | *
|
---|
62 | * ä¸æ¹ãæ°ãã«å®è£
|
---|
63 | ããæ¹æ³ã¯ãéè¤ãããã¼ã¿ãå¤æ°åå¨ããäºã«çç®ãã
|
---|
64 | * ãã®ã§ãåºéæ¯ã«é©ç¨ããã·ã¼ã±ã³ã¹ãå®ç¾©ãããã¼ãã«ãç¨ããã
|
---|
65 | * ããã¯ãã¼ãã«ãç·å½¢æ¢ç´¢ããããå¾æ¹ã«ãããã¼ã¿ã«ãªãã»ã©åä½ã¯é
|
---|
66 | ãã
|
---|
67 | * ããããã³ã¼ããµã¤ãºã¯ãªãªã¸ãã«ã®å
|
---|
68 | ¨ç¶²ç¾
|
---|
69 | å½¢å¼ã®ãã¼ãã«ãããå°ããã
|
---|
70 | *
|
---|
71 | * @retval 0 使ããªãã
|
---|
72 | * @retval 1 使ãã
|
---|
73 | */
|
---|
74 | #define USE_ORIGINAL_LUT (0)
|
---|
75 |
|
---|
76 | #define MAX_INTERMEDIATE_CHARS 2
|
---|
77 | #define ACTION(state_change) (vtrecv_action_t)((state_change & 0x0F) >> 0)
|
---|
78 | #define STATE(state_change) (vtrecv_state_t)((state_change & 0xF0) >> 4)
|
---|
79 |
|
---|
80 | typedef enum {
|
---|
81 | VTRECV_STATE_CSI_ENTRY = 1,
|
---|
82 | VTRECV_STATE_CSI_IGNORE = 2,
|
---|
83 | VTRECV_STATE_CSI_INTERMEDIATE = 3,
|
---|
84 | VTRECV_STATE_CSI_PARAM = 4,
|
---|
85 | VTRECV_STATE_DCS_ENTRY = 5,
|
---|
86 | VTRECV_STATE_DCS_IGNORE = 6,
|
---|
87 | VTRECV_STATE_DCS_INTERMEDIATE = 7,
|
---|
88 | VTRECV_STATE_DCS_PARAM = 8,
|
---|
89 | VTRECV_STATE_DCS_PASSTHROUGH = 9,
|
---|
90 | VTRECV_STATE_ESCAPE = 10,
|
---|
91 | VTRECV_STATE_ESCAPE_INTERMEDIATE = 11,
|
---|
92 | VTRECV_STATE_GROUND = 12,
|
---|
93 | VTRECV_STATE_OSC_STRING = 13,
|
---|
94 | VTRECV_STATE_SOS_PM_APC_STRING = 14,
|
---|
95 | } vtrecv_state_t;
|
---|
96 |
|
---|
97 | typedef enum {
|
---|
98 | VTRECV_ACTION_CLEAR = 1,
|
---|
99 | VTRECV_ACTION_COLLECT = 2,
|
---|
100 | VTRECV_ACTION_CSI_DISPATCH = 3,
|
---|
101 | VTRECV_ACTION_ESC_DISPATCH = 4,
|
---|
102 | VTRECV_ACTION_EXECUTE = 5,
|
---|
103 | VTRECV_ACTION_HOOK = 6,
|
---|
104 | VTRECV_ACTION_IGNORE = 7,
|
---|
105 | VTRECV_ACTION_OSC_END = 8,
|
---|
106 | VTRECV_ACTION_OSC_PUT = 9,
|
---|
107 | VTRECV_ACTION_OSC_START = 10,
|
---|
108 | VTRECV_ACTION_PARAM = 11,
|
---|
109 | VTRECV_ACTION_PRINT = 12,
|
---|
110 | VTRECV_ACTION_PUT = 13,
|
---|
111 | VTRECV_ACTION_UNHOOK = 14,
|
---|
112 | VTRECV_ACTION_ERROR = 15,
|
---|
113 | } vtrecv_action_t;
|
---|
114 |
|
---|
115 | typedef unsigned char state_change_t;
|
---|
116 | struct vtrecv;
|
---|
117 | typedef void (*vtrecv_callback_t)(struct vtrecv*, vtrecv_action_t, unsigned int);
|
---|
118 | typedef struct vtrecv {
|
---|
119 | int utf8_state;
|
---|
120 | unsigned int ch;
|
---|
121 | vtrecv_state_t state;
|
---|
122 | vtrecv_callback_t cb;
|
---|
123 | unsigned char intermediate_chars[MAX_INTERMEDIATE_CHARS+1];
|
---|
124 | int num_intermediate_chars;
|
---|
125 | char ignore_flagged;
|
---|
126 | int params[16];
|
---|
127 | int num_params;
|
---|
128 | void* user_data;
|
---|
129 | } vtrecv_t;
|
---|
130 |
|
---|
131 | #ifdef __cplusplus
|
---|
132 | extern "C" {
|
---|
133 | #endif
|
---|
134 |
|
---|
135 | void vtrecv_init(vtrecv_t *parser, vtrecv_callback_t cb);
|
---|
136 | void vtrecv_execute(vtrecv_t *parser, unsigned char *data, int len);
|
---|
137 |
|
---|
138 | #ifdef __cplusplus
|
---|
139 | }
|
---|
140 | #endif
|
---|
141 |
|
---|
142 | #endif
|
---|
143 |
|
---|