blob: cb1d00c7831f6a2f4e7a508c2349ec9253007b6e [file] [log] [blame]
Greg Clayton73844aa2012-08-22 17:17:09 +00001//===-- OptionValueFileSpec.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
Daniel Malead891f9b2012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Greg Clayton73844aa2012-08-22 17:17:09 +000012#include "lldb/Interpreter/OptionValueFileSpec.h"
13
14// C Includes
15// C++ Includes
16// Other libraries and framework includes
17// Project includes
18#include "lldb/Core/FormatManager.h"
19#include "lldb/Core/State.h"
20#include "lldb/Interpreter/Args.h"
21#include "lldb/Interpreter/CommandCompletions.h"
22
23using namespace lldb;
24using namespace lldb_private;
25
Greg Clayton437b5bc2012-09-27 22:26:11 +000026
27OptionValueFileSpec::OptionValueFileSpec () :
28 OptionValue(),
29 m_current_value (),
30 m_default_value (),
31 m_data_sp(),
32 m_completion_mask (CommandCompletions::eDiskFileCompletion)
33{
34}
35
36OptionValueFileSpec::OptionValueFileSpec (const FileSpec &value) :
37 OptionValue(),
38 m_current_value (value),
39 m_default_value (value),
40 m_data_sp(),
41 m_completion_mask (CommandCompletions::eDiskFileCompletion)
42{
43}
44
45OptionValueFileSpec::OptionValueFileSpec (const FileSpec &current_value,
46 const FileSpec &default_value) :
47 OptionValue(),
48 m_current_value (current_value),
49 m_default_value (default_value),
50 m_data_sp(),
51 m_completion_mask (CommandCompletions::eDiskFileCompletion)
52{
53}
54
Greg Clayton73844aa2012-08-22 17:17:09 +000055void
56OptionValueFileSpec::DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask)
57{
58 if (dump_mask & eDumpOptionType)
59 strm.Printf ("(%s)", GetTypeAsCString ());
60 if (dump_mask & eDumpOptionValue)
61 {
62 if (dump_mask & eDumpOptionType)
63 strm.PutCString (" = ");
64
65 if (m_current_value)
66 {
67 if (m_current_value.GetDirectory())
68 {
69 strm << '"' << m_current_value.GetDirectory();
70 if (m_current_value.GetFilename())
71 strm << '/' << m_current_value.GetFilename();
72 strm << '"';
73 }
74 else
75 {
76 strm << '"' << m_current_value.GetFilename() << '"';
77 }
78 }
79 }
80}
81
82Error
83OptionValueFileSpec::SetValueFromCString (const char *value_cstr,
84 VarSetOperationType op)
85{
86 Error error;
87 switch (op)
88 {
89 case eVarSetOperationClear:
90 Clear ();
91 break;
92
93 case eVarSetOperationReplace:
94 case eVarSetOperationAssign:
95 if (value_cstr && value_cstr[0])
96 {
97 m_value_was_set = true;
Jason Molendafb332f92012-10-11 06:05:54 +000098 m_current_value.SetFile(value_cstr, value_cstr[0] == '~');
Greg Clayton73844aa2012-08-22 17:17:09 +000099 }
100 else
101 {
102 error.SetErrorString("invalid value string");
103 }
104 break;
105
106 case eVarSetOperationInsertBefore:
107 case eVarSetOperationInsertAfter:
108 case eVarSetOperationRemove:
109 case eVarSetOperationAppend:
110 case eVarSetOperationInvalid:
111 error = OptionValue::SetValueFromCString (value_cstr, op);
112 break;
113 }
114 return error;
115}
116
117lldb::OptionValueSP
118OptionValueFileSpec::DeepCopy () const
119{
120 return OptionValueSP(new OptionValueFileSpec(*this));
121}
122
123
124size_t
125OptionValueFileSpec::AutoComplete (CommandInterpreter &interpreter,
126 const char *s,
127 int match_start_point,
128 int max_return_elements,
129 bool &word_complete,
130 StringList &matches)
131{
132 word_complete = false;
133 matches.Clear();
134 CommandCompletions::InvokeCommonCompletionCallbacks (interpreter,
Greg Clayton437b5bc2012-09-27 22:26:11 +0000135 m_completion_mask,
Greg Clayton73844aa2012-08-22 17:17:09 +0000136 s,
137 match_start_point,
138 max_return_elements,
139 NULL,
140 word_complete,
141 matches);
142 return matches.GetSize();
143}
144
145
146
Greg Claytonc6e82e42012-08-22 18:39:03 +0000147const lldb::DataBufferSP &
Greg Claytonfc04d242012-08-30 18:15:10 +0000148OptionValueFileSpec::GetFileContents(bool null_terminate)
Greg Claytonc6e82e42012-08-22 18:39:03 +0000149{
150 if (!m_data_sp && m_current_value)
Greg Claytonfc04d242012-08-30 18:15:10 +0000151 {
152 if (null_terminate)
153 m_data_sp = m_current_value.ReadFileContentsAsCString();
154 else
155 m_data_sp = m_current_value.ReadFileContents();
156 }
Greg Claytonc6e82e42012-08-22 18:39:03 +0000157 return m_data_sp;
158}
159
Greg Clayton73844aa2012-08-22 17:17:09 +0000160