zsv 1.3.0 → 1.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +41 -3
- data/ext/zsv/extconf.rb +66 -49
- data/ext/zsv/options.c +1 -2
- data/ext/zsv/parser.c +14 -0
- data/ext/zsv/zsv_ext.c +3 -0
- data/lib/zsv/version.rb +1 -1
- metadata +6 -226
- data/ext/zsv/vendor/zsv-1.3.0/app/2db.c +0 -756
- data/ext/zsv/vendor/zsv-1.3.0/app/2json.c +0 -381
- data/ext/zsv/vendor/zsv-1.3.0/app/2tsv.c +0 -228
- data/ext/zsv/vendor/zsv-1.3.0/app/builtin/help.c +0 -123
- data/ext/zsv/vendor/zsv-1.3.0/app/builtin/license.c +0 -39
- data/ext/zsv/vendor/zsv-1.3.0/app/builtin/register.c +0 -104
- data/ext/zsv/vendor/zsv-1.3.0/app/builtin/thirdparty.c +0 -41
- data/ext/zsv/vendor/zsv-1.3.0/app/builtin/unregister.c +0 -1
- data/ext/zsv/vendor/zsv-1.3.0/app/builtin/version.c +0 -14
- data/ext/zsv/vendor/zsv-1.3.0/app/check/simdutf_wrapper.h +0 -19
- data/ext/zsv/vendor/zsv-1.3.0/app/check/utf8.c +0 -116
- data/ext/zsv/vendor/zsv-1.3.0/app/check.c +0 -194
- data/ext/zsv/vendor/zsv-1.3.0/app/cli.c +0 -796
- data/ext/zsv/vendor/zsv-1.3.0/app/cli_const.h +0 -41
- data/ext/zsv/vendor/zsv-1.3.0/app/cli_export.h +0 -16
- data/ext/zsv/vendor/zsv-1.3.0/app/cli_ini.c +0 -280
- data/ext/zsv/vendor/zsv-1.3.0/app/cli_internal.h +0 -36
- data/ext/zsv/vendor/zsv-1.3.0/app/compare.c +0 -913
- data/ext/zsv/vendor/zsv-1.3.0/app/compare.h +0 -23
- data/ext/zsv/vendor/zsv-1.3.0/app/compare_added_column.c +0 -20
- data/ext/zsv/vendor/zsv-1.3.0/app/compare_internal.h +0 -140
- data/ext/zsv/vendor/zsv-1.3.0/app/compare_sort.c +0 -91
- data/ext/zsv/vendor/zsv-1.3.0/app/compare_unique_colname.c +0 -81
- data/ext/zsv/vendor/zsv-1.3.0/app/count-pull.c +0 -82
- data/ext/zsv/vendor/zsv-1.3.0/app/count.c +0 -404
- data/ext/zsv/vendor/zsv-1.3.0/app/desc.c +0 -569
- data/ext/zsv/vendor/zsv-1.3.0/app/echo.c +0 -365
- data/ext/zsv/vendor/zsv-1.3.0/app/ext_example/my_extension.c +0 -366
- data/ext/zsv/vendor/zsv-1.3.0/app/ext_example/mysheet_extension.c +0 -341
- data/ext/zsv/vendor/zsv-1.3.0/app/ext_template/YOUR_EXTENSION_zsvext.c +0 -263
- data/ext/zsv/vendor/zsv-1.3.0/app/external/inih/ini.c +0 -298
- data/ext/zsv/vendor/zsv-1.3.0/app/external/inih/ini.h +0 -157
- data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/json_numeric.c +0 -177
- data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/jsonwriter.c +0 -444
- data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/jsonwriter.h +0 -145
- data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/utils.c +0 -110
- data/ext/zsv/vendor/zsv-1.3.0/app/external/memfile-1.0/include/memfile.h +0 -15
- data/ext/zsv/vendor/zsv-1.3.0/app/external/memfile-1.0/src/memfile.c +0 -64
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sglib/sglib.h +0 -1955
- data/ext/zsv/vendor/zsv-1.3.0/app/external/simdutf/simdutf.h +0 -6802
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3.c +0 -230517
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3.h +0 -12174
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_and_csv_vtab.c +0 -2
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab-mem.c +0 -142
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab-mem.h +0 -49
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab-zsv.c +0 -485
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab.c +0 -1015
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3ext.h +0 -663
- data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/vtab_helper.c +0 -85
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_common.h +0 -75
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_gen.h +0 -167
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_parse.h +0 -228
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_tree.h +0 -186
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_version.h +0 -23
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_common.h +0 -76
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_gen.h +0 -167
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_parse.h +0 -238
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_tree.h +0 -186
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl.c +0 -184
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_alloc.c +0 -52
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_alloc.h +0 -34
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_buf.c +0 -103
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_buf.h +0 -57
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_bytestack.h +0 -69
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_encode.c +0 -220
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_encode.h +0 -34
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_gen.c +0 -362
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_lex.c +0 -764
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_lex.h +0 -117
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_parser.c +0 -508
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_parser.h +0 -78
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_tree.c +0 -505
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_version.c +0 -7
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper/json_value.h +0 -59
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper/yajl_helper.h +0 -208
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper.c +0 -795
- data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper_internal.h +0 -28
- data/ext/zsv/vendor/zsv-1.3.0/app/flatten.c +0 -851
- data/ext/zsv/vendor/zsv-1.3.0/app/jq.c +0 -106
- data/ext/zsv/vendor/zsv-1.3.0/app/jq.h +0 -6
- data/ext/zsv/vendor/zsv-1.3.0/app/mv.c +0 -113
- data/ext/zsv/vendor/zsv-1.3.0/app/noop.c +0 -90
- data/ext/zsv/vendor/zsv-1.3.0/app/overwrite.c +0 -295
- data/ext/zsv/vendor/zsv-1.3.0/app/paste.c +0 -175
- data/ext/zsv/vendor/zsv-1.3.0/app/pretty.c +0 -693
- data/ext/zsv/vendor/zsv-1.3.0/app/prop.c +0 -980
- data/ext/zsv/vendor/zsv-1.3.0/app/rm.c +0 -131
- data/ext/zsv/vendor/zsv-1.3.0/app/select/fixed.c +0 -130
- data/ext/zsv/vendor/zsv-1.3.0/app/select/internal.h +0 -118
- data/ext/zsv/vendor/zsv-1.3.0/app/select/parallel.c +0 -45
- data/ext/zsv/vendor/zsv-1.3.0/app/select/parallel.h +0 -41
- data/ext/zsv/vendor/zsv-1.3.0/app/select/processing.c +0 -107
- data/ext/zsv/vendor/zsv-1.3.0/app/select/rand.c +0 -20
- data/ext/zsv/vendor/zsv-1.3.0/app/select/regex.c +0 -61
- data/ext/zsv/vendor/zsv-1.3.0/app/select/search.c +0 -14
- data/ext/zsv/vendor/zsv-1.3.0/app/select/selection.c +0 -192
- data/ext/zsv/vendor/zsv-1.3.0/app/select/usage.c +0 -72
- data/ext/zsv/vendor/zsv-1.3.0/app/select-pull.c +0 -812
- data/ext/zsv/vendor/zsv-1.3.0/app/select.c +0 -753
- data/ext/zsv/vendor/zsv-1.3.0/app/serialize.c +0 -372
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/curses.h +0 -15
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/cursor.c +0 -119
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/errors.c +0 -45
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/file.c +0 -63
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/file.h +0 -12
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/filter.c +0 -166
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/handlers.c +0 -214
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/handlers_internal.h +0 -128
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/help.c +0 -43
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/index.c +0 -81
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/index.h +0 -25
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/key-bindings.c +0 -325
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/key-bindings.h +0 -73
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/lexer.c +0 -203
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/newline_handler.c +0 -7
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/pivot.c +0 -318
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/procedure.c +0 -134
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/procedure.h +0 -119
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/read-data.c +0 -322
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/screen_buffer.c +0 -203
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/screen_buffer.h +0 -36
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/sheet-sql.c +0 -167
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/sheet_internal.h +0 -36
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/sqlfilter.c +0 -153
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/terminfo.c +0 -32
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/transformation.c +0 -312
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/transformation.h +0 -29
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/ui_buffer.c +0 -266
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/usage.c +0 -9
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet/utf8-width.c +0 -60
- data/ext/zsv/vendor/zsv-1.3.0/app/sheet.c +0 -1007
- data/ext/zsv/vendor/zsv-1.3.0/app/sql.c +0 -453
- data/ext/zsv/vendor/zsv-1.3.0/app/sql_internal.c +0 -101
- data/ext/zsv/vendor/zsv-1.3.0/app/sql_internal.h +0 -49
- data/ext/zsv/vendor/zsv-1.3.0/app/stack.c +0 -393
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/arg.c +0 -322
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/cache.c +0 -228
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/cat.c +0 -91
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/chunk.c +0 -240
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/chunk.h +0 -63
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/clock.c +0 -57
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/db.c +0 -148
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs-no-jq.c +0 -2
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs.c +0 -427
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs_from_json.c +0 -253
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs_to_json.c +0 -121
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/dl.c +0 -20
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/emcc/fs_api.c +0 -159
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/err.c +0 -24
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/file-mem.c +0 -180
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/file.c +0 -256
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/index.c +0 -197
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/index.h +0 -49
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/jq.c +0 -400
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/json.c +0 -120
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/mem.c +0 -18
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/memmem.c +0 -132
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/os.c +0 -178
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/overwrite.c +0 -258
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/overwrite_writer.c +0 -246
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/pcre2-8/pcre2-8-test.c +0 -123
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/pcre2-8/pcre2-8.c +0 -153
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/pcre2-8/pcre2-8.h +0 -54
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/prop.c +0 -267
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/signal.c +0 -53
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/string.c +0 -357
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/dir_exists_longpath.c +0 -83
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/dl.c +0 -33
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/fopen_longpath.c +0 -184
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/foreach_dirent_longpath.c +0 -292
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/io.c +0 -259
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/io.h +0 -13
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/mkdir_longpath.c +0 -255
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/remove_longpath.c +0 -96
- data/ext/zsv/vendor/zsv-1.3.0/app/utils/writer.c +0 -361
- data/ext/zsv/vendor/zsv-1.3.0/app/zsv_command.h +0 -40
- data/ext/zsv/vendor/zsv-1.3.0/app/zsv_command_standalone.c +0 -16
- data/ext/zsv/vendor/zsv-1.3.0/app/zsv_main.h +0 -44
- data/ext/zsv/vendor/zsv-1.3.0/examples/js/zsv_parser_api_dummy.c +0 -3
- data/ext/zsv/vendor/zsv-1.3.0/examples/lib/parse_by_chunk.c +0 -100
- data/ext/zsv/vendor/zsv-1.3.0/examples/lib/print_my_column.c +0 -143
- data/ext/zsv/vendor/zsv-1.3.0/examples/lib/pull.c +0 -89
- data/ext/zsv/vendor/zsv-1.3.0/examples/lib/simple.c +0 -123
- data/ext/zsv/vendor/zsv-1.3.0/fuzz/fuzz.c +0 -16
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/api.h +0 -336
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/common.h +0 -361
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/ext/implementation.h +0 -62
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/ext/implementation_private.h +0 -113
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/ext/sheet.h +0 -73
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/ext.h +0 -329
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/arg.h +0 -90
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/cache.h +0 -49
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/clock.h +0 -36
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/compiler.h +0 -58
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/db.h +0 -19
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/dirs.h +0 -147
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/dl.h +0 -22
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/emcc/fs_api.h +0 -28
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/err.h +0 -22
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/file-mem.h +0 -17
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/file.h +0 -99
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/jq.h +0 -65
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/json.h +0 -19
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/mem.h +0 -19
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/memmem.h +0 -13
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/os.h +0 -54
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/overwrite.h +0 -71
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/overwrite_writer.h +0 -53
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/prop.h +0 -107
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/signal.h +0 -18
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/sql.h +0 -11
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/string.h +0 -148
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/utf8.h +0 -41
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/win/dl.h +0 -25
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/writer.h +0 -101
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv/zsv_export.h +0 -33
- data/ext/zsv/vendor/zsv-1.3.0/include/zsv.h +0 -20
- data/ext/zsv/vendor/zsv-1.3.0/src/vector_delim.c +0 -60
- data/ext/zsv/vendor/zsv-1.3.0/src/zsv.c +0 -484
- data/ext/zsv/vendor/zsv-1.3.0/src/zsv_internal.c +0 -731
- data/ext/zsv/vendor/zsv-1.3.0/src/zsv_scan_delim.c +0 -285
- data/ext/zsv/vendor/zsv-1.3.0/src/zsv_scan_fixed.c +0 -88
- data/ext/zsv/vendor/zsv-1.3.0/src/zsv_strencode.c +0 -51
|
@@ -1,175 +0,0 @@
|
|
|
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 <stdio.h>
|
|
10
|
-
#include <string.h>
|
|
11
|
-
#include <stdlib.h>
|
|
12
|
-
#include <zsv/utils/writer.h>
|
|
13
|
-
|
|
14
|
-
#define ZSV_COMMAND paste
|
|
15
|
-
#include "zsv_command.h"
|
|
16
|
-
|
|
17
|
-
static int zsv_paste_usage(void) {
|
|
18
|
-
static const char *usage[] = {
|
|
19
|
-
"Usage: paste <filename> [<filename> ...]",
|
|
20
|
-
"",
|
|
21
|
-
"Horizontally paste two tables together: given inputs X, Y, ... of N rows",
|
|
22
|
-
"outputs 1...N rows, where each row i contains:",
|
|
23
|
-
" row i of input X,",
|
|
24
|
-
" followed by row i of input Y,",
|
|
25
|
-
" [followed by ...]",
|
|
26
|
-
"",
|
|
27
|
-
"Options:",
|
|
28
|
-
" -h,--help : show usage",
|
|
29
|
-
NULL,
|
|
30
|
-
};
|
|
31
|
-
for (size_t i = 0; usage[i]; i++)
|
|
32
|
-
printf("%s\n", usage[i]);
|
|
33
|
-
return 0;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
struct zsv_paste_input_file {
|
|
37
|
-
struct zsv_paste_input_file *next;
|
|
38
|
-
const char *fname;
|
|
39
|
-
struct zsv_opts opts;
|
|
40
|
-
FILE *f;
|
|
41
|
-
unsigned col_count;
|
|
42
|
-
zsv_parser parser;
|
|
43
|
-
enum zsv_status zsv_status; // parser status
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
enum zsv_paste_status {
|
|
47
|
-
zsv_paste_status_ok = 0,
|
|
48
|
-
zsv_paste_status_file,
|
|
49
|
-
zsv_paste_status_memory,
|
|
50
|
-
zsv_paste_status_error
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
// zsv_paste_load_row: return number of inputs that a row was retrieved from
|
|
54
|
-
static int zsv_paste_load_row(struct zsv_paste_input_file *inputs) {
|
|
55
|
-
int have_row = 0;
|
|
56
|
-
for (struct zsv_paste_input_file *pf = inputs; pf; pf = pf->next) {
|
|
57
|
-
if (pf->zsv_status == zsv_status_row) {
|
|
58
|
-
pf->zsv_status = zsv_next_row(pf->parser);
|
|
59
|
-
if (pf->zsv_status == zsv_status_row)
|
|
60
|
-
have_row++;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return have_row;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
static void zsv_paste_print_row(zsv_csv_writer w, struct zsv_paste_input_file *inputs) {
|
|
67
|
-
char first = 1;
|
|
68
|
-
for (struct zsv_paste_input_file *pf = inputs; pf; pf = pf->next) {
|
|
69
|
-
unsigned int j = pf->zsv_status == zsv_status_row ? zsv_cell_count(pf->parser) : 0;
|
|
70
|
-
unsigned int k = pf->col_count;
|
|
71
|
-
|
|
72
|
-
for (unsigned int i = 0; i < j && i < k; i++) {
|
|
73
|
-
struct zsv_cell cell = zsv_get_cell(pf->parser, i);
|
|
74
|
-
zsv_writer_cell(w, first, cell.str, cell.len, cell.quoted);
|
|
75
|
-
first = 0;
|
|
76
|
-
}
|
|
77
|
-
for (unsigned int i = j; i < k; i++) {
|
|
78
|
-
zsv_writer_cell(w, first, (const unsigned char *)"", 0, 0);
|
|
79
|
-
first = 0;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
static void zsv_paste_delete_input(struct zsv_paste_input_file *pf) {
|
|
85
|
-
if (pf->parser)
|
|
86
|
-
zsv_delete(pf->parser);
|
|
87
|
-
if (pf->opts.stream)
|
|
88
|
-
fclose(pf->opts.stream);
|
|
89
|
-
free(pf);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// zsv_paste_add_input(): return error
|
|
93
|
-
static enum zsv_paste_status zsv_paste_add_input(const char *fname, struct zsv_paste_input_file **next,
|
|
94
|
-
struct zsv_paste_input_file ***next_next, struct zsv_opts *opts,
|
|
95
|
-
struct zsv_prop_handler *custom_prop_handler) {
|
|
96
|
-
FILE *f = fopen(fname, "rb");
|
|
97
|
-
if (!f) {
|
|
98
|
-
perror(fname);
|
|
99
|
-
return zsv_paste_status_file;
|
|
100
|
-
}
|
|
101
|
-
struct zsv_paste_input_file *pf = calloc(1, sizeof(*pf));
|
|
102
|
-
if (!pf) {
|
|
103
|
-
fclose(f);
|
|
104
|
-
return zsv_paste_status_memory;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
pf->opts = *opts;
|
|
108
|
-
pf->opts.stream = f;
|
|
109
|
-
pf->fname = fname;
|
|
110
|
-
*next = pf;
|
|
111
|
-
*next_next = &pf->next;
|
|
112
|
-
|
|
113
|
-
if (zsv_new_with_properties(&pf->opts, custom_prop_handler, fname, &pf->parser) != zsv_status_ok) {
|
|
114
|
-
fprintf(stderr, "Unable to initialize parser for %s\n", fname);
|
|
115
|
-
return zsv_paste_status_error;
|
|
116
|
-
} else {
|
|
117
|
-
if ((pf->zsv_status = zsv_next_row(pf->parser)) == zsv_status_row)
|
|
118
|
-
pf->col_count = zsv_cell_count(pf->parser);
|
|
119
|
-
else
|
|
120
|
-
fprintf(stderr, "Warning: no data read from %s\n", fname);
|
|
121
|
-
}
|
|
122
|
-
return zsv_paste_status_ok;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
int ZSV_MAIN_FUNC(ZSV_COMMAND)(int argc, const char *argv[], struct zsv_opts *opts,
|
|
126
|
-
struct zsv_prop_handler *custom_prop_handler) {
|
|
127
|
-
for (int i = 1; i < argc; i++) {
|
|
128
|
-
const char *arg = argv[i];
|
|
129
|
-
if (!strcmp(arg, "-h") || !strcmp(arg, "--help"))
|
|
130
|
-
return zsv_paste_usage();
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
struct zsv_paste_input_file *inputs = NULL;
|
|
134
|
-
struct zsv_paste_input_file **next_input = &inputs;
|
|
135
|
-
enum zsv_paste_status status = zsv_paste_status_ok;
|
|
136
|
-
struct zsv_csv_writer_options writer_opts = zsv_writer_get_default_opts();
|
|
137
|
-
zsv_csv_writer writer = zsv_writer_new(&writer_opts);
|
|
138
|
-
if (!writer) {
|
|
139
|
-
status = zsv_printerr(zsv_paste_status_error, "Unable to create csv writer");
|
|
140
|
-
goto zsv_paste_done;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
for (int i = 1; status == zsv_paste_status_ok && i < argc; i++) {
|
|
144
|
-
const char *arg = argv[i];
|
|
145
|
-
if (!(!strcmp(arg, "-h") || !strcmp(arg, "--help")))
|
|
146
|
-
status = zsv_paste_add_input(arg, next_input, &next_input, opts, custom_prop_handler);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (status == zsv_paste_status_ok) {
|
|
150
|
-
if (!inputs) {
|
|
151
|
-
fprintf(stderr, "Please specify at least one input file\n");
|
|
152
|
-
status = zsv_paste_status_error;
|
|
153
|
-
goto zsv_paste_done;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// print headers
|
|
157
|
-
zsv_paste_print_row(writer, inputs);
|
|
158
|
-
|
|
159
|
-
// print one row at a time
|
|
160
|
-
while (zsv_paste_load_row(inputs))
|
|
161
|
-
zsv_paste_print_row(writer, inputs);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
zsv_paste_done:
|
|
165
|
-
for (struct zsv_paste_input_file *next, *pf = inputs; pf; pf = next) {
|
|
166
|
-
next = pf->next;
|
|
167
|
-
zsv_paste_delete_input(pf);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
if (opts->stream && opts->stream != stdin)
|
|
171
|
-
fclose(opts->stream);
|
|
172
|
-
|
|
173
|
-
zsv_writer_delete(writer);
|
|
174
|
-
return status;
|
|
175
|
-
}
|