From: Gerhard Sittig Date: Tue, 15 Oct 2019 19:43:55 +0000 (+0200) Subject: input/csv: fixup input file line number handling X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=ef0b9935cf1b133910d9b02e1ee3b798804716c6;p=libsigrok.git input/csv: fixup input file line number handling The previous implementation allowed CSV input files to use any line termination in either CR only, LF only, or CR/LF format. The first EOL was searched for and was recorded, but then was not used. Instead any of CR or LF were considered a line termination. "Raw data processing" still was correct, but line numbers in diagnostics were way off, and optional features like skipping first N lines were not effective. Fix that. Source code inspection suggests the "startline" feature did not work at all. The user provided number was used in the initial optional search for the header line (to get signal names) or auto-determination of the number of columns. But then was not used when the file actually got processed. --- diff --git a/src/input/csv.c b/src/input/csv.c index 4fc35adb..88c49c43 100644 --- a/src/input/csv.c +++ b/src/input/csv.c @@ -685,7 +685,10 @@ static int initial_parse(const struct sr_input *in, GString *buf) columns = NULL; line_number = 0; - lines = g_strsplit_set(buf->str, delim_set, 0); + if (inc->termination) + lines = g_strsplit(buf->str, inc->termination, 0); + else + lines = g_strsplit_set(buf->str, delim_set, 0); for (line_idx = 0; (line = lines[line_idx]); line_idx++) { line_number++; if (inc->start_line > line_number) { @@ -914,9 +917,13 @@ static int process_buffer(struct sr_input *in, gboolean is_eof) g_strstrip(in->buf->str); ret = SR_OK; - lines = g_strsplit_set(in->buf->str, delim_set, 0); + lines = g_strsplit(in->buf->str, inc->termination, 0); for (line_idx = 0; (line = lines[line_idx]); line_idx++) { inc->line_number++; + if (inc->line_number < inc->start_line) { + sr_spew("Line %zu skipped (before start).", inc->line_number); + continue; + } if (line[0] == '\0') { sr_spew("Blank line %zu skipped.", inc->line_number); continue;