zsv 1.3.1 → 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.
Files changed (229) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -0
  3. data/README.md +41 -3
  4. data/ext/zsv/extconf.rb +1 -1
  5. data/lib/zsv/version.rb +1 -1
  6. metadata +6 -226
  7. data/ext/zsv/vendor/zsv-1.3.0/app/2db.c +0 -756
  8. data/ext/zsv/vendor/zsv-1.3.0/app/2json.c +0 -381
  9. data/ext/zsv/vendor/zsv-1.3.0/app/2tsv.c +0 -228
  10. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/help.c +0 -123
  11. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/license.c +0 -39
  12. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/register.c +0 -104
  13. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/thirdparty.c +0 -41
  14. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/unregister.c +0 -1
  15. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/version.c +0 -14
  16. data/ext/zsv/vendor/zsv-1.3.0/app/check/simdutf_wrapper.h +0 -19
  17. data/ext/zsv/vendor/zsv-1.3.0/app/check/utf8.c +0 -116
  18. data/ext/zsv/vendor/zsv-1.3.0/app/check.c +0 -194
  19. data/ext/zsv/vendor/zsv-1.3.0/app/cli.c +0 -796
  20. data/ext/zsv/vendor/zsv-1.3.0/app/cli_const.h +0 -41
  21. data/ext/zsv/vendor/zsv-1.3.0/app/cli_export.h +0 -16
  22. data/ext/zsv/vendor/zsv-1.3.0/app/cli_ini.c +0 -280
  23. data/ext/zsv/vendor/zsv-1.3.0/app/cli_internal.h +0 -36
  24. data/ext/zsv/vendor/zsv-1.3.0/app/compare.c +0 -913
  25. data/ext/zsv/vendor/zsv-1.3.0/app/compare.h +0 -23
  26. data/ext/zsv/vendor/zsv-1.3.0/app/compare_added_column.c +0 -20
  27. data/ext/zsv/vendor/zsv-1.3.0/app/compare_internal.h +0 -140
  28. data/ext/zsv/vendor/zsv-1.3.0/app/compare_sort.c +0 -91
  29. data/ext/zsv/vendor/zsv-1.3.0/app/compare_unique_colname.c +0 -81
  30. data/ext/zsv/vendor/zsv-1.3.0/app/count-pull.c +0 -82
  31. data/ext/zsv/vendor/zsv-1.3.0/app/count.c +0 -404
  32. data/ext/zsv/vendor/zsv-1.3.0/app/desc.c +0 -569
  33. data/ext/zsv/vendor/zsv-1.3.0/app/echo.c +0 -365
  34. data/ext/zsv/vendor/zsv-1.3.0/app/ext_example/my_extension.c +0 -366
  35. data/ext/zsv/vendor/zsv-1.3.0/app/ext_example/mysheet_extension.c +0 -341
  36. data/ext/zsv/vendor/zsv-1.3.0/app/ext_template/YOUR_EXTENSION_zsvext.c +0 -263
  37. data/ext/zsv/vendor/zsv-1.3.0/app/external/inih/ini.c +0 -298
  38. data/ext/zsv/vendor/zsv-1.3.0/app/external/inih/ini.h +0 -157
  39. data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/json_numeric.c +0 -177
  40. data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/jsonwriter.c +0 -444
  41. data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/jsonwriter.h +0 -145
  42. data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/utils.c +0 -110
  43. data/ext/zsv/vendor/zsv-1.3.0/app/external/memfile-1.0/include/memfile.h +0 -15
  44. data/ext/zsv/vendor/zsv-1.3.0/app/external/memfile-1.0/src/memfile.c +0 -64
  45. data/ext/zsv/vendor/zsv-1.3.0/app/external/sglib/sglib.h +0 -1955
  46. data/ext/zsv/vendor/zsv-1.3.0/app/external/simdutf/simdutf.h +0 -6802
  47. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3.c +0 -230517
  48. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3.h +0 -12174
  49. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_and_csv_vtab.c +0 -2
  50. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab-mem.c +0 -142
  51. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab-mem.h +0 -49
  52. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab-zsv.c +0 -485
  53. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab.c +0 -1015
  54. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3ext.h +0 -663
  55. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/vtab_helper.c +0 -85
  56. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_common.h +0 -75
  57. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_gen.h +0 -167
  58. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_parse.h +0 -228
  59. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_tree.h +0 -186
  60. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_version.h +0 -23
  61. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_common.h +0 -76
  62. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_gen.h +0 -167
  63. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_parse.h +0 -238
  64. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_tree.h +0 -186
  65. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl.c +0 -184
  66. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_alloc.c +0 -52
  67. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_alloc.h +0 -34
  68. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_buf.c +0 -103
  69. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_buf.h +0 -57
  70. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_bytestack.h +0 -69
  71. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_encode.c +0 -220
  72. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_encode.h +0 -34
  73. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_gen.c +0 -362
  74. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_lex.c +0 -764
  75. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_lex.h +0 -117
  76. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_parser.c +0 -508
  77. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_parser.h +0 -78
  78. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_tree.c +0 -505
  79. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_version.c +0 -7
  80. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper/json_value.h +0 -59
  81. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper/yajl_helper.h +0 -208
  82. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper.c +0 -795
  83. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper_internal.h +0 -28
  84. data/ext/zsv/vendor/zsv-1.3.0/app/flatten.c +0 -851
  85. data/ext/zsv/vendor/zsv-1.3.0/app/jq.c +0 -106
  86. data/ext/zsv/vendor/zsv-1.3.0/app/jq.h +0 -6
  87. data/ext/zsv/vendor/zsv-1.3.0/app/mv.c +0 -113
  88. data/ext/zsv/vendor/zsv-1.3.0/app/noop.c +0 -90
  89. data/ext/zsv/vendor/zsv-1.3.0/app/overwrite.c +0 -295
  90. data/ext/zsv/vendor/zsv-1.3.0/app/paste.c +0 -175
  91. data/ext/zsv/vendor/zsv-1.3.0/app/pretty.c +0 -693
  92. data/ext/zsv/vendor/zsv-1.3.0/app/prop.c +0 -980
  93. data/ext/zsv/vendor/zsv-1.3.0/app/rm.c +0 -131
  94. data/ext/zsv/vendor/zsv-1.3.0/app/select/fixed.c +0 -130
  95. data/ext/zsv/vendor/zsv-1.3.0/app/select/internal.h +0 -118
  96. data/ext/zsv/vendor/zsv-1.3.0/app/select/parallel.c +0 -45
  97. data/ext/zsv/vendor/zsv-1.3.0/app/select/parallel.h +0 -41
  98. data/ext/zsv/vendor/zsv-1.3.0/app/select/processing.c +0 -107
  99. data/ext/zsv/vendor/zsv-1.3.0/app/select/rand.c +0 -20
  100. data/ext/zsv/vendor/zsv-1.3.0/app/select/regex.c +0 -61
  101. data/ext/zsv/vendor/zsv-1.3.0/app/select/search.c +0 -14
  102. data/ext/zsv/vendor/zsv-1.3.0/app/select/selection.c +0 -192
  103. data/ext/zsv/vendor/zsv-1.3.0/app/select/usage.c +0 -72
  104. data/ext/zsv/vendor/zsv-1.3.0/app/select-pull.c +0 -812
  105. data/ext/zsv/vendor/zsv-1.3.0/app/select.c +0 -753
  106. data/ext/zsv/vendor/zsv-1.3.0/app/serialize.c +0 -372
  107. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/curses.h +0 -15
  108. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/cursor.c +0 -119
  109. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/errors.c +0 -45
  110. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/file.c +0 -63
  111. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/file.h +0 -12
  112. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/filter.c +0 -166
  113. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/handlers.c +0 -214
  114. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/handlers_internal.h +0 -128
  115. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/help.c +0 -43
  116. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/index.c +0 -81
  117. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/index.h +0 -25
  118. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/key-bindings.c +0 -325
  119. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/key-bindings.h +0 -73
  120. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/lexer.c +0 -203
  121. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/newline_handler.c +0 -7
  122. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/pivot.c +0 -318
  123. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/procedure.c +0 -134
  124. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/procedure.h +0 -119
  125. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/read-data.c +0 -322
  126. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/screen_buffer.c +0 -203
  127. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/screen_buffer.h +0 -36
  128. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/sheet-sql.c +0 -167
  129. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/sheet_internal.h +0 -36
  130. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/sqlfilter.c +0 -153
  131. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/terminfo.c +0 -32
  132. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/transformation.c +0 -312
  133. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/transformation.h +0 -29
  134. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/ui_buffer.c +0 -266
  135. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/usage.c +0 -9
  136. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/utf8-width.c +0 -60
  137. data/ext/zsv/vendor/zsv-1.3.0/app/sheet.c +0 -1007
  138. data/ext/zsv/vendor/zsv-1.3.0/app/sql.c +0 -453
  139. data/ext/zsv/vendor/zsv-1.3.0/app/sql_internal.c +0 -101
  140. data/ext/zsv/vendor/zsv-1.3.0/app/sql_internal.h +0 -49
  141. data/ext/zsv/vendor/zsv-1.3.0/app/stack.c +0 -393
  142. data/ext/zsv/vendor/zsv-1.3.0/app/utils/arg.c +0 -322
  143. data/ext/zsv/vendor/zsv-1.3.0/app/utils/cache.c +0 -228
  144. data/ext/zsv/vendor/zsv-1.3.0/app/utils/cat.c +0 -91
  145. data/ext/zsv/vendor/zsv-1.3.0/app/utils/chunk.c +0 -240
  146. data/ext/zsv/vendor/zsv-1.3.0/app/utils/chunk.h +0 -63
  147. data/ext/zsv/vendor/zsv-1.3.0/app/utils/clock.c +0 -57
  148. data/ext/zsv/vendor/zsv-1.3.0/app/utils/db.c +0 -148
  149. data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs-no-jq.c +0 -2
  150. data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs.c +0 -427
  151. data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs_from_json.c +0 -253
  152. data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs_to_json.c +0 -121
  153. data/ext/zsv/vendor/zsv-1.3.0/app/utils/dl.c +0 -20
  154. data/ext/zsv/vendor/zsv-1.3.0/app/utils/emcc/fs_api.c +0 -159
  155. data/ext/zsv/vendor/zsv-1.3.0/app/utils/err.c +0 -24
  156. data/ext/zsv/vendor/zsv-1.3.0/app/utils/file-mem.c +0 -180
  157. data/ext/zsv/vendor/zsv-1.3.0/app/utils/file.c +0 -256
  158. data/ext/zsv/vendor/zsv-1.3.0/app/utils/index.c +0 -197
  159. data/ext/zsv/vendor/zsv-1.3.0/app/utils/index.h +0 -49
  160. data/ext/zsv/vendor/zsv-1.3.0/app/utils/jq.c +0 -400
  161. data/ext/zsv/vendor/zsv-1.3.0/app/utils/json.c +0 -120
  162. data/ext/zsv/vendor/zsv-1.3.0/app/utils/mem.c +0 -18
  163. data/ext/zsv/vendor/zsv-1.3.0/app/utils/memmem.c +0 -132
  164. data/ext/zsv/vendor/zsv-1.3.0/app/utils/os.c +0 -178
  165. data/ext/zsv/vendor/zsv-1.3.0/app/utils/overwrite.c +0 -258
  166. data/ext/zsv/vendor/zsv-1.3.0/app/utils/overwrite_writer.c +0 -246
  167. data/ext/zsv/vendor/zsv-1.3.0/app/utils/pcre2-8/pcre2-8-test.c +0 -123
  168. data/ext/zsv/vendor/zsv-1.3.0/app/utils/pcre2-8/pcre2-8.c +0 -153
  169. data/ext/zsv/vendor/zsv-1.3.0/app/utils/pcre2-8/pcre2-8.h +0 -54
  170. data/ext/zsv/vendor/zsv-1.3.0/app/utils/prop.c +0 -267
  171. data/ext/zsv/vendor/zsv-1.3.0/app/utils/signal.c +0 -53
  172. data/ext/zsv/vendor/zsv-1.3.0/app/utils/string.c +0 -357
  173. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/dir_exists_longpath.c +0 -83
  174. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/dl.c +0 -33
  175. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/fopen_longpath.c +0 -184
  176. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/foreach_dirent_longpath.c +0 -292
  177. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/io.c +0 -259
  178. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/io.h +0 -13
  179. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/mkdir_longpath.c +0 -255
  180. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/remove_longpath.c +0 -96
  181. data/ext/zsv/vendor/zsv-1.3.0/app/utils/writer.c +0 -361
  182. data/ext/zsv/vendor/zsv-1.3.0/app/zsv_command.h +0 -40
  183. data/ext/zsv/vendor/zsv-1.3.0/app/zsv_command_standalone.c +0 -16
  184. data/ext/zsv/vendor/zsv-1.3.0/app/zsv_main.h +0 -44
  185. data/ext/zsv/vendor/zsv-1.3.0/examples/js/zsv_parser_api_dummy.c +0 -3
  186. data/ext/zsv/vendor/zsv-1.3.0/examples/lib/parse_by_chunk.c +0 -100
  187. data/ext/zsv/vendor/zsv-1.3.0/examples/lib/print_my_column.c +0 -143
  188. data/ext/zsv/vendor/zsv-1.3.0/examples/lib/pull.c +0 -89
  189. data/ext/zsv/vendor/zsv-1.3.0/examples/lib/simple.c +0 -123
  190. data/ext/zsv/vendor/zsv-1.3.0/fuzz/fuzz.c +0 -16
  191. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/api.h +0 -336
  192. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/common.h +0 -361
  193. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/ext/implementation.h +0 -62
  194. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/ext/implementation_private.h +0 -113
  195. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/ext/sheet.h +0 -73
  196. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/ext.h +0 -329
  197. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/arg.h +0 -90
  198. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/cache.h +0 -49
  199. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/clock.h +0 -36
  200. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/compiler.h +0 -58
  201. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/db.h +0 -19
  202. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/dirs.h +0 -147
  203. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/dl.h +0 -22
  204. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/emcc/fs_api.h +0 -28
  205. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/err.h +0 -22
  206. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/file-mem.h +0 -17
  207. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/file.h +0 -99
  208. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/jq.h +0 -65
  209. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/json.h +0 -19
  210. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/mem.h +0 -19
  211. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/memmem.h +0 -13
  212. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/os.h +0 -54
  213. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/overwrite.h +0 -71
  214. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/overwrite_writer.h +0 -53
  215. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/prop.h +0 -107
  216. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/signal.h +0 -18
  217. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/sql.h +0 -11
  218. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/string.h +0 -148
  219. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/utf8.h +0 -41
  220. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/win/dl.h +0 -25
  221. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/writer.h +0 -101
  222. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/zsv_export.h +0 -33
  223. data/ext/zsv/vendor/zsv-1.3.0/include/zsv.h +0 -20
  224. data/ext/zsv/vendor/zsv-1.3.0/src/vector_delim.c +0 -60
  225. data/ext/zsv/vendor/zsv-1.3.0/src/zsv.c +0 -484
  226. data/ext/zsv/vendor/zsv-1.3.0/src/zsv_internal.c +0 -731
  227. data/ext/zsv/vendor/zsv-1.3.0/src/zsv_scan_delim.c +0 -285
  228. data/ext/zsv/vendor/zsv-1.3.0/src/zsv_scan_fixed.c +0 -88
  229. data/ext/zsv/vendor/zsv-1.3.0/src/zsv_strencode.c +0 -51
