summaryrefslogtreecommitdiffstats
path: root/lldb/source/Interpreter/CommandObjectRegexCommand.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-06-08 16:52:24 +0000
committerChris Lattner <sabre@nondot.org>2010-06-08 16:52:24 +0000
commit30fdc8d841c9d24ac5f3d452b6ece84ee0ac991c (patch)
treef70013106f6a461a14abcd71c65f48a95a2979a6 /lldb/source/Interpreter/CommandObjectRegexCommand.cpp
parent312c4c799da215b337f790fda330f70c4aa757cf (diff)
downloadbcm5719-llvm-30fdc8d841c9d24ac5f3d452b6ece84ee0ac991c.tar.gz
bcm5719-llvm-30fdc8d841c9d24ac5f3d452b6ece84ee0ac991c.zip
Initial checkin of lldb code from internal Apple repo.
llvm-svn: 105619
Diffstat (limited to 'lldb/source/Interpreter/CommandObjectRegexCommand.cpp')
-rw-r--r--lldb/source/Interpreter/CommandObjectRegexCommand.cpp123
1 files changed, 123 insertions, 0 deletions
diff --git a/lldb/source/Interpreter/CommandObjectRegexCommand.cpp b/lldb/source/Interpreter/CommandObjectRegexCommand.cpp
new file mode 100644
index 00000000000..b3fa6a41d97
--- /dev/null
+++ b/lldb/source/Interpreter/CommandObjectRegexCommand.cpp
@@ -0,0 +1,123 @@
+//===-- CommandObjectRegexCommand.cpp ---------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Interpreter/CommandObjectRegexCommand.h"
+
+// C Includes
+// C++ Includes
+// Other libraries and framework includes
+// Project includes
+#include "lldb/Interpreter/CommandInterpreter.h"
+#include "lldb/Interpreter/CommandReturnObject.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+//----------------------------------------------------------------------
+// CommandObjectRegexCommand constructor
+//----------------------------------------------------------------------
+CommandObjectRegexCommand::CommandObjectRegexCommand
+(
+ const char *name,
+ const char *help,
+ const char *syntax,
+ uint32_t max_matches
+) :
+ CommandObject (name, help, syntax),
+ m_entries(),
+ m_max_matches (max_matches)
+{
+}
+
+//----------------------------------------------------------------------
+// Destructor
+//----------------------------------------------------------------------
+CommandObjectRegexCommand::~CommandObjectRegexCommand()
+{
+}
+
+
+bool
+CommandObjectRegexCommand::Execute
+(
+ Args& command,
+ CommandContext *context,
+ CommandInterpreter *interpreter,
+ CommandReturnObject &result
+)
+{
+ return false;
+}
+
+
+bool
+CommandObjectRegexCommand::ExecuteRawCommandString
+(
+ const char *command,
+ CommandContext *context,
+ CommandInterpreter *interpreter,
+ CommandReturnObject &result
+)
+{
+ if (command)
+ {
+ EntryCollection::const_iterator pos, end = m_entries.end();
+ for (pos = m_entries.begin(); pos != end; ++pos)
+ {
+ if (pos->regex.Execute (command, m_max_matches))
+ {
+ std::string new_command(pos->command);
+ std::string match_str;
+ char percent_var[8];
+ size_t idx, percent_var_idx;
+ for (uint32_t match_idx=1; match_idx <= m_max_matches; ++match_idx)
+ {
+ if (pos->regex.GetMatchAtIndex (command, match_idx, match_str))
+ {
+ const int percent_var_len = ::snprintf (percent_var, sizeof(percent_var), "%%%u", match_idx);
+ for (idx = 0; (percent_var_idx = new_command.find(percent_var, idx)) != std::string::npos; )
+ {
+ new_command.erase(percent_var_idx, percent_var_len);
+ new_command.insert(percent_var_idx, match_str);
+ idx += percent_var_idx + match_str.size();
+ }
+ }
+ }
+ // Interpret the new command and return this as the result!
+// if (m_options.verbose)
+// result.GetOutputStream().Printf("%s\n", new_command.c_str());
+ return interpreter->HandleCommand(new_command.c_str(), true, result);
+ }
+ }
+ result.SetStatus(eReturnStatusFailed);
+ result.AppendErrorWithFormat("Command contents '%s' failed to match any regular expression in the '%s' regex command.\n",
+ command,
+ m_cmd_name.c_str());
+ return false;
+ }
+ result.AppendError("empty command passed to regular exression command");
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+}
+
+
+bool
+CommandObjectRegexCommand::AddRegexCommand (const char *re_cstr, const char *command_cstr)
+{
+ m_entries.resize(m_entries.size() + 1);
+ // Only add the regular expression if it compiles
+ if (m_entries.back().regex.Compile (re_cstr, REG_EXTENDED))
+ {
+ m_entries.back().command.assign (command_cstr);
+ return true;
+ }
+ // The regex didn't compile...
+ m_entries.pop_back();
+ return false;
+}
OpenPOWER on IntegriCloud