diff options
author | kcgen <kcgen@users.noreply.github.com> | 2022-10-12 00:51:25 +0300 |
---|---|---|
committer | kcgen <1557255+kcgen@users.noreply.github.com> | 2022-10-22 21:15:34 +0300 |
commit | ec9df4708b60715772d1322d7de42eb8e4c67459 (patch) | |
tree | cc2d0cea45c5d737fd03afe1d2d3e66594729b05 | |
parent | 181dbfce0a149a419b4e34300682bc6da0bebe9c (diff) |
Use the existing interface strings in ParseInterfaces
-rw-r--r-- | src/dos/program_mousectl.cpp | 45 |
1 files changed, 18 insertions, 27 deletions
diff --git a/src/dos/program_mousectl.cpp b/src/dos/program_mousectl.cpp index d66d69e5a..7f529321b 100644 --- a/src/dos/program_mousectl.cpp +++ b/src/dos/program_mousectl.cpp @@ -22,6 +22,7 @@ #include "ansi_code_markup.h" #include "checks.h" +#include "string_utils.h" #include "video.h" #include <set> @@ -119,33 +120,23 @@ bool MOUSECTL::ParseAndRun() bool MOUSECTL::ParseInterfaces(std::vector<std::string> ¶ms) { - while (params.size()) { - auto compare = [¶ms](const char *string) - { - return (0 == strcasecmp(params[0].c_str(), string)); - }; - - // Check if first parameter is one of supported mouse interfaces - if (compare("DOS")) - list_ids.push_back(MouseInterfaceId::DOS); - else if (compare("PS/2")) - list_ids.push_back(MouseInterfaceId::PS2); - else if (compare("PS2")) - list_ids.push_back(MouseInterfaceId::PS2); - else if (compare("COM1")) - list_ids.push_back(MouseInterfaceId::COM1); - else if (compare("COM2")) - list_ids.push_back(MouseInterfaceId::COM2); - else if (compare("COM3")) - list_ids.push_back(MouseInterfaceId::COM3); - else if (compare("COM4")) - list_ids.push_back(MouseInterfaceId::COM4); - else - break; // It isn't - end of interface list - - // First parameter is consummed, remove it - params.erase(params.begin()); - } + auto add_if_is_interface = [&](const std::string ¶m) { + for (const auto id : { + MouseInterfaceId::DOS, + MouseInterfaceId::PS2, + MouseInterfaceId::COM1, + MouseInterfaceId::COM2, + MouseInterfaceId::COM3, + MouseInterfaceId::COM4, + }) { + const auto is_interface = string_iequals(param, GetInterfaceStr(id)); + if (is_interface) + list_ids.push_back(id); + return is_interface; + } + }; + while (!params.empty() && add_if_is_interface(params.front())) + params.erase(params.begin()); // pop // Check that all interfaces are unique std::set<MouseInterfaceId> tmp(list_ids.begin(), list_ids.end()); |