Hello,

This patch makes the grub_checkkey() function return
a boolean value (1 = a key is available, 0 = none).

I have tested it with play.mod, and it works OK.

Note that the grub_console_checkkey() function in
term/efi/console.c already (erroneously) assumed a
boolean value, so this patch automatically fixes that.

Cheers,
--
Andrew Apted  <[EMAIL PROTECTED]>
Index: ChangeLog
===================================================================
RCS file: /sources/grub/grub2/ChangeLog,v
retrieving revision 1.262
diff -u -r1.262 ChangeLog
--- ChangeLog   9 May 2006 20:11:11 -0000       1.262
+++ ChangeLog   12 May 2006 15:02:30 -0000
@@ -1,3 +1,16 @@
+2006-05-12  Andrew Apted <[EMAIL PROTECTED]>
+
+       * include/grub/term.h: changed API of grub_checkkey() to
+       return a boolean value (1 = key available, 0 = none).
+
+       * commands/i386/pc/play.c (grub_cmd_play): Likewise.
+       * kern/i386/pc/startup.S (grub_console_checkkey): Likewise.
+       * normal/menu.c (run_menu): Likewise.
+       * term/i386/pc/serial.c (grub_serial_checkkey): Likewise.
+       (serial_hw_init): Likewise.
+       * term/ieee1275/ofconsole.c (grub_ofconsole_checkkey): Likewise.
+       * util/console.c (grub_ncurses_checkkey): Likewise.
+
 2006-05-09  Vesa Jaaskelainen  <[EMAIL PROTECTED]>
 
        * video/i386/pc/vbe.c (grub_video_vbe_fill_rect): Corrected bounds
Index: commands/i386/pc/play.c
===================================================================
RCS file: /sources/grub/grub2/commands/i386/pc/play.c,v
retrieving revision 1.1
diff -u -r1.1 play.c
--- commands/i386/pc/play.c     3 Dec 2005 16:18:27 -0000       1.1
+++ commands/i386/pc/play.c     12 May 2006 15:02:30 -0000
@@ -186,7 +186,7 @@
 
   while (grub_file_read (file, (void *) &buf,
                          sizeof (struct note)) == sizeof (struct note)
-         && buf.pitch != T_FINE && grub_checkkey () < 0)
+         && buf.pitch != T_FINE && ! grub_checkkey ())
     {
       
       grub_dprintf ("play", "pitch = %d, duration = %d\n", buf.pitch,
@@ -204,7 +204,7 @@
         }
 
       to = grub_get_rtc () + BASE_TEMPO * buf.duration / tempo;
-      while (((unsigned int) grub_get_rtc () <= to) && (grub_checkkey () < 0))
+      while (((unsigned int) grub_get_rtc () <= to) && ! grub_checkkey ())
         ;
 
     }
@@ -213,7 +213,7 @@
 
   grub_file_close (file);
 
-  while (grub_checkkey () > 0)
+  while (grub_checkkey ())
     grub_getkey ();
 
   return 0;
Index: include/grub/term.h
===================================================================
RCS file: /sources/grub/grub2/include/grub/term.h,v
retrieving revision 1.10
diff -u -r1.10 term.h
--- include/grub/term.h 15 Oct 2005 09:22:31 -0000      1.10
+++ include/grub/term.h 12 May 2006 15:02:31 -0000
@@ -140,7 +140,8 @@
      encoded in Unicode.  */
   grub_ssize_t (*getcharwidth) (grub_uint32_t c);
   
-  /* Check if any input character is available.  */
+  /* Check if any input character is available.
+     The return value is boolean (1 = available, 0 = none).  */
   int (*checkkey) (void);
   
   /* Get a character.  */
