mirror of
https://github.com/labwc/labwc.git
synced 2025-11-06 13:29:58 -05:00
config/rcxml.c: fix parsing of three-state query parameters
This commit is contained in:
parent
96da82c085
commit
2b877d2293
3 changed files with 35 additions and 15 deletions
|
|
@ -3,31 +3,41 @@
|
|||
#include <wlr/util/log.h>
|
||||
#include "common/parse-bool.h"
|
||||
|
||||
int
|
||||
parse_bool(const char *str, int default_value)
|
||||
enum three_state
|
||||
parse_three_state(const char *str)
|
||||
{
|
||||
if (!str) {
|
||||
goto error_not_a_boolean;
|
||||
} else if (!strcasecmp(str, "yes")) {
|
||||
return true;
|
||||
return LAB_STATE_ENABLED;
|
||||
} else if (!strcasecmp(str, "true")) {
|
||||
return true;
|
||||
return LAB_STATE_ENABLED;
|
||||
} else if (!strcasecmp(str, "on")) {
|
||||
return true;
|
||||
return LAB_STATE_ENABLED;
|
||||
} else if (!strcmp(str, "1")) {
|
||||
return true;
|
||||
return LAB_STATE_ENABLED;
|
||||
} else if (!strcasecmp(str, "no")) {
|
||||
return false;
|
||||
return LAB_STATE_DISABLED;
|
||||
} else if (!strcasecmp(str, "false")) {
|
||||
return false;
|
||||
return LAB_STATE_DISABLED;
|
||||
} else if (!strcasecmp(str, "off")) {
|
||||
return false;
|
||||
return LAB_STATE_DISABLED;
|
||||
} else if (!strcmp(str, "0")) {
|
||||
return false;
|
||||
return LAB_STATE_DISABLED;
|
||||
}
|
||||
error_not_a_boolean:
|
||||
wlr_log(WLR_ERROR, "(%s) is not a boolean value", str);
|
||||
return default_value;
|
||||
return LAB_STATE_UNSPECIFIED;
|
||||
}
|
||||
|
||||
int
|
||||
parse_bool(const char *str, int default_value)
|
||||
{
|
||||
enum three_state val = parse_three_state(str);
|
||||
if (val == LAB_STATE_UNSPECIFIED) {
|
||||
return default_value;
|
||||
}
|
||||
return (val == LAB_STATE_ENABLED) ? 1 : 0;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue