[nemiver/console] Execute command file given as cmd line parameter
- From: Fabien Parent <fparent src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nemiver/console] Execute command file given as cmd line parameter
- Date: Sat, 3 Mar 2012 12:16:06 +0000 (UTC)
commit 762714f5c6e37db773443b615e3c9a620046c43f
Author: Fabien Parent <parent f gmail com>
Date: Sat Mar 3 13:15:28 2012 +0100
Execute command file given as cmd line parameter
src/common/nmv-console.cc | 56 ++++++++++++++++++++++-
src/common/nmv-console.h | 2 +
src/main.cc | 20 ++++++++
src/persp/dbgperspective/nmv-dbg-perspective.cc | 11 +++++
src/persp/dbgperspective/nmv-dbg-perspective.h | 2 +
5 files changed, 89 insertions(+), 2 deletions(-)
---
diff --git a/src/common/nmv-console.cc b/src/common/nmv-console.cc
index 80ad2aa..115689d 100644
--- a/src/common/nmv-console.cc
+++ b/src/common/nmv-console.cc
@@ -31,6 +31,7 @@
#include <map>
#include <vector>
#include <cstring>
+#include <fstream>
#include <cctype>
#include <readline/readline.h>
#include <readline/history.h>
@@ -97,6 +98,7 @@ Console::Stream::operator<< (int a_int)
struct Console::Priv {
std::map<std::string, Console::Command&> commands;
std::vector<Console::Command*> commands_vector;
+ std::list<UString> command_queue;
int fd;
struct readline_state console_state;
@@ -112,7 +114,7 @@ struct Console::Priv {
fd (a_fd),
stream (a_fd),
io_source (Glib::IOSource::create (a_fd, Glib::IO_IN)),
- done_signal_received (false)
+ done_signal_received (true)
{
init ();
}
@@ -294,7 +296,7 @@ struct Console::Priv {
}
void
- execute_command (char *a_buffer)
+ execute_command (const char *a_buffer)
{
std::string command_name;
std::vector<UString> cmd_argv;
@@ -356,6 +358,17 @@ struct Console::Priv {
cmd_execution_timeout_connection.disconnect();
cmd_execution_done_connection.disconnect ();
+ while (command_queue.size ())
+ {
+ NEMIVER_TRY
+ UString command = command_queue.front ();
+ command_queue.pop_front ();
+ stream << command << "\n";
+ add_history (command.c_str ());
+ execute_command (command.c_str ());
+ NEMIVER_CATCH_NOX
+ }
+
NEMIVER_CATCH_NOX
}
@@ -413,6 +426,26 @@ struct Console::Priv {
free (a_command);
}
+
+ void
+ queue_command (const UString &a_command)
+ {
+ NEMIVER_TRY
+
+ if (a_command.empty ()) {
+ return;
+ }
+
+ if (!command_queue.size () && done_signal_received) {
+ stream << a_command << "\n";
+ add_history (a_command.c_str ());
+ execute_command (a_command.c_str ());
+ } else {
+ command_queue.push_back (a_command);
+ }
+
+ NEMIVER_CATCH_NOX
+ }
};
Console::Console (int a_fd) :
@@ -449,6 +482,25 @@ Console::register_command (Console::Command &a_command)
}
}
+void
+Console::execute_command_file (const UString &a_command_file)
+{
+ std::ifstream file (a_command_file.c_str ());
+ while (file.good ()) {
+ std::string command;
+ std::getline (file, command);
+ execute_command (command);
+ }
+ file.close ();
+}
+
+void
+Console::execute_command (const UString &a_command)
+{
+ THROW_IF_FAIL (m_priv);
+ m_priv->queue_command (a_command);
+}
+
NEMIVER_END_NAMESPACE(common)
NEMIVER_END_NAMESPACE(nemiver)
diff --git a/src/common/nmv-console.h b/src/common/nmv-console.h
index c215728..62a45c9 100644
--- a/src/common/nmv-console.h
+++ b/src/common/nmv-console.h
@@ -103,6 +103,8 @@ public:
explicit Console (int a_fd);
virtual ~Console ();
void register_command (Console::Command &a_command);
+ void execute_command_file (const UString &a_command_file);
+ void execute_command (const UString &a_command);
};
NEMIVER_END_NAMESPACE(common)
diff --git a/src/main.cc b/src/main.cc
index 9bf1964..d71b9ad 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -64,6 +64,7 @@ static bool gv_use_launch_terminal = false;
static gchar *gv_remote = 0;
static gchar *gv_solib_prefix = 0;
static gchar *gv_gdb_binary_filepath = 0;
+static gchar *gv_command_filepath = 0;
static gchar *gv_core_path = 0;
static GOptionEntry entries[] =
@@ -179,6 +180,15 @@ static GOptionEntry entries[] =
_("Set the path of the GDB binary to use to debug the inferior"),
"</path/to/gdb>"
},
+ {
+ "exec-command-file",
+ 0,
+ 0,
+ G_OPTION_ARG_STRING,
+ &gv_command_filepath,
+ _("Set the path of a file of commands to execute at start-up"),
+ "</path/to/command/file>"
+ },
{
"version",
0,
@@ -651,6 +661,16 @@ process_gui_options (int& a_argc, char** a_argv)
prog_args,
env);
}
+
+ if (gv_command_filepath) {
+ char *command_filepath = realpath (gv_command_filepath, 0);
+ if (command_filepath) {
+ debug_persp->execute_command_file (command_filepath);
+ } else {
+ LOG_ERROR ("Could not resolve the full path "
+ "of the command file");
+ }
+ }
} else {
cerr << "Could not find the debugger perspective plugin\n";
return false;
diff --git a/src/persp/dbgperspective/nmv-dbg-perspective.cc b/src/persp/dbgperspective/nmv-dbg-perspective.cc
index e3b68da..cfcf177 100644
--- a/src/persp/dbgperspective/nmv-dbg-perspective.cc
+++ b/src/persp/dbgperspective/nmv-dbg-perspective.cc
@@ -559,6 +559,8 @@ public:
ISessMgr& session_manager ();
+ void execute_command_file (const UString &a_command_file);
+
void execute_session (ISessMgr::Session &a_session);
void execute_program ();
@@ -5720,6 +5722,15 @@ DBGPerspective::session_manager ()
}
void
+DBGPerspective::execute_command_file (const UString &a_command_file)
+{
+ THROW_IF_FAIL (m_priv);
+ THROW_IF_FAIL (m_priv->dbg_console);
+
+ m_priv->dbg_console->execute_command_file (a_command_file);
+}
+
+void
DBGPerspective::execute_session (ISessMgr::Session &a_session)
{
LOG_FUNCTION_SCOPE_NORMAL_DD;
diff --git a/src/persp/dbgperspective/nmv-dbg-perspective.h b/src/persp/dbgperspective/nmv-dbg-perspective.h
index cc0ea7b..a249158 100644
--- a/src/persp/dbgperspective/nmv-dbg-perspective.h
+++ b/src/persp/dbgperspective/nmv-dbg-perspective.h
@@ -98,6 +98,8 @@ public:
virtual ISessMgr& session_manager () = 0;
+ virtual void execute_command_file (const UString &a_command_file) = 0;
+
virtual void execute_session (ISessMgr::Session &a_session) = 0;
virtual void execute_program () = 0;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]