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,41 @@
|
|
|
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 CLI_LICENSE_H
|
|
10
|
+
#define CLI_LICENSE_H
|
|
11
|
+
|
|
12
|
+
// clang-format off
|
|
13
|
+
|
|
14
|
+
const char *zsv_license_text_MIT =
|
|
15
|
+
"Permission is hereby granted, free of charge, to any person obtaining a copy of\n"
|
|
16
|
+
"this software and associated documentation files (the \"Software\"), to deal in\n"
|
|
17
|
+
"the Software without restriction, including without limitation the rights to\n"
|
|
18
|
+
"use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\n"
|
|
19
|
+
"of the Software, and to permit persons to whom the Software is furnished to do\n"
|
|
20
|
+
"so, subject to the following conditions:\n"
|
|
21
|
+
"\n"
|
|
22
|
+
"The above copyright notice and this permission notice shall be included in all\n"
|
|
23
|
+
"copies or substantial portions of the Software.\n"
|
|
24
|
+
"\n"
|
|
25
|
+
"THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n"
|
|
26
|
+
"IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n"
|
|
27
|
+
"FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n"
|
|
28
|
+
"AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n"
|
|
29
|
+
"LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n"
|
|
30
|
+
"OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n"
|
|
31
|
+
"SOFTWARE.\n"
|
|
32
|
+
;
|
|
33
|
+
|
|
34
|
+
// clang-format on
|
|
35
|
+
|
|
36
|
+
const char *zsv_thirdparty[] = {
|
|
37
|
+
"See https://github.com/liquidaty/zsv/blob/main/misc/THIRDPARTY.md",
|
|
38
|
+
NULL,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
#endif
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#ifndef ZSV_CLI_EXPORT_H
|
|
2
|
+
#define ZSV_CLI_EXPORT_H
|
|
3
|
+
|
|
4
|
+
#ifdef __EMSCRIPTEN__
|
|
5
|
+
#include <emscripten.h>
|
|
6
|
+
#define ZSV_CLI_EXPORT EMSCRIPTEN_KEEPALIVE
|
|
7
|
+
#ifndef NO_PLAYGROUND
|
|
8
|
+
#define ZSV_CLI_MAIN main
|
|
9
|
+
#else
|
|
10
|
+
#define ZSV_CLI_MAIN zsv
|
|
11
|
+
#endif
|
|
12
|
+
#else
|
|
13
|
+
#define ZSV_CLI_EXPORT
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
#endif
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2021 Liquidaty and zsv contributors. All rights reserved.
|
|
3
|
+
* This file is part of zsv/lib, distributed under the license defined at
|
|
4
|
+
* https://opensource.org/licenses/MIT
|
|
5
|
+
*/
|
|
6
|
+
#include <errno.h>
|
|
7
|
+
#include <zsv/utils/string.h>
|
|
8
|
+
#include <zsv/utils/os.h>
|
|
9
|
+
#include <zsv/utils/file.h>
|
|
10
|
+
#include <zsv/utils/dirs.h>
|
|
11
|
+
#include <zsv/utils/mem.h>
|
|
12
|
+
|
|
13
|
+
#define INI_HANDLER_LINENO 1
|
|
14
|
+
#define INI_CALL_HANDLER_ON_NEW_SECTION 1
|
|
15
|
+
#include <ini.h>
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* PREFIX is compile-time option specifying where init data will reside
|
|
19
|
+
* on *x operating systems, when building from source, this should be
|
|
20
|
+
* "/usr/local". For packaged distributions, this should be ""
|
|
21
|
+
* on Windows, this should be either LOCALAPPDATA or APPDATA
|
|
22
|
+
*/
|
|
23
|
+
#ifndef PREFIX
|
|
24
|
+
#if defined(_WIN32)
|
|
25
|
+
#define PREFIX "LOCALAPPDATA"
|
|
26
|
+
#elif defined(__EMSCRIPTEN__)
|
|
27
|
+
#define PREFIX "/tmp"
|
|
28
|
+
#else
|
|
29
|
+
#define PREFIX "/usr/local"
|
|
30
|
+
#endif
|
|
31
|
+
#endif
|
|
32
|
+
|
|
33
|
+
static void write_extension_config(struct zsv_ext *ext, FILE *f) {
|
|
34
|
+
fprintf(f, "[%s]\n\n", ext->id);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// config_save: return error
|
|
38
|
+
static int config_save(struct cli_config *config) {
|
|
39
|
+
const char *config_filepath = NULL;
|
|
40
|
+
if (*config->filepath)
|
|
41
|
+
config_filepath = config->filepath;
|
|
42
|
+
if (*config->home_filepath) {
|
|
43
|
+
if (config_filepath) {
|
|
44
|
+
fprintf(stderr, "config_save: only home or global config filepath should exist, but got both\n");
|
|
45
|
+
return 1;
|
|
46
|
+
}
|
|
47
|
+
config_filepath = config->home_filepath;
|
|
48
|
+
}
|
|
49
|
+
if (!config_filepath) {
|
|
50
|
+
fprintf(stderr, "config_save: no home or global filepath found\n");
|
|
51
|
+
return 1;
|
|
52
|
+
}
|
|
53
|
+
int err = 1;
|
|
54
|
+
char *tmp = zsv_get_temp_filename("zsv_config_XXXXXXXX");
|
|
55
|
+
if (!tmp)
|
|
56
|
+
fprintf(stderr, "Out of memory!\n");
|
|
57
|
+
else {
|
|
58
|
+
FILE *f = fopen(tmp, "wb");
|
|
59
|
+
if (!f)
|
|
60
|
+
perror(tmp);
|
|
61
|
+
else {
|
|
62
|
+
for (struct zsv_ext *ext = config->extensions; ext; ext = ext->next)
|
|
63
|
+
write_extension_config(ext, f);
|
|
64
|
+
fclose(f);
|
|
65
|
+
if ((err = zsv_replace_file(tmp, config_filepath)))
|
|
66
|
+
perror(config_filepath);
|
|
67
|
+
else if (config_filepath != config->home_filepath) {
|
|
68
|
+
// try to change permissions to allow anyone to read
|
|
69
|
+
mode_t new_permissions = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
|
|
70
|
+
if (chmod(config_filepath, new_permissions) != 0) {
|
|
71
|
+
; // maybe handle error here
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
free(tmp);
|
|
76
|
+
}
|
|
77
|
+
return err;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
static enum zsv_ext_status zsv_ext_delete(struct zsv_ext *ext);
|
|
81
|
+
|
|
82
|
+
static int remove_extension(struct zsv_ext **list, struct zsv_ext *element) {
|
|
83
|
+
char found = 1;
|
|
84
|
+
for (; *list; list = &(*list)->next) {
|
|
85
|
+
if (*list == element) {
|
|
86
|
+
*list = element->next;
|
|
87
|
+
found = 1;
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (found) {
|
|
92
|
+
element->next = NULL;
|
|
93
|
+
return zsv_ext_delete(element);
|
|
94
|
+
}
|
|
95
|
+
return 1;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
static struct zsv_ext *find_extension(struct cli_config *config, const char *id) {
|
|
99
|
+
for (struct zsv_ext *ext = config ? config->extensions : NULL; ext; ext = ext->next)
|
|
100
|
+
if (!zsv_stricmp((const unsigned char *)ext->id, (const unsigned char *)id))
|
|
101
|
+
return ext;
|
|
102
|
+
return NULL;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
static char extension_id_ok(const unsigned char *id) {
|
|
106
|
+
for (int i = 0; id[i]; i++)
|
|
107
|
+
if (!((id[i] >= 'a' && id[i] <= 'z') || (id[i] >= '0' && id[i] <= '9')))
|
|
108
|
+
return 0;
|
|
109
|
+
return 1;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// load an extension
|
|
113
|
+
static struct zsv_ext *load_extension_dl(const unsigned char *extension_id, char verbose) {
|
|
114
|
+
char *extension_name;
|
|
115
|
+
struct zsv_ext *ext = NULL;
|
|
116
|
+
asprintf(&extension_name, "zsvext%s.%s", extension_id, DL_SUFFIX);
|
|
117
|
+
if (!extension_name)
|
|
118
|
+
fprintf(stderr, "Out of memory!\n");
|
|
119
|
+
else if ((ext = zsv_ext_new(extension_name, (const char *)extension_id, verbose))) {
|
|
120
|
+
if (verbose && ext->dl)
|
|
121
|
+
fprintf(stderr, "Loaded extension %s\n", extension_name);
|
|
122
|
+
free(extension_name);
|
|
123
|
+
}
|
|
124
|
+
return ext;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// load an extension and if successful, add to config->extensions head
|
|
128
|
+
static int add_extension(const char *id, struct zsv_ext **exts, char ignore_err, char verbose) {
|
|
129
|
+
int err = 0;
|
|
130
|
+
const char *dash = strchr(id, '-');
|
|
131
|
+
unsigned char *extension_id = NULL;
|
|
132
|
+
size_t len;
|
|
133
|
+
if (dash)
|
|
134
|
+
len = dash - id;
|
|
135
|
+
else
|
|
136
|
+
len = strlen(id);
|
|
137
|
+
extension_id = zsv_strtolowercase((const unsigned char *)id, &len);
|
|
138
|
+
if (extension_id && len) {
|
|
139
|
+
struct zsv_ext *ext = NULL;
|
|
140
|
+
if (!extension_id_ok(extension_id))
|
|
141
|
+
fprintf(stderr, "Invalid extension id: %s\n", extension_id), err = 1;
|
|
142
|
+
else if (!(ext = load_extension_dl(extension_id, verbose)))
|
|
143
|
+
fprintf(stderr, "Unexpected error loading extension %s\n", extension_id);
|
|
144
|
+
else {
|
|
145
|
+
if (!ignore_err && !(ext && ext->ok)) {
|
|
146
|
+
fprintf(stderr, "Invalid extension: %s\n", extension_id), err = 1;
|
|
147
|
+
zsv_ext_delete(ext);
|
|
148
|
+
} else {
|
|
149
|
+
ext->next = *exts;
|
|
150
|
+
*exts = ext;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
free(extension_id);
|
|
155
|
+
return err;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
static int config_ini_handler(void *ctx, const char *section, const char *name, const char *value, int lineno) {
|
|
159
|
+
int err = 0;
|
|
160
|
+
struct cli_config *config = ctx;
|
|
161
|
+
if (section) {
|
|
162
|
+
if (!name && !value) { // initialize section
|
|
163
|
+
if (zsv_stricmp((const unsigned char *)section, (const unsigned char *)"default")) {
|
|
164
|
+
if (!(strlen(section) >= ZSV_EXTENSION_ID_MIN_LEN && strlen(section) <= ZSV_EXTENSION_ID_MAX_LEN)) {
|
|
165
|
+
fprintf(stderr, "Invalid extension id: %s. Length must be between %i and %i\n", section,
|
|
166
|
+
ZSV_EXTENSION_ID_MIN_LEN, ZSV_EXTENSION_ID_MAX_LEN);
|
|
167
|
+
err = 1;
|
|
168
|
+
} else {
|
|
169
|
+
struct zsv_ext *ext = find_extension(config, section);
|
|
170
|
+
if (!ext && add_extension(section, &config->extensions, 1, config->verbose)) {
|
|
171
|
+
if (config->err_if_not_found) {
|
|
172
|
+
err = 1;
|
|
173
|
+
fprintf(stderr, "At line %i in %s\n", lineno, config->current_filepath);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return err ? 0 : 1;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// get_config_file(): return non-zero on success
|
|
184
|
+
static size_t get_ini_file(char *buff, size_t buffsize, char global) {
|
|
185
|
+
size_t len = 0;
|
|
186
|
+
int n = 0;
|
|
187
|
+
if (global) {
|
|
188
|
+
len = zsv_get_config_dir(buff, buffsize, PREFIX);
|
|
189
|
+
if (len > 0)
|
|
190
|
+
n = snprintf(buff + len, buffsize - len, "%czsv", FILESLASH);
|
|
191
|
+
} else {
|
|
192
|
+
n = zsv_get_home_dir(buff, buffsize);
|
|
193
|
+
if (n > 0 && (size_t)n < buffsize) {
|
|
194
|
+
len = (size_t)n;
|
|
195
|
+
n = snprintf(buff + len, buffsize - len, "%c.config%czsv", FILESLASH, FILESLASH);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (len > 0) {
|
|
199
|
+
if (n > 0 && (size_t)n + len < buffsize)
|
|
200
|
+
len += (size_t)n;
|
|
201
|
+
else
|
|
202
|
+
len = 0;
|
|
203
|
+
}
|
|
204
|
+
if (len && buffsize > len) {
|
|
205
|
+
int dir_exists = zsv_dir_exists(buff);
|
|
206
|
+
if (!dir_exists) {
|
|
207
|
+
if (zsv_mkdirs(buff, 0)) // unable to create the config file parent dir
|
|
208
|
+
perror(buff);
|
|
209
|
+
else if (global) {
|
|
210
|
+
dir_exists = 1;
|
|
211
|
+
// try to make dir read-only for all
|
|
212
|
+
// Set permissions to rwxr-xr-x (0755)
|
|
213
|
+
mode_t new_permissions = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
|
|
214
|
+
chmod(buff, new_permissions); // to do: maybe handle error?
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (dir_exists) {
|
|
218
|
+
n = snprintf(buff + len, buffsize - len, "%czsv.ini", FILESLASH);
|
|
219
|
+
if (n > 0 && (size_t)n + len < buffsize)
|
|
220
|
+
return len + (size_t)n;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return 0;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
static int parse_extensions_ini_file(struct cli_config *config, const char *path, int *opened_count) {
|
|
227
|
+
int err = 0;
|
|
228
|
+
if (path && *path) {
|
|
229
|
+
FILE *f = fopen(path, "r");
|
|
230
|
+
if (!f)
|
|
231
|
+
err = errno;
|
|
232
|
+
else {
|
|
233
|
+
(*opened_count)++;
|
|
234
|
+
config->current_filepath = path;
|
|
235
|
+
err = ini_parse_file(f, config_ini_handler, config);
|
|
236
|
+
fclose(f);
|
|
237
|
+
if (err > 0)
|
|
238
|
+
fprintf(stderr, "Error parsing %s on line %i\n", config->current_filepath, err);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return err;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// parse_extensions_ini: return -2 (unexpected), -1 (file open), 0 (success), > 0 (line number)
|
|
245
|
+
static int parse_extensions_ini(struct cli_config *config, char err_if_not_found, char verbose) {
|
|
246
|
+
int err = 0;
|
|
247
|
+
int opened_config_files = 0;
|
|
248
|
+
char old_err_if_not_found = config->err_if_not_found;
|
|
249
|
+
char old_verbose = config->verbose;
|
|
250
|
+
config->err_if_not_found = err_if_not_found;
|
|
251
|
+
config->verbose = verbose;
|
|
252
|
+
parse_extensions_ini_file(config, config->home_filepath, &opened_config_files);
|
|
253
|
+
parse_extensions_ini_file(config, config->filepath, &opened_config_files);
|
|
254
|
+
if (err_if_not_found && opened_config_files == 0) {
|
|
255
|
+
err = -1;
|
|
256
|
+
fprintf(stderr, "No extensions configured%s%s%s%s\n", verbose ? " or file(s) not found:\n " : "",
|
|
257
|
+
verbose ? config->home_filepath : "", verbose ? "\n " : "", verbose ? config->filepath : "");
|
|
258
|
+
}
|
|
259
|
+
config->err_if_not_found = old_err_if_not_found;
|
|
260
|
+
config->verbose = old_verbose;
|
|
261
|
+
return err;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
static struct zsv_ext_command *ext_command_new(const char *id, const char *help,
|
|
265
|
+
enum zsv_ext_status (*extmain)(zsv_execution_context ctx, int argc,
|
|
266
|
+
const char *argv[], struct zsv_opts *)) {
|
|
267
|
+
struct zsv_ext_command *cmd = calloc(1, sizeof(*cmd));
|
|
268
|
+
cmd->id = strdup(id ? id : "");
|
|
269
|
+
cmd->help = help ? strdup(help) : NULL;
|
|
270
|
+
cmd->main = extmain;
|
|
271
|
+
return cmd;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
static void ext_command_delete(struct zsv_ext_command *cmd) {
|
|
275
|
+
if (cmd) {
|
|
276
|
+
free(cmd->id);
|
|
277
|
+
free(cmd->help);
|
|
278
|
+
free(cmd);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
#include <zsv.h>
|
|
10
|
+
struct zsv_ext_command {
|
|
11
|
+
struct zsv_ext_command *next;
|
|
12
|
+
char *id;
|
|
13
|
+
char *help;
|
|
14
|
+
zsv_ext_main main;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
struct zsv_ext {
|
|
18
|
+
struct zsv_ext *next;
|
|
19
|
+
void *dl;
|
|
20
|
+
char *id;
|
|
21
|
+
char ok;
|
|
22
|
+
char *help;
|
|
23
|
+
char *license;
|
|
24
|
+
char *thirdparty;
|
|
25
|
+
struct zsv_ext_command *commands;
|
|
26
|
+
struct zsv_ext_command **commands_next;
|
|
27
|
+
#define zsv_init_started 1
|
|
28
|
+
#define zsv_init_ok 2
|
|
29
|
+
char inited;
|
|
30
|
+
struct {
|
|
31
|
+
#include "cli_internal.h.in"
|
|
32
|
+
} module;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
static int zsv_unload_custom_cmds(struct zsv_ext *ext);
|
|
36
|
+
static enum zsv_ext_status zsv_ext_delete(struct zsv_ext *ext);
|