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,166 @@
1
+ #include <stdlib.h>
2
+ #include <pthread.h>
3
+ #include <string.h>
4
+ #include <zsv/utils/mem.h>
5
+ #include <zsv/ext/sheet.h>
6
+ #include "transformation.h"
7
+ #include "handlers_internal.h"
8
+
9
+ #ifdef HAVE_PCRE2_8
10
+ #include "../utils/pcre2-8/pcre2-8.h"
11
+ #endif
12
+
13
+ struct filtered_file_ctx {
14
+ char *filter;
15
+ size_t filter_len;
16
+ #ifdef HAVE_PCRE2_8
17
+ regex_handle_t *regex;
18
+ #endif
19
+ size_t row_num; // 1-based row number (1 = header row, 2 = first data row)
20
+ size_t passed;
21
+ size_t single_row_ix_plus_1;
22
+ unsigned char seen_header : 1;
23
+ unsigned char has_row_num : 1;
24
+ unsigned char _ : 7;
25
+ };
26
+
27
+ // zsvsheet_nullify_row_buff: return 1 if row has overwrite
28
+ static int zsvsheet_nullify_row_buff(zsv_parser z) {
29
+ unsigned int j = zsv_cell_count(z);
30
+ unsigned char *end = NULL;
31
+ int have_overwrite = 0;
32
+ for (unsigned int i = 0; i < j; i++) {
33
+ struct zsv_cell cell = zsv_get_cell(z, i);
34
+ if (cell.overwritten)
35
+ have_overwrite = 1;
36
+ if (end) {
37
+ while (end < cell.str) {
38
+ *end = '\0';
39
+ end++;
40
+ }
41
+ }
42
+ end = cell.str + cell.len;
43
+ }
44
+ return have_overwrite;
45
+ }
46
+
47
+ static void zsvsheet_save_filtered_file_row_handler(zsvsheet_transformation trn) {
48
+ struct filtered_file_ctx *ctx = zsvsheet_transformation_user_context(trn);
49
+ zsv_parser parser = zsvsheet_transformation_parser(trn);
50
+ zsv_csv_writer writer = zsvsheet_transformation_writer(trn);
51
+ size_t col_count = zsv_cell_count(parser);
52
+ const size_t single_row_ix_plus_1 = ctx->single_row_ix_plus_1;
53
+
54
+ ctx->row_num++;
55
+ if (col_count == 0)
56
+ return;
57
+ if (ctx->seen_header) {
58
+ size_t start_ix = 0;
59
+ if (single_row_ix_plus_1) {
60
+ col_count = single_row_ix_plus_1;
61
+ start_ix = single_row_ix_plus_1 - 1;
62
+ if (ctx->has_row_num)
63
+ col_count++, start_ix++;
64
+ }
65
+ int have_overwrite = single_row_ix_plus_1 ? 0 : zsvsheet_nullify_row_buff(parser);
66
+ if (have_overwrite || single_row_ix_plus_1) {
67
+ // we need to do this cell by cell
68
+ for (unsigned int i = start_ix; i < col_count; i++) {
69
+ struct zsv_cell cell = zsv_get_cell(parser, i);
70
+ const unsigned char *start = cell.str;
71
+ const unsigned char *end = cell.str + cell.len;
72
+ if (cell.len) {
73
+ #ifdef HAVE_PCRE2_8
74
+ if (ctx->regex) {
75
+ if (!zsv_pcre2_8_match(ctx->regex, start, end - start))
76
+ return; // no match: don't save this row
77
+ } else
78
+ #endif
79
+ if (!memmem(start, end - start, ctx->filter, ctx->filter_len))
80
+ return; // no match: don't save this row
81
+ }
82
+ }
83
+ } else {
84
+ struct zsv_cell first_cell = zsv_get_cell(parser, 0);
85
+ struct zsv_cell last_cell = zsv_get_cell(parser, col_count - 1);
86
+ const unsigned char *start = first_cell.str;
87
+ const unsigned char *end = last_cell.str + last_cell.len;
88
+ if (end > start) {
89
+ #ifdef HAVE_PCRE2_8
90
+ if (ctx->regex) {
91
+ if (!zsv_pcre2_8_match(ctx->regex, start, end - start))
92
+ return; // no match: don't save this row
93
+ } else
94
+ #endif
95
+ if (!memmem(start, end - start, ctx->filter, ctx->filter_len))
96
+ return; // no match: don't save this row
97
+ }
98
+ }
99
+ } else {
100
+ struct zsv_cell first_cell = zsv_get_cell(parser, 0);
101
+ ctx->seen_header = 1;
102
+ /// just use uibuff->has_row_num?
103
+ if (first_cell.len == ZSVSHEET_ROWNUM_HEADER_LEN && !memcmp(first_cell.str, ZSVSHEET_ROWNUM_HEADER, first_cell.len))
104
+ ctx->has_row_num = 1;
105
+ }
106
+
107
+ char row_started = 0;
108
+ if (!ctx->has_row_num) {
109
+ // create our own rownum column
110
+ row_started = 1;
111
+ if (ctx->row_num == 1)
112
+ zsv_writer_cell_s(writer, 1, (const unsigned char *)"Row #", 0); // to do: consolidate "Row #"
113
+ else
114
+ zsv_writer_cell_zu(writer, 1, ctx->row_num - 1);
115
+ }
116
+
117
+ col_count = zsv_cell_count(parser);
118
+ for (size_t i = 0; i < col_count; i++) {
119
+ struct zsv_cell cell = zsv_get_cell(parser, i);
120
+ zsv_writer_cell(writer, i == 0 && row_started == 0, cell.str, cell.len, cell.quoted);
121
+ }
122
+
123
+ ctx->passed++;
124
+ }
125
+
126
+ static void zsvsheet_filter_file_on_done(zsvsheet_transformation trn) {
127
+ struct filtered_file_ctx *ctx = zsvsheet_transformation_user_context(trn);
128
+ struct zsvsheet_ui_buffer *uib = trn->ui_buffer;
129
+
130
+ char *status = NULL;
131
+ asprintf(&status, "(%zu filtered rows) ", ctx->passed - 1);
132
+
133
+ pthread_mutex_lock(&uib->mutex);
134
+ char *old_status = uib->status;
135
+ uib->status = status;
136
+ pthread_mutex_unlock(&uib->mutex);
137
+
138
+ free(old_status);
139
+ #ifdef HAVE_PCRE2_8
140
+ zsv_pcre2_8_delete(ctx->regex);
141
+ #endif
142
+ free(ctx->filter);
143
+ }
144
+
145
+ static enum zsvsheet_status zsvsheet_filter_file(zsvsheet_proc_context_t proc_ctx, const char *row_filter,
146
+ size_t single_row_ix_plus_1) {
147
+ struct filtered_file_ctx ctx = {
148
+ .seen_header = 0,
149
+ .row_num = 0,
150
+ .passed = 0,
151
+ .has_row_num = 0,
152
+ .filter = strdup(row_filter),
153
+ .filter_len = strlen(row_filter),
154
+ #ifdef HAVE_PCRE2_8
155
+ .regex = row_filter && *row_filter == '/' && row_filter[1] ? zsv_pcre2_8_new(row_filter + 1, 0) : NULL,
156
+ .single_row_ix_plus_1 = single_row_ix_plus_1,
157
+ #endif
158
+ };
159
+ struct zsvsheet_buffer_transformation_opts opts = {
160
+ .user_context = zsv_memdup(&ctx, sizeof(ctx)),
161
+ .row_handler = zsvsheet_save_filtered_file_row_handler,
162
+ .on_done = zsvsheet_filter_file_on_done,
163
+ };
164
+
165
+ return zsvsheet_push_transformation(proc_ctx, opts);
166
+ }
@@ -0,0 +1,214 @@
1
+ #include "file.h"
2
+ #include "procedure.h"
3
+
4
+ static void zsvsheet_key_handlers_delete(struct zsvsheet_key_data **root, struct zsvsheet_key_data ***nextp) {
5
+ for (struct zsvsheet_key_data *next, *e = *root; e; e = next) {
6
+ next = e->next;
7
+ free(e->long_name);
8
+ free(e);
9
+ }
10
+ *root = NULL;
11
+ *nextp = &(*root)->next;
12
+ }
13
+
14
+ struct zsvsheet_key_data *zsvsheet_get_registered_key_handler(int ch, const char *long_name,
15
+ struct zsvsheet_key_data *root) {
16
+ for (struct zsvsheet_key_data *kh = root; kh; kh = kh->next)
17
+ if (ch == kh->ch || (long_name && kh->long_name && !strcmp(long_name, kh->long_name)))
18
+ return kh;
19
+ return NULL;
20
+ }
21
+
22
+ /****** API ******/
23
+
24
+ /**
25
+ * Set the subcommand prompt
26
+ */
27
+ zsvsheet_status zsvsheet_subcommand_prompt(zsvsheet_subcommand_context_t ctx, const char *fmt, ...) {
28
+ va_list argv;
29
+ va_start(argv, fmt);
30
+ int n = vsnprintf(ctx->prompt, sizeof(ctx->prompt), fmt, argv);
31
+ va_end(argv);
32
+ if (n > 0 && (size_t)n < sizeof(ctx->prompt))
33
+ return zsvsheet_status_ok;
34
+ return zsvsheet_status_error;
35
+ }
36
+
37
+ /**
38
+ * Set a status message
39
+ */
40
+ zsvsheet_status zsvsheet_set_status(struct zsvsheet_proc_context *ctx, const char *fmt, ...) {
41
+ struct zsvsheet_sheet_context *state = (struct zsvsheet_sheet_context *)ctx->subcommand_context;
42
+ va_list argv;
43
+ va_start(argv, fmt);
44
+ vsnprintf(zsvsheet_status_text, sizeof(zsvsheet_status_text), fmt, argv);
45
+ va_end(argv);
46
+ // note: if (n < (int)sizeof(zsvsheet_status_text)), then we just ignore
47
+ zsvsheet_display_status_text(state->display_info.dimensions);
48
+ return zsvsheet_status_ok;
49
+ }
50
+
51
+ /**
52
+ * Get the key press that triggered this subcommand handler
53
+ */
54
+ int zsvsheet_ext_keypress(zsvsheet_proc_context_t ctx) {
55
+ if (ctx && ctx->invocation.type == zsvsheet_proc_invocation_type_keypress)
56
+ return ctx->invocation.u.keypress.ch;
57
+ return -1;
58
+ }
59
+
60
+ /**
61
+ * Get the current buffer
62
+ */
63
+ zsvsheet_buffer_t zsvsheet_buffer_current(struct zsvsheet_proc_context *ctx) {
64
+ struct zsvsheet_sheet_context *state = (struct zsvsheet_sheet_context *)ctx->subcommand_context;
65
+ return state && state->display_info.ui_buffers.current ? *state->display_info.ui_buffers.current : NULL;
66
+ }
67
+
68
+ /**
69
+ * Get the prior buffer
70
+ */
71
+ zsvsheet_buffer_t zsvsheet_buffer_prior(zsvsheet_buffer_t b) {
72
+ struct zsvsheet_ui_buffer *uib = b;
73
+ return uib ? uib->prior : NULL;
74
+ }
75
+
76
+ /**
77
+ * Get the filename associated with a buffer
78
+ */
79
+ const char *zsvsheet_buffer_filename(zsvsheet_buffer_t h) {
80
+ struct zsvsheet_ui_buffer *uib = h;
81
+ return uib ? uib->filename : NULL;
82
+ }
83
+
84
+ /**
85
+ * Get the data file associated with a buffer. This might not be the same as the filename,
86
+ * such as when the data has been filtered
87
+ */
88
+ const char *zsvsheet_buffer_data_filename(zsvsheet_buffer_t h) {
89
+ struct zsvsheet_ui_buffer *uib = h;
90
+ if (uib)
91
+ return uib->data_filename ? uib->data_filename : uib->filename;
92
+ return NULL;
93
+ }
94
+
95
+ /**
96
+ * Set custom handler on Enter key press
97
+ *
98
+ * @return zsv_ext_status_ok on success, else zsv_ext_status error code
99
+ */
100
+ enum zsv_ext_status zsvsheet_buffer_on_newline(zsvsheet_buffer_t h,
101
+ zsvsheet_status (*on_newline)(zsvsheet_proc_context_t)) {
102
+ if (h)
103
+ ((struct zsvsheet_ui_buffer *)h)->on_newline = on_newline;
104
+ return zsv_ext_status_ok;
105
+ }
106
+
107
+ /**
108
+ * Get the currently-selected cell
109
+ */
110
+ zsvsheet_status zsvsheet_buffer_get_selected_cell(zsvsheet_buffer_t h, struct zsvsheet_rowcol *rc) {
111
+ struct zsvsheet_ui_buffer *uib = h;
112
+ if (!uib)
113
+ return zsvsheet_status_error;
114
+ rc->row = uib->cursor_row + uib->input_offset.row + uib->buff_offset.row;
115
+ rc->col = uib->cursor_col + uib->input_offset.col + uib->buff_offset.col;
116
+ return zsvsheet_status_ok;
117
+ }
118
+
119
+ /**
120
+ * Set custom context
121
+ * @param on_close optional callback to invoke when the buffer is closed
122
+ *
123
+ * @return zsv_ext_status_ok on success, else zsv_ext_status error code
124
+ */
125
+ enum zsv_ext_status zsvsheet_buffer_set_ctx(zsvsheet_buffer_t h, void *ctx, void (*on_close)(void *)) {
126
+ if (h) {
127
+ // TO DO: return zsv_ext_status_not_permitted if this buffer is protected and the caller is not authorized
128
+ struct zsvsheet_ui_buffer *uib = h;
129
+ uib->ext_ctx = ctx;
130
+ uib->ext_on_close = on_close;
131
+ }
132
+ return zsv_ext_status_ok;
133
+ }
134
+
135
+ /**
136
+ * Get custom context previously set via zsvsheet_buffer_set_ctx()
137
+ */
138
+ enum zsv_ext_status zsvsheet_buffer_get_ctx(zsvsheet_buffer_t h, void **ctx_out) {
139
+ // TO DO: return zsv_ext_status_not_permitted if this buffer is protected and the caller is not authorized
140
+ *ctx_out = h ? ((struct zsvsheet_ui_buffer *)h)->ext_ctx : NULL;
141
+ return zsv_ext_status_ok;
142
+ }
143
+
144
+ /** Set callback for fetching cell attributes **/
145
+ void zsvsheet_buffer_set_cell_attrs(zsvsheet_buffer_t h,
146
+ enum zsv_ext_status (*get_cell_attrs)(void *ext_ctx, zsvsheet_cell_attr_t *,
147
+ size_t start_row, size_t row_count,
148
+ size_t col_count)) {
149
+ if (h) {
150
+ struct zsvsheet_ui_buffer *buff = h;
151
+ buff->get_cell_attrs = get_cell_attrs;
152
+ zsvsheet_ui_buffer_update_cell_attr(buff);
153
+ }
154
+ }
155
+
156
+ /** Get zsv_opts use to open the buffer's data file **/
157
+ struct zsv_opts zsvsheet_buffer_get_zsv_opts(zsvsheet_buffer_t h) {
158
+ if (h) {
159
+ struct zsvsheet_ui_buffer *buff = h;
160
+ return buff->zsv_opts;
161
+ }
162
+ struct zsv_opts opts = {0};
163
+ return opts;
164
+ }
165
+
166
+ /**
167
+ * Get information about the type and state of the buffer and its backing file.
168
+ *
169
+ * This returns a copy of the information. Properties relating to the index and transformations
170
+ * are updated by background threads and may be stale upon return. However they only ever
171
+ * transition from false to true.
172
+ */
173
+ struct zsvsheet_buffer_info_internal zsvsheet_buffer_info_internal(zsvsheet_buffer_t h) {
174
+ struct zsvsheet_buffer_info_internal info = {0};
175
+
176
+ if (h) {
177
+ struct zsvsheet_ui_buffer *b = h;
178
+
179
+ pthread_mutex_lock(&b->mutex);
180
+ info.index_started = b->index_started;
181
+ info.index_ready = b->index_ready;
182
+ info.write_in_progress = b->write_in_progress;
183
+ info.write_done = b->write_done;
184
+ pthread_mutex_unlock(&b->mutex);
185
+ }
186
+
187
+ return info;
188
+ }
189
+
190
+ struct zsvsheet_buffer_data zsvsheet_buffer_info(zsvsheet_buffer_t h) {
191
+ struct zsvsheet_buffer_data d = {0};
192
+ struct zsvsheet_ui_buffer *b = h;
193
+ if (b) {
194
+ d.has_row_num = b->has_row_num;
195
+ }
196
+ return d;
197
+ }
198
+
199
+ /**
200
+ * Get the corresponding cell attributes for the given profile
201
+ */
202
+ zsvsheet_cell_attr_t zsvsheet_cell_profile_attrs(enum zsvsheet_cell_profile_t t) {
203
+ switch (t) {
204
+ case zsvsheet_cell_attr_profile_link:
205
+ #ifndef A_ITALIC
206
+ return A_BOLD;
207
+ #else
208
+ return A_ITALIC | A_BOLD;
209
+ #endif
210
+ default:
211
+ break;
212
+ }
213
+ return zsvsheet_cell_attr_profile_none;
214
+ }
@@ -0,0 +1,128 @@
1
+ #ifndef ZSVSHEET_HANDLER_INTERNAL_H
2
+ #define ZSVSHEET_HANDLER_INTERNAL_H
3
+
4
+ struct zsvsheet_context {
5
+ const char *subcommand_value; // e.g. "/path/to/myfile.csv"
6
+ int ch; // key press value from getch()
7
+ struct {
8
+ struct zsvsheet_ui_buffer **base;
9
+ struct zsvsheet_ui_buffer **current;
10
+ } ui_buffers;
11
+ const struct zsvsheet_display_dimensions *display_dims;
12
+ struct zsv_prop_handler *custom_prop_handler;
13
+ };
14
+
15
+ struct zsvsheet_subcommand_context {
16
+ int ch; // keyboard shortcut
17
+ struct zsvsheet_ui_buffer *ui_buffers;
18
+ struct zsvsheet_ui_buffer *current_ui_buffer;
19
+ char prompt[256];
20
+ };
21
+
22
+ struct zsvsheet_key_data {
23
+ struct zsvsheet_key_data *next;
24
+ int ch; // from getch()
25
+ char *long_name; // command name that can be manually invoked via run-command <cmd>
26
+ zsvsheet_status (*subcommand_handler)(zsvsheet_subcommand_context_t);
27
+ zsvsheet_status (*handler)(zsvsheet_context_t);
28
+ };
29
+
30
+ /**
31
+ * Open a tabular file as a new buffer
32
+ */
33
+ zsvsheet_status zsvsheet_open_file(struct zsvsheet_proc_context *ctx, const char *filepath, struct zsv_opts *zopts);
34
+
35
+ /** extension support **/
36
+
37
+ /**
38
+ * Set the subcommand prompt
39
+ */
40
+ zsvsheet_status zsvsheet_subcommand_prompt(zsvsheet_subcommand_context_t ctx, const char *fmt, ...);
41
+
42
+ /**
43
+ * Set a status message
44
+ */
45
+
46
+ zsvsheet_status zsvsheet_set_status(struct zsvsheet_proc_context *ctx, const char *fmt, ...);
47
+
48
+ /**
49
+ * Get the key press that triggered this subcommand handler
50
+ */
51
+ int zsvsheet_ext_keypress(zsvsheet_proc_context_t);
52
+
53
+ /**
54
+ * Get the current buffer
55
+ */
56
+ zsvsheet_buffer_t zsvsheet_buffer_current(struct zsvsheet_proc_context *ctx);
57
+
58
+ /**
59
+ * Get the prior buffer
60
+ */
61
+ zsvsheet_buffer_t zsvsheet_buffer_prior(zsvsheet_buffer_t);
62
+
63
+ /**
64
+ * Get the filename associated with a buffer
65
+ */
66
+ const char *zsvsheet_buffer_filename(zsvsheet_buffer_t h);
67
+
68
+ /**
69
+ * Get the data file associated with a buffer. This might not be the same as the filename,
70
+ * such as when the data has been filtered
71
+ */
72
+ const char *zsvsheet_buffer_data_filename(zsvsheet_buffer_t h);
73
+
74
+ /**
75
+ * Set custom context
76
+ * @param on_close optional callback to invoke when the buffer is closed
77
+ *
78
+ * @return zsv_ext_status_ok on success, else zsv_ext_status error code
79
+ */
80
+ enum zsv_ext_status zsvsheet_buffer_set_ctx(zsvsheet_buffer_t h, void *ctx, void (*on_close)(void *));
81
+
82
+ /**
83
+ * Get custom context previously set via zsvsheet_buffer_set_ctx()
84
+ * @param ctx_out result will be written to this address
85
+ *
86
+ * @return zsv_ext_status_ok on success, else zsv_ext_status error code
87
+ */
88
+ enum zsv_ext_status zsvsheet_buffer_get_ctx(zsvsheet_buffer_t h, void **ctx_out);
89
+
90
+ /**
91
+ * Set custom handler on Enter key press
92
+ *
93
+ * @return zsv_ext_status_ok on success, else zsv_ext_status error code
94
+ */
95
+ enum zsv_ext_status zsvsheet_buffer_on_newline(zsvsheet_buffer_t h,
96
+ zsvsheet_status (*on_newline)(zsvsheet_proc_context_t));
97
+
98
+ zsvsheet_status zsvsheet_buffer_get_selected_cell(zsvsheet_buffer_t h, struct zsvsheet_rowcol *rc);
99
+
100
+ /**
101
+ * Set custom cell attributes
102
+ */
103
+ void zsvsheet_buffer_set_cell_attrs(zsvsheet_buffer_t h,
104
+ enum zsv_ext_status (*get_cell_attrs)(void *ext_ctx, zsvsheet_cell_attr_t *,
105
+ size_t start_row, size_t row_count,
106
+ size_t col_count));
107
+
108
+ /** Get zsv_opts use to open the buffer's data file **/
109
+ struct zsv_opts zsvsheet_buffer_get_zsv_opts(zsvsheet_buffer_t h);
110
+
111
+ /**
112
+ * Register a custom sheet command
113
+ */
114
+ zsvsheet_status zsvsheet_register_command(int ch, const char *long_name,
115
+ zsvsheet_status (*subcommand_handler)(zsvsheet_subcommand_context_t),
116
+ zsvsheet_status (*handler)(zsvsheet_context_t));
117
+
118
+ /**
119
+ * Transform the current buffer's underlying file into a new one and open the new file in a buffer
120
+ */
121
+ enum zsvsheet_status zsvsheet_push_transformation(zsvsheet_proc_context_t ctx,
122
+ struct zsvsheet_buffer_transformation_opts opts);
123
+ #endif
124
+
125
+ struct zsvsheet_buffer_data zsvsheet_buffer_info(zsvsheet_buffer_t buff);
126
+
127
+ /** cell formatting **/
128
+ zsvsheet_cell_attr_t zsvsheet_cell_profile_attrs(enum zsvsheet_cell_profile_t);
@@ -0,0 +1,43 @@
1
+ struct zsvsheet_help_data {
2
+ size_t rows_fetched;
3
+ const char *row_data[3];
4
+ };
5
+
6
+ const unsigned char **zsvsheet_get_help_header(void *d) {
7
+ struct zsvsheet_help_data *data = d;
8
+ data->row_data[0] = "Key(s)";
9
+ data->row_data[1] = "Action";
10
+ data->row_data[2] = "Description";
11
+ return (const unsigned char **)data->row_data;
12
+ }
13
+
14
+ const unsigned char *zsvsheet_get_help_status(void *_) {
15
+ (void)(_);
16
+ return (const unsigned char *)"<esc> to exit help";
17
+ }
18
+
19
+ const unsigned char **zsvsheet_get_help_row(void *d) {
20
+ struct zsvsheet_help_data *data = d;
21
+ while (1) {
22
+ size_t i = data->rows_fetched++;
23
+ if (zsvsheet_get_key_binding(i) == NULL)
24
+ return NULL;
25
+
26
+ struct zsvsheet_key_binding *kb = zsvsheet_get_key_binding(i);
27
+ struct zsvsheet_procedure *proc = zsvsheet_find_procedure(kb->proc_id);
28
+ if (proc == NULL || kb->hidden)
29
+ continue;
30
+
31
+ data->row_data[0] = zsvsheet_key_binding_ch_name(kb);
32
+ data->row_data[1] = proc->name;
33
+ data->row_data[2] = proc->description;
34
+ return (const unsigned char **)data->row_data;
35
+ }
36
+ }
37
+
38
+ static zsvsheet_status zsvsheet_help_handler(struct zsvsheet_proc_context *ctx) {
39
+ const size_t cols = 3;
40
+ struct zsvsheet_help_data d = {0};
41
+ return zsvsheet_buffer_new_static(ctx, cols, zsvsheet_get_help_header, zsvsheet_get_help_row,
42
+ zsvsheet_get_help_status, &d, NULL);
43
+ }
@@ -0,0 +1,81 @@
1
+ #include <stdlib.h>
2
+ #include <string.h>
3
+ #include <unistd.h>
4
+ #include <zsv.h>
5
+ #include <zsv/utils/prop.h>
6
+ #include <zsv/utils/file.h>
7
+ #include <zsv/utils/writer.h>
8
+
9
+ #include "../utils/index.h"
10
+ #include "index.h"
11
+ static void build_memory_index_row_handler(void *ctx) {
12
+ struct zsvsheet_indexer *ixr = ctx;
13
+ struct zsv_index *ix = ixr->ix;
14
+ zsv_parser parser = ixr->parser;
15
+ uint64_t line_end = zsv_cum_scanned_length(parser);
16
+
17
+ if (zsv_index_add_row(ix, line_end) != zsv_index_status_ok)
18
+ zsv_abort(parser);
19
+ }
20
+
21
+ enum zsv_index_status build_memory_index(struct zsvsheet_index_opts *optsp) {
22
+ struct zsvsheet_indexer ixr = {0};
23
+ enum zsv_index_status ret = zsv_index_status_error;
24
+ struct zsv_opts ix_zopts = optsp->zsv_opts;
25
+
26
+ if (optsp->uib->data_filename) {
27
+ ix_zopts.stream = fopen(optsp->uib->data_filename, "rb");
28
+ } else {
29
+ ix_zopts.stream = fopen(optsp->filename, "rb");
30
+ }
31
+
32
+ if (!ix_zopts.stream)
33
+ goto out;
34
+
35
+ ix_zopts.ctx = &ixr;
36
+ ix_zopts.row_handler = build_memory_index_row_handler;
37
+
38
+ enum zsv_status zst = zsv_new_with_properties(&ix_zopts, optsp->custom_prop_handler, optsp->filename, &ixr.parser);
39
+ if (zst != zsv_status_ok)
40
+ goto out;
41
+
42
+ ixr.ix = zsv_index_new();
43
+ if (!ixr.ix)
44
+ goto out;
45
+
46
+ optsp->uib->index = ixr.ix;
47
+
48
+ char cancelled = 0;
49
+ size_t committed_bytes = 0;
50
+ while (!cancelled && (zst = zsv_parse_more(ixr.parser)) == zsv_status_ok) {
51
+ if (zsv_cum_scanned_length(ixr.parser) - committed_bytes < 32 * 1024 * 1024)
52
+ continue;
53
+ committed_bytes = zsv_cum_scanned_length(ixr.parser);
54
+
55
+ pthread_mutex_lock(&optsp->uib->mutex);
56
+ if (optsp->uib->worker_cancelled) {
57
+ cancelled = 1;
58
+ zst = zsv_status_cancelled;
59
+ }
60
+ zsv_index_commit_rows(ixr.ix);
61
+ optsp->uib->index_ready = 1;
62
+ pthread_mutex_unlock(&optsp->uib->mutex);
63
+ }
64
+
65
+ zsv_finish(ixr.parser);
66
+ pthread_mutex_lock(&optsp->uib->mutex);
67
+ zsv_index_commit_rows(ixr.ix);
68
+ optsp->uib->index_ready = 1;
69
+ pthread_mutex_unlock(&optsp->uib->mutex);
70
+
71
+ if (zst == zsv_status_no_more_input || zst == zsv_status_cancelled)
72
+ ret = zsv_index_status_ok;
73
+
74
+ out:
75
+ if (ixr.parser)
76
+ zsv_delete(ixr.parser);
77
+ if (ix_zopts.stream)
78
+ fclose(ix_zopts.stream);
79
+
80
+ return ret;
81
+ }
@@ -0,0 +1,25 @@
1
+ #ifndef SHEET_INDEX_H
2
+ #define SHEET_INDEX_H
3
+
4
+ #include <pthread.h>
5
+
6
+ #include "zsv.h"
7
+
8
+ struct zsvsheet_indexer {
9
+ zsv_parser parser;
10
+ struct zsv_index *ix;
11
+ };
12
+
13
+ struct zsvsheet_index_opts {
14
+ pthread_mutex_t *mutexp;
15
+ const char *filename;
16
+ struct zsv_opts zsv_opts;
17
+ struct zsvsheet_ui_buffer *uib;
18
+ int *errp;
19
+ struct zsv_prop_handler *custom_prop_handler;
20
+ char *old_ui_status;
21
+ };
22
+
23
+ enum zsv_index_status build_memory_index(struct zsvsheet_index_opts *optsp);
24
+
25
+ #endif