Index: kern/i386/pc/startup.S
===================================================================
RCS file: /sources/grub/grub2/kern/i386/pc/startup.S,v
retrieving revision 1.22
diff -u -r1.22 startup.S
--- kern/i386/pc/startup.S      6 May 2006 22:33:51 -0000       1.22
+++ kern/i386/pc/startup.S      12 May 2006 15:02:33 -0000
@@ -1446,7 +1446,7 @@
 
 /*
  * int grub_console_checkkey (void)
- *     if there is a character pending, return it; otherwise return -1
+ *     if there is a character pending, return 1; otherwise return 0
  * BIOS call "INT 16H Function 01H" to check whether a character is pending
  *     Call with       %ah = 0x1
  *     Return:
@@ -1467,15 +1467,11 @@
        movb    $0x1, %ah
        int     $0x16
 
-       jz      notpending
+       jz      notpending
 
-       movw    %ax, %dx
-       DATA32  jmp     pending
+       incl    %edx
 
 notpending:
-       decl    %edx
-
-pending:
        DATA32  call    real_to_prot
        .code32
 
Index: normal/menu.c
===================================================================
RCS file: /sources/grub/grub2/normal/menu.c,v
retrieving revision 1.16
diff -u -r1.16 menu.c
--- normal/menu.c       7 May 2006 18:28:24 -0000       1.16
+++ normal/menu.c       12 May 2006 15:02:33 -0000
@@ -340,7 +340,7 @@
          return default_entry;
        }
       
-      if (grub_checkkey () >= 0 || timeout < 0)
+      if (grub_checkkey () || timeout < 0)
        {
          c = GRUB_TERM_ASCII_CHAR (grub_getkey ());
          
Index: term/i386/pc/serial.c
===================================================================
RCS file: /sources/grub/grub2/term/i386/pc/serial.c,v
retrieving revision 1.2
diff -u -r1.2 serial.c
--- term/i386/pc/serial.c       13 Nov 2005 15:47:09 -0000      1.2
+++ term/i386/pc/serial.c       12 May 2006 15:02:33 -0000
@@ -254,10 +254,7 @@
 static int
 grub_serial_checkkey (void)
 {
-  if (fill_input_buf (1))
-    return input_buf[0];
-  else
-    return -1;
+  return (fill_input_buf (1) > 0);
 }
 
 /* The serial version of getkey.  */
@@ -310,7 +307,7 @@
   outb (serial_settings.port + UART_MCR, UART_ENABLE_MODEM);
 
   /* Drain the input buffer.  */
-  while (grub_serial_checkkey () != -1)
+  while (grub_serial_checkkey ())
     (void) grub_serial_getkey ();
 
   /*  FIXME: should check if the serial terminal was found.  */
Index: term/ieee1275/ofconsole.c
===================================================================
RCS file: /sources/grub/grub2/term/ieee1275/ofconsole.c,v
retrieving revision 1.9
diff -u -r1.9 ofconsole.c
--- term/ieee1275/ofconsole.c   10 Nov 2005 01:57:52 -0000      1.9
+++ term/ieee1275/ofconsole.c   12 May 2006 15:02:33 -0000
@@ -196,7 +196,7 @@
       return 1;
     }
     
-  return -1;
+  return 0;
 }
 
 static int
Index: util/console.c
===================================================================
RCS file: /sources/grub/grub2/util/console.c,v
retrieving revision 1.13
diff -u -r1.13 console.c
--- util/console.c      21 Aug 2005 07:22:51 -0000      1.13
+++ util/console.c      12 May 2006 15:02:33 -0000
@@ -131,7 +131,7 @@
   /* Check for SAVED_CHAR. This should not be true, because this
      means checkkey is called twice continuously.  */
   if (saved_char != ERR)
-    return saved_char;
+    return 1;
   
   wtimeout (stdscr, 100);
   c = getch ();
@@ -139,10 +139,10 @@
   if (c != ERR)
     {
       saved_char = c;
-      return c;
+      return 1;
     }
 
-  return -1;
+  return 0;
 }
 
 static int
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to