]> sigrok.org Git - libsigrok.git/blobdiff - src/input/csv.c
fx2lafw: Replace obsoleted strncmp() calls.
[libsigrok.git] / src / input / csv.c
index cc721baf2427a3e89c3c50d12bf196569dfafe59..e89f99aa6852ed02be46c3bbea4f835292375ebc 100644 (file)
@@ -393,7 +393,7 @@ static int init(struct sr_input *in, GHashTable *options)
        struct context *inc;
        const char *s;
 
-       in->sdi = sr_dev_inst_new(SR_ST_ACTIVE, NULL, NULL, NULL);
+       in->sdi = g_malloc0(sizeof(struct sr_dev_inst));
        in->priv = inc = g_malloc0(sizeof(struct context));
 
        inc->single_column = g_variant_get_int32(g_hash_table_lookup(options, "single-column"));
@@ -557,7 +557,7 @@ static int initial_parse(const struct sr_input *in, GString *buf)
                if (inc->header && inc->multi_column_mode && strlen(columns[i]))
                        g_string_assign(channel_name, columns[i]);
                else
-                       g_string_printf(channel_name, "%lu", i);
+                       g_string_printf(channel_name, "%zu", i);
                ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, channel_name->str);
                in->sdi->channels = g_slist_append(in->sdi->channels, ch);
        }
@@ -651,6 +651,7 @@ static int process_buffer(struct sr_input *in)
        else
                max_columns = 1;
 
+       ret = SR_OK;
        lines = g_strsplit_set(in->buf->str, "\r\n", 0);
        for (l = 0; lines[l]; l++) {
                inc->line_number++;
@@ -666,6 +667,13 @@ static int process_buffer(struct sr_input *in)
                        continue;
                }
 
+               /* Skip the header line, its content was used as the channel names. */
+               if (inc->header) {
+                       sr_spew("Header line %zu skipped.", inc->line_number);
+                       inc->header = FALSE;
+                       continue;
+               }
+
                if (!(columns = parse_line(lines[l], inc, max_columns))) {
                        sr_err("Error while parsing line %zu.", inc->line_number);
                        return SR_ERR;
@@ -811,6 +819,7 @@ SR_PRIV struct sr_input_module input_csv = {
        .id = "csv",
        .name = "CSV",
        .desc = "Comma-separated values",
+       .exts = (const char*[]){"csv", NULL},
        .metadata = { SR_INPUT_META_MIMETYPE },
        .options = get_options,
        .format_match = format_match,