From b21333d4f8abe249a0b98a04348f9c73c77af8c8 Mon Sep 17 00:00:00 2001 From: curt Date: Sun, 25 Aug 2002 22:38:20 +0000 Subject: [PATCH] Erik Hofman: I've modified the code to display a brief help message instead of the whole bunch of options. To get the complete message -v or --verbose has to be added to the command line. --- src/Main/options.cxx | 50 +++++++++++++++++++++++++++++++------------- src/Main/options.hxx | 2 +- 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/Main/options.cxx b/src/Main/options.cxx index 5f37bfcc8..5d30b1836 100644 --- a/src/Main/options.cxx +++ b/src/Main/options.cxx @@ -68,7 +68,8 @@ enum { FG_OPTIONS_OK = 0, FG_OPTIONS_HELP = 1, - FG_OPTIONS_ERROR = 2 + FG_OPTIONS_ERROR = 2, + FG_OPTIONS_VERBOSE_HELP = 3 }; static double @@ -594,6 +595,9 @@ parse_option (const string& arg) if ( (arg == "--help") || (arg == "-h") ) { // help/usage request return(FG_OPTIONS_HELP); + } else if ( (arg == "--verbose") || (arg == "-v") ) { + // verbose help/usage request + return(FG_OPTIONS_VERBOSE_HELP); } else if ( arg == "--disable-game-mode") { fgSetBool("/sim/startup/game-mode", false); } else if ( arg == "--enable-game-mode" ) { @@ -1061,6 +1065,8 @@ void fgParseArgs (int argc, char **argv) { bool in_options = true; + bool verbose = false; + bool help = false; SG_LOG(SG_GENERAL, SG_INFO, "Processing command line arguments"); @@ -1072,11 +1078,11 @@ fgParseArgs (int argc, char **argv) in_options = false; } else { int result = parse_option(arg); - if ( (result == FG_OPTIONS_HELP) || - (result == FG_OPTIONS_ERROR) ) { - fgUsage(); - exit(-1); - } + if ((result == FG_OPTIONS_HELP) || (result == FG_OPTIONS_ERROR)) + help = true; + + else if (result == FG_OPTIONS_VERBOSE_HELP) + verbose = true; } } else { in_options = false; @@ -1086,6 +1092,11 @@ fgParseArgs (int argc, char **argv) } } + if (help) { + fgUsage(verbose); + exit(0); + } + SG_LOG(SG_GENERAL, SG_INFO, "Finished command line arguments"); } @@ -1135,7 +1146,7 @@ fgParseOptions (const string& path) { // Print usage message void -fgUsage () +fgUsage (bool verbose) { SGPropertyNode options_root; SGPath opath( globals->get_fg_root() ); @@ -1168,11 +1179,7 @@ fgUsage () vectorsection = options->getChildren("section"); for (unsigned int j = 0; j < section.size(); j++) { - - SGPropertyNode *name = section[j]->getNode("name"); - if (name) { - cout << endl << name->getStringValue() << ":" << endl; - } + string msg = ""; vectoroption = section[j]->getChildren("option"); for (unsigned int k = 0; k < option.size(); k++) { @@ -1181,8 +1188,9 @@ fgUsage () SGPropertyNode *short_name = option[k]->getNode("short"); SGPropertyNode *key = option[k]->getNode("key"); SGPropertyNode *arg = option[k]->getNode("arg"); + bool brief = option[k]->getNode("brief"); - if (name) { + if ((brief || verbose) && name) { string tmp = name->getStringValue(); if (key){ @@ -1204,8 +1212,8 @@ fgUsage () } else { snprintf(cstr, 96, "\n --%s\n%32c", tmp.c_str(), ' '); } - string msg = cstr; + msg += cstr; SGPropertyNode *desc = option[k]->getNode("description"); if (desc) { msg += desc->getStringValue(); @@ -1218,9 +1226,21 @@ fgUsage () desc->getStringValue()); msg += cstr; } + msg += '\n'; } - cout << msg << endl; } } + + SGPropertyNode *name = section[j]->getNode("name"); + if (!msg.empty() && name) { + cout << endl << name->getStringValue() << ":" << endl; + cout << msg; + msg.erase(); + } + } + + if ( !verbose ) { + cout << endl; + cout << "For a complete list of options use --help --verbose" << endl; } } diff --git a/src/Main/options.hxx b/src/Main/options.hxx index b9e0aeb60..7d6866dde 100644 --- a/src/Main/options.hxx +++ b/src/Main/options.hxx @@ -34,6 +34,6 @@ extern string fgScanForRoot (int argc, char ** argv); extern string fgScanForRoot (const string &file_path); extern void fgParseArgs (int argc, char ** argv); extern void fgParseOptions (const string &file_path); -extern void fgUsage (); +extern void fgUsage (bool verbose = false); #endif /* _OPTIONS_HXX */