184c39663SGreg Clayton //===-- OptionGroupOutputFile.cpp -------------------------------*- C++ -*-===//
284c39663SGreg Clayton //
384c39663SGreg Clayton //                     The LLVM Compiler Infrastructure
484c39663SGreg Clayton //
584c39663SGreg Clayton // This file is distributed under the University of Illinois Open Source
684c39663SGreg Clayton // License. See LICENSE.TXT for details.
784c39663SGreg Clayton //
884c39663SGreg Clayton //===----------------------------------------------------------------------===//
984c39663SGreg Clayton 
10*4bee32e5SJohnny Chen #include "lldb/Interpreter/OptionGroupOutputFile.h"
1184c39663SGreg Clayton 
1284c39663SGreg Clayton // C Includes
1384c39663SGreg Clayton // C++ Includes
1484c39663SGreg Clayton // Other libraries and framework includes
1584c39663SGreg Clayton // Project includes
1684c39663SGreg Clayton 
1784c39663SGreg Clayton using namespace lldb;
1884c39663SGreg Clayton using namespace lldb_private;
1984c39663SGreg Clayton 
2084c39663SGreg Clayton OptionGroupOutputFile::OptionGroupOutputFile() :
2184c39663SGreg Clayton     m_file (),
2284c39663SGreg Clayton     m_append (false, false)
2384c39663SGreg Clayton {
2484c39663SGreg Clayton }
2584c39663SGreg Clayton 
2684c39663SGreg Clayton OptionGroupOutputFile::~OptionGroupOutputFile ()
2784c39663SGreg Clayton {
2884c39663SGreg Clayton }
2984c39663SGreg Clayton 
3084c39663SGreg Clayton static OptionDefinition
3184c39663SGreg Clayton g_option_table[] =
3284c39663SGreg Clayton {
3384c39663SGreg Clayton { LLDB_OPT_SET_1 , false, "outfile", 'o', required_argument, NULL, 0, eArgTypePath , "Specify a path for capturing command output."},
3484c39663SGreg Clayton { LLDB_OPT_SET_1 , false, "append-outfile" , 'A', no_argument, NULL, 0, eArgTypeNone , "Append to the the file specified with '--outfile <path>'."},
3584c39663SGreg Clayton };
3684c39663SGreg Clayton 
3784c39663SGreg Clayton const uint32_t k_num_file_options = sizeof(g_option_table)/sizeof(OptionDefinition);
3884c39663SGreg Clayton 
3984c39663SGreg Clayton uint32_t
4084c39663SGreg Clayton OptionGroupOutputFile::GetNumDefinitions ()
4184c39663SGreg Clayton {
4284c39663SGreg Clayton     return k_num_file_options;
4384c39663SGreg Clayton }
4484c39663SGreg Clayton 
4584c39663SGreg Clayton const OptionDefinition *
4684c39663SGreg Clayton OptionGroupOutputFile::GetDefinitions ()
4784c39663SGreg Clayton {
4884c39663SGreg Clayton     return g_option_table;
4984c39663SGreg Clayton }
5084c39663SGreg Clayton 
5184c39663SGreg Clayton Error
5284c39663SGreg Clayton OptionGroupOutputFile::SetOptionValue (CommandInterpreter &interpreter,
5384c39663SGreg Clayton                                          uint32_t option_idx,
5484c39663SGreg Clayton                                          const char *option_arg)
5584c39663SGreg Clayton {
5684c39663SGreg Clayton     Error error;
5784c39663SGreg Clayton     char short_option = (char) g_option_table[option_idx].short_option;
5884c39663SGreg Clayton 
5984c39663SGreg Clayton     switch (short_option)
6084c39663SGreg Clayton     {
6184c39663SGreg Clayton         case 'o':
6284c39663SGreg Clayton             error = m_file.SetValueFromCString (option_arg);
6384c39663SGreg Clayton             break;
6484c39663SGreg Clayton 
6584c39663SGreg Clayton         case 'A':
6684c39663SGreg Clayton             m_append.SetCurrentValue(true);
6784c39663SGreg Clayton             break;
6884c39663SGreg Clayton 
6984c39663SGreg Clayton         default:
7084c39663SGreg Clayton             error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
7184c39663SGreg Clayton             break;
7284c39663SGreg Clayton     }
7384c39663SGreg Clayton 
7484c39663SGreg Clayton     return error;
7584c39663SGreg Clayton }
7684c39663SGreg Clayton 
7784c39663SGreg Clayton void
7884c39663SGreg Clayton OptionGroupOutputFile::OptionParsingStarting (CommandInterpreter &interpreter)
7984c39663SGreg Clayton {
8084c39663SGreg Clayton     m_file.Clear();
8184c39663SGreg Clayton     m_append.Clear();
8284c39663SGreg Clayton }
83