diff --git a/app/Makefile b/app/Makefile index a4c3b312..e9630b76 100644 --- a/app/Makefile +++ b/app/Makefile @@ -161,7 +161,7 @@ CFLAGS+= -I${PREFIX}/include THIS_LIB_BASE=$(shell cd .. && pwd) INCLUDE_DIR=${THIS_LIB_BASE}/include BUILD_DIR=${THIS_LIB_BASE}/build/${BUILD_SUBDIR}/${CCBN} -UTILS1=writer file err signal mem clock arg dl string dirs prop cache jq os overwrite index overwrite_writer +UTILS1=writer file err signal mem clock arg dl string dirs prop cache jq os index ZSV_EXTRAS ?= @@ -175,6 +175,11 @@ else # not emcc CFLAGS+= ${CFLAGS_AVX} ${CFLAGS_SSE} LDFLAGS+=-lpthread # Linux explicitly requires endif + +ifeq ($(ZSV_EXTRAS),1) + UTILS1+= overwrite overwrite_writer +endif + UTILS=$(addprefix ${BUILD_DIR}/objs/utils/,$(addsuffix .o,${UTILS1})) ifeq ($(NO_THREADING),1) @@ -195,8 +200,14 @@ endif ZSV=$(BINDIR)/zsv${EXE} -SOURCES=echo paste count count-pull select select-pull 2tsv 2json serialize flatten pretty stack desc sql 2db compare prop rm mv jq overwrite -CLI_SOURCES=echo select desc count paste 2tsv pretty sql flatten 2json serialize stack 2db compare prop rm mv jq overwrite +SOURCES=echo paste count count-pull select select-pull 2tsv 2json serialize flatten pretty stack desc sql 2db compare prop rm mv jq +ifeq ($(ZSV_EXTRAS),1) + SOURCES+=overwrite +endif +CLI_SOURCES=echo select desc count paste 2tsv pretty sql flatten 2json serialize stack 2db compare prop rm mv jq +ifeq ($(ZSV_EXTRAS),1) + CLI_SOURCES+=overwrite +endif ifeq ($(ZSVSHEET_BUILD),1) SOURCES+=sheet diff --git a/app/echo.c b/app/echo.c index b25c12c9..f1d83dfe 100644 --- a/app/echo.c +++ b/app/echo.c @@ -181,9 +181,10 @@ int ZSV_MAIN_FUNC(ZSV_COMMAND)(int argc, const char *argv[], struct zsv_opts *op data.skip_until_prefix_len = data.skip_until_prefix ? strlen((char *)data.skip_until_prefix) : 0; } #ifdef ZSV_EXTRAS - } else if (!strcmp(arg, "--overwrite")) + } else if (!strcmp(arg, "--overwrite")) { overwrite_opts.src = zsv_next_arg(++arg_i, argc, argv, &err); - else if (!data.in) { +#endif + } else if (!data.in) { #ifndef NO_STDIN if (!strcmp(arg, "-")) data.in = stdin; @@ -195,7 +196,6 @@ int ZSV_MAIN_FUNC(ZSV_COMMAND)(int argc, const char *argv[], struct zsv_opts *op } else data.input_path = arg; } -#endif } else { fprintf(stderr, "Unrecognized option: %s\n", arg); err = 1; diff --git a/app/test/Makefile b/app/test/Makefile index cf56d255..62cf3ed6 100644 --- a/app/test/Makefile +++ b/app/test/Makefile @@ -45,7 +45,10 @@ BUILD_DIR=${THIS_LIB_BASE}/build/${BUILD_SUBDIR}/${CCBN} export TMP_DIR=${THIS_LIB_BASE}/tmp TEST_DATA_DIR=${THIS_LIB_BASE}/data -SOURCES=echo count count-pull select select-pull sql 2json serialize flatten pretty desc stack 2db 2tsv jq compare overwrite +SOURCES=echo count count-pull select select-pull sql 2json serialize flatten pretty desc stack 2db 2tsv jq compare +ifneq ($(ZSV_EXTRAS),) + SOURCES+=overwrite +endif TARGETS=$(addprefix ${BUILD_DIR}/bin/zsv_,$(addsuffix ${EXE},${SOURCES})) TESTS=test-blank-leading-rows $(addprefix test-,${SOURCES}) test-rm test-mv test-2json-help test-paste @@ -180,11 +183,14 @@ test-echo-chars: ${BUILD_DIR}/bin/zsv_echo${EXE} @${CMP} ${TMP_DIR}/$@.out expected/$@.out && ${TEST_PASS} || ${TEST_FAIL} test-echo-overwrite: ${BUILD_DIR}/bin/zsv_echo${EXE} +ifneq ($(ZSV_EXTRAS),) @${TEST_INIT} @${PREFIX} $< ${TEST_DATA_DIR}/loans_1.csv --overwrite 'sqlite3://${TEST_DATA_DIR}/loans_1-overwrite.db?sql=select row,col,value from overwrites order by row,col' ${REDIRECT} ${TMP_DIR}/$@.out @${CMP} ${TMP_DIR}/$@.out expected/$@.out && ${TEST_PASS} || ${TEST_FAIL} +endif test-echo-overwrite-auto: ${BUILD_DIR}/bin/zsv_echo${EXE} +ifneq ($(ZSV_EXTRAS),) @${TEST_INIT} @rm -f ${TEST_DATA_DIR}/.zsv/data/loans_2.csv/overwrite.sqlite3 @cp -p ${TEST_DATA_DIR}/loans_1.csv ${TEST_DATA_DIR}/loans_2.csv @@ -196,11 +202,14 @@ test-echo-overwrite-auto: ${BUILD_DIR}/bin/zsv_echo${EXE} @${CMP} ${TMP_DIR}/$@-after-ignored.out expected/$@-after-ignored.out && ${TEST_PASS} || ${TEST_FAIL} @${PREFIX} $< ${TEST_DATA_DIR}/loans_2.csv --apply-overwrites ${REDIRECT} ${TMP_DIR}/$@-after-applied.out @${CMP} ${TMP_DIR}/$@-after-applied.out expected/$@-after-applied.out && ${TEST_PASS} || ${TEST_FAIL} +endif test-echo-overwrite-csv: ${BUILD_DIR}/bin/zsv_echo${EXE} ${TEST_DATA_DIR}/loans_1-overwrite.csv +ifneq ($(ZSV_EXTRAS),) @${TEST_INIT} @${PREFIX} $< ${TEST_DATA_DIR}/loans_1.csv --overwrite '${TEST_DATA_DIR}/loans_1-overwrite.csv' ${REDIRECT} ${TMP_DIR}/$@.out @${CMP} ${TMP_DIR}/$@.out expected/$@.out && ${TEST_PASS} || ${TEST_FAIL} +endif worldcitiespop_mil.csv: curl -LOk 'https://burntsushi.net/stuff/worldcitiespop_mil.csv' @@ -503,7 +512,7 @@ ${BUILD_DIR}/bin/zsv_%${EXE}: test-2db: test-%: ${BUILD_DIR}/bin/zsv_%${EXE} worldcitiespop_mil.csv ${BUILD_DIR}/bin/zsv_2json${EXE} ${BUILD_DIR}/bin/zsv_select${EXE} @${TEST_INIT} - @${BUILD_DIR}/bin/zsv_select${EXE} -L 25000 -N worldcitiespop_mil.csv | ${BUILD_DIR}/bin/zsv_2json${EXE} --database --index "country_ix on country" --unique-index "ux on [#]" > ${TMP_DIR}/$@.json + @${BUILD_DIR}/bin/zsv_select${EXE} -H 24999 -N worldcitiespop_mil.csv | ${BUILD_DIR}/bin/zsv_2json${EXE} --database --index "country_ix on country" --unique-index "ux on [#]" > ${TMP_DIR}/$@.json @(${PREFIX} $< ${ARGS-$*} -o ${TMP_DIR}/$@.db --table data --overwrite < ${TMP_DIR}/test-2db.json ${REDIRECT1} ${TMP_DIR}/$@.out) @${CMP} ${TMP_DIR}/$@.out expected/$@.out && ${TEST_PASS} || ${TEST_FAIL} @sqlite3 ${TMP_DIR}/$@.db .schema | sed 's/ IF NOT EXISTS//' | sed 's/"data"/data/g' > ${TMP_DIR}/$@.out2 @@ -543,8 +552,7 @@ test-2json: test-%: ${BUILD_DIR}/bin/zsv_%${EXE} ${BUILD_DIR}/bin/zsv_2db${EXE} @(${PREFIX} $< --object --no-empty < ${TEST_DATA_DIR}/quoted4.csv ${REDIRECT1} ${TMP_DIR}/$@.out6 && \ ${CMP} ${TMP_DIR}/$@.out6 expected/$@.out6 && ${TEST_PASS} || ${TEST_FAIL}) - @${BUILD_DIR}/bin/zsv_select${EXE} -L 2000 -N worldcitiespop_mil.csv | ${BUILD_DIR}/bin/zsv_2json${EXE} --database --index "country_ix on country" --unique-index "ux on [#]" | ${BUILD_DIR}/bin/zsv_2db${EXE} -o ${TMP_DIR}/$@.db --table data --overwrite && (${PREFIX} $< --from-db ${TMP_DIR}/$@.db ${REDIRECT1} ${TMP_DIR}/$@.out7 && ${CMP} ${TMP_DIR}/$@.out7 expected/$@.out7 && ${TEST_PASS} || ${TEST_FAIL}) - + @${BUILD_DIR}/bin/zsv_select${EXE} -H 1999 -N worldcitiespop_mil.csv | ${BUILD_DIR}/bin/zsv_2json${EXE} --database --index "country_ix on country" --unique-index "ux on [#]" | ${BUILD_DIR}/bin/zsv_2db${EXE} -o ${TMP_DIR}/$@.db --table data --overwrite && (${PREFIX} $< --from-db ${TMP_DIR}/$@.db ${REDIRECT1} ${TMP_DIR}/$@.out7 && ${CMP} ${TMP_DIR}/$@.out7 expected/$@.out7 && ${TEST_PASS} || ${TEST_FAIL}) # ajv validate --strict-tuples=false -s ${THIS_MAKEFILE_DIR}/../../docs/db.schema.json -d expected/$@.out7.json [suffix must be json] test-2json-help: test-%-help: ${BUILD_DIR}/bin/zsv_%${EXE} diff --git a/app/utils/prop.c b/app/utils/prop.c index 82ab3a34..7297bd3b 100644 --- a/app/utils/prop.c +++ b/app/utils/prop.c @@ -257,8 +257,10 @@ enum zsv_status zsv_new_with_properties(struct zsv_opts *opts, struct zsv_prop_h if (fp.stat != zsv_status_ok) return fp.stat; } +#ifdef ZSV_EXTRAS if (opts->overwrite_auto) zsv_overwrite_auto(opts, input_path); +#endif if ((*handle_out = zsv_new(opts))) return zsv_status_ok; return zsv_status_memory;