blob: b1fc42f763721020903232b6b69aff4e136a1350 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- CommandObjectSyntax.cpp ---------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "CommandObjectSyntax.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
16#include "lldb/Core/Args.h"
17#include "lldb/Core/Options.h"
18
19#include "lldb/Interpreter/CommandInterpreter.h"
20#include "lldb/Interpreter/CommandReturnObject.h"
21#include "lldb/Interpreter/CommandObjectMultiword.h"
22
23using namespace lldb;
24using namespace lldb_private;
25
26//-------------------------------------------------------------------------
27// CommandObjectSyntax
28//-------------------------------------------------------------------------
29
30CommandObjectSyntax::CommandObjectSyntax () :
31 CommandObject ("syntax",
32 "Shows the correct syntax for a given debugger command.",
33 "syntax <command>")
34{
35}
36
37CommandObjectSyntax::~CommandObjectSyntax()
38{
39}
40
41
42bool
43CommandObjectSyntax::OldExecute
44(
45 Args& command,
46 CommandContext *context,
47 CommandInterpreter *interpreter,
48 CommandReturnObject &result
49)
50{
51 CommandObject *cmd_obj;
52
53 if (command.GetArgumentCount() != 0)
54 {
55 cmd_obj = interpreter->GetCommandObject(command.GetArgumentAtIndex(0));
56 if (cmd_obj)
57 {
58 Stream &output_strm = result.GetOutputStream();
59 if (cmd_obj->GetOptions() != NULL)
60 {
61 output_strm.Printf ("\nSyntax: %s\n", cmd_obj->GetSyntax());
62 //cmd_obj->GetOptions()->GenerateOptionUsage (output_strm, cmd_obj);
63 output_strm.Printf ("(Try 'help %s' for more information on command options syntax.)\n",
64 cmd_obj->GetCommandName());
65 result.SetStatus (eReturnStatusSuccessFinishNoResult);
66 }
67 else
68 {
69 output_strm.Printf ("\nSyntax: %s\n", cmd_obj->GetSyntax());
70 result.SetStatus (eReturnStatusSuccessFinishNoResult);
71 }
72 }
73 else
74 {
75 result.AppendErrorWithFormat ("'%s' is not a known command.\n", command.GetArgumentAtIndex(0));
76 result.AppendError ("Try 'help' to see a current list of commands.");
77 result.SetStatus (eReturnStatusFailed);
78 }
79 }
80 else
81 {
82 result.AppendError ("Must call 'syntax' with a valid command.");
83 result.SetStatus (eReturnStatusFailed);
84 }
85 return result.Succeeded();
86}
87
88bool
89CommandObjectSyntax::Execute (Args &command, CommandContext *context, CommandInterpreter *interpreter,
90 CommandReturnObject &result)
91{
92 CommandObject::CommandMap::iterator pos;
93 CommandObject *cmd_obj;
94 const int argc = command.GetArgumentCount();
95
96 if (argc > 0)
97 {
98 cmd_obj = interpreter->GetCommandObject (command.GetArgumentAtIndex(0));
99 bool all_okay = true;
100 for (int i = 1; i < argc; ++i)
101 {
102 std::string sub_command = command.GetArgumentAtIndex (i);
103 if (! cmd_obj->IsMultiwordObject())
104 all_okay = false;
105 else
106 {
107 pos = ((CommandObjectMultiword *) cmd_obj)->m_subcommand_dict.find (sub_command);
108 if (pos != ((CommandObjectMultiword *) cmd_obj)->m_subcommand_dict.end())
109 cmd_obj = pos->second.get();
110 else
111 all_okay = false;
112 }
113 }
114
115 if (all_okay && (cmd_obj != NULL))
116 {
117 Stream &output_strm = result.GetOutputStream();
118 if (cmd_obj->GetOptions() != NULL)
119 {
120 output_strm.Printf ("\nSyntax: %s\n", cmd_obj->GetSyntax());
121 //cmd_obj->GetOptions()->GenerateOptionUsage (output_strm, cmd_obj);
122 output_strm.Printf ("(Try 'help %s' for more information on command options syntax.)\n",
123 cmd_obj->GetCommandName());
124 result.SetStatus (eReturnStatusSuccessFinishNoResult);
125 }
126 else
127 {
128 output_strm.Printf ("\nSyntax: %s\n", cmd_obj->GetSyntax());
129 result.SetStatus (eReturnStatusSuccessFinishNoResult);
130 }
131 }
132 else
133 {
134 std::string cmd_string;
135 command.GetCommandString (cmd_string);
136 result.AppendErrorWithFormat ("'%s' is not a known command.\n", cmd_string.c_str());
137 result.AppendError ("Try 'help' to see a current list of commands.");
138 result.SetStatus (eReturnStatusFailed);
139 }
140 }
141 else
142 {
143 result.AppendError ("Must call 'syntax' with a valid command.");
144 result.SetStatus (eReturnStatusFailed);
145 }
146
147 return result.Succeeded();
148}