zsv 1.3.1 → 1.4.4

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 (259) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +153 -2
  3. data/README.md +132 -240
  4. data/ext/zsv/ZSV_UPSTREAM +7 -0
  5. data/ext/zsv/common.h +0 -12
  6. data/ext/zsv/extconf.rb +70 -122
  7. data/ext/zsv/options.c +63 -62
  8. data/ext/zsv/options.h +8 -11
  9. data/ext/zsv/parser.c +390 -201
  10. data/ext/zsv/parser.h +35 -22
  11. data/ext/zsv/row.c +75 -28
  12. data/ext/zsv/row.h +15 -9
  13. data/ext/zsv/upstream.rb +55 -0
  14. data/ext/zsv/vendor/zsv/LICENSE +21 -0
  15. data/ext/zsv/vendor/zsv/VENDORED_FROM +2 -0
  16. data/ext/zsv/vendor/zsv/configure +1212 -0
  17. data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/api.h +39 -0
  18. data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/common.h +36 -0
  19. data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/ext/sheet.h +8 -1
  20. data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/ext.h +6 -2
  21. data/ext/zsv/vendor/zsv/include/zsv/utils/appname.h +51 -0
  22. data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/arg.h +50 -1
  23. data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/compiler.h +19 -8
  24. data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/dirs.h +2 -0
  25. data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/file-mem.h +1 -0
  26. data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/file.h +28 -2
  27. data/ext/zsv/vendor/zsv/include/zsv/utils/os.h +145 -0
  28. data/ext/zsv/vendor/zsv/include/zsv/utils/output.h +34 -0
  29. data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/overwrite_writer.h +1 -1
  30. data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/prop.h +16 -4
  31. data/ext/zsv/vendor/zsv/include/zsv/utils/rng.h +35 -0
  32. data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/signal.h +7 -0
  33. data/ext/zsv/vendor/zsv/include/zsv/utils/sql.h +13 -0
  34. data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/string.h +25 -0
  35. data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/writer.h +9 -1
  36. data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/zsv_export.h +1 -1
  37. data/ext/zsv/vendor/{zsv-1.3.0/include/zsv.h → zsv/include/zsv.h.in} +1 -3
  38. data/ext/zsv/vendor/zsv/src/Makefile +238 -0
  39. data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/src/zsv.c +152 -14
  40. data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/src/zsv_internal.c +108 -50
  41. data/ext/zsv/vendor/zsv/src/zsv_scan_delim_fast.c +741 -0
  42. data/ext/zsv/vendor/zsv/src/zsv_scan_simd_avx2.h +89 -0
  43. data/ext/zsv/vendor/zsv/src/zsv_scan_simd_neon.h +80 -0
  44. data/ext/zsv/vendor/zsv/src/zsv_scan_simd_sse2.h +93 -0
  45. data/ext/zsv/vendor/zsv/src/zsv_scan_simd_wasm.h +79 -0
  46. data/ext/zsv/vendor/zsv/src/zsv_strencode.c +84 -0
  47. data/ext/zsv/zsv_ext.c +176 -105
  48. data/lib/zsv/errors.rb +32 -0
  49. data/lib/zsv/input.rb +88 -0
  50. data/lib/zsv/options.rb +132 -0
  51. data/lib/zsv/strict_validator.rb +124 -0
  52. data/lib/zsv/version.rb +1 -1
  53. data/lib/zsv.rb +137 -35
  54. metadata +81 -230
  55. data/ext/zsv/vendor/zsv-1.3.0/app/2db.c +0 -756
  56. data/ext/zsv/vendor/zsv-1.3.0/app/2json.c +0 -381
  57. data/ext/zsv/vendor/zsv-1.3.0/app/2tsv.c +0 -228
  58. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/help.c +0 -123
  59. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/license.c +0 -39
  60. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/register.c +0 -104
  61. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/thirdparty.c +0 -41
  62. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/unregister.c +0 -1
  63. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/version.c +0 -14
  64. data/ext/zsv/vendor/zsv-1.3.0/app/check/simdutf_wrapper.h +0 -19
  65. data/ext/zsv/vendor/zsv-1.3.0/app/check/utf8.c +0 -116
  66. data/ext/zsv/vendor/zsv-1.3.0/app/check.c +0 -194
  67. data/ext/zsv/vendor/zsv-1.3.0/app/cli.c +0 -796
  68. data/ext/zsv/vendor/zsv-1.3.0/app/cli_const.h +0 -41
  69. data/ext/zsv/vendor/zsv-1.3.0/app/cli_export.h +0 -16
  70. data/ext/zsv/vendor/zsv-1.3.0/app/cli_ini.c +0 -280
  71. data/ext/zsv/vendor/zsv-1.3.0/app/cli_internal.h +0 -36
  72. data/ext/zsv/vendor/zsv-1.3.0/app/compare.c +0 -913
  73. data/ext/zsv/vendor/zsv-1.3.0/app/compare.h +0 -23
  74. data/ext/zsv/vendor/zsv-1.3.0/app/compare_added_column.c +0 -20
  75. data/ext/zsv/vendor/zsv-1.3.0/app/compare_internal.h +0 -140
  76. data/ext/zsv/vendor/zsv-1.3.0/app/compare_sort.c +0 -91
  77. data/ext/zsv/vendor/zsv-1.3.0/app/compare_unique_colname.c +0 -81
  78. data/ext/zsv/vendor/zsv-1.3.0/app/count-pull.c +0 -82
  79. data/ext/zsv/vendor/zsv-1.3.0/app/count.c +0 -404
  80. data/ext/zsv/vendor/zsv-1.3.0/app/desc.c +0 -569
  81. data/ext/zsv/vendor/zsv-1.3.0/app/echo.c +0 -365
  82. data/ext/zsv/vendor/zsv-1.3.0/app/ext_example/my_extension.c +0 -366
  83. data/ext/zsv/vendor/zsv-1.3.0/app/ext_example/mysheet_extension.c +0 -341
  84. data/ext/zsv/vendor/zsv-1.3.0/app/ext_template/YOUR_EXTENSION_zsvext.c +0 -263
  85. data/ext/zsv/vendor/zsv-1.3.0/app/external/inih/ini.c +0 -298
  86. data/ext/zsv/vendor/zsv-1.3.0/app/external/inih/ini.h +0 -157
  87. data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/json_numeric.c +0 -177
  88. data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/jsonwriter.c +0 -444
  89. data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/jsonwriter.h +0 -145
  90. data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/utils.c +0 -110
  91. data/ext/zsv/vendor/zsv-1.3.0/app/external/memfile-1.0/include/memfile.h +0 -15
  92. data/ext/zsv/vendor/zsv-1.3.0/app/external/memfile-1.0/src/memfile.c +0 -64
  93. data/ext/zsv/vendor/zsv-1.3.0/app/external/sglib/sglib.h +0 -1955
  94. data/ext/zsv/vendor/zsv-1.3.0/app/external/simdutf/simdutf.h +0 -6802
  95. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3.c +0 -230517
  96. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3.h +0 -12174
  97. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_and_csv_vtab.c +0 -2
  98. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab-mem.c +0 -142
  99. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab-mem.h +0 -49
  100. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab-zsv.c +0 -485
  101. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab.c +0 -1015
  102. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3ext.h +0 -663
  103. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/vtab_helper.c +0 -85
  104. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_common.h +0 -75
  105. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_gen.h +0 -167
  106. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_parse.h +0 -228
  107. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_tree.h +0 -186
  108. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_version.h +0 -23
  109. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_common.h +0 -76
  110. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_gen.h +0 -167
  111. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_parse.h +0 -238
  112. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_tree.h +0 -186
  113. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl.c +0 -184
  114. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_alloc.c +0 -52
  115. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_alloc.h +0 -34
  116. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_buf.c +0 -103
  117. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_buf.h +0 -57
  118. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_bytestack.h +0 -69
  119. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_encode.c +0 -220
  120. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_encode.h +0 -34
  121. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_gen.c +0 -362
  122. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_lex.c +0 -764
  123. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_lex.h +0 -117
  124. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_parser.c +0 -508
  125. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_parser.h +0 -78
  126. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_tree.c +0 -505
  127. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_version.c +0 -7
  128. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper/json_value.h +0 -59
  129. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper/yajl_helper.h +0 -208
  130. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper.c +0 -795
  131. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper_internal.h +0 -28
  132. data/ext/zsv/vendor/zsv-1.3.0/app/flatten.c +0 -851
  133. data/ext/zsv/vendor/zsv-1.3.0/app/jq.c +0 -106
  134. data/ext/zsv/vendor/zsv-1.3.0/app/jq.h +0 -6
  135. data/ext/zsv/vendor/zsv-1.3.0/app/mv.c +0 -113
  136. data/ext/zsv/vendor/zsv-1.3.0/app/noop.c +0 -90
  137. data/ext/zsv/vendor/zsv-1.3.0/app/overwrite.c +0 -295
  138. data/ext/zsv/vendor/zsv-1.3.0/app/paste.c +0 -175
  139. data/ext/zsv/vendor/zsv-1.3.0/app/pretty.c +0 -693
  140. data/ext/zsv/vendor/zsv-1.3.0/app/prop.c +0 -980
  141. data/ext/zsv/vendor/zsv-1.3.0/app/rm.c +0 -131
  142. data/ext/zsv/vendor/zsv-1.3.0/app/select/fixed.c +0 -130
  143. data/ext/zsv/vendor/zsv-1.3.0/app/select/internal.h +0 -118
  144. data/ext/zsv/vendor/zsv-1.3.0/app/select/parallel.c +0 -45
  145. data/ext/zsv/vendor/zsv-1.3.0/app/select/parallel.h +0 -41
  146. data/ext/zsv/vendor/zsv-1.3.0/app/select/processing.c +0 -107
  147. data/ext/zsv/vendor/zsv-1.3.0/app/select/rand.c +0 -20
  148. data/ext/zsv/vendor/zsv-1.3.0/app/select/regex.c +0 -61
  149. data/ext/zsv/vendor/zsv-1.3.0/app/select/search.c +0 -14
  150. data/ext/zsv/vendor/zsv-1.3.0/app/select/selection.c +0 -192
  151. data/ext/zsv/vendor/zsv-1.3.0/app/select/usage.c +0 -72
  152. data/ext/zsv/vendor/zsv-1.3.0/app/select-pull.c +0 -812
  153. data/ext/zsv/vendor/zsv-1.3.0/app/select.c +0 -753
  154. data/ext/zsv/vendor/zsv-1.3.0/app/serialize.c +0 -372
  155. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/curses.h +0 -15
  156. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/cursor.c +0 -119
  157. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/errors.c +0 -45
  158. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/file.c +0 -63
  159. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/file.h +0 -12
  160. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/filter.c +0 -166
  161. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/handlers.c +0 -214
  162. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/handlers_internal.h +0 -128
  163. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/help.c +0 -43
  164. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/index.c +0 -81
  165. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/index.h +0 -25
  166. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/key-bindings.c +0 -325
  167. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/key-bindings.h +0 -73
  168. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/lexer.c +0 -203
  169. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/newline_handler.c +0 -7
  170. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/pivot.c +0 -318
  171. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/procedure.c +0 -134
  172. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/procedure.h +0 -119
  173. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/read-data.c +0 -322
  174. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/screen_buffer.c +0 -203
  175. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/screen_buffer.h +0 -36
  176. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/sheet-sql.c +0 -167
  177. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/sheet_internal.h +0 -36
  178. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/sqlfilter.c +0 -153
  179. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/terminfo.c +0 -32
  180. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/transformation.c +0 -312
  181. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/transformation.h +0 -29
  182. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/ui_buffer.c +0 -266
  183. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/usage.c +0 -9
  184. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/utf8-width.c +0 -60
  185. data/ext/zsv/vendor/zsv-1.3.0/app/sheet.c +0 -1007
  186. data/ext/zsv/vendor/zsv-1.3.0/app/sql.c +0 -453
  187. data/ext/zsv/vendor/zsv-1.3.0/app/sql_internal.c +0 -101
  188. data/ext/zsv/vendor/zsv-1.3.0/app/sql_internal.h +0 -49
  189. data/ext/zsv/vendor/zsv-1.3.0/app/stack.c +0 -393
  190. data/ext/zsv/vendor/zsv-1.3.0/app/utils/arg.c +0 -322
  191. data/ext/zsv/vendor/zsv-1.3.0/app/utils/cache.c +0 -228
  192. data/ext/zsv/vendor/zsv-1.3.0/app/utils/cat.c +0 -91
  193. data/ext/zsv/vendor/zsv-1.3.0/app/utils/chunk.c +0 -240
  194. data/ext/zsv/vendor/zsv-1.3.0/app/utils/chunk.h +0 -63
  195. data/ext/zsv/vendor/zsv-1.3.0/app/utils/clock.c +0 -57
  196. data/ext/zsv/vendor/zsv-1.3.0/app/utils/db.c +0 -148
  197. data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs-no-jq.c +0 -2
  198. data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs.c +0 -427
  199. data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs_from_json.c +0 -253
  200. data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs_to_json.c +0 -121
  201. data/ext/zsv/vendor/zsv-1.3.0/app/utils/dl.c +0 -20
  202. data/ext/zsv/vendor/zsv-1.3.0/app/utils/emcc/fs_api.c +0 -159
  203. data/ext/zsv/vendor/zsv-1.3.0/app/utils/err.c +0 -24
  204. data/ext/zsv/vendor/zsv-1.3.0/app/utils/file-mem.c +0 -180
  205. data/ext/zsv/vendor/zsv-1.3.0/app/utils/file.c +0 -256
  206. data/ext/zsv/vendor/zsv-1.3.0/app/utils/index.c +0 -197
  207. data/ext/zsv/vendor/zsv-1.3.0/app/utils/index.h +0 -49
  208. data/ext/zsv/vendor/zsv-1.3.0/app/utils/jq.c +0 -400
  209. data/ext/zsv/vendor/zsv-1.3.0/app/utils/json.c +0 -120
  210. data/ext/zsv/vendor/zsv-1.3.0/app/utils/mem.c +0 -18
  211. data/ext/zsv/vendor/zsv-1.3.0/app/utils/memmem.c +0 -132
  212. data/ext/zsv/vendor/zsv-1.3.0/app/utils/os.c +0 -178
  213. data/ext/zsv/vendor/zsv-1.3.0/app/utils/overwrite.c +0 -258
  214. data/ext/zsv/vendor/zsv-1.3.0/app/utils/overwrite_writer.c +0 -246
  215. data/ext/zsv/vendor/zsv-1.3.0/app/utils/pcre2-8/pcre2-8-test.c +0 -123
  216. data/ext/zsv/vendor/zsv-1.3.0/app/utils/pcre2-8/pcre2-8.c +0 -153
  217. data/ext/zsv/vendor/zsv-1.3.0/app/utils/pcre2-8/pcre2-8.h +0 -54
  218. data/ext/zsv/vendor/zsv-1.3.0/app/utils/prop.c +0 -267
  219. data/ext/zsv/vendor/zsv-1.3.0/app/utils/signal.c +0 -53
  220. data/ext/zsv/vendor/zsv-1.3.0/app/utils/string.c +0 -357
  221. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/dir_exists_longpath.c +0 -83
  222. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/dl.c +0 -33
  223. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/fopen_longpath.c +0 -184
  224. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/foreach_dirent_longpath.c +0 -292
  225. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/io.c +0 -259
  226. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/io.h +0 -13
  227. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/mkdir_longpath.c +0 -255
  228. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/remove_longpath.c +0 -96
  229. data/ext/zsv/vendor/zsv-1.3.0/app/utils/writer.c +0 -361
  230. data/ext/zsv/vendor/zsv-1.3.0/app/zsv_command.h +0 -40
  231. data/ext/zsv/vendor/zsv-1.3.0/app/zsv_command_standalone.c +0 -16
  232. data/ext/zsv/vendor/zsv-1.3.0/app/zsv_main.h +0 -44
  233. data/ext/zsv/vendor/zsv-1.3.0/examples/js/zsv_parser_api_dummy.c +0 -3
  234. data/ext/zsv/vendor/zsv-1.3.0/examples/lib/parse_by_chunk.c +0 -100
  235. data/ext/zsv/vendor/zsv-1.3.0/examples/lib/print_my_column.c +0 -143
  236. data/ext/zsv/vendor/zsv-1.3.0/examples/lib/pull.c +0 -89
  237. data/ext/zsv/vendor/zsv-1.3.0/examples/lib/simple.c +0 -123
  238. data/ext/zsv/vendor/zsv-1.3.0/fuzz/fuzz.c +0 -16
  239. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/os.h +0 -54
  240. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/sql.h +0 -11
  241. data/ext/zsv/vendor/zsv-1.3.0/src/zsv_strencode.c +0 -51
  242. /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/ext/implementation.h +0 -0
  243. /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/ext/implementation_private.h +0 -0
  244. /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/cache.h +0 -0
  245. /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/clock.h +0 -0
  246. /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/db.h +0 -0
  247. /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/dl.h +0 -0
  248. /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/emcc/fs_api.h +0 -0
  249. /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/err.h +0 -0
  250. /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/jq.h +0 -0
  251. /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/json.h +0 -0
  252. /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/mem.h +0 -0
  253. /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/memmem.h +0 -0
  254. /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/overwrite.h +0 -0
  255. /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/utf8.h +0 -0
  256. /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/include/zsv/utils/win/dl.h +0 -0
  257. /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/src/vector_delim.c +0 -0
  258. /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/src/zsv_scan_delim.c +0 -0
  259. /data/ext/zsv/vendor/{zsv-1.3.0 → zsv}/src/zsv_scan_fixed.c +0 -0
