]> sigrok.org Git - libsigrok.git/blobdiff - strutil.c
Other method to avoid "unused var" compiler warnings.
[libsigrok.git] / strutil.c
index e5278dfe3fda303156eb05b62bc95577f71b4158..380d78f59efdbb0bf72009c903484a85d9f87a06 100644 (file)
--- a/strutil.c
+++ b/strutil.c
@@ -22,6 +22,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sigrok.h>
+#include <sigrok-internal.h>
 
 /**
  * Convert a numeric samplerate value to its "natural" string representation.
@@ -114,7 +115,12 @@ char **sr_parse_triggerstring(struct sr_device *device,
 
        max_probes = g_slist_length(device->probes);
        error = FALSE;
-       triggerlist = g_malloc0(max_probes * sizeof(char *));
+
+       if (!(triggerlist = g_try_malloc0(max_probes * sizeof(char *)))) {
+               sr_err("session file: %s: metafile malloc failed", __func__);
+               return NULL;
+       }
+
        tokens = g_strsplit(triggerstring, ",", max_probes);
        trigger_types = device->plugin->get_device_info(0, SR_DI_TRIGGER_TYPES);
        if (trigger_types == NULL)
@@ -138,7 +144,7 @@ char **sr_parse_triggerstring(struct sr_device *device,
                }
 
                if (probenum < 1 || probenum > max_probes) {
-                       printf("Invalid probe.\n");
+                       sr_err("Invalid probe.\n");
                        error = TRUE;
                        break;
                }
@@ -146,7 +152,7 @@ char **sr_parse_triggerstring(struct sr_device *device,
                if ((trigger = strchr(tokens[i], '='))) {
                        for (tc = ++trigger; *tc; tc++) {
                                if (strchr(trigger_types, *tc) == NULL) {
-                                       printf("Unsupported trigger type "
+                                       sr_err("Unsupported trigger type "
                                               "'%c'\n", *tc);
                                        error = TRUE;
                                        break;
@@ -261,3 +267,18 @@ uint64_t sr_parse_timestring(const char *timestring)
 
        return time_msec;
 }
+
+gboolean sr_parse_boolstring(const char *boolstr)
+{
+       if (!boolstr)
+               return FALSE;
+
+       if (!g_strcasecmp(boolstr, "true") || 
+           !g_strcasecmp(boolstr, "yes") ||
+           !g_strcasecmp(boolstr, "on") ||
+           !g_strcasecmp(boolstr, "1")) 
+               return TRUE;
+
+       return FALSE;
+}
+