Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 1 | //===-- 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 Chen | 4bee32e | 2011-05-13 20:21:08 +0000 | [diff] [blame] | 10 | #include "lldb/Interpreter/OptionGroupOutputFile.h" |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 11 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
Johnny Chen | 7c575b3 | 2011-09-10 00:48:33 +0000 | [diff] [blame] | 16 | #include "lldb/Utility/Utils.h" |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 17 | |
| 18 | using namespace lldb; |
| 19 | using namespace lldb_private; |
| 20 | |
| 21 | OptionGroupOutputFile::OptionGroupOutputFile() : |
| 22 | m_file (), |
| 23 | m_append (false, false) |
| 24 | { |
| 25 | } |
| 26 | |
| 27 | OptionGroupOutputFile::~OptionGroupOutputFile () |
| 28 | { |
| 29 | } |
| 30 | |
Saleem Abdulrasool | 44edda0 | 2014-03-18 04:43:47 +0000 | [diff] [blame^] | 31 | static const uint32_t SHORT_OPTION_APND = 0x61706e64; // 'apnd' |
| 32 | |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 33 | static OptionDefinition |
| 34 | g_option_table[] = |
| 35 | { |
Virgile Bello | e2607b5 | 2013-09-05 16:42:23 +0000 | [diff] [blame] | 36 | { LLDB_OPT_SET_1 , false, "outfile", 'o', OptionParser::eRequiredArgument, NULL, 0, eArgTypeFilename , "Specify a path for capturing command output."}, |
Saleem Abdulrasool | 44edda0 | 2014-03-18 04:43:47 +0000 | [diff] [blame^] | 37 | { 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 Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 40 | }; |
| 41 | |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 42 | uint32_t |
| 43 | OptionGroupOutputFile::GetNumDefinitions () |
| 44 | { |
Johnny Chen | 6ebc8c45 | 2012-05-15 23:21:36 +0000 | [diff] [blame] | 45 | return llvm::array_lengthof(g_option_table); |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | const OptionDefinition * |
| 49 | OptionGroupOutputFile::GetDefinitions () |
| 50 | { |
| 51 | return g_option_table; |
| 52 | } |
| 53 | |
| 54 | Error |
| 55 | OptionGroupOutputFile::SetOptionValue (CommandInterpreter &interpreter, |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 56 | uint32_t option_idx, |
| 57 | const char *option_arg) |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 58 | { |
| 59 | Error error; |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 60 | const int short_option = g_option_table[option_idx].short_option; |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 61 | |
| 62 | switch (short_option) |
| 63 | { |
| 64 | case 'o': |
| 65 | error = m_file.SetValueFromCString (option_arg); |
| 66 | break; |
| 67 | |
Saleem Abdulrasool | 44edda0 | 2014-03-18 04:43:47 +0000 | [diff] [blame^] | 68 | case SHORT_OPTION_APND: |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 69 | m_append.SetCurrentValue(true); |
| 70 | break; |
| 71 | |
| 72 | default: |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 73 | error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); |
Greg Clayton | 84c3966 | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 74 | break; |
| 75 | } |
| 76 | |
| 77 | return error; |
| 78 | } |
| 79 | |
| 80 | void |
| 81 | OptionGroupOutputFile::OptionParsingStarting (CommandInterpreter &interpreter) |
| 82 | { |
| 83 | m_file.Clear(); |
| 84 | m_append.Clear(); |
| 85 | } |