zsv 1.3.1 → 1.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +153 -2
- data/README.md +132 -240
- data/ext/zsv/ZSV_UPSTREAM +7 -0
- data/ext/zsv/common.h +0 -12
- data/ext/zsv/extconf.rb +70 -122
- data/ext/zsv/options.c +63 -62
- data/ext/zsv/options.h +8 -11
- data/ext/zsv/parser.c +390 -201
- data/ext/zsv/parser.h +35 -22
- data/ext/zsv/row.c +75 -28
- data/ext/zsv/row.h +15 -9
- data/ext/zsv/upstream.rb +55 -0
- data/ext/zsv/vendor/zsv/LICENSE +21 -0
- data/ext/zsv/vendor/zsv/VENDORED_FROM +2 -0
- data/ext/zsv/vendor/zsv/configure +1212 -0
- data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/api.h +39 -0
- data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/common.h +36 -0
- data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/ext/sheet.h +8 -1
- data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/ext.h +6 -2
- data/ext/zsv/vendor/zsv/include/zsv/utils/appname.h +51 -0
- data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/arg.h +50 -1
- data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/compiler.h +19 -8
- data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/dirs.h +2 -0
- data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/file-mem.h +1 -0
- data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/file.h +28 -2
- data/ext/zsv/vendor/zsv/include/zsv/utils/os.h +145 -0
- data/ext/zsv/vendor/zsv/include/zsv/utils/output.h +34 -0
- data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/overwrite_writer.h +1 -1
- data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/prop.h +16 -4
- data/ext/zsv/vendor/zsv/include/zsv/utils/rng.h +35 -0
- data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/signal.h +7 -0
- data/ext/zsv/vendor/zsv/include/zsv/utils/sql.h +13 -0
- data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/string.h +25 -0
- data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/writer.h +9 -1
- data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/zsv_export.h +1 -1
- data/ext/zsv/vendor/{zsv-1.3.0/include/zsv.h → zsv/include/zsv.h.in} +1 -3
- data/ext/zsv/vendor/zsv/src/Makefile +238 -0
- data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/src/zsv.c +152 -14
- data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/src/zsv_internal.c +108 -50
- data/ext/zsv/vendor/zsv/src/zsv_scan_delim_fast.c +741 -0
- data/ext/zsv/vendor/zsv/src/zsv_scan_simd_avx2.h +89 -0
- data/ext/zsv/vendor/zsv/src/zsv_scan_simd_neon.h +80 -0
- data/ext/zsv/vendor/zsv/src/zsv_scan_simd_sse2.h +93 -0
- data/ext/zsv/vendor/zsv/src/zsv_scan_simd_wasm.h +79 -0
- data/ext/zsv/vendor/zsv/src/zsv_strencode.c +84 -0
- data/ext/zsv/zsv_ext.c +176 -105
- data/lib/zsv/errors.rb +32 -0
- data/lib/zsv/input.rb +88 -0
- data/lib/zsv/options.rb +132 -0
- data/lib/zsv/strict_validator.rb +124 -0
- data/lib/zsv/version.rb +1 -1
- data/lib/zsv.rb +137 -35
- metadata +81 -230
- data/ext/zsv/vendor/zsv-1.3.0/app/2db.c +0 -756
- data/ext/zsv/vendor/zsv-1.3.0/app/2json.c +0 -381
- data/ext/zsv/vendor/zsv-1.3.0/app/2tsv.c +0 -228
- data/ext/zsv/vendor/zsv-1.3.0/app/builtin/help.c +0 -123
- data/ext/zsv/vendor/zsv-1.3.0/app/builtin/license.c +0 -39
- data/ext/zsv/vendor/zsv-1.3.0/app/builtin/register.c +0 -104
- data/ext/zsv/vendor/zsv-1.3.0/app/builtin/thirdparty.c +0 -41
- data/ext/zsv/vendor/zsv-1.3.0/app/builtin/unregister.c +0 -1
- data/ext/zsv/vendor/zsv-1.3.0/app/builtin/version.c +0 -14
- data/ext/zsv/vendor/zsv-1.3.0/app/check/simdutf_wrapper.h +0 -19
- data/ext/zsv/vendor/zsv-1.3.0/app/check/utf8.c +0 -116
- data/ext/zsv/vendor/zsv-1.3.0/app/check.c +0 -194
- data/ext/zsv/vendor/zsv-1.3.0/app/cli.c +0 -796
- data/ext/zsv/vendor/zsv-1.3.0/app/cli_const.h +0 -41
- data/ext/zsv/vendor/zsv-1.3.0/app/cli_export.h +0 -16
- data/ext/zsv/vendor/zsv-1.3.0/app/cli_ini.c +0 -280
- data/ext/zsv/vendor/zsv-1.3.0/app/cli_internal.h +0 -36
- data/ext/zsv/vendor/zsv-1.3.0/app/compare.c +0 -913
- data/ext/zsv/vendor/zsv-1.3.0/app/compare.h +0 -23
- data/ext/zsv/vendor/zsv-1.3.0/app/compare_added_column.c +0 -20
- data/ext/zsv/vendor/zsv-1.3.0/app/compare_internal.h +0 -140
- data/ext/zsv/vendor/zsv-1.3.0/app/compare_sort.c +0 -91
- data/ext/zsv/vendor/zsv-1.3.0/app/compare_unique_colname.c +0 -81
- data/ext/zsv/vendor/zsv-1.3.0/app/count-pull.c +0 -82
- data/ext/zsv/vendor/zsv-1.3.0/app/count.c +0 -404
- data/ext/zsv/vendor/zsv-1.3.0/app/desc.c +0 -569
- data/ext/zsv/vendor/zsv-1.3.0/app/echo.c +0 -365
- data/ext/zsv/vendor/zsv-1.3.0/app/ext_example/my_extension.c +0 -366
- data/ext/zsv/vendor/zsv-1.3.0/app/ext_example/mysheet_extension.c +0 -341
- data/ext/zsv/vendor/zsv-1.3.0/app/ext_template/YOUR_EXTENSION_zsvext.c +0 -263
- data/ext/zsv/vendor/zsv-1.3.0/app/external/inih/ini.c +0 -298
- data/ext/zsv/vendor/zsv-1.3.0/app/external/inih/ini.h +0 -157
- data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/json_numeric.c +0 -177
- data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/jsonwriter.c +0 -444
- data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/jsonwriter.h +0 -145
- data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/utils.c +0 -110
- data/ext/zsv/vendor/zsv-1.3.0/app/external/memfile-1.0/include/memfile.h +0 -15
- data/ext/zsv/vendor/zsv-1.3.0/app/external/memfile-1.0/src/memfile.c +0 -64
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sglib/sglib.h +0 -1955
- data/ext/zsv/vendor/zsv-1.3.0/app/external/simdutf/simdutf.h +0 -6802
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3.c +0 -230517
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3.h +0 -12174
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_and_csv_vtab.c +0 -2
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab-mem.c +0 -142
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab-mem.h +0 -49
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab-zsv.c +0 -485
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab.c +0 -1015
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3ext.h +0 -663
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/vtab_helper.c +0 -85
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_common.h +0 -75
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_gen.h +0 -167
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_parse.h +0 -228
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_tree.h +0 -186
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_version.h +0 -23
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_common.h +0 -76
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_gen.h +0 -167
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_parse.h +0 -238
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_tree.h +0 -186
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl.c +0 -184
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_alloc.c +0 -52
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_alloc.h +0 -34
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_buf.c +0 -103
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_buf.h +0 -57
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_bytestack.h +0 -69
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_encode.c +0 -220
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_encode.h +0 -34
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_gen.c +0 -362
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_lex.c +0 -764
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_lex.h +0 -117
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_parser.c +0 -508
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_parser.h +0 -78
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_tree.c +0 -505
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_version.c +0 -7
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper/json_value.h +0 -59
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper/yajl_helper.h +0 -208
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper.c +0 -795
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper_internal.h +0 -28
- data/ext/zsv/vendor/zsv-1.3.0/app/flatten.c +0 -851
- data/ext/zsv/vendor/zsv-1.3.0/app/jq.c +0 -106
- data/ext/zsv/vendor/zsv-1.3.0/app/jq.h +0 -6
- data/ext/zsv/vendor/zsv-1.3.0/app/mv.c +0 -113
- data/ext/zsv/vendor/zsv-1.3.0/app/noop.c +0 -90
- data/ext/zsv/vendor/zsv-1.3.0/app/overwrite.c +0 -295
- data/ext/zsv/vendor/zsv-1.3.0/app/paste.c +0 -175
- data/ext/zsv/vendor/zsv-1.3.0/app/pretty.c +0 -693
- data/ext/zsv/vendor/zsv-1.3.0/app/prop.c +0 -980
- data/ext/zsv/vendor/zsv-1.3.0/app/rm.c +0 -131
- data/ext/zsv/vendor/zsv-1.3.0/app/select/fixed.c +0 -130
- data/ext/zsv/vendor/zsv-1.3.0/app/select/internal.h +0 -118
- data/ext/zsv/vendor/zsv-1.3.0/app/select/parallel.c +0 -45
- data/ext/zsv/vendor/zsv-1.3.0/app/select/parallel.h +0 -41
- data/ext/zsv/vendor/zsv-1.3.0/app/select/processing.c +0 -107
- data/ext/zsv/vendor/zsv-1.3.0/app/select/rand.c +0 -20
- data/ext/zsv/vendor/zsv-1.3.0/app/select/regex.c +0 -61
- data/ext/zsv/vendor/zsv-1.3.0/app/select/search.c +0 -14
- data/ext/zsv/vendor/zsv-1.3.0/app/select/selection.c +0 -192
- data/ext/zsv/vendor/zsv-1.3.0/app/select/usage.c +0 -72
- data/ext/zsv/vendor/zsv-1.3.0/app/select-pull.c +0 -812
- data/ext/zsv/vendor/zsv-1.3.0/app/select.c +0 -753
- data/ext/zsv/vendor/zsv-1.3.0/app/serialize.c +0 -372
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/curses.h +0 -15
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/cursor.c +0 -119
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/errors.c +0 -45
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/file.c +0 -63
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/file.h +0 -12
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/filter.c +0 -166
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/handlers.c +0 -214
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/handlers_internal.h +0 -128
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/help.c +0 -43
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/index.c +0 -81
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/index.h +0 -25
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/key-bindings.c +0 -325
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/key-bindings.h +0 -73
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/lexer.c +0 -203
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/newline_handler.c +0 -7
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/pivot.c +0 -318
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/procedure.c +0 -134
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/procedure.h +0 -119
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/read-data.c +0 -322
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/screen_buffer.c +0 -203
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/screen_buffer.h +0 -36
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/sheet-sql.c +0 -167
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/sheet_internal.h +0 -36
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/sqlfilter.c +0 -153
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/terminfo.c +0 -32
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/transformation.c +0 -312
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/transformation.h +0 -29
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/ui_buffer.c +0 -266
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/usage.c +0 -9
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/utf8-width.c +0 -60
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet.c +0 -1007
- data/ext/zsv/vendor/zsv-1.3.0/app/sql.c +0 -453
- data/ext/zsv/vendor/zsv-1.3.0/app/sql_internal.c +0 -101
- data/ext/zsv/vendor/zsv-1.3.0/app/sql_internal.h +0 -49
- data/ext/zsv/vendor/zsv-1.3.0/app/stack.c +0 -393
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/arg.c +0 -322
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/cache.c +0 -228
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/cat.c +0 -91
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/chunk.c +0 -240
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/chunk.h +0 -63
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/clock.c +0 -57
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/db.c +0 -148
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs-no-jq.c +0 -2
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs.c +0 -427
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs_from_json.c +0 -253
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs_to_json.c +0 -121
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/dl.c +0 -20
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/emcc/fs_api.c +0 -159
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/err.c +0 -24
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/file-mem.c +0 -180
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/file.c +0 -256
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/index.c +0 -197
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/index.h +0 -49
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/jq.c +0 -400
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/json.c +0 -120
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/mem.c +0 -18
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/memmem.c +0 -132
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/os.c +0 -178
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/overwrite.c +0 -258
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/overwrite_writer.c +0 -246
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/pcre2-8/pcre2-8-test.c +0 -123
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/pcre2-8/pcre2-8.c +0 -153
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/pcre2-8/pcre2-8.h +0 -54
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/prop.c +0 -267
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/signal.c +0 -53
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/string.c +0 -357
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/dir_exists_longpath.c +0 -83
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/dl.c +0 -33
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/fopen_longpath.c +0 -184
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/foreach_dirent_longpath.c +0 -292
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/io.c +0 -259
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/io.h +0 -13
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/mkdir_longpath.c +0 -255
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/remove_longpath.c +0 -96
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/writer.c +0 -361
- data/ext/zsv/vendor/zsv-1.3.0/app/zsv_command.h +0 -40
- data/ext/zsv/vendor/zsv-1.3.0/app/zsv_command_standalone.c +0 -16
- data/ext/zsv/vendor/zsv-1.3.0/app/zsv_main.h +0 -44
- data/ext/zsv/vendor/zsv-1.3.0/examples/js/zsv_parser_api_dummy.c +0 -3
- data/ext/zsv/vendor/zsv-1.3.0/examples/lib/parse_by_chunk.c +0 -100
- data/ext/zsv/vendor/zsv-1.3.0/examples/lib/print_my_column.c +0 -143
- data/ext/zsv/vendor/zsv-1.3.0/examples/lib/pull.c +0 -89
- data/ext/zsv/vendor/zsv-1.3.0/examples/lib/simple.c +0 -123
- data/ext/zsv/vendor/zsv-1.3.0/fuzz/fuzz.c +0 -16
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/os.h +0 -54
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/sql.h +0 -11
- data/ext/zsv/vendor/zsv-1.3.0/src/zsv_strencode.c +0 -51
- /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/ext/implementation.h +0 -0
- /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/ext/implementation_private.h +0 -0
- /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/cache.h +0 -0
- /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/clock.h +0 -0
- /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/db.h +0 -0
- /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/dl.h +0 -0
- /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/emcc/fs_api.h +0 -0
- /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/err.h +0 -0
- /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/jq.h +0 -0
- /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/json.h +0 -0
- /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/mem.h +0 -0
- /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/memmem.h +0 -0
- /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/overwrite.h +0 -0
- /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/utf8.h +0 -0
- /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/win/dl.h +0 -0
- /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/src/vector_delim.c +0 -0
- /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/src/zsv_scan_delim.c +0 -0
- /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/src/zsv_scan_fixed.c +0 -0
|
@@ -236,6 +236,32 @@ ZSV_EXPORT enum zsv_status zsv_parse_bytes(zsv_parser parser, const unsigned cha
|
|
|
236
236
|
ZSV_EXPORT
|
|
237
237
|
const unsigned char *zsv_parse_status_desc(enum zsv_status status);
|
|
238
238
|
|
|
239
|
+
/**
|
|
240
|
+
* Set a column filter for the fast scanner engine. When set, only the
|
|
241
|
+
* specified columns receive full processing (quote normalization, UTF-8
|
|
242
|
+
* encoding). Other columns are stored as raw pointers into the input
|
|
243
|
+
* buffer without normalization. Has no effect on the standard engine.
|
|
244
|
+
*
|
|
245
|
+
* @param parser
|
|
246
|
+
* @param col_indices array of 0-based column indices to fully process
|
|
247
|
+
* @param count number of elements in col_indices
|
|
248
|
+
* @return zsv_status_ok on success
|
|
249
|
+
*/
|
|
250
|
+
ZSV_EXPORT
|
|
251
|
+
enum zsv_status zsv_set_column_filter(zsv_parser parser, const unsigned int *col_indices, unsigned int count);
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Hint to the parser that cell data is not needed. When set, the fast
|
|
255
|
+
* scanner engine skips per-cell storage and uses popcount-only row
|
|
256
|
+
* counting. The row_handler callback is still invoked for each row.
|
|
257
|
+
* Has no effect on the standard scanner engine.
|
|
258
|
+
*
|
|
259
|
+
* @param parser
|
|
260
|
+
* @param skip non-zero to skip cell storage, 0 to resume normal parsing
|
|
261
|
+
*/
|
|
262
|
+
ZSV_EXPORT
|
|
263
|
+
void zsv_set_skip_cells(zsv_parser parser, int skip);
|
|
264
|
+
|
|
239
265
|
/**
|
|
240
266
|
* Abort parsing. After this function is called, no further
|
|
241
267
|
* `row_handler()` or `cell_handler()` calls will be made, and parse functions
|
|
@@ -333,4 +359,17 @@ size_t zsv_strencode(unsigned char *s, size_t n, unsigned char replace,
|
|
|
333
359
|
int (*malformed_handler)(void *, const unsigned char *s, size_t n, size_t offset),
|
|
334
360
|
void *handler_ctx);
|
|
335
361
|
|
|
362
|
+
/**
|
|
363
|
+
* Scan a string for malformed UTF8 without modifying it
|
|
364
|
+
* @param s input string (read-only)
|
|
365
|
+
* @param n length (in bytes) of input
|
|
366
|
+
* @param callback optional callback invoked upon scanning malformed UTF8
|
|
367
|
+
* @param ctx context pointer passed to callback
|
|
368
|
+
* @return number of malformed UTF8 sequences found
|
|
369
|
+
*/
|
|
370
|
+
ZSV_EXPORT
|
|
371
|
+
size_t zsv_strencode_validate(const unsigned char *s, size_t n,
|
|
372
|
+
int (*malformed_handler)(void *, const unsigned char *s, size_t n, size_t offset),
|
|
373
|
+
void *handler_ctx);
|
|
374
|
+
|
|
336
375
|
#endif
|
|
@@ -25,6 +25,10 @@ enum zsv_status {
|
|
|
25
25
|
zsv_status_memory,
|
|
26
26
|
zsv_status_error,
|
|
27
27
|
zsv_status_row,
|
|
28
|
+
/* Fast SIMD engine only: input violates RFC 4180 (e.g. a quote in the
|
|
29
|
+
* middle of an unquoted cell). The fast engine requires standard CSV;
|
|
30
|
+
* use ZSV_MODE_COMPAT (the scalar/legacy engine) for non-standard input. */
|
|
31
|
+
zsv_status_nonstandard_csv,
|
|
28
32
|
zsv_status_done = 100
|
|
29
33
|
#ifdef ZSV_EXTRAS
|
|
30
34
|
,
|
|
@@ -233,6 +237,13 @@ struct zsv_opts {
|
|
|
233
237
|
*/
|
|
234
238
|
char only_crlf_rowend;
|
|
235
239
|
#endif
|
|
240
|
+
/**
|
|
241
|
+
* scan engine: 0 = default, 3 = fast (branchless SIMD)
|
|
242
|
+
*
|
|
243
|
+
* cli option: --parser <default|fast|compat>
|
|
244
|
+
*/
|
|
245
|
+
unsigned char scan_engine;
|
|
246
|
+
|
|
236
247
|
/**
|
|
237
248
|
* flag to print more verbose messages to the console
|
|
238
249
|
* cli option: -v,--verbose
|
|
@@ -296,6 +307,19 @@ struct zsv_opts {
|
|
|
296
307
|
unsigned char _ : 4;
|
|
297
308
|
} option_overrides;
|
|
298
309
|
|
|
310
|
+
/**
|
|
311
|
+
* Optional file path to be treated as the input's path when locating
|
|
312
|
+
* cached file properties (.zsv/data/<filepath>/). Applied only to an
|
|
313
|
+
* input that has no path of its own (e.g. stdin); an input read from an
|
|
314
|
+
* actual file keeps its own property lookup. Consumed when loading cached
|
|
315
|
+
* properties (by zsv_new_with_properties(), and directly by `sql` for
|
|
316
|
+
* buffered stdin input); ignored by zsv_new(). Has no effect on which
|
|
317
|
+
* data is parsed
|
|
318
|
+
*
|
|
319
|
+
* cli option: --stdin-filename <path>
|
|
320
|
+
*/
|
|
321
|
+
const char *stdin_filename;
|
|
322
|
+
|
|
299
323
|
int (*errprintf)(void *ctx, const char *format, ...);
|
|
300
324
|
void *errf;
|
|
301
325
|
int (*errclose)(void *ctx);
|
|
@@ -356,6 +380,18 @@ struct zsv_opts {
|
|
|
356
380
|
struct zsv_opt_overwrite overwrite;
|
|
357
381
|
|
|
358
382
|
#endif /* ZSV_EXTRAS */
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* optional handler invoked when a cell contains malformed UTF8, whatever
|
|
386
|
+
* `malformed_utf8_replace` says to do about it: called at most once per
|
|
387
|
+
* cell, with the cell's index in the current row and the number of
|
|
388
|
+
* malformed sequences scanned. Not invoked for cells past the row's cell
|
|
389
|
+
* limit (overflow), nor in fixed-width mode.
|
|
390
|
+
* Last in the struct so consumers built against the prior layout keep
|
|
391
|
+
* their field offsets (a size change still requires a rebuild)
|
|
392
|
+
*/
|
|
393
|
+
void (*malformed_utf8_handler)(void *ctx, size_t cell_ix, size_t count);
|
|
394
|
+
void *malformed_utf8_handler_ctx;
|
|
359
395
|
};
|
|
360
396
|
|
|
361
397
|
#endif
|
|
@@ -31,7 +31,9 @@ struct zsvsheet_buffer_transformation_opts {
|
|
|
31
31
|
/**
|
|
32
32
|
* Caller supplied context; can be retrieved with ext_sheet_transformation_user_context(trn).
|
|
33
33
|
*
|
|
34
|
-
* This is free'd by the library after on_done is called unless it is NULL.
|
|
34
|
+
* This is free'd by the library after on_done is called unless it is NULL. That holds
|
|
35
|
+
* for every outcome, including zsvsheet_status_busy -- so a caller that retries must
|
|
36
|
+
* build a fresh context rather than reuse the opts it just passed.
|
|
35
37
|
*/
|
|
36
38
|
void *user_context;
|
|
37
39
|
/**
|
|
@@ -61,6 +63,11 @@ struct zsvsheet_buffer_transformation_opts {
|
|
|
61
63
|
* For small input files this may be executed in the main thread, for larger ones
|
|
62
64
|
* it will be done in a background thread. So if an operation done inside this handler
|
|
63
65
|
* can take a long time even on small inputs then it could block the main thread.
|
|
66
|
+
*
|
|
67
|
+
* Called exactly once. If the transformation failed before it was created, trn is
|
|
68
|
+
* a stub: its parser, writer, filename and buffer are all NULL, and
|
|
69
|
+
* ext_sheet_transformation_user_context(trn) may itself be NULL. So this handler
|
|
70
|
+
* must not dereference anything it did not itself allocate.
|
|
64
71
|
*/
|
|
65
72
|
void (*on_done)(zsvsheet_transformation trn);
|
|
66
73
|
};
|
|
@@ -224,7 +224,10 @@ struct zsv_ext_callbacks {
|
|
|
224
224
|
|
|
225
225
|
/**
|
|
226
226
|
* Get the data file associated with a buffer. This might not be the same as the filename,
|
|
227
|
-
* such as when the data has been filtered
|
|
227
|
+
* such as when the data has been filtered. Unsaved cell edits are first written to a new
|
|
228
|
+
* data file, so the file reflects them; the name can differ from an earlier call's, and
|
|
229
|
+
* an earlier name must not be used afterwards. Call from the thread that handles sheet
|
|
230
|
+
* commands. Returns NULL if writing the edits fails
|
|
228
231
|
*/
|
|
229
232
|
const char *(*ext_sheet_buffer_data_filename)(zsvsheet_buffer_t);
|
|
230
233
|
|
|
@@ -276,7 +279,8 @@ struct zsv_ext_callbacks {
|
|
|
276
279
|
zsvsheet_status (*on_newline)(zsvsheet_proc_context_t));
|
|
277
280
|
|
|
278
281
|
/**
|
|
279
|
-
* Get zsv_opts used to open the buffer's data file
|
|
282
|
+
* Get zsv_opts used to open the buffer's data file. Like ext_sheet_buffer_data_filename(),
|
|
283
|
+
* first writes unsaved cell edits to a new data file, whose options these are
|
|
280
284
|
*/
|
|
281
285
|
struct zsv_opts (*ext_sheet_buffer_get_zsv_opts)(zsvsheet_buffer_t h);
|
|
282
286
|
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2021 Liquidaty and the zsv/lib contributors
|
|
3
|
+
* All rights reserved
|
|
4
|
+
*
|
|
5
|
+
* This file is part of zsv/lib, distributed under the license defined at
|
|
6
|
+
* https://opensource.org/licenses/MIT
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
#ifndef ZSV_UTILS_APPNAME_H
|
|
10
|
+
#define ZSV_UTILS_APPNAME_H
|
|
11
|
+
|
|
12
|
+
#include <stdio.h> /* FILE */
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
* The zsv commands can be bundled into the `zsv` CLI, built standalone, or
|
|
16
|
+
* embedded into a third-party app. Their help/usage text must therefore refer
|
|
17
|
+
* to the host program by its *runtime* name (e.g. "zsv" or "xxx"), not a name
|
|
18
|
+
* fixed at compile time.
|
|
19
|
+
*
|
|
20
|
+
* Usage strings embed the ZSV_USAGE_PROG placeholder wherever the host program
|
|
21
|
+
* name belongs; zsv_print_usage() substitutes the runtime name when printing.
|
|
22
|
+
* The subcommand portion ("compare", "count", ...) is supplied separately via
|
|
23
|
+
* the APPNAME macro (see zsv_command.h), so a single token suffices here.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/* Compile-time fallback; an embedder may override with
|
|
27
|
+
* -DZSV_DEFAULT_PROG_NAME='"xxx"' */
|
|
28
|
+
#ifndef ZSV_DEFAULT_PROG_NAME
|
|
29
|
+
#define ZSV_DEFAULT_PROG_NAME "zsv"
|
|
30
|
+
#endif
|
|
31
|
+
|
|
32
|
+
/* Placeholder for the host program name within usage[] string literals.
|
|
33
|
+
* Uses a control character that never appears in legitimate help text. */
|
|
34
|
+
#define ZSV_USAGE_PROG "\x01"
|
|
35
|
+
|
|
36
|
+
/* Set the host program name once at startup, from argv[0] (the basename is
|
|
37
|
+
* extracted) or an explicit override. host may be NULL or empty, in which case
|
|
38
|
+
* the current value (default ZSV_DEFAULT_PROG_NAME) is retained. */
|
|
39
|
+
void zsv_set_prog_name(const char *host);
|
|
40
|
+
|
|
41
|
+
/* The host program name, e.g. "zsv" or "xxx". Never NULL. */
|
|
42
|
+
const char *zsv_prog_name(void);
|
|
43
|
+
|
|
44
|
+
/* Print a NULL-terminated array of usage lines to the given stream, substituting
|
|
45
|
+
* ZSV_USAGE_PROG with zsv_prog_name() and appending a newline to each line. */
|
|
46
|
+
void zsv_fprint_usage(FILE *f, const char *const *lines);
|
|
47
|
+
|
|
48
|
+
/* Convenience wrapper for zsv_fprint_usage(stdout, lines). */
|
|
49
|
+
void zsv_print_usage(const char *const *lines);
|
|
50
|
+
|
|
51
|
+
#endif
|
|
@@ -47,7 +47,11 @@ void zsv_set_default_completed_callback(zsv_completed_callback cb, void *ctx);
|
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
49
|
* Convert common command-line arguments to zsv_opts
|
|
50
|
-
* Return new argc/argv values with processed args stripped out
|
|
50
|
+
* Return new argc/argv values with processed args stripped out, each arg
|
|
51
|
+
* matched by zsv_arg_to_opts(). Every arg is scanned, "--" and the values of
|
|
52
|
+
* the command's own options included, since only the command knows which args
|
|
53
|
+
* those are; a command that takes arbitrary option values calls
|
|
54
|
+
* zsv_arg_to_opts() from its own parser instead.
|
|
51
55
|
* Initializes opts_out with `zsv_get_default_opts()`, then with
|
|
52
56
|
* the below common options if present:
|
|
53
57
|
* -B,--buff-size <N>
|
|
@@ -56,9 +60,16 @@ void zsv_set_default_completed_callback(zsv_completed_callback cb, void *ctx);
|
|
|
56
60
|
* -t,--tab-delim
|
|
57
61
|
* -O,--other-delim <C>
|
|
58
62
|
* -q,--no-quote
|
|
63
|
+
* -R,--skip-head <n>: skip n initial rows
|
|
59
64
|
* -S,--keep-blank-headers: disable default behavior of ignoring leading blank rows
|
|
60
65
|
* -d,--header-row-span <n>: apply header depth (rowspan) of n
|
|
66
|
+
* --stdin-filename <path>: apply saved file properties associated with
|
|
67
|
+
* the given path to input read from stdin
|
|
61
68
|
* -v,--verbose
|
|
69
|
+
* -u,--malformed-utf8-replacement <string>
|
|
70
|
+
* -0,--header-row <header>
|
|
71
|
+
* -1,--apply-overwrites, -L,--limit-rows <n> (ZSV_EXTRAS only)
|
|
72
|
+
* --only-crlf (unless ZSV_NO_ONLY_CRLF), --parser <default|fast|compat>
|
|
62
73
|
*
|
|
63
74
|
* @param argc count of args to process
|
|
64
75
|
* @param argv args to process
|
|
@@ -71,6 +82,30 @@ void zsv_set_default_completed_callback(zsv_completed_callback cb, void *ctx);
|
|
|
71
82
|
enum zsv_status zsv_args_to_opts(int argc, const char *argv[], int *argc_out, const char **argv_out,
|
|
72
83
|
struct zsv_opts *opts_out);
|
|
73
84
|
|
|
85
|
+
enum zsv_arg_match {
|
|
86
|
+
zsv_arg_none = 0, /* not a common option: the caller handles argv[*arg_i] */
|
|
87
|
+
zsv_arg_ok, /* applied to opts */
|
|
88
|
+
zsv_arg_err /* invalid, with the message on stderr */
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Match argv[*arg_i] against the common options zsv_args_to_opts() handles and
|
|
93
|
+
* apply it to opts. For a command that parses its own args: call it where the
|
|
94
|
+
* command's own options fail to match, so the value of one of its options is
|
|
95
|
+
* never read as a common option.
|
|
96
|
+
*
|
|
97
|
+
* "-" (stdin), "--" and non-option args are zsv_arg_none. On zsv_arg_ok and
|
|
98
|
+
* zsv_arg_err, *arg_i is left at the last arg consumed (the option's value, if
|
|
99
|
+
* it takes one), so the caller's loop increment moves past it.
|
|
100
|
+
*
|
|
101
|
+
* @param argc count of args
|
|
102
|
+
* @param argv args
|
|
103
|
+
* @param arg_i index of the arg to match; updated as above
|
|
104
|
+
* @param opts options to update; the caller initializes them, e.g. with
|
|
105
|
+
* zsv_get_default_opts()
|
|
106
|
+
*/
|
|
107
|
+
enum zsv_arg_match zsv_arg_to_opts(int argc, const char *argv[], int *arg_i, struct zsv_opts *opts);
|
|
108
|
+
|
|
74
109
|
/**
|
|
75
110
|
* Fetch the next arg, if it exists, else print an error message
|
|
76
111
|
* The argc_i argument does not need to be valid; it will be checked
|
|
@@ -87,4 +122,18 @@ enum zsv_status zsv_args_to_opts(int argc, const char *argv[], int *argc_out, co
|
|
|
87
122
|
*/
|
|
88
123
|
const char *zsv_next_arg(int arg_i, int argc, const char *argv[], int *err);
|
|
89
124
|
|
|
125
|
+
/**
|
|
126
|
+
* zsv_arg_is_option: true for an option-shaped token ('-x', '-xyz', '--name');
|
|
127
|
+
* false for a lone "-" (stdin) and for non-dash tokens. Use at a command's
|
|
128
|
+
* "treat as input" fall-through to detect a token that no option branch matched.
|
|
129
|
+
*/
|
|
130
|
+
int zsv_arg_is_option(const char *arg);
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* zsv_err_unrecognized_option: print the canonical unrecognized-option
|
|
134
|
+
* diagnostic ("Unrecognized option: <arg>") to stderr and return the uniform
|
|
135
|
+
* nonzero exit status used across all commands.
|
|
136
|
+
*/
|
|
137
|
+
int zsv_err_unrecognized_option(const char *arg);
|
|
138
|
+
|
|
90
139
|
#endif
|
|
@@ -12,18 +12,18 @@
|
|
|
12
12
|
#ifdef HAVE___BUILTIN_EXPECT
|
|
13
13
|
|
|
14
14
|
#ifndef LIKELY
|
|
15
|
-
#define LIKELY(x) __builtin_expect(x, 1)
|
|
15
|
+
#define LIKELY(x) __builtin_expect(!!(x), 1)
|
|
16
16
|
#endif
|
|
17
17
|
|
|
18
18
|
#ifndef UNLIKELY
|
|
19
|
-
#define UNLIKELY(x) __builtin_expect(x, 0)
|
|
19
|
+
#define UNLIKELY(x) __builtin_expect(!!(x), 0)
|
|
20
20
|
#endif
|
|
21
21
|
|
|
22
22
|
#ifndef VERY_LIKELY
|
|
23
23
|
#ifdef NO___BUILTIN_EXPECT_WITH_PROBABILITY
|
|
24
24
|
#define VERY_LIKELY(x) LIKELY(x)
|
|
25
25
|
#else
|
|
26
|
-
#define VERY_LIKELY(x) __builtin_expect_with_probability(x, 1, 0.999)
|
|
26
|
+
#define VERY_LIKELY(x) __builtin_expect_with_probability(!!(x), 1, 0.999)
|
|
27
27
|
#endif
|
|
28
28
|
#endif
|
|
29
29
|
|
|
@@ -31,28 +31,39 @@
|
|
|
31
31
|
#ifdef NO___BUILTIN_EXPECT_WITH_PROBABILITY
|
|
32
32
|
#define VERY_UNLIKELY(x) UNLIKELY(x)
|
|
33
33
|
#else
|
|
34
|
-
#define VERY_UNLIKELY(x) __builtin_expect_with_probability(x, 0, 0.999)
|
|
34
|
+
#define VERY_UNLIKELY(x) __builtin_expect_with_probability(!!(x), 0, 0.999)
|
|
35
35
|
#endif
|
|
36
36
|
#endif
|
|
37
37
|
|
|
38
38
|
#else
|
|
39
39
|
/* no HAVE___BUILTIN_EXPECT */
|
|
40
40
|
#ifndef LIKELY
|
|
41
|
-
#define LIKELY(x) (x)
|
|
41
|
+
#define LIKELY(x) (!!(x))
|
|
42
42
|
#endif
|
|
43
43
|
|
|
44
44
|
#ifndef UNLIKELY
|
|
45
|
-
#define UNLIKELY(x) (x)
|
|
45
|
+
#define UNLIKELY(x) (!!(x))
|
|
46
46
|
#endif
|
|
47
47
|
|
|
48
48
|
#ifndef VERY_LIKELY
|
|
49
|
-
#define VERY_LIKELY(x) (x)
|
|
49
|
+
#define VERY_LIKELY(x) (!!(x))
|
|
50
50
|
#endif
|
|
51
51
|
|
|
52
52
|
#ifndef VERY_UNLIKELY
|
|
53
|
-
#define VERY_UNLIKELY(x) (x)
|
|
53
|
+
#define VERY_UNLIKELY(x) (!!(x))
|
|
54
54
|
#endif
|
|
55
55
|
|
|
56
56
|
#endif /* HAVE___BUILTIN_EXPECT */
|
|
57
57
|
|
|
58
|
+
/* Warn (and, under -Werror, fail to compile) when a function's return value is ignored by a caller. */
|
|
59
|
+
#ifndef ZSV_WARN_UNUSED_RESULT
|
|
60
|
+
#if defined(__GNUC__) || defined(__clang__)
|
|
61
|
+
#define ZSV_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
|
|
62
|
+
#elif defined(_MSC_VER)
|
|
63
|
+
#define ZSV_WARN_UNUSED_RESULT _Check_return_
|
|
64
|
+
#else
|
|
65
|
+
#define ZSV_WARN_UNUSED_RESULT
|
|
66
|
+
#endif
|
|
58
67
|
#endif
|
|
68
|
+
|
|
69
|
+
#endif /* ZSV_UTILS_COMPILER */
|
|
@@ -34,6 +34,7 @@ size_t zsv_get_config_dir(char *buff, size_t buffsize, const char *prefix);
|
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* Get the path of the current executable
|
|
37
|
+
* @return length written to buff, or 0 if the path could not be determined
|
|
37
38
|
*/
|
|
38
39
|
size_t zsv_get_executable_path(char *buff, size_t buffsize);
|
|
39
40
|
|
|
@@ -61,6 +62,7 @@ int zsv_mkdir(const char *path);
|
|
|
61
62
|
|
|
62
63
|
/**
|
|
63
64
|
* Make a directory, as well as any intermediate dirs
|
|
65
|
+
* On non-Windows, new dirs are created with mode 0777, less the process umask
|
|
64
66
|
* return zero on success
|
|
65
67
|
*/
|
|
66
68
|
int zsv_mkdirs(const char *path, char path_is_filename);
|
|
@@ -9,6 +9,7 @@ typedef struct zsv_memfile zsv_memfile;
|
|
|
9
9
|
|
|
10
10
|
// Public API Functions
|
|
11
11
|
zsv_memfile *zsv_memfile_open(size_t buffsz);
|
|
12
|
+
// fwrite() semantics: returns the number of complete items written (n on full success)
|
|
12
13
|
size_t zsv_memfile_write(const void *data, size_t sz, size_t n, zsv_memfile *zfm);
|
|
13
14
|
int zsv_memfile_rewind(zsv_memfile *zfm);
|
|
14
15
|
size_t zsv_memfile_read(void *buffer, size_t size, size_t nitems, zsv_memfile *zfm);
|
|
@@ -20,13 +20,33 @@
|
|
|
20
20
|
#endif
|
|
21
21
|
#endif // LINEEND
|
|
22
22
|
/**
|
|
23
|
-
* Get a temp file name. The
|
|
24
|
-
* on the heap, and the caller should
|
|
23
|
+
* Get a temp file name. The file is created (empty, mode 0600); the returned
|
|
24
|
+
* value, if any, will have been allocated on the heap, and the caller should
|
|
25
|
+
* `free()`.
|
|
26
|
+
*
|
|
27
|
+
* On POSIX the directory is `$TMPDIR`, falling back to the current directory
|
|
28
|
+
* when it is unset, empty, or unusable (a fallback warns on stderr). On Windows
|
|
29
|
+
* it is `GetTempPath()` (TMP/TEMP/USERPROFILE) with no fallback.
|
|
25
30
|
*
|
|
26
31
|
* @param prefix string with which the resulting file name will be prefixed
|
|
27
32
|
*/
|
|
28
33
|
char *zsv_get_temp_filename(const char *prefix);
|
|
29
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Get a temp file name for a caller that creates the file itself with
|
|
37
|
+
* exclusive-create semantics (`O_CREAT|O_EXCL`), such as the toonwriter /
|
|
38
|
+
* json2toon spill store. Same as `zsv_get_temp_filename()` except the
|
|
39
|
+
* placeholder file it creates is removed, so the caller's create succeeds.
|
|
40
|
+
* The caller's `O_EXCL` still fails closed, so hijacking the path means
|
|
41
|
+
* guessing the name within that window -- which is `mkstemp`-random on POSIX,
|
|
42
|
+
* but only weakly unpredictable on Windows, where `GetTempFileName()` derives
|
|
43
|
+
* it from the system time.
|
|
44
|
+
*
|
|
45
|
+
* @param prefix truncated to the 3 chars `zsv_get_temp_filename()` accepts,
|
|
46
|
+
* so a library's longer fixed prefix is safe to pass through
|
|
47
|
+
*/
|
|
48
|
+
char *zsv_get_temp_filename_excl(const char *prefix);
|
|
49
|
+
|
|
30
50
|
/**
|
|
31
51
|
* Replacement for tmpfile().
|
|
32
52
|
* Returns filename; file must be manually removed after fclose
|
|
@@ -43,6 +63,12 @@ FILE *zsv_tmpfile(const char *prefix, char **filename, const char *mode);
|
|
|
43
63
|
*/
|
|
44
64
|
int zsv_file_exists(const char *filename);
|
|
45
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Check whether an open stream is a regular file (as opposed to a pipe, FIFO,
|
|
68
|
+
* terminal or other non-seekable source). Returns 0 if it cannot be determined
|
|
69
|
+
*/
|
|
70
|
+
int zsv_file_is_regular(FILE *f);
|
|
71
|
+
|
|
46
72
|
/**
|
|
47
73
|
* Check if a file exists and is readable (with fopen + "rb")
|
|
48
74
|
*
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2021 Liquidaty and the zsv/lib contributors
|
|
3
|
+
* All rights reserved
|
|
4
|
+
*
|
|
5
|
+
* This file is part of zsv/lib, distributed under the license defined at
|
|
6
|
+
* https://opensource.org/licenses/MIT
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
#ifndef ZSV_OS_H
|
|
10
|
+
#define ZSV_OS_H
|
|
11
|
+
|
|
12
|
+
// the macros below expand to fopen()/remove(); a consumer including only this
|
|
13
|
+
// header would otherwise get an implicit declaration
|
|
14
|
+
#include <stdio.h>
|
|
15
|
+
|
|
16
|
+
void zsv_perror(const char *);
|
|
17
|
+
|
|
18
|
+
/*
|
|
19
|
+
* Path encoding on Windows: a path of MAX_PATH bytes or more, or whose absolute
|
|
20
|
+
* form is MAX_PATH UTF-16 units or more, and every path given to
|
|
21
|
+
* zsv_replace_file(), zsv_copy_permissions(), zsv_create_new_file(),
|
|
22
|
+
* zsv_same_file() or zsv_remove(), are read as UTF-8; a shorter path given to
|
|
23
|
+
* the CRT (fopen(), rename(), mkdir()), zsv_fopen() or zsv_dir_exists() is read
|
|
24
|
+
* in the process ANSI code page. zsv's executables make the two agree by setting
|
|
25
|
+
* the ANSI code page to UTF-8 with an application manifest (app/win/utf8.manifest
|
|
26
|
+
* in the zsv sources), which Windows 10 1903 and later honor. A program that
|
|
27
|
+
* links these utilities needs the same manifest for non-ASCII names to work at
|
|
28
|
+
* every length
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* zsv_fopen(): same as normal fopen(), except on Win it also works with long filenames
|
|
33
|
+
*/
|
|
34
|
+
#ifndef _WIN32
|
|
35
|
+
#define zsv_fopen fopen
|
|
36
|
+
#else
|
|
37
|
+
FILE *zsv_fopen(const char *fname, const char *mode);
|
|
38
|
+
// NULL when original_path is empty, short and !always_prefix, not UTF-8, or on error
|
|
39
|
+
char *zsv_ensureLongPathPrefix(const char *original_path, unsigned char always_prefix);
|
|
40
|
+
#endif
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* zsv_mkstemp(): same as normal mkstemp(), which wasi-libc does not have
|
|
44
|
+
* (wasm has no temp directory concept). Creates and opens a file whose name is
|
|
45
|
+
* `tmpl` with its trailing 'X's (at least 6) replaced; `tmpl` is modified in
|
|
46
|
+
* place. Returns an open fd, or -1 with errno set.
|
|
47
|
+
*
|
|
48
|
+
* A function rather than a macro aliasing mkstemp(): glibc hides mkstemp()
|
|
49
|
+
* under -std=cNN, so a macro would leave this header un-self-sufficient for a
|
|
50
|
+
* consumer that has not set a feature-test macro.
|
|
51
|
+
*/
|
|
52
|
+
int zsv_mkstemp(char *tmpl);
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* zsv_remove(): same as normal remove()
|
|
56
|
+
but for files only, and on Win it also works with long filenames
|
|
57
|
+
*/
|
|
58
|
+
#ifndef _WIN32
|
|
59
|
+
#define zsv_remove remove
|
|
60
|
+
#else
|
|
61
|
+
int zsv_remove_winlp(const char *path_utf8);
|
|
62
|
+
#define zsv_remove zsv_remove_winlp
|
|
63
|
+
#endif
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* zsv_replace_file(): rename src over dest, copying across devices if needed.
|
|
67
|
+
* Returns 0, or an errno value that errno is also set to. On Windows both paths
|
|
68
|
+
* are UTF-8 and may exceed MAX_PATH; a path that is not UTF-8 gives EILSEQ
|
|
69
|
+
*/
|
|
70
|
+
int zsv_replace_file(const char *src, const char *dest);
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* zsv_same_file(): whether both paths name the same file, by device and file id, so
|
|
74
|
+
* links and differently-spelled paths match. Returns 1 if they do, 0 if they do not
|
|
75
|
+
* (including when either does not exist), or -1 if that cannot be determined
|
|
76
|
+
*/
|
|
77
|
+
int zsv_same_file(const char *a, const char *b);
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* zsv_copy_permissions(): give file `to` the permission bits of existing file `from`,
|
|
81
|
+
* and on POSIX its group. Where the group cannot be set, `to` gets no more group
|
|
82
|
+
* access than others have, so no other group gains access. On Windows the only bit
|
|
83
|
+
* is the read-only attribute. Use before `to` replaces `from`. Returns 0, or an
|
|
84
|
+
* errno value (on Windows, EILSEQ for a path that is not UTF-8)
|
|
85
|
+
*/
|
|
86
|
+
int zsv_copy_permissions(const char *from, const char *to);
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* zsv_create_new_file(): create an empty file at `path`, which must not exist, with
|
|
90
|
+
* the permissions the system gives a new file (umask, directory defaults). Returns 0,
|
|
91
|
+
* or an errno value (EEXIST if `path` exists; on Windows, EILSEQ for a path that is
|
|
92
|
+
* not UTF-8)
|
|
93
|
+
*/
|
|
94
|
+
int zsv_create_new_file(const char *path);
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* zsv_fsync(): flush a file descriptor's data to storage; 0 on success, else -1
|
|
98
|
+
* with errno set. A function for the reason zsv_mkstemp() is one
|
|
99
|
+
*/
|
|
100
|
+
int zsv_fsync(int fd);
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* zsv_final_path(): the path of the file `path` names after following symbolic
|
|
104
|
+
* links, so that replacing it replaces that file rather than the link. A copy of
|
|
105
|
+
* `path` if it does not exist, or on Windows. Returns heap memory the caller frees,
|
|
106
|
+
* or NULL with errno set (ENOENT for a link to nothing)
|
|
107
|
+
*/
|
|
108
|
+
char *zsv_final_path(const char *path);
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* ZSV_STDIN_IS_TTY(): nonzero when stdin is an interactive terminal
|
|
112
|
+
*/
|
|
113
|
+
#ifndef _WIN32
|
|
114
|
+
#include <unistd.h>
|
|
115
|
+
#define ZSV_STDIN_IS_TTY() isatty(fileno(stdin))
|
|
116
|
+
#else
|
|
117
|
+
#include <io.h>
|
|
118
|
+
#define ZSV_STDIN_IS_TTY() _isatty(_fileno(stdin))
|
|
119
|
+
#endif
|
|
120
|
+
|
|
121
|
+
#ifdef _WIN32
|
|
122
|
+
#include <windows.h>
|
|
123
|
+
|
|
124
|
+
#ifndef ARRAY_SIZE
|
|
125
|
+
#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
|
|
126
|
+
#endif
|
|
127
|
+
|
|
128
|
+
// converts UTF-8 `path` into wbuf, cutting it off at PATH_MAX; wbuf is empty if the path
|
|
129
|
+
// is not UTF-8. For short names such as a DLL's; file paths go through the long-path helpers
|
|
130
|
+
void zsv_win_to_unicode(const void *path, wchar_t *wbuf, size_t wbuf_len);
|
|
131
|
+
|
|
132
|
+
#endif // #ifdef _WIN32
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* get number of cores
|
|
136
|
+
*/
|
|
137
|
+
unsigned int zsv_get_number_of_cores(void);
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* zsv_now_ms(): milliseconds from a monotonic clock, for measuring elapsed time; only
|
|
141
|
+
* differences are meaningful. Returns 0 if the platform clock is unavailable, in which
|
|
142
|
+
* case a caller that compares two readings should treat the difference as unknown
|
|
143
|
+
*/
|
|
144
|
+
unsigned long long zsv_now_ms(void);
|
|
145
|
+
#endif // ZSV_OS_H
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2021 Liquidaty and the zsv/lib contributors
|
|
3
|
+
* All rights reserved
|
|
4
|
+
*
|
|
5
|
+
* This file is part of zsv/lib, distributed under the license defined at
|
|
6
|
+
* https://opensource.org/licenses/MIT
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
#ifndef ZSV_OUTPUT_H
|
|
10
|
+
#define ZSV_OUTPUT_H
|
|
11
|
+
|
|
12
|
+
#include <stdlib.h>
|
|
13
|
+
|
|
14
|
+
enum zsv_output_format {
|
|
15
|
+
zsv_output_format_json = 0,
|
|
16
|
+
zsv_output_format_toon = 1
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/*
|
|
20
|
+
* get_default_output_format(): the output format a command should use when the
|
|
21
|
+
* caller has not explicitly selected one. Returns TOON when the AI_AGENT
|
|
22
|
+
* environment variable is set to a non-blank value (so agents get token-dense
|
|
23
|
+
* TOON by default), otherwise JSON. An explicit command-line format option
|
|
24
|
+
* always overrides this.
|
|
25
|
+
*/
|
|
26
|
+
static inline enum zsv_output_format get_default_output_format(void) {
|
|
27
|
+
const char *e = getenv("AI_AGENT");
|
|
28
|
+
if (e)
|
|
29
|
+
while (*e == ' ' || *e == '\t' || *e == '\r' || *e == '\n')
|
|
30
|
+
e++;
|
|
31
|
+
return e && *e ? zsv_output_format_toon : zsv_output_format_json;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
#endif
|
|
@@ -42,7 +42,7 @@ struct zsv_overwrite_args {
|
|
|
42
42
|
|
|
43
43
|
struct zsv_overwrite *zsv_overwrite_writer_new(struct zsv_overwrite_args *args, struct zsv_overwrite_opts *ctx_opts);
|
|
44
44
|
|
|
45
|
-
void zsv_overwrite_writer_delete();
|
|
45
|
+
void zsv_overwrite_writer_delete(struct zsv_overwrite *data);
|
|
46
46
|
|
|
47
47
|
enum zsv_status zsv_overwrite_writer_add(struct zsv_overwrite *data);
|
|
48
48
|
|
|
@@ -72,15 +72,27 @@ enum zsv_status zsv_properties_parser_destroy(struct zsv_properties_parser *pars
|
|
|
72
72
|
*
|
|
73
73
|
* @param opts parser options. see `zsv_new()`
|
|
74
74
|
* @param cust_prop optional custom file property handler
|
|
75
|
-
* @param input_path path of file whose zsv properties should be loaded
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
75
|
+
* @param input_path path of file whose zsv properties should be loaded
|
|
76
|
+
* (if NULL or "-", opts->stdin_filename, if set, is used in
|
|
77
|
+
* its place). this param is used solely for loading
|
|
78
|
+
* properties and has no impact on the data that is
|
|
79
|
+
* actually parsed, which is determined by opts->stream
|
|
79
80
|
* @param handle_out returns zsv parser handle, or NULL on fail
|
|
80
81
|
*/
|
|
81
82
|
enum zsv_status zsv_new_with_properties(struct zsv_opts *opts, struct zsv_prop_handler *custom_prop,
|
|
82
83
|
const char *input_path, zsv_parser *handle_out);
|
|
83
84
|
|
|
85
|
+
/**
|
|
86
|
+
* zsv_opts_load_properties(): merge into `opts` the saved properties and the
|
|
87
|
+
* extension-implied delimiter for `input_path`, exactly as zsv_new_with_properties()
|
|
88
|
+
* does before it creates the parser. Use it to learn how a file would be parsed.
|
|
89
|
+
* input_path may name a file that does not exist
|
|
90
|
+
*
|
|
91
|
+
* @return zsv_status_ok on success
|
|
92
|
+
*/
|
|
93
|
+
enum zsv_status zsv_opts_load_properties(struct zsv_opts *opts, struct zsv_prop_handler *custom_prop,
|
|
94
|
+
const char *input_path);
|
|
95
|
+
|
|
84
96
|
/**
|
|
85
97
|
* If you are building your own CLI and incorporating zsv CLI commands into it,
|
|
86
98
|
* the `prop` command can be customized by providing your own function
|