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