zsv 1.3.1 → 1.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -0
  3. data/README.md +41 -3
  4. data/ext/zsv/extconf.rb +1 -1
  5. data/lib/zsv/version.rb +1 -1
  6. metadata +6 -226
  7. data/ext/zsv/vendor/zsv-1.3.0/app/2db.c +0 -756
  8. data/ext/zsv/vendor/zsv-1.3.0/app/2json.c +0 -381
  9. data/ext/zsv/vendor/zsv-1.3.0/app/2tsv.c +0 -228
  10. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/help.c +0 -123
  11. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/license.c +0 -39
  12. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/register.c +0 -104
  13. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/thirdparty.c +0 -41
  14. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/unregister.c +0 -1
  15. data/ext/zsv/vendor/zsv-1.3.0/app/builtin/version.c +0 -14
  16. data/ext/zsv/vendor/zsv-1.3.0/app/check/simdutf_wrapper.h +0 -19
  17. data/ext/zsv/vendor/zsv-1.3.0/app/check/utf8.c +0 -116
  18. data/ext/zsv/vendor/zsv-1.3.0/app/check.c +0 -194
  19. data/ext/zsv/vendor/zsv-1.3.0/app/cli.c +0 -796
  20. data/ext/zsv/vendor/zsv-1.3.0/app/cli_const.h +0 -41
  21. data/ext/zsv/vendor/zsv-1.3.0/app/cli_export.h +0 -16
  22. data/ext/zsv/vendor/zsv-1.3.0/app/cli_ini.c +0 -280
  23. data/ext/zsv/vendor/zsv-1.3.0/app/cli_internal.h +0 -36
  24. data/ext/zsv/vendor/zsv-1.3.0/app/compare.c +0 -913
  25. data/ext/zsv/vendor/zsv-1.3.0/app/compare.h +0 -23
  26. data/ext/zsv/vendor/zsv-1.3.0/app/compare_added_column.c +0 -20
  27. data/ext/zsv/vendor/zsv-1.3.0/app/compare_internal.h +0 -140
  28. data/ext/zsv/vendor/zsv-1.3.0/app/compare_sort.c +0 -91
  29. data/ext/zsv/vendor/zsv-1.3.0/app/compare_unique_colname.c +0 -81
  30. data/ext/zsv/vendor/zsv-1.3.0/app/count-pull.c +0 -82
  31. data/ext/zsv/vendor/zsv-1.3.0/app/count.c +0 -404
  32. data/ext/zsv/vendor/zsv-1.3.0/app/desc.c +0 -569
  33. data/ext/zsv/vendor/zsv-1.3.0/app/echo.c +0 -365
  34. data/ext/zsv/vendor/zsv-1.3.0/app/ext_example/my_extension.c +0 -366
  35. data/ext/zsv/vendor/zsv-1.3.0/app/ext_example/mysheet_extension.c +0 -341
  36. data/ext/zsv/vendor/zsv-1.3.0/app/ext_template/YOUR_EXTENSION_zsvext.c +0 -263
  37. data/ext/zsv/vendor/zsv-1.3.0/app/external/inih/ini.c +0 -298
  38. data/ext/zsv/vendor/zsv-1.3.0/app/external/inih/ini.h +0 -157
  39. data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/json_numeric.c +0 -177
  40. data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/jsonwriter.c +0 -444
  41. data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/jsonwriter.h +0 -145
  42. data/ext/zsv/vendor/zsv-1.3.0/app/external/json_writer-1.01/utils.c +0 -110
  43. data/ext/zsv/vendor/zsv-1.3.0/app/external/memfile-1.0/include/memfile.h +0 -15
  44. data/ext/zsv/vendor/zsv-1.3.0/app/external/memfile-1.0/src/memfile.c +0 -64
  45. data/ext/zsv/vendor/zsv-1.3.0/app/external/sglib/sglib.h +0 -1955
  46. data/ext/zsv/vendor/zsv-1.3.0/app/external/simdutf/simdutf.h +0 -6802
  47. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3.c +0 -230517
  48. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3.h +0 -12174
  49. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_and_csv_vtab.c +0 -2
  50. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab-mem.c +0 -142
  51. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab-mem.h +0 -49
  52. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab-zsv.c +0 -485
  53. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3_csv_vtab.c +0 -1015
  54. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/sqlite3ext.h +0 -663
  55. data/ext/zsv/vendor/zsv-1.3.0/app/external/sqlite3/vtab_helper.c +0 -85
  56. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_common.h +0 -75
  57. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_gen.h +0 -167
  58. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_parse.h +0 -228
  59. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_tree.h +0 -186
  60. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/build/yajl-2.1.1/include/yajl/yajl_version.h +0 -23
  61. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_common.h +0 -76
  62. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_gen.h +0 -167
  63. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_parse.h +0 -238
  64. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/api/yajl_tree.h +0 -186
  65. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl.c +0 -184
  66. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_alloc.c +0 -52
  67. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_alloc.h +0 -34
  68. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_buf.c +0 -103
  69. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_buf.h +0 -57
  70. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_bytestack.h +0 -69
  71. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_encode.c +0 -220
  72. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_encode.h +0 -34
  73. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_gen.c +0 -362
  74. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_lex.c +0 -764
  75. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_lex.h +0 -117
  76. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_parser.c +0 -508
  77. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_parser.h +0 -78
  78. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_tree.c +0 -505
  79. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl/src/yajl_version.c +0 -7
  80. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper/json_value.h +0 -59
  81. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper/yajl_helper.h +0 -208
  82. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper.c +0 -795
  83. data/ext/zsv/vendor/zsv-1.3.0/app/external/yajl_helper/yajl_helper_internal.h +0 -28
  84. data/ext/zsv/vendor/zsv-1.3.0/app/flatten.c +0 -851
  85. data/ext/zsv/vendor/zsv-1.3.0/app/jq.c +0 -106
  86. data/ext/zsv/vendor/zsv-1.3.0/app/jq.h +0 -6
  87. data/ext/zsv/vendor/zsv-1.3.0/app/mv.c +0 -113
  88. data/ext/zsv/vendor/zsv-1.3.0/app/noop.c +0 -90
  89. data/ext/zsv/vendor/zsv-1.3.0/app/overwrite.c +0 -295
  90. data/ext/zsv/vendor/zsv-1.3.0/app/paste.c +0 -175
  91. data/ext/zsv/vendor/zsv-1.3.0/app/pretty.c +0 -693
  92. data/ext/zsv/vendor/zsv-1.3.0/app/prop.c +0 -980
  93. data/ext/zsv/vendor/zsv-1.3.0/app/rm.c +0 -131
  94. data/ext/zsv/vendor/zsv-1.3.0/app/select/fixed.c +0 -130
  95. data/ext/zsv/vendor/zsv-1.3.0/app/select/internal.h +0 -118
  96. data/ext/zsv/vendor/zsv-1.3.0/app/select/parallel.c +0 -45
  97. data/ext/zsv/vendor/zsv-1.3.0/app/select/parallel.h +0 -41
  98. data/ext/zsv/vendor/zsv-1.3.0/app/select/processing.c +0 -107
  99. data/ext/zsv/vendor/zsv-1.3.0/app/select/rand.c +0 -20
  100. data/ext/zsv/vendor/zsv-1.3.0/app/select/regex.c +0 -61
  101. data/ext/zsv/vendor/zsv-1.3.0/app/select/search.c +0 -14
  102. data/ext/zsv/vendor/zsv-1.3.0/app/select/selection.c +0 -192
  103. data/ext/zsv/vendor/zsv-1.3.0/app/select/usage.c +0 -72
  104. data/ext/zsv/vendor/zsv-1.3.0/app/select-pull.c +0 -812
  105. data/ext/zsv/vendor/zsv-1.3.0/app/select.c +0 -753
  106. data/ext/zsv/vendor/zsv-1.3.0/app/serialize.c +0 -372
  107. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/curses.h +0 -15
  108. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/cursor.c +0 -119
  109. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/errors.c +0 -45
  110. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/file.c +0 -63
  111. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/file.h +0 -12
  112. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/filter.c +0 -166
  113. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/handlers.c +0 -214
  114. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/handlers_internal.h +0 -128
  115. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/help.c +0 -43
  116. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/index.c +0 -81
  117. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/index.h +0 -25
  118. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/key-bindings.c +0 -325
  119. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/key-bindings.h +0 -73
  120. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/lexer.c +0 -203
  121. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/newline_handler.c +0 -7
  122. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/pivot.c +0 -318
  123. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/procedure.c +0 -134
  124. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/procedure.h +0 -119
  125. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/read-data.c +0 -322
  126. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/screen_buffer.c +0 -203
  127. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/screen_buffer.h +0 -36
  128. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/sheet-sql.c +0 -167
  129. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/sheet_internal.h +0 -36
  130. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/sqlfilter.c +0 -153
  131. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/terminfo.c +0 -32
  132. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/transformation.c +0 -312
  133. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/transformation.h +0 -29
  134. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/ui_buffer.c +0 -266
  135. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/usage.c +0 -9
  136. data/ext/zsv/vendor/zsv-1.3.0/app/sheet/utf8-width.c +0 -60
  137. data/ext/zsv/vendor/zsv-1.3.0/app/sheet.c +0 -1007
  138. data/ext/zsv/vendor/zsv-1.3.0/app/sql.c +0 -453
  139. data/ext/zsv/vendor/zsv-1.3.0/app/sql_internal.c +0 -101
  140. data/ext/zsv/vendor/zsv-1.3.0/app/sql_internal.h +0 -49
  141. data/ext/zsv/vendor/zsv-1.3.0/app/stack.c +0 -393
  142. data/ext/zsv/vendor/zsv-1.3.0/app/utils/arg.c +0 -322
  143. data/ext/zsv/vendor/zsv-1.3.0/app/utils/cache.c +0 -228
  144. data/ext/zsv/vendor/zsv-1.3.0/app/utils/cat.c +0 -91
  145. data/ext/zsv/vendor/zsv-1.3.0/app/utils/chunk.c +0 -240
  146. data/ext/zsv/vendor/zsv-1.3.0/app/utils/chunk.h +0 -63
  147. data/ext/zsv/vendor/zsv-1.3.0/app/utils/clock.c +0 -57
  148. data/ext/zsv/vendor/zsv-1.3.0/app/utils/db.c +0 -148
  149. data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs-no-jq.c +0 -2
  150. data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs.c +0 -427
  151. data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs_from_json.c +0 -253
  152. data/ext/zsv/vendor/zsv-1.3.0/app/utils/dirs_to_json.c +0 -121
  153. data/ext/zsv/vendor/zsv-1.3.0/app/utils/dl.c +0 -20
  154. data/ext/zsv/vendor/zsv-1.3.0/app/utils/emcc/fs_api.c +0 -159
  155. data/ext/zsv/vendor/zsv-1.3.0/app/utils/err.c +0 -24
  156. data/ext/zsv/vendor/zsv-1.3.0/app/utils/file-mem.c +0 -180
  157. data/ext/zsv/vendor/zsv-1.3.0/app/utils/file.c +0 -256
  158. data/ext/zsv/vendor/zsv-1.3.0/app/utils/index.c +0 -197
  159. data/ext/zsv/vendor/zsv-1.3.0/app/utils/index.h +0 -49
  160. data/ext/zsv/vendor/zsv-1.3.0/app/utils/jq.c +0 -400
  161. data/ext/zsv/vendor/zsv-1.3.0/app/utils/json.c +0 -120
  162. data/ext/zsv/vendor/zsv-1.3.0/app/utils/mem.c +0 -18
  163. data/ext/zsv/vendor/zsv-1.3.0/app/utils/memmem.c +0 -132
  164. data/ext/zsv/vendor/zsv-1.3.0/app/utils/os.c +0 -178
  165. data/ext/zsv/vendor/zsv-1.3.0/app/utils/overwrite.c +0 -258
  166. data/ext/zsv/vendor/zsv-1.3.0/app/utils/overwrite_writer.c +0 -246
  167. data/ext/zsv/vendor/zsv-1.3.0/app/utils/pcre2-8/pcre2-8-test.c +0 -123
  168. data/ext/zsv/vendor/zsv-1.3.0/app/utils/pcre2-8/pcre2-8.c +0 -153
  169. data/ext/zsv/vendor/zsv-1.3.0/app/utils/pcre2-8/pcre2-8.h +0 -54
  170. data/ext/zsv/vendor/zsv-1.3.0/app/utils/prop.c +0 -267
  171. data/ext/zsv/vendor/zsv-1.3.0/app/utils/signal.c +0 -53
  172. data/ext/zsv/vendor/zsv-1.3.0/app/utils/string.c +0 -357
  173. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/dir_exists_longpath.c +0 -83
  174. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/dl.c +0 -33
  175. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/fopen_longpath.c +0 -184
  176. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/foreach_dirent_longpath.c +0 -292
  177. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/io.c +0 -259
  178. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/io.h +0 -13
  179. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/mkdir_longpath.c +0 -255
  180. data/ext/zsv/vendor/zsv-1.3.0/app/utils/win/remove_longpath.c +0 -96
  181. data/ext/zsv/vendor/zsv-1.3.0/app/utils/writer.c +0 -361
  182. data/ext/zsv/vendor/zsv-1.3.0/app/zsv_command.h +0 -40
  183. data/ext/zsv/vendor/zsv-1.3.0/app/zsv_command_standalone.c +0 -16
  184. data/ext/zsv/vendor/zsv-1.3.0/app/zsv_main.h +0 -44
  185. data/ext/zsv/vendor/zsv-1.3.0/examples/js/zsv_parser_api_dummy.c +0 -3
  186. data/ext/zsv/vendor/zsv-1.3.0/examples/lib/parse_by_chunk.c +0 -100
  187. data/ext/zsv/vendor/zsv-1.3.0/examples/lib/print_my_column.c +0 -143
  188. data/ext/zsv/vendor/zsv-1.3.0/examples/lib/pull.c +0 -89
  189. data/ext/zsv/vendor/zsv-1.3.0/examples/lib/simple.c +0 -123
  190. data/ext/zsv/vendor/zsv-1.3.0/fuzz/fuzz.c +0 -16
  191. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/api.h +0 -336
  192. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/common.h +0 -361
  193. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/ext/implementation.h +0 -62
  194. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/ext/implementation_private.h +0 -113
  195. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/ext/sheet.h +0 -73
  196. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/ext.h +0 -329
  197. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/arg.h +0 -90
  198. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/cache.h +0 -49
  199. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/clock.h +0 -36
  200. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/compiler.h +0 -58
  201. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/db.h +0 -19
  202. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/dirs.h +0 -147
  203. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/dl.h +0 -22
  204. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/emcc/fs_api.h +0 -28
  205. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/err.h +0 -22
  206. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/file-mem.h +0 -17
  207. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/file.h +0 -99
  208. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/jq.h +0 -65
  209. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/json.h +0 -19
  210. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/mem.h +0 -19
  211. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/memmem.h +0 -13
  212. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/os.h +0 -54
  213. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/overwrite.h +0 -71
  214. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/overwrite_writer.h +0 -53
  215. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/prop.h +0 -107
  216. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/signal.h +0 -18
  217. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/sql.h +0 -11
  218. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/string.h +0 -148
  219. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/utf8.h +0 -41
  220. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/win/dl.h +0 -25
  221. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/utils/writer.h +0 -101
  222. data/ext/zsv/vendor/zsv-1.3.0/include/zsv/zsv_export.h +0 -33
  223. data/ext/zsv/vendor/zsv-1.3.0/include/zsv.h +0 -20
  224. data/ext/zsv/vendor/zsv-1.3.0/src/vector_delim.c +0 -60
  225. data/ext/zsv/vendor/zsv-1.3.0/src/zsv.c +0 -484
  226. data/ext/zsv/vendor/zsv-1.3.0/src/zsv_internal.c +0 -731
  227. data/ext/zsv/vendor/zsv-1.3.0/src/zsv_scan_delim.c +0 -285
  228. data/ext/zsv/vendor/zsv-1.3.0/src/zsv_scan_fixed.c +0 -88
  229. data/ext/zsv/vendor/zsv-1.3.0/src/zsv_strencode.c +0 -51
