2011-03-23 Eric B. Weddington <eric.weddington@atmel.com>
[deliverable/binutils-gdb.git] / readline / terminal.c
index cc61388f816641fd066e813fe3462e51d350044a..46b50e77e24a37b303ac9cbd48d0a214ae018184 100644 (file)
 #  include <sys/ioctl.h>
 #endif /* GWINSZ_IN_SYS_IOCTL && !TIOCGWINSZ */
 
+#ifdef __MSDOS__
+# include <pc.h>
+#endif
+
 #include "rltty.h"
 #include "tcap.h"
 
 #include "rlshell.h"
 #include "xmalloc.h"
 
+#if defined (__MINGW32__)
+# include <windows.h>
+# include <wincon.h>
+#endif
+
 #define CUSTOM_REDISPLAY_FUNC() (rl_redisplay_function != rl_redisplay)
 #define CUSTOM_INPUT_FUNC() (rl_getc_function != rl_getc)
 
@@ -77,8 +86,10 @@ int rl_prefer_env_winsize;
 /*                                                                 */
 /* **************************************************************** */
 
+#ifndef __MSDOS__
 static char *term_buffer = (char *)NULL;
 static char *term_string_buffer = (char *)NULL;
+#endif /* !__MSDOS__ */
 
 static int tcap_initialized;
 
@@ -122,7 +133,7 @@ char *_rl_term_up;
 static char *_rl_visible_bell;
 
 /* Non-zero means the terminal can auto-wrap lines. */
-int _rl_term_autowrap;
+int _rl_term_autowrap = -1;
 
 /* Non-zero means that this terminal has a meta key. */
 static int term_has_meta;
@@ -207,6 +218,20 @@ _rl_get_screen_size (tty, ignore_env)
     }
 #endif /* TIOCGWINSZ */
 
+  /* For MinGW, we get the console size from the Windows API.  */
+#if defined (__MINGW32__)
+  HANDLE hConOut = GetStdHandle (STD_OUTPUT_HANDLE);
+  if (hConOut != INVALID_HANDLE_VALUE)
+    {
+      CONSOLE_SCREEN_BUFFER_INFO scr;
+      if (GetConsoleScreenBufferInfo (hConOut, &scr))
+       {
+         wc = scr.dwSize.X;
+         wr = scr.srWindow.Bottom - scr.srWindow.Top + 1;
+       }
+    }
+#endif
+
 #if defined (__EMX__)
   _emx_get_screensize (&_rl_screenwidth, &_rl_screenheight);
 #endif
@@ -230,7 +255,10 @@ _rl_get_screen_size (tty, ignore_env)
       if (_rl_screenwidth <= 0)
         _rl_screenwidth = wc;
 
-#if !defined (__DJGPP__)
+#if defined (__DJGPP__)
+      if (_rl_screenwidth <= 0)
+       _rl_screenwidth = ScreenCols ();
+#else
       if (_rl_screenwidth <= 0 && term_string_buffer)
        _rl_screenwidth = tgetnum ("co");
 #endif
@@ -246,7 +274,10 @@ _rl_get_screen_size (tty, ignore_env)
       if (_rl_screenheight <= 0)
         _rl_screenheight = wr;
 
-#if !defined (__DJGPP__)
+#if defined (__DJGPP__)
+      if (_rl_screenheight <= 0)
+       _rl_screenheight = ScreenRows ();
+#else
       if (_rl_screenheight <= 0 && term_string_buffer)
        _rl_screenheight = tgetnum ("li");
 #endif
@@ -274,6 +305,9 @@ void
 _rl_set_screen_size (rows, cols)
      int rows, cols;
 {
+  if (_rl_term_autowrap == -1)
+    _rl_init_terminal_io (rl_terminal_name);
+
   if (rows > 0)
     _rl_screenheight = rows;
   if (cols > 0)
@@ -397,6 +431,23 @@ _rl_init_terminal_io (terminal_name)
   if (term == 0)
     term = "dumb";
 
+#ifdef __MSDOS__
+  _rl_term_im = _rl_term_ei = _rl_term_ic = _rl_term_IC = (char *)NULL;
+  _rl_term_up = _rl_term_dc = _rl_term_DC = _rl_visible_bell = (char *)NULL;
+  _rl_term_ku = _rl_term_kd = _rl_term_kl = _rl_term_kr = (char *)NULL;
+  _rl_term_mm = _rl_term_mo = (char *)NULL;
+  _rl_terminal_can_insert = term_has_meta = _rl_term_autowrap = 0;
+  _rl_term_cr = "\r";
+  _rl_term_clreol = _rl_term_clrpag = _rl_term_backspace = (char *)NULL;
+  _rl_term_goto = _rl_term_pc = _rl_term_ip = (char *)NULL;
+  _rl_term_ks = _rl_term_ke =_rl_term_vs = _rl_term_ve = (char *)NULL;
+  _rl_term_kh = _rl_term_kH = _rl_term_at7 = _rl_term_kI = (char *)NULL;
+#if defined(HACK_TERMCAP_MOTION)
+  _rl_term_forward_char = (char *)NULL;
+#endif
+
+  _rl_get_screen_size (tty, 0);
+#else  /* !__MSDOS__ */
   /* I've separated this out for later work on not calling tgetent at all
      if the calling application has supplied a custom redisplay function,
      (and possibly if the application has supplied a custom input function). */
@@ -499,6 +550,8 @@ _rl_init_terminal_io (terminal_name)
   if (!term_has_meta)
     _rl_term_mm = _rl_term_mo = (char *)NULL;
 
+#endif /* !__MSDOS__ */
+
   /* Attempt to find and bind the arrow keys.  Do not override already
      bound keys in an overzealous attempt, however. */
 
@@ -595,10 +648,12 @@ _rl_backspace (count)
 {
   register int i;
 
+#ifndef __MSDOS__
   if (_rl_term_backspace)
     for (i = 0; i < count; i++)
       tputs (_rl_term_backspace, 1, _rl_output_character_function);
   else
+#endif
     for (i = 0; i < count; i++)
       putc ('\b', _rl_out_stream);
   return 0;
@@ -628,12 +683,17 @@ rl_ding ()
        default:
          break;
        case VISIBLE_BELL:
+#ifdef __MSDOS__
+         ScreenVisualBell ();
+         break;
+#else
          if (_rl_visible_bell)
            {
              tputs (_rl_visible_bell, 1, _rl_output_character_function);
              break;
            }
          /* FALLTHROUGH */
+#endif
        case AUDIBLE_BELL:
          fprintf (stderr, "\007");
          fflush (stderr);
@@ -685,6 +745,7 @@ void
 _rl_set_cursor (im, force)
      int im, force;
 {
+#ifndef __MSDOS__
   if (_rl_term_ve && _rl_term_vs)
     {
       if (force || im != rl_insert_mode)
@@ -695,4 +756,5 @@ _rl_set_cursor (im, force)
            tputs (_rl_term_ve, 1, _rl_output_character_function);
        }
     }
+#endif
 }
This page took 0.029877 seconds and 4 git commands to generate.