blob: 59bd82e79d195d97b08ccf2317b4a518434b9827 [file] [log] [blame]
Greg Clayton84c39662011-04-27 22:04:39 +00001//===-- OptionGroupOutputFile.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
Johnny Chen4bee32e2011-05-13 20:21:08 +000010#include "lldb/Interpreter/OptionGroupOutputFile.h"
Greg Clayton84c39662011-04-27 22:04:39 +000011
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
Johnny Chen7c575b32011-09-10 00:48:33 +000016#include "lldb/Utility/Utils.h"
Greg Clayton84c39662011-04-27 22:04:39 +000017
18using namespace lldb;
19using namespace lldb_private;
20
21OptionGroupOutputFile::OptionGroupOutputFile() :
22 m_file (),
23 m_append (false, false)
24{
25}
26
27OptionGroupOutputFile::~OptionGroupOutputFile ()
28{
29}
30
Saleem Abdulrasool44edda02014-03-18 04:43:47 +000031static const uint32_t SHORT_OPTION_APND = 0x61706e64; // 'apnd'
32
Greg Clayton84c39662011-04-27 22:04:39 +000033static OptionDefinition
34g_option_table[] =
35{
Virgile Belloe2607b52013-09-05 16:42:23 +000036 { LLDB_OPT_SET_1 , false, "outfile", 'o', OptionParser::eRequiredArgument, NULL, 0, eArgTypeFilename , "Specify a path for capturing command output."},
Saleem Abdulrasool44edda02014-03-18 04:43:47 +000037 { LLDB_OPT_SET_1 , false, "append-outfile" , SHORT_OPTION_APND,
38 OptionParser::eNoArgument, NULL, 0, eArgTypeNone ,
39 "Append to the the file specified with '--outfile <path>'."},
Greg Clayton84c39662011-04-27 22:04:39 +000040};
41
Greg Clayton84c39662011-04-27 22:04:39 +000042uint32_t
43OptionGroupOutputFile::GetNumDefinitions ()
44{
Johnny Chen6ebc8c452012-05-15 23:21:36 +000045 return llvm::array_lengthof(g_option_table);
Greg Clayton84c39662011-04-27 22:04:39 +000046}
47
48const OptionDefinition *
49OptionGroupOutputFile::GetDefinitions ()
50{
51 return g_option_table;
52}
53
54Error
55OptionGroupOutputFile::SetOptionValue (CommandInterpreter &interpreter,
Greg Clayton3bcdfc02012-12-04 00:32:51 +000056 uint32_t option_idx,
57 const char *option_arg)
Greg Clayton84c39662011-04-27 22:04:39 +000058{
59 Error error;
Greg Clayton3bcdfc02012-12-04 00:32:51 +000060 const int short_option = g_option_table[option_idx].short_option;
Greg Clayton84c39662011-04-27 22:04:39 +000061
62 switch (short_option)
63 {
64 case 'o':
65 error = m_file.SetValueFromCString (option_arg);
66 break;
67
Saleem Abdulrasool44edda02014-03-18 04:43:47 +000068 case SHORT_OPTION_APND:
Greg Clayton84c39662011-04-27 22:04:39 +000069 m_append.SetCurrentValue(true);
70 break;
71
72 default:
Greg Clayton86edbf42011-10-26 00:56:27 +000073 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
Greg Clayton84c39662011-04-27 22:04:39 +000074 break;
75 }
76
77 return error;
78}
79
80void
81OptionGroupOutputFile::OptionParsingStarting (CommandInterpreter &interpreter)
82{
83 m_file.Clear();
84 m_append.Clear();
85}