X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=output%2Foutput_gnuplot.c;h=9d550a48ef4a14db76940aeb2f2443475943ce3e;hb=afc8e4deb68271ba7696e38cc02053b97cfc1a19;hp=25306d8d865149ac5972bb69e4699d384d7de3ad;hpb=e2ad47b5b0ad98fc99579d4cd9ebee7db2a03d82;p=libsigrok.git diff --git a/output/output_gnuplot.c b/output/output_gnuplot.c index 25306d8d..9d550a48 100644 --- a/output/output_gnuplot.c +++ b/output/output_gnuplot.c @@ -25,8 +25,8 @@ #include "config.h" struct context { - int num_enabled_probes; - int unitsize; + unsigned int num_enabled_probes; + unsigned int unitsize; char *probelist[65]; char *header; }; @@ -48,9 +48,10 @@ static int init(struct output *o) struct probe *probe; GSList *l; uint64_t samplerate; - int i, b, num_probes; - char *c; - char sbuf[10], wbuf[1000]; + unsigned int i; + int b, num_probes; + char *c, *samplerate_s; + char wbuf[1000]; ctx = malloc(sizeof(struct context)); if (ctx == NULL) @@ -75,16 +76,9 @@ static int init(struct output *o) /* 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)); - - /* Samplerate string */ - if (samplerate >= GHZ(1)) - snprintf(sbuf, 10, "%"PRIu64" GHz", samplerate / 1000000000); - else if (samplerate >= MHZ(1)) - snprintf(sbuf, 10, "%"PRIu64" MHz", samplerate / 1000000); - else if (samplerate >= KHZ(1)) - snprintf(sbuf, 10, "%"PRIu64" KHz", samplerate / 1000); - else - snprintf(sbuf, 10, "%"PRIu64" Hz", samplerate); + + if ((samplerate_s = sigrok_samplerate_string(samplerate)) == NULL) + return -1; // FIXME /* Columns / channels */ wbuf[0] = '\0'; @@ -97,7 +91,9 @@ static int init(struct output *o) /* TODO: Timescale */ b = snprintf(ctx->header, MAX_HEADER_LEN, gnuplot_header, PACKAGE_STRING, "TODO", ctx->num_enabled_probes, - num_probes, (char *)&sbuf, 1, "ns", (char *)&wbuf); + num_probes, samplerate_s, 1, "ns", (char *)&wbuf); + + free(samplerate_s); /* TODO: Handle snprintf errors. */ @@ -133,7 +129,7 @@ static int data(struct output *o, char *data_in, uint64_t length_in, char **data_out, uint64_t *length_out) { struct context *ctx; - int offset, outsize, p, curbit; + unsigned int offset, outsize, p, curbit; uint64_t sample, count = 0; char *outbuf, *c;