input/csv: improve robustness of "use header for channel names"
Don't clobber the value of the user provided 'header' option. Use a separate flag to track whether the header line was seen before, or needs to get skipped when it passes by.
This commit is contained in:
parent
246aca5f54
commit
de8fe3b515
|
@ -156,7 +156,8 @@ struct context {
|
||||||
* Determines if the first line should be treated as header and used for
|
* Determines if the first line should be treated as header and used for
|
||||||
* channel names in multi column mode.
|
* channel names in multi column mode.
|
||||||
*/
|
*/
|
||||||
gboolean header;
|
gboolean use_header;
|
||||||
|
gboolean header_seen;
|
||||||
|
|
||||||
/* Format sample data is stored in single column mode. */
|
/* Format sample data is stored in single column mode. */
|
||||||
enum single_col_format format;
|
enum single_col_format format;
|
||||||
|
@ -574,7 +575,7 @@ static int init(struct sr_input *in, GHashTable *options)
|
||||||
|
|
||||||
inc->first_channel = g_variant_get_uint32(g_hash_table_lookup(options, "first-channel"));
|
inc->first_channel = g_variant_get_uint32(g_hash_table_lookup(options, "first-channel"));
|
||||||
|
|
||||||
inc->header = g_variant_get_boolean(g_hash_table_lookup(options, "header"));
|
inc->use_header = g_variant_get_boolean(g_hash_table_lookup(options, "header"));
|
||||||
|
|
||||||
inc->start_line = g_variant_get_uint32(g_hash_table_lookup(options, "startline"));
|
inc->start_line = g_variant_get_uint32(g_hash_table_lookup(options, "startline"));
|
||||||
if (inc->start_line < 1) {
|
if (inc->start_line < 1) {
|
||||||
|
@ -737,7 +738,7 @@ static int initial_parse(const struct sr_input *in, GString *buf)
|
||||||
channel_name = g_string_sized_new(64);
|
channel_name = g_string_sized_new(64);
|
||||||
for (i = 0; i < inc->num_channels; i++) {
|
for (i = 0; i < inc->num_channels; i++) {
|
||||||
column = columns[i];
|
column = columns[i];
|
||||||
if (inc->header && inc->multi_column_mode && column[0] != '\0')
|
if (inc->use_header && inc->multi_column_mode && column[0] != '\0')
|
||||||
g_string_assign(channel_name, column);
|
g_string_assign(channel_name, column);
|
||||||
else
|
else
|
||||||
g_string_printf(channel_name, "%zu", i);
|
g_string_printf(channel_name, "%zu", i);
|
||||||
|
@ -892,9 +893,9 @@ static int process_buffer(struct sr_input *in, gboolean is_eof)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Skip the header line, its content was used as the channel names. */
|
/* Skip the header line, its content was used as the channel names. */
|
||||||
if (inc->header) {
|
if (inc->use_header && !inc->header_seen) {
|
||||||
sr_spew("Header line %zu skipped.", inc->line_number);
|
sr_spew("Header line %zu skipped.", inc->line_number);
|
||||||
inc->header = FALSE;
|
inc->header_seen = TRUE;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue