]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Macroify GRUB_TERM_NO_KEY and use grub_checkkey in grub_getkey
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Mon, 23 Aug 2010 10:53:42 +0000 (12:53 +0200)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Mon, 23 Aug 2010 10:53:42 +0000 (12:53 +0200)
include/grub/term.h
kern/i386/pc/startup.S
kern/term.c
term/at_keyboard.c
term/efi/console.c
term/terminfo.c
term/usb_keyboard.c

index 4289781429c294ab7d365c0cc7cfff1228befb09..81c18365c4af6042ad40c7c9f78c5aba5cf396f1 100644 (file)
@@ -19,6 +19,8 @@
 #ifndef GRUB_TERM_HEADER
 #define GRUB_TERM_HEADER       1
 
+#define GRUB_TERM_NO_KEY        -1
+
 /* Internal codes used by GRUB to represent terminal input.  */
 /* Only for keys otherwise not having shifted modification.  */
 #define GRUB_TERM_SHIFT         0x01000000
index 2d726415612231ef2112efd9f055e9a48e6ea645..5a6934dee35997e4b9137c377d78df8638086ed9 100644 (file)
@@ -1226,6 +1226,9 @@ notpending:
        .code16
        DATA32  call    real_to_prot
        .code32
+#if GRUB_TERM_NO_KEY != -1
+#error Fix this asm code
+#endif
        decl %eax
        jmp 2b
 
index a05325346911bc84b7a1316c076f760962e13182..9d23b4f91b61b4df5087ff73fa26f242d5bae71b 100644 (file)
@@ -78,43 +78,14 @@ grub_xputs_dumb (const char *str)
 
 void (*grub_xputs) (const char *str) = grub_xputs_dumb;
 
-static int pending_key = -1;
-
-int
-grub_getkey (void)
-{
-  grub_term_input_t term;
-
-  grub_refresh ();
-
-  if (pending_key != -1)
-    {
-      pending_key = -1;
-      return pending_key;
-    }
-
-  while (1)
-    {
-      if (grub_term_poll_usb)
-       grub_term_poll_usb ();
-
-      FOR_ACTIVE_TERM_INPUTS(term)
-      {
-       int key = term->getkey (term);
-       if (key != -1)
-         return key;
-      }
-
-      grub_cpu_idle ();
-    }
-}
+static int pending_key = GRUB_TERM_NO_KEY;
 
 int
 grub_checkkey (void)
 {
   grub_term_input_t term;
 
-  if (pending_key != -1)
+  if (pending_key != GRUB_TERM_NO_KEY)
     return pending_key;
 
   if (grub_term_poll_usb)
@@ -123,13 +94,28 @@ grub_checkkey (void)
   FOR_ACTIVE_TERM_INPUTS(term)
   {
     pending_key = term->getkey (term);
-    if (pending_key != -1)
+    if (pending_key != GRUB_TERM_NO_KEY)
       return pending_key;
   }
 
   return -1;
 }
 
+int
+grub_getkey (void)
+{
+  grub_refresh ();
+
+  while (pending_key != GRUB_TERM_NO_KEY)
+    {
+      grub_cpu_idle ();
+      grub_checkkey ();
+    }
+  pending_key = GRUB_TERM_NO_KEY;
+  return pending_key;
+}
+
+
 void
 grub_refresh (void)
 {
index 6ea908a2b71a50cc5fa36c0846d06bb60c6504fd..681dd3ef9763ba1dbb527b539d93b807273b9f8c 100644 (file)
@@ -475,14 +475,15 @@ grub_keyboard_getkey (void)
   return key;
 }
 
