OptionParser.cpp revision 263363
1//===-- source/Host/common/OptionParser.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
10#include "lldb/Host/OptionParser.h"
11
12#ifdef _MSC_VER
13#include "../windows/msvc/getopt.inc"
14#else
15#ifdef _WIN32
16#define _BSD_SOURCE // Required so that getopt.h defines optreset
17#endif
18#include <getopt.h>
19#endif
20
21using namespace lldb_private;
22
23void
24OptionParser::Prepare()
25{
26#ifdef __GLIBC__
27    optind = 0;
28#else
29    optreset = 1;
30    optind = 1;
31#endif
32}
33
34void
35OptionParser::EnableError(bool error)
36{
37    opterr = error ? 1 : 0;
38}
39
40int
41OptionParser::Parse(int argc, char * const argv [],
42        const char *optstring,
43        const Option *longopts, int *longindex)
44{
45    return getopt_long_only(argc, argv, optstring, (const option*)longopts, longindex);
46}
47
48char* OptionParser::GetOptionArgument()
49{
50    return optarg;
51}
52
53int OptionParser::GetOptionIndex()
54{
55    return optind;
56}
57
58int OptionParser::GetOptionErrorCause()
59{
60    return optopt;
61}
62