mirror of
https://github.com/labwc/labwc.git
synced 2025-11-05 13:29:58 -05:00
common/parse-bool.c: make parse_bool() generic
...to avoid multiple versions of a boolean-parser. - Optionally take a default value - Return -1 on error - Rename get-bool.c to parse-bool.c
This commit is contained in:
parent
473f0aacbd
commit
fa50149525
7 changed files with 144 additions and 64 deletions
25
src/common/parse-bool.c
Normal file
25
src/common/parse-bool.c
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include "common/parse-bool.h"
|
||||
|
||||
int
|
||||
parse_bool(const char *str, int default_value)
|
||||
{
|
||||
if (!str) {
|
||||
goto error_not_a_boolean;
|
||||
} else if (!strcasecmp(str, "yes")) {
|
||||
return true;
|
||||
} else if (!strcasecmp(str, "true")) {
|
||||
return true;
|
||||
} else if (!strcasecmp(str, "no")) {
|
||||
return false;
|
||||
} else if (!strcasecmp(str, "false")) {
|
||||
return false;
|
||||
}
|
||||
error_not_a_boolean:
|
||||
wlr_log(WLR_ERROR, "(%s) is not a boolean value", str);
|
||||
return default_value;
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue