if ( !in.is_open() ) {
SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << aptdb_file );
- exit(-1);
+ throw sg_io_exception("cannot open APT file", aptdb_file);
}
string line;
} else {
SG_LOG( SG_GENERAL, SG_ALERT,
"Unknown line(#" << line_num << ") in apt.dat file: " << line );
- exit( -1 );
+ throw sg_format_exception("malformed line in apt.dat:", line);
}
}
#include <simgear/compiler.h>
#include <simgear/debug/logstream.hxx>
#include <simgear/misc/strutils.hxx>
+#include <simgear/structure/exception.hxx>
#include <Main/globals.hxx>
#include <Airports/runways.hxx>
if ((start.size() != end.size())
|| (start.size() != scheduleNames.size())) {
SG_LOG(SG_GENERAL, SG_INFO, "Unable to parse schedule times");
- exit(1);
+ throw sg_exception("Unable to parse schedule times");
} else {
int nrItems = start.size();
//cerr << "Nr of items to process: " << nrItems << endl;
FGSidStar::FGSidStar(const FGSidStar &other) {
cerr << "TODO" << endl;
- exit(1);
}
void FGSidStar::load(SGPath filename) {
}
// Read in configuration (file and command line)
-bool fgInitConfig ( int argc, char **argv )
+int fgInitConfig ( int argc, char **argv )
{
SGPath dataPath = globals->get_fg_home();
FindAndCacheAircraft f(globals->get_props());
if (!f.loadAircraft()) {
- return false;
+ return flightgear::FG_OPTIONS_ERROR;
}
// parse options after loading aircraft to ensure any user
// overrides of defaults are honored.
- options->processOptions();
-
- return true;
+ return options->processOptions();
}
SG_LOG( SG_GENERAL, SG_ALERT,
"Cannot continue without a path to the base package "
<< "being defined." );
- exit(-1);
+ return false;
}
SG_LOG( SG_GENERAL, SG_INFO, "FG_ROOT = " << '"' << root << '"' << endl );
mpath.append( fgGetString("/sim/rendering/materials-file") );
if ( ! globals->get_matlib()->load(globals->get_fg_root(), mpath.str(),
globals->get_props()) ) {
- SG_LOG( SG_GENERAL, SG_ALERT,
- "Error loading materials file " << mpath.str() );
- exit(-1);
+ throw sg_io_exception("Error loading materials file", mpath);
}
globals->add_subsystem( "http", new FGHTTPClient );
void fgInitHome();
// Read in configuration (file and command line)
-bool fgInitConfig ( int argc, char **argv );
+int fgInitConfig ( int argc, char **argv );
// log various settings / configuration state
#include "fg_props.hxx"
#include "positioninit.hxx"
#include "subsystemFactory.hxx"
+#include "options.hxx"
using namespace flightgear;
// Do some quick general initializations
if( !fgInitGeneral()) {
- SG_LOG( SG_GENERAL, SG_ALERT,
- "General initialization failed ..." );
- exit(-1);
+ throw sg_exception("General initialization failed");
}
////////////////////////////////////////////////////////////////////
// Load the configuration parameters. (Command line options
// override config file options. Config file options override
// defaults.)
- if ( !fgInitConfig(argc, argv) ) {
- SG_LOG( SG_GENERAL, SG_ALERT, "Config option parsing failed ..." );
- exit(-1);
+ int configResult = fgInitConfig(argc, argv);
+ if (configResult == flightgear::FG_OPTIONS_ERROR) {
+ return EXIT_FAILURE;
+ } else if (configResult == flightgear::FG_OPTIONS_EXIT) {
+ return EXIT_SUCCESS;
}
-
+
// Initialize the Window/Graphics environment.
fgOSInit(&argc, argv);
_bootstrap_OSInit++;
using std::vector;
using std::cin;
-#define NEW_DEFAULT_MODEL_HZ 120
+using namespace flightgear;
-enum
-{
- FG_OPTIONS_OK = 0,
- FG_OPTIONS_HELP = 1,
- FG_OPTIONS_ERROR = 2,
- FG_OPTIONS_EXIT = 3,
- FG_OPTIONS_VERBOSE_HELP = 4,
- FG_OPTIONS_SHOW_AIRCRAFT = 5,
- FG_OPTIONS_SHOW_SOUND_DEVICES = 6,
- FG_OPTIONS_NO_DEFAULT_CONFIG = 7
-};
+#define NEW_DEFAULT_MODEL_HZ 120
static flightgear::Options* shared_instance = NULL;
{
string file = arg;
try {
- readProperties(file, globals->get_props());
+ readProperties(file, globals->get_props());
} catch (const sg_exception &e) {
- string message = "Error loading config file: ";
- message += e.getFormattedMessage() + e.getOrigin();
- SG_LOG(SG_INPUT, SG_ALERT, message);
- exit(2);
+ string message = "Error loading config file: ";
+ message += e.getFormattedMessage() + e.getOrigin();
+ SG_LOG(SG_INPUT, SG_ALERT, message);
+ return FG_OPTIONS_ERROR;
}
return FG_OPTIONS_OK;
}
return result;
}
-void Options::processOptions()
+OptionResult Options::processOptions()
{
// establish locale before showing help (this selects the default locale,
// when no explicit option was set)
// out quickly, but rely on aircraft / root settings
if (p->showHelp) {
showUsage();
- exit(0);
+ return FG_OPTIONS_EXIT;
}
// processing order is complicated. We must process groups LIFO, but the
{
case FG_OPTIONS_ERROR:
showUsage();
- exit(-1); // exit and return an error
+ return FG_OPTIONS_ERROR;
+
case FG_OPTIONS_EXIT:
- exit(0); // clean exit
+ return FG_OPTIONS_EXIT;
+
default:
break;
}
root.append("Scenery");
globals->append_fg_scenery(root.str());
}
+
+ return FG_OPTIONS_OK;
}
void Options::showUsage() const
namespace flightgear
{
-
+
+/// 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,
+ FG_OPTIONS_HELP = 1,
+ FG_OPTIONS_ERROR = 2,
+ FG_OPTIONS_EXIT = 3,
+ FG_OPTIONS_VERBOSE_HELP = 4,
+ FG_OPTIONS_SHOW_AIRCRAFT = 5,
+ FG_OPTIONS_SHOW_SOUND_DEVICES = 6,
+ FG_OPTIONS_NO_DEFAULT_CONFIG = 7
+};
+
class Options
{
private:
/**
* apply option values to the simulation state
- * (set properties, etc)
+ * (set properties, etc).
*/
- void processOptions();
+ OptionResult processOptions();
/**
* init the aircraft options
#include <simgear/misc/sgstream.hxx>
#include <simgear/misc/sg_path.hxx>
#include <simgear/math/sg_geodesy.hxx>
+#include <simgear/structure/exception.hxx>
#include "fixlist.hxx"
#include <Navaids/fix.hxx>
{
sg_gzifstream in( path.str() );
if ( !in.is_open() ) {
- SG_LOG( SG_NAVAID, SG_ALERT, "Cannot open file: " << path.str() );
- exit(-1);
+ throw sg_io_exception("Cannot open file:", path);
}
// toss the first two lines of the file
if (! sample)
{
string filename = dir_prefix + string(name) + ".wav";
- try
- {
- sample = new SGSoundSample(filename.c_str(), SGPath());
- }
- catch (const sg_exception &e)
- {
- SG_LOG(SG_SOUND, SG_ALERT, "Error loading sound sample \"" + filename + "\": " + e.getFormattedMessage());
- exit(1);
- }
-
+ sample = new SGSoundSample(filename.c_str(), SGPath());
+
_sgr->add(sample, refname);
samples[refname] = sample;
}
if ( build(config_props) ) {
enabled = true;
} else {
- SG_LOG( SG_SYSTEMS, SG_ALERT,
- "Detected a logic error in the electrical system ");
- SG_LOG( SG_SYSTEMS, SG_ALERT,
- "specification file. See earlier errors for " );
- SG_LOG( SG_SYSTEMS, SG_ALERT,
- "details.");
- exit(-1);
+ throw sg_exception("Logic error in electrical system file.");
}
} catch (const sg_exception&) {
SG_LOG( SG_SYSTEMS, SG_ALERT,
#include <simgear/misc/sg_dir.hxx>
#include <simgear/props/props.hxx>
#include <simgear/structure/subsystem_mgr.hxx>
+#include <simgear/structure/exception.hxx>
+
#include <simgear/xml/easyxml.hxx>
#include <simgear/threads/SGThread.hxx>
#include <simgear/threads/SGGuard.hxx>
if (!tokens.empty()) {
if (tokens[0] == string("AC")) {
if (tokens.size() != 13) {
- SG_LOG(SG_AI, SG_ALERT, "Error parsing traffic file " << infileName.str() << " at " << buffString);
- exit(1);
+ throw sg_io_exception("Error parsing traffic file @ " + buffString, sg_location(infileName.str()));
}
+
+
model = tokens[12];
livery = tokens[6];
homePort = tokens[1];
#include <simgear/scene/tgdb/userdata.hxx>
#include <simgear/scene/model/ModelRegistry.hxx>
#include <simgear/scene/model/modellib.hxx>
+#include <simgear/structure/exception.hxx>
#include <Scenery/scenery.hxx>
globals = new FGGlobals;
- if ( !fgInitConfig(arguments.argc(), arguments.argv()) ) {
- SG_LOG( SG_GENERAL, SG_ALERT, "Config option parsing failed ..." );
- exit(-1);
+ int configResult = fgInitConfig(arguments.argc(), arguments.argv());
+ if (configResult == flightgear::FG_OPTIONS_ERROR) {
+ return EXIT_FAILURE;
+ } else if (configResult == flightgear::FG_OPTIONS_EXIT) {
+ return EXIT_SUCCESS;
}
osgDB::FilePathList filePathList
mpath.append( fgGetString("/sim/rendering/materials-file") );
if ( ! globals->get_matlib()->load(globals->get_fg_root(), mpath.str(),
globals->get_props()) ) {
- SG_LOG( SG_GENERAL, SG_ALERT,
- "Error loading materials file " << mpath.str() );
- exit(-1);
+ throw sg_io_exception("Error loading materials file", mpath);
}
globals->set_scenery( new FGScenery );