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,29 @@
1
+ #ifndef ZSVSHEET_TRANSFORMATION_H
2
+ #define ZSVSHEET_TRANSFORMATION_H
3
+
4
+ #include "zsv.h"
5
+ #include "zsv/utils/writer.h"
6
+ #include "zsv/ext/sheet.h"
7
+
8
+ struct zsvsheet_transformation_opts {
9
+ /**
10
+ * As usual the zsv_opts used during parsing, but note that the
11
+ * ctx passed to the row_handler is wrapped in zsvsheet_transformation.
12
+ */
13
+ struct zsv_opts zsv_opts;
14
+ struct zsv_prop_handler *custom_prop_handler;
15
+ const char *input_filename;
16
+ void (*on_done)(zsvsheet_transformation trn);
17
+ struct zsvsheet_ui_buffer *ui_buffer;
18
+ struct zsv_index *index;
19
+ };
20
+
21
+ enum zsv_status zsvsheet_transformation_new(struct zsvsheet_transformation_opts, zsvsheet_transformation *);
22
+ void zsvsheet_transformation_delete(zsvsheet_transformation);
23
+
24
+ zsv_parser zsvsheet_transformation_parser(zsvsheet_transformation);
25
+ zsv_csv_writer zsvsheet_transformation_writer(zsvsheet_transformation);
26
+ const char *zsvsheet_transformation_filename(zsvsheet_transformation);
27
+ void *zsvsheet_transformation_user_context(zsvsheet_transformation trn);
28
+
29
+ #endif
@@ -0,0 +1,266 @@
1
+ #include <unistd.h> // unlink()
2
+ #include <pthread.h>
3
+ #include "../utils/index.h"
4
+ #include "index.h"
5
+
6
+ struct uib_parse_errs {
7
+ size_t count;
8
+ size_t max;
9
+ char **errors;
10
+ };
11
+
12
+ static void uib_parse_errs_init(struct uib_parse_errs *p, size_t max) {
13
+ memset(p, 0, sizeof(*p));
14
+ p->max = max;
15
+ }
16
+
17
+ static void uib_parse_errs_clear(struct uib_parse_errs *parse_errs) {
18
+ for (size_t i = 0; i < parse_errs->count; i++)
19
+ free(parse_errs->errors[i]);
20
+ free(parse_errs->errors);
21
+
22
+ // reset so it can be used again
23
+ size_t max = parse_errs->max;
24
+ uib_parse_errs_init(parse_errs, max);
25
+ }
26
+
27
+ struct zsvsheet_ui_buffer {
28
+ char *filename;
29
+ char *data_filename; // if this dataset was filtered from another, the filtered data is stored here
30
+ struct zsv_opts zsv_opts; // options to use when opening this file
31
+ struct zsvsheet_ui_buffer *prior; // previous buffer in this stack. If null, this is the first buffer in the stack
32
+ struct zsvsheet_screen_buffer_opts *buff_opts;
33
+ zsvsheet_screen_buffer_t buffer;
34
+ size_t cursor_row;
35
+ size_t cursor_col;
36
+ struct zsvsheet_input_dimensions dimensions;
37
+ struct zsv_index *index;
38
+ struct zsvsheet_index_opts *ixopts;
39
+ pthread_mutex_t mutex;
40
+ pthread_t worker_thread;
41
+
42
+ // input_offset: location within the input from which the buffer is read
43
+ // i.e. if row = 5, col = 3, the buffer data starts from cell D6
44
+ struct zsvsheet_rowcol input_offset;
45
+
46
+ // buff_offset: location within the buffer from which the data is
47
+ // displayed on the screen
48
+ struct zsvsheet_rowcol buff_offset;
49
+ size_t buff_used_rows;
50
+ char *status;
51
+
52
+ void *ext_ctx; // extension context via zsvsheet_ext_set_ctx() zsvsheet_ext_get_ctx()
53
+
54
+ // cleanup callback set by zsvsheet_ext_get_ctx()
55
+ // if non-null, called when buffer is closed
56
+ zsvsheet_status (*on_newline)(zsvsheet_proc_context_t);
57
+ void (*ext_on_close)(void *);
58
+
59
+ enum zsv_ext_status (*get_cell_attrs)(void *, zsvsheet_cell_attr_t *, size_t, size_t, size_t);
60
+
61
+ struct uib_parse_errs parse_errs;
62
+
63
+ unsigned char index_ready : 1;
64
+ unsigned char rownum_col_offset : 1;
65
+ unsigned char index_started : 1;
66
+ unsigned char has_row_num : 1;
67
+ unsigned char mutex_inited : 1;
68
+ unsigned char write_in_progress : 1;
69
+ unsigned char write_done : 1;
70
+ unsigned char worker_active : 1;
71
+ unsigned char worker_cancelled : 1;
72
+ unsigned char _ : 7;
73
+ };
74
+
75
+ void zsvsheet_ui_buffer_create_worker(struct zsvsheet_ui_buffer *ub, void *(*start_func)(void *), void *arg) {
76
+ assert(!ub->worker_active);
77
+ assert(ub->mutex_inited);
78
+
79
+ pthread_create(&ub->worker_thread, NULL, start_func, arg);
80
+ ub->worker_active = 1;
81
+ }
82
+
83
+ void zsvsheet_ui_buffer_set_status(struct zsvsheet_ui_buffer *ub, const char *status) {
84
+ free(ub->status);
85
+ ub->status = status ? strdup(status) : NULL;
86
+ }
87
+
88
+ int zsvsheet_ui_buffer_index_ready(struct zsvsheet_ui_buffer *ub, char skip_lock) {
89
+ if (!skip_lock)
90
+ pthread_mutex_lock(&ub->mutex);
91
+ int rc = !!ub->index_ready;
92
+ if (!skip_lock)
93
+ pthread_mutex_unlock(&ub->mutex);
94
+ return rc;
95
+ }
96
+
97
+ void zsvsheet_ui_buffer_join_worker(struct zsvsheet_ui_buffer *ub) {
98
+ assert(ub->worker_active);
99
+ assert(ub->mutex_inited);
100
+
101
+ pthread_join(ub->worker_thread, NULL);
102
+ ub->worker_active = 0;
103
+ }
104
+
105
+ void zsvsheet_ui_buffer_delete(struct zsvsheet_ui_buffer *ub) {
106
+ if (ub) {
107
+ if (ub->worker_active) {
108
+ pthread_mutex_lock(&ub->mutex);
109
+ ub->worker_cancelled = 1;
110
+ pthread_mutex_unlock(&ub->mutex);
111
+
112
+ zsvsheet_ui_buffer_join_worker(ub);
113
+ }
114
+ if (ub->ext_on_close)
115
+ ub->ext_on_close(ub->ext_ctx);
116
+ zsvsheet_screen_buffer_delete(ub->buffer);
117
+ if (ub->mutex_inited)
118
+ pthread_mutex_destroy(&ub->mutex);
119
+ if (ub->ixopts)
120
+ ub->ixopts->uib = NULL;
121
+ zsv_index_delete(ub->index);
122
+ free(ub->status);
123
+ if (ub->data_filename)
124
+ unlink(ub->data_filename);
125
+ uib_parse_errs_clear(&ub->parse_errs);
126
+ free(ub->data_filename);
127
+ free(ub->filename);
128
+ free(ub);
129
+ }
130
+ }
131
+
132
+ struct zsvsheet_ui_buffer_opts {
133
+ struct zsvsheet_screen_buffer_opts *buff_opts;
134
+ const char *filename;
135
+ const char *data_filename;
136
+ struct zsv_opts zsv_opts; // options to use when opening this file
137
+ char no_rownum_col_offset;
138
+ char write_after_open;
139
+ };
140
+
141
+ struct zsvsheet_ui_buffer *zsvsheet_ui_buffer_new(zsvsheet_screen_buffer_t buffer,
142
+ struct zsvsheet_ui_buffer_opts *uibopts) {
143
+ struct zsvsheet_ui_buffer *uib = calloc(1, sizeof(*uib));
144
+ pthread_mutex_t init = PTHREAD_MUTEX_INITIALIZER;
145
+ if (uib) {
146
+ uib->buffer = buffer;
147
+ uib->mutex_inited = 1;
148
+ memcpy(&uib->mutex, &init, sizeof(init));
149
+ if (!(uibopts && uibopts->no_rownum_col_offset))
150
+ uib->rownum_col_offset = 1;
151
+ if (uibopts) {
152
+ if (uibopts->filename && !(uib->filename = strdup(uibopts->filename))) {
153
+ zsvsheet_ui_buffer_delete(uib);
154
+ return NULL;
155
+ }
156
+ if (uibopts->data_filename && !(uib->data_filename = strdup(uibopts->data_filename))) {
157
+ zsvsheet_ui_buffer_delete(uib);
158
+ return NULL;
159
+ }
160
+ uib->zsv_opts = uibopts->zsv_opts;
161
+ uib->write_in_progress = uibopts->write_after_open;
162
+ }
163
+ }
164
+ return uib;
165
+ }
166
+
167
+ int zsvsheet_ui_buffer_update_cell_attr(struct zsvsheet_ui_buffer *uib) {
168
+ if (uib && uib->buffer && uib->buffer->opts.rows && uib->buffer->cols) {
169
+ size_t row_sz = uib->buffer->cols * sizeof(*uib->buffer->cell_attrs);
170
+ if (uib->get_cell_attrs) {
171
+ if (!uib->buffer->cell_attrs) {
172
+ uib->buffer->cell_attrs = calloc(uib->buffer->opts.rows, row_sz);
173
+ if (!uib->buffer->cell_attrs)
174
+ return ENOMEM;
175
+ }
176
+ memset(uib->buffer->cell_attrs, 0, uib->buffer->opts.rows * row_sz);
177
+ uib->get_cell_attrs(uib->ext_ctx, uib->buffer->cell_attrs, uib->input_offset.row, uib->buff_used_rows,
178
+ uib->buffer->cols);
179
+ }
180
+ }
181
+ return 0;
182
+ }
183
+
184
+ static int uib_parse_errs_printf(void *uib_parse_errs_ptr, const char *fmt, ...) {
185
+ struct uib_parse_errs *parse_errs = uib_parse_errs_ptr;
186
+ char *err_msg = NULL;
187
+ int n = 0;
188
+ if (parse_errs->count < parse_errs->max) {
189
+ va_list argv;
190
+ va_start(argv, fmt);
191
+ n = vasprintf(&err_msg, fmt, argv);
192
+ va_end(argv);
193
+ if (!(n <= 0 || !err_msg || !*err_msg)) {
194
+ if (!parse_errs->errors)
195
+ parse_errs->errors = (char **)calloc(parse_errs->max + 1, sizeof(*parse_errs->errors));
196
+ if (parse_errs->errors) {
197
+ parse_errs->errors[parse_errs->count++] = err_msg;
198
+ return n;
199
+ }
200
+ }
201
+ } else if (parse_errs->count > 0 && parse_errs->count == parse_errs->max && parse_errs->errors) {
202
+ err_msg = strdup("Additional errors ignored");
203
+ if (err_msg) {
204
+ parse_errs->errors[parse_errs->count++] = err_msg;
205
+ return strlen(err_msg);
206
+ }
207
+ }
208
+ free(err_msg);
209
+ return n;
210
+ }
211
+
212
+ enum zsvsheet_priv_status zsvsheet_ui_buffer_new_blank(struct zsvsheet_ui_buffer **uibp) {
213
+ enum zsvsheet_priv_status status;
214
+ zsvsheet_screen_buffer_t buffer = zsvsheet_screen_buffer_new(1, NULL, &status);
215
+ if (buffer) {
216
+ *uibp = zsvsheet_ui_buffer_new(buffer, NULL);
217
+ return zsvsheet_priv_status_ok;
218
+ }
219
+ return zsvsheet_priv_status_error;
220
+ }
221
+
222
+ void zsvsheet_ui_buffers_delete(struct zsvsheet_ui_buffer *ub) {
223
+ for (struct zsvsheet_ui_buffer *prior; ub; ub = prior) {
224
+ prior = ub->prior;
225
+ zsvsheet_ui_buffer_delete(ub);
226
+ }
227
+ }
228
+
229
+ void zsvsheet_ui_buffer_push(struct zsvsheet_ui_buffer **base, struct zsvsheet_ui_buffer **current,
230
+ struct zsvsheet_ui_buffer *element) {
231
+ if (*base == NULL)
232
+ *base = *current = element;
233
+ else {
234
+ element->prior = *current;
235
+ *current = element;
236
+ }
237
+ }
238
+
239
+ /*
240
+ * zsvsheet_ui_buffer_pop: pop the top off the stack
241
+ * return 1 if popped, 0 if nothing popped
242
+ * if @popped is non-NULL, set it to the popped element
243
+ * otherwise delete the popped element
244
+ */
245
+ int zsvsheet_ui_buffer_pop(struct zsvsheet_ui_buffer **base, struct zsvsheet_ui_buffer **current,
246
+ struct zsvsheet_ui_buffer **popped) {
247
+ if (*current) {
248
+ struct zsvsheet_ui_buffer *old_current = *current;
249
+ if (old_current->prior)
250
+ *current = old_current->prior;
251
+ else
252
+ *base = NULL;
253
+ if (popped)
254
+ *popped = old_current;
255
+ else
256
+ zsvsheet_ui_buffer_delete(old_current);
257
+ return 1;
258
+ }
259
+ return 0;
260
+ }
261
+
262
+ static const char *zsvsheet_ui_buffer_get_header(struct zsvsheet_ui_buffer *uib, size_t col) {
263
+ struct zsvsheet_screen_buffer *sb = uib->buffer;
264
+
265
+ return (char *)zsvsheet_screen_buffer_cell_display(sb, 0, col);
266
+ }
@@ -0,0 +1,9 @@
1
+
2
+ const char *zsvsheet_usage_msg[] = {
3
+ APPNAME ": opens interactive spreadsheet-like viewer in the console", "", "Usage: " APPNAME " filename", "", NULL,
4
+ };
5
+
6
+ static void zsvsheet_usage(void) {
7
+ for (size_t i = 0; zsvsheet_usage_msg[i]; i++)
8
+ fprintf(stdout, "%s\n", zsvsheet_usage_msg[i]);
9
+ }
@@ -0,0 +1,60 @@
1
+ #include <utf8proc.h>
2
+
3
+ static int has_multibyte_char(const char *utf8, size_t len) {
4
+ // this can be further optimized with simd
5
+ // but doing so is probably not noticeably impactful
6
+ // since we only do this for the finite number of cells on the screen
7
+ uint64_t x;
8
+ while (len >= 8) {
9
+ len -= 8;
10
+ // Copy the first 8 bytes into 64-bit integers
11
+ memcpy(&x, utf8, sizeof(x));
12
+
13
+ // Check if any high bits are set
14
+ if ((x & 0x8080808080808080ULL) != 0)
15
+ return 1;
16
+ utf8 += 8;
17
+ }
18
+ if (len) {
19
+ x = 0;
20
+ memcpy(&x, utf8, len);
21
+ if ((x & 0x8080808080808080ULL) != 0)
22
+ return 1;
23
+ }
24
+ return 0;
25
+ }
26
+
27
+ static size_t is_newline(const unsigned char *utf8, int wchar_len) {
28
+ return (wchar_len == 1 && strchr("\n\r", utf8[0]));
29
+ // add multibyte newline check?
30
+ }
31
+
32
+ static size_t utf8_bytes_up_to_max_width_and_replace_newlines(unsigned char *str1, size_t len1, size_t max_width,
33
+ size_t *used_width, int *err) {
34
+ utf8proc_int32_t codepoint1;
35
+ utf8proc_ssize_t bytes_read1;
36
+ size_t width_so_far = *used_width = 0;
37
+ int this_char_width = 0;
38
+ size_t bytes_so_far = 0;
39
+ while (bytes_so_far < len1) {
40
+ bytes_read1 = utf8proc_iterate((utf8proc_uint8_t *)str1 + bytes_so_far, len1, &codepoint1);
41
+ if (!bytes_read1) {
42
+ bytes_read1 = 1;
43
+ *err = 1;
44
+ this_char_width = 1;
45
+ } else if (is_newline(str1 + bytes_so_far, bytes_read1)) {
46
+ memset((void *)(str1 + bytes_so_far), ' ', bytes_read1);
47
+ continue;
48
+ } else {
49
+ this_char_width = utf8proc_charwidth(codepoint1);
50
+ if (width_so_far + this_char_width > max_width) {
51
+ *used_width = width_so_far;
52
+ return bytes_so_far;
53
+ }
54
+ }
55
+ width_so_far += this_char_width;
56
+ bytes_so_far += bytes_read1;
57
+ }
58
+ *used_width = width_so_far;
59
+ return bytes_so_far;
60
+ }