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 
21 using namespace lldb_private;
22 
23 void
24 OptionParser::Prepare()
25 {
26 #ifdef __GLIBC__
27     optind = 0;
28 #else
29     optreset = 1;
30     optind = 1;
31 #endif
32 }
33 
34 void
35 OptionParser::EnableError(bool error)
36 {
37     opterr = error ? 1 : 0;
38 }
39 
40 int
41 OptionParser::Parse (int argc,
42                      char * const argv [],
43                      const char *optstring,
44                      const Option *longopts,
45                      int *longindex)
46 {
47     return getopt_long_only(argc, argv, optstring, (const option*)longopts, longindex);
48 }
49 
50 char* OptionParser::GetOptionArgument()
51 {
52     return optarg;
53 }
54 
55 int OptionParser::GetOptionIndex()
56 {
57     return optind;
58 }
59 
60 int OptionParser::GetOptionErrorCause()
61 {
62     return optopt;
63 }
64