1998-04-24 00:49:17 +00:00
|
|
|
// options.hxx -- class to handle command line options
|
|
|
|
//
|
|
|
|
// Written by Curtis Olson, started April 1998.
|
|
|
|
//
|
2004-11-19 22:10:41 +00:00
|
|
|
// Copyright (C) 1998 Curtis L. Olson - http://www.flightgear.org/~curt
|
1998-04-24 00:49:17 +00:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
2006-02-21 01:16:04 +00:00
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
1998-04-24 00:49:17 +00:00
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef _OPTIONS_HXX
|
|
|
|
#define _OPTIONS_HXX
|
|
|
|
|
2011-10-16 17:35:40 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
1998-04-24 00:49:17 +00:00
|
|
|
|
2011-10-16 17:35:40 +00:00
|
|
|
#include <simgear/misc/strutils.hxx>
|
1998-09-17 18:35:30 +00:00
|
|
|
|
2011-10-16 17:35:40 +00:00
|
|
|
// forward decls
|
|
|
|
class SGPath;
|
|
|
|
|
|
|
|
namespace flightgear
|
|
|
|
{
|
2013-10-15 21:16:50 +00:00
|
|
|
|
2015-03-17 22:10:49 +00:00
|
|
|
/**
|
|
|
|
* return the default platform dependant download directory.
|
|
|
|
* This must be a user-writeable location, the question is if it should
|
|
|
|
* be a user visible location. On Windows we default to a subdir of
|
|
|
|
* Documents (FlightGear), on Unixes we default to FG_HOME, which is
|
|
|
|
* typically invisible.
|
|
|
|
*/
|
2016-06-23 13:26:34 +00:00
|
|
|
SGPath defaultDownloadDir();
|
2015-03-17 22:10:49 +00:00
|
|
|
|
2013-10-15 21:16:50 +00:00
|
|
|
/// option processing can have various result values
|
|
|
|
/// depending on what the user requested. Note processOptions only
|
|
|
|
/// returns a subset of these.
|
|
|
|
enum OptionResult
|
|
|
|
{
|
|
|
|
FG_OPTIONS_OK = 0,
|
Fix the --version option
1) Paths and the FG_SCENERY paths list are now printed like:
FG_ROOT=/home/flo/flightgear/src/fgdata
instead of:
FG_ROOT=Path "/home/flo/flightgear/src/fgdata"
Moreover, FG_SCENERY is now correctly printed (without 'Path ""'
wrapping, without Terrain, Objects and markers instead of the actual
scenery paths) regardless of the position of --version relatively to
--fg-scenery, --terrasync-dir, etc. Of course, the values given to
these options do influence the output of --version.
Simplify printing of FG_SCENERY via SGPath::join() and use the
correct, OS-dependent separator between paths, SGPath::pathListSep.
Write the --version output to stdout, as already done for --help;
then it can be easily piped to $PAGER and doesn't get mixed with the
output of SG_LOG (which is on stderr). This is of course backward
incompatible for programs reading the stderr output of
'fgfs --version', but has been agreed upon on FlightGear-devel (cf.
<https://sourceforge.net/p/flightgear/mailman/message/35461619/>).
2) Don't write explicit values in the OptionResult enum: they don't
matter, but giving them is error-prone in case one does a copy-paste
to add a new member to the enum and forgets to change the value.
2016-10-30 16:25:06 +00:00
|
|
|
FG_OPTIONS_HELP,
|
|
|
|
FG_OPTIONS_ERROR,
|
|
|
|
FG_OPTIONS_EXIT,
|
|
|
|
FG_OPTIONS_VERBOSE_HELP,
|
|
|
|
FG_OPTIONS_SHOW_AIRCRAFT,
|
|
|
|
FG_OPTIONS_SHOW_SOUND_DEVICES,
|
|
|
|
FG_OPTIONS_NO_DEFAULT_CONFIG
|
2013-10-15 21:16:50 +00:00
|
|
|
};
|
|
|
|
|
2011-10-16 17:35:40 +00:00
|
|
|
class Options
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
Options();
|
|
|
|
|
|
|
|
public:
|
|
|
|
static Options* sharedInstance();
|
|
|
|
|
|
|
|
~Options();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* pass command line arguments, read default config files
|
|
|
|
*/
|
2011-10-21 15:49:15 +00:00
|
|
|
void init(int argc, char* argv[], const SGPath& appDataPath);
|
2011-10-16 17:35:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* parse a config file (eg, .fgfsrc)
|
|
|
|
*/
|
|
|
|
void readConfig(const SGPath& path);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* read the value for an option, if it has been set
|
|
|
|
*/
|
|
|
|
std::string valueForOption(const std::string& key, const std::string& defValue = std::string()) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* return all values for a multi-valued option
|
|
|
|
*/
|
|
|
|
string_list valuesForOption(const std::string& key) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* check if a particular option has been set (so far)
|
|
|
|
*/
|
|
|
|
bool isOptionSet(const std::string& key) const;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set an option value, assuming it is not already set (or multiple values
|
|
|
|
* are permitted)
|
|
|
|
* This can be used to inject option values, eg based upon environment variables
|
|
|
|
*/
|
|
|
|
int addOption(const std::string& key, const std::string& value);
|
2016-03-24 15:05:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* set an option, overwriting any existing value which might be set
|
|
|
|
*/
|
|
|
|
int setOption(const std::string& key, const std::string& value);
|
|
|
|
|
|
|
|
void clearOption(const std::string& key);
|
|
|
|
|
2011-10-16 17:35:40 +00:00
|
|
|
/**
|
|
|
|
* apply option values to the simulation state
|
2013-10-15 21:16:50 +00:00
|
|
|
* (set properties, etc).
|
2011-10-16 17:35:40 +00:00
|
|
|
*/
|
2013-10-15 21:16:50 +00:00
|
|
|
OptionResult processOptions();
|
2014-12-26 12:20:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* process command line options relating to scenery / aircraft / data paths
|
|
|
|
*/
|
|
|
|
void initPaths();
|
|
|
|
|
2011-10-16 17:35:40 +00:00
|
|
|
/**
|
|
|
|
* init the aircraft options
|
|
|
|
*/
|
|
|
|
void initAircraft();
|
2012-09-29 18:02:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* should defualt configuration files be loaded and processed or not?
|
|
|
|
* There's many configuration files we have historically read by default
|
2016-09-08 10:41:40 +00:00
|
|
|
* on startup - fgfs.rc in various places and so on.
|
2012-09-29 18:02:03 +00:00
|
|
|
* --no-default-config allows this behaviour to be changed, so only
|
2016-09-08 10:41:40 +00:00
|
|
|
* expicitly listed files are read Expose
|
2012-09-29 18:02:03 +00:00
|
|
|
* the value of the option here.
|
|
|
|
*/
|
|
|
|
bool shouldLoadDefaultConfig() const;
|
2014-02-19 21:53:52 +00:00
|
|
|
|
2016-09-08 10:41:40 +00:00
|
|
|
/**
|
|
|
|
* when using the built-in launcher, we disable the default config files.
|
|
|
|
* explicitly loaded confg files are still permitted.
|
|
|
|
*/
|
|
|
|
void setShouldLoadDefaultConfig(bool load);
|
|
|
|
|
2014-02-19 21:53:52 +00:00
|
|
|
/**
|
|
|
|
* check if the arguments array contains a particular string (with a '--' or
|
|
|
|
* '-' prefix).
|
|
|
|
* Used by early startup code before Options object is created
|
|
|
|
*/
|
|
|
|
static bool checkForArg(int argc, char* argv[], const char* arg);
|
2016-01-17 19:10:22 +00:00
|
|
|
|
2016-06-21 11:29:04 +00:00
|
|
|
SGPath platformDefaultRoot() const;
|
2011-10-16 17:35:40 +00:00
|
|
|
private:
|
|
|
|
void showUsage() const;
|
Fix the --version option
1) Paths and the FG_SCENERY paths list are now printed like:
FG_ROOT=/home/flo/flightgear/src/fgdata
instead of:
FG_ROOT=Path "/home/flo/flightgear/src/fgdata"
Moreover, FG_SCENERY is now correctly printed (without 'Path ""'
wrapping, without Terrain, Objects and markers instead of the actual
scenery paths) regardless of the position of --version relatively to
--fg-scenery, --terrasync-dir, etc. Of course, the values given to
these options do influence the output of --version.
Simplify printing of FG_SCENERY via SGPath::join() and use the
correct, OS-dependent separator between paths, SGPath::pathListSep.
Write the --version output to stdout, as already done for --help;
then it can be easily piped to $PAGER and doesn't get mixed with the
output of SG_LOG (which is on stderr). This is of course backward
incompatible for programs reading the stderr output of
'fgfs --version', but has been agreed upon on FlightGear-devel (cf.
<https://sourceforge.net/p/flightgear/mailman/message/35461619/>).
2) Don't write explicit values in the OptionResult enum: they don't
matter, but giving them is error-prone in case one does a copy-paste
to add a new member to the enum and forgets to change the value.
2016-10-30 16:25:06 +00:00
|
|
|
void showVersion() const;
|
2016-10-31 21:21:52 +00:00
|
|
|
// Write info such as FG version, FG_ROOT, FG_HOME, scenery paths, aircraft
|
|
|
|
// paths, etc. to stdout in JSON format, using the UTF-8 encoding.
|
|
|
|
void printJSONReport() const;
|
Fix the --version option
1) Paths and the FG_SCENERY paths list are now printed like:
FG_ROOT=/home/flo/flightgear/src/fgdata
instead of:
FG_ROOT=Path "/home/flo/flightgear/src/fgdata"
Moreover, FG_SCENERY is now correctly printed (without 'Path ""'
wrapping, without Terrain, Objects and markers instead of the actual
scenery paths) regardless of the position of --version relatively to
--fg-scenery, --terrasync-dir, etc. Of course, the values given to
these options do influence the output of --version.
Simplify printing of FG_SCENERY via SGPath::join() and use the
correct, OS-dependent separator between paths, SGPath::pathListSep.
Write the --version output to stdout, as already done for --help;
then it can be easily piped to $PAGER and doesn't get mixed with the
output of SG_LOG (which is on stderr). This is of course backward
incompatible for programs reading the stderr output of
'fgfs --version', but has been agreed upon on FlightGear-devel (cf.
<https://sourceforge.net/p/flightgear/mailman/message/35461619/>).
2) Don't write explicit values in the OptionResult enum: they don't
matter, but giving them is error-prone in case one does a copy-paste
to add a new member to the enum and forgets to change the value.
2016-10-30 16:25:06 +00:00
|
|
|
|
2011-10-16 17:35:40 +00:00
|
|
|
int parseOption(const std::string& s);
|
|
|
|
|
|
|
|
void processArgResult(int result);
|
2015-03-06 18:52:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup the root base, and check it's valid. Bails out with exit(-1) if
|
|
|
|
* the root package was not found or is the incorrect version. Argv/argv
|
|
|
|
* are passed since we might potentially show a GUI dialog at this point
|
|
|
|
* to help the user our (finding a base package), and hence need to init Qt.
|
|
|
|
*/
|
|
|
|
void setupRoot(int argc, char **argv);
|
2016-01-17 19:10:22 +00:00
|
|
|
|
2011-10-16 17:35:40 +00:00
|
|
|
|
|
|
|
class OptionsPrivate;
|
|
|
|
std::auto_ptr<OptionsPrivate> p;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // of namespace flightgear
|
1998-04-24 00:49:17 +00:00
|
|
|
|
2013-11-16 12:00:00 +00:00
|
|
|
void fgSetDefaults();
|
|
|
|
|
2001-02-02 22:39:13 +00:00
|
|
|
#endif /* _OPTIONS_HXX */
|