nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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