Greg Clayton | 57b3c6b | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 1 | //===-- OptionGroupFormat.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/OptionGroupFormat.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 | |
Greg Clayton | a42880a | 2011-10-25 06:44:01 +0000 | [diff] [blame^] | 21 | OptionGroupFormat::OptionGroupFormat (lldb::Format default_format, |
| 22 | uint64_t default_byte_size, |
| 23 | uint64_t default_count) : |
| 24 | m_format (default_format, default_format), |
| 25 | m_byte_size (default_byte_size, default_byte_size), |
| 26 | m_count (default_count, default_count) |
Greg Clayton | 57b3c6b | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 27 | { |
| 28 | } |
| 29 | |
| 30 | OptionGroupFormat::~OptionGroupFormat () |
| 31 | { |
| 32 | } |
| 33 | |
| 34 | static OptionDefinition |
| 35 | g_option_table[] = |
| 36 | { |
Greg Clayton | a42880a | 2011-10-25 06:44:01 +0000 | [diff] [blame^] | 37 | { LLDB_OPT_SET_1, false, "format",'f', required_argument, NULL, 0, eArgTypeFormat , "Specify a format to be used for display."}, |
| 38 | { LLDB_OPT_SET_2, false, "size" ,'s', required_argument, NULL, 0, eArgTypeByteSize, "The size in bytes to use when displaying with the selected format."}, |
| 39 | { LLDB_OPT_SET_3, false, "count" ,'c', required_argument, NULL, 0, eArgTypeCount , "The number of total items to display."}, |
Greg Clayton | 57b3c6b | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 40 | }; |
Greg Clayton | 57b3c6b | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 41 | |
| 42 | uint32_t |
| 43 | OptionGroupFormat::GetNumDefinitions () |
| 44 | { |
Greg Clayton | a42880a | 2011-10-25 06:44:01 +0000 | [diff] [blame^] | 45 | if (m_byte_size.GetDefaultValue() < UINT64_MAX) |
| 46 | { |
| 47 | if (m_count.GetDefaultValue() < UINT64_MAX) |
| 48 | return 3; |
| 49 | else |
| 50 | return 2; |
| 51 | } |
| 52 | return 1; |
Greg Clayton | 57b3c6b | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | const OptionDefinition * |
| 56 | OptionGroupFormat::GetDefinitions () |
| 57 | { |
| 58 | return g_option_table; |
| 59 | } |
| 60 | |
| 61 | Error |
| 62 | OptionGroupFormat::SetOptionValue (CommandInterpreter &interpreter, |
Greg Clayton | 56bbdaf | 2011-04-28 20:55:26 +0000 | [diff] [blame] | 63 | uint32_t option_idx, |
| 64 | const char *option_arg) |
Greg Clayton | 57b3c6b | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 65 | { |
| 66 | Error error; |
| 67 | char short_option = (char) g_option_table[option_idx].short_option; |
| 68 | |
| 69 | switch (short_option) |
| 70 | { |
| 71 | case 'f': |
| 72 | error = m_format.SetValueFromCString (option_arg); |
| 73 | break; |
| 74 | |
Greg Clayton | a42880a | 2011-10-25 06:44:01 +0000 | [diff] [blame^] | 75 | case 'c': |
| 76 | if (m_count.GetDefaultValue() == 0) |
| 77 | { |
| 78 | error.SetErrorString ("--count option is disabled"); |
| 79 | } |
| 80 | else |
| 81 | { |
| 82 | error = m_count.SetValueFromCString (option_arg); |
| 83 | if (m_count.GetCurrentValue() == 0) |
| 84 | error.SetErrorStringWithFormat("invalid --count option value '%s'", option_arg); |
| 85 | } |
| 86 | break; |
| 87 | |
| 88 | case 's': |
| 89 | if (m_byte_size.GetDefaultValue() == 0) |
| 90 | { |
| 91 | error.SetErrorString ("--size option is disabled"); |
| 92 | } |
| 93 | else |
| 94 | { |
| 95 | error = m_byte_size.SetValueFromCString (option_arg); |
| 96 | if (m_byte_size.GetCurrentValue() == 0) |
| 97 | error.SetErrorStringWithFormat("invalid --size option value '%s'", option_arg); |
| 98 | } |
| 99 | break; |
| 100 | |
Greg Clayton | 57b3c6b | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 101 | default: |
| 102 | error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option); |
| 103 | break; |
| 104 | } |
| 105 | |
| 106 | return error; |
| 107 | } |
| 108 | |
| 109 | void |
| 110 | OptionGroupFormat::OptionParsingStarting (CommandInterpreter &interpreter) |
| 111 | { |
| 112 | m_format.Clear(); |
Greg Clayton | a42880a | 2011-10-25 06:44:01 +0000 | [diff] [blame^] | 113 | m_byte_size.Clear(); |
| 114 | m_count.Clear(); |
Greg Clayton | 57b3c6b | 2011-04-27 22:04:39 +0000 | [diff] [blame] | 115 | } |