Updated copyright notices for most files.
[deliverable/binutils-gdb.git] / gdb / tui / tui-interp.c
index 17dda51d8caa715dbdb1149088b110e785b9eb10..bf38aae3e0e81ff1fc84d8cd9d89f1e65d153183 100644 (file)
@@ -1,12 +1,12 @@
 /* TUI Interpreter definitions for GDB, the GNU debugger.
 
-   Copyright 2003 Free Software Foundation, Inc.
+   Copyright (C) 2003, 2007, 2008, 2009 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
@@ -15,9 +15,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330,
-   Boston, MA 02111-1307, USA.  */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
 #include "interps.h"
@@ -33,7 +31,8 @@
 #include "tui/tui-io.h"
 #include "exceptions.h"
 
-/* Set to 1 when the TUI mode must be activated when we first start gdb.  */
+/* Set to 1 when the TUI mode must be activated when we first start
+   gdb.  */
 static int tui_start_enabled = 0;
 
 /* Cleanup the tui before exiting.  */
@@ -41,15 +40,15 @@ static int tui_start_enabled = 0;
 static void
 tui_exit (void)
 {
-  /* Disable the tui.  Curses mode is left leaving the screen
-     in a clean state (see endwin()).  */
+  /* Disable the tui.  Curses mode is left leaving the screen in a
+     clean state (see endwin()).  */
   tui_disable ();
 }
 
 /* These implement the TUI interpreter.  */
 
 static void *
-tui_init (void)
+tui_init (int top_level)
 {
   /* Install exit handler to leave the screen in a good shape.  */
   atexit (tui_exit);
@@ -57,6 +56,7 @@ tui_init (void)
   tui_initialize_static_data ();
 
   tui_initialize_io ();
+  tui_initialize_win ();
   tui_initialize_readline ();
 
   return NULL;
@@ -67,8 +67,9 @@ tui_resume (void *data)
 {
   struct ui_file *stream;
 
-  /* gdb_setup_readline will change gdb_stdout.  If the TUI was previously
-     writing to gdb_stdout, then set it to the new gdb_stdout afterwards.  */
+  /* gdb_setup_readline will change gdb_stdout.  If the TUI was
+     previously writing to gdb_stdout, then set it to the new
+     gdb_stdout afterwards.  */
 
   stream = cli_out_set_stream (tui_old_uiout, gdb_stdout);
   if (stream != gdb_stdout)
@@ -119,19 +120,20 @@ tui_exec (void *data, const char *command_str)
 static void
 tui_command_loop (void *data)
 {
-  int length;
-  char *a_prompt;
-  char *gdb_prompt = get_prompt ();
-
   /* If we are using readline, set things up and display the first
      prompt, otherwise just print the prompt.  */
   if (async_command_editing_p)
     {
+      int length;
+      char *a_prompt;
+      char *gdb_prompt = get_prompt ();
+
       /* Tell readline what the prompt to display is and what function
          it will need to call after a whole line is read. This also
          displays the first prompt.  */
-      length = strlen (PREFIX (0)) + strlen (gdb_prompt) + strlen (SUFFIX (0)) + 1;
-      a_prompt = (char *) xmalloc (length);
+      length = strlen (PREFIX (0)) 
+       + strlen (gdb_prompt) + strlen (SUFFIX (0)) + 1;
+      a_prompt = (char *) alloca (length);
       strcpy (a_prompt, PREFIX (0));
       strcat (a_prompt, gdb_prompt);
       strcat (a_prompt, SUFFIX (0));
@@ -162,6 +164,10 @@ tui_command_loop (void *data)
       
       if (result == 0)
        {
+         /* If any exception escaped to here, we better enable
+            stdin.  Otherwise, any command that calls async_disable_stdin,
+            and then throws, will leave stdin inoperable.  */
+         async_enable_stdin ();
          /* FIXME: this should really be a call to a hook that is
             interface specific, because interfaces can display the
             prompt in their own way.  */
@@ -197,15 +203,15 @@ _initialize_tui_interp (void)
   };
   struct interp *tui_interp;
 
-  /* Create a default uiout builder for the TUI. */
+  /* Create a default uiout builder for the TUI.  */
   tui_out = tui_out_new (gdb_stdout);
-  interp_add (interp_new ("tui", NULL, tui_out, &procs));
-  if (interpreter_p && strcmp (interpreter_p, "tui") == 0)
+  interp_add (interp_new (INTERP_TUI, NULL, tui_out, &procs));
+  if (interpreter_p && strcmp (interpreter_p, INTERP_TUI) == 0)
     tui_start_enabled = 1;
 
   if (interpreter_p && strcmp (interpreter_p, INTERP_CONSOLE) == 0)
     {
       xfree (interpreter_p);
-      interpreter_p = xstrdup ("tui");
+      interpreter_p = xstrdup (INTERP_TUI);
     }
 }
This page took 0.026207 seconds and 4 git commands to generate.