From 3cbc6f21c76c7c13e726782b488c1904345ca1cd Mon Sep 17 00:00:00 2001 From: david Date: Fri, 4 Jan 2002 20:58:48 +0000 Subject: [PATCH] Renamed fgParseOptions(int,string) to fgParseArgs, and modified the function to allow property files as non-option parameters after the options have finished (and added "--" to terminate options). It's now possible to do something like fgfs denver-am.fgd or even fgfs at-lax.fgd in-c310.fgd around-sunset.fgd This works the same way as the --config option, but will be friendlier for GUIs, where start-up situation files can now be associated easily with FlightGear. --- src/Main/fg_init.cxx | 2 +- src/Main/options.cxx | 36 ++++++++++++++++++++++++------------ src/Main/options.hxx | 2 +- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index ec6039b60..f804c2070 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -288,7 +288,7 @@ bool fgInitConfig ( int argc, char **argv ) { // Parse remaining command line options // These will override anything specified in a config file - fgParseOptions(argc, argv); + fgParseArgs(argc, argv); return true; } diff --git a/src/Main/options.cxx b/src/Main/options.cxx index e5eedb048..f7931419e 100644 --- a/src/Main/options.cxx +++ b/src/Main/options.cxx @@ -1001,23 +1001,35 @@ fgScanForRoot (const string& path) // Parse the command line options void -fgParseOptions (int argc, char **argv) { - int i = 1; - int result; +fgParseArgs (int argc, char **argv) +{ + bool in_options = true; SG_LOG(SG_GENERAL, SG_INFO, "Processing command line arguments"); - while ( i < argc ) { - SG_LOG( SG_GENERAL, SG_DEBUG, "argv[" << i << "] = " << argv[i] ); - - result = parse_option(argv[i]); - if ( (result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR) ) { - fgUsage(); - exit(-1); + for (int i = 1; i < argc; i++) { + string arg = argv[i]; + + if (in_options && (arg.find('-') == 0)) { + if (arg == "--") { + in_options = false; + } else { + int result = parse_option(arg); + if ( (result == FG_OPTIONS_HELP) || + (result == FG_OPTIONS_ERROR) ) { + fgUsage(); + exit(-1); + } + } + } else { + in_options = false; + SG_LOG(SG_GENERAL, SG_INFO, + "Reading command-line property file " << arg); + readProperties(arg, globals->get_props()); } - - i++; } + + SG_LOG(SG_GENERAL, SG_INFO, "Finished command line arguments"); } diff --git a/src/Main/options.hxx b/src/Main/options.hxx index 36128137b..b4ecc9f82 100644 --- a/src/Main/options.hxx +++ b/src/Main/options.hxx @@ -32,7 +32,7 @@ extern void fgSetDefaults (); extern string fgScanForRoot (int argc, char ** argv); extern string fgScanForRoot (const string &file_path); -extern void fgParseOptions (int argc, char ** argv); +extern void fgParseArgs (int argc, char ** argv); extern void fgParseOptions (const string &file_path); extern void fgUsage (); -- 2.39.5