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,192 @@
|
|
|
1
|
+
static enum zsv_select_column_index_selection_type zsv_select_column_index_selection(const unsigned char *arg,
|
|
2
|
+
unsigned *lo, unsigned *hi);
|
|
3
|
+
|
|
4
|
+
static inline void zsv_select_add_exclusion(struct zsv_select_data *data, const char *name) {
|
|
5
|
+
if (data->exclusion_count < MAX_EXCLUSIONS)
|
|
6
|
+
data->exclusions[data->exclusion_count++] = (const unsigned char *)name;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
static inline unsigned char *zsv_select_get_header_name(struct zsv_select_data *data, unsigned in_ix) {
|
|
10
|
+
if (in_ix < data->header_name_count)
|
|
11
|
+
return data->header_names[in_ix];
|
|
12
|
+
return NULL;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
static inline char zsv_select_excluded_current_header_name(struct zsv_select_data *data, unsigned in_ix) {
|
|
16
|
+
if (data->exclusion_count) {
|
|
17
|
+
if (data->use_header_indexes) {
|
|
18
|
+
for (unsigned int ix = 0; ix < data->exclusion_count; ix++) {
|
|
19
|
+
unsigned i, j;
|
|
20
|
+
switch (zsv_select_column_index_selection(data->exclusions[ix], &i, &j)) {
|
|
21
|
+
case zsv_select_column_index_selection_type_none:
|
|
22
|
+
// not expected!
|
|
23
|
+
break;
|
|
24
|
+
case zsv_select_column_index_selection_type_single:
|
|
25
|
+
if (in_ix + 1 == i)
|
|
26
|
+
return 1;
|
|
27
|
+
break;
|
|
28
|
+
case zsv_select_column_index_selection_type_range:
|
|
29
|
+
if (i <= in_ix + 1 && in_ix + 1 <= j)
|
|
30
|
+
return 1;
|
|
31
|
+
break;
|
|
32
|
+
case zsv_select_column_index_selection_type_lower_bounded:
|
|
33
|
+
if (i <= in_ix + 1)
|
|
34
|
+
return 1;
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
unsigned char *header_name = zsv_select_get_header_name(data, in_ix);
|
|
40
|
+
if (header_name) {
|
|
41
|
+
for (unsigned int i = 0; i < data->exclusion_count; i++)
|
|
42
|
+
if (!zsv_stricmp(header_name, data->exclusions[i]))
|
|
43
|
+
return 1;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// zsv_select_find_header(): return 1-based index, or 0 if not found
|
|
51
|
+
static int zsv_select_find_header(struct zsv_select_data *data, const unsigned char *header_name) {
|
|
52
|
+
if (header_name) {
|
|
53
|
+
for (unsigned int i = 0; i < data->output_cols_count; i++) {
|
|
54
|
+
unsigned char *prior_header_name = zsv_select_get_header_name(data, data->out2in[i].ix);
|
|
55
|
+
if (prior_header_name && !zsv_stricmp(header_name, prior_header_name))
|
|
56
|
+
return i + 1;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return 0;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
static int zsv_select_add_output_col(struct zsv_select_data *data, unsigned in_ix) {
|
|
63
|
+
int err = 0;
|
|
64
|
+
if (data->output_cols_count < data->opts->max_columns) {
|
|
65
|
+
int found = zsv_select_find_header(data, zsv_select_get_header_name(data, in_ix));
|
|
66
|
+
if (data->distinct && found) {
|
|
67
|
+
if (data->distinct == ZSV_SELECT_DISTINCT_MERGE) {
|
|
68
|
+
// add this index
|
|
69
|
+
struct zsv_select_uint_list *ix = calloc(1, sizeof(*ix));
|
|
70
|
+
if (!ix)
|
|
71
|
+
err = zsv_printerr(1, "Out of memory!\n");
|
|
72
|
+
else {
|
|
73
|
+
ix->value = in_ix;
|
|
74
|
+
if (!data->out2in[found - 1].merge.indexes)
|
|
75
|
+
data->out2in[found - 1].merge.indexes = ix;
|
|
76
|
+
else
|
|
77
|
+
*data->out2in[found - 1].merge.last_index = ix;
|
|
78
|
+
data->out2in[found - 1].merge.last_index = &ix->next;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return err;
|
|
82
|
+
}
|
|
83
|
+
if (zsv_select_excluded_current_header_name(data, in_ix))
|
|
84
|
+
return err;
|
|
85
|
+
data->out2in[data->output_cols_count++].ix = in_ix;
|
|
86
|
+
}
|
|
87
|
+
return err;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// not very fast, but we don't need it to be
|
|
91
|
+
static inline unsigned int str_array_ifind(const unsigned char *needle, unsigned char *haystack[], unsigned hay_count) {
|
|
92
|
+
for (unsigned int i = 0; i < hay_count; i++) {
|
|
93
|
+
if (!(needle && *needle) && !(haystack[i] && *haystack[i]))
|
|
94
|
+
return i + 1;
|
|
95
|
+
if (!(needle && *needle && haystack[i] && *haystack[i]))
|
|
96
|
+
continue;
|
|
97
|
+
if (!zsv_stricmp(needle, haystack[i]))
|
|
98
|
+
return i + 1;
|
|
99
|
+
}
|
|
100
|
+
return 0;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
static int zsv_select_set_output_columns(struct zsv_select_data *data) {
|
|
104
|
+
int err = 0;
|
|
105
|
+
unsigned int header_name_count = data->header_name_count;
|
|
106
|
+
if (!data->col_argc) {
|
|
107
|
+
for (unsigned int i = 0; !err && i < header_name_count; i++)
|
|
108
|
+
err = zsv_select_add_output_col(data, i);
|
|
109
|
+
} else if (data->use_header_indexes) {
|
|
110
|
+
for (int arg_i = 0; !err && arg_i < data->col_argc; arg_i++) {
|
|
111
|
+
const char *arg = data->col_argv[arg_i];
|
|
112
|
+
unsigned i, j;
|
|
113
|
+
switch (zsv_select_column_index_selection((const unsigned char *)arg, &i, &j)) {
|
|
114
|
+
case zsv_select_column_index_selection_type_none:
|
|
115
|
+
zsv_printerr(1, "Invalid column index: %s", arg);
|
|
116
|
+
err = -1;
|
|
117
|
+
break;
|
|
118
|
+
case zsv_select_column_index_selection_type_single:
|
|
119
|
+
err = zsv_select_add_output_col(data, i - 1);
|
|
120
|
+
break;
|
|
121
|
+
case zsv_select_column_index_selection_type_range:
|
|
122
|
+
while (i <= j && i < data->opts->max_columns) {
|
|
123
|
+
err = zsv_select_add_output_col(data, i - 1);
|
|
124
|
+
i++;
|
|
125
|
+
}
|
|
126
|
+
break;
|
|
127
|
+
case zsv_select_column_index_selection_type_lower_bounded:
|
|
128
|
+
if (i) {
|
|
129
|
+
for (unsigned int k = i - 1; !err && k < header_name_count; k++)
|
|
130
|
+
err = zsv_select_add_output_col(data, k);
|
|
131
|
+
}
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
} else { // using header names
|
|
136
|
+
for (int arg_i = 0; !err && arg_i < data->col_argc; arg_i++) {
|
|
137
|
+
// find the location of the matching header name, if any
|
|
138
|
+
unsigned int in_pos =
|
|
139
|
+
str_array_ifind((const unsigned char *)data->col_argv[arg_i], data->header_names, header_name_count);
|
|
140
|
+
if (!in_pos) {
|
|
141
|
+
fprintf(stderr, "Column %s not found\n", data->col_argv[arg_i]);
|
|
142
|
+
err = -1;
|
|
143
|
+
} else
|
|
144
|
+
err = zsv_select_add_output_col(data, in_pos - 1);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return err;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
static enum zsv_select_column_index_selection_type zsv_select_column_index_selection(const unsigned char *arg,
|
|
151
|
+
unsigned *lo, unsigned *hi) {
|
|
152
|
+
enum zsv_select_column_index_selection_type result = zsv_select_column_index_selection_type_none;
|
|
153
|
+
|
|
154
|
+
unsigned int i = 0;
|
|
155
|
+
unsigned int j = 0;
|
|
156
|
+
int n = 0;
|
|
157
|
+
int k = sscanf((const char *)arg, "%u-%u%n", &i, &j, &n);
|
|
158
|
+
if (k == 2) {
|
|
159
|
+
if (n >= 0 && (size_t)n == strlen((const char *)arg) && i > 0 && j >= i)
|
|
160
|
+
result = zsv_select_column_index_selection_type_range;
|
|
161
|
+
} else {
|
|
162
|
+
k = sscanf((const char *)arg, "%u%n", &i, &n);
|
|
163
|
+
if (k == 1 && n >= 0 && (size_t)n == strlen((const char *)arg)) {
|
|
164
|
+
if (i > 0)
|
|
165
|
+
result = zsv_select_column_index_selection_type_single;
|
|
166
|
+
} else {
|
|
167
|
+
k = sscanf((const char *)arg, "%u-%n", &i, &n);
|
|
168
|
+
if (k == 1 && n >= 0 && (size_t)n == strlen((const char *)arg)) {
|
|
169
|
+
if (i > 0) {
|
|
170
|
+
result = zsv_select_column_index_selection_type_lower_bounded;
|
|
171
|
+
j = 0;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (lo)
|
|
177
|
+
*lo = i;
|
|
178
|
+
if (hi)
|
|
179
|
+
*hi = j;
|
|
180
|
+
return result;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// zsv_select_check_exclusions_are_indexes(): return err
|
|
184
|
+
static int zsv_select_check_exclusions_are_indexes(struct zsv_select_data *data) {
|
|
185
|
+
int err = 0;
|
|
186
|
+
for (unsigned int e = 0; e < data->exclusion_count; e++) {
|
|
187
|
+
const unsigned char *arg = data->exclusions[e];
|
|
188
|
+
if (zsv_select_column_index_selection(arg, NULL, NULL) == zsv_select_column_index_selection_type_none)
|
|
189
|
+
err = zsv_printerr(1, "Invalid column index: %s", arg);
|
|
190
|
+
}
|
|
191
|
+
return err;
|
|
192
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
const char *zsv_select_usage_msg[] = {
|
|
2
|
+
APPNAME ": extracts and outputs specified columns",
|
|
3
|
+
"",
|
|
4
|
+
"Usage: " APPNAME " [filename] [options] [-- col_specifier [... col_specifier]]",
|
|
5
|
+
" where col_specifier is a column name or, if the -n option is used,",
|
|
6
|
+
" a column index (starting at 1) or index range in the form of n-m",
|
|
7
|
+
" e.g. " APPNAME " -n file.csv -- 1 4-6 50 10",
|
|
8
|
+
" " APPNAME " file.csv -- first_col fiftieth_column \"Tenth Column\"",
|
|
9
|
+
"",
|
|
10
|
+
"Note: Outputs the columns specified after '--' separator, or all columns if omitted.",
|
|
11
|
+
"",
|
|
12
|
+
"Options:",
|
|
13
|
+
" -b,--with-bom : output with BOM",
|
|
14
|
+
" --fixed <offset1,offset2,..> : parse as fixed-width text; use given CSV list of positive integers for",
|
|
15
|
+
" cell and indexes",
|
|
16
|
+
" --fixed-auto : parse as fixed-width text; derive widths from first row in input data (max 256k)",
|
|
17
|
+
" assumes ASCII whitespace; multi-byte whitespace is not counted as whitespace",
|
|
18
|
+
" --fixed-auto-max-lines : maximum number of lines to use in calculating fixed widths",
|
|
19
|
+
#ifndef ZSV_CLI
|
|
20
|
+
" -v,--verbose : verbose output",
|
|
21
|
+
#endif
|
|
22
|
+
" -H,--head <n> : (head) only process the first n rows of input data (including header)",
|
|
23
|
+
" --skip-data <n> : skip the specified number of data rows",
|
|
24
|
+
" --no-header : do not output header row",
|
|
25
|
+
" --prepend-header <value> : prepend each column header with the given text <value>",
|
|
26
|
+
" -s,--search <value> : only output rows with at least one cell containing <value>",
|
|
27
|
+
#ifdef HAVE_PCRE2_8
|
|
28
|
+
" --regex-search <pattern> : only output rows with at least one cell matching the given regex pattern",
|
|
29
|
+
#endif
|
|
30
|
+
// TO DO: " -s,--search /<pattern>/modifiers: search on regex pattern; modifiers include 'g' (global) and 'i'
|
|
31
|
+
// (case-insensitive)",
|
|
32
|
+
" --sample-every <num_of_rows> : output a sample consisting of the first row, then every nth row",
|
|
33
|
+
" --sample-pct <percentage> : output a randomly-selected sample (32 bits of randomness) of n%% of input rows",
|
|
34
|
+
" --distinct : skip subsequent occurrences of columns with the same name",
|
|
35
|
+
" --merge : merge subsequent occurrences of columns with the same name",
|
|
36
|
+
" outputting first non-null value",
|
|
37
|
+
// --rename: like distinct, but instead of removing cols with dupe names, renames them, trying _<n> for n up to max
|
|
38
|
+
// cols
|
|
39
|
+
" -e <embedded_lineend_char> : char to replace embedded lineend. If left empty, embedded lineends are preserved.",
|
|
40
|
+
" If the provided string begins with 0x, it will be interpreted as the hex",
|
|
41
|
+
" representation of a string.",
|
|
42
|
+
" -x <column> : exclude the indicated column. can be specified more than once",
|
|
43
|
+
" -N,--line-number : prefix each row with the row number",
|
|
44
|
+
" -n : provided column indexes are numbers corresponding to column positions",
|
|
45
|
+
" (starting with 1), instead of names",
|
|
46
|
+
#ifndef ZSV_CLI
|
|
47
|
+
" -T : input is tab-delimited, instead of comma-delimited",
|
|
48
|
+
" -O,--other-delim <delim> : input is delimited with the given char",
|
|
49
|
+
" Note: This option does not support quoted values with embedded delimiters.",
|
|
50
|
+
#endif
|
|
51
|
+
" --unescape : escape any backslash-escaped input e.g. \\t, \\n, \\r such as output from `2tsv`",
|
|
52
|
+
" -w,--whitespace-clean : normalize all whitespace to space or newline, single-char (non-consecutive)",
|
|
53
|
+
" occurrences",
|
|
54
|
+
" --whitespace-clean-no-newline: clean whitespace and remove embedded newlines",
|
|
55
|
+
" -W,--no-trim : do not trim whitespace",
|
|
56
|
+
#ifndef ZSV_CLI
|
|
57
|
+
" -C <max_num_of_columns> : defaults to " ZSV_SELECT_MAX_COLS_DEFAULT_S,
|
|
58
|
+
" -L,--max-row-size <n> : set the maximum memory used for a single row",
|
|
59
|
+
" Default: " ZSV_ROW_MAX_SIZE_MIN_S " (min), " ZSV_ROW_MAX_SIZE_DEFAULT_S " (max)",
|
|
60
|
+
#endif
|
|
61
|
+
#ifndef ZSV_NO_PARALLEL
|
|
62
|
+
" -j,--jobs <N> : parallelize using N threads",
|
|
63
|
+
" --parallel : parallelize using a number of threads equal to the number of cores",
|
|
64
|
+
#endif
|
|
65
|
+
" -o <filename> : filename to save output to",
|
|
66
|
+
NULL,
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
static void zsv_select_usage(void) {
|
|
70
|
+
for (size_t i = 0; zsv_select_usage_msg[i]; i++)
|
|
71
|
+
fprintf(stdout, "%s\n", zsv_select_usage_msg[i]);
|
|
72
|
+
}
|