From b24cfff4be24b21382cc1568eee8136a8b436edc Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Mon, 19 Jul 2021 17:35:29 +0200 Subject: [PATCH] Only log error when setting FullScreenSelectedMonitors We don't want the log to spam every time this parameter is used so only complain from the parses when the value is changed. --- vncviewer/MonitorIndicesParameter.cxx | 27 ++++++++++++++++----------- vncviewer/MonitorIndicesParameter.h | 3 ++- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/vncviewer/MonitorIndicesParameter.cxx b/vncviewer/MonitorIndicesParameter.cxx index 651d636b..b3ee4b19 100644 --- a/vncviewer/MonitorIndicesParameter.cxx +++ b/vncviewer/MonitorIndicesParameter.cxx @@ -74,7 +74,7 @@ bool MonitorIndicesParameter::setParam(const char* value) if (strlen(value) < 0) return false; - if (!parseIndices(value, &indices)) { + if (!parseIndices(value, &indices, true)) { vlog.error(_("Invalid configuration specified for %s"), name); return false; } @@ -134,21 +134,19 @@ static bool parseNumber(std::string number, std::set *indices) int v = strtol(number.c_str(), NULL, 0); - if (v <= 0) { - vlog.error(_("The given monitor index(%s) is too small to be valid"), number.c_str()); + if (v <= 0) return false; - } - if (v > INT_MAX) { - vlog.error(_("The given monitor index (%s) is too large to be valid"), number.c_str()); + if (v > INT_MAX) return false; - } indices->insert(v-1); return true; } -bool MonitorIndicesParameter::parseIndices(const char* value, std::set *indices) +bool MonitorIndicesParameter::parseIndices(const char* value, + std::set *indices, + bool complain) { char d; std::string current; @@ -162,13 +160,16 @@ bool MonitorIndicesParameter::parseIndices(const char* value, std::set *ind current.push_back(d); else if (d == ',') { if (!parseNumber(current, indices)) { - vlog.error(_("Invalid monitor index '%s'"), current.c_str()); + if (complain) + vlog.error(_("Invalid monitor index '%s'"), + current.c_str()); return false; } current.clear(); } else { - vlog.error(_("Unexpected character '%c'"), d); + if (complain) + vlog.error(_("Unexpected character '%c'"), d); return false; } } @@ -178,8 +179,12 @@ bool MonitorIndicesParameter::parseIndices(const char* value, std::set *ind return true; // Parsing anything we have left. - if (!parseNumber(current, indices)) + if (!parseNumber(current, indices)) { + if (complain) + vlog.error(_("Invalid monitor index '%s'"), + current.c_str()); return false; + } return true; } diff --git a/vncviewer/MonitorIndicesParameter.h b/vncviewer/MonitorIndicesParameter.h index 1e0925d2..58e55e43 100644 --- a/vncviewer/MonitorIndicesParameter.h +++ b/vncviewer/MonitorIndicesParameter.h @@ -36,7 +36,8 @@ private: int fltkIndex; } Monitor; - bool parseIndices(const char* value, std::set *indices); + bool parseIndices(const char* value, std::set *indices, + bool complain=false); std::vector fetchMonitors(); static int compare(const void*, const void*); }; -- 2.39.5