summaryrefslogtreecommitdiffstats
path: root/lldb/source/Commands/CommandObjectApropos.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/Commands/CommandObjectApropos.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/Commands/CommandObjectApropos.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectApropos.cpp96
1 files changed, 96 insertions, 0 deletions
diff --git a/lldb/source/Commands/CommandObjectApropos.cpp b/lldb/source/Commands/CommandObjectApropos.cpp
new file mode 100644
index 00000000000..0fcc093901f
--- /dev/null
+++ b/lldb/source/Commands/CommandObjectApropos.cpp
@@ -0,0 +1,96 @@
+//===-- CommandObjectApropos.cpp ---------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "CommandObjectApropos.h"
+
+// C Includes
+// C++ Includes
+// Other libraries and framework includes
+// Project includes
+#include "lldb/Core/Args.h"
+#include "lldb/Core/Options.h"
+
+#include "lldb/Interpreter/CommandInterpreter.h"
+#include "lldb/Interpreter/CommandReturnObject.h"
+#include "lldb/Interpreter/CommandObjectMultiword.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+//-------------------------------------------------------------------------
+// CommandObjectApropos
+//-------------------------------------------------------------------------
+
+CommandObjectApropos::CommandObjectApropos () :
+ CommandObject ("apropos",
+ "Finds a list of debugger commands related to a particular word/subject.",
+ "apropos <search-word>")
+{
+}
+
+CommandObjectApropos::~CommandObjectApropos()
+{
+}
+
+
+bool
+CommandObjectApropos::Execute (Args &command, CommandContext *context, CommandInterpreter *interpreter,
+ CommandReturnObject &result)
+{
+ const int argc = command.GetArgumentCount ();
+
+ if (argc == 1)
+ {
+ const char *search_word = command.GetArgumentAtIndex(0);
+ if ((search_word != NULL)
+ && (strlen (search_word) > 0))
+ {
+ // The bulk of the work must be done inside the Command Interpreter, since the command dictionary
+ // is private.
+ StringList commands_found;
+ StringList commands_help;
+ interpreter->FindCommandsForApropos (search_word, commands_found, commands_help);
+ if (commands_found.GetSize() == 0)
+ {
+ result.AppendMessageWithFormat ("No commands found pertaining to '%s'.", search_word);
+ result.AppendMessage ("Try 'help' to see a complete list of debugger commands.");
+ }
+ else
+ {
+ result.AppendMessageWithFormat ("The following commands may relate to '%s':\n", search_word);
+ size_t max_len = 0;
+
+ for (int i = 0; i < commands_found.GetSize(); ++i)
+ {
+ int len = strlen (commands_found.GetStringAtIndex (i));
+ if (len > max_len)
+ max_len = len;
+ }
+
+ for (int i = 0; i < commands_found.GetSize(); ++i)
+ interpreter->OutputFormattedHelpText (result.GetOutputStream(), commands_found.GetStringAtIndex(i),
+ "--", commands_help.GetStringAtIndex(i), max_len);
+
+ }
+ result.SetStatus (eReturnStatusSuccessFinishNoResult);
+ }
+ else
+ {
+ result.AppendError ("'' is not a valid search word.\n");
+ result.SetStatus (eReturnStatusFailed);
+ }
+ }
+ else
+ {
+ result.AppendError ("'apropos' must be called with exactly one argument.\n");
+ result.SetStatus (eReturnStatusFailed);
+ }
+
+ return result.Succeeded();
+}
OpenPOWER on IntegriCloud