@@ -1,693 +0,0 @@
1
- /*
2
- * Copyright (C) 2021 Liquidaty and zsv contributors. All rights reserved.
3
- *
4
- * This file is part of zsv/lib, distributed under the MIT license as defined at
5
- * https://opensource.org/licenses/MIT
6
- */
7
-
8
- #include <utf8proc.h>
9
- #include <stdio.h>
10
- #include <stdlib.h>
11
- #include <string.h>
12
- #include <math.h>
13
-
14
- #define ZSV_COMMAND pretty
15
- #include "zsv_command.h"
16
- #include <zsv/utils/string.h>
17
-
18
- #define ZSV_PRETTY_DEFAULT_LINE_MAX_WIDTH 160
19
- #define ZSV_PRETTY_DEFAULT_COLUMN_MAX_WIDTH 35
20
- #define ZSV_PRETTY_DEFAULT_COLUMN_MIN_WIDTH 2
21
-
22
- #define ZSV_PRETTY_DEFAULT_CACHE_MAX 100
23
-
24
- struct zsv_pretty_opts {
25
- size_t line_width_max;
26
- size_t column_width_min;
27
- size_t column_width_max;
28
- size_t cache_max_rows;
29
-
30
- FILE *out;
31
-
32
- unsigned char ignore_header_lengths : 1;
33
- unsigned char markdown : 1;
34
- unsigned char markdown_pad : 1;
35
- unsigned char no_align : 1;
36
- unsigned char dummy : 4;
37
- };
38
-
39
- enum zsv_pretty_status {
40
- zsv_pretty_status_ok = 0,
41
- zsv_pretty_status_error,
42
- zsv_pretty_status_memory,
43
- zsv_pretty_status_cache_updated,
44
- zsv_pretty_status_cache_full,
45
- // ...
46
- zsv_pretty_status_end
47
- };
48
-
49
- #ifdef WIN32
50
- #include <windows.h>
51
- static size_t get_console_width(void) {
52
- CONSOLE_SCREEN_BUFFER_INFO csbi;
53
- int ret;
54
- ret = GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
55
- if (ret)
56
- return csbi.dwSize.X;
57
- return 0;
58
- }
59
- #else
60
- #include <sys/ioctl.h>
61
- #include <stdio.h>
62
- #include <stdlib.h>
63
-
64
- #ifndef HAVE_TGETENT
65
- static size_t get_console_width(void) {
66
- return 0;
67
- }
68
-
69
- #else
70
- #include <termcap.h>
71
- static size_t get_console_width(void) {
72
- char termbuf[2048];
73
- char *termtype = getenv("TERM");
74
- if (tgetent(termbuf, termtype) < 0)
75
- return 0;
76
-
77
- int columns = tgetnum("co");
78
- return columns > 0 ? columns : 0;
79
- }
80
- #endif // HAVE_TGETENT
81
-
82
- #endif // WIN32-else
83
-
84
- const unsigned char UTF8_ELLIPSIS[] = {226, 128, 166, '\0'}; // e2 80 a6
85
-
86
- struct zsv_cached_row {
87
- struct zsv_cached_row *next;
88
- unsigned char **values;
89
- unsigned int count;
90
- };
91
-
92
- static struct zsv_cell zsv_pretty_get_cell(zsv_parser parser, struct zsv_cached_row *r, unsigned ix) {
93
- struct zsv_cell c;
94
- memset(&c, 0, sizeof(c));
95
- if (r) {
96
- if (ix < r->count)
97
- c.str = r->values[ix];
98
- if (!c.str)
99
- c.str = (unsigned char *)"";
100
- c.len = strlen((char *)c.str);
101
- } else
102
- c = zsv_get_cell(parser, ix);
103
- return c;
104
- }
105
-
106
- static void zsv_cached_rows_delete(struct zsv_cached_row *first) {
107
- for (struct zsv_cached_row *next, *e = first; e; e = next) {
108
- next = e->next;
109
- for (unsigned int i = 0; i < e->count; i++)
110
- free(e->values[i]);
111
- free(e->values);
112
- free(e);
113
- }
114
- }
115
-
116
- static struct zsv_cached_row *zsv_pretty_dupe_row(zsv_parser parser) {
117
- unsigned col_count = zsv_cell_count(parser);
118
- if (col_count) {
119
- struct zsv_cached_row *r = calloc(1, sizeof(*r));
120
- if (r) {
121
- r->count = col_count;
122
- r->values = calloc(r->count, sizeof(*r->values));
123
- if (!r->values) {
124
- fprintf(stderr, "Error: out of memory\n");
125
- free(r);
126
- return NULL;
127
- }
128
-
129
- for (unsigned int i = 0; i < r->count; i++) {
130
- struct zsv_cell cell = zsv_get_cell(parser, i);
131
- cell.str = (unsigned char *)zsv_strtrim(cell.str, &cell.len);
132
- if ((r->values[i] = malloc(cell.len + 1))) {
133
- memcpy(r->values[i], cell.str, cell.len);
134
- r->values[i][cell.len] = '\0';
135
- }
136
- }
137
- return r;
138
- }
139
- }
140
- return NULL;
141
- }
142
-
143
- struct zsv_pretty_data {
144
- int err;
145
- size_t row_ix;
146
- zsv_parser parser;
147
- enum zsv_status parser_status;
148
-
149
- size_t (*write)(const void *, size_t, size_t, void *);
150
- void *write_arg;
151
-
152
- struct {
153
- size_t printed;
154
- size_t max;
155
- } line;
156
-
157
- struct {
158
- struct zsv_cached_row *c_rows;
159
- struct zsv_cached_row **next;
160
- size_t count;
161
- size_t max;
162
- char full;
163
- } cache;
164
-
165
- struct {
166
- size_t *values;
167
- size_t allocated;
168
- size_t used;
169
- size_t min, max;
170
- } widths;
171
-
172
- size_t current_table_lines_written;
173
-
174
- size_t first_column_count;
175
-
176
- unsigned char no_trim : 1;
177
- unsigned char verbose : 1;
178
- unsigned char ignore_header_lengths : 1;
179
- unsigned char markdown : 1;
180
- unsigned char markdown_pad : 1;
181
- unsigned char no_align : 1;
182
- unsigned char dummy : 2;
183
- };
184
-
185
- static size_t zsv_pretty_get_width(struct zsv_pretty_data *data, size_t ix) {
186
- if (ix < data->widths.used)
187
- return data->widths.values[ix];
188
- return 0;
189
- }
190
-
191
- static size_t zsv_pretty_get_row_count(struct zsv_pretty_data *data, struct zsv_cached_row *r) {
192
- return r ? r->count : zsv_cell_count(data->parser);
193
- }
194
-
195
- static void zsv_pretty_output_lineend(struct zsv_pretty_data *data, struct zsv_cached_row *r) {
196
- size_t columns_used = zsv_pretty_get_row_count(data, r);
197
- // size_t columns_used = zsv_row_cells_count(r);
198
- char empty_line = columns_used == 0 || (columns_used == 1 && zsv_pretty_get_cell(data->parser, r, 0).len == 0);
199
-
200
- if (empty_line)
201
- data->current_table_lines_written = 0;
202
- else if (columns_used > 1) {
203
- data->current_table_lines_written++;
204
- if (data->markdown || data->markdown_pad) {
205
- if (data->current_table_lines_written == 1) {
206
- data->write("|\n", 1, 2, data->write_arg);
207
- size_t printed = 0;
208
- for (unsigned col_ix = 0; printed < data->line.max && col_ix < columns_used; col_ix++) {
209
- data->write("|", 1, 1, data->write_arg);
210
- printed++;
211
- if (data->markdown_pad && col_ix <= data->widths.used) {
212
- int j = zsv_pretty_get_width(data, col_ix);
213
- if (!j)
214
- j = 1;
215
- for (; j-- && printed <= data->line.max; printed++)
216
- data->write("-", 1, 1, data->write_arg);
217
- } else
218
- data->write("--", 1, 2, data->write_arg);
219
- }
220
- }
221
- data->write("|", 1, 1, data->write_arg);
222
- }
223
- }
224
- data->write("\n", 1, 1, data->write_arg);
225
-
226
- data->line.printed = 0;
227
- }
228
-
229
- static void zsv_pretty_output_linestart(struct zsv_pretty_data *data) {
230
- if (data->markdown || data->markdown_pad)
231
- data->write("|", 1, 1, data->write_arg);
232
- }
233
-
234
- static size_t is_newline(const unsigned char *utf8, int wchar_len) {
235
- return (wchar_len == 1 && strchr("\n\r", utf8[0]));
236
- // add multibyte newline check?
237
- }
238
-
239
- // utf8_bytes_up_to_max_width: return number of bytes used up to a maximum screen width
240
- // set to the actual width used
241
- static size_t utf8_bytes_up_to_max_width_and_replace_newlines(unsigned char *str1, size_t len1, size_t max_width,
242
- size_t *used_width, int *err) {
243
- utf8proc_int32_t codepoint1;
244
- utf8proc_ssize_t bytes_read1;
245
- size_t width_so_far = *used_width = 0;
246
- int this_char_width = 0;
247
- size_t bytes_so_far = 0;
248
- while (bytes_so_far < len1) {
249
- bytes_read1 = utf8proc_iterate((utf8proc_uint8_t *)str1 + bytes_so_far, len1, &codepoint1);
250
- if (!bytes_read1) {
251
- bytes_read1 = 1;
252
- *err = 1;
253
- this_char_width = 1;
254
- } else if (is_newline(str1 + bytes_so_far, bytes_read1)) {
255
- memset((void *)(str1 + bytes_so_far), ' ', bytes_read1);
256
- continue;
257
- } else {
258
- this_char_width = utf8proc_charwidth(codepoint1);
259
- if (width_so_far + this_char_width > max_width) {
260
- *used_width = width_so_far;
261
- return bytes_so_far;
262
- }
263
- }
264
- width_so_far += this_char_width;
265
- bytes_so_far += bytes_read1;
266
- }
267
- *used_width = width_so_far;
268
- return bytes_so_far;
269
- }
270
-
271
- void zsv_pretty_write_cell(unsigned char *buff, size_t bytes, struct zsv_pretty_data *data, size_t max_col_width,
272
- char last_column) {
273
- if (data->line.max > data->line.printed) {
274
- size_t used_width = 0;
275
- size_t max_width = max_col_width == 0 || max_col_width > data->line.max - data->line.printed
276
- ? data->line.max - data->line.printed
277
- : max_col_width;
278
- if (bytes) {
279
- int utf8_err;
280
- size_t bytes_to_print =
281
- utf8_bytes_up_to_max_width_and_replace_newlines(buff, bytes, max_width, &used_width, &utf8_err);
282
- char ellipsis = 0;
283
- if (bytes_to_print && bytes_to_print < bytes && max_col_width == max_width && used_width == max_col_width) {
284
- ellipsis = 1;
285
- if (max_width > 1)
286
- bytes_to_print =
287
- utf8_bytes_up_to_max_width_and_replace_newlines(buff, bytes, max_width - 1, &used_width, &utf8_err);
288
- }
289
- if (bytes_to_print) {
290
- if ((data->markdown || data->markdown_pad) &&
291
- (memchr(buff, '|', bytes_to_print) || memchr(buff, '\\', bytes_to_print))) {
292
- char *tmp = malloc(bytes_to_print * 2);
293
- if (!tmp)
294
- data->parser_status = zsv_status_memory;
295
- else {
296
- size_t tmp_len = 0;
297
- for (size_t i = 0; i < bytes_to_print; i++) {
298
- if (memchr("|\\", buff[i], 2))
299
- tmp[tmp_len++] = '\\';
300
- tmp[tmp_len++] = buff[i];
301
- }
302
- data->write(tmp, 1, tmp_len, data->write_arg);
303
- free(tmp);
304
- }
305
- } else
306
- data->write(buff, 1, bytes_to_print, data->write_arg);
307
- data->line.printed += used_width;
308
-
309
- if (ellipsis) {
310
- data->write((unsigned char *)UTF8_ELLIPSIS, 1, strlen((const char *)UTF8_ELLIPSIS), data->write_arg);
311
- data->line.printed++;
312
- used_width++;
313
- }
314
- } else
315
- used_width = 0;
316
- }
317
-
318
- if (data->markdown_pad || (!data->markdown && !last_column)) {
319
- size_t remaining = max_width - used_width;
320
- while (remaining) {
321
- data->write((unsigned char *)" ", 1, 1, data->write_arg);
322
- data->line.printed++;
323
- --remaining;
324
- }
325
- }
326
- }
327
- }
328
-
329
- #define zsv_pretty_output_col_spacer(data) \
330
- do { \
331
- if (data->line.printed < data->line.max) { \
332
- data->write((unsigned char *)"|", 1, 1, data->write_arg); \
333
- data->line.printed++; \
334
- } \
335
- } while (0)
336
-
337
- static void zsv_pretty_output_row(struct zsv_pretty_data *data, struct zsv_cached_row *r) {
338
- size_t columns_used = zsv_pretty_get_row_count(data, r);
339
- size_t columns_to_print = data->first_column_count > columns_used ? data->first_column_count : columns_used;
340
- if (columns_used == 1) {
341
- struct zsv_cell cell = zsv_pretty_get_cell(data->parser, r, 0);
342
- if (cell.len)
343
- zsv_pretty_write_cell(cell.str, cell.len, data, 0, 1);
344
- } else {
345
- for (unsigned col_ix = 0; col_ix < columns_used; col_ix++) {
346
- if (col_ix > 0)
347
- zsv_pretty_output_col_spacer(data);
348
- else
349
- zsv_pretty_output_linestart(data);
350
- struct zsv_cell cell = zsv_pretty_get_cell(data->parser, r, col_ix);
351
- zsv_pretty_write_cell(cell.str, cell.len, data, zsv_pretty_get_width(data, col_ix),
352
- col_ix + 1 == columns_to_print);
353
- }
354
- }
355
-
356
- // pad the output with additional cells, if this row had fewer than the first row
357
- if (!data->no_align && !data->markdown && !data->markdown_pad) {
358
- if (data->first_column_count < 2)
359
- data->first_column_count = columns_used;
360
- else {
361
- unsigned char empty[2];
362
- empty[0] = '\0';
363
- empty[1] = '\0';
364
- while (columns_used > 1 && columns_used < data->first_column_count) {
365
- zsv_pretty_output_col_spacer(data);
366
- zsv_pretty_write_cell(empty, 0, data, zsv_pretty_get_width(data, columns_used),
367
- columns_used + 1 == columns_to_print);
368
- columns_used++;
369
- }
370
- }
371
- }
372
- zsv_pretty_output_lineend(data, r);
373
- }
374
-
375
- static void zsv_pretty_output_cache(struct zsv_pretty_data *data) {
376
- for (struct zsv_cached_row *c_row = data->cache.c_rows; c_row; c_row = c_row->next)
377
- zsv_pretty_output_row(data, c_row);
378
- }
379
-
380
- static void zsv_pretty_clear_cache(struct zsv_pretty_data *data) {
381
- zsv_cached_rows_delete(data->cache.c_rows);
382
- data->cache.c_rows = NULL;
383
- data->cache.next = &data->cache.c_rows;
384
- data->cache.count = 0;
385
- }
386
-
387
- static void set_min_col_widths(struct zsv_pretty_data *data, size_t used) {
388
- for (unsigned i = 0; i < used; i++)
389
- if (data->widths.values[i] < data->widths.min)
390
- data->widths.values[i] = data->widths.min;
391
- }
392
-
393
- static void zsv_pretty_reset_column_widths(struct zsv_pretty_data *data) {
394
- zsv_pretty_output_cache(data);
395
- zsv_pretty_clear_cache(data);
396
- data->cache.full = 0;
397
- if (data->widths.used && data->widths.values) {
398
- memset(data->widths.values, 0, data->widths.used * sizeof(*data->widths.values));
399
- set_min_col_widths(data, data->widths.used);
400
- }
401
- data->widths.used = 0;
402
- data->first_column_count = 0;
403
- }
404
-
405
- static enum zsv_pretty_status zsv_pretty_add_to_cache(struct zsv_pretty_data *data) {
406
- enum zsv_pretty_status status = zsv_pretty_status_error;
407
- if (data->cache.full)
408
- status = zsv_pretty_status_cache_full;
409
- else {
410
- struct zsv_cached_row *dupe = zsv_pretty_dupe_row(data->parser);
411
- if (!dupe)
412
- status = zsv_pretty_status_memory;
413
- else {
414
- *data->cache.next = dupe;
415
- data->cache.next = &dupe->next;
416
- if (++data->cache.count >= data->cache.max)
417
- data->cache.full = 1;
418
- status = zsv_pretty_status_cache_updated;
419
- }
420
- }
421
- return status;
422
- }
423
-
424
- static enum zsv_pretty_status zsv_pretty_update_column_widths(struct zsv_pretty_data *data) {
425
- size_t columns_used = zsv_cell_count(data->parser);
426
- if (columns_used > 1) {
427
- if (columns_used > data->widths.allocated) {
428
- size_t *new_width_values = realloc(data->widths.values, columns_used * sizeof(*new_width_values));
429
- if (!new_width_values)
430
- return zsv_pretty_status_memory;
431
- // zero out the newly-allocated memory
432
- for (unsigned int j = data->widths.allocated; j < columns_used; j++)
433
- new_width_values[j] = data->widths.min;
434
-
435
- data->widths.values = new_width_values;
436
- data->widths.allocated = columns_used;
437
- }
438
- for (unsigned i = 0; i < columns_used; i++) {
439
- // struct zsv_row_cell v = zsv_row_get_cell(r, i);
440
- struct zsv_cell cell = zsv_get_cell(data->parser, i);
441
- size_t cell_width;
442
- int utf8_err;
443
- utf8_bytes_up_to_max_width_and_replace_newlines(cell.str, cell.len, data->line.max + 1, &cell_width, &utf8_err);
444
- if (cell_width > data->widths.values[i] && data->widths.values[i] < data->widths.max)
445
- data->widths.values[i] = cell_width > data->widths.max ? data->widths.max : cell_width;
446
- }
447
- if (data->widths.used < columns_used)
448
- data->widths.used = columns_used;
449
- }
450
- return zsv_pretty_status_ok;
451
- }
452
-
453
- /*
454
- zsv_pretty_row():
455
- - if the number of columns == 1, then:
456
- - output + clear the cache, and output the column
457
- - alternatively, if data length > 0, add to cache or print if cache is full, but don't update lengths
458
- - if the number of columns > 1, then:
459
- - if the cache is not full, update column lengths and cache the column
460
- - if the cache is full, then:
461
- - if the cache is not printed, print it
462
- - output the column with the given lengths
463
- */
464
- static void zsv_pretty_row(void *ctx) {
465
- struct zsv_pretty_data *data = ctx;
466
- if (data->err)
467
- return;
468
-
469
- unsigned int columns_used = zsv_cell_count(data->parser);
470
- if (columns_used < 2 && (zsv_pretty_get_cell(data->parser, NULL, 0).len == 0 || data->widths.used == 0)) {
471
- zsv_pretty_reset_column_widths(data);
472
- zsv_pretty_output_row(data, NULL);
473
- } else { // >= 2 columns
474
- switch (zsv_pretty_add_to_cache(data)) {
475
- case zsv_pretty_status_cache_updated: // row was added to cache
476
- if (!data->ignore_header_lengths || data->cache.count > 1)
477
- zsv_pretty_update_column_widths(data);
478
- break;
479
- case zsv_pretty_status_cache_full: // row not added
480
- if (data->cache.c_rows) {
481
- zsv_pretty_output_cache(data);
482
- zsv_pretty_clear_cache(data);
483
- }
484
- zsv_pretty_output_row(data, NULL);
485
- break;
486
- default:
487
- break;
488
- }
489
- }
490
-
491
- if (++data->row_ix % 1000 == 0 && data->verbose)
492
- fprintf(stderr, "Processed %zu rows\n", data->row_ix);
493
- }
494
-
495
- const char *zsv_pretty_usage_msg[] = {
496
- APPNAME ": print one or more tables of data in fixed-width format",
497
- "",
498
- "Usage: " APPNAME " [options] <filename>",
499
- "",
500
- "Options:",
501
- " -o,--output <filename> : save output the the specified file",
502
- " -W,--width <n> : max line width to output, try to detect automatically if omitted",
503
- " -p,--rows <n> : number of (preview) rows to calculated widths from if omitted (default: 150)",
504
- " -C,--max-col-width <n> : max column width. if not provided, defaults to 50",
505
- " -D,--min-col-width <n> : min column width. if not provided, defaults to 2",
506
- " -A,--no-align : do not fill in additional cells if first row has more columns than current row",
507
- " -m,--markdown : output table in markdown format",
508
- " -M,--markdown-pad : output table in markdown format with padding",
509
- " -H,--ignore-header-lengths : ignore header lengths in determining column width",
510
- NULL,
511
- };
512
-
513
- static void zsv_pretty_usage(void) {
514
- for (size_t i = 0; zsv_pretty_usage_msg[i]; i++)
515
- fprintf(stdout, "%s\n", zsv_pretty_usage_msg[i]);
516
- }
517
-
518
- static void zsv_pretty_flush(struct zsv_pretty_data *data) {
519
- if (data->parser)
520
- zsv_finish(data->parser);
521
- if (data->cache.c_rows) {
522
- zsv_pretty_output_cache(data);
523
- zsv_pretty_clear_cache(data);
524
- }
525
- }
526
-
527
- static void zsv_pretty_destroy(struct zsv_pretty_data *data) {
528
- if (data->parser) {
529
- zsv_finish(data->parser);
530
- zsv_delete(data->parser);
531
- }
532
- // zsv_row_destroy(data->row);
533
- zsv_pretty_clear_cache(data);
534
-
535
- if (data->widths.values)
536
- free(data->widths.values);
537
-
538
- free(data);
539
- }
540
-
541
- static struct zsv_pretty_data *zsv_pretty_init(struct zsv_pretty_opts *opts, struct zsv_opts *parser_opts,
542
- struct zsv_prop_handler *custom_prop_handler, const char *input_path) {
543
- struct zsv_pretty_data *data = calloc(1, sizeof(*data));
544
- if (!data)
545
- return NULL;
546
-
547
- data->ignore_header_lengths = opts->ignore_header_lengths;
548
- data->markdown = opts->markdown;
549
- data->markdown_pad = opts->markdown_pad;
550
- data->no_align = opts->no_align;
551
-
552
- if (opts->line_width_max)
553
- data->line.max = opts->line_width_max;
554
- else if (!(data->line.max = get_console_width()))
555
- data->line.max = ZSV_PRETTY_DEFAULT_LINE_MAX_WIDTH;
556
-
557
- parser_opts->row_handler = zsv_pretty_row;
558
- parser_opts->ctx = data;
559
- zsv_new_with_properties(parser_opts, custom_prop_handler, input_path, &data->parser);
560
-
561
- data->write = (size_t(*)(const void *, size_t, size_t, void *))fwrite;
562
- data->write_arg = opts->out ? opts->out : stdout;
563
-
564
- zsv_pretty_clear_cache(data);
565
-
566
- if (opts->column_width_min)
567
- data->widths.min = opts->column_width_min;
568
- else
569
- data->widths.min = ZSV_PRETTY_DEFAULT_COLUMN_MIN_WIDTH;
570
-
571
- if (opts->column_width_max)
572
- data->widths.max = opts->column_width_max;
573
- else
574
- data->widths.max = ZSV_PRETTY_DEFAULT_COLUMN_MAX_WIDTH;
575
-
576
- if (opts->cache_max_rows)
577
- data->cache.max = opts->cache_max_rows;
578
- else
579
- data->cache.max = ZSV_PRETTY_DEFAULT_CACHE_MAX;
580
-
581
- return data;
582
- }
583
-
584
- int ZSV_MAIN_FUNC(ZSV_COMMAND)(int argc, const char *argv[], struct zsv_opts *parser_opts,
585
- struct zsv_prop_handler *custom_prop_handler) {
586
- if (argc > 1 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))) {
587
- zsv_pretty_usage();
588
- return 0;
589
- }
590
-
591
- int rc = 0;
592
- FILE *in = stdin;
593
- const char *input_path = NULL;
594
-
595
- struct zsv_pretty_opts opts = {0};
596
-
597
- opts.line_width_max = ZSV_PRETTY_DEFAULT_LINE_MAX_WIDTH;
598
- opts.column_width_min = ZSV_PRETTY_DEFAULT_COLUMN_MIN_WIDTH;
599
- opts.column_width_max = ZSV_PRETTY_DEFAULT_COLUMN_MAX_WIDTH;
600
- opts.cache_max_rows = ZSV_PRETTY_DEFAULT_CACHE_MAX;
601
-
602
- const char *size_t_args[] = {"-W", "--width", "-C", "--max-col-width", "-D", "--min-col-width", "-p", "--rows", NULL};
603
- size_t size_t_maximums[] = {32000, 32000, 500, 500, 500, 500, 100000000, 100000000};
604
- for (int i = 1; !rc && i < argc; i++) {
605
- if (*argv[i] == '-') {
606
- if (!strcmp(argv[i], "-o") || !strcmp(argv[i], "--output")) {
607
- if (++i >= argc)
608
- rc = zsv_printerr(1, "%s option requires a filename value", argv[i - 1]);
609
- else if (opts.out)
610
- rc = zsv_printerr(1, "Output specified more than once");
611
- else if (!(opts.out = fopen(argv[i], "wb")))
612
- rc = zsv_printerr(1, "Unable to open for writing: %s", argv[i]);
613
- } else if (!strcmp(argv[i], "-m") || !strcmp(argv[i], "--markdown"))
614
- opts.markdown = 1;
615
- else if (!strcmp(argv[i], "-A") || !strcmp(argv[i], "--no-align"))
616
- opts.no_align = 1;
617
- else if (!strcmp(argv[i], "-M") || !strcmp(argv[i], "--markdown-pad"))
618
- opts.markdown_pad = 1;
619
- else if (!strcmp(argv[i], "-H") || !strcmp(argv[i], "--ignore-header-lengths"))
620
- opts.ignore_header_lengths = 1;
621
- else {
622
- char got_opt = 0;
623
- for (int j = 0; size_t_args[j]; j++) {
624
- if (!strcmp(size_t_args[j], argv[i])) {
625
- got_opt = 1;
626
- i++;
627
- if (i >= argc)
628
- rc = zsv_printerr(1, "%s option requires a value", size_t_args[j]);
629
- else if (atol(argv[i]) < 2 || (size_t)atol(argv[i]) > size_t_maximums[j])
630
- rc = zsv_printerr(1, "%s value must be an integer between 2 and %zu", size_t_args[j], size_t_maximums[j]);
631
- else {
632
- switch (j) {
633
- case 0:
634
- case 1: // --width
635
- opts.line_width_max = atol(argv[i]);
636
- break;
637
- case 2:
638
- case 3: // --max-col-width
639
- opts.column_width_max = atol(argv[i]);
640
- break;
641
- case 4:
642
- case 5: // --min-col-width
643
- opts.column_width_min = atol(argv[i]);
644
- break;
645
- case 6: // --rows
646
- case 7:
647
- opts.cache_max_rows = atol(argv[i]);
648
- break;
649
- }
650
- }
651
- break;
652
- }
653
- }
654
- if (!got_opt)
655
- rc = zsv_printerr(1, "Unrecognized option: %s", argv[i]);
656
- }
657
- } else if (!(in = fopen(argv[i], "rb")))
658
- rc = zsv_printerr(1, "Unable to open file %s for reading", argv[i]);
659
- else
660
- input_path = argv[i];
661
- }
662
-
663
- #ifdef NO_STDIN
664
- if (in == stdin)
665
- rc = zsv_printerr(1, "Please specify an input file");
666
- #endif
667
- if (opts.column_width_min > opts.column_width_max || opts.column_width_min > opts.line_width_max)
668
- rc = zsv_printerr(1, "Min column width cannot exceed max column width or max line width");
669
-
670
- parser_opts->stream = in;
671
- struct zsv_pretty_data *h = zsv_pretty_init(&opts, parser_opts, custom_prop_handler, input_path);
672
- if (!h)
673
- rc = 1;
674
- else {
675
- zsv_handle_ctrl_c_signal();
676
- rc = 0;
677
- enum zsv_status status;
678
- while (zsv_parse_more(h->parser) == zsv_status_ok)
679
- ;
680
-
681
- while (!rc && !zsv_signal_interrupted && (status = zsv_parse_more(h->parser)) == zsv_status_ok)
682
- ;
683
-
684
- zsv_pretty_flush(h);
685
- zsv_pretty_destroy(h);
686
- }
687
- if (opts.out && opts.out != stdout)
688
- fclose(opts.out);
689
- if (in && in != stdin)
690
- fclose(in);
691
-
692
- return rc;
693
- }