]>
cygwin.com Git - cygwin-apps/setup.git/blob - libgetopt++/src/OptionSet.cc
2 * Copyright (c) 2002 Robert Collins.
3 * Copyright (c) 2003 Robert Collins.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * A copy of the GNU General Public License can be found at
13 * Written by Robert Collins <robertc@hotmail.com>
20 #include "getopt++/OptionSet.h"
21 #include "getopt++/Option.h"
22 #include "getopt++/DefaultFormatter.h"
28 OptionSet::OptionSet () {}
29 OptionSet::~OptionSet ()
36 options
= std::vector
<Option
*> ();
40 OptionSet::Process (int argc
, char **argv
, OptionSet
*defaultOptionSet
)
44 // log (LOG_TIMESTAMP, "No command line options pass\n");
47 if (options
.size() == 0)
50 return defaultOptionSet
->Process (argc
, argv
);
51 // log (LOG_TIMESTAMP,
52 // "%d Command line options passed, and no options registered\n",
56 // log (LOG_TIMESTAMP, "Process command line options\n");
57 struct option longopts
[options
.size() + 1];
59 for (std::vector
<Option
*>::iterator i
= options
.begin(); i
!= options
.end(); ++i
)
61 shortopts
+= (*i
)->shortOption ();
62 longopts
[distance(options
.begin(), i
)] = (*i
)->longOption ();
64 char const * opts
= shortopts
.c_str ();
66 struct option foo
= {0, 0, 0, 0};
67 longopts
[options
.size()] = foo
;
69 // where is this correctly defined? opterr=0;
71 while ((lastoption
= getopt_long (argc
, argv
, opts
, longopts
, 0)) != -1)
75 if (lastoption
== '\?')
83 for (std::vector
<Option
*>::iterator i
= options
.begin(); i
!= options
.end(); ++i
)
85 if (longopts
[distance(options
.begin(), i
)].val
== lastoption
&& !longopts
[distance(options
.begin(), i
)].flag
)
86 (*i
)->Process (optarg
);
91 if (optind
< argc
&& optind
> 0 && defaultOptionSet
)
92 return defaultOptionSet
->Process (argc
- optind
, &argv
[optind
]);
99 //FIXME: check for conflicts.
101 OptionSet::Register (Option
* anOption
)
103 options
.push_back(anOption
);
107 OptionSet::ParameterUsage (ostream
&aStream
)
109 for_each (options
.begin(), options
.end(), DefaultFormatter (aStream
));
112 std::vector
<Option
*> const &
113 OptionSet::optionsInSet() const
This page took 0.039405 seconds and 6 git commands to generate.