X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Finput%2Fcsv.c;h=47fee73e7304aba095e998a7d65e50191428341f;hb=e8be616955f2bc4e2c72fc55d899056ad68fb75c;hp=180ff3df264c6aaac50f43c69d1f710748e78115;hpb=4ab01c3564ddec604d0b6a9daf76fcba277da287;p=libsigrok.git diff --git a/src/input/csv.c b/src/input/csv.c index 180ff3df..47fee73e 100644 --- a/src/input/csv.c +++ b/src/input/csv.c @@ -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")); @@ -472,7 +472,6 @@ static char *get_line_termination(GString *buf) static int initial_parse(const struct sr_input *in, GString *buf) { struct context *inc; - struct sr_channel *ch; GString *channel_name; gsize num_columns, l, i; unsigned int line_number; @@ -558,8 +557,7 @@ static int initial_parse(const struct sr_input *in, GString *buf) g_string_assign(channel_name, columns[i]); else 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); + sr_channel_new(in->sdi, i, SR_CHANNEL_LOGIC, TRUE, channel_name->str); } g_string_free(channel_name, TRUE); @@ -667,6 +665,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; @@ -812,6 +817,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,