Skip to content

Commit

Permalink
sheet: Override header span and skip rows when using properties file
Browse files Browse the repository at this point in the history
The properties file was overriding opts.rows_to_ignore and
opts.header_span values that need to be set to zero when using an
index. This recreates the parser with zsv_new after the opts have
been rewritten when an index is active.
  • Loading branch information
richiejp committed Nov 7, 2024
1 parent e8876d6 commit 1a8e4d3
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions app/sheet/read-data.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ static int read_data(struct zsvsheet_ui_buffer **uibufferp, // a new zsvsheet_

opts.stream = fp; // Input file stream

zsv_parser parser = {0};
if (zsv_new_with_properties(&opts, custom_prop_handler, filename, opts_used, &parser) != zsv_status_ok) {
fclose(fp);
zsv_delete(parser);
return errno ? errno : -1;
}

if (uibuff) {
pthread_mutex_lock(&uibuff->mutex);
if (uibuff->index_ready && row_filter) {
Expand All @@ -88,6 +95,9 @@ static int read_data(struct zsvsheet_ui_buffer **uibufferp, // a new zsvsheet_
opts.rows_to_ignore = 0;
zst = zsv_index_seek_row(uibuff->index, &opts, start_row);

zsv_delete(parser);
parser = zsv_new(&opts);

remaining_header_to_skip = 0;
remaining_rows_to_skip = 0;
original_row_num = header_span + start_row;
Expand All @@ -99,13 +109,6 @@ static int read_data(struct zsvsheet_ui_buffer **uibufferp, // a new zsvsheet_

size_t rows_read = header_span;

zsv_parser parser = {0};
if (zsv_new_with_properties(&opts, custom_prop_handler, filename, opts_used, &parser) != zsv_status_ok) {
fclose(fp);
zsv_delete(parser);
return errno ? errno : -1;
}

size_t find_len = zsvsheet_opts->find ? strlen(zsvsheet_opts->find) : 0;
size_t rows_searched = 0;
zsvsheet_buffer_t buffer = uibuff ? uibuff->buffer : NULL;
Expand Down

0 comments on commit 1a8e4d3

Please sign in to comment.