-/* If there is a character pending, return it; otherwise return -1.  */
+/* If there is a character pending, return it;
+   otherwise return GRUB_TERM_NO_KEY.  */
 static int
 grub_at_keyboard_getkey (struct grub_term_input *term __attribute__ ((unused)))
 {
   int code;
   code = grub_keyboard_getkey ();
   if (code == -1)
-    return -1;
+    return GRUB_TERM_NO_KEY;
 #ifdef DEBUG_AT_KEYBOARD
   grub_dprintf ("atkeyb", "Detected key 0x%x\n", key);
 #endif
@@ -496,7 +497,7 @@ grub_at_keyboard_getkey (struct grub_term_input *term __attribute__ ((unused)))
 #ifdef DEBUG_AT_KEYBOARD
        grub_dprintf ("atkeyb", "caps_lock = %d\n", !!(at_keyboard_status & KEYBOARD_STATUS_CAPS_LOCK));
 #endif
-       return -1;
+       return GRUB_TERM_NO_KEY;
       case GRUB_KEYBOARD_KEY_NUM_LOCK:
        at_keyboard_status ^= GRUB_TERM_STATUS_NUM;
        led_status ^= KEYBOARD_LED_NUM;
@@ -505,12 +506,12 @@ grub_at_keyboard_getkey (struct grub_term_input *term __attribute__ ((unused)))
 #ifdef DEBUG_AT_KEYBOARD
        grub_dprintf ("atkeyb", "num_lock = %d\n", !!(at_keyboard_status & KEYBOARD_STATUS_NUM_LOCK));
 #endif
-       return -1;
+       return GRUB_TERM_NO_KEY;
       case GRUB_KEYBOARD_KEY_SCROLL_LOCK:
        at_keyboard_status ^= GRUB_TERM_STATUS_SCROLL;
        led_status ^= KEYBOARD_LED_SCROLL;
        keyboard_controller_led (led_status);
-       return -1;
+       return GRUB_TERM_NO_KEY;
       default:
        return grub_term_map_key (code, at_keyboard_status);
     }
index 97fefd9819c4b277a523d0b2a7e10f515448bd10..1667bcd4f10ae89b30a3024ce0cf512d7fad9b68 100644 (file)
@@ -120,14 +120,14 @@ grub_console_getkey (struct grub_term_input *term __attribute__ ((unused)))
   status = efi_call_2 (i->read_key_stroke, i, &key);
 
   if (status != GRUB_EFI_SUCCESS)
-    return -1;
+    return GRUB_TERM_NO_KEY;
 
   if (key.scan_code == 0)
     return key.unicode_char;
   else if (key.scan_code < ARRAY_SIZE (efi_codes))
     return efi_codes[key.scan_code];
 
-  return -1;
+  return GRUB_TERM_NO_KEY;
 }
 
 static grub_uint16_t
index d2d821449e9f047b0b40064245547fc5ae4e2d50..8dea7aea1565a3873b6898bff078f0bb3ab5a0dc 100644 (file)
@@ -490,7 +490,7 @@ grub_terminfo_getkey (struct grub_term_input *termi)
       return data->input_buf[0];
     }
 
-  return -1;
+  return GRUB_TERM_NO_KEY;
 }
 
 grub_err_t
index ca3a81179e8de8d1b1a4416cbc4a3784e447a8d1..6b1485e96d0430f507aaa05377f05abbc9506f40 100644 (file)
@@ -279,7 +279,7 @@ grub_usb_keyboard_getkey (struct grub_term_input *term)
   grub_size_t actual;
 
   if (termdata->dead)
-    return -1;
+    return GRUB_TERM_NO_KEY;
 
   /* Poll interrupt pipe.  */
   err = grub_usb_check_transfer (termdata->transfer, &actual);
@@ -293,7 +293,7 @@ grub_usb_keyboard_getkey (struct grub_term_input *term)
            + GRUB_TERM_REPEAT_INTERVAL;
          return termdata->last_key;
        }
-      return -1;
+      return GRUB_TERM_NO_KEY;
     }
 
   grub_memcpy (data, termdata->report, sizeof (data));
@@ -318,29 +318,29 @@ grub_usb_keyboard_getkey (struct grub_term_input *term)
                data[4], data[5], data[6], data[7]);
 
   if (err || actual < 1)
-    return -1;
+    return GRUB_TERM_NO_KEY;
 
   termdata->status = data[0];
 
   if (actual < 3)
-    return -1;
+    return GRUB_TERM_NO_KEY;
 
   if (data[2] == KEY_NO_KEY || data[2] == KEY_ERR_BUFFER
       || data[2] == KEY_ERR_POST || data[2] == KEY_ERR_UNDEF)
-    return -1;
+    return GRUB_TERM_NO_KEY;
 
   if (data[2] == KEY_CAPS_LOCK)
     {
       termdata->mods ^= GRUB_TERM_STATUS_CAPS;
       send_leds (termdata);
-      return -1;
+      return GRUB_TERM_NO_KEY;
     }
 
   if (data[2] == KEY_NUM_LOCK)
     {
       termdata->mods ^= GRUB_TERM_STATUS_NUM;
       send_leds (termdata);
-      return -1;
+      return GRUB_TERM_NO_KEY;
     }
 
   termdata->last_key = grub_term_map_key (data[2], interpret_status (data[0])