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.
Files changed (240) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +36 -0
  3. data/LICENSE +21 -0
  4. data/README.md +311 -0
  5. data/ext/zsv/common.h +34 -0
  6. data/ext/zsv/extconf.rb +137 -0
  7. data/ext/zsv/options.c +126 -0
  8. data/ext/zsv/options.h +31 -0
  9. data/ext/zsv/options_internal.h +8 -0
  10. data/ext/zsv/parser.c +300 -0
  11. data/ext/zsv/parser.h +62 -0
  12. data/ext/zsv/row.c +122 -0
  13. data/ext/zsv/row.h +39 -0
  14. data/ext/zsv/vendor/zsv-1.3.0/app/2db.c +756 -0
  15. data/ext/zsv/vendor/zsv-1.3.0/app/2json.c +381 -0
  16. data/ext/zsv/vendor/zsv-1.3.0/app/2tsv.c +228 -0
  17. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/help.c +123 -0
  18. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/license.c +39 -0
  19. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/register.c +104 -0
  20. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/thirdparty.c +41 -0
  21. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/unregister.c +1 -0
  22. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/version.c +14 -0
  23. data/ext/zsv/vendor/zsv-1.3.0/app/check/simdutf_wrapper.h +19 -0
  24. data/ext/zsv/vendor/zsv-1.3.0/app/check/utf8.c +116 -0
  25. data/ext/zsv/vendor/zsv-1.3.0/app/check.c +194 -0
  26. data/ext/zsv/vendor/zsv-1.3.0/app/cli.c +796 -0
  27. data/ext/zsv/vendor/zsv-1.3.0/app/cli_const.h +41 -0
  28. data/ext/zsv/vendor/zsv-1.3.0/app/cli_export.h +16 -0
  29. data/ext/zsv/vendor/zsv-1.3.0/app/cli_ini.c +280 -0
  30. data/ext/zsv/vendor/zsv-1.3.0/app/cli_internal.h +36 -0
  31. data/ext/zsv/vendor/zsv-1.3.0/app/compare.c +913 -0
  32. data/ext/zsv/vendor/zsv-1.3.0/app/compare.h +23 -0
  33. data/ext/zsv/vendor/zsv-1.3.0/app/compare_added_column.c +20 -0
  34. data/ext/zsv/vendor/zsv-1.3.0/app/compare_internal.h +140 -0
  35. data/ext/zsv/vendor/zsv-1.3.0/app/compare_sort.c +91 -0
  36. data/ext/zsv/vendor/zsv-1.3.0/app/compare_unique_colname.c +81 -0
  37. data/ext/zsv/vendor/zsv-1.3.0/app/count-pull.c +82 -0
  38. data/ext/zsv/vendor/zsv-1.3.0/app/count.c +404 -0
  39. data/ext/zsv/vendor/zsv-1.3.0/app/desc.c +569 -0
  40. data/ext/zsv/vendor/zsv-1.3.0/app/echo.c +365 -0
  41. data/ext/zsv/vendor/zsv-1.3.0/app/ext_example/my_extension.c +366 -0
  42. data/ext/zsv/vendor/zsv-1.3.0/app/ext_example/mysheet_extension.c +341 -0
  43. data/ext/zsv/vendor/zsv-1.3.0/app/ext_template/YOUR_EXTENSION_zsvext.c +263 -0
  44. data/ext/zsv/vendor/zsv-1.3.0/app/external/inih/ini.c +298 -0
  45. data/ext/zsv/vendor/zsv-1.3.0/app/external/inih/ini.h +157 -0
  46. data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/json_numeric.c +177 -0
  47. data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/jsonwriter.c +444 -0
  48. data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/jsonwriter.h +145 -0
  49. data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/utils.c +110 -0
  50. data/ext/zsv/vendor/zsv-1.3.0/app/external/memfile-1.0/include/memfile.h +15 -0
  51. data/ext/zsv/vendor/zsv-1.3.0/app/external/memfile-1.0/src/memfile.c +64 -0
  52. data/ext/zsv/vendor/zsv-1.3.0/app/external/sglib/sglib.h +1955 -0
  53. data/ext/zsv/vendor/zsv-1.3.0/app/external/simdutf/simdutf.h +6802 -0
  54. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3.c +230517 -0
  55. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3.h +12174 -0
  56. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_and_csv_vtab.c +2 -0
  57. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab-mem.c +142 -0
  58. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab-mem.h +49 -0
  59. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab-zsv.c +485 -0
  60. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab.c +1015 -0
  61. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3ext.h +663 -0
  62. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/vtab_helper.c +85 -0
  63. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_common.h +75 -0
  64. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_gen.h +167 -0
  65. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_parse.h +228 -0
  66. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_tree.h +186 -0
  67. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_version.h +23 -0
  68. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_common.h +76 -0
  69. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_gen.h +167 -0
  70. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_parse.h +238 -0
  71. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_tree.h +186 -0
  72. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl.c +184 -0
  73. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_alloc.c +52 -0
  74. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_alloc.h +34 -0
  75. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_buf.c +103 -0
  76. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_buf.h +57 -0
  77. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_bytestack.h +69 -0
  78. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_encode.c +220 -0
  79. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_encode.h +34 -0
  80. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_gen.c +362 -0
  81. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_lex.c +764 -0
  82. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_lex.h +117 -0
  83. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_parser.c +508 -0
  84. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_parser.h +78 -0
  85. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_tree.c +505 -0
  86. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_version.c +7 -0
  87. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper/json_value.h +59 -0
  88. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper/yajl_helper.h +208 -0
  89. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper.c +795 -0
  90. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper_internal.h +28 -0
  91. data/ext/zsv/vendor/zsv-1.3.0/app/flatten.c +851 -0
  92. data/ext/zsv/vendor/zsv-1.3.0/app/jq.c +106 -0
  93. data/ext/zsv/vendor/zsv-1.3.0/app/jq.h +6 -0
  94. data/ext/zsv/vendor/zsv-1.3.0/app/mv.c +113 -0
  95. data/ext/zsv/vendor/zsv-1.3.0/app/noop.c +90 -0
  96. data/ext/zsv/vendor/zsv-1.3.0/app/overwrite.c +295 -0
  97. data/ext/zsv/vendor/zsv-1.3.0/app/paste.c +175 -0
  98. data/ext/zsv/vendor/zsv-1.3.0/app/pretty.c +693 -0
  99. data/ext/zsv/vendor/zsv-1.3.0/app/prop.c +980 -0
  100. data/ext/zsv/vendor/zsv-1.3.0/app/rm.c +131 -0
  101. data/ext/zsv/vendor/zsv-1.3.0/app/select/fixed.c +130 -0
  102. data/ext/zsv/vendor/zsv-1.3.0/app/select/internal.h +118 -0
  103. data/ext/zsv/vendor/zsv-1.3.0/app/select/parallel.c +45 -0
  104. data/ext/zsv/vendor/zsv-1.3.0/app/select/parallel.h +41 -0
  105. data/ext/zsv/vendor/zsv-1.3.0/app/select/processing.c +107 -0
  106. data/ext/zsv/vendor/zsv-1.3.0/app/select/rand.c +20 -0
  107. data/ext/zsv/vendor/zsv-1.3.0/app/select/regex.c +61 -0
  108. data/ext/zsv/vendor/zsv-1.3.0/app/select/search.c +14 -0
  109. data/ext/zsv/vendor/zsv-1.3.0/app/select/selection.c +192 -0
  110. data/ext/zsv/vendor/zsv-1.3.0/app/select/usage.c +72 -0
  111. data/ext/zsv/vendor/zsv-1.3.0/app/select-pull.c +812 -0
  112. data/ext/zsv/vendor/zsv-1.3.0/app/select.c +753 -0
  113. data/ext/zsv/vendor/zsv-1.3.0/app/serialize.c +372 -0
  114. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/curses.h +15 -0
  115. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/cursor.c +119 -0
  116. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/errors.c +45 -0
  117. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/file.c +63 -0
  118. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/file.h +12 -0
  119. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/filter.c +166 -0
  120. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/handlers.c +214 -0
  121. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/handlers_internal.h +128 -0
  122. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/help.c +43 -0
  123. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/index.c +81 -0
  124. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/index.h +25 -0
  125. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/key-bindings.c +325 -0
  126. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/key-bindings.h +73 -0
  127. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/lexer.c +203 -0
  128. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/newline_handler.c +7 -0
  129. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/pivot.c +318 -0
  130. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/procedure.c +134 -0
  131. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/procedure.h +119 -0
  132. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/read-data.c +322 -0
  133. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/screen_buffer.c +203 -0
  134. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/screen_buffer.h +36 -0
  135. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/sheet-sql.c +167 -0
  136. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/sheet_internal.h +36 -0
  137. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/sqlfilter.c +153 -0
  138. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/terminfo.c +32 -0
  139. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/transformation.c +312 -0
  140. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/transformation.h +29 -0
  141. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/ui_buffer.c +266 -0
  142. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/usage.c +9 -0
  143. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/utf8-width.c +60 -0
  144. data/ext/zsv/vendor/zsv-1.3.0/app/sheet.c +1007 -0
  145. data/ext/zsv/vendor/zsv-1.3.0/app/sql.c +453 -0
  146. data/ext/zsv/vendor/zsv-1.3.0/app/sql_internal.c +101 -0
  147. data/ext/zsv/vendor/zsv-1.3.0/app/sql_internal.h +49 -0
  148. data/ext/zsv/vendor/zsv-1.3.0/app/stack.c +393 -0
  149. data/ext/zsv/vendor/zsv-1.3.0/app/utils/arg.c +322 -0
  150. data/ext/zsv/vendor/zsv-1.3.0/app/utils/cache.c +228 -0
  151. data/ext/zsv/vendor/zsv-1.3.0/app/utils/cat.c +91 -0
  152. data/ext/zsv/vendor/zsv-1.3.0/app/utils/chunk.c +240 -0
  153. data/ext/zsv/vendor/zsv-1.3.0/app/utils/chunk.h +63 -0
  154. data/ext/zsv/vendor/zsv-1.3.0/app/utils/clock.c +57 -0
  155. data/ext/zsv/vendor/zsv-1.3.0/app/utils/db.c +148 -0
  156. data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs-no-jq.c +2 -0
  157. data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs.c +427 -0
  158. data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs_from_json.c +253 -0
  159. data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs_to_json.c +121 -0
  160. data/ext/zsv/vendor/zsv-1.3.0/app/utils/dl.c +20 -0
  161. data/ext/zsv/vendor/zsv-1.3.0/app/utils/emcc/fs_api.c +159 -0
  162. data/ext/zsv/vendor/zsv-1.3.0/app/utils/err.c +24 -0
  163. data/ext/zsv/vendor/zsv-1.3.0/app/utils/file-mem.c +180 -0
  164. data/ext/zsv/vendor/zsv-1.3.0/app/utils/file.c +256 -0
  165. data/ext/zsv/vendor/zsv-1.3.0/app/utils/index.c +197 -0
  166. data/ext/zsv/vendor/zsv-1.3.0/app/utils/index.h +49 -0
  167. data/ext/zsv/vendor/zsv-1.3.0/app/utils/jq.c +400 -0
  168. data/ext/zsv/vendor/zsv-1.3.0/app/utils/json.c +120 -0
  169. data/ext/zsv/vendor/zsv-1.3.0/app/utils/mem.c +18 -0
  170. data/ext/zsv/vendor/zsv-1.3.0/app/utils/memmem.c +132 -0
  171. data/ext/zsv/vendor/zsv-1.3.0/app/utils/os.c +178 -0
  172. data/ext/zsv/vendor/zsv-1.3.0/app/utils/overwrite.c +258 -0
  173. data/ext/zsv/vendor/zsv-1.3.0/app/utils/overwrite_writer.c +246 -0
  174. data/ext/zsv/vendor/zsv-1.3.0/app/utils/pcre2-8/pcre2-8-test.c +123 -0
  175. data/ext/zsv/vendor/zsv-1.3.0/app/utils/pcre2-8/pcre2-8.c +153 -0
  176. data/ext/zsv/vendor/zsv-1.3.0/app/utils/pcre2-8/pcre2-8.h +54 -0
  177. data/ext/zsv/vendor/zsv-1.3.0/app/utils/prop.c +267 -0
  178. data/ext/zsv/vendor/zsv-1.3.0/app/utils/signal.c +53 -0
  179. data/ext/zsv/vendor/zsv-1.3.0/app/utils/string.c +357 -0
  180. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/dir_exists_longpath.c +83 -0
  181. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/dl.c +33 -0
  182. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/fopen_longpath.c +184 -0
  183. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/foreach_dirent_longpath.c +292 -0
  184. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/io.c +259 -0
  185. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/io.h +13 -0
  186. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/mkdir_longpath.c +255 -0
  187. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/remove_longpath.c +96 -0
  188. data/ext/zsv/vendor/zsv-1.3.0/app/utils/writer.c +361 -0
  189. data/ext/zsv/vendor/zsv-1.3.0/app/zsv_command.h +40 -0
  190. data/ext/zsv/vendor/zsv-1.3.0/app/zsv_command_standalone.c +16 -0
  191. data/ext/zsv/vendor/zsv-1.3.0/app/zsv_main.h +44 -0
  192. data/ext/zsv/vendor/zsv-1.3.0/examples/js/zsv_parser_api_dummy.c +3 -0
  193. data/ext/zsv/vendor/zsv-1.3.0/examples/lib/parse_by_chunk.c +100 -0
  194. data/ext/zsv/vendor/zsv-1.3.0/examples/lib/print_my_column.c +143 -0
  195. data/ext/zsv/vendor/zsv-1.3.0/examples/lib/pull.c +89 -0
  196. data/ext/zsv/vendor/zsv-1.3.0/examples/lib/simple.c +123 -0
  197. data/ext/zsv/vendor/zsv-1.3.0/fuzz/fuzz.c +16 -0
  198. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/api.h +336 -0
  199. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/common.h +361 -0
  200. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/ext/implementation.h +62 -0
  201. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/ext/implementation_private.h +113 -0
  202. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/ext/sheet.h +73 -0
  203. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/ext.h +329 -0
  204. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/arg.h +90 -0
  205. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/cache.h +49 -0
  206. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/clock.h +36 -0
  207. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/compiler.h +58 -0
  208. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/db.h +19 -0
  209. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/dirs.h +147 -0
  210. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/dl.h +22 -0
  211. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/emcc/fs_api.h +28 -0
  212. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/err.h +22 -0
  213. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/file-mem.h +17 -0
  214. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/file.h +99 -0
  215. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/jq.h +65 -0
  216. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/json.h +19 -0
  217. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/mem.h +19 -0
  218. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/memmem.h +13 -0
  219. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/os.h +54 -0
  220. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/overwrite.h +71 -0
  221. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/overwrite_writer.h +53 -0
  222. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/prop.h +107 -0
  223. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/signal.h +18 -0
  224. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/sql.h +11 -0
  225. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/string.h +148 -0
  226. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/utf8.h +41 -0
  227. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/win/dl.h +25 -0
  228. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/writer.h +101 -0
  229. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/zsv_export.h +33 -0
  230. data/ext/zsv/vendor/zsv-1.3.0/include/zsv.h +20 -0
  231. data/ext/zsv/vendor/zsv-1.3.0/src/vector_delim.c +60 -0
  232. data/ext/zsv/vendor/zsv-1.3.0/src/zsv.c +484 -0
  233. data/ext/zsv/vendor/zsv-1.3.0/src/zsv_internal.c +731 -0
  234. data/ext/zsv/vendor/zsv-1.3.0/src/zsv_scan_delim.c +285 -0
  235. data/ext/zsv/vendor/zsv-1.3.0/src/zsv_scan_fixed.c +88 -0
  236. data/ext/zsv/vendor/zsv-1.3.0/src/zsv_strencode.c +51 -0
  237. data/ext/zsv/zsv_ext.c +343 -0
  238. data/lib/zsv/version.rb +5 -0
  239. data/lib/zsv.rb +81 -0
  240. metadata +340 -0
