Mercurial > vim
comparison src/libvterm/src/parser.c @ 20498:55a373a243c0 v8.2.0803
patch 8.2.0803: libvterm code lags behind the upstream version
Commit: https://github.com/vim/vim/commit/83a52533b23c88f90be0dea01bc5e32ddadc1d6a
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed May 20 19:30:19 2020 +0200
patch 8.2.0803: libvterm code lags behind the upstream version
Problem: Libvterm code lags behind the upstream version.
Solution: Include revisions 764 - 767
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 20 May 2020 19:45:04 +0200 |
parents | 1d595fada804 |
children | a4652d7ec99f |
comparison
equal
deleted
inserted
replaced
20497:1f96d44df1a7 | 20498:55a373a243c0 |
---|---|
117 } | 117 } |
118 | 118 |
119 #define ENTER_STATE(st) do { vt->parser.state = st; string_start = NULL; } while(0) | 119 #define ENTER_STATE(st) do { vt->parser.state = st; string_start = NULL; } while(0) |
120 #define ENTER_NORMAL_STATE() ENTER_STATE(NORMAL) | 120 #define ENTER_NORMAL_STATE() ENTER_STATE(NORMAL) |
121 | 121 |
122 #define IS_STRING_STATE() (vt->parser.state >= OSC_COMMAND) | |
123 | |
122 for( ; pos < len; pos++) { | 124 for( ; pos < len; pos++) { |
123 unsigned char c = bytes[pos]; | 125 unsigned char c = bytes[pos]; |
124 int c1_allowed = !vt->mode.utf8; | 126 int c1_allowed = !vt->mode.utf8; |
125 size_t string_len; | 127 size_t string_len; |
126 | 128 |
127 if(c == 0x00 || c == 0x7f) { // NUL, DEL | 129 if(c == 0x00 || c == 0x7f) { // NUL, DEL |
128 if(vt->parser.state >= OSC) { | 130 if(IS_STRING_STATE()) { |
129 string_fragment(vt, string_start, bytes + pos - string_start, FALSE); | 131 string_fragment(vt, string_start, bytes + pos - string_start, FALSE); |
130 string_start = bytes + pos + 1; | 132 string_start = bytes + pos + 1; |
131 } | 133 } |
132 continue; | 134 continue; |
133 } | 135 } |
136 ENTER_NORMAL_STATE(); | 138 ENTER_NORMAL_STATE(); |
137 continue; | 139 continue; |
138 } | 140 } |
139 else if(c == 0x1b) { // ESC | 141 else if(c == 0x1b) { // ESC |
140 vt->parser.intermedlen = 0; | 142 vt->parser.intermedlen = 0; |
141 if(vt->parser.state < OSC) | 143 if(!IS_STRING_STATE()) |
142 vt->parser.state = NORMAL; | 144 vt->parser.state = NORMAL; |
143 vt->parser.in_esc = TRUE; | 145 vt->parser.in_esc = TRUE; |
144 continue; | 146 continue; |
145 } | 147 } |
146 else if(c == 0x07 && // BEL, can stand for ST in OSC or DCS state | 148 else if(c == 0x07 && // BEL, can stand for ST in OSC or DCS state |
147 vt->parser.state >= OSC) { | 149 IS_STRING_STATE()) { |
148 // fallthrough | 150 // fallthrough |
149 } | 151 } |
150 else if(c < 0x20) { // other C0 | 152 else if(c < 0x20) { // other C0 |
151 if(vterm_get_special_pty_type() == 2) { | 153 if(vterm_get_special_pty_type() == 2) { |
152 if(c == 0x08) // BS | 154 if(c == 0x08) // BS |
153 // Set the trick for BS output after a sequence, to delay backspace | 155 // Set the trick for BS output after a sequence, to delay backspace |
154 // activation | 156 // activation |
155 if(pos + 2 < len && bytes[pos + 1] == 0x20 && bytes[pos + 2] == 0x08) | 157 if(pos + 2 < len && bytes[pos + 1] == 0x20 && bytes[pos + 2] == 0x08) |
156 vt->in_backspace = 2; // Trigger when count down to 1 | 158 vt->in_backspace = 2; // Trigger when count down to 1 |
157 } | 159 } |
158 if(vt->parser.state >= OSC) | 160 if(IS_STRING_STATE()) |
159 string_fragment(vt, string_start, bytes + pos - string_start, FALSE); | 161 string_fragment(vt, string_start, bytes + pos - string_start, FALSE); |
160 do_control(vt, c); | 162 do_control(vt, c); |
161 if(vt->parser.state >= OSC) | 163 if(IS_STRING_STATE()) |
162 string_start = bytes + pos + 1; | 164 string_start = bytes + pos + 1; |
163 continue; | 165 continue; |
164 } | 166 } |
165 // else fallthrough | 167 // else fallthrough |
166 | 168 |
169 if(vt->parser.in_esc) { | 171 if(vt->parser.in_esc) { |
170 // Hoist an ESC letter into a C1 if we're not in a string mode | 172 // Hoist an ESC letter into a C1 if we're not in a string mode |
171 // Always accept ESC \ == ST even in string mode | 173 // Always accept ESC \ == ST even in string mode |
172 if(!vt->parser.intermedlen && | 174 if(!vt->parser.intermedlen && |
173 c >= 0x40 && c < 0x60 && | 175 c >= 0x40 && c < 0x60 && |
174 ((vt->parser.state < OSC || c == 0x5c))) { | 176 ((!IS_STRING_STATE() || c == 0x5c))) { |
175 c += 0x40; | 177 c += 0x40; |
176 c1_allowed = TRUE; | 178 c1_allowed = TRUE; |
177 string_len -= 1; | 179 string_len -= 1; |
178 vt->parser.in_esc = FALSE; | 180 vt->parser.in_esc = FALSE; |
179 } | 181 } |
258 break; | 260 break; |
259 } | 261 } |
260 | 262 |
261 /* else fallthrough */ | 263 /* else fallthrough */ |
262 string_start = bytes + pos; | 264 string_start = bytes + pos; |
265 string_len = 0; | |
263 vt->parser.state = OSC; | 266 vt->parser.state = OSC; |
264 goto string_state; | 267 goto string_state; |
265 | 268 |
266 case DCS_COMMAND: | 269 case DCS_COMMAND: |
267 if(vt->parser.v.dcs.commandlen < CSI_LEADER_MAX) | 270 if(vt->parser.v.dcs.commandlen < CSI_LEADER_MAX) |
310 ENTER_STATE(CSI_LEADER); | 313 ENTER_STATE(CSI_LEADER); |
311 break; | 314 break; |
312 case 0x9d: // OSC | 315 case 0x9d: // OSC |
313 vt->parser.v.osc.command = -1; | 316 vt->parser.v.osc.command = -1; |
314 vt->parser.string_initial = TRUE; | 317 vt->parser.string_initial = TRUE; |
318 string_start = bytes + pos + 1; | |
315 ENTER_STATE(OSC_COMMAND); | 319 ENTER_STATE(OSC_COMMAND); |
316 break; | 320 break; |
317 default: | 321 default: |
318 do_control(vt, c); | 322 do_control(vt, c); |
319 break; | 323 break; |