From ba83f60e21ad6f37a7e6609ccd18ec41a43c9d36 Mon Sep 17 00:00:00 2001 From: Matt Hill Date: Sun, 11 May 2014 11:51:09 -0500 Subject: [PATCH] Removed "exit" function call from CmdLine code. Now returning out of main. --- src/main.cpp | 7 ++++++- src/tclap/CmdLine.h | 17 +++++++++++------ src/tclap/CmdLineInterface.h | 4 ++-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index d205966..03593a6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -76,7 +76,12 @@ int main( int argc, const char** argv ) cmd.add( fileArg ); cmd.add( countryCodeArg ); - cmd.parse( argc, argv ); + + if (cmd.parse( argc, argv ) == false) + { + // Error occured while parsing. Exit now. + return 1; + } filename = fileArg.getValue(); diff --git a/src/tclap/CmdLine.h b/src/tclap/CmdLine.h index 353cfee..c1f4159 100644 --- a/src/tclap/CmdLine.h +++ b/src/tclap/CmdLine.h @@ -240,14 +240,14 @@ class CmdLine : public CmdLineInterface * \param argc - Number of arguments. * \param argv - Array of arguments. */ - void parse(int argc, const char * const * argv); + bool parse(int argc, const char * const * argv); /** * Parses the command line. * \param args - A vector of strings representing the args. * args[0] is still the program name. */ - void parse(std::vector& args); + bool parse(std::vector& args); /** * @@ -423,17 +423,17 @@ inline void CmdLine::add( Arg* a ) } -inline void CmdLine::parse(int argc, const char * const * argv) +inline bool CmdLine::parse(int argc, const char * const * argv) { // this step is necessary so that we have easy access to // mutable strings. std::vector args; for (int i = 0; i < argc; i++) args.push_back(argv[i]); - parse(args); + return parse(args); } -inline void CmdLine::parse(std::vector& args) +inline bool CmdLine::parse(std::vector& args) { bool shouldExit = false; int estat = 0; @@ -497,7 +497,12 @@ inline void CmdLine::parse(std::vector& args) shouldExit = true; } if (shouldExit) - exit(estat); + { + //exit(estat); + return false; + } + + return true; } inline bool CmdLine::_emptyCombined(const std::string& s) diff --git a/src/tclap/CmdLineInterface.h b/src/tclap/CmdLineInterface.h index 86329a9..8838b46 100644 --- a/src/tclap/CmdLineInterface.h +++ b/src/tclap/CmdLineInterface.h @@ -83,14 +83,14 @@ class CmdLineInterface * \param argc - Number of arguments. * \param argv - Array of arguments. */ - virtual void parse(int argc, const char * const * argv)=0; + virtual bool parse(int argc, const char * const * argv)=0; /** * Parses the command line. * \param args - A vector of strings representing the args. * args[0] is still the program name. */ - void parse(std::vector& args); + bool parse(std::vector& args); /** * Returns the CmdLineOutput object.