From: Uwe Hermann Date: Wed, 28 Mar 2012 18:00:13 +0000 (+0200) Subject: sr: out: Use uint8_t (not char) for buffers. X-Git-Tag: libsigrok-0.1.0~15 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=054e67090641e0a56a7e55789a3882ca138a0b11;p=libsigrok.git sr: out: Use uint8_t (not char) for buffers. --- diff --git a/filter.c b/filter.c index 9c025710..2465cbbd 100644 --- a/filter.c +++ b/filter.c @@ -74,8 +74,8 @@ * out_unitsize, data_out, and length_out are undefined. */ SR_API int sr_filter_probes(int in_unitsize, int out_unitsize, - const int *probelist, const unsigned char *data_in, - uint64_t length_in, char **data_out, + const int *probelist, const uint8_t *data_in, + uint64_t length_in, uint8_t **data_out, uint64_t *length_out) { unsigned int in_offset, out_offset; diff --git a/output/analog.c b/output/analog.c index da42b39c..9029f099 100644 --- a/output/analog.c +++ b/output/analog.c @@ -42,7 +42,7 @@ struct context { int line_offset; int linebuf_len; char *probelist[SR_MAX_NUM_PROBES + 1]; - char *linebuf; + uint8_t *linebuf; int spl_cnt; uint8_t *linevalues; char *header; @@ -51,7 +51,7 @@ struct context { enum outputmode mode; }; -static void flush_linebufs(struct context *ctx, char *outbuf) +static void flush_linebufs(struct context *ctx, uint8_t *outbuf) { static int max_probename_len = 0; int len, i; @@ -168,12 +168,12 @@ static int init(struct sr_output *o, int default_spl, enum outputmode mode) return SR_OK; } -static int event(struct sr_output *o, int event_type, char **data_out, +static int event(struct sr_output *o, int event_type, uint8_t **data_out, uint64_t *length_out) { struct context *ctx; int outsize; - char *outbuf; + uint8_t *outbuf; ctx = o->internal; switch (event_type) { @@ -210,14 +210,15 @@ static int init_bits(struct sr_output *o) return init(o, DEFAULT_BPL_BITS, MODE_BITS); } -static int data_bits(struct sr_output *o, const char *data_in, - uint64_t length_in, char **data_out, uint64_t *length_out) +static int data_bits(struct sr_output *o, const uint8_t *data_in, + uint64_t length_in, uint8_t **data_out, + uint64_t *length_out) { struct context *ctx; unsigned int outsize, offset, p; int max_linelen; struct sr_analog_sample *sample; - char *outbuf, c; + uint8_t *outbuf, c; ctx = o->internal; max_linelen = SR_MAX_PROBENAME_LEN + 3 + ctx->samples_per_line @@ -299,14 +300,15 @@ static int init_hex(struct sr_output *o) return init(o, DEFAULT_BPL_HEX, MODE_HEX); } -static int data_hex(struct sr_output *o, const char *data_in, - uint64_t length_in, char **data_out, uint64_t *length_out) +static int data_hex(struct sr_output *o, const uint8_t *data_in, + uint64_t length_in, uint8_t **data_out, + uint64_t *length_out) { struct context *ctx; unsigned int outsize, offset, p; int max_linelen; uint64_t sample; - char *outbuf; + uint8_t *outbuf; ctx = o->internal; max_linelen = SR_MAX_PROBENAME_LEN + 3 + ctx->samples_per_line @@ -366,14 +368,15 @@ static int init_ascii(struct sr_output *o) return init(o, DEFAULT_BPL_ASCII, MODE_ASCII); } -static int data_ascii(struct sr_output *o, const char *data_in, - uint64_t length_in, char **data_out, uint64_t *length_out) +static int data_ascii(struct sr_output *o, const uint8_t *data_in, + uint64_t length_in, uint8_t **data_out, + uint64_t *length_out) { struct context *ctx; unsigned int outsize, offset, p; int max_linelen; uint64_t sample; - char *outbuf; + uint8_t *outbuf; ctx = o->internal; max_linelen = SR_MAX_PROBENAME_LEN + 3 + ctx->samples_per_line diff --git a/output/binary.c b/output/binary.c index bbf49c70..6141b4ff 100644 --- a/output/binary.c +++ b/output/binary.c @@ -24,10 +24,10 @@ #include "sigrok.h" #include "sigrok-internal.h" -static int data(struct sr_output *o, const char *data_in, uint64_t length_in, - char **data_out, uint64_t *length_out) +static int data(struct sr_output *o, const uint8_t *data_in, + uint64_t length_in, uint8_t **data_out, uint64_t *length_out) { - char *outbuf; + uint8_t *outbuf; /* Prevent compiler warnings. */ (void)o; diff --git a/output/chronovu_la8.c b/output/chronovu_la8.c index 944473f4..cca6a295 100644 --- a/output/chronovu_la8.c +++ b/output/chronovu_la8.c @@ -133,11 +133,11 @@ static int init(struct sr_output *o) return 0; /* TODO: SR_OK? */ } -static int event(struct sr_output *o, int event_type, char **data_out, +static int event(struct sr_output *o, int event_type, uint8_t **data_out, uint64_t *length_out) { struct context *ctx; - char *outbuf; + uint8_t *outbuf; if (!o) { sr_warn("la8 out: %s: o was NULL", __func__); @@ -196,11 +196,11 @@ static int event(struct sr_output *o, int event_type, char **data_out, return SR_OK; } -static int data(struct sr_output *o, const char *data_in, uint64_t length_in, - char **data_out, uint64_t *length_out) +static int data(struct sr_output *o, const uint8_t *data_in, + uint64_t length_in, uint8_t **data_out, uint64_t *length_out) { struct context *ctx; - char *outbuf; + uint8_t *outbuf; if (!o) { sr_warn("la8 out: %s: o was NULL", __func__); diff --git a/output/csv.c b/output/csv.c index cc22eb84..0f9f731a 100644 --- a/output/csv.c +++ b/output/csv.c @@ -122,7 +122,7 @@ static int init(struct sr_output *o) return 0; /* TODO: SR_OK? */ } -static int event(struct sr_output *o, int event_type, char **data_out, +static int event(struct sr_output *o, int event_type, uint8_t **data_out, uint64_t *length_out) { struct context *ctx; @@ -168,8 +168,8 @@ static int event(struct sr_output *o, int event_type, char **data_out, return SR_OK; } -static int data(struct sr_output *o, const char *data_in, uint64_t length_in, - char **data_out, uint64_t *length_out) +static int data(struct sr_output *o, const uint8_t *data_in, + uint64_t length_in, uint8_t **data_out, uint64_t *length_out) { struct context *ctx; GString *outstr; @@ -209,7 +209,7 @@ static int data(struct sr_output *o, const char *data_in, uint64_t length_in, g_string_append_printf(outstr, "\n"); } - *data_out = outstr->str; + *data_out = (uint8_t *)outstr->str; *length_out = outstr->len; g_string_free(outstr, FALSE); diff --git a/output/gnuplot.c b/output/gnuplot.c index 32369610..d57e6847 100644 --- a/output/gnuplot.c +++ b/output/gnuplot.c @@ -118,7 +118,7 @@ static int init(struct sr_output *o) /* Columns / channels */ wbuf[0] = '\0'; for (i = 0; i < ctx->num_enabled_probes; i++) { - c = (char *)&wbuf + strlen((char *)&wbuf); + c = (char *)&wbuf + strlen((const char *)&wbuf); sprintf(c, "# %d\t\t%s\n", i + 1, ctx->probelist[i]); } @@ -145,7 +145,7 @@ static int init(struct sr_output *o) return 0; } -static int event(struct sr_output *o, int event_type, char **data_out, +static int event(struct sr_output *o, int event_type, uint8_t **data_out, uint64_t *length_out) { if (!o) { @@ -183,14 +183,14 @@ static int event(struct sr_output *o, int event_type, char **data_out, return SR_OK; } -static int data(struct sr_output *o, const char *data_in, uint64_t length_in, - char **data_out, uint64_t *length_out) +static int data(struct sr_output *o, const uint8_t *data_in, + uint64_t length_in, uint8_t **data_out, uint64_t *length_out) { struct context *ctx; unsigned int max_linelen, outsize, p, curbit, i; uint64_t sample; static uint64_t samplecount = 0, old_sample = 0; - char *outbuf, *c; + uint8_t *outbuf, *c; if (!o) { sr_err("gnuplot out: %s: o was NULL", __func__); @@ -231,7 +231,7 @@ static int data(struct sr_output *o, const char *data_in, uint64_t length_in, outbuf[0] = '\0'; if (ctx->header) { /* The header is still here, this must be the first packet. */ - strncpy(outbuf, ctx->header, outsize); + strncpy((char *)outbuf, ctx->header, outsize); g_free(ctx->header); ctx->header = NULL; } @@ -251,22 +251,22 @@ static int data(struct sr_output *o, const char *data_in, uint64_t length_in, old_sample = sample; /* The first column is a counter (needed for gnuplot). */ - c = outbuf + strlen(outbuf); - sprintf(c, "%" PRIu64 "\t", samplecount++); + c = outbuf + strlen((const char *)outbuf); + sprintf((char *)c, "%" PRIu64 "\t", samplecount++); /* The next columns are the values of all channels. */ for (p = 0; p < ctx->num_enabled_probes; p++) { curbit = (sample & ((uint64_t) (1 << p))) >> p; - c = outbuf + strlen(outbuf); - sprintf(c, "%d ", curbit); + c = outbuf + strlen((const char *)outbuf); + sprintf((char *)c, "%d ", curbit); } - c = outbuf + strlen(outbuf); - sprintf(c, "\n"); + c = outbuf + strlen((const char *)outbuf); + sprintf((char *)c, "\n"); } *data_out = outbuf; - *length_out = strlen(outbuf); + *length_out = strlen((const char *)outbuf); return SR_OK; } @@ -360,14 +360,15 @@ static int analog_init(struct sr_output *o) return 0; } -static int analog_data(struct sr_output *o, char *data_in, uint64_t length_in, - char **data_out, uint64_t *length_out) +static int analog_data(struct sr_output *o, uint8_t *data_in, + uint64_t length_in, uint8_t **data_out, + uint64_t *length_out) { struct context *ctx; unsigned int max_linelen, outsize, p, /* curbit, */ i; // uint64_t sample; static uint64_t samplecount = 0; - char *outbuf, *c; + uint8_t *outbuf, *c; struct sr_analog_sample *sample; ctx = o->internal; diff --git a/output/ols.c b/output/ols.c index e0196717..0a55daf0 100644 --- a/output/ols.c +++ b/output/ols.c @@ -76,7 +76,7 @@ static int init(struct sr_output *o) return SR_OK; } -static int event(struct sr_output *o, int event_type, char **data_out, +static int event(struct sr_output *o, int event_type, uint8_t **data_out, uint64_t *length_out) { struct context *ctx; @@ -95,8 +95,8 @@ static int event(struct sr_output *o, int event_type, char **data_out, return SR_OK; } -static int data(struct sr_output *o, const char *data_in, uint64_t length_in, - char **data_out, uint64_t *length_out) +static int data(struct sr_output *o, const uint8_t *data_in, + uint64_t length_in, uint8_t **data_out, uint64_t *length_out) { GString *out; struct context *ctx; @@ -117,7 +117,7 @@ static int data(struct sr_output *o, const char *data_in, uint64_t length_in, g_string_append_printf(out, "%08x@%"PRIu64"\n", (uint32_t) sample, ctx->num_samples++); } - *data_out = out->str; + *data_out = (uint8_t *)out->str; *length_out = out->len; g_string_free(out, FALSE); diff --git a/output/text/ascii.c b/output/text/ascii.c index 3b4f87d8..dd4373f4 100644 --- a/output/text/ascii.c +++ b/output/text/ascii.c @@ -30,15 +30,15 @@ SR_PRIV int init_ascii(struct sr_output *o) return init(o, DEFAULT_BPL_ASCII, MODE_ASCII); } -SR_PRIV int data_ascii(struct sr_output *o, const char *data_in, - uint64_t length_in, char **data_out, +SR_PRIV int data_ascii(struct sr_output *o, const uint8_t *data_in, + uint64_t length_in, uint8_t **data_out, uint64_t *length_out) { struct context *ctx; unsigned int outsize, offset, p; int max_linelen; uint64_t sample; - char *outbuf; + uint8_t *outbuf; ctx = o->internal; max_linelen = SR_MAX_PROBENAME_LEN + 3 + ctx->samples_per_line @@ -58,7 +58,7 @@ SR_PRIV int data_ascii(struct sr_output *o, const char *data_in, outbuf[0] = '\0'; if (ctx->header) { /* The header is still here, this must be the first packet. */ - strncpy(outbuf, ctx->header, outsize); + strncpy((char *)outbuf, ctx->header, outsize); g_free(ctx->header); ctx->header = NULL; } @@ -113,7 +113,7 @@ SR_PRIV int data_ascii(struct sr_output *o, const char *data_in, } *data_out = outbuf; - *length_out = strlen(outbuf); + *length_out = strlen((const char *)outbuf); return SR_OK; } diff --git a/output/text/bits.c b/output/text/bits.c index 89359bb2..9692ac31 100644 --- a/output/text/bits.c +++ b/output/text/bits.c @@ -30,14 +30,15 @@ SR_PRIV int init_bits(struct sr_output *o) return init(o, DEFAULT_BPL_BITS, MODE_BITS); } -SR_PRIV int data_bits(struct sr_output *o, const char *data_in, - uint64_t length_in, char **data_out, uint64_t *length_out) +SR_PRIV int data_bits(struct sr_output *o, const uint8_t *data_in, + uint64_t length_in, uint8_t **data_out, + uint64_t *length_out) { struct context *ctx; unsigned int outsize, offset, p; int max_linelen; uint64_t sample; - char *outbuf, c; + uint8_t *outbuf, c; ctx = o->internal; max_linelen = SR_MAX_PROBENAME_LEN + 3 + ctx->samples_per_line @@ -57,7 +58,7 @@ SR_PRIV int data_bits(struct sr_output *o, const char *data_in, outbuf[0] = '\0'; if (ctx->header) { /* The header is still here, this must be the first packet. */ - strncpy(outbuf, ctx->header, outsize); + strncpy((char *)outbuf, ctx->header, outsize); g_free(ctx->header); ctx->header = NULL; @@ -99,7 +100,7 @@ SR_PRIV int data_bits(struct sr_output *o, const char *data_in, } *data_out = outbuf; - *length_out = strlen(outbuf); + *length_out = strlen((const char *)outbuf); return SR_OK; } diff --git a/output/text/hex.c b/output/text/hex.c index 0d2c0778..b0e20aa6 100644 --- a/output/text/hex.c +++ b/output/text/hex.c @@ -30,14 +30,15 @@ SR_PRIV int init_hex(struct sr_output *o) return init(o, DEFAULT_BPL_HEX, MODE_HEX); } -SR_PRIV int data_hex(struct sr_output *o, const char *data_in, - uint64_t length_in, char **data_out, uint64_t *length_out) +SR_PRIV int data_hex(struct sr_output *o, const uint8_t *data_in, + uint64_t length_in, uint8_t **data_out, + uint64_t *length_out) { struct context *ctx; unsigned int outsize, offset, p; int max_linelen; uint64_t sample; - char *outbuf; + uint8_t *outbuf; ctx = o->internal; max_linelen = SR_MAX_PROBENAME_LEN + 3 + ctx->samples_per_line @@ -53,7 +54,7 @@ SR_PRIV int data_hex(struct sr_output *o, const char *data_in, outbuf[0] = '\0'; if (ctx->header) { /* The header is still here, this must be the first packet. */ - strncpy(outbuf, ctx->header, outsize); + strncpy((char *)outbuf, ctx->header, outsize); g_free(ctx->header); ctx->header = NULL; } @@ -66,7 +67,7 @@ SR_PRIV int data_hex(struct sr_output *o, const char *data_in, ctx->linevalues[p] <<= 1; if (sample & ((uint64_t) 1 << p)) ctx->linevalues[p] |= 1; - sprintf(ctx->linebuf + (p * ctx->linebuf_len) + + sprintf((char *)ctx->linebuf + (p * ctx->linebuf_len) + ctx->line_offset, "%.2x", ctx->linevalues[p]); } ctx->spl_cnt++; @@ -87,7 +88,7 @@ SR_PRIV int data_hex(struct sr_output *o, const char *data_in, } *data_out = outbuf; - *length_out = strlen(outbuf); + *length_out = strlen((const char *)outbuf); return SR_OK; } diff --git a/output/text/text.c b/output/text/text.c index f08d7cbc..f0237a98 100644 --- a/output/text/text.c +++ b/output/text/text.c @@ -27,7 +27,7 @@ #include "sigrok-internal.h" #include "text.h" -SR_PRIV void flush_linebufs(struct context *ctx, char *outbuf) +SR_PRIV void flush_linebufs(struct context *ctx, uint8_t *outbuf) { static int max_probename_len = 0; int len, i; @@ -45,7 +45,8 @@ SR_PRIV void flush_linebufs(struct context *ctx, char *outbuf) } for (i = 0; ctx->probelist[i]; i++) { - sprintf(outbuf + strlen(outbuf), "%*s:%s\n", max_probename_len, + sprintf((char *)outbuf + strlen((const char *)outbuf), + "%*s:%s\n", max_probename_len, ctx->probelist[i], ctx->linebuf + i * ctx->linebuf_len); } @@ -57,8 +58,8 @@ SR_PRIV void flush_linebufs(struct context *ctx, char *outbuf) if (ctx->mode == MODE_ASCII) space_offset = 0; - sprintf(outbuf + strlen(outbuf), "T:%*s^\n", - ctx->mark_trigger + space_offset, ""); + sprintf((char *)outbuf + strlen((const char *)outbuf), + "T:%*s^\n", ctx->mark_trigger + space_offset, ""); } memset(ctx->linebuf, 0, i * ctx->linebuf_len); @@ -142,12 +143,12 @@ SR_PRIV int init(struct sr_output *o, int default_spl, enum outputmode mode) return SR_OK; } -SR_PRIV int event(struct sr_output *o, int event_type, char **data_out, +SR_PRIV int event(struct sr_output *o, int event_type, uint8_t **data_out, uint64_t *length_out) { struct context *ctx; int outsize; - char *outbuf; + uint8_t *outbuf; ctx = o->internal; switch (event_type) { @@ -165,7 +166,7 @@ SR_PRIV int event(struct sr_output *o, int event_type, char **data_out, } flush_linebufs(ctx, outbuf); *data_out = outbuf; - *length_out = strlen(outbuf); + *length_out = strlen((const char *)outbuf); g_free(o->internal); o->internal = NULL; break; diff --git a/output/text/text.h b/output/text/text.h index 8dcb45d2..3469e62e 100644 --- a/output/text/text.h +++ b/output/text/text.h @@ -37,7 +37,7 @@ struct context { int line_offset; int linebuf_len; char *probelist[SR_MAX_NUM_PROBES + 1]; - char *linebuf; + uint8_t *linebuf; int spl_cnt; uint8_t *linevalues; char *header; @@ -46,23 +46,24 @@ struct context { enum outputmode mode; }; -SR_PRIV void flush_linebufs(struct context *ctx, char *outbuf); +SR_PRIV void flush_linebufs(struct context *ctx, uint8_t *outbuf); SR_PRIV int init(struct sr_output *o, int default_spl, enum outputmode mode); -SR_PRIV int event(struct sr_output *o, int event_type, char **data_out, +SR_PRIV int event(struct sr_output *o, int event_type, uint8_t **data_out, uint64_t *length_out); SR_PRIV int init_bits(struct sr_output *o); -SR_PRIV int data_bits(struct sr_output *o, const char *data_in, - uint64_t length_in, char **data_out, +SR_PRIV int data_bits(struct sr_output *o, const uint8_t *data_in, + uint64_t length_in, uint8_t **data_out, uint64_t *length_out); SR_PRIV int init_hex(struct sr_output *o); -SR_PRIV int data_hex(struct sr_output *o, const char *data_in, - uint64_t length_in, char **data_out, uint64_t *length_out); +SR_PRIV int data_hex(struct sr_output *o, const uint8_t *data_in, + uint64_t length_in, uint8_t **data_out, + uint64_t *length_out); SR_PRIV int init_ascii(struct sr_output *o); -SR_PRIV int data_ascii(struct sr_output *o, const char *data_in, - uint64_t length_in, char **data_out, +SR_PRIV int data_ascii(struct sr_output *o, const uint8_t *data_in, + uint64_t length_in, uint8_t **data_out, uint64_t *length_out); #endif diff --git a/output/vcd.c b/output/vcd.c index 0840c589..9f42f152 100644 --- a/output/vcd.c +++ b/output/vcd.c @@ -135,16 +135,16 @@ static int init(struct sr_output *o) return SR_OK; } -static int event(struct sr_output *o, int event_type, char **data_out, +static int event(struct sr_output *o, int event_type, uint8_t **data_out, uint64_t *length_out) { - char *outbuf; + uint8_t *outbuf; switch (event_type) { case SR_DF_END: - outbuf = g_strdup("$dumpoff\n$end\n"); + outbuf = (uint8_t *)g_strdup("$dumpoff\n$end\n"); *data_out = outbuf; - *length_out = strlen(outbuf); + *length_out = strlen((const char *)outbuf); g_free(o->internal); o->internal = NULL; break; @@ -157,8 +157,8 @@ static int event(struct sr_output *o, int event_type, char **data_out, return SR_OK; } -static int data(struct sr_output *o, const char *data_in, uint64_t length_in, - char **data_out, uint64_t *length_out) +static int data(struct sr_output *o, const uint8_t *data_in, + uint64_t length_in, uint8_t **data_out, uint64_t *length_out) { struct context *ctx; unsigned int i; @@ -207,7 +207,7 @@ static int data(struct sr_output *o, const char *data_in, uint64_t length_in, ctx->prevsample = sample; } - *data_out = out->str; + *data_out = (uint8_t *)out->str; *length_out = out->len; g_string_free(out, FALSE); diff --git a/sigrok-proto.h b/sigrok-proto.h index 0913f898..2c45c01e 100644 --- a/sigrok-proto.h +++ b/sigrok-proto.h @@ -65,8 +65,8 @@ SR_API int sr_dev_info_get(const struct sr_dev *dev, int id, const void **data); /*--- filter.c --------------------------------------------------------------*/ SR_API int sr_filter_probes(int in_unitsize, int out_unitsize, - const int *probelist, const unsigned char *data_in, - uint64_t length_in, char **data_out, + const int *probelist, const uint8_t *data_in, + uint64_t length_in, uint8_t **data_out, uint64_t *length_out); /*--- hwdriver.c ------------------------------------------------------------*/ diff --git a/sigrok.h.in b/sigrok.h.in index 2a7d9762..adde2da3 100644 --- a/sigrok.h.in +++ b/sigrok.h.in @@ -186,9 +186,10 @@ struct sr_output_format { char *description; int df_type; int (*init) (struct sr_output *o); - int (*data) (struct sr_output *o, const char *data_in, - uint64_t length_in, char **data_out, uint64_t *length_out); - int (*event) (struct sr_output *o, int event_type, char **data_out, + int (*data) (struct sr_output *o, const uint8_t *data_in, + uint64_t length_in, uint8_t **data_out, + uint64_t *length_out); + int (*event) (struct sr_output *o, int event_type, uint8_t **data_out, uint64_t *length_out); };