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 
104bee32e5SJohnny 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
167c575b3bSJohnny Chen #include "lldb/Utility/Utils.h"
1784c39663SGreg Clayton 
1884c39663SGreg Clayton using namespace lldb;
1984c39663SGreg Clayton using namespace lldb_private;
2084c39663SGreg Clayton 
2184c39663SGreg Clayton OptionGroupOutputFile::OptionGroupOutputFile() :
2284c39663SGreg Clayton     m_file (),
2384c39663SGreg Clayton     m_append (false, false)
2484c39663SGreg Clayton {
2584c39663SGreg Clayton }
2684c39663SGreg Clayton 
2784c39663SGreg Clayton OptionGroupOutputFile::~OptionGroupOutputFile ()
2884c39663SGreg Clayton {
2984c39663SGreg Clayton }
3084c39663SGreg Clayton 
3184c39663SGreg Clayton static OptionDefinition
3284c39663SGreg Clayton g_option_table[] =
3384c39663SGreg Clayton {
3484c39663SGreg Clayton     { LLDB_OPT_SET_1 , false, "outfile", 'o', required_argument, NULL, 0, eArgTypePath , "Specify a path for capturing command output."},
3584c39663SGreg Clayton     { LLDB_OPT_SET_1 , false, "append-outfile" , 'A', no_argument, NULL, 0, eArgTypeNone , "Append to the the file specified with '--outfile <path>'."},
3684c39663SGreg Clayton };
3784c39663SGreg Clayton 
3884c39663SGreg Clayton uint32_t
3984c39663SGreg Clayton OptionGroupOutputFile::GetNumDefinitions ()
4084c39663SGreg Clayton {
417c575b3bSJohnny Chen     return arraysize(g_option_table);
4284c39663SGreg Clayton }
4384c39663SGreg Clayton 
4484c39663SGreg Clayton const OptionDefinition *
4584c39663SGreg Clayton OptionGroupOutputFile::GetDefinitions ()
4684c39663SGreg Clayton {
4784c39663SGreg Clayton     return g_option_table;
4884c39663SGreg Clayton }
4984c39663SGreg Clayton 
5084c39663SGreg Clayton Error
5184c39663SGreg Clayton OptionGroupOutputFile::SetOptionValue (CommandInterpreter &interpreter,
5284c39663SGreg Clayton                                          uint32_t option_idx,
5384c39663SGreg Clayton                                          const char *option_arg)
5484c39663SGreg Clayton {
5584c39663SGreg Clayton     Error error;
5684c39663SGreg Clayton     char short_option = (char) g_option_table[option_idx].short_option;
5784c39663SGreg Clayton 
5884c39663SGreg Clayton     switch (short_option)
5984c39663SGreg Clayton     {
6084c39663SGreg Clayton         case 'o':
6184c39663SGreg Clayton             error = m_file.SetValueFromCString (option_arg);
6284c39663SGreg Clayton             break;
6384c39663SGreg Clayton 
6484c39663SGreg Clayton         case 'A':
6584c39663SGreg Clayton             m_append.SetCurrentValue(true);
6684c39663SGreg Clayton             break;
6784c39663SGreg Clayton 
6884c39663SGreg Clayton         default:
69*86edbf41SGreg Clayton             error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
7084c39663SGreg Clayton             break;
7184c39663SGreg Clayton     }
7284c39663SGreg Clayton 
7384c39663SGreg Clayton     return error;
7484c39663SGreg Clayton }
7584c39663SGreg Clayton 
7684c39663SGreg Clayton void
7784c39663SGreg Clayton OptionGroupOutputFile::OptionParsingStarting (CommandInterpreter &interpreter)
7884c39663SGreg Clayton {
7984c39663SGreg Clayton     m_file.Clear();
8084c39663SGreg Clayton     m_append.Clear();
8184c39663SGreg Clayton }
82