Blame SOURCES/0023-grub-core-term-terminfo.c-Recognize-keys-F1-F12.patch

a85e8e
From 59a8ad9fb81ae9dc665a153242a580e51c2fc9b1 Mon Sep 17 00:00:00 2001
a85e8e
From: Vladimir Serbinenko <phcoder@gmail.com>
a85e8e
Date: Sat, 18 Jan 2014 16:57:35 +0100
a85e8e
Subject: [PATCH 023/260] * grub-core/term/terminfo.c: Recognize keys F1-F12.
a85e8e
a85e8e
---
a85e8e
 ChangeLog                 |  4 +++
a85e8e
 grub-core/term/terminfo.c | 86 +++++++++++++++++++++++++++--------------------
a85e8e
 2 files changed, 54 insertions(+), 36 deletions(-)
a85e8e
a85e8e
diff --git a/ChangeLog b/ChangeLog
a85e8e
index 9c3ef2e21..bdfbf44da 100644
a85e8e
--- a/ChangeLog
a85e8e
+++ b/ChangeLog
a85e8e
@@ -1,3 +1,7 @@
a85e8e
+2014-01-18  Vladimir Serbinenko  <phcoder@gmail.com>
a85e8e
+
a85e8e
+	* grub-core/term/terminfo.c: Recognize keys F1-F12.
a85e8e
+
a85e8e
 2014-01-07  Andrey Borzenkov <arvidjaar@gmail.com>
a85e8e
 
a85e8e
 	* configure.ac: Add support for BUILD_LDFLAGS.
a85e8e
diff --git a/grub-core/term/terminfo.c b/grub-core/term/terminfo.c
a85e8e
index 3d48b198f..f0d3e3deb 100644
a85e8e
--- a/grub-core/term/terminfo.c
a85e8e
+++ b/grub-core/term/terminfo.c
a85e8e
@@ -460,28 +460,31 @@ grub_terminfo_readkey (struct grub_term_input *term, int *keys, int *len,
a85e8e
 	{'@', GRUB_TERM_KEY_INSERT},
a85e8e
       };
a85e8e
 
a85e8e
-    static struct
a85e8e
-    {
a85e8e
-      char key;
a85e8e
-      unsigned ascii;
a85e8e
-    }
a85e8e
-    four_code_table[] =
a85e8e
+    static unsigned four_code_table[] =
a85e8e
       {
a85e8e
-	{'1', GRUB_TERM_KEY_HOME},
a85e8e
-	{'3', GRUB_TERM_KEY_DC},
a85e8e
-	{'5', GRUB_TERM_KEY_PPAGE},
a85e8e
-	{'6', GRUB_TERM_KEY_NPAGE},
a85e8e
-	{'7', GRUB_TERM_KEY_HOME},
a85e8e
-	{'8', GRUB_TERM_KEY_END}
a85e8e
+	[1] = GRUB_TERM_KEY_HOME,
a85e8e
+	[3] = GRUB_TERM_KEY_DC,
a85e8e
+	[5] = GRUB_TERM_KEY_PPAGE,
a85e8e
+	[6] = GRUB_TERM_KEY_NPAGE,
a85e8e
+	[7] = GRUB_TERM_KEY_HOME,
a85e8e
+	[8] = GRUB_TERM_KEY_END,
a85e8e
+	[17] = GRUB_TERM_KEY_F6,
a85e8e
+	[18] = GRUB_TERM_KEY_F7,
a85e8e
+	[19] = GRUB_TERM_KEY_F8,
a85e8e
+	[20] = GRUB_TERM_KEY_F9,
a85e8e
+	[21] = GRUB_TERM_KEY_F10,
a85e8e
+	[23] = GRUB_TERM_KEY_F11,
a85e8e
+	[24] = GRUB_TERM_KEY_F12,
a85e8e
       };
a85e8e
     char fx_key[] = 
a85e8e
       { 'P', 'Q', 'w', 'x', 't', 'u',
a85e8e
-        'q', 'r', 'p', 'M', 'A', 'B' };
a85e8e
+        'q', 'r', 'p', 'M', 'A', 'B', 'H', 'F' };
a85e8e
     unsigned fx_code[] = 