@@ -1,372 +0,0 @@
1
- /*
2
- * Copyright (C) 2021 Liquidaty and zsv contributors. All rights reserved.
3
- *
4
- * This file is part of zsv/lib, distributed under the MIT license as defined at
5
- * https://opensource.org/licenses/MIT
6
- */
7
-
8
- #include <stdio.h>
9
- #include <stdlib.h>
10
-
11
- #define _GNU_SOURCE 1
12
- #include <string.h>
13
- #include <ctype.h>
14
-
15
- #define ZSV_COMMAND serialize
16
- #include "zsv_command.h"
17
-
18
- #include <zsv/utils/writer.h>
19
- #include <zsv/utils/string.h>
20
-
21
- struct output_header_name {
22
- unsigned char *str;
23
- size_t len;
24
- };
25
-
26
- struct serialize_additional_column {
27
- struct serialize_additional_column *next;
28
- unsigned char *name;
29
- size_t len;
30
- size_t position_plus_1; // 0 = unassigned / not found
31
- };
32
-
33
- struct serialize_data {
34
- FILE *in;
35
- const char *input_path;
36
- zsv_csv_writer csv_writer;
37
- zsv_parser parser;
38
-
39
- struct output_header_name *header_names;
40
- unsigned int col_count;
41
- unsigned int id_column_position;
42
-
43
- char *err_msg;
44
-
45
- struct serialize_additional_column *additional_columns;
46
- struct serialize_additional_column **additional_columns_next;
47
- struct {
48
- const char *value;
49
- unsigned char *value_lc; // only used if case_insensitive is set
50
- size_t len;
51
- unsigned char case_insensitive : 1;
52
- unsigned char entire : 1;
53
- unsigned _ : 6;
54
- } filter;
55
- unsigned char use_column_position : 1;
56
- unsigned char _ : 7;
57
- };
58
-
59
- static void serialize_write_tuple(struct serialize_data *data, const unsigned char *id, size_t id_len, char id_quoted,
60
- const unsigned char *colname, size_t colname_len, const unsigned char *s, size_t len,
61
- char quoted) {
62
- // write row ID, column name, cell value
63
- zsv_writer_cell(data->csv_writer, 1, id, id_len, id_quoted);
64
- zsv_writer_cell(data->csv_writer, 0, colname, colname_len, 0);
65
- zsv_writer_cell(data->csv_writer, 0, s, len, quoted);
66
-
67
- // to do: write additional column headers
68
- for (struct serialize_additional_column *col = data->additional_columns; col; col = col->next) {
69
- if (col->position_plus_1) {
70
- struct zsv_cell c = zsv_get_cell(data->parser, col->position_plus_1 - 1);
71
- zsv_writer_cell(data->csv_writer, 0, c.str, c.len, c.quoted);
72
- }
73
- }
74
- }
75
-
76
- static inline void serialize_cell(struct serialize_data *data, struct zsv_cell id, unsigned i) {
77
- struct zsv_cell cell = zsv_get_cell(data->parser, i);
78
- char skip = 0;
79
- if (data->filter.value) {
80
- if (data->filter.case_insensitive) {
81
- if (data->filter.entire) {
82
- int err = 0;
83
- skip = zsv_strincmp(cell.str, cell.len, (const unsigned char *)data->filter.value, data->filter.len);
84
- if (err) {
85
- skip = 1;
86
- fprintf(stderr, "Ignoring invalid utf8: %.*s\n", (int)cell.len, cell.str);
87
- }
88
- } else { // case-insensitive, not-entire-cell. skip if not contains
89
- if (data->filter.value_lc) {
90
- size_t len = cell.len;
91
- unsigned char *tmp = zsv_strtolowercase(cell.str, &len);
92
- if (tmp) {
93
- skip = !zsv_strstr(tmp, data->filter.value_lc);
94
- free(tmp);
95
- }
96
- }
97
- }
98
- } else {
99
- if (data->filter.entire) // case-sensitive, exact / entire-cell. skip if not equal
100
- skip = !(cell.len == data->filter.len && !memcmp(cell.str, data->filter.value, cell.len));
101
- else // case-sensitive, not-entire-cell. skip if not contains
102
- skip = !memmem(cell.str, cell.len, data->filter.value, data->filter.len);
103
- }
104
- }
105
-
106
- if (!skip)
107
- // write tuple
108
- serialize_write_tuple(data, id.str, id.len, id.quoted, data->header_names[i].str, data->header_names[i].len,
109
- cell.str, cell.len, cell.quoted);
110
- }
111
-
112
- static void serialize_row(void *hook);
113
-
114
- static void serialize_header(void *hook) {
115
- struct serialize_data *data = hook;
116
- zsv_set_row_handler(data->parser, serialize_row);
117
- if (data->err_msg)
118
- return;
119
-
120
- data->col_count = zsv_cell_count(data->parser);
121
- if (!data->col_count)
122
- asprintf(&data->err_msg, "No columns read in first row; aborting\n");
123
- else {
124
- // write header
125
- struct zsv_cell idCell = zsv_get_cell(data->parser, data->id_column_position);
126
- if (idCell.len == 0) {
127
- idCell.str = (unsigned char *)"(Blank)";
128
- idCell.len = strlen((const char *)idCell.str);
129
- }
130
- // if we have additional columns, find them and output their header names
131
- if (data->additional_columns) {
132
- for (struct serialize_additional_column *c = data->additional_columns; c && !data->err_msg; c = c->next) {
133
- for (unsigned i = 0; i < data->col_count && !data->err_msg; i++) {
134
- struct zsv_cell tmp = zsv_get_cell(data->parser, i);
135
-
136
- if (!zsv_strincmp(tmp.str, tmp.len, c->name, c->len)) {
137
- // found
138
- c->position_plus_1 = i + 1;
139
- break;
140
- }
141
- }
142
- if (!c->position_plus_1)
143
- asprintf(&data->err_msg, "Column '%s' not found\n", (char *)c->name);
144
- }
145
- }
146
- if (!data->err_msg) {
147
- data->header_names = calloc(data->col_count, sizeof(*data->header_names));
148
- if (!data->header_names)
149
- asprintf(&data->err_msg, "Out of memory!");
150
- }
151
-
152
- for (unsigned i = 1; i < data->col_count && !data->err_msg; i++) {
153
- struct zsv_cell cell = zsv_get_cell(data->parser, i);
154
- // save the column header name
155
- if (data->use_column_position)
156
- asprintf((char **)&data->header_names[i].str, "%u", i);
157
- else {
158
- struct zsv_cell c = zsv_get_cell(data->parser, i);
159
- if (i == 0 && c.len == 0)
160
- data->header_names[i].str = (unsigned char *)strdup("(Blank)");
161
- else
162
- data->header_names[i].str = zsv_writer_str_to_csv(cell.str, cell.len);
163
- }
164
-
165
- if (data->header_names[i].str)
166
- data->header_names[i].len = strlen((const char *)data->header_names[i].str);
167
- else if (cell.len)
168
- asprintf(&data->err_msg, "Out of memory!");
169
- }
170
-
171
- if (!data->err_msg) {
172
- // print the output table header
173
- serialize_write_tuple(data, idCell.str, idCell.len, idCell.quoted, (const unsigned char *)"Column",
174
- strlen("Column"), (const unsigned char *)"Value", strlen("Value"), 0);
175
-
176
- if (data->use_column_position) {
177
- // process the header row as if it was a data row
178
- // output ID cell
179
- struct zsv_cell cell = zsv_get_cell(data->parser, data->id_column_position);
180
- serialize_write_tuple(data, (const unsigned char *)"Header", strlen("Header"), 0, (const unsigned char *)"0", 1,
181
- cell.str, cell.len, cell.quoted);
182
-
183
- // output other cells
184
- for (unsigned i = 0; i < data->col_count; i++) {
185
- if (i != data->id_column_position) {
186
- cell = zsv_get_cell(data->parser, i);
187
- serialize_write_tuple(data, (const unsigned char *)"Header", strlen("Header"), 0, data->header_names[i].str,
188
- data->header_names[i].len, cell.str, cell.len, cell.quoted);
189
- }
190
- }
191
- }
192
- }
193
- }
194
- }
195
-
196
- static void serialize_row(void *hook) {
197
- struct serialize_data *data = hook;
198
- if (data->err_msg)
199
- return;
200
-
201
- // get the row id
202
- struct zsv_cell id = zsv_get_cell(data->parser, data->id_column_position);
203
-
204
- unsigned j = zsv_cell_count(data->parser);
205
- for (unsigned i = 0; i < j && i < data->col_count; i++)
206
- if (i != data->id_column_position)
207
- serialize_cell(data, id, i);
208
- }
209
-
210
- const char *serialize_usage_msg[] = {
211
- APPNAME ": serialize a CSV file into row/column/value triplets",
212
- "",
213
- "Usage: " APPNAME " [<filename>]",
214
- "",
215
- "Options:",
216
- " -b : output with BOM",
217
- " -f,--filter <value> : only output cells with text that contains the given value",
218
- " -e,--entire : match the entire cell's content (only applicable with -f)",
219
- " -i,--case-insensitive : use case-insensitive match for the filter value",
220
- " --id-column <n> : the 1-based position of the column to use as the identifier (default=1, max=2000)",
221
- " -p,--position : output column position instead of name; the second column",
222
- " will be position 1, and the first row will be treated as a",
223
- " normal data row",
224
- " -a,--add <column name> : add additional columns to output. may be specified",
225
- " multiple times for multiple additional columns",
226
- NULL,
227
- };
228
-
229
- static int serialize_usage(void) {
230
- for (size_t i = 0; serialize_usage_msg[i]; i++)
231
- fprintf(stdout, "%s\n", serialize_usage_msg[i]);
232
- return 1;
233
- }
234
-
235
- static void serialize_cleanup(struct serialize_data *data) {
236
- zsv_writer_delete(data->csv_writer);
237
-
238
- free(data->filter.value_lc);
239
- free(data->err_msg);
240
-
241
- if (data->header_names) {
242
- for (unsigned int i = 0; i < data->col_count; i++)
243
- free(data->header_names[i].str);
244
- free(data->header_names);
245
- }
246
-
247
- if (data->in && data->in != stdin)
248
- fclose(data->in);
249
-
250
- for (struct serialize_additional_column *next, *c = data->additional_columns; c; c = next) {
251
- next = c->next;
252
- free(c->name);
253
- free(c);
254
- }
255
- }
256
-
257
- static int serialize_append_additional_column(struct serialize_data *data, const char *name) {
258
- struct serialize_additional_column *c = calloc(1, sizeof(*c));
259
- if (c) {
260
- if ((c->name = (unsigned char *)strdup(name))) {
261
- c->len = strlen((char *)c->name);
262
- if (!data->additional_columns)
263
- data->additional_columns = c;
264
- else
265
- *data->additional_columns_next = c;
266
- data->additional_columns_next = &c->next;
267
- return 0;
268
- }
269
- free(c);
270
- }
271
- return 1;
272
- }
273
-
274
- int ZSV_MAIN_FUNC(ZSV_COMMAND)(int argc, const char *argv[], struct zsv_opts *opts,
275
- struct zsv_prop_handler *custom_prop_handler) {
276
- if (argc > 1 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))) {
277
- serialize_usage();
278
- return 0;
279
- } else {
280
- struct zsv_csv_writer_options writer_opts = zsv_writer_get_default_opts();
281
- struct serialize_data data = {0};
282
- int err = 0;
283
- for (int arg_i = 1; !err && arg_i < argc; arg_i++) {
284
- const char *arg = argv[arg_i];
285
- if (!strcmp(arg, "-f") || !strcmp(arg, "--filter")) {
286
- if (arg_i + 1 < argc)
287
- data.filter.value = argv[++arg_i];
288
- else {
289
- fprintf(stderr, "filter option requires a value\n");
290
- err = 1;
291
- }
292
- } else if (!strcmp(arg, "-a") || !strcmp(arg, "--add")) {
293
- if (arg_i + 1 < argc)
294
- err = serialize_append_additional_column(&data, argv[++arg_i]);
295
- else {
296
- fprintf(stderr, "%s option requires a value\n", argv[arg_i]);
297
- err = 1;
298
- }
299
- } else if (!strcmp(arg, "-i") || !strcmp(arg, "--case-insensitive"))
300
- data.filter.case_insensitive = 1;
301
- else if (!strcmp(arg, "--id-column")) {
302
- if (arg_i + 1 < argc && atoi(argv[arg_i + 1]) > 0 && atoi(argv[arg_i + 1]) <= 2000)
303
- data.id_column_position = atoi(argv[++arg_i]) - 1;
304
- else {
305
- fprintf(stderr, "%s option requires a value between 1 and 2000\n", argv[arg_i]);
306
- err = 1;
307
- }
308
- } else if (!strcmp(arg, "-p") || !strcmp(arg, "--position"))
309
- data.use_column_position = 1;
310
- else if (!strcmp(arg, "-e") || !strcmp(arg, "--entire"))
311
- data.filter.entire = 1;
312
- else if (!strcmp(argv[arg_i], "-b"))
313
- writer_opts.with_bom = 1;
314
- else if (data.in) {
315
- err = 1;
316
- fprintf(stderr, "Input file specified twice, or unrecognized argument: %s\n", argv[arg_i]);
317
- } else if (!(data.in = fopen(argv[arg_i], "rb"))) {
318
- err = 1;
319
- fprintf(stderr, "Could not open for reading: %s\n", argv[arg_i]);
320
- } else
321
- data.input_path = argv[arg_i];
322
- }
323
-
324
- if (data.filter.value) {
325
- data.filter.len = strlen(data.filter.value);
326
- if (data.filter.case_insensitive)
327
- data.filter.value_lc = zsv_strtolowercase((const unsigned char *)data.filter.value, &data.filter.len);
328
- }
329
-
330
- if (!data.in) {
331
- #ifdef NO_STDIN
332
- fprintf(stderr, "Please specify an input file\n");
333
- err = 1;
334
- #else
335
- data.in = stdin;
336
- #endif
337
- }
338
-
339
- if (err) {
340
- serialize_cleanup(&data);
341
- return 1;
342
- }
343
-
344
- opts->row_handler = serialize_header;
345
- opts->stream = data.in;
346
- const char *input_path = data.input_path;
347
-
348
- opts->ctx = &data;
349
- data.csv_writer = zsv_writer_new(&writer_opts);
350
- if (zsv_new_with_properties(opts, custom_prop_handler, input_path, &data.parser) != zsv_status_ok ||
351
- !data.csv_writer) {
352
- serialize_cleanup(&data);
353
- return 1;
354
- }
355
-
356
- // create a local csv writer buff for faster performance
357
- unsigned char writer_buff[64];
358
- zsv_writer_set_temp_buff(data.csv_writer, writer_buff, sizeof(writer_buff));
359
-
360
- // process the input data
361
- zsv_handle_ctrl_c_signal();
362
- while (!zsv_signal_interrupted && zsv_parse_more(data.parser) == zsv_status_ok)
363
- ;
364
-
365
- if (data.err_msg)
366
- fprintf(stderr, "Error: %s\n", data.err_msg);
367
- zsv_finish(data.parser);
368
- zsv_delete(data.parser);
369
- serialize_cleanup(&data);
370
- }
371
- return 0;
372
- }
@@ -1,15 +0,0 @@
1
- #if defined(WIN32) || defined(_WIN32)
2
- #ifdef HAVE_NCURSESW
3
- #include <ncursesw/ncurses.h>
4
- #else
5
- #include <ncurses/ncurses.h>
6
- #endif // HAVE_NCURSESW
7
- #else
8
- #if __has_include(<ncursesw/curses.h>)
9
- #include <ncursesw/curses.h>
10
- #elif __has_include(<curses.h>)
11
- #include <curses.h>
12
- #else
13
- #error Cannot find ncurses include file!
14
- #endif
15
- #endif
@@ -1,119 +0,0 @@
1
- static size_t input_offset_top(void) {
2
- return 0;
3
- }
4
-
5
- static size_t input_offset_bottom(struct zsvsheet_input_dimensions *input_dims,
6
- size_t buffer_row_count // number of rows in the buffer, w/o regard to header
7
- ) {
8
- return input_dims->row_count - buffer_row_count;
9
- }
10
-
11
- static size_t input_offset_centered(struct zsvsheet_input_dimensions *input_dims,
12
- size_t buffer_row_count, // number of rows in the buffer, w/o regard to header
13
- size_t target_raw_ix // raw row index starting at zero, w/o regard to header
14
- ) {
15
- if (input_dims->row_count <= buffer_row_count) // entire input fits in buffer
16
- return input_offset_top();
17
- size_t buffer_half_row_count = buffer_row_count / 2;
18
- if (target_raw_ix <= buffer_half_row_count) // target is at the top of the file
19
- return input_offset_top();
20
- if (target_raw_ix + buffer_half_row_count > input_dims->row_count) // target is at the end of the file
21
- return input_offset_bottom(input_dims, buffer_row_count);
22
- return target_raw_ix - buffer_half_row_count;
23
- }
24
-
25
- // zsvsheet_goto_input_raw_row
26
- // return non-zero if buffer must be reloaded
27
- /*
28
- ------- INPUT
29
- 0 | header | => BUFFER[BHEADSPAN]
30
- 1 | ... | => BUFFER[BHEADSPAN]
31
- 2 | data
32
- ------- BUFFER[BHEADSPAN:]
33
- ioff->3 |
34
- 4 |
35
- ------- DISPLAY DATA
36
- 5 | boff-> | displayed data 1
37
- 6 | | displayed data 2
38
- ...
39
- N+4| | displayed data M = max_y - BHEADSPAN - 1
40
- -------
41
- */
42
-
43
- static void set_window_to_cursor(struct zsvsheet_rowcol *buff_offset, size_t target_raw_row,
44
- struct zsvsheet_rowcol *input_offset, size_t input_header_span,
45
- struct zsvsheet_display_dimensions *ddims, size_t cursor_row) {
46
- // assume that input_offset->row is fixed; set buff_offset->row
47
- if (target_raw_row + ddims->header_span >= input_offset->row + cursor_row + input_header_span)
48
- buff_offset->row = target_raw_row - input_offset->row - cursor_row + ddims->header_span - input_header_span;
49
- else
50
- buff_offset->row = 0;
51
- }
52
-
53
- static int zsvsheet_goto_input_raw_row(struct zsvsheet_ui_buffer *uib, size_t input_raw_num, size_t input_header_span,
54
- struct zsvsheet_display_dimensions *ddims, size_t final_cursor_position) {
55
- zsvsheet_screen_buffer_t buffer = uib->buffer;
56
- struct zsvsheet_rowcol *input_offset = &uib->input_offset;
57
- struct zsvsheet_rowcol *buff_offset = &uib->buff_offset;
58
- struct zsvsheet_input_dimensions *input_dims = &uib->dimensions;
59
- size_t *cursor_rowp = &uib->cursor_row;
60
-
61
- size_t buffer_rows = zsvsheet_screen_buffer_rows(buffer);
62
- int update_buffer = 0;
63
- if (input_raw_num < input_offset->row + input_header_span // move the buffer up
64
- || input_raw_num + input_header_span + 1 > input_offset->row + buffer_rows // move the buffer down
65
- ) {
66
- input_offset->row = input_offset_centered(input_dims, buffer_rows, input_raw_num);
67
- update_buffer = 1;
68
- } else if (!(input_raw_num >= input_offset->row + buff_offset->row &&
69
- input_raw_num <=
70
- input_offset->row + buff_offset->row + (ddims->rows + ddims->header_span + ddims->footer_span))) {
71
- // buffer already has the data but display window needs to move
72
- } else {
73
- if (final_cursor_position == (size_t)-1) {
74
- // just move the cursor however much we needed to shift
75
- size_t current = zsvsheet_get_input_raw_row(input_offset, buff_offset, *cursor_rowp);
76
- final_cursor_position = *cursor_rowp + input_raw_num - current;
77
- }
78
- }
79
- if (final_cursor_position == (size_t)-1)
80
- final_cursor_position = ddims->header_span;
81
- if (final_cursor_position < ddims->header_span)
82
- final_cursor_position = ddims->header_span;
83
- if (final_cursor_position > ddims->rows - ddims->footer_span - 1)
84
- final_cursor_position = ddims->rows - ddims->footer_span - 1;
85
- *cursor_rowp = final_cursor_position;
86
-
87
- // we may still need to update the buffer if the row we are jumping to will be
88
- // in the middle of the screen and therefore we still want to display additional
89
- // rows, and those additional rows are not loaded into the buffer
90
- if (!update_buffer && final_cursor_position < ddims->rows - 1) {
91
- size_t last_raw_row_to_display = input_raw_num + (ddims->rows - 1 - final_cursor_position);
92
- if (last_raw_row_to_display > input_dims->row_count)
93
- last_raw_row_to_display = input_dims->row_count;
94
- if (last_raw_row_to_display < input_offset->row + input_header_span // move the buffer up
95
- || last_raw_row_to_display + input_header_span + 1 > input_offset->row + buffer_rows // move the buffer down
96
- ) {
97
- input_offset->row = input_offset_centered(input_dims, buffer_rows, input_raw_num);
98
- update_buffer = 1;
99
- }
100
- }
101
- set_window_to_cursor(buff_offset, input_raw_num, input_offset, input_header_span, ddims, *cursor_rowp);
102
- return update_buffer;
103
- }
104
-
105
- static int cursor_right(int max_x, unsigned display_width, size_t max_col_count, size_t *cursor_colp,
106
- size_t *start_colp) {
107
- size_t cursor_col = *cursor_colp;
108
- size_t start_col = *start_colp;
109
- int rc = 1;
110
- if (cursor_col + 1 < max_x / display_width && start_col + cursor_col + 1 < max_col_count) {
111
- cursor_col++;
112
- } else if ((start_col + max_x / display_width) < max_col_count) {
113
- start_col++;
114
- } else
115
- rc = 0;
116
- *cursor_colp = cursor_col;
117
- *start_colp = start_col;
118
- return rc;
119
- }
@@ -1,45 +0,0 @@
1
- struct zsvsheet_errors_data {
2
- struct zsvsheet_ui_buffer *uib;
3
- size_t rows_fetched;
4
- const char *row_data[1];
5
- };
6
-
7
- const unsigned char **zsvsheet_errors_header(void *d) {
8
- struct zsvsheet_errors_data *data = d;
9
- data->row_data[0] = "Error";
10
- return (const unsigned char **)data->row_data;
11
- }
12
-
13
- const unsigned char *zsvsheet_errors_status(void *_) {
14
- (void)(_);
15
- return (const unsigned char *)"<esc> to exit, then :errors-clear to clear";
16
- }
17
-
18
- const unsigned char **zsvsheet_errors_row(void *d) {
19
- struct zsvsheet_errors_data *data = d;
20
- while (data->rows_fetched < data->uib->parse_errs.count) {
21
- data->row_data[0] = data->uib->parse_errs.errors[data->rows_fetched];
22
- data->rows_fetched++;
23
- if (data->row_data[0] && *data->row_data[0])
24
- return (const unsigned char **)data->row_data;
25
- }
26
- return NULL;
27
- }
28
-
29
- static zsvsheet_status zsvsheet_errors_handler(struct zsvsheet_proc_context *ctx) {
30
- struct zsvsheet_errors_data d = {0};
31
- d.uib = zsvsheet_buffer_current(ctx);
32
- if (!d.uib)
33
- return zsvsheet_status_error;
34
- if (ctx->proc_id == zsvsheet_builtin_proc_errors_clear) {
35
- uib_parse_errs_clear(&d.uib->parse_errs);
36
- return zsvsheet_status_ok;
37
- }
38
- if (d.uib->parse_errs.count == 0) {
39
- zsvsheet_ui_buffer_set_status(d.uib, "No errors");
40
- return zsvsheet_status_ok;
41
- }
42
- const size_t cols = 1;
43
- return zsvsheet_buffer_new_static(ctx, cols, zsvsheet_errors_header, zsvsheet_errors_row, zsvsheet_errors_status, &d,
44
- NULL);
45
- }
@@ -1,63 +0,0 @@
1
- int zsvsheet_ui_buffer_open_file_opts(struct zsvsheet_ui_buffer_opts *uibopts,
2
- struct zsv_prop_handler *custom_prop_handler,
3
- struct zsvsheet_ui_buffer **ui_buffer_stack_bottom,
4
- struct zsvsheet_ui_buffer **ui_buffer_stack_top) {
5
- struct zsvsheet_opts zsvsheet_opts = {0};
6
- struct zsvsheet_screen_buffer_opts bopts = {0};
7
- struct zsvsheet_ui_buffer *tmp_ui_buffer = NULL;
8
-
9
- if (!uibopts->buff_opts)
10
- uibopts->buff_opts = &bopts;
11
-
12
- int err = 0;
13
- if ((err = read_data(&tmp_ui_buffer, uibopts, 0, 0, 0, &zsvsheet_opts, custom_prop_handler)) != 0 || !tmp_ui_buffer ||
14
- !tmp_ui_buffer->buff_used_rows) {
15
- zsvsheet_ui_buffer_delete(tmp_ui_buffer);
16
- if (err)
17
- return err;
18
- return -1;
19
- }
20
- tmp_ui_buffer->cursor_row = 1; // first row is header
21
- zsvsheet_ui_buffer_push(ui_buffer_stack_bottom, ui_buffer_stack_top, tmp_ui_buffer);
22
-
23
- return 0;
24
- }
25
-
26
- int zsvsheet_ui_buffer_open_file(const char *filename, const struct zsv_opts *zsv_optsp,
27
- struct zsv_prop_handler *custom_prop_handler,
28
- struct zsvsheet_ui_buffer **ui_buffer_stack_bottom,
29
- struct zsvsheet_ui_buffer **ui_buffer_stack_top) {
30
- struct zsvsheet_ui_buffer_opts uibopts = {0};
31
- uibopts.filename = filename;
32
- if (zsv_optsp)
33
- uibopts.zsv_opts = *zsv_optsp;
34
-
35
- return zsvsheet_ui_buffer_open_file_opts(&uibopts, custom_prop_handler, ui_buffer_stack_bottom, ui_buffer_stack_top);
36
- }
37
-
38
- /****** API ******/
39
-
40
- /**
41
- * Open a tabular file as a new buffer
42
- */
43
- zsvsheet_status zsvsheet_open_file(struct zsvsheet_proc_context *ctx, const char *filepath, struct zsv_opts *zopts) {
44
- struct zsvsheet_sheet_context *state = (struct zsvsheet_sheet_context *)ctx->subcommand_context;
45
- struct zsvsheet_display_info *di = &state->display_info;
46
- if (!di || !di->ui_buffers.base || !di->ui_buffers.current)
47
- return zsvsheet_status_error;
48
- int err = zsvsheet_ui_buffer_open_file(filepath, zopts, NULL, di->ui_buffers.base, di->ui_buffers.current);
49
- if (err)
50
- return zsvsheet_status_error;
51
- return zsvsheet_status_ok;
52
- }
53
-
54
- zsvsheet_status zsvsheet_open_file_opts(struct zsvsheet_proc_context *ctx, struct zsvsheet_ui_buffer_opts *opts) {
55
- struct zsvsheet_sheet_context *state = (struct zsvsheet_sheet_context *)ctx->subcommand_context;
56
- struct zsvsheet_display_info *di = &state->display_info;
57
- if (!di || !di->ui_buffers.base || !di->ui_buffers.current)
58
- return zsvsheet_status_error;
59
- int err = zsvsheet_ui_buffer_open_file_opts(opts, NULL, di->ui_buffers.base, di->ui_buffers.current);
60
- if (err)
61
- return zsvsheet_status_error;
62
- return zsvsheet_status_ok;
63
- }
@@ -1,12 +0,0 @@
1
- #ifndef ZSVSHEET_FILE_H
2
- #define ZSVSHEET_FILE_H
3
-
4
- int zsvsheet_ui_buffer_open_file(const char *filename, const struct zsv_opts *zsv_optsp,
5
- struct zsv_prop_handler *custom_prop_handler,
6
- struct zsvsheet_ui_buffer **ui_buffer_stack_bottom,
7
- struct zsvsheet_ui_buffer **ui_buffer_stack_top);
8
-
9
- zsvsheet_status zsvsheet_open_file_opts(struct zsvsheet_proc_context *ctx, struct zsvsheet_ui_buffer_opts *opts);
10
- zsvsheet_status zsvsheet_open_file(struct zsvsheet_proc_context *ctx, const char *filepath, struct zsv_opts *zopts);
11
-
12
- #endif