zsv 1.3.0
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 +7 -0
- data/CHANGELOG.md +36 -0
- data/LICENSE +21 -0
- data/README.md +311 -0
- data/ext/zsv/common.h +34 -0
- data/ext/zsv/extconf.rb +137 -0
- data/ext/zsv/options.c +126 -0
- data/ext/zsv/options.h +31 -0
- data/ext/zsv/options_internal.h +8 -0
- data/ext/zsv/parser.c +300 -0
- data/ext/zsv/parser.h +62 -0
- data/ext/zsv/row.c +122 -0
- data/ext/zsv/row.h +39 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/2db.c +756 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/2json.c +381 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/2tsv.c +228 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/builtin/help.c +123 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/builtin/license.c +39 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/builtin/register.c +104 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/builtin/thirdparty.c +41 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/builtin/unregister.c +1 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/builtin/version.c +14 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/check/simdutf_wrapper.h +19 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/check/utf8.c +116 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/check.c +194 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/cli.c +796 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/cli_const.h +41 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/cli_export.h +16 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/cli_ini.c +280 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/cli_internal.h +36 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/compare.c +913 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/compare.h +23 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/compare_added_column.c +20 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/compare_internal.h +140 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/compare_sort.c +91 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/compare_unique_colname.c +81 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/count-pull.c +82 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/count.c +404 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/desc.c +569 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/echo.c +365 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/ext_example/my_extension.c +366 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/ext_example/mysheet_extension.c +341 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/ext_template/YOUR_EXTENSION_zsvext.c +263 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/inih/ini.c +298 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/inih/ini.h +157 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/json_numeric.c +177 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/jsonwriter.c +444 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/jsonwriter.h +145 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/utils.c +110 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/memfile-1.0/include/memfile.h +15 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/memfile-1.0/src/memfile.c +64 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sglib/sglib.h +1955 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/simdutf/simdutf.h +6802 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3.c +230517 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3.h +12174 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_and_csv_vtab.c +2 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab-mem.c +142 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab-mem.h +49 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab-zsv.c +485 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab.c +1015 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3ext.h +663 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/vtab_helper.c +85 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_common.h +75 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_gen.h +167 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_parse.h +228 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_tree.h +186 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_version.h +23 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_common.h +76 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_gen.h +167 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_parse.h +238 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_tree.h +186 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl.c +184 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_alloc.c +52 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_alloc.h +34 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_buf.c +103 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_buf.h +57 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_bytestack.h +69 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_encode.c +220 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_encode.h +34 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_gen.c +362 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_lex.c +764 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_lex.h +117 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_parser.c +508 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_parser.h +78 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_tree.c +505 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_version.c +7 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper/json_value.h +59 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper/yajl_helper.h +208 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper.c +795 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper_internal.h +28 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/flatten.c +851 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/jq.c +106 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/jq.h +6 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/mv.c +113 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/noop.c +90 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/overwrite.c +295 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/paste.c +175 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/pretty.c +693 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/prop.c +980 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/rm.c +131 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/select/fixed.c +130 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/select/internal.h +118 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/select/parallel.c +45 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/select/parallel.h +41 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/select/processing.c +107 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/select/rand.c +20 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/select/regex.c +61 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/select/search.c +14 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/select/selection.c +192 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/select/usage.c +72 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/select-pull.c +812 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/select.c +753 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/serialize.c +372 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/curses.h +15 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/cursor.c +119 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/errors.c +45 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/file.c +63 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/file.h +12 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/filter.c +166 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/handlers.c +214 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/handlers_internal.h +128 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/help.c +43 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/index.c +81 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/index.h +25 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/key-bindings.c +325 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/key-bindings.h +73 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/lexer.c +203 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/newline_handler.c +7 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/pivot.c +318 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/procedure.c +134 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/procedure.h +119 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/read-data.c +322 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/screen_buffer.c +203 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/screen_buffer.h +36 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/sheet-sql.c +167 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/sheet_internal.h +36 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/sqlfilter.c +153 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/terminfo.c +32 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/transformation.c +312 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/transformation.h +29 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/ui_buffer.c +266 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/usage.c +9 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/utf8-width.c +60 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet.c +1007 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sql.c +453 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sql_internal.c +101 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/sql_internal.h +49 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/stack.c +393 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/arg.c +322 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/cache.c +228 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/cat.c +91 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/chunk.c +240 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/chunk.h +63 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/clock.c +57 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/db.c +148 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs-no-jq.c +2 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs.c +427 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs_from_json.c +253 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs_to_json.c +121 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/dl.c +20 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/emcc/fs_api.c +159 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/err.c +24 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/file-mem.c +180 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/file.c +256 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/index.c +197 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/index.h +49 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/jq.c +400 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/json.c +120 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/mem.c +18 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/memmem.c +132 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/os.c +178 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/overwrite.c +258 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/overwrite_writer.c +246 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/pcre2-8/pcre2-8-test.c +123 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/pcre2-8/pcre2-8.c +153 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/pcre2-8/pcre2-8.h +54 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/prop.c +267 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/signal.c +53 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/string.c +357 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/dir_exists_longpath.c +83 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/dl.c +33 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/fopen_longpath.c +184 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/foreach_dirent_longpath.c +292 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/io.c +259 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/io.h +13 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/mkdir_longpath.c +255 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/remove_longpath.c +96 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/writer.c +361 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/zsv_command.h +40 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/zsv_command_standalone.c +16 -0
- data/ext/zsv/vendor/zsv-1.3.0/app/zsv_main.h +44 -0
- data/ext/zsv/vendor/zsv-1.3.0/examples/js/zsv_parser_api_dummy.c +3 -0
- data/ext/zsv/vendor/zsv-1.3.0/examples/lib/parse_by_chunk.c +100 -0
- data/ext/zsv/vendor/zsv-1.3.0/examples/lib/print_my_column.c +143 -0
- data/ext/zsv/vendor/zsv-1.3.0/examples/lib/pull.c +89 -0
- data/ext/zsv/vendor/zsv-1.3.0/examples/lib/simple.c +123 -0
- data/ext/zsv/vendor/zsv-1.3.0/fuzz/fuzz.c +16 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/api.h +336 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/common.h +361 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/ext/implementation.h +62 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/ext/implementation_private.h +113 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/ext/sheet.h +73 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/ext.h +329 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/arg.h +90 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/cache.h +49 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/clock.h +36 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/compiler.h +58 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/db.h +19 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/dirs.h +147 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/dl.h +22 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/emcc/fs_api.h +28 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/err.h +22 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/file-mem.h +17 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/file.h +99 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/jq.h +65 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/json.h +19 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/mem.h +19 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/memmem.h +13 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/os.h +54 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/overwrite.h +71 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/overwrite_writer.h +53 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/prop.h +107 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/signal.h +18 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/sql.h +11 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/string.h +148 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/utf8.h +41 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/win/dl.h +25 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/writer.h +101 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/zsv_export.h +33 -0
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv.h +20 -0
- data/ext/zsv/vendor/zsv-1.3.0/src/vector_delim.c +60 -0
- data/ext/zsv/vendor/zsv-1.3.0/src/zsv.c +484 -0
- data/ext/zsv/vendor/zsv-1.3.0/src/zsv_internal.c +731 -0
- data/ext/zsv/vendor/zsv-1.3.0/src/zsv_scan_delim.c +285 -0
- data/ext/zsv/vendor/zsv-1.3.0/src/zsv_scan_fixed.c +88 -0
- data/ext/zsv/vendor/zsv-1.3.0/src/zsv_strencode.c +51 -0
- data/ext/zsv/zsv_ext.c +343 -0
- data/lib/zsv/version.rb +5 -0
- data/lib/zsv.rb +81 -0
- metadata +340 -0
|
@@ -0,0 +1,62 @@
|
|
|
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_EXT_PRIVATE_H
|
|
10
|
+
#define ZSV_EXT_PRIVATE_H
|
|
11
|
+
|
|
12
|
+
#include <zsv/ext.h>
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @file zsv_ext.h
|
|
16
|
+
* @brief ZSV extension implementation specification
|
|
17
|
+
* @defgroup zsv_extension implementation specification
|
|
18
|
+
* @ingroup ZSV
|
|
19
|
+
* @{
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Overridable compiler flag ZSV_EXT=1 indicates that we are compiling a ZSV
|
|
24
|
+
* extension
|
|
25
|
+
*/
|
|
26
|
+
#ifndef ZSV_EXT
|
|
27
|
+
#define ZSV_EXT 1
|
|
28
|
+
#endif
|
|
29
|
+
|
|
30
|
+
ZSV_BEGIN_DECL
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* To build a zsv extension:
|
|
34
|
+
* - implement the following required functions:
|
|
35
|
+
* `zsv_ext_id`
|
|
36
|
+
* `zsv_ext_init`
|
|
37
|
+
* `zsv_ext_main`
|
|
38
|
+
*
|
|
39
|
+
* - optionally, implement the following recommended functions:
|
|
40
|
+
* `zsv_ext_help`
|
|
41
|
+
* `zsv_ext_errstr`
|
|
42
|
+
* `zsv_ext_version`
|
|
43
|
+
* `zsv_ext_license`
|
|
44
|
+
*
|
|
45
|
+
* - on Windows, be sure to decorate your function definitions
|
|
46
|
+
* with ZSV_EXT_EXPORT
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
#ifdef _WIN32
|
|
50
|
+
#define ZSV_EXT_EXPORT __declspec(dllexport)
|
|
51
|
+
#elif __EMSCRIPTEN__
|
|
52
|
+
#include <emscripten.h>
|
|
53
|
+
#define ZSV_EXT_EXPORT EMSCRIPTEN_KEEPALIVE
|
|
54
|
+
#else
|
|
55
|
+
#define ZSV_EXT_EXPORT
|
|
56
|
+
#endif
|
|
57
|
+
|
|
58
|
+
#include "implementation_private.h"
|
|
59
|
+
|
|
60
|
+
/** @} */
|
|
61
|
+
ZSV_END_DECL
|
|
62
|
+
#endif
|
|
@@ -0,0 +1,113 @@
|
|
|
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
|
+
/**
|
|
10
|
+
* @file zsv_ext_private.h
|
|
11
|
+
* @brief ZSV extension implementation specification
|
|
12
|
+
* @defgroup zsv_extension implementation specification
|
|
13
|
+
* @ingroup ZSV
|
|
14
|
+
* @{
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Return a module identifier, which must be a 2-char string
|
|
19
|
+
*
|
|
20
|
+
* Required. Any sub-command that starts with this id followed by a dash
|
|
21
|
+
* will be passed on to this module
|
|
22
|
+
*
|
|
23
|
+
* Your DLL or shared lib filename must correspondingly be "zsvext<id>"
|
|
24
|
+
*
|
|
25
|
+
* For example, to implement sub-commands that begin with "my-":
|
|
26
|
+
* - your function zsv_ext_id() would return "my"
|
|
27
|
+
* - your library would be named zsvextmy.dll (or .so or .dylib)
|
|
28
|
+
*/
|
|
29
|
+
ZSV_EXT_EXPORT
|
|
30
|
+
const char *zsv_ext_id(void);
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Initialize your module
|
|
34
|
+
*
|
|
35
|
+
* Called once, when your library is loaded
|
|
36
|
+
*
|
|
37
|
+
* @param callbacks Pointer to struct holding zsvlib function pointers
|
|
38
|
+
* @return Zero on success, non-zero on fail
|
|
39
|
+
*/
|
|
40
|
+
ZSV_EXT_EXPORT
|
|
41
|
+
enum zsv_ext_status zsv_ext_init(struct zsv_ext_callbacks *callbacks, zsv_execution_context ctx);
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Get your extension's internal error code
|
|
45
|
+
*
|
|
46
|
+
* In the case that any of your module functions return zsv_ext_status_error
|
|
47
|
+
* this function is called to obtain your extension's internal error code
|
|
48
|
+
*
|
|
49
|
+
* @param context Execution context
|
|
50
|
+
* @return Error code
|
|
51
|
+
*/
|
|
52
|
+
ZSV_EXT_EXPORT
|
|
53
|
+
int zsv_ext_errcode(zsv_execution_context context);
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Get an error message
|
|
57
|
+
*
|
|
58
|
+
* In the case that any of your module functions return zsv_ext_status_error,
|
|
59
|
+
* this function is called to obtain the message corresponding to the internal
|
|
60
|
+
* error code returned by zsv_ext_errcode()
|
|
61
|
+
*
|
|
62
|
+
* @param context Execution context
|
|
63
|
+
* @param int Return code from zsv_ext_errcode()
|
|
64
|
+
* @return Error message to display
|
|
65
|
+
*/
|
|
66
|
+
ZSV_EXT_EXPORT
|
|
67
|
+
char *zsv_ext_errstr(zsv_execution_context context, int err);
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Free an error message
|
|
71
|
+
*
|
|
72
|
+
* Called after obtaining any non-NULL result from `zsv_ext_errstr()`
|
|
73
|
+
*
|
|
74
|
+
* @param errstr The string returned from zsv_ext_errstr()
|
|
75
|
+
*/
|
|
76
|
+
ZSV_EXT_EXPORT
|
|
77
|
+
void zsv_ext_errfree(char *errstr);
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Exit your module
|
|
81
|
+
*
|
|
82
|
+
* Called once, when your library is unloaded
|
|
83
|
+
*
|
|
84
|
+
* @return Zero on success, non-zero on fail
|
|
85
|
+
*/
|
|
86
|
+
ZSV_EXT_EXPORT
|
|
87
|
+
enum zsv_ext_status zsv_ext_exit(void);
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Help message. Displayed when user enters any command beginning with
|
|
91
|
+
* `zsv help <module-id>`
|
|
92
|
+
*
|
|
93
|
+
* @param argc Number of arguments
|
|
94
|
+
* @param argv Arguments
|
|
95
|
+
*/
|
|
96
|
+
ZSV_EXT_EXPORT
|
|
97
|
+
const char *const *zsv_ext_help(int argc, const char *argv[]);
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* License message. Displayed when user enters any command beginning with
|
|
101
|
+
* `zsv license <module-id>`
|
|
102
|
+
*
|
|
103
|
+
*/
|
|
104
|
+
ZSV_EXT_EXPORT
|
|
105
|
+
const char *const *zsv_ext_license(void);
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Version message. Displayed when user enters any command beginning with
|
|
109
|
+
* `zsv version <module-id>`
|
|
110
|
+
*
|
|
111
|
+
*/
|
|
112
|
+
ZSV_EXT_EXPORT
|
|
113
|
+
const char *const *zsv_ext_version(void);
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#ifndef ZSVSHEET_H
|
|
2
|
+
#define ZSVSHEET_H
|
|
3
|
+
|
|
4
|
+
/* custom sheet handler id */
|
|
5
|
+
typedef int zsvsheet_proc_id_t;
|
|
6
|
+
|
|
7
|
+
typedef struct zsvsheet_proc_context *zsvsheet_proc_context_t;
|
|
8
|
+
|
|
9
|
+
typedef enum zsvsheet_status {
|
|
10
|
+
zsvsheet_status_ok = 0,
|
|
11
|
+
zsvsheet_status_error,
|
|
12
|
+
zsvsheet_status_ignore,
|
|
13
|
+
zsvsheet_status_duplicate,
|
|
14
|
+
zsvsheet_status_memory,
|
|
15
|
+
zsvsheet_status_exit,
|
|
16
|
+
zsvsheet_status_busy,
|
|
17
|
+
zsvsheet_status_no_data
|
|
18
|
+
} zsvsheet_status;
|
|
19
|
+
|
|
20
|
+
typedef struct zsvsheet_context *zsvsheet_context_t;
|
|
21
|
+
typedef struct zsvsheet_subcommand_context *zsvsheet_subcommand_context_t;
|
|
22
|
+
|
|
23
|
+
typedef void *zsvsheet_buffer_t;
|
|
24
|
+
// int zsvsheet_ext_keypress(zsvsheet_proc_context_t);
|
|
25
|
+
|
|
26
|
+
typedef struct zsvsheet_transformation *zsvsheet_transformation;
|
|
27
|
+
/**
|
|
28
|
+
* Transformation options passed to zsvsheet_push_transformation
|
|
29
|
+
*/
|
|
30
|
+
struct zsvsheet_buffer_transformation_opts {
|
|
31
|
+
/**
|
|
32
|
+
* Caller supplied context; can be retrieved with ext_sheet_transformation_user_context(trn).
|
|
33
|
+
*
|
|
34
|
+
* This is free'd by the library after on_done is called unless it is NULL.
|
|
35
|
+
*/
|
|
36
|
+
void *user_context;
|
|
37
|
+
/**
|
|
38
|
+
* This is called each time a row is parsed and available.
|
|
39
|
+
*
|
|
40
|
+
* It can be used to write out a new row immediately or contribute to a calculation
|
|
41
|
+
* where the partial results are stored in the context.
|
|
42
|
+
*
|
|
43
|
+
* Note that when doing a reduction which does not produce output until the end;
|
|
44
|
+
* it is best to write out a header row in the row_handler and flush the writer. Otherwise the
|
|
45
|
+
* main thread will be blocked waiting for something to display.
|
|
46
|
+
*
|
|
47
|
+
* Once some data has been written to the output file execution is moved to a background thread.
|
|
48
|
+
*
|
|
49
|
+
* The parser can be retrieved with ext_sheet_transformation_parser(trn),
|
|
50
|
+
* the output file writer can be retrieved with ext_sheet_transformation_writer(trn),
|
|
51
|
+
* the context can be retrieved with ext_sheet_transformation_user_context(trn),
|
|
52
|
+
* and so on
|
|
53
|
+
*/
|
|
54
|
+
void (*row_handler)(zsvsheet_transformation trn);
|
|
55
|
+
/**
|
|
56
|
+
* Called when the parser has no more data or was cancelled.
|
|
57
|
+
*
|
|
58
|
+
* This can be used to free resources, complete a calculation or to write out one
|
|
59
|
+
* or more final rows.
|
|
60
|
+
*
|
|
61
|
+
* For small input files this may be executed in the main thread, for larger ones
|
|
62
|
+
* it will be done in a background thread. So if an operation done inside this handler
|
|
63
|
+
* can take a long time even on small inputs then it could block the main thread.
|
|
64
|
+
*/
|
|
65
|
+
void (*on_done)(zsvsheet_transformation trn);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
struct zsvsheet_rowcol {
|
|
69
|
+
size_t row;
|
|
70
|
+
size_t col;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
#endif
|
|
@@ -0,0 +1,329 @@
|
|
|
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_EXT_H
|
|
10
|
+
#define ZSV_EXT_H
|
|
11
|
+
|
|
12
|
+
#define ZSV_EXTENSION_ID_MIN_LEN 2
|
|
13
|
+
#define ZSV_EXTENSION_ID_MAX_LEN 8
|
|
14
|
+
|
|
15
|
+
#include <stdio.h>
|
|
16
|
+
#include <stdint.h>
|
|
17
|
+
#include "common.h"
|
|
18
|
+
#include "ext/sheet.h"
|
|
19
|
+
#include "utils/sql.h"
|
|
20
|
+
#include "utils/prop.h"
|
|
21
|
+
#include "utils/writer.h"
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @file ext.h
|
|
25
|
+
* @brief ZSV extension api, common to zsvlib and any zsv extension
|
|
26
|
+
* @defgroup zsv_extension api
|
|
27
|
+
* @ingroup ZSV
|
|
28
|
+
* @{
|
|
29
|
+
*/
|
|
30
|
+
ZSV_BEGIN_DECL
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Status and error codes for zsv extensions. If a command's `main()` program
|
|
34
|
+
* returns a status other than zsv_ext_status_ok, `zsv_ext_errcode()` will be
|
|
35
|
+
* called and its result used for the final exit code. If it returns
|
|
36
|
+
* zsv_ext_status_error, then furthermore, `zsv_ext_errstr()` will be called
|
|
37
|
+
* and any non-null result displayed as an error message
|
|
38
|
+
*/
|
|
39
|
+
enum zsv_ext_status {
|
|
40
|
+
zsv_ext_status_ok = 0,
|
|
41
|
+
zsv_ext_status_memory,
|
|
42
|
+
zsv_ext_status_unrecognized_cmd,
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* if a zsv_ext function returns zsv_ext_status_error, an error message
|
|
46
|
+
* is generated by calling the module's `zsv_ext_errcode()` and `zsv_ext_errstr()`
|
|
47
|
+
* functions. Otherwise an error string is generated from the zsv_ext_status code
|
|
48
|
+
*/
|
|
49
|
+
zsv_ext_status_error,
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* operation not permitted, such as an extension attempting
|
|
53
|
+
* to modify a buffer that is owned by a different extension
|
|
54
|
+
*/
|
|
55
|
+
zsv_ext_status_not_permitted,
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* zsv_ext_status_other is treated as a silent error by ZSV, e.g. if you have
|
|
59
|
+
* already handled your error and do not want any further error message displayed
|
|
60
|
+
*/
|
|
61
|
+
zsv_ext_status_other
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The context in which any call to your extension is made, used with:
|
|
66
|
+
* `set_ext_context()`
|
|
67
|
+
* `get_ext_context()`
|
|
68
|
+
*/
|
|
69
|
+
typedef void *zsv_execution_context;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Signature of the function called for each implemented sub-command
|
|
73
|
+
*/
|
|
74
|
+
typedef enum zsv_ext_status (*zsv_ext_main)(zsv_execution_context ctx, int argc, const char *argv[],
|
|
75
|
+
struct zsv_opts *opts);
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* ZSV callbacks structure
|
|
79
|
+
*
|
|
80
|
+
* Contains the addresses of the ZSV functions that can be used by custom
|
|
81
|
+
* extensions, and which are passed from ZSV to the extension via the
|
|
82
|
+
* custom `zsv_ext_init()` implementation. See zsv_ext.h for additional
|
|
83
|
+
* extension specifications, or examples/extension.c for an example
|
|
84
|
+
* implementation
|
|
85
|
+
*
|
|
86
|
+
* For a description of each callback, see the corresponding zsv_-prefixed
|
|
87
|
+
* function in zsv.h
|
|
88
|
+
*/
|
|
89
|
+
struct zsvsheet_buffer_data {
|
|
90
|
+
unsigned char has_row_num : 1;
|
|
91
|
+
unsigned char _ : 7;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
typedef uint32_t zsvsheet_cell_attr_t;
|
|
95
|
+
enum zsvsheet_cell_profile_t {
|
|
96
|
+
zsvsheet_cell_attr_profile_none = 0,
|
|
97
|
+
zsvsheet_cell_attr_profile_link,
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
struct zsv_ext_callbacks {
|
|
101
|
+
void (*set_row_handler)(zsv_parser handle, void (*row)(void *ctx));
|
|
102
|
+
void (*set_context)(zsv_parser handle, void *ctx);
|
|
103
|
+
enum zsv_status (*parse_more)(struct zsv_scanner *scanner);
|
|
104
|
+
void (*abort)(struct zsv_scanner *scanner);
|
|
105
|
+
size_t (*cell_count)(zsv_parser parser);
|
|
106
|
+
struct zsv_cell (*get_cell)(zsv_parser parser, size_t ix);
|
|
107
|
+
enum zsv_status (*finish)(zsv_parser);
|
|
108
|
+
enum zsv_status (*delete)(zsv_parser);
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Set or get custom context (e.g. to persist private data between
|
|
112
|
+
* ZSV-initiated calls to your extension)
|
|
113
|
+
*/
|
|
114
|
+
void (*ext_set_context)(zsv_execution_context ctx, void *private_context);
|
|
115
|
+
void *(*ext_get_context)(zsv_execution_context ctx);
|
|
116
|
+
|
|
117
|
+
zsv_parser (*ext_get_parser)(zsv_execution_context ctx);
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* To add an extension command, invoke `ext_add_command`, passing it your command's
|
|
121
|
+
* handler function as a callback with a `zsv_ext_main` signature
|
|
122
|
+
*/
|
|
123
|
+
enum zsv_ext_status (*ext_add_command)(zsv_execution_context ctx, const char *id, const char *help,
|
|
124
|
+
zsv_ext_main main);
|
|
125
|
+
void (*ext_set_help)(zsv_execution_context ctx, const char *help);
|
|
126
|
+
void (*ext_set_license)(zsv_execution_context ctx, const char *license);
|
|
127
|
+
void (*ext_set_thirdparty)(zsv_execution_context ctx, const char *thirdparty[]);
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* fetch options from execution context. used to fetch just the ctx-related parser
|
|
131
|
+
* opts, including any of the below if specified by the user when zsv was invoked:
|
|
132
|
+
* -B,--buff-size <N>
|
|
133
|
+
* -c,--max-column-count <N>
|
|
134
|
+
* -r,--max-row-size <N>
|
|
135
|
+
* -t,--tab-delim
|
|
136
|
+
* -O,--other-delim <C>
|
|
137
|
+
* -q,--no-quote
|
|
138
|
+
* -v,--verbose
|
|
139
|
+
*
|
|
140
|
+
* @param ctx execution context
|
|
141
|
+
* @return option values
|
|
142
|
+
*/
|
|
143
|
+
struct zsv_opts (*ext_parser_opts)(zsv_execution_context ctx);
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* convenience function that calls ext_args_to_opts, allocates parser,
|
|
147
|
+
* sets custom ctx, runs parser, and de-allocates parser
|
|
148
|
+
*/
|
|
149
|
+
enum zsv_ext_status (*ext_parse_all)(zsv_execution_context ctx, void *user_context, void (*row_handler)(void *ctx),
|
|
150
|
+
struct zsv_opts *const custom);
|
|
151
|
+
/**
|
|
152
|
+
* As an alternative to `ext_parse_all()`, for more granular control:
|
|
153
|
+
* ```
|
|
154
|
+
* struct zsv_opts opts = custom ? *custom : zsv_get_default_opts();
|
|
155
|
+
* zsv_parser parser = zsv_new(&opts);
|
|
156
|
+
* if(!parser)
|
|
157
|
+
* stat = zsv_ext_status_memory;
|
|
158
|
+
* else {
|
|
159
|
+
* opts.row = YOUR_COMMAND_rowhandler;
|
|
160
|
+
* // ... set other options ...
|
|
161
|
+
* zsv_parser p = new_with_context(ctx, &opts);
|
|
162
|
+
* while((stat = zsv_parse_more(parser)) == zsv_status_ok) ;
|
|
163
|
+
* if(stat == zsv_status_no_more_input)
|
|
164
|
+
* stat = zsv_finish(p);
|
|
165
|
+
* zsv_delete(p);
|
|
166
|
+
* }
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
|
|
170
|
+
/****************************************
|
|
171
|
+
* Registering a custom `sheet` command *
|
|
172
|
+
****************************************/
|
|
173
|
+
zsvsheet_proc_id_t (*ext_sheet_register_proc)(const char *name, const char *description,
|
|
174
|
+
zsvsheet_status (*handler)(zsvsheet_proc_context_t ctx));
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Bind a command to a key binding
|
|
178
|
+
* TO DO: allow binding of key that already exists; in which case
|
|
179
|
+
* allow handler to act as middleware that can cancel or allow other handlers to be executed
|
|
180
|
+
*
|
|
181
|
+
* @return 0 on success, else error
|
|
182
|
+
*/
|
|
183
|
+
int (*ext_sheet_register_proc_key_binding)(char ch, zsvsheet_proc_id_t proc_id);
|
|
184
|
+
|
|
185
|
+
/*** Custom command prompt ***/
|
|
186
|
+
/**
|
|
187
|
+
* Set the prompt for entering a subcommand
|
|
188
|
+
* @param s text to set the subcommand prompt to. must be < 256 bytes in length
|
|
189
|
+
* returns zsvsheet_status_ok on success
|
|
190
|
+
*/
|
|
191
|
+
zsvsheet_status (*ext_sheet_prompt)(zsvsheet_proc_context_t ctx, char *buffer, size_t bufsz, const char *fmt, ...);
|
|
192
|
+
|
|
193
|
+
/*** Custom command handling ***/
|
|
194
|
+
/**
|
|
195
|
+
* Set a status message
|
|
196
|
+
*/
|
|
197
|
+
zsvsheet_status (*ext_sheet_set_status)(zsvsheet_proc_context_t ctx, const char *fmt, ...);
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Get the key press that triggered this subcommand handler
|
|
201
|
+
*/
|
|
202
|
+
int (*ext_sheet_keypress)(zsvsheet_proc_context_t ctx);
|
|
203
|
+
|
|
204
|
+
/****** Managing buffers ******/
|
|
205
|
+
/**
|
|
206
|
+
* Get the current buffer
|
|
207
|
+
*/
|
|
208
|
+
zsvsheet_buffer_t (*ext_sheet_buffer_current)(zsvsheet_proc_context_t ctx);
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Get the prior buffer
|
|
212
|
+
*/
|
|
213
|
+
zsvsheet_buffer_t (*ext_sheet_buffer_prior)(zsvsheet_buffer_t b);
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Get info about a buffer
|
|
217
|
+
*/
|
|
218
|
+
struct zsvsheet_buffer_data (*ext_sheet_buffer_info)(zsvsheet_buffer_t);
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Get the filename associated with a buffer
|
|
222
|
+
*/
|
|
223
|
+
const char *(*ext_sheet_buffer_filename)(zsvsheet_buffer_t);
|
|
224
|
+
|
|
225
|
+
/**
|
|
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
|
|
228
|
+
*/
|
|
229
|
+
const char *(*ext_sheet_buffer_data_filename)(zsvsheet_buffer_t);
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Get the currently-selected cell
|
|
233
|
+
*/
|
|
234
|
+
zsvsheet_status (*ext_sheet_buffer_get_selected_cell)(zsvsheet_buffer_t, struct zsvsheet_rowcol *);
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Open a tabular file as a new buffer
|
|
238
|
+
*/
|
|
239
|
+
zsvsheet_status (*ext_sheet_open_file)(zsvsheet_proc_context_t, const char *filepath, struct zsv_opts *zopts);
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Set custom context
|
|
243
|
+
* @param on_close optional callback to invoke when the buffer is closed
|
|
244
|
+
*
|
|
245
|
+
* @return zsv_ext_status_ok on success, else zsv_ext_status error code
|
|
246
|
+
*/
|
|
247
|
+
enum zsv_ext_status (*ext_sheet_buffer_set_ctx)(zsvsheet_buffer_t h, void *ctx, void (*on_close)(void *));
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Get custom context previously set via zsvsheet_buffer_set_ctx()
|
|
251
|
+
* @param ctx_out result will be written to this address
|
|
252
|
+
*
|
|
253
|
+
* @return zsv_ext_status_ok on success, else zsv_ext_status error code
|
|
254
|
+
*/
|
|
255
|
+
enum zsv_ext_status (*ext_sheet_buffer_get_ctx)(zsvsheet_buffer_t h, void **ctx_out);
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
*
|
|
259
|
+
*/
|
|
260
|
+
zsvsheet_cell_attr_t (*ext_sheet_cell_profile_attrs)(enum zsvsheet_cell_profile_t);
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Set custom cell attributes
|
|
264
|
+
*/
|
|
265
|
+
void (*ext_sheet_buffer_set_cell_attrs)(zsvsheet_buffer_t h,
|
|
266
|
+
enum zsv_ext_status (*get_cell_attrs)(void *pdh, zsvsheet_cell_attr_t *attrs,
|
|
267
|
+
size_t start_row, size_t row_count,
|
|
268
|
+
size_t cols));
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Set custom handler on Enter key press
|
|
272
|
+
*
|
|
273
|
+
* @return zsv_ext_status_ok on success, else zsv_ext_status error code
|
|
274
|
+
*/
|
|
275
|
+
enum zsv_ext_status (*ext_sheet_buffer_on_newline)(zsvsheet_buffer_t h,
|
|
276
|
+
zsvsheet_status (*on_newline)(zsvsheet_proc_context_t));
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Get zsv_opts used to open the buffer's data file
|
|
280
|
+
*/
|
|
281
|
+
struct zsv_opts (*ext_sheet_buffer_get_zsv_opts)(zsvsheet_buffer_t h);
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* SQLITE3 helpers
|
|
285
|
+
*/
|
|
286
|
+
int (*ext_sqlite3_add_csv)(struct zsv_sqlite3_db *zdb, const char *csv_filename, struct zsv_opts *opts,
|
|
287
|
+
struct zsv_prop_handler *custom_prop_handler);
|
|
288
|
+
void (*ext_sqlite3_db_delete)(zsv_sqlite3_db_t);
|
|
289
|
+
zsv_sqlite3_db_t (*ext_sqlite3_db_new)(struct zsv_sqlite3_dbopts *dbopts);
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Create a new buffer from the current one using a transformation
|
|
293
|
+
* and make the new buffer the current one
|
|
294
|
+
*
|
|
295
|
+
* Note that the transformation is performed in a seperate thread so the user_context
|
|
296
|
+
* must not be a stack variable
|
|
297
|
+
*
|
|
298
|
+
* See struct zsvsheet_buffer_transformation_opts in zsv/ext/sheet.h
|
|
299
|
+
*/
|
|
300
|
+
zsvsheet_status (*ext_sheet_push_transformation)(zsvsheet_proc_context_t ctx,
|
|
301
|
+
struct zsvsheet_buffer_transformation_opts opts);
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Get the writer associated with a transformation.
|
|
305
|
+
*
|
|
306
|
+
* The transformation itself is passed as the context variable to the row handler
|
|
307
|
+
*/
|
|
308
|
+
zsv_csv_writer (*ext_sheet_transformation_writer)(zsvsheet_transformation trn);
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Get the user provided context from the context provided to a transformation row handler
|
|
312
|
+
*/
|
|
313
|
+
void *(*ext_sheet_transformation_user_context)(zsvsheet_transformation trn);
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Get the parser from the context provided to a transformation row handler
|
|
317
|
+
*/
|
|
318
|
+
zsv_parser (*ext_sheet_transformation_parser)(zsvsheet_transformation trn);
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Get the filename that the transformation writer outputs to from the context provided to a transformation row
|
|
322
|
+
* handler.
|
|
323
|
+
*/
|
|
324
|
+
const char *(*ext_sheet_transformation_filename)(zsvsheet_transformation trn);
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
/** @} */
|
|
328
|
+
ZSV_END_DECL
|
|
329
|
+
#endif
|
|
@@ -0,0 +1,90 @@
|
|
|
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_ARG_H
|
|
10
|
+
#define ZSV_ARG_H
|
|
11
|
+
|
|
12
|
+
#include <zsv/common.h>
|
|
13
|
+
|
|
14
|
+
/* havearg(): case-insensitive partial arg matching */
|
|
15
|
+
char havearg(const char *arg, const char *form1, size_t min_len1, const char *form2, size_t min_len2);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* set or get default parser options
|
|
19
|
+
*/
|
|
20
|
+
void zsv_set_default_opts(struct zsv_opts);
|
|
21
|
+
|
|
22
|
+
struct zsv_opts zsv_get_default_opts(void);
|
|
23
|
+
|
|
24
|
+
void zsv_clear_default_opts(void);
|
|
25
|
+
|
|
26
|
+
#ifdef ZSV_EXTRAS
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* set the default option progress callback (e.g. from wasm where `struct zsv_opts`
|
|
30
|
+
* cannot be independently accessed)
|
|
31
|
+
* @param cb callback to call
|
|
32
|
+
* @param ctx pointer passed to callback
|
|
33
|
+
* @param frequency number of rows to parse between progress calls
|
|
34
|
+
*/
|
|
35
|
+
void zsv_set_default_progress_callback(zsv_progress_callback cb, void *ctx, size_t rows_interval,
|
|
36
|
+
unsigned int seconds_interval);
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* set the default option completed callback (e.g. from wasm where `struct zsv_opts`
|
|
40
|
+
* cannot be independently accessed)
|
|
41
|
+
* @param cb callback to call
|
|
42
|
+
* @param ctx pointer passed to callback
|
|
43
|
+
*/
|
|
44
|
+
void zsv_set_default_completed_callback(zsv_completed_callback cb, void *ctx);
|
|
45
|
+
|
|
46
|
+
#endif
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Convert common command-line arguments to zsv_opts
|
|
50
|
+
* Return new argc/argv values with processed args stripped out
|
|
51
|
+
* Initializes opts_out with `zsv_get_default_opts()`, then with
|
|
52
|
+
* the below common options if present:
|
|
53
|
+
* -B,--buff-size <N>
|
|
54
|
+
* -c,--max-column-count <N>
|
|
55
|
+
* -r,--max-row-size <N>
|
|
56
|
+
* -t,--tab-delim
|
|
57
|
+
* -O,--other-delim <C>
|
|
58
|
+
* -q,--no-quote
|
|
59
|
+
* -S,--keep-blank-headers: disable default behavior of ignoring leading blank rows
|
|
60
|
+
* -d,--header-row-span <n>: apply header depth (rowspan) of n
|
|
61
|
+
* -v,--verbose
|
|
62
|
+
*
|
|
63
|
+
* @param argc count of args to process
|
|
64
|
+
* @param argv args to process
|
|
65
|
+
* @param argc_out count of unprocessed args
|
|
66
|
+
* @param argv_out array of unprocessed arg values. Must be allocated by caller
|
|
67
|
+
* with size of at least argc * sizeof(*argv)
|
|
68
|
+
* @param opts_out options, updated to reflect any processed args
|
|
69
|
+
* @return zero on success, non-zero on error
|
|
70
|
+
*/
|
|
71
|
+
enum zsv_status zsv_args_to_opts(int argc, const char *argv[], int *argc_out, const char **argv_out,
|
|
72
|
+
struct zsv_opts *opts_out);
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Fetch the next arg, if it exists, else print an error message
|
|
76
|
+
* The argc_i argument does not need to be valid; it will be checked
|
|
77
|
+
* against argc.
|
|
78
|
+
*
|
|
79
|
+
* Example:
|
|
80
|
+
* const char *value = zsv_next_arg(++arg_i, argc, argv, &err);
|
|
81
|
+
*
|
|
82
|
+
* @param argc_i index of next arg to test
|
|
83
|
+
* @param argc total arg count
|
|
84
|
+
* @param argv args to process
|
|
85
|
+
* @param err return non-zero in the case of error
|
|
86
|
+
* @return next argument, if it exists, else NULL
|
|
87
|
+
*/
|
|
88
|
+
const char *zsv_next_arg(int arg_i, int argc, const char *argv[], int *err);
|
|
89
|
+
|
|
90
|
+
#endif
|