More booleans (yes, no, on, off) and case-insensitive

This commit is contained in:
radare 2018-04-14 10:46:08 +02:00 committed by GitHub
parent d7df7212a4
commit a30a11e2ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 3 deletions

View File

@ -49,6 +49,19 @@ R_API void r_config_node_free(void *n) {
free (node);
}
static bool isBoolean(const char *val) {
if (!strcasecmp (val, "true") || !strcasecmp (val, "false")) {
return true;
}
if (!strcasecmp (val, "on") || !strcasecmp (val, "off")) {
return true;
}
if (!strcasecmp (val, "yes") || !strcasecmp (val, "no")) {
return true;
}
return false;
}
static void config_print_value_json(RConfig *cfg, RConfigNode *node) {
const char *val = node->value;
if (!val) {
@ -59,7 +72,7 @@ static void config_print_value_json(RConfig *cfg, RConfigNode *node) {
if (!strncmp (val, "0x", 2)) {
ut64 n = r_num_get (NULL, val);
cfg->cb_printf ("%"PFMT64d, n);
} else if (r_str_isnumber (val) || !strcmp (val, "true") || !strcmp (val, "false")) {
} else if (r_str_isnumber (val) || isBoolean (val)) {
cfg->cb_printf ("%s", val);
} else {
cfg->cb_printf ("\"%s\"", sval);
@ -296,7 +309,7 @@ R_API int r_config_set_setter(RConfig *cfg, const char *key, RConfigCallback cb)
}
static bool is_true(const char *s) {
return !strcasecmp ("true", s) || !strcasecmp ("1", s);
return !strcasecmp ("yes", s) || !strcasecmp ("on", s) || !strcasecmp ("true", s) || !strcasecmp ("1", s);
}
static bool is_bool(const char *s) {

View File

@ -218,9 +218,10 @@ static char *getstr(const char *src) {
static int parseBool(const char *e) {
return (strcmp (e, "yes")?
(strcmp (e, "on")?
(strcmp (e, "true")?
(strcmp (e, "1")?
0: 1): 1): 1);
0: 1): 1): 1): 1);
}
#if __linux__