@@ -1,148 +0,0 @@
1
- #include <stdio.h>
2
- #include <string.h>
3
- #include <sqlite3.h>
4
- #include <jsonwriter.h>
5
- #include <zsv/utils/string.h>
6
-
7
- // starts_w_str_underscore(): helper function
8
- // returns 1 if s starts with prefix (case-insensitive), followed by underscore
9
- static char starts_w_str_underscore(const unsigned char *s, size_t s_len, const unsigned char *prefix) {
10
- char result = 0;
11
- unsigned char *s_lc = zsv_strtolowercase(s, &s_len);
12
- size_t pfx_len = strlen((const char *)prefix);
13
- unsigned char *prefix_lc = zsv_strtolowercase(prefix, &pfx_len);
14
- if (pfx_len + 1 < s_len && !memcmp(s_lc, prefix_lc, pfx_len) && s_lc[pfx_len] == '_')
15
- result = 1;
16
- free(s_lc);
17
- free(prefix_lc);
18
- return result;
19
- }
20
-
21
- int zsv_dbtable2json(sqlite3 *db, const char *tname, jsonwriter_handle jsw, size_t limit) {
22
- int err = 0;
23
- const char *index_sql = "select name, sql from sqlite_master where type = 'index' and tbl_name = :tbl_name";
24
- const char *unique_sql = "select 1 from PRAGMA_index_list(?) where name = ? and [unique] <> 0";
25
- sqlite3_str *data_sql = sqlite3_str_new(db);
26
- if (data_sql) {
27
- sqlite3_str_appendf(data_sql, "select * from \"%w\"", tname);
28
- sqlite3_stmt *data_stmt = NULL;
29
- sqlite3_stmt *index_stmt = NULL;
30
- sqlite3_stmt *unique_stmt = NULL;
31
- int colcount = 0;
32
-
33
- err = 1;
34
- if (sqlite3_prepare_v2(db, sqlite3_str_value(data_sql), -1, &data_stmt, NULL) != SQLITE_OK)
35
- fprintf(stderr, "Unable to prepare %s: %s\n", sqlite3_str_value(data_sql), sqlite3_errmsg(db));
36
- else if (!(colcount = sqlite3_column_count(data_stmt)))
37
- fprintf(stderr, "No columns found in table %s\n", tname);
38
- else if (sqlite3_prepare_v2(db, index_sql, -1, &index_stmt, NULL) != SQLITE_OK)
39
- fprintf(stderr, "Unable to prepare %s: %s\n", index_sql, sqlite3_errmsg(db));
40
- else if (sqlite3_prepare_v2(db, unique_sql, -1, &unique_stmt, NULL) != SQLITE_OK)
41
- fprintf(stderr, "Unable to prepare %s: %s\n", unique_sql, sqlite3_errmsg(db));
42
- else {
43
- err = 0;
44
- jsonwriter_start_array(jsw); // output is an array with 2 items: meta and data
45
-
46
- // ----- meta: columns and index info
47
- jsonwriter_start_object(jsw);
48
-
49
- jsonwriter_object_cstr(jsw, "name", tname);
50
-
51
- // indexes
52
- jsonwriter_object_object(jsw, "indexes"); // indexes
53
- sqlite3_bind_text(index_stmt, 1, tname, (int)strlen(tname), SQLITE_STATIC);
54
- while (sqlite3_step(index_stmt) == SQLITE_ROW) {
55
- const unsigned char *text = sqlite3_column_text(index_stmt, 0);
56
- const unsigned char *ix_sql = sqlite3_column_text(index_stmt, 1);
57
- size_t len = text ? sqlite3_column_bytes(index_stmt, 0) : 0;
58
- size_t ix_sql_len = ix_sql ? sqlite3_column_bytes(index_stmt, 1) : 0;
59
-
60
- if (text && ix_sql && len && ix_sql_len) {
61
- // on: for now we just look for the first and last parens
62
- const unsigned char *first_paren = memchr(ix_sql, '(', ix_sql_len);
63
- const unsigned char *last_paren = ix_sql + ix_sql_len;
64
- while (first_paren && last_paren > first_paren + 1 && *last_paren != ')')
65
- last_paren--;
66
- if (first_paren && last_paren > first_paren) {
67
- // name
68
-
69
- // strip the leading "tablename_" from the index name
70
- const char *ix_name = (const char *)text;
71
- size_t ix_name_len = len;
72
- if (ix_name_len > strlen(tname) + 1 &&
73
- starts_w_str_underscore((const unsigned char *)ix_name, ix_name_len, (const unsigned char *)tname)) {
74
- ix_name += strlen(tname) + 1;
75
- ix_name_len -= strlen(tname) + 1;
76
- }
77
- jsonwriter_object_keyn(jsw, (const char *)ix_name, ix_name_len);
78
-
79
- // ix obj
80
- jsonwriter_start_object(jsw);
81
-
82
- // on
83
- jsonwriter_object_strn(jsw, "on", first_paren + 1, last_paren - first_paren - 1);
84
-
85
- // unique
86
- sqlite3_bind_text(unique_stmt, 1, tname, (int)strlen(tname), SQLITE_STATIC);
87
- sqlite3_bind_text(unique_stmt, 2, (const char *)text, len, SQLITE_STATIC);
88
- if (sqlite3_step(unique_stmt) == SQLITE_ROW)
89
- jsonwriter_object_bool(jsw, "unique", 1);
90
- sqlite3_reset(unique_stmt);
91
-
92
- // end ix obj
93
- jsonwriter_end_object(jsw);
94
- }
95
- }
96
- }
97
- jsonwriter_end_object(jsw); // end indexes
98
-
99
- // columns
100
- jsonwriter_object_array(jsw, "columns");
101
- for (int i = 0; i < colcount; i++) {
102
- const char *colname = sqlite3_column_name(data_stmt, i);
103
- jsonwriter_start_object(jsw);
104
- jsonwriter_object_cstr(jsw, "name", colname);
105
- const char *dtype = sqlite3_column_decltype(data_stmt, i);
106
- if (dtype)
107
- jsonwriter_object_cstr(jsw, "datatype", dtype);
108
-
109
- // TO DO: collate nocase etc
110
- jsonwriter_end_object(jsw);
111
- }
112
- jsonwriter_end_array(jsw); // end columns
113
-
114
- jsonwriter_end_object(jsw); // end meta obj
115
-
116
- // ------ data: array of rows
117
- jsonwriter_start_array(jsw);
118
- // for each row
119
- size_t count = 0;
120
- while (sqlite3_step(data_stmt) == SQLITE_ROW) {
121
- jsonwriter_start_array(jsw); // start row
122
- for (int i = 0; i < colcount; i++) {
123
- const unsigned char *text = sqlite3_column_text(data_stmt, i);
124
- if (text) {
125
- int len = sqlite3_column_bytes(data_stmt, i);
126
- jsonwriter_strn(jsw, text, len);
127
- } else
128
- jsonwriter_null(jsw);
129
- }
130
- jsonwriter_end_array(jsw); // end row
131
- if (limit && ++count >= limit)
132
- break;
133
- }
134
- jsonwriter_end_array(jsw);
135
-
136
- jsonwriter_end_array(jsw); // end of output
137
- }
138
- if (data_stmt)
139
- sqlite3_finalize(data_stmt);
140
- if (index_stmt)
141
- sqlite3_finalize(index_stmt);
142
- if (unique_stmt)
143
- sqlite3_finalize(unique_stmt);
144
-
145
- sqlite3_free(sqlite3_str_finish(data_sql));
146
- } // if data_sql
147
- return err;
148
- }
@@ -1,2 +0,0 @@
1
- #define ZSV_NO_JQ
2
- #include "dirs.c"
@@ -1,427 +0,0 @@
1
- /*
2
- * Copyright (C) 2021 Liquidaty and the zsv/lib contributors
3
- * All rights reserved
4
- *
5
- * This file is part of zsv/lib, distributed under the license defined at
6
- * https://opensource.org/licenses/MIT
7
- */
8
-
9
- #include <stddef.h>
10
- #include <stdlib.h>
11
- #include <stdio.h>
12
- #include <string.h>
13
- #include <dirent.h>
14
- #include <errno.h>
15
- #include <zsv/utils/os.h>
16
- #ifndef ZSV_NO_JQ
17
- #include <zsv/utils/json.h>
18
- #include <zsv/utils/jq.h>
19
- #endif
20
- #include <zsv/utils/dirs.h>
21
- #include <zsv/utils/string.h>
22
- #include <unistd.h> // unlink
23
- #include <sys/stat.h>
24
- #ifndef ZSV_NO_JQ
25
- #include <yajl_helper/yajl_helper.h>
26
- #endif
27
-
28
- #if defined(_WIN32)
29
- #include <windows.h>
30
- #include "win/io.c"
31
- #endif
32
-
33
- /**
34
- * Most of these functions require the caller to provide a buffer, in which case
35
- * the buffer size should be at least FILENAME_MAX
36
- */
37
-
38
- static size_t chop_slash(char *buff, size_t len) {
39
- if (buff[len - 1] == '\\' || buff[len - 1] == '/') {
40
- buff[len - 1] = '\0';
41
- len--;
42
- }
43
- return (size_t)len;
44
- }
45
-
46
- /**
47
- * Get os-independent configuration file path
48
- * prefix should be determined at compile time e.g. /usr/local or ""
49
- * @return length written to buff, or 0 if failed
50
- */
51
- size_t zsv_get_config_dir(char *buff, size_t buffsize, const char *prefix) {
52
- #if defined(_WIN32)
53
- const char *env_val = getenv("ZSV_CONFIG_DIR");
54
- (void)(prefix);
55
- // if(!(env_val && *env_val))
56
- // env_val = getenv(prefix);
57
- if (!(env_val && *env_val))
58
- env_val = getenv("LOCALAPPDATA");
59
- if (!(env_val && *env_val))
60
- env_val = "C:\\temp";
61
- int written = snprintf(buff, buffsize, "%s", env_val);
62
- #elif defined(__EMSCRIPTEN__)
63
- (void)(prefix);
64
- int written = snprintf(buff, buffsize, "/tmp");
65
- #else
66
- int written;
67
- const char *env_val = getenv("ZSV_CONFIG_DIR");
68
- if (env_val && *env_val)
69
- written = snprintf(buff, buffsize, "%s", env_val);
70
- else
71
- written = snprintf(buff, buffsize, "%s/etc", prefix ? prefix : "");
72
- #endif
73
- if (written > 0 && ((size_t)written) < buffsize)
74
- return chop_slash(buff, written);
75
- return 0;
76
- }
77
-
78
- /**
79
- * Check if a directory exists
80
- * return true (non-zero) or false (zero)
81
- */
82
- #ifdef WIN32
83
- #include "win/dir_exists_longpath.c"
84
- #endif
85
- int zsv_dir_exists(const char *path) {
86
- #ifdef WIN32
87
- if (strlen(path) >= MAX_PATH)
88
- return zsv_dir_exists_winlp(path);
89
-
90
- // TO DO: support win long filepath prefix
91
- // TO DO: work properly if dir exists but we don't have permission
92
- wchar_t wpath[MAX_PATH];
93
- mbstowcs(wpath, path, MAX_PATH);
94
-
95
- DWORD attrs = GetFileAttributesW(wpath);
96
- if (attrs == INVALID_FILE_ATTRIBUTES)
97
- // Could check GetLastError() to see if it's a permission issue vs. not-found
98
- return 0;
99
-
100
- // If it has the directory attribute, it's presumably a directory
101
- return (attrs & FILE_ATTRIBUTE_DIRECTORY) != 0;
102
-
103
- #else
104
- struct stat path_stat;
105
- if (!stat(path, &path_stat))
106
- return S_ISDIR(path_stat.st_mode);
107
- return 0;
108
- #endif
109
- }
110
-
111
- /**
112
- * Make a directory, as well as any intermediate dirs
113
- * return zero on success
114
- */
115
- #ifdef WIN32
116
- #include "win/mkdir_longpath.c"
117
- #define zsv_mkdir zsv_mkdir_winlp
118
- #else
119
- #define zsv_mkdir mkdir
120
- #endif
121
-
122
- int zsv_mkdirs(const char *path, char path_is_filename) {
123
- // int rc = 0;
124
- if (!path || !*path)
125
- return -1;
126
- size_t len = strlen(path);
127
- if (len < 1)
128
- return -1;
129
-
130
- char *tmp = strdup(path);
131
- if (!tmp) {
132
- perror(path);
133
- return -1;
134
- }
135
-
136
- if (len && strchr("/\\", tmp[len - 1]))
137
- tmp[--len] = 0;
138
-
139
- int offset = 0;
140
- #ifdef WIN32
141
- if (len > 1) {
142
- // starts with two slashes
143
- if (strchr("/\\", tmp[0]) && strchr("/\\", tmp[1])) {
144
- offset = 2;
145
- // find the next slash
146
- char *path_end = tmp + 3;
147
- while (*path_end && !strchr("/\\", *path_end))
148
- path_end++;
149
- if (*path_end)
150
- path_end++;
151
- if (*path_end)
152
- offset = path_end - tmp;
153
- else {
154
- fprintf(stderr, "Invalid path: %s\n", path);
155
- free(tmp);
156
- return -1;
157
- }
158
- }
159
- // starts with *:
160
- else if (tmp[1] == ':')
161
- offset = 2;
162
- }
163
- #else
164
- offset = 1;
165
- #endif
166
-
167
- // TO DO: first find the longest subdir that exists, in *reverse* order so as
168
- // to properly handle case where no access to intermediate dir,
169
- // and then only start mkdir from there
170
- int last_dir_exists_rc = 0;
171
- int last_errno = -1;
172
- for (char *p = tmp + offset; /* !rc && */ *p; p++) {
173
- if (strchr("/\\", *p)) {
174
- char tmp_c = p[1];
175
- p[0] = FILESLASH;
176
- p[1] = '\0';
177
- if (*tmp && !(last_dir_exists_rc = zsv_dir_exists(tmp))) {
178
- if (zsv_mkdir(tmp
179
- #ifndef WIN32
180
- ,
181
- S_IRWXU
182
- #endif
183
- )) {
184
- if (errno == EEXIST)
185
- last_dir_exists_rc = 1;
186
- else { // errno could be EEXIST if we have no permissions to an intermediate directory
187
- last_errno = errno;
188
- perror(tmp);
189
- // rc = -1;
190
- }
191
- } else
192
- last_dir_exists_rc = 1;
193
- }
194
- p[1] = tmp_c;
195
- }
196
- }
197
-
198
- if (/* !rc && */ path_is_filename == 0 && *tmp && !(last_dir_exists_rc = zsv_dir_exists(tmp))) {
199
- if (zsv_mkdir(tmp
200
- #ifndef WIN32
201
- ,
202
- S_IRWXU
203
- #endif
204
- )) {
205
- if (errno == EEXIST)
206
- last_dir_exists_rc = 1;
207
- else {
208
- last_errno = errno;
209
- perror(tmp);
210
- // rc = -1;
211
- }
212
- } else
213
- last_dir_exists_rc = 1;
214
- }
215
-
216
- free(tmp);
217
- return last_dir_exists_rc ? 0 : last_errno ? last_errno : -1;
218
- }
219
-
220
- #if defined(_WIN32)
221
- size_t zsv_get_executable_path(char *buff, size_t buffsize) {
222
- return GetModuleFileNameA(NULL, buff, (DWORD)buffsize);
223
- }
224
-
225
- #elif defined(__APPLE__)
226
- #include <mach-o/dyld.h>
227
- size_t zsv_get_executable_path(char *buff, size_t bufflen) {
228
- uint32_t pathlen = bufflen;
229
- if (!_NSGetExecutablePath(buff, &pathlen)) {
230
- char real[FILENAME_MAX];
231
- if (realpath(buff, real) != NULL && strlen(real) < bufflen) {
232
- bufflen = strlen(real);
233
- memcpy(buff, real, bufflen);
234
- buff[bufflen] = '\0';
235
- } else
236
- bufflen = pathlen;
237
- return bufflen;
238
- }
239
- return 0;
240
- }
241
- #elif defined(__linux__) || defined(__EMSCRIPTEN__)
242
- #include <unistd.h>
243
- size_t zsv_get_executable_path(char *buff, size_t buffsize) {
244
- buffsize = readlink("/proc/self/exe", buff, buffsize - 1);
245
- buff[buffsize] = '\0';
246
- return buffsize;
247
- }
248
- #elif defined(__FreeBSD__)
249
- #include <sys/stat.h>
250
- #include <sys/sysctl.h>
251
- size_t zsv_get_executable_path(char *buff, size_t buffsize) {
252
- int mib[4];
253
- mib[0] = CTL_KERN;
254
- mib[1] = KERN_PROC;
255
- mib[2] = KERN_PROC_PATHNAME;
256
- mib[3] = -1;
257
- sysctl(mib, 4, buff, &buffsize, NULL, 0);
258
- buff[buffsize] = '\0';
259
- return buffsize;
260
- }
261
- #else
262
- // TODO: Add support for this OS!
263
- #endif /* end of: #if defined(_WIN32) */
264
-
265
- /**
266
- * Get current user's home dir, without trailing slash
267
- * On win, any backslashes are replaced with fwd slash
268
- * ex: zsv_get_home_dir(char[MAX_PATH], MAX_PATH)
269
- * returns 0 if no home dir could be found
270
- * returns > 0 and < bufflen on success
271
- * returns > 0 and >= bufflen if buffer was too small
272
- */
273
- int zsv_get_home_dir(char *buff, size_t bufflen) {
274
- int written = 0;
275
- if (getenv("HOME"))
276
- written = snprintf(buff, bufflen, "%s", getenv("HOME"));
277
- #if defined(WIN32) || defined(_WIN32)
278
- if (!written && getenv("HOMEDRIVE") && getenv("HOMEPATH"))
279
- written = snprintf(buff, bufflen, "%s%s", getenv("HOMEDRIVE"), getenv("HOMEPATH"));
280
- #endif
281
- if (written > 0 && ((size_t)written) < bufflen) {
282
- if (buff[written - 1] == '\\' || buff[written - 1] == '/') {
283
- buff[written - 1] = '\0';
284
- written--;
285
- }
286
- }
287
- #if defined(WIN32) || defined(_WIN32)
288
- for (int i = 0; i < written; i++)
289
- if (buff[i] == '\\')
290
- buff[i] = '/';
291
- #endif
292
- return written;
293
- }
294
-
295
- struct dir_path {
296
- struct dir_path *next;
297
- char *path;
298
- };
299
-
300
- /**
301
- * remove an empty directory; on error print msg to stderr
302
- * return 0 on success
303
- */
304
- static int rmdir_w_msg(const char *path, int *err) {
305
- #ifdef WIN32
306
- if (!RemoveDirectoryA(path)) {
307
- zsv_perror(path);
308
- // zsv_win_printLastError();
309
- *err = 1;
310
- }
311
- #else
312
- if (remove(path)) {
313
- perror(path);
314
- *err = 1;
315
- }
316
- #endif
317
- return *err;
318
- }
319
-
320
- static int zsv_foreach_dirent_remove(struct zsv_foreach_dirent_handle *h, size_t depth) {
321
- (void)(depth);
322
- if (!h->is_dir) { // file
323
- if (h->parent_and_entry) {
324
- if (zsv_remove(h->parent_and_entry)) {
325
- perror(h->parent_and_entry); // "Unable to remove file");
326
- return 1;
327
- }
328
- }
329
- } else { // dir
330
- if (h->parent_and_entry) {
331
- struct dir_path *dn = calloc(1, sizeof(*dn));
332
- if (!dn) {
333
- fprintf(stderr, "Out of memory!\n");
334
- return 1;
335
- }
336
- dn->path = strdup(h->parent_and_entry);
337
- dn->next = *((struct dir_path **)h->ctx);
338
- *((struct dir_path **)h->ctx) = dn;
339
- }
340
- }
341
- return 0;
342
- }
343
-
344
- #ifdef _WIN32
345
- #include "win/foreach_dirent_longpath.c"
346
- #else
347
- // return error
348
- static int zsv_foreach_dirent_aux(const char *dir_path, size_t depth, size_t max_depth,
349
- zsv_foreach_dirent_handler handler, void *ctx, char verbose) {
350
- int err = 0;
351
- if (!dir_path)
352
- return 1;
353
-
354
- if (max_depth > 0 && depth >= max_depth)
355
- return 0;
356
-
357
- DIR *dr;
358
- if ((dr = opendir(dir_path))) {
359
- struct dirent *de;
360
- while ((de = readdir(dr)) != NULL) {
361
- if (!*de->d_name || !strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
362
- continue;
363
- char *tmp;
364
- asprintf(&tmp, "%s%c%s", dir_path, FILESLASH, de->d_name);
365
- if (!tmp)
366
- fprintf(stderr, "Out of memory!\n"), err = 1;
367
- else {
368
- struct zsv_foreach_dirent_handle h = {0};
369
- h.verbose = verbose;
370
- stat(tmp, (struct stat *)&h.stat);
371
- h.parent = dir_path;
372
- h.entry = de->d_name;
373
- h.parent_and_entry = tmp;
374
- h.ctx = ctx;
375
- char is_dir = h.stat.st_mode & S_IFDIR ? 1 : 0;
376
- h.is_dir = is_dir;
377
- if (handler)
378
- handler(&h, depth + 1);
379
-
380
- if (is_dir && !h.no_recurse)
381
- // recurse!
382
- err = zsv_foreach_dirent_aux(tmp, depth + 1, max_depth, handler, ctx, verbose);
383
- free(tmp);
384
- }
385
- }
386
- closedir(dr);
387
- }
388
- return err;
389
- }
390
- #endif
391
-
392
- int zsv_foreach_dirent(const char *dir_path, size_t max_depth, zsv_foreach_dirent_handler handler, void *ctx,
393
- char verbose) {
394
- return zsv_foreach_dirent_aux(dir_path, 0, max_depth, handler, ctx, verbose);
395
- }
396
-
397
- /**
398
- * Remove a directory and all of its contents
399
- */
400
- int zsv_remove_dir_recursive(const unsigned char *path) {
401
- // we will delete all files first, then
402
- // delete directories in the reverse order we received them
403
- struct dir_path *reverse_dirs = NULL;
404
- int err = zsv_foreach_dirent((const char *)path, 0, zsv_foreach_dirent_remove, &reverse_dirs, 0);
405
-
406
- // unlink each dir
407
- for (struct dir_path *dn = reverse_dirs; !err && dn; dn = dn->next)
408
- rmdir_w_msg(dn->path, &err);
409
-
410
- // free each dir
411
- for (struct dir_path *next, *dn = reverse_dirs; !err && dn; dn = next) {
412
- next = dn->next;
413
- free(dn->path);
414
- free(dn);
415
- }
416
- if (!err)
417
- rmdir_w_msg((const char *)path, &err);
418
-
419
- return err;
420
- }
421
-
422
- #ifndef ZSV_NO_JQ
423
- #include "dirs_to_json.c"
424
-
425
- #include "dirs_from_json.c"
426
-
427
- #endif