From: Jens Steinhauser Date: Sun, 19 Oct 2014 08:47:31 +0000 (+0200) Subject: Parse boolean command line options. X-Git-Tag: sigrok-cli-0.6.0~57 X-Git-Url: https://sigrok.org/gitweb/?p=sigrok-cli.git;a=commitdiff_plain;h=41ef1ae49a4973e136ffb99849ad98aa570f9f99 Parse boolean command line options. This fixes bug 450. --- diff --git a/parsers.c b/parsers.c index 526be78..8d654ee 100644 --- a/parsers.c +++ b/parsers.c @@ -294,6 +294,7 @@ GHashTable *generic_arg_to_opt(const struct sr_option **opts, GHashTable *genarg GVariant *gvar; int i; char *s; + gboolean b; hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)g_variant_unref); @@ -320,6 +321,17 @@ GHashTable *generic_arg_to_opt(const struct sr_option **opts, GHashTable *genarg gvar = g_variant_new_string(s); g_hash_table_insert(hash, g_strdup(opts[i]->id), g_variant_ref_sink(gvar)); + } else if (g_variant_is_of_type(opts[i]->def, G_VARIANT_TYPE_BOOLEAN)) { + b = TRUE; + if (0 == strcmp(s, "false") || 0 == strcmp(s, "no")) { + b = FALSE; + } else if (!(0 == strcmp(s, "true") || 0 == strcmp(s, "yes"))) { + g_critical("Unable to convert '%s' to boolean!", s); + } + + gvar = g_variant_new_boolean(b); + g_hash_table_insert(hash, g_strdup(opts[i]->id), + g_variant_ref_sink(gvar)); } else { g_critical("Don't know GVariant type for option '%s'!", opts[i]->id); }