From a14c45d8c7005399495456799fe2a61badb7347b Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Tue, 13 Oct 2020 19:49:34 +0200 Subject: [PATCH] Small improvements --- scripts/cppcheck.sh | 4 +-- src/fapplication.cpp | 62 +++++++++++++++++--------------- src/include/final/fapplication.h | 30 ++++++++-------- src/include/final/flog.h | 2 +- src/include/final/fstring.h | 16 ++++----- 5 files changed, 58 insertions(+), 56 deletions(-) diff --git a/scripts/cppcheck.sh b/scripts/cppcheck.sh index e98a26b7..99adf228 100755 --- a/scripts/cppcheck.sh +++ b/scripts/cppcheck.sh @@ -2,8 +2,8 @@ if [ $# -gt 0 ] then - eval cppcheck --force --std=c++11 --enable=all -I../src/include/ "$@" + eval cppcheck --force --language=c++ --std=c++11 --enable=all -I../src/include/ "$@" else - eval cppcheck --force --std=c++11 --enable=all -I../src/include/ ../src/ ../examples/ + eval cppcheck --force --language=c++ --std=c++11 --enable=all -I../src/include/ ../src/ ../examples/ fi diff --git a/src/fapplication.cpp b/src/fapplication.cpp index 4de4859f..47393032 100644 --- a/src/fapplication.cpp +++ b/src/fapplication.cpp @@ -69,31 +69,6 @@ uInt64 FApplication::next_event_wait {5000}; // preset to 5 ms (200 struct timeval FApplication::time_last_event{}; -const std::vector FApplication::long_options = -{ - {"encoding", required_argument, nullptr, 'e' }, - {"log-file", required_argument, nullptr, 'l' }, - {"no-mouse", no_argument, nullptr, 'm' }, - {"no-optimized-cursor", no_argument, nullptr, 'o' }, - {"no-terminal-detection", no_argument, nullptr, 'd' }, - {"no-terminal-data-request", no_argument, nullptr, 'r' }, - {"no-color-change", no_argument, nullptr, 'c' }, - {"no-sgr-optimizer", no_argument, nullptr, 's' }, - {"vgafont", no_argument, nullptr, 'v' }, - {"newfont", no_argument, nullptr, 'n' }, - {"dark-theme", no_argument, nullptr, 't' }, - -#if defined(__FreeBSD__) || defined(__DragonFly__) - {"no-esc-for-alt-meta", no_argument, nullptr, 'E' }, - {"no-cursorstyle-change", no_argument, nullptr, 'C' }, -#elif defined(__NetBSD__) || defined(__OpenBSD__) - {"no-esc-for-alt-meta", no_argument, nullptr, 'E' }, -#endif - - {nullptr, 0, nullptr, 0 } -}; - - //---------------------------------------------------------------------- // class FApplication //---------------------------------------------------------------------- @@ -484,13 +459,40 @@ void FApplication::setTerminalEncoding (const FString& enc_str) } //---------------------------------------------------------------------- -inline FApplication::CmdMap& FApplication::mapCmdOptions() +inline void FApplication::setLongOptions (std::vector& long_options) +{ + long_options = + { + {"encoding", required_argument, nullptr, 'e' }, + {"log-file", required_argument, nullptr, 'l' }, + {"no-mouse", no_argument, nullptr, 'm' }, + {"no-optimized-cursor", no_argument, nullptr, 'o' }, + {"no-terminal-detection", no_argument, nullptr, 'd' }, + {"no-terminal-data-request", no_argument, nullptr, 'r' }, + {"no-color-change", no_argument, nullptr, 'c' }, + {"no-sgr-optimizer", no_argument, nullptr, 's' }, + {"vgafont", no_argument, nullptr, 'v' }, + {"newfont", no_argument, nullptr, 'n' }, + {"dark-theme", no_argument, nullptr, 't' }, + + #if defined(__FreeBSD__) || defined(__DragonFly__) + {"no-esc-for-alt-meta", no_argument, nullptr, 'E' }, + {"no-cursorstyle-change", no_argument, nullptr, 'C' }, + #elif defined(__NetBSD__) || defined(__OpenBSD__) + {"no-esc-for-alt-meta", no_argument, nullptr, 'E' }, + #endif + + {nullptr, 0, nullptr, 0 } + }; +} + +//---------------------------------------------------------------------- +inline void FApplication::setCmdOptionsMap (CmdMap& cmd_map) { using std::placeholders::_1; auto enc = std::bind(&FApplication::setTerminalEncoding, _1); auto log = std::bind(&FApplication::setLogFile, _1); auto opt = &FApplication::getStartOptions; - static CmdMap cmd_map{}; // --encoding cmd_map['e'] = [enc] (const char* arg) { enc(FString(arg)); }; @@ -523,7 +525,6 @@ inline FApplication::CmdMap& FApplication::mapCmdOptions() // --no-esc-for-alt-meta cmd_map['E'] = [opt] (const char*) { opt().meta_sends_escape = false; }; #endif - return cmd_map; } //---------------------------------------------------------------------- @@ -531,12 +532,15 @@ void FApplication::cmdOptions (const int& argc, char* argv[]) { // Interpret the command line options - auto& cmd_map = mapCmdOptions(); + CmdMap cmd_map{}; + setCmdOptionsMap(cmd_map); while ( true ) { opterr = 0; int idx{0}; + std::vector long_options{}; + setLongOptions(long_options); auto p = reinterpret_cast(long_options.data()); const int opt = getopt_long (argc, argv, "", p, &idx); diff --git a/src/include/final/fapplication.h b/src/include/final/fapplication.h index e9803d9d..ec24e493 100644 --- a/src/include/final/fapplication.h +++ b/src/include/final/fapplication.h @@ -150,6 +150,18 @@ class FApplication : public FWidget virtual void processExternalUserEvent(); private: +#if defined(__sun) && defined(__SVR4) + struct CmdOption + { + const char* name; // <- name is without 'const' in Solaris + int has_arg; + int* flag; + int val; + }; +#else + using CmdOption = struct option; +#endif + // Typedefs typedef std::pair EventPair; typedef std::deque FEventQueue; @@ -158,7 +170,8 @@ class FApplication : public FWidget // Methods void init(); static void setTerminalEncoding (const FString&); - static CmdMap& mapCmdOptions(); + static void setLongOptions(std::vector&); + static void setCmdOptionsMap (CmdMap&); static void cmdOptions (const int&, char*[]); static FStartOptions& getStartOptions(); static void showParameterUsage(); @@ -222,23 +235,8 @@ class FApplication : public FWidget static FMouseControl* mouse; static FKeyboard* keyboard; static FWidget* keyboard_widget; - -#if defined(__sun) && defined(__SVR4) - struct CmdOption - { - const char* name; // <- name is without 'const' in Solaris - int has_arg; - int* flag; - int val; - }; -#else - using CmdOption = struct option; -#endif - - static const std::vector long_options; }; - // non-member function forward declarations // implemented in fwidget_functions.cpp //---------------------------------------------------------------------- diff --git a/src/include/final/flog.h b/src/include/final/flog.h index ffc5b56f..e5d46e0d 100644 --- a/src/include/final/flog.h +++ b/src/include/final/flog.h @@ -108,7 +108,7 @@ class FLog : public std::stringbuf // Data member LogLevel level{Info}; LineEnding end_of_line{CRLF}; - std::mutex mut; + std::mutex mut{}; FLogPrint current_log{std::bind(&FLog::info, this, std::placeholders::_1)}; std::ostream stream{this}; diff --git a/src/include/final/fstring.h b/src/include/final/fstring.h index f5d02195..38f94404 100644 --- a/src/include/final/fstring.h +++ b/src/include/final/fstring.h @@ -112,11 +112,11 @@ class FString FString& operator << (const wchar_t); FString& operator << (const char); template ::value + , typename std::enable_if< ( std::is_integral::value && ! std::is_same::value - && ! std::is_pointer::value - || std::is_floating_point::value - && ! std::is_pointer::value + && ! std::is_pointer::value ) + || ( std::is_floating_point::value + && ! std::is_pointer::value ) , int>::type = 0 > FString& operator << (const NumT); @@ -275,11 +275,11 @@ class FString // FString inline functions //---------------------------------------------------------------------- template ::value + , typename std::enable_if< ( std::is_integral::value && ! std::is_same::value - && ! std::is_pointer::value - || std::is_floating_point::value - && ! std::is_pointer::value + && ! std::is_pointer::value ) + || ( std::is_floating_point::value + && ! std::is_pointer::value ) , int>::type > inline FString& FString::operator << (const NumT val) {