]> sigrok.org Git - libsigrok.git/blobdiff - src/output/gnuplot.c
output/csv: Support SR_DF_ANALOG2.
[libsigrok.git] / src / output / gnuplot.c
index a9feec67ba056f2f55daeed75990fca6eb1619e9..9a2a78cdff7c5599f9c047976d6e237ffbdf3c58 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+#include <config.h>
 #include <stdlib.h>
 #include <string.h>
 #include <glib.h>
-#include "config.h" /* Needed for PACKAGE_STRING and others. */
-#include "libsigrok.h"
+#include <libsigrok/libsigrok.h>
 #include "libsigrok-internal.h"
 
 #define LOG_PREFIX "output/gnuplot"
@@ -43,19 +43,20 @@ static const char *gnuplot_header2 = "\
 # -----------------------------------------------------------------------------\n\
 # 0\t\tSample counter (for internal gnuplot purposes)\n";
 
-
-static int init(struct sr_output *o)
+static int init(struct sr_output *o, GHashTable *options)
 {
        struct context *ctx;
        struct sr_channel *ch;
        GSList *l;
        unsigned int i;
 
+       (void)options;
+
        if (!o || !o->sdi)
                return SR_ERR_ARG;
 
        ctx = g_malloc0(sizeof(struct context));
-       o->internal = ctx;
+       o->priv = ctx;
        ctx->num_enabled_channels = 0;
        for (l = o->sdi->channels; l; l = l->next) {
                ch = l->data;
@@ -84,7 +85,7 @@ static int init(struct sr_output *o)
        return SR_OK;
 }
 
-static GString *gen_header(struct sr_output *o)
+static GString *gen_header(const struct sr_output *o)
 {
        struct context *ctx;
        struct sr_channel *ch;
@@ -94,7 +95,7 @@ static GString *gen_header(struct sr_output *o)
        unsigned int num_channels, i;
        char *samplerate_s;
 
-       ctx = o->internal;
+       ctx = o->priv;
        if (ctx->samplerate == 0) {
                if (sr_config_get(o->sdi->driver, o->sdi, NULL, SR_CONF_SAMPLERATE,
                                &gvar) == SR_OK) {
@@ -106,8 +107,8 @@ static GString *gen_header(struct sr_output *o)
        t = time(NULL);
        header = g_string_sized_new(512);
        g_string_printf(header, "%s", gnuplot_header);
-       g_string_append_printf(header, "# Generated by %s on %s",
-                       PACKAGE_STRING, ctime(&t));
+       g_string_append_printf(header, "# Generated by %s %s on %s",
+                       PACKAGE_NAME, SR_PACKAGE_VERSION_STRING, ctime(&t));
 
        num_channels = g_slist_length(o->sdi->channels);
        g_string_append_printf(header, "# Acquisition with %d/%d channels",
@@ -130,7 +131,7 @@ static GString *gen_header(struct sr_output *o)
        return header;
 }
 
-static int receive(struct sr_output *o, const struct sr_datafeed_packet *packet,
+static int receive(const struct sr_output *o, const struct sr_datafeed_packet *packet,
                GString **out)
 {
        const struct sr_datafeed_meta *meta;
@@ -142,9 +143,9 @@ static int receive(struct sr_output *o, const struct sr_datafeed_packet *packet,
        unsigned int curbit, p, idx, i;
 
        *out = NULL;
-       if (!o || !o->internal)
+       if (!o || !o->priv)
                return SR_ERR_BUG;
-       ctx = o->internal;
+       ctx = o->priv;
 
        if (packet->type == SR_DF_META) {
                meta = packet->payload;
@@ -205,9 +206,9 @@ static int cleanup(struct sr_output *o)
 {
        struct context *ctx;
 
-       if (!o || !o->internal)
+       if (!o || !o->priv)
                return SR_ERR_BUG;
-       ctx = o->internal;
+       ctx = o->priv;
        g_free(ctx->channel_index);
        g_free(ctx->prevsample);
        g_free(ctx);
@@ -215,9 +216,13 @@ static int cleanup(struct sr_output *o)
        return SR_OK;
 }
 
-SR_PRIV struct sr_output_format output_gnuplot = {
+SR_PRIV struct sr_output_module output_gnuplot = {
        .id = "gnuplot",
-       .description = "Gnuplot",
+       .name = "Gnuplot",
+       .desc = "Gnuplot data file format",
+       .exts = (const char*[]){"dat", NULL},
+       .flags = 0,
+       .options = NULL,
        .init = init,
        .receive = receive,
        .cleanup = cleanup,