]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
make serial use ANSI code recognition in terminfo.mod
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Thu, 6 May 2010 19:32:58 +0000 (21:32 +0200)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Thu, 6 May 2010 19:32:58 +0000 (21:32 +0200)
conf/i386-ieee1275.rmk
include/grub/terminfo.h
term/ieee1275/ofconsole.c
term/serial.c

index 64820565794ae109cadad180d0121b8a82cef701..66e75c77bd8e6f80b945e9ec7220e7a554b72ba9 100644 (file)
@@ -25,7 +25,7 @@ kernel_img_SOURCES = kern/i386/ieee1275/startup.S \
        term/terminfo.c term/tparm.c    \
        disk/ieee1275/ofdisk.c \
        symlist.c
-kernel_img_HEADERS += ieee1275/ieee1275.h
+kernel_img_HEADERS += ieee1275/ieee1275.h terminfo.h
 kernel_img_CFLAGS = $(COMMON_CFLAGS)
 kernel_img_ASFLAGS = $(COMMON_ASFLAGS)
 kernel_img_LDFLAGS += $(COMMON_LDFLAGS) -Wl,-N,-S,-Ttext,0x10000,-Bstatic
index 84a6f6ab241b6209b9e10f09e5b83171d96e8b0b..f078871d06848e4dcbca03a130f9c2cefab46f13 100644 (file)
 #include <grub/types.h>
 #include <grub/term.h>
 
-char *grub_terminfo_get_current (void);
-grub_err_t grub_terminfo_set_current (const char *);
+char *EXPORT_FUNC(grub_terminfo_get_current) (void);
+grub_err_t EXPORT_FUNC(grub_terminfo_set_current) (const char *);
 
-void grub_terminfo_gotoxy (grub_uint8_t x, grub_uint8_t y,
-                          grub_term_output_t oterm);
-void grub_terminfo_cls (grub_term_output_t oterm);
-void grub_terminfo_reverse_video_on (grub_term_output_t oterm);
-void grub_terminfo_reverse_video_off (grub_term_output_t oterm);
-void grub_terminfo_cursor_on (grub_term_output_t oterm);
-void grub_terminfo_cursor_off (grub_term_output_t oterm);
+void EXPORT_FUNC(grub_terminfo_gotoxy) (grub_uint8_t x, grub_uint8_t y,
+                                       grub_term_output_t oterm);
+void EXPORT_FUNC(grub_terminfo_cls) (grub_term_output_t oterm);
+void EXPORT_FUNC(grub_terminfo_reverse_video_on) (grub_term_output_t oterm);
+void EXPORT_FUNC(grub_terminfo_reverse_video_off) (grub_term_output_t oterm);
+void EXPORT_FUNC(grub_terminfo_cursor_on) (grub_term_output_t oterm);
+void EXPORT_FUNC(grub_terminfo_cursor_off) (grub_term_output_t oterm);
 
 #define GRUB_TERMINFO_READKEY_MAX_LEN 4
-void grub_terminfo_readkey (int *keys, int *len, int (*readkey) (void));
+void EXPORT_FUNC(grub_terminfo_readkey) (int *keys, int *len, int (*readkey) (void));
 
 #endif /* ! GRUB_TERMINFO_HEADER */
index 74de5806e10e05f396587e9704e48ee5580881ff..b9b60901b3e78385ba36a4fe3fbef78c5735b113 100644 (file)
@@ -166,12 +166,12 @@ static int
 grub_ofconsole_checkkey (void)
 {
   if (grub_buflen)
-    return 1;
+    return grub_keybuf[0];
 
   grub_terminfo_readkey (grub_keybuf, &grub_buflen, readkey);
 
   if (grub_buflen)
-    return 1;
+    return grub_keybuf[0];
 
   return -1;
 }
index 6a20545b226d291a221732983818e5e43cf87f0d..bdc80cb74ae482c746d5f8741ab8ab27545dc4ef 100644 (file)
@@ -35,8 +35,8 @@ static unsigned int keep_track = 1;
 static unsigned int registered = 0;
 
 /* An input buffer.  */
