From e16c50a11a4cc49b0b4a88c481642f72003aac89 Mon Sep 17 00:00:00 2001 From: Jim Ingham Date: Fri, 18 Feb 2011 00:54:25 +0000 Subject: Factor all the code that does "Execute a list of lldb command interpreter commands" into a single function in the Interpreter, and then use that in all the places that used to do this by hand. llvm-svn: 125807 --- lldb/source/Commands/CommandObjectCommands.cpp | 154 +++++++++++++++---------- 1 file changed, 94 insertions(+), 60 deletions(-) (limited to 'lldb/source/Commands/CommandObjectCommands.cpp') diff --git a/lldb/source/Commands/CommandObjectCommands.cpp b/lldb/source/Commands/CommandObjectCommands.cpp index e2358bda..9230aea 100644 --- a/lldb/source/Commands/CommandObjectCommands.cpp +++ b/lldb/source/Commands/CommandObjectCommands.cpp @@ -22,14 +22,87 @@ using namespace lldb; using namespace lldb_private; -const char *k_space_characters = "\t\n\v\f\r "; - //------------------------------------------------------------------------- // CommandObjectCommandsSource //------------------------------------------------------------------------- class CommandObjectCommandsSource : public CommandObject { +private: + + class CommandOptions : public Options + { + public: + + CommandOptions (){} + + virtual + ~CommandOptions (){} + + virtual Error + SetOptionValue (int option_idx, const char *option_arg) + { + Error error; + char short_option = (char) m_getopt_table[option_idx].val; + bool success; + + switch (short_option) + { + case 'e': + m_stop_on_error = Args::StringToBoolean(option_arg, true, &success); + if (!success) + error.SetErrorStringWithFormat("Invalid value for stop-on-error: %s.\n", option_arg); + break; + case 'c': + m_stop_on_continue = Args::StringToBoolean(option_arg, true, &success); + if (!success) + error.SetErrorStringWithFormat("Invalid value for stop-on-continue: %s.\n", option_arg); + break; + default: + error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option); + break; + } + + return error; + } + + void + ResetOptionValues () + { + Options::ResetOptionValues(); + + m_stop_on_error = true; + m_stop_on_continue = true; + } + + const lldb::OptionDefinition* + GetDefinitions () + { + return g_option_table; + } + + // Options table: Required for subclasses of Options. + + static lldb::OptionDefinition g_option_table[]; + + // Instance variables to hold the values for command options. + + bool m_stop_on_error; + bool m_stop_on_continue; + }; + + // Options table: Required for subclasses of Options. + + static lldb::OptionDefinition g_option_table[]; + + CommandOptions m_options; + + virtual Options * + GetOptions () + { + return &m_options; + } + public: CommandObjectCommandsSource(CommandInterpreter &interpreter) : CommandObject (interpreter, @@ -66,68 +139,21 @@ public: if (argc == 1) { const char *filename = args.GetArgumentAtIndex(0); - bool success = true; result.AppendMessageWithFormat ("Executing commands in '%s'.\n", filename); FileSpec cmd_file (filename, true); - if (cmd_file.Exists()) - { - STLStringArray commands; - success = cmd_file.ReadFileLines (commands); - - STLStringArray::iterator pos = commands.begin(); - - // Trim out any empty lines or lines that start with the comment - // char '#' - while (pos != commands.end()) - { - size_t non_space = pos->find_first_not_of (k_space_characters); - // Check for empty line or comment line (lines whose first - // non-space character is a '#') - if (non_space == std::string::npos || (*pos)[non_space] == '#') - pos = commands.erase(pos); - else - ++pos; - } - - if (commands.size() > 0) - { - const size_t num_commands = commands.size(); - size_t i; - for (i = 0; i