diff --git a/app/sheet.c b/app/sheet.c index f8e1ee84..d2d74ff6 100644 --- a/app/sheet.c +++ b/app/sheet.c @@ -87,7 +87,6 @@ struct zsvsheet_builtin_proc_state { struct zsvsheet_display_info display_info; char *find; struct zsv_prop_handler *custom_prop_handler; - const char *opts_used; }; static void get_subcommand(const char *prompt, char *buff, size_t buffsize, int footer_row) { @@ -338,8 +337,8 @@ static zsvsheet_status zsvsheet_move_hor_end(struct zsvsheet_display_info *di, b // zsvsheet_handle_find_next: return non-zero if a result was found char zsvsheet_handle_find_next(struct zsvsheet_ui_buffer *uib, const char *needle, struct zsvsheet_opts *zsvsheet_opts, size_t header_span, struct zsvsheet_display_dimensions *ddims, int *update_buffer, - struct zsv_prop_handler *custom_prop_handler, const char *opts_used) { - if (zsvsheet_find_next(uib, needle, zsvsheet_opts, header_span, custom_prop_handler, opts_used) > 0) { + struct zsv_prop_handler *custom_prop_handler) { + if (zsvsheet_find_next(uib, needle, zsvsheet_opts, header_span, custom_prop_handler) > 0) { *update_buffer = zsvsheet_goto_input_raw_row(uib, zsvsheet_opts->found_rownum, header_span, ddims, (size_t)-1); return 1; } @@ -370,7 +369,7 @@ static zsvsheet_status zsvsheet_find(struct zsvsheet_builtin_proc_state *state, if (state->find) { zsvsheet_handle_find_next(current_ui_buffer, state->find, &zsvsheet_opts, di->header_span, di->dimensions, - &di->update_buffer, state->custom_prop_handler, state->opts_used); + &di->update_buffer, state->custom_prop_handler); } out: @@ -381,6 +380,7 @@ static zsvsheet_status zsvsheet_open_file_handler(struct zsvsheet_proc_context * // TODO: should be PATH_MAX but that's going to be about a page and compiler // might complain about stack being too large. Probably move to handler // state or something. + // TODO: allow additional zsv options char prompt_buffer[256] = {0}; struct zsvsheet_builtin_proc_state *state = (struct zsvsheet_builtin_proc_state *)ctx->subcommand_context; @@ -394,7 +394,8 @@ static zsvsheet_status zsvsheet_open_file_handler(struct zsvsheet_proc_context * if (*prompt_buffer == '\0') goto no_input; - if ((err = zsvsheet_ui_buffer_open_file(prompt_buffer, NULL, NULL, state->custom_prop_handler, state->opts_used, + const char *opts_used = NULL; + if ((err = zsvsheet_ui_buffer_open_file(prompt_buffer, NULL, NULL, state->custom_prop_handler, opts_used, di->ui_buffers.base, di->ui_buffers.current))) { if (err > 0) zsvsheet_priv_set_status(di->dimensions, 1, "%s: %s", prompt_buffer, strerror(err)); @@ -426,8 +427,7 @@ static zsvsheet_status zsvsheet_filter_handler(struct zsvsheet_proc_context *ctx const char *data_filename = zsvsheet_buffer_data_filename(current_ui_buffer); char is_filtered_file = !(data_filename == current_ui_buffer->filename); struct zsv_opts *zsv_opts = is_filtered_file ? NULL : ¤t_ui_buffer->zsv_opts; - const char *opts_used = is_filtered_file ? NULL : state->opts_used; - if ((err = zsvsheet_ui_buffer_open_file(data_filename, zsv_opts, prompt_buffer, state->custom_prop_handler, opts_used, + if ((err = zsvsheet_ui_buffer_open_file(data_filename, zsv_opts, prompt_buffer, state->custom_prop_handler, NULL, di->ui_buffers.base, di->ui_buffers.current))) { if (err > 0) zsvsheet_priv_set_status(di->dimensions, 1, "%s: %s", current_ui_buffer->filename, strerror(err)); @@ -439,13 +439,6 @@ static zsvsheet_status zsvsheet_filter_handler(struct zsvsheet_proc_context *ctx } struct zsvsheet_ui_buffer *new_ui_buffer = *state->display_info.ui_buffers.current; - /* - if (new_ui_buffer->dimensions.row_count < 2) { - zsvsheet_ui_buffer_pop(di->ui_buffers.base, di->ui_buffers.current, NULL); - zsvsheet_priv_set_status(di->dimensions, 1, "Not found: %s", prompt_buffer); - return zsvsheet_status_ignore; - } - */ if (is_filtered_file) { free(new_ui_buffer->filename); new_ui_buffer->filename = strdup(current_ui_buffer->filename); @@ -701,7 +694,6 @@ int ZSV_MAIN_FUNC(ZSV_COMMAND)(int argc, const char *argv[], struct zsv_opts *op .display_info.header_span = header_span, .find = NULL, .custom_prop_handler = custom_prop_handler, - .opts_used = opts_used, }; zsvsheet_status status; @@ -736,7 +728,7 @@ int ZSV_MAIN_FUNC(ZSV_COMMAND)(int argc, const char *argv[], struct zsv_opts *op if (handler_state.display_info.update_buffer && current_ui_buffer->filename) { struct zsvsheet_opts zsvsheet_opts = {0}; if (read_data(¤t_ui_buffer, NULL, current_ui_buffer->input_offset.row, current_ui_buffer->input_offset.col, - header_span, &zsvsheet_opts, custom_prop_handler, opts_used)) { + header_span, &zsvsheet_opts, custom_prop_handler)) { zsvsheet_priv_set_status(&display_dims, 1, "Unexpected error!"); // to do: better error message continue; } diff --git a/app/sheet/file.c b/app/sheet/file.c index 6f848ba8..ed527385 100644 --- a/app/sheet/file.c +++ b/app/sheet/file.c @@ -7,14 +7,13 @@ int zsvsheet_ui_buffer_open_file(const char *filename, const struct zsv_opts *zs uibopts.filename = filename; if (zsv_optsp) uibopts.zsv_opts = *zsv_optsp; + uibopts.opts_used = opts_used; uibopts.buff_opts = &bopts; struct zsvsheet_opts zsvsheet_opts = {0}; int err = 0; struct zsvsheet_ui_buffer *tmp_ui_buffer = NULL; uibopts.row_filter = row_filter; - if (!opts_used) - opts_used = ""; - if ((err = read_data(&tmp_ui_buffer, &uibopts, 0, 0, 0, &zsvsheet_opts, custom_prop_handler, opts_used)) != 0 || + if ((err = read_data(&tmp_ui_buffer, &uibopts, 0, 0, 0, &zsvsheet_opts, custom_prop_handler)) != 0 || !tmp_ui_buffer || !tmp_ui_buffer->buff_used_rows) { zsvsheet_ui_buffer_delete(tmp_ui_buffer); if (err) diff --git a/app/sheet/index.c b/app/sheet/index.c index bf86ca0d..feeb745d 100644 --- a/app/sheet/index.c +++ b/app/sheet/index.c @@ -90,7 +90,7 @@ enum zsv_index_status build_memory_index(struct zsvsheet_index_opts *optsp) { ix_zopts.row_handler = save_filtered_file_row_handler; enum zsv_status zst = - zsv_new_with_properties(&ix_zopts, optsp->custom_prop_handler, optsp->filename, optsp->opts_used, &ixr.parser); + zsv_new_with_properties(&ix_zopts, optsp->custom_prop_handler, optsp->filename, NULL, &ixr.parser); if (zst != zsv_status_ok) goto out; @@ -113,7 +113,7 @@ enum zsv_index_status build_memory_index(struct zsvsheet_index_opts *optsp) { ix_zopts.row_handler = build_memory_index_row_handler; enum zsv_status zst = - zsv_new_with_properties(&ix_zopts, optsp->custom_prop_handler, optsp->filename, optsp->opts_used, &ixr.parser); + zsv_new_with_properties(&ix_zopts, optsp->custom_prop_handler, optsp->filename, NULL, &ixr.parser); if (zst != zsv_status_ok) goto out; diff --git a/app/sheet/index.h b/app/sheet/index.h index d68ee766..12b1eca9 100644 --- a/app/sheet/index.h +++ b/app/sheet/index.h @@ -32,7 +32,6 @@ struct zsvsheet_index_opts { struct zsvsheet_ui_buffer *uib; int *errp; struct zsv_prop_handler *custom_prop_handler; - const char *opts_used; }; enum zsv_index_status build_memory_index(struct zsvsheet_index_opts *optsp); diff --git a/app/sheet/read-data.c b/app/sheet/read-data.c index b993ae44..a3b49b14 100644 --- a/app/sheet/read-data.c +++ b/app/sheet/read-data.c @@ -28,7 +28,8 @@ static void *get_data_index(void *d); static void get_data_index_async(struct zsvsheet_ui_buffer *uibuffp, const char *filename, struct zsv_opts *optsp, const char *row_filter, struct zsv_prop_handler *custom_prop_handler, - const char *opts_used, pthread_mutex_t *mutexp) { + // const char *opts_used, + pthread_mutex_t *mutexp) { struct zsvsheet_index_opts *ixopts = calloc(1, sizeof(*ixopts)); ixopts->mutexp = mutexp; ixopts->filename = filename; @@ -38,7 +39,7 @@ static void get_data_index_async(struct zsvsheet_ui_buffer *uibuffp, const char ixopts->index = &uibuffp->index; ixopts->index_ready = &uibuffp->index_ready; ixopts->custom_prop_handler = custom_prop_handler; - ixopts->opts_used = opts_used; + // ixopts->opts_used = opts_used; ixopts->uib = uibuffp; ixopts->uib->ixopts = ixopts; pthread_t thread; @@ -49,13 +50,16 @@ static void get_data_index_async(struct zsvsheet_ui_buffer *uibuffp, const char static int read_data(struct zsvsheet_ui_buffer **uibufferp, // a new zsvsheet_ui_buffer will be allocated struct zsvsheet_ui_buffer_opts *uibopts, // if *uibufferp == NULL and uibopts != NULL size_t start_row, size_t start_col, size_t header_span, struct zsvsheet_opts *zsvsheet_opts, - struct zsv_prop_handler *custom_prop_handler, const char *opts_used) { + struct zsv_prop_handler *custom_prop_handler) { const char *filename = (uibufferp && *uibufferp) ? (*uibufferp)->filename : uibopts ? uibopts->filename : NULL; struct zsv_opts opts = {0}; + const char *opts_used = ""; if (uibufferp && *uibufferp) opts = (*uibufferp)->zsv_opts; - else if (uibopts) + else if (uibopts) { opts = uibopts->zsv_opts; + opts_used = uibopts->opts_used; + } struct zsvsheet_ui_buffer *uibuff = uibufferp ? *uibufferp : NULL; size_t remaining_rows_to_skip = start_row; size_t remaining_header_to_skip = header_span; @@ -77,6 +81,7 @@ static int read_data(struct zsvsheet_ui_buffer **uibufferp, // a new zsvsheet_ zsv_delete(parser); return errno ? errno : -1; } + // opts_used is no longer needed since opts will be updated if (uibuff) { pthread_mutex_lock(&uibuff->mutex); @@ -216,7 +221,7 @@ static int read_data(struct zsvsheet_ui_buffer **uibufferp, // a new zsvsheet_ uibuff->index_started = 1; if (original_row_num > 1 && (row_filter == NULL || rows_read > 0)) { opts.stream = NULL; - get_data_index_async(uibuff, filename, &opts, row_filter, custom_prop_handler, opts_used, &uibuff->mutex); + get_data_index_async(uibuff, filename, &opts, row_filter, custom_prop_handler, /* opts_used, */ &uibuff->mutex); asprintf(&ui_status, "(building index) "); } } @@ -271,7 +276,7 @@ static void *get_data_index(void *gdi) { static size_t zsvsheet_find_next(struct zsvsheet_ui_buffer *uib, const char *needle, struct zsvsheet_opts *zsvsheet_opts, size_t header_span, - struct zsv_prop_handler *custom_prop_handler, const char *opts_used) { + struct zsv_prop_handler *custom_prop_handler) { struct zsvsheet_rowcol *input_offset = &uib->input_offset; struct zsvsheet_rowcol *buff_offset = &uib->buff_offset; size_t cursor_row = uib->cursor_row; @@ -279,7 +284,7 @@ static size_t zsvsheet_find_next(struct zsvsheet_ui_buffer *uib, const char *nee zsvsheet_opts->found_rownum = 0; // TO DO: check if it exists in current row, later column (and change 'cursor_row - 1' below to 'cursor_row') read_data(&uib, NULL, input_offset->row + buff_offset->row + header_span + cursor_row - 1, 0, header_span, - zsvsheet_opts, custom_prop_handler, opts_used); + zsvsheet_opts, custom_prop_handler); zsvsheet_opts->find = NULL; return zsvsheet_opts->found_rownum; } diff --git a/app/sheet/ui_buffer.c b/app/sheet/ui_buffer.c index cb9f7d9c..f8e2c2c1 100644 --- a/app/sheet/ui_buffer.c +++ b/app/sheet/ui_buffer.c @@ -67,6 +67,7 @@ struct zsvsheet_ui_buffer_opts { const char *row_filter; const char *filename; struct zsv_opts zsv_opts; // options to use when opening this file + const char *opts_used; char no_rownum_col_offset; }; diff --git a/app/utils/prop.c b/app/utils/prop.c index 1530300e..0361ba84 100644 --- a/app/utils/prop.c +++ b/app/utils/prop.c @@ -138,7 +138,8 @@ enum zsv_status zsv_properties_parser_destroy(struct zsv_properties_parser *pars * print a warning to stderr * * @param data_filepath required file path - * @param opts (optional) parser options to load + * @param opts (optional) parser options to load. will be updated to reflect + * what is actually used * @param custom_prop_handler (optional) handler for custom properties * @param cmd_opts_used (optional) cmd option codes to skip + warn if found * @return zsv_status_ok on success