-static char input_buf[8];
-static unsigned int npending = 0;
+static int input_buf[GRUB_TERMINFO_READKEY_MAX_LEN];
+static int npending = 0;
 
 static struct grub_term_output grub_serial_term_output;
 
@@ -114,98 +114,6 @@ serial_hw_put (const int c)
   grub_outb (c, serial_settings.port + UART_TX);
 }
 
-static void
-serial_translate_key_sequence (void)
-{
-  unsigned int i;
-  static struct
-  {
-    char key;
-    char ascii;
-  }
-  three_code_table[] =
-    {
-      {'A', 16},
-      {'B', 14},
-      {'C', 6},
-      {'D', 2},
-      {'F', 5},
-      {'H', 1},
-      {'4', 4}
-    };
-
-  static struct
-  {
-      short key;
-      char ascii;
-  }
-  four_code_table[] =
-    {
-      {('1' | ('~' << 8)), 1},
-      {('3' | ('~' << 8)), 4},
-      {('5' | ('~' << 8)), 7},
-      {('6' | ('~' << 8)), 3}
-    };
-
-  if (npending < 3)
-    return;
-
-  /* The buffer must start with "ESC [".  */
-  if (input_buf[0] != '\e' || input_buf[1] != '[')
-    return;
-
-  for (i = 0; i < ARRAY_SIZE (three_code_table); i++)
-    if (three_code_table[i].key == input_buf[2])
-      {
-       input_buf[0] = three_code_table[i].ascii;
-       npending -= 2;
-       grub_memmove (input_buf + 1, input_buf + 3, npending - 1);
-       return;
-      }
-
-  if (npending >= 4)
-    {
-      short key = input_buf[3] | (input_buf[4] << 8);
-
-      for (i = 0; i < ARRAY_SIZE (four_code_table); i++)
-       if (four_code_table[i].key == key)
-         {
-           input_buf[0] = four_code_table[i].ascii;
-           npending -= 3;
-           grub_memmove (input_buf + 1, input_buf + 4, npending - 1);
-           return;
-         }
-    }
-}
-
-static int
-fill_input_buf (const int nowait)
-{
-  int i;
-
-  for (i = 0; i < 10000 && npending < sizeof (input_buf); i++)
-    {
-      int c;
-
-      c = serial_hw_fetch ();
-      if (c >= 0)
-       {
-         input_buf[npending++] = c;
-
-         /* Reset the counter to zero, to wait for the same interval.  */
-         i = 0;
-       }
-
-      if (nowait)
-       break;
-    }
-
-  /* Translate some key sequences.  */
-  serial_translate_key_sequence ();
-
-  return npending;
-}
-
 /* Convert speed to divisor.  */
 static unsigned short
 serial_get_divisor (unsigned int speed)
@@ -248,28 +156,29 @@ serial_get_divisor (unsigned int speed)
 static int
 grub_serial_checkkey (void)
 {
-  if (fill_input_buf (1))
+  if (npending)
     return input_buf[0];
-  else
-    return -1;
+
+  grub_terminfo_readkey (input_buf, &npending, serial_hw_fetch);
+
+  if (npending)
+    return input_buf[0];
+
+  return -1;
 }
 
 /* The serial version of getkey.  */
 static int
 grub_serial_getkey (void)
 {
-  int c;
-
-  while (! fill_input_buf (0))
-    ;
-
-  c = input_buf[0];
-  if (c == 0x7f)
-    c = GRUB_TERM_BACKSPACE;
-
-  grub_memmove (input_buf, input_buf + 1, --npending);
-
-  return c;
+  int ret;
+  while (! npending)
+    grub_terminfo_readkey (input_buf, &npending, serial_hw_fetch);
+
+  ret = input_buf[0];
+  npending--;
+  grub_memmove (input_buf, input_buf + 1, npending);
+  return ret;
 }
 
 /* Initialize a serial device. PORT is the port number for a serial device.