diff --git a/include/tclap/DocBookOutput.h b/include/tclap/DocBookOutput.h index c833c08..5dbfb26 100644 --- a/include/tclap/DocBookOutput.h +++ b/include/tclap/DocBookOutput.h @@ -1,3 +1,4 @@ +// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- /****************************************************************************** * @@ -189,10 +190,10 @@ inline void DocBookOutput::usage(CmdLineInterface& _cmd ) } inline void DocBookOutput::failure( CmdLineInterface& _cmd, - ArgException& e ) + ArgException& e ) { std::cout << e.what() << std::endl; - exit(1); + throw ExitException(1); } inline void DocBookOutput::substituteSpecialChars( std::string& s, diff --git a/include/tclap/HelpVisitor.h b/include/tclap/HelpVisitor.h index 7b8a395..2cdb997 100644 --- a/include/tclap/HelpVisitor.h +++ b/include/tclap/HelpVisitor.h @@ -60,7 +60,7 @@ class HelpVisitor: public Visitor * Calls the usage method of the CmdLineOutput for the * specified CmdLine. */ - void visit() { (*_out)->usage(*_cmd); exit(0); } + void visit() { (*_out)->usage(*_cmd); throw ExitException(0); } }; diff --git a/include/tclap/StdOutput.h b/include/tclap/StdOutput.h index 7cf5566..9dd6d0f 100644 --- a/include/tclap/StdOutput.h +++ b/include/tclap/StdOutput.h @@ -1,3 +1,4 @@ +// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- /****************************************************************************** * @@ -65,7 +66,7 @@ class StdOutput : public CmdLineOutput * \param e - The ArgException that caused the failure. */ virtual void failure(CmdLineInterface& c, - ArgException& e ); + ArgException& e ); protected: @@ -128,7 +129,7 @@ inline void StdOutput::usage(CmdLineInterface& _cmd ) } inline void StdOutput::failure( CmdLineInterface& _cmd, - ArgException& e ) + ArgException& e ) { std::string progName = _cmd.getProgramName(); @@ -136,23 +137,24 @@ inline void StdOutput::failure( CmdLineInterface& _cmd, << " " << e.error() << std::endl << std::endl; if ( _cmd.hasHelpAndVersion() ) - { - std::cerr << "Brief USAGE: " << std::endl; + { + std::cerr << "Brief USAGE: " << std::endl; - _shortUsage( _cmd, std::cerr ); + _shortUsage( _cmd, std::cerr ); - std::cerr << std::endl << "For complete USAGE and HELP type: " - << std::endl << " " << progName << " --help" - << std::endl << std::endl; - } + std::cerr << std::endl << "For complete USAGE and HELP type: " + << std::endl << " " << progName << " --help" + << std::endl << std::endl; + } else usage(_cmd); - exit(1); + throw ExitException(1); } -inline void StdOutput::_shortUsage( CmdLineInterface& _cmd, - std::ostream& os ) const +inline void +StdOutput::_shortUsage( CmdLineInterface& _cmd, + std::ostream& os ) const { std::list argList = _cmd.getArgList(); std::string progName = _cmd.getProgramName(); @@ -163,14 +165,14 @@ inline void StdOutput::_shortUsage( CmdLineInterface& _cmd, // first the xor for ( int i = 0; static_cast(i) < xorList.size(); i++ ) - { - s += " {"; - for ( ArgVectorIterator it = xorList[i].begin(); - it != xorList[i].end(); it++ ) - s += (*it)->shortID() + "|"; + { + s += " {"; + for ( ArgVectorIterator it = xorList[i].begin(); + it != xorList[i].end(); it++ ) + s += (*it)->shortID() + "|"; - s[s.length()-1] = '}'; - } + s[s.length()-1] = '}'; + } // then the rest for (ArgListIterator it = argList.begin(); it != argList.end(); it++) @@ -180,13 +182,14 @@ inline void StdOutput::_shortUsage( CmdLineInterface& _cmd, // if the program name is too long, then adjust the second line offset int secondLineOffset = static_cast(progName.length()) + 2; if ( secondLineOffset > 75/2 ) - secondLineOffset = static_cast(75/2); + secondLineOffset = static_cast(75/2); - spacePrint( std::cout, s, 75, 3, secondLineOffset ); + spacePrint( os, s, 75, 3, secondLineOffset ); } -inline void StdOutput::_longUsage( CmdLineInterface& _cmd, - std::ostream& os ) const +inline void +StdOutput::_longUsage( CmdLineInterface& _cmd, + std::ostream& os ) const { std::list argList = _cmd.getArgList(); std::string message = _cmd.getMessage(); @@ -195,28 +198,28 @@ inline void StdOutput::_longUsage( CmdLineInterface& _cmd, // first the xor for ( int i = 0; static_cast(i) < xorList.size(); i++ ) - { - for ( ArgVectorIterator it = xorList[i].begin(); - it != xorList[i].end(); - it++ ) { - spacePrint( os, (*it)->longID(), 75, 3, 3 ); - spacePrint( os, (*it)->getDescription(), 75, 5, 0 ); + for ( ArgVectorIterator it = xorList[i].begin(); + it != xorList[i].end(); + it++ ) + { + spacePrint( os, (*it)->longID(), 75, 3, 3 ); + spacePrint( os, (*it)->getDescription(), 75, 5, 0 ); - if ( it+1 != xorList[i].end() ) - spacePrint(os, "-- OR --", 75, 9, 0); + if ( it+1 != xorList[i].end() ) + spacePrint(os, "-- OR --", 75, 9, 0); + } + os << std::endl << std::endl; } - os << std::endl << std::endl; - } // then the rest for (ArgListIterator it = argList.begin(); it != argList.end(); it++) if ( !xorHandler.contains( (*it) ) ) - { - spacePrint( os, (*it)->longID(), 75, 3, 3 ); - spacePrint( os, (*it)->getDescription(), 75, 5, 0 ); - os << std::endl; - } + { + spacePrint( os, (*it)->longID(), 75, 3, 3 ); + spacePrint( os, (*it)->getDescription(), 75, 5, 0 ); + os << std::endl; + } os << std::endl; @@ -232,63 +235,63 @@ inline void StdOutput::spacePrint( std::ostream& os, int len = static_cast(s.length()); if ( (len + indentSpaces > maxWidth) && maxWidth > 0 ) - { - int allowedLen = maxWidth - indentSpaces; - int start = 0; - while ( start < len ) { - // find the substring length - // int stringLen = std::min( len - start, allowedLen ); - // doing it this way to support a VisualC++ 2005 bug - using namespace std; - int stringLen = min( len - start, allowedLen ); + int allowedLen = maxWidth - indentSpaces; + int start = 0; + while ( start < len ) + { + // find the substring length + // int stringLen = std::min( len - start, allowedLen ); + // doing it this way to support a VisualC++ 2005 bug + using namespace std; + int stringLen = min( len - start, allowedLen ); - // trim the length so it doesn't end in middle of a word - if ( stringLen == allowedLen ) - while ( s[stringLen+start] != ' ' && - s[stringLen+start] != ',' && - s[stringLen+start] != '|' && - stringLen >= 0 ) - stringLen--; + // trim the length so it doesn't end in middle of a word + if ( stringLen == allowedLen ) + while ( s[stringLen+start] != ' ' && + s[stringLen+start] != ',' && + s[stringLen+start] != '|' && + stringLen >= 0 ) + stringLen--; - // ok, the word is longer than the line, so just split - // wherever the line ends - if ( stringLen <= 0 ) - stringLen = allowedLen; + // ok, the word is longer than the line, so just split + // wherever the line ends + if ( stringLen <= 0 ) + stringLen = allowedLen; - // check for newlines - for ( int i = 0; i < stringLen; i++ ) - if ( s[start+i] == '\n' ) - stringLen = i+1; + // check for newlines + for ( int i = 0; i < stringLen; i++ ) + if ( s[start+i] == '\n' ) + stringLen = i+1; - // print the indent + // print the indent + for ( int i = 0; i < indentSpaces; i++ ) + os << " "; + + if ( start == 0 ) + { + // handle second line offsets + indentSpaces += secondLineOffset; + + // adjust allowed len + allowedLen -= secondLineOffset; + } + + os << s.substr(start,stringLen) << std::endl; + + // so we don't start a line with a space + while ( s[stringLen+start] == ' ' && start < len ) + start++; + + start += stringLen; + } + } + else + { for ( int i = 0; i < indentSpaces; i++ ) os << " "; - - if ( start == 0 ) - { - // handle second line offsets - indentSpaces += secondLineOffset; - - // adjust allowed len - allowedLen -= secondLineOffset; - } - - os << s.substr(start,stringLen) << std::endl; - - // so we don't start a line with a space - while ( s[stringLen+start] == ' ' && start < len ) - start++; - - start += stringLen; + os << s << std::endl; } - } - else - { - for ( int i = 0; i < indentSpaces; i++ ) - os << " "; - os << s << std::endl; - } } } //namespace TCLAP diff --git a/include/tclap/VersionVisitor.h b/include/tclap/VersionVisitor.h index 9faae95..3e55921 100644 --- a/include/tclap/VersionVisitor.h +++ b/include/tclap/VersionVisitor.h @@ -1,3 +1,4 @@ +// -*- Mode: c++; c-basic-offset: 4; tab-width: 4; -*- /****************************************************************************** * @@ -61,7 +62,10 @@ class VersionVisitor: public Visitor * Calls the version method of the output object using the * specified CmdLine. */ - void visit() { (*_out)->version(*_cmd); exit(0); } + void visit() { + (*_out)->version(*_cmd); + throw ExitException(0); + } };