blob: 03608753658f4f9221919945f3e08c24442cb479 [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
24void
25OptionValueFileSpec::DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask)
26{
27 if (dump_mask & eDumpOptionType)
28 strm.Printf ("(%s)", GetTypeAsCString ());
29 if (dump_mask & eDumpOptionValue)
30 {
31 if (dump_mask & eDumpOptionType)
32 strm.PutCString (" = ");
33
34 if (m_current_value)
35 {
36 if (m_current_value.GetDirectory())
37 {
38 strm << '"' << m_current_value.GetDirectory();
39 if (m_current_value.GetFilename())
40 strm << '/' << m_current_value.GetFilename();
41 strm << '"';
42 }
43 else
44 {
45 strm << '"' << m_current_value.GetFilename() << '"';
46 }
47 }
48 }
49}
50
51Error
52OptionValueFileSpec::SetValueFromCString (const char *value_cstr,
53 VarSetOperationType op)
54{
55 Error error;
56 switch (op)
57 {
58 case eVarSetOperationClear:
59 Clear ();
60 break;
61
62 case eVarSetOperationReplace:
63 case eVarSetOperationAssign:
64 if (value_cstr && value_cstr[0])
65 {
66 m_value_was_set = true;
67 m_current_value.SetFile(value_cstr, false);
68 }
69 else
70 {
71 error.SetErrorString("invalid value string");
72 }
73 break;
74
75 case eVarSetOperationInsertBefore:
76 case eVarSetOperationInsertAfter:
77 case eVarSetOperationRemove:
78 case eVarSetOperationAppend:
79 case eVarSetOperationInvalid:
80 error = OptionValue::SetValueFromCString (value_cstr, op);
81 break;
82 }
83 return error;
84}
85
86lldb::OptionValueSP
87OptionValueFileSpec::DeepCopy () const
88{
89 return OptionValueSP(new OptionValueFileSpec(*this));
90}
91
92
93size_t
94OptionValueFileSpec::AutoComplete (CommandInterpreter &interpreter,
95 const char *s,
96 int match_start_point,
97 int max_return_elements,
98 bool &word_complete,
99 StringList &matches)
100{
101 word_complete = false;
102 matches.Clear();
103 CommandCompletions::InvokeCommonCompletionCallbacks (interpreter,
104 CommandCompletions::eDiskFileCompletion,
105 s,
106 match_start_point,
107 max_return_elements,
108 NULL,
109 word_complete,
110 matches);
111 return matches.GetSize();
112}
113
114
115
Greg Claytonc6e82e42012-08-22 18:39:03 +0000116const lldb::DataBufferSP &
Greg Claytonfc04d242012-08-30 18:15:10 +0000117OptionValueFileSpec::GetFileContents(bool null_terminate)
Greg Claytonc6e82e42012-08-22 18:39:03 +0000118{
119 if (!m_data_sp && m_current_value)
Greg Claytonfc04d242012-08-30 18:15:10 +0000120 {
121 if (null_terminate)
122 m_data_sp = m_current_value.ReadFileContentsAsCString();
123 else
124 m_data_sp = m_current_value.ReadFileContents();
125 }
Greg Claytonc6e82e42012-08-22 18:39:03 +0000126 return m_data_sp;
127}
128
Greg Clayton73844aa2012-08-22 17:17:09 +0000129