texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[5694] skip unrecognized keys in input


From: Gavin D. Smith
Subject: [5694] skip unrecognized keys in input
Date: Tue, 01 Jul 2014 17:23:39 +0000

Revision: 5694
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=5694
Author:   gavin
Date:     2014-07-01 17:23:37 +0000 (Tue, 01 Jul 2014)
Log Message:
-----------
skip unrecognized keys in input

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/info/session.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2014-07-01 12:38:52 UTC (rev 5693)
+++ trunk/ChangeLog     2014-07-01 17:23:37 UTC (rev 5694)
@@ -1,5 +1,11 @@
 2014-07-01  Gavin Smith  <address@hidden>
 
+       * info/session.c (get_input_key): Try to ignore sequences in the input
+       stream produced by unrecognized keys.
+       (get_input_key, get_input_key_internal): Wrapper around get_input_key.
+
+2014-07-01  Gavin Smith  <address@hidden>
+
        * info/pseudotty.c: Read bytes from file descriptor 3 and feed into
        master side of pseudoterminal.
        * info/t/Init-intera.inc, info/t/Init-inter.inc: File renamed.  Create

Modified: trunk/info/session.c
===================================================================
--- trunk/info/session.c        2014-07-01 12:38:52 UTC (rev 5693)
+++ trunk/info/session.c        2014-07-01 17:23:37 UTC (rev 5694)
@@ -462,12 +462,24 @@
   return 1;
 }
 
+static int get_input_key_internal (void);
+
 /* Return number representing a key that has been pressed, which is an index
-   into info_keymap and echo_area_keymap.  Return -1 if no key has been
-   pressed. */
+   into info_keymap and echo_area_keymap. */
 int
 get_input_key (void)
 {
+  int ret = -1;
+
+  while (ret == -1)
+    ret = get_input_key_internal ();
+}
+
+/* Read bytes from input and return what key has been pressed.  Return -1 on
+   reading an unrecognized key. */
+static int
+get_input_key_internal (void)
+{
   BYTEMAP_ENTRY *b;
   unsigned char c;
   int esc_seen;
@@ -486,6 +498,7 @@
   while (pop_index != push_index)
     {
       int in_map = 0;
+      int unknown = 0;
       if (!get_byte_from_input_buffer (&c))
         break; /* Incomplete byte sequence. */
 
@@ -502,9 +515,13 @@
           b = b[c].next;
           break;
         case BYTEMAP_NONE:
+          unknown = 1;
           break;
         }
 
+      if (unknown)
+        break;
+
       /* If we read an incomplete byte sequence, pause a short while to
          see if more bytes follow.  We should probably allow the length
          of this delay to be settable by the user. */
@@ -522,22 +539,20 @@
           ready = select (fileno(info_input_stream)+1, &readfds,
                           NULL, NULL, &timer);
 #else
-              ready = 1;
+          ready = 1;
 #endif /* FD_SET */
           if (ready)
             fill_input_buffer (0);
         }
     }
 
-  if (esc_seen)
+  if (!esc_seen)
+    /* If the sequence was incomplete, return the first byte. */
+    return first;
+  else
     {
-      /* The sequence started with ESC, but wasn't recognized.  Treat it
-         as introducing a sequence produced by a key chord with the meta key
-         pressed. */
-
       /* Start again with the first key after ESC. */
       pop_index = pop_start;
-      b = byte_seq_to_key;
 
       /* If there are no more characters, then decide that the escape key
          itself has been pressed. */
@@ -547,32 +562,52 @@
       /* Save the first byte waiting in the input buffer. */
       first = info_input_buffer[pop_index];
 
-      while (pop_index != push_index)
+      /* Skip byte sequences that look like they could have come from
+         unrecognized keys, e.g. F3 or C-S-Left, to avoid them as being
+         interpreted as random garbage.  These might produce sequences
+         that look like "ESC O R" or "ESC [ 1 ; 6 ~", depending on
+         the terminal. */
+
+      /* Check if the sequence starts ESC O. */
+      get_byte_from_input_buffer (&c);
+      if (c == 'O')
         {
+          /* If no more bytes, call it M-O. */
           if (!get_byte_from_input_buffer (&c))
-            break; /* Incomplete byte sequence. */
-          switch (b[c].type)
-            {
-            case BYTEMAP_KEY:
-              return b[c].key + KEYMAP_META_BASE;
-            case BYTEMAP_MAP:
-              b = b[c].next;
+            return 'O' + KEYMAP_META_BASE;
+
+          /* Otherwise it could be an unrecognized key producing a sequence
+             ESC O (byte).  Ignore it. */
+          return -1;
+        }
+
+      /* Unknown CSI-style sequences. */
+      else if (c == '[')
+        {
+          /* If no more bytes, call it M-[. */
+          if (!get_byte_from_input_buffer (&c))
+            return '[' + KEYMAP_META_BASE;
+
+          /* Skip a control sequence as defined by ECMA-48. */
+          while (c >= 0x30 && c <= 0x3f)
+            if (!get_byte_from_input_buffer (&c))
               break;
-            case BYTEMAP_ESC:
-              /* This could happen if there were two escapes in a row, or
-                 if the user types something like M-Left. */
-              b = b[c].next;
+
+          while (c >= 0x20 && c <= 0x2f)
+            if (!get_byte_from_input_buffer (&c))
               break;
-            case BYTEMAP_NONE:
-              break;
-            }
+
+          return -1;
         }
-      /* If the sequence was incomplete. */
-      return first + KEYMAP_META_BASE;
+
+      else
+        {
+          /* The sequence started with ESC, but wasn't recognized.  Treat it
+             as introducing a sequence produced by a key chord with the meta
+             key pressed. */
+          return c + KEYMAP_META_BASE;
+        }
     }
-
-  /* If the sequence was incomplete, return the first byte. */
-  return first;
 }
 
 /* **************************************************************** */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]