mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-22 12:25:38 +02:00
module/script: parse booleans correctly
User is expected to send ‘false’ or ‘true’. But we were parsing the value using `strtol()`. This caused all bools to be false, since `strtol()` would always return 0.
This commit is contained in:
parent
1e5a1d0341
commit
f0a34d0055
1 changed files with 11 additions and 1 deletions
|
@ -67,6 +67,16 @@ content(struct module *mod)
|
|||
return e;
|
||||
}
|
||||
|
||||
|
||||
static bool
|
||||
str_to_bool(const char *s)
|
||||
{
|
||||
return strcasecmp(s, "on") == 0 ||
|
||||
strcasecmp(s, "true") == 0 ||
|
||||
strcasecmp(s, "yes") == 0 ||
|
||||
strtoul(s, NULL, 0) > 0;
|
||||
}
|
||||
|
||||
static struct tag *
|
||||
process_line(struct module *mod, const char *line, size_t len)
|
||||
{
|
||||
|
@ -112,7 +122,7 @@ process_line(struct module *mod, const char *line, size_t len)
|
|||
tag = tag_new_int(mod, name, strtol(value, NULL, 0));
|
||||
|
||||
else if (type_len == 4 && memcmp(type, "bool", 4) == 0)
|
||||
tag = tag_new_bool(mod, name, strtol(value, NULL, 0));
|
||||
tag = tag_new_bool(mod, name, str_to_bool(value));
|
||||
|
||||
else if (type_len == 5 && memcmp(type, "float", 5) == 0)
|
||||
tag = tag_new_float(mod, name, strtod(value, NULL));
|
||||
|
|
Loading…
Add table
Reference in a new issue