X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Finput%2Fcsv.c;h=4dcc77b8eaeb19e13999324e230786d8da19ef9f;hb=4b8348941dd44e24f59584834e630f27fe3614cb;hp=3a42fc9b1e6cfd1d479bb7f9de72643f862e759f;hpb=31b4a9a2364b25e2c8808e1714c4cf629b7410b5;p=libsigrok.git diff --git a/src/input/csv.c b/src/input/csv.c index 3a42fc9b..4dcc77b8 100644 --- a/src/input/csv.c +++ b/src/input/csv.c @@ -136,9 +136,6 @@ /* * TODO * - * - Unbreak analog data when submitted in the 'double' data type. This - * was observed with sigrok-cli screen output. Is analog.encoding->unitsize - * not handled appropriately? Is it a sigrok-cli or libsigrok issue? * - Add a test suite for input modules in general, and CSV in specific? * Becomes more important with the multitude of options and their * interaction. Could cover edge cases (BOM presence, line termination @@ -146,7 +143,7 @@ * samplerates, etc). */ -typedef float csv_analog_t; /* 'double' currently is flawed. */ +typedef double csv_analog_t; /* Single column formats. */ enum single_col_format { @@ -277,21 +274,13 @@ struct context { static int flush_samplerate(const struct sr_input *in) { struct context *inc; - struct sr_datafeed_packet packet; - struct sr_datafeed_meta meta; - struct sr_config *src; inc = in->priv; if (!inc->calc_samplerate && inc->samplerate) inc->calc_samplerate = inc->samplerate; if (inc->calc_samplerate && !inc->samplerate_sent) { - packet.type = SR_DF_META; - packet.payload = &meta; - src = sr_config_new(SR_CONF_SAMPLERATE, g_variant_new_uint64(inc->calc_samplerate)); - meta.config = g_slist_append(NULL, src); - sr_session_send(in->sdi, &packet); - g_slist_free(meta.config); - sr_config_free(src); + (void)sr_session_send_meta(in->sdi, SR_CONF_SAMPLERATE, + g_variant_new_uint64(inc->calc_samplerate)); inc->samplerate_sent = TRUE; } @@ -668,10 +657,12 @@ static int make_column_details_from_format(const struct sr_input *in, * line won't get processed another time. */ column = column_texts[detail->col_nr - 1]; - if (inc->use_header && column && *column) + if (inc->use_header && column && *column) { + column = g_strstrip(column); caption = sr_scpi_unquote_string(column); - else + } else { caption = NULL; + } if (!caption || !*caption) caption = NULL; /* @@ -767,7 +758,20 @@ static void strip_comment(char *buf, const GString *prefix) */ static char **split_line(char *buf, struct context *inc) { - return g_strsplit(buf, inc->delimiter->str, 0); + char **fields, *f; + size_t l; + + fields = g_strsplit(buf, inc->delimiter->str, 0); + if (!fields) + return NULL; + + l = g_strv_length(fields); + while (l--) { + f = fields[l]; + g_strchomp(f); + } + + return fields; } /**