From 2babadbf62ada6f32330371b946338baa0d79037 Mon Sep 17 00:00:00 2001 From: liquidaty Date: Mon, 28 Oct 2024 16:29:54 -0700 Subject: [PATCH] add option to cancel overwrites --- include/zsv/common.h | 1 + src/zsv_internal.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/zsv/common.h b/include/zsv/common.h index 6d3e6825..651fafa6 100644 --- a/include/zsv/common.h +++ b/include/zsv/common.h @@ -107,6 +107,7 @@ struct zsv_opt_overwrite { enum zsv_status (*open)(void *ctx); enum zsv_status (*next)(void *ctx, struct zsv_overwrite_data *odata); enum zsv_status (*close)(void *ctx); + char cancel; // explicitly cancel application of overwrites }; #endif diff --git a/src/zsv_internal.c b/src/zsv_internal.c index 9eef51d2..e36bd215 100644 --- a/src/zsv_internal.c +++ b/src/zsv_internal.c @@ -703,7 +703,7 @@ static int zsv_scanner_init(struct zsv_scanner *scanner, struct zsv_opts *opts) (scanner->row.cells = calloc(scanner->row.allocated, sizeof(*scanner->row.cells)))) { #ifdef ZSV_EXTRAS // initialize overwrites - if (scanner->opts.overwrite.open) { + if (scanner->opts.overwrite.open && !scanner->opts.overwrite.cancel) { if (scanner->opts.overwrite.open(scanner->opts.overwrite.ctx) == zsv_status_ok) { scanner->overwrite.odata.have = 1; scanner->overwrite.next = scanner->opts.overwrite.next;