blob: 857d21e53f48c57fa65ad71f4047035dff7e5eca [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{
Zachary Turnerd37221d2014-07-09 16:31:49 +000036 { LLDB_OPT_SET_1 , false, "outfile", 'o', OptionParser::eRequiredArgument, nullptr, nullptr, 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,
Zachary Turnerd37221d2014-07-09 16:31:49 +000038 OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone ,
Bruce Mitchener58ef3912015-06-18 05:27:05 +000039 "Append to 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
Todd Fialae1cfbc72016-08-11 23:51:28 +000055OptionGroupOutputFile::SetOptionValue(uint32_t option_idx,
56 const char *option_arg,
57 ExecutionContext *execution_context)
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':
Pavel Labathc95f7e22015-02-20 11:14:59 +000065 error = m_file.SetValueFromString (option_arg);
Greg Clayton84c39662011-04-27 22:04:39 +000066 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
Todd Fialae1cfbc72016-08-11 23:51:28 +000081OptionGroupOutputFile::OptionParsingStarting(
82 ExecutionContext *execution_context)
Greg Clayton84c39662011-04-27 22:04:39 +000083{
84 m_file.Clear();
85 m_append.Clear();
86}