blob: ad4f371d8369e0cfe8f5e9e3ccd4c09c95a27cfa [file] [log] [blame]
Greg Clayton57b3c6b2011-04-27 22:04:39 +00001//===-- 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 Chena0f34692011-05-13 20:21:08 +000010#include "lldb/Interpreter/OptionGroupFormat.h"
Greg Clayton57b3c6b2011-04-27 22:04:39 +000011
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
Johnny Chen4003f572011-09-10 00:48:33 +000016#include "lldb/Utility/Utils.h"
Greg Clayton57b3c6b2011-04-27 22:04:39 +000017
18using namespace lldb;
19using namespace lldb_private;
20
Greg Claytona42880a2011-10-25 06:44:01 +000021OptionGroupFormat::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 Clayton57b3c6b2011-04-27 22:04:39 +000027{
28}
29
30OptionGroupFormat::~OptionGroupFormat ()
31{
32}
33
34static OptionDefinition
35g_option_table[] =
36{
Greg Claytona42880a2011-10-25 06:44:01 +000037{ 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 Clayton57b3c6b2011-04-27 22:04:39 +000040};
Greg Clayton57b3c6b2011-04-27 22:04:39 +000041
42uint32_t
43OptionGroupFormat::GetNumDefinitions ()
44{
Greg Claytona42880a2011-10-25 06:44:01 +000045 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 Clayton57b3c6b2011-04-27 22:04:39 +000053}
54
55const OptionDefinition *
56OptionGroupFormat::GetDefinitions ()
57{
58 return g_option_table;
59}
60
61Error
62OptionGroupFormat::SetOptionValue (CommandInterpreter &interpreter,
Greg Clayton56bbdaf2011-04-28 20:55:26 +000063 uint32_t option_idx,
64 const char *option_arg)
Greg Clayton57b3c6b2011-04-27 22:04:39 +000065{
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 Claytona42880a2011-10-25 06:44:01 +000075 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 Clayton57b3c6b2011-04-27 22:04:39 +0000101 default:
102 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
103 break;
104 }
105
106 return error;
107}
108
109void
110OptionGroupFormat::OptionParsingStarting (CommandInterpreter &interpreter)
111{
112 m_format.Clear();
Greg Claytona42880a2011-10-25 06:44:01 +0000113 m_byte_size.Clear();
114 m_count.Clear();
Greg Clayton57b3c6b2011-04-27 22:04:39 +0000115}