Commit 51d995ad authored by Daniel Stone's avatar Daniel Stone Committed by Daniel Stone

config-parser: Make get_bool be bool

Wayland innovated a lot of cool things, but non-binary boolean values is
the great advances of our time.

Make config_parser_get_bool() work on boolean values, and switch all its
users.
Signed-off-by: Daniel Stone's avatarDaniel Stone <daniels@collabora.com>
parent 0a4f6e7d
......@@ -77,7 +77,7 @@ struct desktop {
struct widget *grab_widget;
struct weston_config *config;
int locking;
bool locking;
enum cursor_type grab_cursor;
......@@ -1518,7 +1518,7 @@ int main(int argc, char *argv[])
config_file = weston_config_get_name_from_env();
desktop.config = weston_config_parse(config_file);
s = weston_config_get_section(desktop.config, "shell", NULL, NULL);
weston_config_section_get_bool(s, "locking", &desktop.locking, 1);
weston_config_section_get_bool(s, "locking", &desktop.locking, true);
parse_panel_position(&desktop, s);
parse_clock_format(&desktop, s);
......
This diff is collapsed.
......@@ -464,7 +464,7 @@ shell_configuration(struct desktop_shell *shell)
{
struct weston_config_section *section;
char *s, *client;
int allow_zap;
bool allow_zap;
section = weston_config_get_section(wet_get_config(shell->compositor),
"shell", NULL, NULL);
......
......@@ -30,6 +30,7 @@
extern "C" {
#endif
#include <stdbool.h>
#include <stdint.h>
#define WESTON_CONFIG_FILE_ENV_VAR "WESTON_CONFIG_FILE"
......@@ -102,7 +103,7 @@ weston_config_section_get_string(struct weston_config_section *section,
int
weston_config_section_get_bool(struct weston_config_section *section,
const char *key,
int *value, int default_value);
bool *value, bool default_value);
const char *
weston_config_get_name_from_env(void);
......
......@@ -379,7 +379,7 @@ init_ivi_shell(struct weston_compositor *compositor, struct ivi_shell *shell)
{
struct weston_config *config = wet_get_config(compositor);
struct weston_config_section *section;
int developermode;
bool developermode;
shell->compositor = compositor;
......
......@@ -302,7 +302,7 @@ WL_EXPORT
int
weston_config_section_get_bool(struct weston_config_section *section,
const char *key,
int *value, int default_value)
bool *value, bool default_value)
{
struct weston_config_entry *entry;
......@@ -314,9 +314,9 @@ weston_config_section_get_bool(struct weston_config_section *section,
}
if (strcmp(entry->value, "false") == 0)
*value = 0;
*value = false;
else if (strcmp(entry->value, "true") == 0)
*value = 1;
*value = true;
else {
*value = default_value;
errno = EINVAL;
......
......@@ -322,51 +322,55 @@ ZUC_TEST_F(config_test_t1, test009, data)
ZUC_TEST_F(config_test_t1, test010, data)
{
int r, b;
int r;
bool b;
struct weston_config_section *section;
struct weston_config *config = data;
section = weston_config_get_section(config, "bar", NULL, NULL);
r = weston_config_section_get_bool(section, "flag", &b, 600);
r = weston_config_section_get_bool(section, "flag", &b, true);
ZUC_ASSERT_EQ(0, r);
ZUC_ASSERT_EQ(0, b);
ZUC_ASSERT_EQ(false, b);
}
ZUC_TEST_F(config_test_t1, test011, data)
{
int r, b;
int r;
bool b;
struct weston_config_section *section;
struct weston_config *config = data;
section = weston_config_get_section(config, "stuff", NULL, NULL);
r = weston_config_section_get_bool(section, "flag", &b, -1);
r = weston_config_section_get_bool(section, "flag", &b, false);
ZUC_ASSERT_EQ(0, r);
ZUC_ASSERT_EQ(1, b);
ZUC_ASSERT_EQ(true, b);
}
ZUC_TEST_F(config_test_t1, test012, data)
{
int r, b;
int r;
bool b;
struct weston_config_section *section;
struct weston_config *config = data;
section = weston_config_get_section(config, "stuff", NULL, NULL);
r = weston_config_section_get_bool(section, "flag", &b, -1);
r = weston_config_section_get_bool(section, "flag", &b, false);
ZUC_ASSERT_EQ(0, r);
ZUC_ASSERT_EQ(1, b);
ZUC_ASSERT_EQ(true, b);
}
ZUC_TEST_F(config_test_t1, test013, data)
{
int r, b;
int r;
bool b;
struct weston_config_section *section;
struct weston_config *config = data;
section = weston_config_get_section(config, "stuff", NULL, NULL);
r = weston_config_section_get_bool(section, "bonk", &b, -1);
r = weston_config_section_get_bool(section, "bonk", &b, false);
ZUC_ASSERT_EQ(-1, r);
ZUC_ASSERT_EQ(ENOENT, errno);
ZUC_ASSERT_EQ(-1, b);
ZUC_ASSERT_EQ(false, b);
}
ZUC_TEST_F(config_test_t1, test014, data)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment