2003-03-27 Andrew Cagney <cagney@redhat.com>
[deliverable/binutils-gdb.git] / gdb / top.c
index 4749c38180961b3b945c7a4aab24ca687de76366..fea71dfd87f21b5cca27e2cf8d397791f322f1fd 100644 (file)
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -1,7 +1,7 @@
 /* Top level stuff for GDB, the GNU debugger.
 
    Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
-   1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
+   1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
    Free Software Foundation, Inc.
 
    This file is part of GDB.
@@ -82,7 +82,7 @@ int inhibit_gdbinit = 0;
 /* If nonzero, and GDB has been configured to be able to use windows,
    attempt to open them upon startup.  */
 
-int use_windows = 1;
+int use_windows = 0;
 
 extern char lang_frame_mismatch_warn[];                /* language.c */
 
@@ -703,12 +703,12 @@ execute_command (char *p, int from_tty)
        execute_user_command (c, arg);
       else if (c->type == set_cmd || c->type == show_cmd)
        do_setshow_command (arg, from_tty & caution, c);
-      else if (c->func == NULL)
+      else if (!cmd_func_p (c))
        error ("That is not a command, just a help topic.");
       else if (call_command_hook)
        call_command_hook (c, arg, from_tty & caution);
       else
-       (*c->func) (c, arg, from_tty & caution);
+       cmd_func (c, arg, from_tty & caution);
        
       /* If this command has been post-hooked, run the hook last. */
       execute_cmd_post_hook (c);
@@ -947,6 +947,29 @@ static int write_history_p;
 static int history_size;
 static char *history_filename;
 
+/* This is like readline(), but it has some gdb-specific behavior.
+   gdb can use readline in both the synchronous and async modes during
+   a single gdb invocation.  At the ordinary top-level prompt we might
+   be using the async readline.  That means we can't use
+   rl_pre_input_hook, since it doesn't work properly in async mode.
+   However, for a secondary prompt (" >", such as occurs during a
+   `define'), gdb just calls readline() directly, running it in
+   synchronous mode.  So for operate-and-get-next to work in this
+   situation, we have to switch the hooks around.  That is what
+   gdb_readline_wrapper is for.  */
+char *
+gdb_readline_wrapper (char *prompt)
+{
+  /* Set the hook that works in this case.  */
+  if (event_loop_p && after_char_processing_hook)
+    {
+      rl_pre_input_hook = (Function *) after_char_processing_hook;
+      after_char_processing_hook = NULL;
+    }
+
+  return readline (prompt);
+}
+
 \f
 #ifdef STOP_SIGNAL
 static void
@@ -1037,7 +1060,7 @@ static int operate_saved_history = -1;
 /* This is put on the appropriate hook and helps operate-and-get-next
    do its work.  */
 void
-gdb_rl_operate_and_get_next_completion ()
+gdb_rl_operate_and_get_next_completion (void)
 {
   int delta = where_history () - operate_saved_history;
   /* The `key' argument to rl_get_previous_history is ignored.  */
@@ -1059,6 +1082,8 @@ gdb_rl_operate_and_get_next_completion ()
 static int
 gdb_rl_operate_and_get_next (int count, int key)
 {
+  int where;
+
   if (event_loop_p)
     {
       /* Use the async hook.  */
@@ -1071,8 +1096,20 @@ gdb_rl_operate_and_get_next (int count, int key)
       rl_pre_input_hook = (Function *) gdb_rl_operate_and_get_next_completion;
     }
 
-  /* Add 1 because we eventually want the next line.  */
-  operate_saved_history = where_history () + 1;
+  /* Find the current line, and find the next line to use.  */
+  where = where_history();
+
+  /* FIXME: kettenis/20020817: max_input_history is renamed into
+     history_max_entries in readline-4.2.  When we do a new readline
+     import, we should probably change it here too, even though
+     readline maintains backwards compatibility for now by still
+     defining max_input_history.  */
+  if ((history_is_stifled () && (history_length >= max_input_history)) ||
+      (where >= history_length - 1))
+    operate_saved_history = where;
+  else
+    operate_saved_history = where + 1;
+
   return rl_newline (1, key);
 }
 \f
@@ -1174,7 +1211,7 @@ command_line_input (char *prompt_arg, int repeat, char *annotation_suffix)
        }
       else if (command_editing_p && instream == stdin && ISATTY (instream))
        {
-         rl = readline (local_prompt);
+         rl = gdb_readline_wrapper (local_prompt);
        }
       else
        {
@@ -1320,7 +1357,7 @@ print_gdb_version (struct ui_file *stream)
 
   /* Second line is a copyright notice. */
 
-  fprintf_filtered (stream, "Copyright 2002 Free Software Foundation, Inc.\n");
+  fprintf_filtered (stream, "Copyright 2003 Free Software Foundation, Inc.\n");
 
   /* Following the copyright is a brief statement that the program is
      free software, that users are free to copy and change it on
@@ -1915,11 +1952,12 @@ init_main (void)
   write_history_p = 0;
 
   /* Setup important stuff for command line editing.  */
-  rl_completion_entry_function = (int (*)()) readline_line_completion_function;
+  rl_completion_entry_function = readline_line_completion_function;
   rl_completer_word_break_characters =
                                 get_gdb_completer_word_break_characters ();
   rl_completer_quote_characters = get_gdb_completer_quote_characters ();
   rl_readline_name = "gdb";
+  rl_terminal_name = getenv ("TERM");
 
   /* The name for this defun comes from Bash, where it originated.
      15 is Control-o, the same binding this function has in Bash.  */
@@ -2086,19 +2124,4 @@ gdb_init (char *argv0)
      it wants GDB to revert to the CLI, it should clear init_ui_hook. */
   if (init_ui_hook)
     init_ui_hook (argv0);
-
-  /* Install the default UI */
-  if (!init_ui_hook)
-    {
-      uiout = cli_out_new (gdb_stdout);
-
-      /* All the interpreters should have had a look at things by now.
-        Initialize the selected interpreter. */
-      if (interpreter_p)
-       {
-         fprintf_unfiltered (gdb_stderr, "Interpreter `%s' unrecognized.\n",
-                             interpreter_p);
-         exit (1);
-       }
-    }
 }
This page took 0.026903 seconds and 4 git commands to generate.