dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

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

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