aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDavid Walter Seikel2014-02-01 14:57:08 +1000
committerDavid Walter Seikel2014-02-01 14:57:08 +1000
commit3715a176851a786c071e5bb18c00fbb80040ff04 (patch)
tree2ea4ac982d36638e2731e99b4538669463e88537
parentFix typo in key definitions. (diff)
downloadopensim-SC-3715a176851a786c071e5bb18c00fbb80040ff04.zip
opensim-SC-3715a176851a786c071e5bb18c00fbb80040ff04.tar.gz
opensim-SC-3715a176851a786c071e5bb18c00fbb80040ff04.tar.bz2
opensim-SC-3715a176851a786c071e5bb18c00fbb80040ff04.tar.xz
Smarten up the CSI parser a little.
-rw-r--r--handlekeys.c29
1 files changed, 13 insertions, 16 deletions
diff --git a/handlekeys.c b/handlekeys.c
index ea99d57..f1fe56c 100644
--- a/handlekeys.c
+++ b/handlekeys.c
@@ -287,20 +287,15 @@ void handle_keys(long extra,
287 if (pendingEsc) continue; 287 if (pendingEsc) continue;
288 288
289 // Check if it's a CSI before we check for the known key sequences. 289 // Check if it's a CSI before we check for the known key sequences.
290 if ('\x9B' == buffer[0]) 290 if ((('\x1B' == buffer[0]) && ('[' == buffer[1]))
291 csi = 1; 291 || (('\xC2' == buffer[0]) && ('\x9B' == buffer[1])))
292 if (('\x1B' == buffer[0]) && ('[' == buffer[1]))
293 csi = 2;
294 if (('\xC2' == buffer[0]) && ('\x9B' == buffer[1]))
295 csi = 2;
296 if (2 == csi)
297 { 292 {
298 buffer[0] = '\x9B'; 293 buffer[0] = '\x9B';
299 for (j = 1; buffer[j]; j++) 294 for (j = 1; buffer[j]; j++)
300 buffer[j] = buffer[j + 1]; 295 buffer[j] = buffer[j + 1];
301 buffIndex--; 296 buffIndex--;
302 csi = 1;
303 } 297 }
298 csi = ('\x9B' == buffer[0]);
304 299
305 // Check for known key sequences. 300 // Check for known key sequences.
306 // For a real timeout checked Esc, buffer is now empty, so this for loop 301 // For a real timeout checked Esc, buffer is now empty, so this for loop
@@ -347,6 +342,7 @@ void handle_keys(long extra,
347 { 342 {
348 // TODO - We have a mouse report, which is CSI M ..., where the rest is 343 // TODO - We have a mouse report, which is CSI M ..., where the rest is
349 // binary encoded, more or less. Not fitting into the CSI format. 344 // binary encoded, more or less. Not fitting into the CSI format.
345 // To make things worse, can't tell how long this will be.
350 } 346 }
351 else 347 else
352 { 348 {
@@ -397,16 +393,17 @@ void handle_keys(long extra,
397 } 393 }
398 while (t); 394 while (t);
399 395
400 // Get the final command sequence, and pass it to the callback. 396 // Check if we got the final byte, and send it to the callback.
401 strcat(csFinal, &buffer[csIndex]); 397 strcat(csFinal, &buffer[csIndex]);
402 if (handle_CSI) 398 t = csFinal + strlen(csFinal) - 1;
403 handle_CSI(extra, csFinal, csParams, p); 399 if (('\x40' <= (*t)) && ((*t) <= '\x7e'))
400 {
401 if (handle_CSI)
402 handle_CSI(extra, csFinal, csParams, p);
403 buffer[0] = buffIndex = 0;
404 sequence[0] = 0;
405 }
404 } 406 }
405
406 csi = 0;
407 // Wether or not it's a CSI we understand, it's been handled either here
408 // or in the key sequence scanning above.
409 buffer[0] = buffIndex = 0;
410 } 407 }
411 408
412 // Pass the result to the callback. 409 // Pass the result to the callback.