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.
This commit is contained in:
parent
836fac9cf6
commit
ef0b9935cf
|
@ -685,6 +685,9 @@ static int initial_parse(const struct sr_input *in, GString *buf)
|
||||||
columns = NULL;
|
columns = NULL;
|
||||||
|
|
||||||
line_number = 0;
|
line_number = 0;
|
||||||
|
if (inc->termination)
|
||||||
|
lines = g_strsplit(buf->str, inc->termination, 0);
|
||||||
|
else
|
||||||
lines = g_strsplit_set(buf->str, delim_set, 0);
|
lines = g_strsplit_set(buf->str, delim_set, 0);
|
||||||
for (line_idx = 0; (line = lines[line_idx]); line_idx++) {
|
for (line_idx = 0; (line = lines[line_idx]); line_idx++) {
|
||||||
line_number++;
|
line_number++;
|
||||||
|
@ -914,9 +917,13 @@ static int process_buffer(struct sr_input *in, gboolean is_eof)
|
||||||
g_strstrip(in->buf->str);
|
g_strstrip(in->buf->str);
|
||||||
|
|
||||||
ret = SR_OK;
|
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++) {
|
for (line_idx = 0; (line = lines[line_idx]); line_idx++) {
|
||||||
inc->line_number++;
|
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') {
|
if (line[0] == '\0') {
|
||||||
sr_spew("Blank line %zu skipped.", inc->line_number);
|
sr_spew("Blank line %zu skipped.", inc->line_number);
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in New Issue