]> sigrok.org Git - libsigrok.git/blobdiff - src/input/csv.c
Change sr_dev_inst_new() to take no parameters.
[libsigrok.git] / src / input / csv.c
index e72357bb6d7f7983c02fd486af9c60467c8e3273..b2756fa0aa124453dd266b2373896d2d06b37d21 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 = sr_dev_inst_new();
        in->priv = inc = g_malloc0(sizeof(struct context));
 
        inc->single_column = g_variant_get_int32(g_hash_table_lookup(options, "single-column"));
@@ -506,7 +506,7 @@ static int initial_parse(const struct sr_input *in, GString *buf)
        }
        if (!lines[l]) {
                /* Not enough data for a proper line yet. */
-               ret = SR_OK_CONTINUE;
+               ret = SR_ERR_NA;
                goto out;
        }
 
@@ -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;