diff options
author | 2018-07-23 21:49:16 -0400 | |
---|---|---|
committer | 2018-07-23 21:49:16 -0400 | |
commit | 71774ecd3658653328f3c903869b52c51c62e237 (patch) | |
tree | bfc136252f81a5350f240c20161d2d0bfc2f80dd /common/util.c | |
parent | Merge pull request #2342 from RyanDwyer/update-cursor (diff) | |
parent | Address review comments on parse_boolean (diff) | |
download | sway-71774ecd3658653328f3c903869b52c51c62e237.tar.gz sway-71774ecd3658653328f3c903869b52c51c62e237.tar.zst sway-71774ecd3658653328f3c903869b52c51c62e237.zip |
Merge pull request #2340 from RedSoxFan/parse_boolean
Switch to using a function to parse booleans
Diffstat (limited to 'common/util.c')
-rw-r--r-- | common/util.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/common/util.c b/common/util.c index e8a88772..467aa4b5 100644 --- a/common/util.c +++ b/common/util.c | |||
@@ -123,6 +123,22 @@ uint32_t parse_color(const char *color) { | |||
123 | return res; | 123 | return res; |
124 | } | 124 | } |
125 | 125 | ||
126 | bool parse_boolean(const char *boolean, bool current) { | ||
127 | if (strcasecmp(boolean, "1") == 0 | ||
128 | || strcasecmp(boolean, "yes") == 0 | ||
129 | || strcasecmp(boolean, "on") == 0 | ||
130 | || strcasecmp(boolean, "true") == 0 | ||
131 | || strcasecmp(boolean, "enable") == 0 | ||
132 | || strcasecmp(boolean, "enabled") == 0 | ||
133 | || strcasecmp(boolean, "active") == 0) { | ||
134 | return true; | ||
135 | } else if (strcasecmp(boolean, "toggle") == 0) { | ||
136 | return !current; | ||
137 | } | ||
138 | // All other values are false to match i3 | ||
139 | return false; | ||
140 | } | ||
141 | |||
126 | char* resolve_path(const char* path) { | 142 | char* resolve_path(const char* path) { |
127 | struct stat sb; | 143 | struct stat sb; |
128 | ssize_t r; | 144 | ssize_t r; |