Greg Clayton | 57b3c6b | 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 | a0f3469 | 2011-05-13 20:21:08 +0000 | [diff] [blame] | 10 | #include "lldb/Interpreter/OptionGroupOutputFile.h" |
Greg Clayton | 57b3c6b | 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 | 4003f57 | 2011-09-10 00:48:33 +0000 | [diff] [blame] | 16 | #include "lldb/Utility/Utils.h" |
Greg Clayton | 57b3c6b | 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 | |
| 31 | static OptionDefinition |
| 32 | g_option_table[] = |
| 33 | { |
Sean Callanan | 9a91ef6 | 2012-10-24 01:12:14 +0000 | [diff] [blame] | 34 | { LLDB_OPT_SET_1 , false, "outfile", 'o', required_argument, NULL, 0, eArgTypeFilename , "Specify a path for capturing command output."}, |
Greg Clayton | 6475c42 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 35 | { LLDB_OPT_SET_1 , false, "append-outfile" , 'apnd', no_argument, NULL, 0, eArgTypeNone , "Append to the the file specified with '--outfile <path>'."}, |
Greg Clayton | 57b3c6b | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 36 | }; |
| 37 | |
Greg Clayton | 57b3c6b | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 38 | uint32_t |
| 39 | OptionGroupOutputFile::GetNumDefinitions () |
| 40 | { |
Johnny Chen | 08af598 | 2012-05-15 23:21:36 +0000 | [diff] [blame] | 41 | return llvm::array_lengthof(g_option_table); |
Greg Clayton | 57b3c6b | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | const OptionDefinition * |
| 45 | OptionGroupOutputFile::GetDefinitions () |
| 46 | { |
| 47 | return g_option_table; |
| 48 | } |
| 49 | |
| 50 | Error |
| 51 | OptionGroupOutputFile::SetOptionValue (CommandInterpreter &interpreter, |
Greg Clayton | 6475c42 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 52 | uint32_t option_idx, |
| 53 | const char *option_arg) |
Greg Clayton | 57b3c6b | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 54 | { |
| 55 | Error error; |
Greg Clayton | 6475c42 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 56 | const int short_option = g_option_table[option_idx].short_option; |
Greg Clayton | 57b3c6b | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 57 | |
| 58 | switch (short_option) |
| 59 | { |
| 60 | case 'o': |
| 61 | error = m_file.SetValueFromCString (option_arg); |
| 62 | break; |
| 63 | |
Greg Clayton | 6475c42 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 64 | case 'apnd': |
Greg Clayton | 57b3c6b | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 65 | m_append.SetCurrentValue(true); |
| 66 | break; |
| 67 | |
| 68 | default: |
Greg Clayton | 9c23673 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 69 | error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option); |
Greg Clayton | 57b3c6b | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 70 | break; |
| 71 | } |
| 72 | |
| 73 | return error; |
| 74 | } |
| 75 | |
| 76 | void |
| 77 | OptionGroupOutputFile::OptionParsingStarting (CommandInterpreter &interpreter) |
| 78 | { |
| 79 | m_file.Clear(); |
| 80 | m_append.Clear(); |
| 81 | } |