]> sigrok.org Git - libsigrok.git/blobdiff - output/output_gnuplot.c
output: if device has no plugin, don't report samplerate
[libsigrok.git] / output / output_gnuplot.c
index 4c887cbcdba61e7aeb5378a80c08b6817c92c4a2..2bc19b399b631ee42f6d4bcf92d75c8f0bfbad49 100644 (file)
@@ -34,11 +34,14 @@ struct context {
 const char *gnuplot_header = "\
 # Sample data in space-separated columns format usable by gnuplot\n\
 #\n\
-# Generated by: %s on %s\n\
-# Comment: Acquisition with %d/%d probes at %s\n\
+# Generated by: %s on %s\n%s\
 # Timescale: %d %s\n\
 # Column assignment:\n%s\n";
 
+const char *gnuplot_header_comment = "\
+# Comment: Acquisition with %d/%d probes at %s\n";
+
+
 static int init(struct output *o)
 {
 /* Maximum header length */
@@ -51,7 +54,7 @@ static int init(struct output *o)
        unsigned int i;
        int b, num_probes;
        char *c, *samplerate_s;
-       char wbuf[1000];
+       char wbuf[1000], comment[128];
 
        ctx = malloc(sizeof(struct context));
        if (ctx == NULL)
@@ -74,11 +77,17 @@ static int init(struct output *o)
                return SIGROK_ERR_MALLOC;
        num_probes = g_slist_length(o->device->probes);
        /* TODO: Handle num_probes == 0, too many probes, etc. */
-       samplerate = *((uint64_t *) o->device->plugin->get_device_info(
-                       o->device->plugin_index, DI_CUR_SAMPLERATE));
-
-       if ((samplerate_s = sigrok_samplerate_string(samplerate)) == NULL)
-               return -1; /* FIXME */
+       if (o->device->plugin) {
+               samplerate = *((uint64_t *) o->device->plugin->get_device_info(
+                               o->device->plugin_index, DI_CUR_SAMPLERATE));
+               if ((samplerate_s = sigrok_samplerate_string(samplerate)) == NULL)
+                       return SIGROK_ERR;
+               snprintf(comment, 127, gnuplot_header_comment, ctx->num_enabled_probes,
+                            num_probes, samplerate_s);
+               free(samplerate_s);
+       }
+       else
+               comment[0] = '\0';
 
        /* Columns / channels */
        wbuf[0] = '\0';
@@ -90,10 +99,7 @@ static int init(struct output *o)
        /* TODO: date: File or signals? Make y/n configurable. */
        /* TODO: Timescale */
        b = snprintf(ctx->header, MAX_HEADER_LEN, gnuplot_header,
-                    PACKAGE_STRING, "TODO", ctx->num_enabled_probes,
-                    num_probes, samplerate_s, 1, "ns", (char *)&wbuf);
-
-       free(samplerate_s);
+                    PACKAGE_STRING, "TODO", comment, 1, "ns", (char *)&wbuf);
 
        /* TODO: Handle snprintf errors. */