From bdf6e13881496d5e186065c56c9382c0a6206985 Mon Sep 17 00:00:00 2001 From: Johan Malm Date: Sun, 26 Mar 2023 10:56:10 +0100 Subject: [PATCH] Move get_bool() to src/common/ ...in preparation for sharing it more widely --- include/common/get-bool.h | 15 +++++++++++++++ src/common/get-bool.c | 19 +++++++++++++++++++ src/common/meson.build | 1 + src/config/rcxml.c | 16 +--------------- 4 files changed, 36 insertions(+), 15 deletions(-) create mode 100644 include/common/get-bool.h create mode 100644 src/common/get-bool.c diff --git a/include/common/get-bool.h b/include/common/get-bool.h new file mode 100644 index 00000000..9c480fde --- /dev/null +++ b/include/common/get-bool.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __LABWC_GET_BOOL_H +#define __LABWC_GET_BOOL_H +#include + +/** + * get_bool - interpret string and return boolean + * @s: string to interpret + * + * Note: This merely performs a case-insensitive check for 'yes' and 'true'. + * Returns false by default. + */ +bool get_bool(const char *s); + +#endif /* __LABWC_GET_BOOL_H */ diff --git a/src/common/get-bool.c b/src/common/get-bool.c new file mode 100644 index 00000000..afddbb4c --- /dev/null +++ b/src/common/get-bool.c @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include +#include +#include "common/get-bool.h" + +bool +get_bool(const char *s) +{ + if (!s) { + return false; + } + if (!strcasecmp(s, "yes")) { + return true; + } + if (!strcasecmp(s, "true")) { + return true; + } + return false; +} diff --git a/src/common/meson.build b/src/common/meson.build index e4f507b6..5f21c258 100644 --- a/src/common/meson.build +++ b/src/common/meson.build @@ -3,6 +3,7 @@ labwc_sources += files( 'dir.c', 'fd_util.c', 'font.c', + 'get-bool.c', 'grab-file.c', 'graphic-helpers.c', 'mem.c', diff --git a/src/config/rcxml.c b/src/config/rcxml.c index 53a95e45..d0321d3d 100644 --- a/src/config/rcxml.c +++ b/src/config/rcxml.c @@ -15,6 +15,7 @@ #include #include #include "action.h" +#include "common/get-bool.h" #include "common/list.h" #include "common/mem.h" #include "common/nodename.h" @@ -178,21 +179,6 @@ fill_mousebind(char *nodename, char *content) } } -static bool -get_bool(const char *s) -{ - if (!s) { - return false; - } - if (!strcasecmp(s, "yes")) { - return true; - } - if (!strcasecmp(s, "true")) { - return true; - } - return false; -} - static enum libinput_config_accel_profile get_accel_profile(const char *s) { -- 2.52.0