From f3bdee9bd2e232db274635ac2c93ec0ec1ec1c40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=A9rence=20Clastres?= Date: Sun, 21 Jun 2020 00:17:20 +0200 Subject: [PATCH] CLI: Allow --mode flag to be case insensitive Also fix handling when no argument passed --- cli.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cli.cpp b/cli.cpp index 50d77eaa..13c43270 100644 --- a/cli.cpp +++ b/cli.cpp @@ -11,6 +11,8 @@ #ifdef _WIN32 #include +/* swy: quirk for MSVC; which doesn't support this case-insensitive function */ +#define strcasecmp strcmpi #endif #ifdef __APPLE__ @@ -101,7 +103,9 @@ unsigned int ParseMode(DeviceOptions& options) { // no need to check if --mode wasn't passed if (options.mode.size() == 0) + { return false; + } /*---------------------------------------------------------*\ | Search through all of the device modes and see if there is| @@ -109,7 +113,7 @@ unsigned int ParseMode(DeviceOptions& options) \*---------------------------------------------------------*/ for(std::size_t mode_idx = 0; mode_idx < rgb_controllers[options.device]->modes.size(); mode_idx++) { - if (rgb_controllers[options.device]->modes[mode_idx].name == options.mode) + if (strcasecmp(rgb_controllers[options.device]->modes[mode_idx].name.c_str(), options.mode.c_str()) == 0) { return mode_idx; } @@ -378,6 +382,11 @@ bool OptionColor(int *currentDev, int *current_zone, std::string argument, Optio bool OptionMode(int *currentDev, std::string argument, Options *options) { + if (argument.size() == 0) + { + std::cout << "Error: --mode passed with no argument" << std::endl; + return false; + } DeviceOptions* currentDevOpts = GetDeviceOptionsForDevID(options, *currentDev); currentDevOpts->mode = argument; currentDevOpts->hasOption = true;