From: Uwe Hermann Date: Sun, 9 May 2010 12:42:46 +0000 (+0200) Subject: VCD/Gnuplot: Cosmetics, code simplifications. X-Git-Tag: libsigrok-0.1.0~515 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=607b58de58f22baa026d24ac7b8e0ae123c9ede0;p=libsigrok.git VCD/Gnuplot: Cosmetics, code simplifications. --- diff --git a/output/output_gnuplot.c b/output/output_gnuplot.c index 2490d660..45b7a870 100644 --- a/output/output_gnuplot.c +++ b/output/output_gnuplot.c @@ -140,7 +140,7 @@ static int data(struct output *o, char *data_in, uint64_t length_in, char **data_out, uint64_t *length_out) { struct context *ctx; - unsigned int offset, outsize, p, curbit; + unsigned int i, outsize, p, curbit; uint64_t sample, count = 0; char *outbuf, *c; @@ -163,9 +163,8 @@ static int data(struct output *o, char *data_in, uint64_t length_in, /* TODO: Are disabled probes handled correctly? */ - for (offset = 0; offset <= length_in - ctx->unitsize; - offset += ctx->unitsize) { - memcpy(&sample, data_in + offset, ctx->unitsize); + for (i = 0; i <= length_in - ctx->unitsize; i += ctx->unitsize) { + memcpy(&sample, data_in + i, ctx->unitsize); /* The first column is a counter (needed for gnuplot). */ c = outbuf + strlen(outbuf); diff --git a/output/output_vcd.c b/output/output_vcd.c index e4ac7bab..fd569e0e 100644 --- a/output/output_vcd.c +++ b/output/output_vcd.c @@ -153,7 +153,7 @@ static int data(struct output *o, char *data_in, uint64_t length_in, char **data_out, uint64_t *length_out) { struct context *ctx; - unsigned int offset, outsize; + unsigned int i, outsize; int p, curbit, prevbit; uint64_t sample, prevsample; char *outbuf, *c; @@ -177,28 +177,27 @@ static int data(struct output *o, char *data_in, uint64_t length_in, /* TODO: Are disabled probes handled correctly? */ - for (offset = 0; offset <= length_in - ctx->unitsize; - offset += ctx->unitsize) { - memcpy(&sample, data_in + offset, ctx->unitsize); + for (i = 0; i <= length_in - ctx->unitsize; i += ctx->unitsize) { + memcpy(&sample, data_in + i, ctx->unitsize); for (p = 0; p < ctx->num_enabled_probes; p++) { curbit = (sample & ((uint64_t) (1 << p))) != 0; - if (offset == 0) { + if (i == 0) { prevbit = ~curbit; } else { - memcpy(&prevsample, data_in + offset - 1, + memcpy(&prevsample, data_in + i - 1, ctx->unitsize); prevbit = (prevsample & ((uint64_t) (1 << p))) != 0; } - if (prevbit != curbit) { - /* FIXME: Only once per sample? */ - c = outbuf + strlen(outbuf); - sprintf(c, "#%i\n", offset * 1 /* TODO */); + /* VCD only contains deltas/changes. */ + if (prevbit == curbit) + continue; - c = outbuf + strlen(outbuf); - sprintf(c, "%i%c\n", curbit, (char)('!' + p)); - } + /* FIXME: Only once per sample? */ + /* TODO: Is 'i' correct here? */ + c = outbuf + strlen(outbuf); + sprintf(c, "#%i\n%i%c\n", i, curbit, (char)('!' + p)); } /* TODO: Use realloc() if strlen(outbuf) is almost "full"... */