Make API calls for setting/getting user settable variables static.
Modify Driver to handle SIGWINCH signals and automatically re-set the
term-width variable.



git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@113506 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/driver/Driver.cpp b/tools/driver/Driver.cpp
index 73aa396..10ab1a1 100644
--- a/tools/driver/Driver.cpp
+++ b/tools/driver/Driver.cpp
@@ -39,6 +39,8 @@
 static void reset_stdin_termios ();
 static struct termios g_old_stdin_termios;
 
+static char *g_debugger_name =  (char *) "";
+
 // In the Driver::MainLoop, we change the terminal settings.  This function is
 // added as an atexit handler to make sure we clean them up.
 static void
@@ -90,6 +92,9 @@
     m_option_data (),
     m_waiting_for_command (false)
 {
+    g_debugger_name = (char *) m_debugger.GetInstanceName();
+    if (g_debugger_name == NULL)
+        g_debugger_name = (char *) "";
 }
 
 Driver::~Driver ()
@@ -1263,6 +1268,22 @@
 }
 
 
+void
+sigwinch_handler (int signo)
+{
+    struct winsize window_size;
+    if (isatty (STDIN_FILENO)
+        && ::ioctl (STDIN_FILENO, TIOCGWINSZ, &window_size) == 0)
+    {
+        if ((window_size.ws_col > 0) && (strlen (g_debugger_name) > 0))
+        {
+            char width_str_buffer[25];
+            ::sprintf (width_str_buffer, "%d", window_size.ws_col);
+            SBDebugger::SetInternalVariable ("term-width", width_str_buffer, g_debugger_name);
+        }
+    }
+}
+
 int
 main (int argc, char const *argv[])
 {
@@ -1270,6 +1291,8 @@
     
     SBHostOS::ThreadCreated ("[main]");
 
+    signal (SIGWINCH, sigwinch_handler);
+
     // Create a scope for driver so that the driver object will destroy itself
     // before SBDebugger::Terminate() is called.
     {