Small improvements
This commit is contained in:
parent
3c46dad798
commit
a14c45d8c7
|
@ -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
|
||||
|
||||
|
|
|
@ -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::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
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -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;
|
||||
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<CmdOption> long_options{};
|
||||
setLongOptions(long_options);
|
||||
auto p = reinterpret_cast<const struct option*>(long_options.data());
|
||||
const int opt = getopt_long (argc, argv, "", p, &idx);
|
||||
|
||||
|
|
|
@ -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<FObject*, FEvent*> EventPair;
|
||||
typedef std::deque<EventPair> 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<CmdOption>&);
|
||||
static void setCmdOptionsMap (CmdMap&);
|
||||
static void cmdOptions (const int&, char*[]);
|
||||
static FStartOptions& getStartOptions();
|
||||
static void showParameterUsage();
|
||||
|
@ -222,22 +235,7 @@ 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<CmdOption> long_options;
|
||||
};
|
||||
|
||||
|
||||
// non-member function forward declarations
|
||||
// implemented in fwidget_functions.cpp
|
||||
|
|
|
@ -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};
|
||||
|
||||
|
|
|
@ -112,11 +112,11 @@ class FString
|
|||
FString& operator << (const wchar_t);
|
||||
FString& operator << (const char);
|
||||
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_pointer<NumT>::value
|
||||
|| std::is_floating_point<NumT>::value
|
||||
&& ! std::is_pointer<NumT>::value
|
||||
&& ! std::is_pointer<NumT>::value )
|
||||
|| ( std::is_floating_point<NumT>::value
|
||||
&& ! std::is_pointer<NumT>::value )
|
||||
, int>::type = 0 >
|
||||
FString& operator << (const NumT);
|
||||
|
||||
|
@ -275,11 +275,11 @@ class FString
|
|||
// FString inline functions
|
||||
//----------------------------------------------------------------------
|
||||
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_pointer<NumT>::value
|
||||
|| std::is_floating_point<NumT>::value
|
||||
&& ! std::is_pointer<NumT>::value
|
||||
&& ! std::is_pointer<NumT>::value )
|
||||
|| ( std::is_floating_point<NumT>::value
|
||||
&& ! std::is_pointer<NumT>::value )
|
||||
, int>::type >
|
||||
inline FString& FString::operator << (const NumT val)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue