#include "defs.h"
#include "interps.h"
#include "ui-file.h"
#include "ui-out.h"
#include "cli-out.h"
#include "gdb_string.h"
#include "cli/cli-cmds.h"
#include "cli/cli-decode.h"
#include "tcl.h"
#include "tk.h"
#include "gdbtk.h"
static void gdbtk_command_loop (void);
static void hack_disable_interpreter_exec (char *, int);
struct gdbtk_interp_data
{
struct ui_file *_stdout;
struct ui_file *_stderr;
struct ui_file *_stdlog;
struct ui_file *_stdtarg;
};
static struct gdbtk_interp_data *gdbtk_data;
static void
hack_disable_interpreter_exec (char *args, int from_tty)
{
error ("interpreter-exec not available when running Insight");
}
static void *
gdbtk_interpreter_init (void)
{
struct cmd_list_element *cmd = NULL;
struct cmd_list_element *alias = NULL;
struct cmd_list_element *prefix = NULL;
gdbtk_init ();
if (lookup_cmd_composition ("interpreter-exec", &alias, &prefix, &cmd))
{
set_cmd_cfunc (cmd, hack_disable_interpreter_exec);
}
return gdbtk_data;
}
static int
gdbtk_interpreter_resume (void *data)
{
static int started = 0;
struct gdbtk_interp_data *d = (struct gdbtk_interp_data *) data;
gdbtk_add_hooks ();
gdb_stdout = d->_stdout;
gdb_stderr = d->_stderr;
gdb_stdlog = d->_stdlog;
gdb_stdtarg = d->_stdtarg;
command_loop_hook = gdbtk_command_loop;
if (!started)
{
started = 1;
gdbtk_source_start_file ();
}
return 1;
}
static int
gdbtk_interpreter_suspend (void *data)
{
return 1;
}
static int
gdbtk_interpreter_display_prompt_p (void *data)
{
return 1;
}
static int
gdbtk_interpreter_exec (void *data, const char *command_str)
{
return 1;
}
static void
gdbtk_command_loop (void)
{
extern FILE *instream;
instream = NULL;
if (Tcl_Eval (gdbtk_interp, "gdbtk_tcl_preloop") != TCL_OK)
{
const char *msg;
Tcl_AddErrorInfo (gdbtk_interp, "");
msg = Tcl_GetVar (gdbtk_interp, "errorInfo", TCL_GLOBAL_ONLY);
#ifdef _WIN32
MessageBox (NULL, msg, NULL, MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
fputs_unfiltered (msg, gdb_stderr);
#endif
}
#ifdef _WIN32
close_bfds ();
#endif
Tk_MainLoop ();
}
void
_initialize_gdbtk_interp (void)
{
static const struct interp_procs procs = {
gdbtk_interpreter_init,
gdbtk_interpreter_resume,
gdbtk_interpreter_suspend,
gdbtk_interpreter_exec,
gdbtk_interpreter_display_prompt_p
};
struct interp *gdbtk_interp;
gdbtk_data =
(struct gdbtk_interp_data *) xmalloc (sizeof (struct gdbtk_interp_data));
memset (gdbtk_data, 0, sizeof (struct gdbtk_interp_data));
gdbtk_data->_stdout = gdbtk_fileopen ();
gdbtk_data->_stderr = gdbtk_fileopen ();
gdbtk_data->_stdlog = gdbtk_fileopen ();
gdbtk_data->_stdtarg = gdbtk_fileopen ();
gdbtk_interp = interp_new ("insight", gdbtk_data, cli_out_new (gdbtk_data->_stdout),
&procs);
interp_add (gdbtk_interp);
}