a85e8e
 	{ GRUB_TERM_KEY_F1, GRUB_TERM_KEY_F2, GRUB_TERM_KEY_F3,
a85e8e
 	  GRUB_TERM_KEY_F4, GRUB_TERM_KEY_F5, GRUB_TERM_KEY_F6,
a85e8e
 	  GRUB_TERM_KEY_F7, GRUB_TERM_KEY_F8, GRUB_TERM_KEY_F9,
a85e8e
-	  GRUB_TERM_KEY_F10, GRUB_TERM_KEY_F11, GRUB_TERM_KEY_F12 };
a85e8e
+	  GRUB_TERM_KEY_F10, GRUB_TERM_KEY_F11, GRUB_TERM_KEY_F12,
a85e8e
+	  GRUB_TERM_KEY_HOME, GRUB_TERM_KEY_END };
a85e8e
     unsigned i;
a85e8e
 
a85e8e
     if (c == '\e')
a85e8e
@@ -492,19 +495,13 @@ grub_terminfo_readkey (struct grub_term_input *term, int *keys, int *len,
a85e8e
 	  {
a85e8e
 	    CONTINUE_READ;
a85e8e
 
a85e8e
-	    switch (c)
a85e8e
-	      {
a85e8e
-	      case 'H':
a85e8e
-		keys[0] = GRUB_TERM_KEY_HOME;
a85e8e
-		*len = 1;
a85e8e
-		return;
a85e8e
-	      case 'F':
a85e8e
-		keys[0] = GRUB_TERM_KEY_END;
a85e8e
-		*len = 1;
a85e8e
-		return;
a85e8e
-	      default:
a85e8e
-		return;
a85e8e
-	      }
a85e8e
+	    for (i = 0; i < ARRAY_SIZE (fx_key); i++)
a85e8e
+	      if (fx_key[i] == c)
a85e8e
+		{
a85e8e
+		  keys[0] = fx_code[i];
a85e8e
+		  *len = 1;
a85e8e
+		  return;
a85e8e
+		}
a85e8e
 	  }
a85e8e
 
a85e8e
 	if (c != '[')
a85e8e
@@ -523,6 +520,15 @@ grub_terminfo_readkey (struct grub_term_input *term, int *keys, int *len,
a85e8e
 
a85e8e
     switch (c)
a85e8e
       {
a85e8e
+      case '[':
a85e8e
+	CONTINUE_READ;
a85e8e
+	if (c >= 'A' && c <= 'E')
a85e8e
+	  {
a85e8e
+	    keys[0] = GRUB_TERM_KEY_F1 + c - 'A';
a85e8e
+	    *len = 1;
a85e8e
+	    return;
a85e8e
+	  }
a85e8e
+	return;
a85e8e
       case 'O':
a85e8e
 	CONTINUE_READ;
a85e8e
 	for (i = 0; i < ARRAY_SIZE (fx_key); i++)
a85e8e
@@ -555,18 +561,26 @@ grub_terminfo_readkey (struct grub_term_input *term, int *keys, int *len,
a85e8e
 	  return;
a85e8e
 	}	  
a85e8e
 
a85e8e
-      default:
a85e8e
-	for (i = 0; i < ARRAY_SIZE (four_code_table); i++)
a85e8e
-	  if (four_code_table[i].key == c)
a85e8e
+      case '1' ... '9':
a85e8e
+	{
a85e8e
+	  unsigned val = c - '0';
a85e8e
+	  CONTINUE_READ;
a85e8e
+	  if (c >= '0' && c <= '9')
a85e8e
 	    {
a85e8e
+	      val = val * 10 + (c - '0');
a85e8e
 	      CONTINUE_READ;
a85e8e
-	      if (c != '~')
a85e8e
-		return;
a85e8e
-	      keys[0] = four_code_table[i].ascii;
a85e8e
-	      *len = 1;
a85e8e
-	      return;
a85e8e
 	    }
a85e8e
-	return;
a85e8e
+	  if (c != '~')
a85e8e
+	    return;
a85e8e
+	  if (val >= ARRAY_SIZE (four_code_table)
a85e8e
+	      || four_code_table[val] == 0)
a85e8e
+	    return;
a85e8e
+	  keys[0] = four_code_table[val];
a85e8e
+	  *len = 1;
a85e8e
+	  return;
a85e8e
+	}
a85e8e
+	default:
a85e8e
+	  return;
a85e8e
       }
a85e8e
   }
a85e8e
 #undef CONTINUE_READ
a85e8e
-- 
a85e8e
2.13.0
a85e8e