diff --git a/lldb/include/lldb/Host/OptionParser.h b/lldb/include/lldb/Host/OptionParser.h new file mode 100644 index 000000000000..410e4d9f9468 --- /dev/null +++ b/lldb/include/lldb/Host/OptionParser.h @@ -0,0 +1,53 @@ +//===-- OptionParser.h ------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_OptionParser_h_ +#define liblldb_OptionParser_h_ + +namespace lldb_private { + +typedef struct Option +{ + // name of long option + const char *name; + // one of no_argument, required_argument, and optional_argument: + // whether option takes an argument + int has_arg; + // if not NULL, set *flag to val when option found + int *flag; + // if flag not NULL, value to set *flag to; else return value + int val; +} Option; + +class OptionParser +{ +public: + enum OptionArgument + { + eNoArgument = 0, + eRequiredArgument, + eOptionalArgument + }; + + static void Prepare(); + + static void EnableError(bool error); + + static int Parse(int argc, char * const argv [], + const char *optstring, + const Option *longopts, int *longindex); + + static char* GetOptionArgument(); + static int GetOptionIndex(); + static int GetOptionErrorCause(); +}; + +} + +#endif // liblldb_OptionParser_h_ diff --git a/lldb/include/lldb/Interpreter/Args.h b/lldb/include/lldb/Interpreter/Args.h index d06c3e56aecd..27feca63e4ad 100644 --- a/lldb/include/lldb/Interpreter/Args.h +++ b/lldb/include/lldb/Interpreter/Args.h @@ -11,8 +11,6 @@ #define liblldb_Command_h_ // C Includes -#include - // C++ Includes #include #include @@ -24,6 +22,7 @@ #include "lldb/lldb-private-types.h" #include "lldb/lldb-types.h" #include "lldb/Core/Error.h" +#include "lldb/Host/OptionParser.h" namespace lldb_private { @@ -319,7 +318,7 @@ public: ParseOptions (Options &options); size_t - FindArgumentIndexForOption (struct option *long_options, int long_options_index); + FindArgumentIndexForOption (Option *long_options, int long_options_index); bool IsPositionalArgument (const char *arg); diff --git a/lldb/include/lldb/Interpreter/Options.h b/lldb/include/lldb/Interpreter/Options.h index ad4e283ba7ff..2b4ac1190557 100644 --- a/lldb/include/lldb/Interpreter/Options.h +++ b/lldb/include/lldb/Interpreter/Options.h @@ -11,7 +11,6 @@ #define liblldb_Options_h_ // C Includes -#include // C++ Includes #include @@ -141,7 +140,7 @@ public: /// @see Args::ParseOptions (Options&) /// @see man getopt_long_only //------------------------------------------------------------------ - struct option * + Option * GetLongOptions (); // This gets passed the short option as an integer... @@ -309,7 +308,7 @@ protected: typedef std::vector OptionSetVector; CommandInterpreter &m_interpreter; - std::vector m_getopt_table; + std::vector