From 863914ec9574eb58cb0746d59f216997c4863cdf Mon Sep 17 00:00:00 2001 From: Brian Ashworth Date: Mon, 23 Jul 2018 15:04:46 -0400 Subject: Switch to using a function to parse booleans --- common/util.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'common') diff --git a/common/util.c b/common/util.c index e8a88772..33a0c77e 100644 --- a/common/util.c +++ b/common/util.c @@ -123,6 +123,21 @@ uint32_t parse_color(const char *color) { return res; } +bool parse_boolean(const char *boolean, const bool current) { + if (strcmp(boolean, "1") == 0 + || strcmp(boolean, "yes") == 0 + || strcmp(boolean, "on") == 0 + || strcmp(boolean, "true") == 0 + || strcmp(boolean, "enable") == 0 + || strcmp(boolean, "enabled") == 0 + || strcmp(boolean, "active") == 0) { + return true; + } else if (strcmp(boolean, "toggle") == 0) { + return !current; + } + return false; +} + char* resolve_path(const char* path) { struct stat sb; ssize_t r; -- cgit v1.2.3 From d56d62c1c0b504d6c414f4b970a4a996cdadd879 Mon Sep 17 00:00:00 2001 From: Brian Ashworth Date: Mon, 23 Jul 2018 16:22:09 -0400 Subject: Remove unneeded const --- common/util.c | 2 +- include/util.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'common') diff --git a/common/util.c b/common/util.c index 33a0c77e..3fa0c03f 100644 --- a/common/util.c +++ b/common/util.c @@ -123,7 +123,7 @@ uint32_t parse_color(const char *color) { return res; } -bool parse_boolean(const char *boolean, const bool current) { +bool parse_boolean(const char *boolean, bool current) { if (strcmp(boolean, "1") == 0 || strcmp(boolean, "yes") == 0 || strcmp(boolean, "on") == 0 diff --git a/include/util.h b/include/util.h index 40f2c7b1..bda941ce 100644 --- a/include/util.h +++ b/include/util.h @@ -56,7 +56,7 @@ uint32_t parse_color(const char *color); * toggling is not desired, pass in true for current so that toggling values * get parsed as not true. */ -bool parse_boolean(const char *boolean, const bool current); +bool parse_boolean(const char *boolean, bool current); /** * Given a path string, recurseively resolves any symlinks to their targets -- cgit v1.2.3 From 9ec1d6cf79e6f9c3233f577c6fddeaeb21bb1bfc Mon Sep 17 00:00:00 2001 From: Brian Ashworth Date: Mon, 23 Jul 2018 21:37:53 -0400 Subject: Address review comments on parse_boolean --- common/util.c | 17 +++++++++-------- sway/commands/focus_wrapping.c | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) (limited to 'common') diff --git a/common/util.c b/common/util.c index 3fa0c03f..467aa4b5 100644 --- a/common/util.c +++ b/common/util.c @@ -124,17 +124,18 @@ uint32_t parse_color(const char *color) { } bool parse_boolean(const char *boolean, bool current) { - if (strcmp(boolean, "1") == 0 - || strcmp(boolean, "yes") == 0 - || strcmp(boolean, "on") == 0 - || strcmp(boolean, "true") == 0 - || strcmp(boolean, "enable") == 0 - || strcmp(boolean, "enabled") == 0 - || strcmp(boolean, "active") == 0) { + if (strcasecmp(boolean, "1") == 0 + || strcasecmp(boolean, "yes") == 0 + || strcasecmp(boolean, "on") == 0 + || strcasecmp(boolean, "true") == 0 + || strcasecmp(boolean, "enable") == 0 + || strcasecmp(boolean, "enabled") == 0 + || strcasecmp(boolean, "active") == 0) { return true; - } else if (strcmp(boolean, "toggle") == 0) { + } else if (strcasecmp(boolean, "toggle") == 0) { return !current; } + // All other values are false to match i3 return false; } diff --git a/sway/commands/focus_wrapping.c b/sway/commands/focus_wrapping.c index 15704228..562ee4f9 100644 --- a/sway/commands/focus_wrapping.c +++ b/sway/commands/focus_wrapping.c @@ -9,7 +9,7 @@ struct cmd_results *cmd_focus_wrapping(int argc, char **argv) { return error; } - if (strcmp(argv[0], "force") == 0) { + if (strcasecmp(argv[0], "force") == 0) { config->focus_wrapping = WRAP_FORCE; } else if (parse_boolean(argv[0], config->focus_wrapping == WRAP_YES)) { config->focus_wrapping = WRAP_YES; -- cgit v1.2.3