OptionValueFileSpec.cpp revision 254721
1254721Semaste//===-- OptionValueFileSpec.cpp ---------------------------------*- C++ -*-===// 2254721Semaste// 3254721Semaste// The LLVM Compiler Infrastructure 4254721Semaste// 5254721Semaste// This file is distributed under the University of Illinois Open Source 6254721Semaste// License. See LICENSE.TXT for details. 7254721Semaste// 8254721Semaste//===----------------------------------------------------------------------===// 9254721Semaste 10254721Semaste#include "lldb/lldb-python.h" 11254721Semaste 12254721Semaste#include "lldb/Interpreter/OptionValueFileSpec.h" 13254721Semaste 14254721Semaste// C Includes 15254721Semaste// C++ Includes 16254721Semaste// Other libraries and framework includes 17254721Semaste// Project includes 18254721Semaste#include "lldb/Core/State.h" 19254721Semaste#include "lldb/DataFormatters/FormatManager.h" 20254721Semaste#include "lldb/Interpreter/Args.h" 21254721Semaste#include "lldb/Interpreter/CommandCompletions.h" 22254721Semaste 23254721Semasteusing namespace lldb; 24254721Semasteusing namespace lldb_private; 25254721Semaste 26254721Semaste 27254721SemasteOptionValueFileSpec::OptionValueFileSpec () : 28254721Semaste OptionValue(), 29254721Semaste m_current_value (), 30254721Semaste m_default_value (), 31254721Semaste m_data_sp(), 32254721Semaste m_completion_mask (CommandCompletions::eDiskFileCompletion) 33254721Semaste{ 34254721Semaste} 35254721Semaste 36254721SemasteOptionValueFileSpec::OptionValueFileSpec (const FileSpec &value) : 37254721Semaste OptionValue(), 38254721Semaste m_current_value (value), 39254721Semaste m_default_value (value), 40254721Semaste m_data_sp(), 41254721Semaste m_completion_mask (CommandCompletions::eDiskFileCompletion) 42254721Semaste{ 43254721Semaste} 44254721Semaste 45254721SemasteOptionValueFileSpec::OptionValueFileSpec (const FileSpec ¤t_value, 46254721Semaste const FileSpec &default_value) : 47254721Semaste OptionValue(), 48254721Semaste m_current_value (current_value), 49254721Semaste m_default_value (default_value), 50254721Semaste m_data_sp(), 51254721Semaste m_completion_mask (CommandCompletions::eDiskFileCompletion) 52254721Semaste{ 53254721Semaste} 54254721Semaste 55254721Semastevoid 56254721SemasteOptionValueFileSpec::DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) 57254721Semaste{ 58254721Semaste if (dump_mask & eDumpOptionType) 59254721Semaste strm.Printf ("(%s)", GetTypeAsCString ()); 60254721Semaste if (dump_mask & eDumpOptionValue) 61254721Semaste { 62254721Semaste if (dump_mask & eDumpOptionType) 63254721Semaste strm.PutCString (" = "); 64254721Semaste 65254721Semaste if (m_current_value) 66254721Semaste { 67254721Semaste strm << '"' << m_current_value.GetPath().c_str() << '"'; 68254721Semaste } 69254721Semaste } 70254721Semaste} 71254721Semaste 72254721SemasteError 73254721SemasteOptionValueFileSpec::SetValueFromCString (const char *value_cstr, 74254721Semaste VarSetOperationType op) 75254721Semaste{ 76254721Semaste Error error; 77254721Semaste switch (op) 78254721Semaste { 79254721Semaste case eVarSetOperationClear: 80254721Semaste Clear (); 81254721Semaste break; 82254721Semaste 83254721Semaste case eVarSetOperationReplace: 84254721Semaste case eVarSetOperationAssign: 85254721Semaste if (value_cstr && value_cstr[0]) 86254721Semaste { 87254721Semaste Args args(value_cstr); 88254721Semaste if (args.GetArgumentCount() == 1) 89254721Semaste { 90254721Semaste const char *path = args.GetArgumentAtIndex(0); 91254721Semaste m_value_was_set = true; 92254721Semaste m_current_value.SetFile(path, true); 93254721Semaste } 94254721Semaste else 95254721Semaste { 96254721Semaste error.SetErrorString("please supply a single path argument for this file or quote the path if it contains spaces"); 97254721Semaste } 98254721Semaste } 99254721Semaste else 100254721Semaste { 101254721Semaste error.SetErrorString("invalid value string"); 102254721Semaste } 103254721Semaste break; 104254721Semaste 105254721Semaste case eVarSetOperationInsertBefore: 106254721Semaste case eVarSetOperationInsertAfter: 107254721Semaste case eVarSetOperationRemove: 108254721Semaste case eVarSetOperationAppend: 109254721Semaste case eVarSetOperationInvalid: 110254721Semaste error = OptionValue::SetValueFromCString (value_cstr, op); 111254721Semaste break; 112254721Semaste } 113254721Semaste return error; 114254721Semaste} 115254721Semaste 116254721Semastelldb::OptionValueSP 117254721SemasteOptionValueFileSpec::DeepCopy () const 118254721Semaste{ 119254721Semaste return OptionValueSP(new OptionValueFileSpec(*this)); 120254721Semaste} 121254721Semaste 122254721Semaste 123254721Semastesize_t 124254721SemasteOptionValueFileSpec::AutoComplete (CommandInterpreter &interpreter, 125254721Semaste const char *s, 126254721Semaste int match_start_point, 127254721Semaste int max_return_elements, 128254721Semaste bool &word_complete, 129254721Semaste StringList &matches) 130254721Semaste{ 131254721Semaste word_complete = false; 132254721Semaste matches.Clear(); 133254721Semaste CommandCompletions::InvokeCommonCompletionCallbacks (interpreter, 134254721Semaste m_completion_mask, 135254721Semaste s, 136254721Semaste match_start_point, 137254721Semaste max_return_elements, 138254721Semaste NULL, 139254721Semaste word_complete, 140254721Semaste matches); 141254721Semaste return matches.GetSize(); 142254721Semaste} 143254721Semaste 144254721Semaste 145254721Semaste 146254721Semasteconst lldb::DataBufferSP & 147254721SemasteOptionValueFileSpec::GetFileContents(bool null_terminate) 148254721Semaste{ 149254721Semaste if (!m_data_sp && m_current_value) 150254721Semaste { 151254721Semaste if (null_terminate) 152254721Semaste m_data_sp = m_current_value.ReadFileContentsAsCString(); 153254721Semaste else 154254721Semaste m_data_sp = m_current_value.ReadFileContents(); 155254721Semaste } 156254721Semaste return m_data_sp; 157254721Semaste} 158254721Semaste 159254721Semaste 160