]> sigrok.org Git - sigrok-cli.git/commitdiff
Parse boolean command line options.
authorJens Steinhauser <redacted>
Sun, 19 Oct 2014 08:47:31 +0000 (10:47 +0200)
committerBert Vermeulen <redacted>
Sun, 19 Oct 2014 09:51:25 +0000 (11:51 +0200)
This fixes bug 450.

parsers.c

index 526be7831ecd8afc587a1788cd7179a85ba1d237..8d654eec5f3804c1ce80958a006610e8ec7def0d 100644 (file)
--- 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);
                 }