Small improvements

This commit is contained in:
Markus Gans 2020-10-13 19:49:34 +02:00
parent 3c46dad798
commit a14c45d8c7
5 changed files with 58 additions and 56 deletions

View File

@ -2,8 +2,8 @@
if [ $# -gt 0 ] if [ $# -gt 0 ]
then 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 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 fi

View File

@ -69,31 +69,6 @@ uInt64 FApplication::next_event_wait {5000}; // preset to 5 ms (200
struct timeval FApplication::time_last_event{}; struct timeval FApplication::time_last_event{};
const std::vector<FApplication::CmdOption> 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 // class FApplication
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -484,13 +459,40 @@ void FApplication::setTerminalEncoding (const FString& enc_str)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline FApplication::CmdMap& FApplication::mapCmdOptions() inline void FApplication::setLongOptions (std::vector<CmdOption>& 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; using std::placeholders::_1;
auto enc = std::bind(&FApplication::setTerminalEncoding, _1); auto enc = std::bind(&FApplication::setTerminalEncoding, _1);
auto log = std::bind(&FApplication::setLogFile, _1); auto log = std::bind(&FApplication::setLogFile, _1);
auto opt = &FApplication::getStartOptions; auto opt = &FApplication::getStartOptions;
static CmdMap cmd_map{};
// --encoding // --encoding
cmd_map['e'] = [enc] (const char* arg) { enc(FString(arg)); }; cmd_map['e'] = [enc] (const char* arg) { enc(FString(arg)); };
@ -523,7 +525,6 @@ inline FApplication::CmdMap& FApplication::mapCmdOptions()
// --no-esc-for-alt-meta // --no-esc-for-alt-meta
cmd_map['E'] = [opt] (const char*) { opt().meta_sends_escape = false; }; cmd_map['E'] = [opt] (const char*) { opt().meta_sends_escape = false; };
#endif #endif
return cmd_map;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -531,12 +532,15 @@ void FApplication::cmdOptions (const int& argc, char* argv[])
{ {
// Interpret the command line options // Interpret the command line options
auto& cmd_map = mapCmdOptions(); CmdMap cmd_map{};
setCmdOptionsMap(cmd_map);
while ( true ) while ( true )
{ {
opterr = 0; opterr = 0;
int idx{0}; int idx{0};
std::vector<CmdOption> long_options{};
setLongOptions(long_options);
auto p = reinterpret_cast<const struct option*>(long_options.data()); auto p = reinterpret_cast<const struct option*>(long_options.data());
const int opt = getopt_long (argc, argv, "", p, &idx); const int opt = getopt_long (argc, argv, "", p, &idx);

View File

@ -150,6 +150,18 @@ class FApplication : public FWidget
virtual void processExternalUserEvent(); virtual void processExternalUserEvent();
private: 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 // Typedefs
typedef std::pair<FObject*, FEvent*> EventPair; typedef std::pair<FObject*, FEvent*> EventPair;
typedef std::deque<EventPair> FEventQueue; typedef std::deque<EventPair> FEventQueue;
@ -158,7 +170,8 @@ class FApplication : public FWidget
// Methods // Methods
void init(); void init();
static void setTerminalEncoding (const FString&); static void setTerminalEncoding (const FString&);
static CmdMap& mapCmdOptions(); static void setLongOptions(std::vector<CmdOption>&);
static void setCmdOptionsMap (CmdMap&);
static void cmdOptions (const int&, char*[]); static void cmdOptions (const int&, char*[]);
static FStartOptions& getStartOptions(); static FStartOptions& getStartOptions();
static void showParameterUsage(); static void showParameterUsage();
@ -222,23 +235,8 @@ class FApplication : public FWidget
static FMouseControl* mouse; static FMouseControl* mouse;
static FKeyboard* keyboard; static FKeyboard* keyboard;
static FWidget* keyboard_widget; 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<CmdOption> long_options;
}; };
// non-member function forward declarations // non-member function forward declarations
// implemented in fwidget_functions.cpp // implemented in fwidget_functions.cpp
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -108,7 +108,7 @@ class FLog : public std::stringbuf
// Data member // Data member
LogLevel level{Info}; LogLevel level{Info};
LineEnding end_of_line{CRLF}; LineEnding end_of_line{CRLF};
std::mutex mut; std::mutex mut{};
FLogPrint current_log{std::bind(&FLog::info, this, std::placeholders::_1)}; FLogPrint current_log{std::bind(&FLog::info, this, std::placeholders::_1)};
std::ostream stream{this}; std::ostream stream{this};

View File

@ -112,11 +112,11 @@ class FString
FString& operator << (const wchar_t); FString& operator << (const wchar_t);
FString& operator << (const char); FString& operator << (const char);
template <typename NumT template <typename NumT
, typename std::enable_if< std::is_integral<NumT>::value , typename std::enable_if< ( std::is_integral<NumT>::value
&& ! std::is_same<NumT, bool>::value && ! std::is_same<NumT, bool>::value
&& ! std::is_pointer<NumT>::value && ! std::is_pointer<NumT>::value )
|| std::is_floating_point<NumT>::value || ( std::is_floating_point<NumT>::value
&& ! std::is_pointer<NumT>::value && ! std::is_pointer<NumT>::value )
, int>::type = 0 > , int>::type = 0 >
FString& operator << (const NumT); FString& operator << (const NumT);
@ -275,11 +275,11 @@ class FString
// FString inline functions // FString inline functions
//---------------------------------------------------------------------- //----------------------------------------------------------------------
template <typename NumT template <typename NumT
, typename std::enable_if< std::is_integral<NumT>::value , typename std::enable_if< ( std::is_integral<NumT>::value
&& ! std::is_same<NumT, bool>::value && ! std::is_same<NumT, bool>::value
&& ! std::is_pointer<NumT>::value && ! std::is_pointer<NumT>::value )
|| std::is_floating_point<NumT>::value || ( std::is_floating_point<NumT>::value
&& ! std::is_pointer<NumT>::value && ! std::is_pointer<NumT>::value )
, int>::type > , int>::type >
inline FString& FString::operator << (const NumT val) inline FString& FString::operator << (const NumT val)
{ {