#include "filenames.h"
#include "frame.h"
#include "buffer.h"
+#include "gdb_select.h"
/* readline include files. */
#include "readline/readline.h"
#define DEFAULT_PROMPT "(gdb) "
#endif
+/* Generate a function that exports a pointer to a field of the
+ current UI. */
+
+#define gen_ret_current_ui_field_ptr(type, name) \
+type * \
+current_ui_## name ## _ptr (void) \
+{ \
+ return ¤t_ui->m_ ## name; \
+}
+
+gen_ret_current_ui_field_ptr (struct ui_file *, gdb_stdout)
+gen_ret_current_ui_field_ptr (struct ui_file *, gdb_stdin)
+gen_ret_current_ui_field_ptr (struct ui_file *, gdb_stderr)
+gen_ret_current_ui_field_ptr (struct ui_file *, gdb_stdlog)
+
/* Initialization file name for gdb. This is host-dependent. */
const char gdbinit[] = GDBINIT;
cleanups = make_cleanup (do_restore_instream_cleanup, instream);
instream = stream;
- command_loop ();
+
+ /* Read commands from `instream' and execute them until end of file
+ or error reading instream. */
+
+ while (instream != NULL && !feof (instream))
+ {
+ char *command;
+
+ /* Get a command-line. This calls the readline package. */
+ command = command_line_input (NULL, 0, NULL);
+ if (command == NULL)
+ break;
+ command_handler (command);
+ }
+
do_cleanups (cleanups);
}
\f
return retval;
}
-/* Read commands from `instream' and execute them
- until end of file or error reading instream. */
-
-void
-command_loop (void)
-{
- while (instream && !feof (instream))
- {
- char *command;
-
- /* Get a command-line. This calls the readline package. */
- command = command_line_input (instream == stdin ?
- get_prompt () : (char *) NULL,
- instream == stdin, "prompt");
- if (command == NULL)
- return;
- command_handler (command);
- }
-}
\f
/* When nonzero, cause dont_repeat to do nothing. This should only be
set via prevent_dont_repeat. */
gdb_readline_no_editing (const char *prompt)
{
struct buffer line_buffer;
+ /* Read from stdin if we are executing a user defined command. This
+ is the right thing for prompt_for_continue, at least. */
+ FILE *stream = instream != NULL ? instream : stdin;
+ int fd = fileno (stream);
buffer_init (&line_buffer);
while (1)
{
int c;
+ int numfds;
+ fd_set readfds;
+
+ QUIT;
+
+ /* Wait until at least one byte of data is available. Control-C
+ can interrupt interruptible_select, but not fgetc. */
+ FD_ZERO (&readfds);
+ FD_SET (fd, &readfds);
+ if (interruptible_select (fd + 1, &readfds, NULL, NULL, NULL) == -1)
+ {
+ if (errno == EINTR)
+ {
+ /* If this was ctrl-c, the QUIT above handles it. */
+ continue;
+ }
+ perror_with_name (("select"));
+ }
- /* Read from stdin if we are executing a user defined command.
- This is the right thing for prompt_for_continue, at least. */
- c = fgetc (instream ? instream : stdin);
+ c = fgetc (stream);
if (c == EOF)
{
static void
gdb_readline_wrapper_cleanup (void *arg)
{
+ struct ui *ui = current_ui;
struct gdb_readline_wrapper_cleanup *cleanup
= (struct gdb_readline_wrapper_cleanup *) arg;
rl_already_prompted = cleanup->already_prompted_orig;
- gdb_assert (input_handler == gdb_readline_wrapper_line);
- input_handler = cleanup->handler_orig;
+ gdb_assert (ui->input_handler == gdb_readline_wrapper_line);
+ ui->input_handler = cleanup->handler_orig;
/* Don't restore our input handler in readline yet. That would make
readline prep the terminal (putting it in raw mode), while the
char *
gdb_readline_wrapper (const char *prompt)
{
+ struct ui *ui = current_ui;
struct cleanup *back_to;
struct gdb_readline_wrapper_cleanup *cleanup;
char *retval;
cleanup = XNEW (struct gdb_readline_wrapper_cleanup);
- cleanup->handler_orig = input_handler;
- input_handler = gdb_readline_wrapper_line;
+ cleanup->handler_orig = ui->input_handler;
+ ui->input_handler = gdb_readline_wrapper_line;
cleanup->already_prompted_orig = rl_already_prompted;
/* Starting a new command line. */
cmd_line_buffer.used_size = 0;
- /* Control-C quits instantly if typed while in this loop
- since it should not wait until the user types a newline. */
- immediate_quit++;
- QUIT;
#ifdef STOP_SIGNAL
if (job_control)
signal (STOP_SIGNAL, handle_stop_sig);
if (job_control)
signal (STOP_SIGNAL, SIG_DFL);
#endif
- immediate_quit--;
return cmd;
}