From 684cecd6326c88836ae8a47962e154d318d1c512 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Fri, 11 Dec 2020 18:00:12 +0000 Subject: [PATCH] Minor bug fixes in the help of calypTools --- lib/CalypOptions.cpp | 17 +++++++-------- lib/CalypOptions.h | 6 +++--- tools/CalypTools.cpp | 6 +++--- tools/CalypToolsCmdParser.cpp | 40 ++++++++++++++++++----------------- 4 files changed, 35 insertions(+), 34 deletions(-) diff --git a/lib/CalypOptions.cpp b/lib/CalypOptions.cpp index 46a38d2..493b85e 100644 --- a/lib/CalypOptions.cpp +++ b/lib/CalypOptions.cpp @@ -38,13 +38,13 @@ #include "CalypOptions.h" -#include "config.h" -#include "lib/CalypModuleIf.h" - #include #include #include +#include "config.h" +#include "lib/CalypModuleIf.h" + using namespace std; struct ParseFailure : public std::exception @@ -284,7 +284,7 @@ bool CalypOptions::hasOpt( const ClpString& optName ) void CalypOptions::addDefaultOptions() { addOptions() /**/ - ( "help,h", "produce help message" ) /**/ + ( "help", "produce help message" ) /**/ ( "version", "show version and exit" ) /**/ ( "pel_fmts", "list pixel formats" ) /**/ ( "quality_metrics", "list supported quality metrics" ) /**/ @@ -477,27 +477,26 @@ unsigned int CalypOptions::parseSHORT( unsigned int argc, char* argv[] ) return 1; } -bool CalypOptions::parse( unsigned int argc, char* argv[] ) +int CalypOptions::parse( unsigned int argc, char* argv[] ) { try { m_aUnhandledArgs = scanArgv( argc, argv ); - if( checkListingOpts() ) { - return false; + return 1; } } catch( std::exception& e ) { std::cerr << "error: " << e.what() << "\n"; - return false; + return -1; } catch( ... ) { std::cerr << "Exception of unknown type!\n"; } - return true; + return 0; } list CalypOptions::scanArgv( unsigned int argc, char* argv[] ) diff --git a/lib/CalypOptions.h b/lib/CalypOptions.h index 8f4fe32..ab2e151 100644 --- a/lib/CalypOptions.h +++ b/lib/CalypOptions.h @@ -40,11 +40,11 @@ #ifndef __CALYPOPTIONS_H__ #define __CALYPOPTIONS_H__ -#include "CalypDefs.h" - #include #include +#include "CalypDefs.h" + /** * \class OptionBase * \ingroup CalypLibGrp @@ -90,7 +90,7 @@ public: CalypOptions( const ClpString& name = "" ); ~CalypOptions(); - bool parse( unsigned int argc, char* argv[] ); + int parse( unsigned int argc, char* argv[] ); void parse( std::vector args_array ); std::list& getUnhandledArgs() { return m_aUnhandledArgs; } diff --git a/tools/CalypTools.cpp b/tools/CalypTools.cpp index 9463caa..c17a51a 100644 --- a/tools/CalypTools.cpp +++ b/tools/CalypTools.cpp @@ -1,5 +1,5 @@ /* This file is a part of Calyp project - * Copyright (C) 2014-2019 by Joao Carreira (jfmcarreira@gmail.com) + * Copyright (C) 2014-2020 by Joao Carreira (jfmcarreira@gmail.com) * Luis Lucas (luisfrlucas@gmail.com) * * This program is free software; you can redistribute it and/or modify @@ -421,8 +421,8 @@ int CalypTools::Open( int argc, char* argv[] ) if( m_uiOperation == INVALID_OPERATION ) { - log( CLP_LOG_ERROR, "No operation was selected! " ); - return -1; + log( CLP_LOG_ERROR, "No operation was selected! Use --help to see usage.\n" ); + return 1; } return iRet; } diff --git a/tools/CalypToolsCmdParser.cpp b/tools/CalypToolsCmdParser.cpp index 1a4efce..9d28a21 100644 --- a/tools/CalypToolsCmdParser.cpp +++ b/tools/CalypToolsCmdParser.cpp @@ -1,5 +1,5 @@ /* This file is a part of Calyp project - * Copyright (C) 2014-2019 by Joao Carreira (jfmcarreira@gmail.com) + * Copyright (C) 2014-202 by Joao Carreira (jfmcarreira@gmail.com) * Luis Lucas (luisfrlucas@gmail.com) * * This program is free software; you can redistribute it and/or modify @@ -59,23 +59,25 @@ int CalypToolsCmdParser::parseToolsArgs( int argc, char* argv[] ) { int iRet = 0; - m_cOptions.addOptions() /**/ - ( "quiet,q", m_bQuiet, "disable verbose" )( "input,i", m_apcInputs, "input file" ) /**/ - ( "output,o", m_strOutput, "output file" ) /**/ - ( "size,s", m_strResolution, "size (WxH)" ) /**/ - ( "pel_fmt,p", m_strPelFmt, "pixel format" ) /**/ - ( "bits_pel", m_strBitsPerPixel, "bits per pixel" ) /**/ - ( "endianness", m_strEndianness, "File endianness (big, little)" ) /**/ - ( "has_negative", m_strHasNegativeValues, "Flag for files with negatie values" ) /**/ - ( "frames,f", m_iFrames, "number of frames to parse" ) /**/ - ( "quality", m_strQualityMetric, "select a quality metric" ) /**/ - ( "module", m_strModule, "select a module (use internal name)" ) /**/ - ( "save", "save a specific frame" ) /**/ - ( "rate-reduction", m_iRateReductionFactor, "reduce the frame rate" ); /**/ + m_cOptions.addOptions() /**/ + ( "quiet,q", m_bQuiet, "disable verbose" ) /**/ + ( "input,i", m_apcInputs, "input file" ) /**/ + ( "output,o", m_strOutput, "output file" ) /**/ + ( "size,s", m_strResolution, "size (WxH)" ) /**/ + ( "pel_fmt,p", m_strPelFmt, "pixel format" ) /**/ + ( "bits_pel", m_strBitsPerPixel, "bits per pixel" ) /**/ + ( "endianness", m_strEndianness, "File endianness (big, little)" ) /**/ + ( "has_negative", m_strHasNegativeValues, "Flag for files with negatie values" ) /**/ + ( "frames,f", m_iFrames, "number of frames to parse" ) /**/ + ( "quality", m_strQualityMetric, "select a quality metric" ) /**/ + ( "module", m_strModule, "select a module (use internal name)" ) /**/ + ( "save", "save a specific frame" ) /**/ + ( "rate-reduction", m_iRateReductionFactor, "reduce the frame rate" ); /**/ - if( !m_cOptions.parse( argc, argv ) ) + iRet = m_cOptions.parse( argc, argv ); + if( iRet < 0 || iRet > 0 ) { - iRet = -1; + return iRet; } if( m_bQuiet ) @@ -96,9 +98,9 @@ int CalypToolsCmdParser::parseToolsArgs( int argc, char* argv[] ) } else if( m_cOptions.hasOpt( "help" ) ) { - printf( "Usage: %s modules/quality/save [options] -input=input_file " - "[--output=output_file]\n", - argv[0] ); + printf( "Usage: %s module/quality/save [options] --input=input_file [--output=output_file]\n", argv[0] ); + printf( " %s --module=module_name [options] --input=input_file [--output=output_file]\n", argv[0] ); + printf( " %s --quality=quality_metric [options] --input=input_file1 --input=input_file2\n", argv[0] ); m_cOptions.doHelp( std::cout ); iRet = 1; }