]> sigrok.org Git - libsigrok.git/blobdiff - src/input/csv.c
output/csv: use intermediate time_t var, silence compiler warning
[libsigrok.git] / src / input / csv.c
index a0beebd6d75715c72275b48a15dd4a468efe9c2b..66ac41dc5c8a7e4bfebfa74e04031691a0386d39 100644 (file)
 /*
  * 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
  *   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;
        }
 
@@ -390,8 +379,6 @@ static void set_analog_value(struct context *inc, size_t ch_idx, csv_analog_t va
 {
        if (ch_idx >= inc->analog_channels)
                return;
-       if (!value)
-               return;
        inc->analog_sample_buffer[ch_idx * inc->analog_datafeed_buf_size] = value;
 }
 
@@ -668,10 +655,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 +756,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;
 }
 
 /**
@@ -1450,7 +1452,7 @@ static int initial_parse(const struct sr_input *in, GString *buf)
                inc->analog_datafeed_buf_size /= sample_size;
                inc->analog_datafeed_buf_size /= inc->analog_channels;
                sample_count = inc->analog_channels * inc->analog_datafeed_buf_size;
-               inc->analog_datafeed_buffer = g_malloc0(sample_count * sample_size);
+               inc->analog_datafeed_buffer = g_malloc(sample_count * sample_size);
                if (!inc->analog_datafeed_buffer) {
                        sr_err("Cannot allocate datafeed send buffer (analog).");
                        ret = SR_ERR_MALLOC;
@@ -1795,7 +1797,7 @@ static struct sr_option options[] = {
        },
        [OPT_HEADER] = {
                "header", "Get channel names from first line.",
-               "Use the first processed line's column captions (when available) as channel names. Off by default",
+               "Use the first processed line's column captions (when available) as channel names. Enabled by default.",
                NULL, NULL,
        },
        [OPT_SAMPLERATE] = {
@@ -1832,7 +1834,7 @@ static const struct sr_option *get_options(void)
                l = g_slist_append(l, g_variant_ref_sink(g_variant_new_string("oct")));
                options[OPT_SINGLE_FMT].values = l;
                options[OPT_START_LINE].def = g_variant_ref_sink(g_variant_new_uint32(1));
-               options[OPT_HEADER].def = g_variant_ref_sink(g_variant_new_boolean(FALSE));
+               options[OPT_HEADER].def = g_variant_ref_sink(g_variant_new_boolean(TRUE));
                options[OPT_SAMPLERATE].def = g_variant_ref_sink(g_variant_new_uint64(0));
                options[OPT_COL_SEP].def = g_variant_ref_sink(g_variant_new_string(","));
                options[OPT_COMMENT].def = g_variant_ref_sink(g_variant_new_string(";"));