@@ -0,0 +1,106 @@
1
+ #include <stdio.h>
2
+ #include <string.h>
3
+
4
+ #define ZSV_COMMAND_NO_OPTIONS
5
+ #define ZSV_COMMAND jq
6
+ #include "zsv_command.h"
7
+
8
+ #include <zsv/utils/jq.h>
9
+
10
+ /**
11
+ * This implementation is not intended to replicate the full functionality of the `jq`
12
+ * utility available at https://github.com/stedolan/jq
13
+ *
14
+ * This `jq` implementation is included as a convenience so as not to require a
15
+ * separate `jq` installation for basic JSON parsing and manipulation
16
+ */
17
+ int ZSV_MAIN_NO_OPTIONS_FUNC(ZSV_COMMAND)(int argc, const char *argv[]) {
18
+ if (argc < 2 || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
19
+ printf("Usage: " APPNAME " <filter> filename [-o,--output filename] [--csv]\n");
20
+ return 0;
21
+ }
22
+
23
+ char to_csv = 0;
24
+ #ifdef NO_STDIN
25
+ const int min_args = 3;
26
+ #else
27
+ const int min_args = 2;
28
+ #endif
29
+ if (argc < min_args) {
30
+ fprintf(stderr, "Please provide a filter and an input file\n");
31
+ return 1;
32
+ }
33
+
34
+ #ifdef NO_STDIN
35
+ FILE *f_in = NULL;
36
+ #else
37
+ FILE *f_in = stdin;
38
+ #endif
39
+
40
+ FILE *f_out = stdout;
41
+
42
+ int err = 0;
43
+ const unsigned char *jqfilter = (const unsigned char *)argv[1];
44
+ struct jv_to_json_ctx ctx = {0};
45
+
46
+ for (int i = 2; !err && i < argc; i++) { // jq filter filename
47
+ const char *arg = argv[i];
48
+ if (i == 2 && *arg != '-') {
49
+ if (!(f_in = fopen(arg, "rb"))) {
50
+ err = 1;
51
+ fprintf(stderr, "Unable to open for read: %s\n", arg);
52
+ }
53
+ } else if (!strcmp(arg, "--csv")) {
54
+ to_csv = 1;
55
+ } else if (!strcmp(arg, "--raw-output")) {
56
+ ctx.raw_output = 1;
57
+ } else if (!strcmp(arg, "-o") || !strcmp(arg, "--output")) {
58
+ i++;
59
+ if (!(i < argc)) {
60
+ err = 1;
61
+ fprintf(stderr, "Option %s requires a filename\n", arg);
62
+ } else if (!(f_out = fopen(argv[i], "wb"))) {
63
+ err = 1;
64
+ fprintf(stderr, "Unable to open for write: %s\n", argv[i]);
65
+ }
66
+ } else {
67
+ fprintf(stderr, "Unrecognized option: %s\n", arg);
68
+ err = 1;
69
+ }
70
+ }
71
+
72
+ if (!f_in) {
73
+ fprintf(stderr, "Please specify an input file\n");
74
+ err = 1;
75
+ }
76
+
77
+ if (!err) {
78
+ void (*jqfunc)(jv, void *) = to_csv ? jv_to_csv : jv_to_json_func;
79
+ ctx.write1 = zsv_jq_fwrite1;
80
+ ctx.ctx = f_out;
81
+ ctx.flags = JV_PRINT_PRETTY | JV_PRINT_SPACE1;
82
+
83
+ void *jqctx = to_csv ? (void *)f_out : (void *)&ctx;
84
+ enum zsv_jq_status jqstat;
85
+ zsv_jq_handle zjq = zsv_jq_new(jqfilter, jqfunc, jqctx, &jqstat);
86
+ if (jqstat != zsv_jq_status_ok) {
87
+ fprintf(stderr, "Invalid filter: %s\n", jqfilter);
88
+ err = 1;
89
+ } else {
90
+ if ((jqstat = zsv_jq_parse_file(zjq, f_in)))
91
+ err = jqstat;
92
+ if ((jqstat = zsv_jq_finish(zjq)) && !err)
93
+ err = jqstat;
94
+ if (!err && !to_csv)
95
+ fprintf(f_out, "\n");
96
+ }
97
+ zsv_jq_delete(zjq);
98
+ }
99
+
100
+ if (f_out && f_out != stdout)
101
+ fclose(f_out);
102
+ if (f_in && f_in != stdin)
103
+ fclose(f_in);
104
+
105
+ return err;
106
+ }
@@ -0,0 +1,6 @@
1
+ #ifndef LQJQ_H
2
+ #define LQJQ_H
3
+
4
+ int lq_jq(int argc, const char *argv[]);
5
+
6
+ #endif
@@ -0,0 +1,113 @@
1
+ /* Copyright (C) 2022 Guarnerix Inc dba Liquidaty - All Rights Reserved
2
+ * Unauthorized copying of this file, via any medium is strictly prohibited
3
+ * Proprietary and confidential
4
+ * Written by Matt Wong <matt@guarnerix.com>
5
+ */
6
+
7
+ /*
8
+ * Move a given file and its cache as follows:
9
+ * 1. check that the destination file doesn't exist. if it does, exit with an error
10
+ * 2. if a cache exists, check that the destination file cache dir doesn't exist. if it does, exit with an error
11
+ * 3. move the file. if it fails, exit with an error
12
+ * 4. move the cache, if it exists. if it fails, attempt to move the file back to its original location, and exit with
13
+ * an error
14
+ */
15
+
16
+ #include <stdlib.h>
17
+ #include <stdio.h>
18
+ #include <string.h>
19
+ #include <unistd.h> // unlink()
20
+ #include <errno.h>
21
+
22
+ #define ZSV_COMMAND_NO_OPTIONS
23
+ #define ZSV_COMMAND mv
24
+ #include "zsv_command.h"
25
+
26
+ #include <zsv/utils/dirs.h>
27
+ #include <zsv/utils/file.h>
28
+ #include <zsv/utils/cache.h>
29
+ #include <zsv/utils/os.h>
30
+
31
+ const char *zsv_mv_usage_msg[] = {
32
+ APPNAME ": move a file and its related cache",
33
+ "",
34
+ "Usage: " APPNAME " [options] <source> <destination>",
35
+ "",
36
+ "Options:",
37
+ " -v,--verbose : verbose output",
38
+ " -C,--cache : only move related cache (not the file)",
39
+ NULL,
40
+ };
41
+
42
+ static int zsv_mv_usage(FILE *target) {
43
+ for (size_t j = 0; zsv_mv_usage_msg[j]; j++)
44
+ fprintf(target, "%s\n", zsv_mv_usage_msg[j]);
45
+ return target == stdout ? 0 : 1;
46
+ }
47
+
48
+ int ZSV_MAIN_NO_OPTIONS_FUNC(ZSV_COMMAND)(int argc, const char *argv[]) {
49
+ int err = 0;
50
+ if (argc > 1 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")))
51
+ err = zsv_mv_usage(stdout);
52
+ else if (argc < 2)
53
+ err = zsv_mv_usage(stderr);
54
+ else {
55
+ const char *source = NULL;
56
+ const char *dest = NULL;
57
+
58
+ char move_file = 1;
59
+ char verbose = 0;
60
+ for (int i = 1; !err && i < argc; i++) {
61
+ const char *arg = argv[i];
62
+ if (*arg == '-') {
63
+ if (!strcmp(arg, "-v") || !strcmp(arg, "--verbose"))
64
+ verbose = 1;
65
+ else if (!strcmp(arg, "-C") || !strcmp(arg, "--cache"))
66
+ move_file = 0;
67
+ else
68
+ err = zsv_printerr(1, "Unrecognized option: %s", arg);
69
+ } else if (!source)
70
+ source = arg;
71
+ else if (!dest)
72
+ dest = arg;
73
+ else
74
+ err = zsv_printerr(1, "Unrecognized option: %s", arg);
75
+ }
76
+
77
+ if (!err) {
78
+ unsigned char *source_cache_dir = zsv_cache_path((const unsigned char *)source, NULL, 0);
79
+ unsigned char *dest_cache_dir = zsv_cache_path((const unsigned char *)dest, NULL, 0);
80
+ if (!source || !dest) {
81
+ err = zsv_mv_usage(stderr);
82
+ } else if (move_file && !zsv_file_exists(source)) {
83
+ err = errno = ENOENT;
84
+ perror(source);
85
+ } else if (move_file && zsv_file_exists(dest)) {
86
+ err = errno = EEXIST;
87
+ perror(dest);
88
+ } else if (zsv_dir_exists((const char *)source_cache_dir) && zsv_dir_exists((const char *)dest_cache_dir)) {
89
+ err = errno = EEXIST;
90
+ perror((char *)dest_cache_dir);
91
+ fprintf(stderr, "Use `mv --cache %s <destination>` to move or `rm --cache %s` to remove, then try again\n",
92
+ dest, dest);
93
+ } else if (move_file && (verbose ? fprintf(stderr, "Renaming files\n") : 1) && zsv_replace_file(source, dest)) {
94
+ err = errno;
95
+ fprintf(stderr, "%s -> %s: ", source, dest);
96
+ zsv_perror(NULL);
97
+ } else if (zsv_dir_exists((const char *)source_cache_dir) && (verbose ? fprintf(stderr, "Moving caches\n") : 1) &&
98
+ rename( // rename(): not sure will work on Win with NFS dirs...
99
+ (char *)source_cache_dir, (char *)dest_cache_dir)) {
100
+ err = errno;
101
+ fprintf(stderr, "%s -> %s: ", source_cache_dir, dest_cache_dir);
102
+ perror(NULL);
103
+ if (rename(dest, source)) { // try to revert the prior rename. see above re Win + NFS
104
+ fprintf(stderr, "%s -> %s: ", dest, source);
105
+ perror(NULL);
106
+ }
107
+ }
108
+ free(source_cache_dir);
109
+ free(dest_cache_dir);
110
+ }
111
+ }
112
+ return err;
113
+ }
@@ -0,0 +1,90 @@
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 <zsv.h>
9
+ #include <zsv/utils/writer.h>
10
+ #include <zsv/utils/signal.h>
11
+ #include <zsv/utils/arg.h>
12
+ #include <stdio.h>
13
+ #include <string.h>
14
+ #include <stdlib.h>
15
+
16
+ struct data {
17
+ int col_count;
18
+ zsv_parser parser;
19
+ };
20
+
21
+ static void error(void *ctx, enum zsv_status status, const unsigned char *err_msg, size_t err_msg_len,
22
+ unsigned char error_c, size_t cum_scanned_length) {
23
+ (void)(ctx);
24
+ (void)(status);
25
+ (void)(err_msg);
26
+ (void)(err_msg_len);
27
+ (void)(error_c);
28
+ (void)(cum_scanned_length);
29
+ }
30
+
31
+ static void cell(void *ctx, unsigned char *utf8_value, size_t len) {
32
+ (void)(ctx);
33
+ (void)(utf8_value);
34
+ (void)(len);
35
+ }
36
+
37
+ static void overflow(void *ctx, unsigned char *utf8_value, size_t len) {
38
+ (void)(ctx);
39
+ (void)(utf8_value);
40
+ (void)(len);
41
+ }
42
+
43
+ static void row(void *ctx) {
44
+ (void)(ctx);
45
+ }
46
+
47
+ int main(int argc, const char *argv[]) {
48
+ FILE *f = NULL;
49
+ struct zsv_csv_writer_options writer_opts = zsv_writer_get_default_opts();
50
+ struct data data = {0};
51
+
52
+ for (int i = 1; i < argc; i++) {
53
+ if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) {
54
+ fprintf(stdout, "Usage: noop [filename]\n");
55
+ fprintf(stdout, " Reads CSV input and does nothing. For performance testing\n\n");
56
+ return 0;
57
+ } else if (!f) {
58
+ if (!(f = fopen(argv[i], "rb"))) {
59
+ fprintf(stderr, "Unable to open %s for writing\n", argv[i]);
60
+ return 1;
61
+ }
62
+ } else {
63
+ fprintf(stderr, "Input file specified more than once (second was %s)\n", argv[i]);
64
+ if (f)
65
+ fclose(f);
66
+ return 1;
67
+ }
68
+ }
69
+
70
+ if (!f)
71
+ f = stdin;
72
+
73
+ struct zsv_opts opts = zsv_get_default_opts();
74
+ opts.cell = cell;
75
+ opts.row = row;
76
+ opts.ctx = &data;
77
+ opts.overflow = overflow;
78
+ opts.error = error;
79
+
80
+ opts.stream = f;
81
+ if ((data.parser = zsv_new(&opts))) {
82
+ zsv_handle_ctrl_c_signal();
83
+ while (!zsv_signal_interrupted && zsv_parse_more(data.parser) == zsv_status_ok)
84
+ ;
85
+ zsv_finish(data.parser);
86
+ zsv_delete(data.parser);
87
+ }
88
+ fclose(f);
89
+ return 0;
90
+ }
@@ -0,0 +1,295 @@
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
+ #include <sqlite3.h>
11
+ #include <errno.h>
12
+ #include <limits.h>
13
+
14
+ #define _GNU_SOURCE 1
15
+ #include <string.h>
16
+ #include <ctype.h>
17
+
18
+ #include <zsv.h>
19
+ #include <zsv/utils/writer.h>
20
+ #include <zsv/utils/cache.h>
21
+ #include <zsv/utils/overwrite.h>
22
+ #include <zsv/utils/clock.h>
23
+ #include <zsv/utils/overwrite_writer.h>
24
+
25
+ #define ZSV_COMMAND overwrite
26
+ #include "zsv_command.h"
27
+
28
+ const char *zsv_overwrite_usage_msg[] = {
29
+ APPNAME " - Manage overwrites associated with a CSV file",
30
+ "",
31
+ "Usage:",
32
+ " " APPNAME " <file> <command> [arguments] [options]",
33
+ "",
34
+ "Commands (where <cell> can be <row>-<col> or an Excel-style address):",
35
+ " list : Display all saved overwrite entries",
36
+ " add <cell> <value> : Add an overwrite entry",
37
+ " Example 1: overwrite the first column of the first",
38
+ " non-header row",
39
+ " overwrite mydata.csv add B2 \"new value\"",
40
+ " - or -",
41
+ " overwrite mydata.csv add 1-1 \"new value\"",
42
+ " Example 2: change the header in the second column",
43
+ " to \"ID #\"",
44
+ " overwrite mydata.csv add B1 \"new value\"",
45
+ " - or -",
46
+ " overwrite mydata.csv add 0-1 \"ID #\"",
47
+ " remove <cell> : Remove an overwrite entry",
48
+ " clear : Remove any / all overwrites",
49
+ " bulk-add <datafile> : Bulk add overwrite entries from a CSV or JSON file",
50
+ " bulk-remove <datafile> : Bulk remove overwrite entries from a CSV or JSON file",
51
+ "",
52
+ "Options:",
53
+ " -h,--help : Show this help message",
54
+ " --old-value <value> : For `add` or `remove`, only proceed if the old value",
55
+ " matches the given value",
56
+ " --force. : For `add`, proceed even if an overwrite for the specified",
57
+ " cell already exists",
58
+ " For `remove`, exit without error even if no overwrite for",
59
+ " the specified cell already exists",
60
+ " --no-timestamp. : For `add`, don't save timestamp when adding an overwrite",
61
+ " --all : For `remove`, remove all overwrites and delete sqlite file",
62
+ " --A1 : For `list`, Display addresses in A1-notation",
63
+ "",
64
+ "Description:",
65
+ " The `overwrite` utility allows you to manage a list of \"overwrites\" associated",
66
+ " with a given CSV input file. Each overwrite entry is a tuple consisting of row,",
67
+ " column, original value, and new value, along with optional timestamp and author",
68
+ " metadata.",
69
+ "",
70
+ " Overwrite data for a given input file `/path/to/my-data.csv` is stored in the \"over‐",
71
+ " writes\" table of `/path/to/.zsv/data/my-data.csv/overwrite.sqlite3`.",
72
+ "",
73
+ " For bulk operations, the data file must be a CSV with \"row\", \"col\" and \"value\" columns",
74
+ " and may optionally include \"old value\", \"timestamp\" and/or \"author\"",
75
+ NULL};
76
+
77
+ static int zsv_overwrite_usage(void) {
78
+ for (size_t i = 0; zsv_overwrite_usage_msg[i]; i++)
79
+ fprintf(stdout, "%s\n", zsv_overwrite_usage_msg[i]);
80
+ return 1;
81
+ }
82
+
83
+ static char *row_col_to_a1(size_t col, size_t row) {
84
+ char buffer[64];
85
+ int index = 63;
86
+ buffer[index] = '\0';
87
+
88
+ while (1) {
89
+ if (index == 0)
90
+ return NULL;
91
+ col--;
92
+ buffer[--index] = 'A' + (col % 26);
93
+ col /= 26;
94
+ if (col == 0)
95
+ break;
96
+ }
97
+ // 20 extra bytes for row
98
+ char *result = malloc(strlen(&buffer[index]) + 20 + 1);
99
+ if (result)
100
+ sprintf(result, "%s%zu", &buffer[index], row + 1);
101
+ return result;
102
+ }
103
+
104
+ static int show_all_overwrites(struct zsv_overwrite *data, zsv_csv_writer writer) {
105
+ zsv_writer_cell(writer, 0, (const unsigned char *)"row", 3, 0);
106
+ zsv_writer_cell(writer, 0, (const unsigned char *)"column", 6, 0);
107
+ zsv_writer_cell(writer, 0, (const unsigned char *)"value", 5, 0);
108
+ zsv_writer_cell(writer, 0, (const unsigned char *)"timestamp", 9, 0);
109
+ zsv_writer_cell(writer, 0, (const unsigned char *)"author", 6, 0);
110
+ struct zsv_overwrite_data odata = {.have = 1};
111
+ while ((data->ctx->next(data->ctx, &odata) == zsv_status_ok) && odata.have) {
112
+ if (data->a1) {
113
+ char *a1_ix = row_col_to_a1(odata.col_ix + 1, odata.row_ix);
114
+ if (a1_ix)
115
+ zsv_writer_cell(writer, 1, (unsigned char *)a1_ix, strlen(a1_ix), 0);
116
+ free(a1_ix);
117
+ } else {
118
+ zsv_writer_cell_zu(writer, 1, odata.row_ix);
119
+ zsv_writer_cell_zu(writer, 0, odata.col_ix);
120
+ }
121
+ zsv_writer_cell(writer, 0, odata.val.str, odata.val.len, 0);
122
+ if (odata.timestamp)
123
+ zsv_writer_cell_zu(writer, 0, odata.timestamp);
124
+ else
125
+ zsv_writer_cell(writer, 0, (unsigned char *)"", 0, 0);
126
+ if (odata.author.len > 0 && odata.author.str)
127
+ zsv_writer_cell(writer, 0, odata.author.str, odata.author.len, 0);
128
+ else
129
+ zsv_writer_cell(writer, 0, (unsigned char *)"", 0, 0);
130
+ }
131
+ return 0;
132
+ }
133
+
134
+ struct xl_address {
135
+ size_t row, col;
136
+ };
137
+
138
+ static int parse_xl_address(const char *s, struct xl_address *address) {
139
+ memset(address, 0, sizeof(*address));
140
+ unsigned len = strlen(s);
141
+ for (unsigned i = 0; i < len; i++) {
142
+ char c = s[i];
143
+ if (c >= '0' && c <= '9') {
144
+ if (address->col == 0)
145
+ return 1; // alpha should come before num
146
+ if (address->row == 0 && c == '0')
147
+ return 1; // first num should not be zero
148
+ address->row = address->row * 10 + (c - '0');
149
+ } else if (c >= 'A' && c <= 'Z') {
150
+ if (address->row > 0)
151
+ return 1; // alpha should come before num
152
+ address->col = address->col * 26 + (c - 'A') + 1;
153
+ } else if (c >= 'a' && c <= 'z') {
154
+ if (address->row > 0)
155
+ return 1; // alpha should come before num
156
+ address->col = address->col * 26 + (c - 'a') + 1;
157
+ } else
158
+ break;
159
+ }
160
+ if (address->row > 0 && address->col > 0) {
161
+ address->row--;
162
+ address->col--;
163
+ return 0;
164
+ }
165
+ return 1; // error
166
+ }
167
+
168
+ static int zsv_overwrite_parse_pos(struct zsv_overwrite_data *overwrite, const char *str) {
169
+ // this means it's an excel-style cell, because it does not start with a number for the row
170
+ if (!isdigit(*str)) {
171
+ struct xl_address address;
172
+ if (parse_xl_address(str, &address) != 0)
173
+ return 1;
174
+ overwrite->row_ix = address.row;
175
+ overwrite->col_ix = address.col;
176
+ return 0;
177
+ }
178
+ return sscanf(str, "%zu-%zu", &overwrite->row_ix, &overwrite->col_ix) != 2;
179
+ }
180
+
181
+ int ZSV_MAIN_FUNC(ZSV_COMMAND)(int argc, const char *argv[], struct zsv_opts *opts,
182
+ struct zsv_prop_handler *custom_prop_handler) {
183
+ int err = 0;
184
+ if (argc < 3 || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
185
+ zsv_overwrite_usage();
186
+ return err;
187
+ }
188
+
189
+ struct zsv_overwrite_opts ctx_opts = {0};
190
+ (void)(opts);
191
+ (void)(custom_prop_handler);
192
+
193
+ struct zsv_overwrite_args args = {0};
194
+ // By default, save timestamps
195
+ struct zsv_overwrite_data overwrite = {0};
196
+ overwrite.timestamp = (size_t)time(NULL);
197
+
198
+ args.filepath = (char *)argv[1];
199
+
200
+ for (int i = 2; !err && i < argc; i++) {
201
+ const char *opt = argv[i];
202
+ if (!strcmp(opt, "-f") || !strcmp(opt, "--force")) {
203
+ args.force = 1;
204
+ } else if (!strcmp(opt, "--old-value")) {
205
+ overwrite.old_value.str = (unsigned char *)strdup(argv[++i]);
206
+ overwrite.old_value.len = strlen((const char *)overwrite.old_value.str);
207
+ } else if (!strcmp(opt, "--no-timestamp")) {
208
+ overwrite.timestamp = 0;
209
+ } else if (!strcmp(opt, "--A1")) {
210
+ args.a1 = 1;
211
+ } else if (!strcmp(opt, "list")) {
212
+ args.mode = zsvsheet_mode_list;
213
+ } else if (!strcmp(opt, "clear")) {
214
+ args.mode = zsvsheet_mode_clear;
215
+ } else if (!strcmp(opt, "add")) {
216
+ if (argc - i > 2) {
217
+ args.mode = zsvsheet_mode_add;
218
+ err = zsv_overwrite_parse_pos(&overwrite, argv[++i]);
219
+ overwrite.val.str = (unsigned char *)strdup(argv[++i]);
220
+ overwrite.val.len = strlen((const char *)overwrite.val.str);
221
+ if (err || !overwrite.val.str) {
222
+ fprintf(stderr, "Expected row, column, and value\n");
223
+ err = 1;
224
+ }
225
+ } else {
226
+ fprintf(stderr, "Expected row, column, and value\n");
227
+ err = 1;
228
+ }
229
+ } else if (!strcmp(opt, "remove")) {
230
+ if (argc - i > 1) {
231
+ args.mode = zsvsheet_mode_remove;
232
+ if (!strcmp(argv[++i], "--all"))
233
+ args.all = 1;
234
+ else
235
+ err = zsv_overwrite_parse_pos(&overwrite, argv[i]);
236
+ if (err) {
237
+ fprintf(stderr, "Expected row and column\n");
238
+ }
239
+ } else {
240
+ fprintf(stderr, "Expected row and column\n");
241
+ err = 1;
242
+ }
243
+ } else if (!strcmp(opt, "bulk-add")) {
244
+ if (argc - i > 1) {
245
+ args.mode = zsvsheet_mode_bulk;
246
+ args.bulk_file = (unsigned char *)strdup(argv[++i]);
247
+ args.next = zsv_overwrite_writer_add;
248
+ } else {
249
+ fprintf(stderr, "Expected overwrite filename\n");
250
+ err = 1;
251
+ }
252
+ } else if (!strcmp(opt, "bulk-remove")) {
253
+ if (argc - i > 1) {
254
+ args.mode = zsvsheet_mode_bulk;
255
+ args.bulk_file = (unsigned char *)strdup(argv[++i]);
256
+ args.next = zsv_overwrite_writer_remove;
257
+ } else {
258
+ fprintf(stderr, "Expected overwrite filename\n");
259
+ err = 1;
260
+ }
261
+ } else {
262
+ err = 1;
263
+ if (*opt == '-')
264
+ fprintf(stderr, "Unrecognized option: %s\n", opt);
265
+ else
266
+ fprintf(stderr, "Unrecognized command or argument: %s\n", opt);
267
+ }
268
+ }
269
+
270
+ args.overwrite = &overwrite;
271
+
272
+ char *overwrites_fn =
273
+ (char *)zsv_cache_filepath((const unsigned char *)args.filepath, zsv_cache_type_overwrite, 0, 0);
274
+ ctx_opts.src = (char *)overwrites_fn;
275
+ struct zsv_overwrite *data = zsv_overwrite_writer_new(&args, &ctx_opts);
276
+ free(overwrites_fn);
277
+
278
+ if (!err && data) {
279
+ if (data->mode == zsvsheet_mode_list)
280
+ err = show_all_overwrites(data, data->writer);
281
+ else if (data->mode == zsvsheet_mode_clear)
282
+ err = zsv_overwrite_writer_clear(data);
283
+ else if (data->mode == zsvsheet_mode_add && data->ctx->sqlite3.db)
284
+ err = zsv_overwrite_writer_add(data);
285
+ else if (data->mode == zsvsheet_mode_remove && data->ctx->sqlite3.db)
286
+ err = zsv_overwrite_writer_remove(data);
287
+ else if (data->mode == zsvsheet_mode_bulk && data->ctx->sqlite3.db) {
288
+ err = zsv_overwrite_writer_bulk(data);
289
+ }
290
+ }
291
+
292
+ zsv_overwrite_writer_delete(data);
293
+
294
+ return err;
295
+ }