1 //===-- 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 21 using namespace lldb; 22 using namespace lldb_private; 23 24 25 OptionValueFileSpec::OptionValueFileSpec () : 26 OptionValue(), 27 m_current_value (), 28 m_default_value (), 29 m_data_sp(), 30 m_completion_mask (CommandCompletions::eDiskFileCompletion) 31 { 32 } 33 34 OptionValueFileSpec::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 43 OptionValueFileSpec::OptionValueFileSpec (const FileSpec ¤t_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 53 void 54 OptionValueFileSpec::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 80 Error 81 OptionValueFileSpec::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, value_cstr[0] == '~'); 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 115 lldb::OptionValueSP 116 OptionValueFileSpec::DeepCopy () const 117 { 118 return OptionValueSP(new OptionValueFileSpec(*this)); 119 } 120 121 122 size_t 123 OptionValueFileSpec::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, 133 m_completion_mask, 134 s, 135 match_start_point, 136 max_return_elements, 137 NULL, 138 word_complete, 139 matches); 140 return matches.GetSize(); 141 } 142 143 144 145 const lldb::DataBufferSP & 146 OptionValueFileSpec::GetFileContents(bool null_terminate) 147 { 148 if (!m_data_sp && m_current_value) 149 { 150 if (null_terminate) 151 m_data_sp = m_current_value.ReadFileContentsAsCString(); 152 else 153 m_data_sp = m_current_value.ReadFileContents(); 154 } 155 return m_data_sp; 156 } 157 158 159