@port-labs/jq-node-bindings 0.0.13 → 0.0.15-dev1

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 (453) hide show
  1. package/README.md +6 -1
  2. package/binding.gyp +41 -19
  3. package/configure +1 -1
  4. package/deps/jq/.gitattributes +12 -0
  5. package/deps/jq/AUTHORS +149 -43
  6. package/deps/jq/COPYING +75 -1
  7. package/deps/jq/ChangeLog +2 -2
  8. package/deps/jq/Makefile.am +106 -65
  9. package/deps/jq/NEWS.md +391 -0
  10. package/deps/jq/README.md +54 -52
  11. package/deps/jq/SECURITY.md +7 -0
  12. package/deps/jq/compile-ios.sh +106 -102
  13. package/deps/jq/configure.ac +72 -59
  14. package/deps/jq/docs/Pipfile +14 -0
  15. package/deps/jq/docs/Pipfile.lock +415 -0
  16. package/deps/jq/docs/README.md +15 -14
  17. package/deps/jq/docs/build_manpage.py +251 -0
  18. package/deps/jq/docs/build_mantests.py +21 -0
  19. package/deps/jq/docs/build_website.py +95 -0
  20. package/deps/jq/docs/content/download/default.yml +249 -0
  21. package/deps/jq/docs/content/index.yml +83 -0
  22. package/deps/jq/docs/content/{3.manual/v1.6 → manual/dev}/manual.yml +992 -452
  23. package/deps/jq/docs/content/{3.manual → manual}/v1.3/manual.yml +105 -116
  24. package/deps/jq/docs/content/{3.manual → manual}/v1.4/manual.yml +122 -129
  25. package/deps/jq/docs/content/{3.manual → manual}/v1.5/manual.yml +313 -262
  26. package/deps/jq/docs/content/{3.manual → manual/v1.6}/manual.yml +407 -332
  27. package/deps/jq/docs/content/manual/v1.7/manual.yml +3697 -0
  28. package/deps/jq/docs/content/tutorial/default.yml +337 -0
  29. package/deps/jq/docs/manual_schema.yml +60 -0
  30. package/deps/jq/docs/public/css/style.css +99 -0
  31. package/deps/jq/docs/public/icon.png +0 -0
  32. package/deps/jq/docs/public/icon.svg +1 -0
  33. package/deps/jq/docs/public/jq.svg +1 -0
  34. package/deps/jq/docs/public/js/manual-search.js +31 -49
  35. package/deps/jq/docs/templates/default.html.j2 +31 -0
  36. package/deps/jq/docs/templates/index.html.j2 +58 -0
  37. package/deps/jq/docs/templates/manual.html.j2 +120 -0
  38. package/deps/jq/docs/templates/shared/_footer.html.j2 +14 -0
  39. package/deps/jq/docs/templates/shared/_head.html.j2 +23 -0
  40. package/deps/jq/docs/templates/shared/_navbar.html.j2 +40 -0
  41. package/deps/jq/docs/validate_manual_schema.py +19 -0
  42. package/deps/jq/jq.1.prebuilt +1102 -294
  43. package/deps/jq/jq.spec +2 -3
  44. package/deps/jq/libjq.pc.in +11 -0
  45. package/deps/jq/m4/ax_pthread.m4 +522 -0
  46. package/deps/jq/modules/oniguruma/.travis.yml +17 -0
  47. package/deps/jq/modules/oniguruma/CMakeLists.txt +206 -41
  48. package/deps/jq/modules/oniguruma/COPYING +23 -25
  49. package/deps/jq/modules/oniguruma/HISTORY +368 -23
  50. package/deps/jq/modules/oniguruma/Makefile.am +61 -7
  51. package/deps/jq/modules/oniguruma/README +34 -20
  52. package/deps/jq/modules/oniguruma/README.md +106 -33
  53. package/deps/jq/modules/oniguruma/README_japanese +183 -0
  54. package/deps/jq/modules/oniguruma/autogen.sh +9 -0
  55. package/deps/jq/modules/oniguruma/cmake/Config.cmake.in +4 -0
  56. package/deps/jq/modules/oniguruma/configure.ac +66 -55
  57. package/deps/jq/modules/oniguruma/doc/API +485 -42
  58. package/deps/jq/modules/oniguruma/doc/API.ja +732 -293
  59. package/deps/jq/modules/oniguruma/doc/CALLOUTS.API +397 -0
  60. package/deps/jq/modules/oniguruma/doc/CALLOUTS.API.ja +393 -0
  61. package/deps/jq/modules/oniguruma/doc/CALLOUTS.BUILTIN +95 -0
  62. package/deps/jq/modules/oniguruma/doc/CALLOUTS.BUILTIN.ja +93 -0
  63. package/deps/jq/modules/oniguruma/doc/FAQ +3 -3
  64. package/deps/jq/modules/oniguruma/doc/FAQ.ja +8 -8
  65. package/deps/jq/modules/oniguruma/doc/RE +223 -63
  66. package/deps/jq/modules/oniguruma/doc/RE.ja +420 -265
  67. package/deps/jq/modules/oniguruma/doc/SYNTAX.md +1091 -0
  68. package/deps/jq/modules/oniguruma/doc/UNICODE_PROPERTIES +840 -697
  69. package/deps/jq/modules/oniguruma/harnesses/ascii_compatible.dict +113 -0
  70. package/deps/jq/modules/oniguruma/harnesses/base.c +749 -0
  71. package/deps/jq/modules/oniguruma/harnesses/deluxe.c +206 -0
  72. package/deps/jq/modules/oniguruma/harnesses/dict_conv.py +72 -0
  73. package/deps/jq/modules/oniguruma/harnesses/fuzzer.options +2 -0
  74. package/deps/jq/modules/oniguruma/harnesses/libfuzzer-onig.cpp +45 -0
  75. package/deps/jq/modules/oniguruma/harnesses/regset.c +392 -0
  76. package/deps/jq/modules/oniguruma/index.html +16 -5
  77. package/deps/jq/modules/oniguruma/index_ja.html +16 -5
  78. package/deps/jq/modules/oniguruma/make_win.bat +5 -0
  79. package/deps/jq/modules/oniguruma/make_win32.bat +5 -3
  80. package/deps/jq/modules/oniguruma/make_win64.bat +5 -3
  81. package/deps/jq/modules/oniguruma/onig-config.cmake.in +80 -0
  82. package/deps/jq/modules/oniguruma/onig-config.in +1 -1
  83. package/deps/jq/modules/oniguruma/oniguruma.pc.cmake.in +1 -1
  84. package/deps/jq/modules/oniguruma/oniguruma.pc.in +0 -1
  85. package/deps/jq/modules/oniguruma/sample/CMakeLists.txt +9 -2
  86. package/deps/jq/modules/oniguruma/sample/Makefile.am +24 -5
  87. package/deps/jq/modules/oniguruma/sample/bug_fix.c +13 -51
  88. package/deps/jq/modules/oniguruma/sample/callback_each_match.c +168 -0
  89. package/deps/jq/modules/oniguruma/sample/callout.c +268 -0
  90. package/deps/jq/modules/oniguruma/sample/count.c +125 -0
  91. package/deps/jq/modules/oniguruma/sample/crnl.c +6 -4
  92. package/deps/jq/modules/oniguruma/sample/echo.c +136 -0
  93. package/deps/jq/modules/oniguruma/sample/encode.c +53 -146
  94. package/deps/jq/modules/oniguruma/sample/listcap.c +18 -10
  95. package/deps/jq/modules/oniguruma/sample/names.c +10 -6
  96. package/deps/jq/modules/oniguruma/sample/posix.c +13 -2
  97. package/deps/jq/modules/oniguruma/sample/regset.c +95 -0
  98. package/deps/jq/modules/oniguruma/sample/scan.c +20 -6
  99. package/deps/jq/modules/oniguruma/sample/simple.c +8 -4
  100. package/deps/jq/modules/oniguruma/sample/sql.c +13 -8
  101. package/deps/jq/modules/oniguruma/sample/syntax.c +11 -10
  102. package/deps/jq/modules/oniguruma/sample/user_property.c +12 -7
  103. package/deps/jq/modules/oniguruma/src/Makefile.am +41 -15
  104. package/deps/jq/modules/oniguruma/src/Makefile.windows +196 -183
  105. package/deps/jq/modules/oniguruma/src/ascii.c +64 -7
  106. package/deps/jq/modules/oniguruma/src/big5.c +25 -15
  107. package/deps/jq/modules/oniguruma/src/config.h.cmake.in +7 -22
  108. package/deps/jq/modules/oniguruma/src/config.h.win32 +56 -84
  109. package/deps/jq/modules/oniguruma/src/config.h.win64 +56 -84
  110. package/deps/jq/modules/oniguruma/src/config.h.windows.in +62 -0
  111. package/deps/jq/modules/oniguruma/src/cp1251.c +14 -8
  112. package/deps/jq/modules/oniguruma/src/euc_jp.c +28 -30
  113. package/deps/jq/modules/oniguruma/src/euc_jp_prop.c +25 -32
  114. package/deps/jq/modules/oniguruma/src/euc_jp_prop.gperf +1 -2
  115. package/deps/jq/modules/oniguruma/src/euc_kr.c +27 -15
  116. package/deps/jq/modules/oniguruma/src/euc_tw.c +40 -17
  117. package/deps/jq/modules/oniguruma/src/gb18030.c +177 -119
  118. package/deps/jq/modules/oniguruma/src/gperf_fold_key_conv.py +12 -8
  119. package/deps/jq/modules/oniguruma/src/gperf_unfold_key_conv.py +8 -6
  120. package/deps/jq/modules/oniguruma/src/iso8859_1.c +92 -91
  121. package/deps/jq/modules/oniguruma/src/iso8859_10.c +13 -29
  122. package/deps/jq/modules/oniguruma/src/iso8859_11.c +4 -2
  123. package/deps/jq/modules/oniguruma/src/iso8859_13.c +13 -33
  124. package/deps/jq/modules/oniguruma/src/iso8859_14.c +13 -30
  125. package/deps/jq/modules/oniguruma/src/iso8859_15.c +13 -34
  126. package/deps/jq/modules/oniguruma/src/iso8859_16.c +13 -29
  127. package/deps/jq/modules/oniguruma/src/iso8859_2.c +13 -29
  128. package/deps/jq/modules/oniguruma/src/iso8859_3.c +13 -33
  129. package/deps/jq/modules/oniguruma/src/iso8859_4.c +13 -32
  130. package/deps/jq/modules/oniguruma/src/iso8859_5.c +16 -23
  131. package/deps/jq/modules/oniguruma/src/iso8859_6.c +4 -2
  132. package/deps/jq/modules/oniguruma/src/iso8859_7.c +14 -29
  133. package/deps/jq/modules/oniguruma/src/iso8859_8.c +4 -2
  134. package/deps/jq/modules/oniguruma/src/iso8859_9.c +13 -33
  135. package/deps/jq/modules/oniguruma/src/koi8.c +14 -27
  136. package/deps/jq/modules/oniguruma/src/koi8_r.c +12 -19
  137. package/deps/jq/modules/oniguruma/src/make_property.sh +21 -0
  138. package/deps/jq/modules/oniguruma/src/make_unicode_egcb.sh +7 -0
  139. package/deps/jq/modules/oniguruma/src/make_unicode_egcb_data.py +267 -0
  140. package/deps/jq/modules/oniguruma/src/make_unicode_fold.sh +25 -11
  141. package/deps/jq/modules/oniguruma/src/make_unicode_fold_data.py +206 -26
  142. package/deps/jq/modules/oniguruma/src/make_unicode_property.sh +19 -10
  143. package/deps/jq/modules/oniguruma/src/make_unicode_property_data.py +474 -375
  144. package/deps/jq/modules/oniguruma/src/make_unicode_wb.sh +7 -0
  145. package/deps/jq/modules/oniguruma/src/make_unicode_wb_data.py +267 -0
  146. package/deps/jq/modules/oniguruma/src/mktable.c +28 -24
  147. package/deps/jq/modules/oniguruma/src/onig_init.c +2 -2
  148. package/deps/jq/modules/oniguruma/src/oniggnu.h +7 -5
  149. package/deps/jq/modules/oniguruma/src/onigposix.h +40 -16
  150. package/deps/jq/modules/oniguruma/src/oniguruma.h +357 -107
  151. package/deps/jq/modules/oniguruma/src/regcomp.c +6214 -3933
  152. package/deps/jq/modules/oniguruma/src/regenc.c +197 -120
  153. package/deps/jq/modules/oniguruma/src/regenc.h +106 -63
  154. package/deps/jq/modules/oniguruma/src/regerror.c +112 -91
  155. package/deps/jq/modules/oniguruma/src/regexec.c +4876 -2010
  156. package/deps/jq/modules/oniguruma/src/regext.c +8 -8
  157. package/deps/jq/modules/oniguruma/src/reggnu.c +13 -17
  158. package/deps/jq/modules/oniguruma/src/regint.h +757 -491
  159. package/deps/jq/modules/oniguruma/src/regparse.c +7204 -3240
  160. package/deps/jq/modules/oniguruma/src/regparse.h +361 -218
  161. package/deps/jq/modules/oniguruma/src/regposerr.c +49 -9
  162. package/deps/jq/modules/oniguruma/src/regposix.c +106 -24
  163. package/deps/jq/modules/oniguruma/src/regsyntax.c +66 -13
  164. package/deps/jq/modules/oniguruma/src/regtrav.c +1 -1
  165. package/deps/jq/modules/oniguruma/src/regversion.c +6 -4
  166. package/deps/jq/modules/oniguruma/src/sjis.c +23 -52
  167. package/deps/jq/modules/oniguruma/src/sjis_prop.c +25 -32
  168. package/deps/jq/modules/oniguruma/src/sjis_prop.gperf +1 -2
  169. package/deps/jq/modules/oniguruma/src/st.c +248 -249
  170. package/deps/jq/modules/oniguruma/src/st.h +4 -5
  171. package/deps/jq/modules/oniguruma/src/unicode.c +869 -294
  172. package/deps/jq/modules/oniguruma/src/unicode_egcb_data.c +1419 -0
  173. package/deps/jq/modules/oniguruma/src/unicode_fold1_key.c +1829 -1300
  174. package/deps/jq/modules/oniguruma/src/unicode_fold2_key.c +32 -9
  175. package/deps/jq/modules/oniguruma/src/unicode_fold3_key.c +32 -9
  176. package/deps/jq/modules/oniguruma/src/unicode_fold_data.c +1210 -984
  177. package/deps/jq/modules/oniguruma/src/unicode_property_data.c +22480 -15198
  178. package/deps/jq/modules/oniguruma/src/unicode_property_data_posix.c +1463 -591
  179. package/deps/jq/modules/oniguruma/src/unicode_unfold_key.c +1958 -1418
  180. package/deps/jq/modules/oniguruma/src/unicode_wb_data.c +1106 -0
  181. package/deps/jq/modules/oniguruma/src/utf16_be.c +90 -49
  182. package/deps/jq/modules/oniguruma/src/utf16_le.c +80 -49
  183. package/deps/jq/modules/oniguruma/src/utf32_be.c +14 -42
  184. package/deps/jq/modules/oniguruma/src/utf32_le.c +13 -40
  185. package/deps/jq/modules/oniguruma/src/utf8.c +33 -78
  186. package/deps/jq/modules/oniguruma/test/CMakeLists.txt +55 -0
  187. package/deps/jq/modules/oniguruma/test/Makefile.am +65 -10
  188. package/deps/jq/modules/oniguruma/test/test.sh +17 -0
  189. package/deps/jq/modules/oniguruma/test/test_back.c +1450 -0
  190. package/deps/jq/modules/oniguruma/test/test_options.c +228 -0
  191. package/deps/jq/modules/oniguruma/test/test_regset.c +466 -0
  192. package/deps/jq/modules/oniguruma/test/test_syntax.c +365 -0
  193. package/deps/jq/modules/oniguruma/test/test_utf8.c +1761 -0
  194. package/deps/jq/modules/oniguruma/test/testc.c +128 -88
  195. package/deps/jq/modules/oniguruma/test/testp.c +613 -0
  196. package/deps/jq/modules/oniguruma/test/testu.c +75 -28
  197. package/deps/jq/modules/oniguruma/tis-ci/stub.c +3 -0
  198. package/deps/jq/modules/oniguruma/tis-ci/test_back.config +26 -0
  199. package/deps/jq/modules/oniguruma/tis-ci/test_regset.config +20 -0
  200. package/deps/jq/modules/oniguruma/tis-ci/test_syntax.config +26 -0
  201. package/deps/jq/modules/oniguruma/tis-ci/test_utf8.config +25 -0
  202. package/deps/jq/modules/oniguruma/tis-ci/testc.config +26 -0
  203. package/deps/jq/modules/oniguruma/tis-ci/testu.config +24 -0
  204. package/deps/jq/modules/oniguruma/tis.config +1336 -0
  205. package/deps/jq/modules/oniguruma/windows/CMakeLists.txt +8 -0
  206. package/deps/jq/modules/oniguruma/windows/testc.c +865 -869
  207. package/deps/jq/scripts/update-website +6 -5
  208. package/deps/jq/scripts/version +10 -7
  209. package/deps/jq/sig/jq-release-new.key +29 -0
  210. package/deps/jq/sig/v1.4/sha256sum.txt +1 -0
  211. package/deps/jq/sig/v1.5/sha256sum.txt +2 -0
  212. package/deps/jq/sig/v1.5rc1/sha256sum.txt +1 -0
  213. package/deps/jq/sig/v1.5rc2/sha256sum.txt +2 -0
  214. package/deps/jq/sig/v1.6/sha256sum.txt +2 -0
  215. package/deps/jq/sig/v1.7/jq-1.7.tar.gz.asc +16 -0
  216. package/deps/jq/sig/v1.7/jq-1.7.zip.asc +16 -0
  217. package/deps/jq/sig/v1.7/jq-linux-amd64.asc +16 -0
  218. package/deps/jq/sig/v1.7/jq-linux-arm64.asc +16 -0
  219. package/deps/jq/sig/v1.7/jq-linux-armel.asc +16 -0
  220. package/deps/jq/sig/v1.7/jq-linux-armhf.asc +16 -0
  221. package/deps/jq/sig/v1.7/jq-linux-i386.asc +16 -0
  222. package/deps/jq/sig/v1.7/jq-linux-mips.asc +16 -0
  223. package/deps/jq/sig/v1.7/jq-linux-mips64.asc +16 -0
  224. package/deps/jq/sig/v1.7/jq-linux-mips64el.asc +16 -0
  225. package/deps/jq/sig/v1.7/jq-linux-mips64r6.asc +16 -0
  226. package/deps/jq/sig/v1.7/jq-linux-mips64r6el.asc +16 -0
  227. package/deps/jq/sig/v1.7/jq-linux-mipsel.asc +16 -0
  228. package/deps/jq/sig/v1.7/jq-linux-mipsr6.asc +16 -0
  229. package/deps/jq/sig/v1.7/jq-linux-mipsr6el.asc +16 -0
  230. package/deps/jq/sig/v1.7/jq-linux-powerpc.asc +16 -0
  231. package/deps/jq/sig/v1.7/jq-linux-ppc64el.asc +16 -0
  232. package/deps/jq/sig/v1.7/jq-linux-riscv64.asc +16 -0
  233. package/deps/jq/sig/v1.7/jq-linux-s390x.asc +16 -0
  234. package/deps/jq/sig/v1.7/jq-macos-amd64.asc +16 -0
  235. package/deps/jq/sig/v1.7/jq-macos-arm64.asc +16 -0
  236. package/deps/jq/sig/v1.7/jq-windows-amd64.exe.asc +16 -0
  237. package/deps/jq/sig/v1.7/jq-windows-i386.exe.asc +16 -0
  238. package/deps/jq/sig/v1.7/sha256sum.txt +23 -0
  239. package/deps/jq/sig/v1.7.1/jq-1.7.1.tar.gz.asc +16 -0
  240. package/deps/jq/sig/v1.7.1/jq-1.7.1.zip.asc +16 -0
  241. package/deps/jq/sig/v1.7.1/jq-linux-amd64.asc +16 -0
  242. package/deps/jq/sig/v1.7.1/jq-linux-arm64.asc +16 -0
  243. package/deps/jq/sig/v1.7.1/jq-linux-armel.asc +16 -0
  244. package/deps/jq/sig/v1.7.1/jq-linux-armhf.asc +16 -0
  245. package/deps/jq/sig/v1.7.1/jq-linux-i386.asc +16 -0
  246. package/deps/jq/sig/v1.7.1/jq-linux-mips.asc +16 -0
  247. package/deps/jq/sig/v1.7.1/jq-linux-mips64.asc +16 -0
  248. package/deps/jq/sig/v1.7.1/jq-linux-mips64el.asc +16 -0
  249. package/deps/jq/sig/v1.7.1/jq-linux-mips64r6.asc +16 -0
  250. package/deps/jq/sig/v1.7.1/jq-linux-mips64r6el.asc +16 -0
  251. package/deps/jq/sig/v1.7.1/jq-linux-mipsel.asc +16 -0
  252. package/deps/jq/sig/v1.7.1/jq-linux-mipsr6.asc +16 -0
  253. package/deps/jq/sig/v1.7.1/jq-linux-mipsr6el.asc +16 -0
  254. package/deps/jq/sig/v1.7.1/jq-linux-powerpc.asc +16 -0
  255. package/deps/jq/sig/v1.7.1/jq-linux-ppc64el.asc +16 -0
  256. package/deps/jq/sig/v1.7.1/jq-linux-riscv64.asc +16 -0
  257. package/deps/jq/sig/v1.7.1/jq-linux-s390x.asc +16 -0
  258. package/deps/jq/sig/v1.7.1/jq-linux64.asc +16 -0
  259. package/deps/jq/sig/v1.7.1/jq-macos-amd64.asc +16 -0
  260. package/deps/jq/sig/v1.7.1/jq-macos-arm64.asc +16 -0
  261. package/deps/jq/sig/v1.7.1/jq-osx-amd64.asc +16 -0
  262. package/deps/jq/sig/v1.7.1/jq-win64.exe.asc +16 -0
  263. package/deps/jq/sig/v1.7.1/jq-windows-amd64.exe.asc +16 -0
  264. package/deps/jq/sig/v1.7.1/jq-windows-i386.exe.asc +16 -0
  265. package/deps/jq/sig/v1.7.1/sha256sum.txt +26 -0
  266. package/deps/jq/sig/v1.7rc1/jq-1.7rc1.tar.gz.asc +16 -0
  267. package/deps/jq/sig/v1.7rc1/jq-1.7rc1.zip.asc +16 -0
  268. package/deps/jq/sig/v1.7rc1/jq-linux-amd64.asc +16 -0
  269. package/deps/jq/sig/v1.7rc1/jq-linux-arm64.asc +16 -0
  270. package/deps/jq/sig/v1.7rc1/jq-linux-armel.asc +16 -0
  271. package/deps/jq/sig/v1.7rc1/jq-linux-armhf.asc +16 -0
  272. package/deps/jq/sig/v1.7rc1/jq-linux-i386.asc +16 -0
  273. package/deps/jq/sig/v1.7rc1/jq-linux-mips.asc +16 -0
  274. package/deps/jq/sig/v1.7rc1/jq-linux-mips64.asc +16 -0
  275. package/deps/jq/sig/v1.7rc1/jq-linux-mips64el.asc +16 -0
  276. package/deps/jq/sig/v1.7rc1/jq-linux-mips64r6.asc +16 -0
  277. package/deps/jq/sig/v1.7rc1/jq-linux-mips64r6el.asc +16 -0
  278. package/deps/jq/sig/v1.7rc1/jq-linux-mipsel.asc +16 -0
  279. package/deps/jq/sig/v1.7rc1/jq-linux-mipsr6.asc +16 -0
  280. package/deps/jq/sig/v1.7rc1/jq-linux-mipsr6el.asc +16 -0
  281. package/deps/jq/sig/v1.7rc1/jq-linux-powerpc.asc +16 -0
  282. package/deps/jq/sig/v1.7rc1/jq-linux-ppc64el.asc +16 -0
  283. package/deps/jq/sig/v1.7rc1/jq-linux-riscv64.asc +16 -0
  284. package/deps/jq/sig/v1.7rc1/jq-linux-s390x.asc +16 -0
  285. package/deps/jq/sig/v1.7rc1/jq-macos-amd64.asc +16 -0
  286. package/deps/jq/sig/v1.7rc1/jq-macos-arm64.asc +16 -0
  287. package/deps/jq/sig/v1.7rc1/jq-windows-amd64.exe.asc +16 -0
  288. package/deps/jq/sig/v1.7rc1/jq-windows-i386.exe.asc +16 -0
  289. package/deps/jq/sig/v1.7rc1/sha256sum.txt +23 -0
  290. package/deps/jq/sig/v1.7rc2/jq-1.7rc2.tar.gz.asc +16 -0
  291. package/deps/jq/sig/v1.7rc2/jq-1.7rc2.zip.asc +16 -0
  292. package/deps/jq/sig/v1.7rc2/jq-linux-amd64.asc +16 -0
  293. package/deps/jq/sig/v1.7rc2/jq-linux-arm64.asc +16 -0
  294. package/deps/jq/sig/v1.7rc2/jq-linux-armel.asc +16 -0
  295. package/deps/jq/sig/v1.7rc2/jq-linux-armhf.asc +16 -0
  296. package/deps/jq/sig/v1.7rc2/jq-linux-i386.asc +16 -0
  297. package/deps/jq/sig/v1.7rc2/jq-linux-mips.asc +16 -0
  298. package/deps/jq/sig/v1.7rc2/jq-linux-mips64.asc +16 -0
  299. package/deps/jq/sig/v1.7rc2/jq-linux-mips64el.asc +16 -0
  300. package/deps/jq/sig/v1.7rc2/jq-linux-mips64r6.asc +16 -0
  301. package/deps/jq/sig/v1.7rc2/jq-linux-mips64r6el.asc +16 -0
  302. package/deps/jq/sig/v1.7rc2/jq-linux-mipsel.asc +16 -0
  303. package/deps/jq/sig/v1.7rc2/jq-linux-mipsr6.asc +16 -0
  304. package/deps/jq/sig/v1.7rc2/jq-linux-mipsr6el.asc +16 -0
  305. package/deps/jq/sig/v1.7rc2/jq-linux-powerpc.asc +16 -0
  306. package/deps/jq/sig/v1.7rc2/jq-linux-ppc64el.asc +16 -0
  307. package/deps/jq/sig/v1.7rc2/jq-linux-riscv64.asc +16 -0
  308. package/deps/jq/sig/v1.7rc2/jq-linux-s390x.asc +16 -0
  309. package/deps/jq/sig/v1.7rc2/jq-macos-amd64.asc +16 -0
  310. package/deps/jq/sig/v1.7rc2/jq-macos-arm64.asc +16 -0
  311. package/deps/jq/sig/v1.7rc2/jq-windows-amd64.exe.asc +16 -0
  312. package/deps/jq/sig/v1.7rc2/jq-windows-i386.exe.asc +16 -0
  313. package/deps/jq/sig/v1.7rc2/sha256sum.txt +23 -0
  314. package/deps/jq/src/builtin.c +537 -343
  315. package/deps/jq/src/builtin.h +18 -0
  316. package/deps/jq/src/builtin.jq +116 -143
  317. package/deps/jq/src/bytecode.h +8 -4
  318. package/deps/jq/src/compile.c +157 -143
  319. package/deps/jq/src/compile.h +3 -4
  320. package/deps/jq/src/decNumber/ICU-license.html +45 -0
  321. package/deps/jq/src/decNumber/decBasic.c +3908 -0
  322. package/deps/jq/src/decNumber/decCommon.c +1835 -0
  323. package/deps/jq/src/decNumber/decContext.c +437 -0
  324. package/deps/jq/src/decNumber/decContext.h +254 -0
  325. package/deps/jq/src/decNumber/decDPD.h +1185 -0
  326. package/deps/jq/src/decNumber/decDouble.c +140 -0
  327. package/deps/jq/src/decNumber/decDouble.h +155 -0
  328. package/deps/jq/src/decNumber/decNumber.c +8143 -0
  329. package/deps/jq/src/decNumber/decNumber.h +182 -0
  330. package/deps/jq/src/decNumber/decNumberLocal.h +757 -0
  331. package/deps/jq/src/decNumber/decPacked.c +220 -0
  332. package/deps/jq/src/decNumber/decPacked.h +52 -0
  333. package/deps/jq/src/decNumber/decQuad.c +135 -0
  334. package/deps/jq/src/decNumber/decQuad.h +177 -0
  335. package/deps/jq/src/decNumber/decSingle.c +71 -0
  336. package/deps/jq/src/decNumber/decSingle.h +86 -0
  337. package/deps/jq/src/decNumber/decimal128.c +553 -0
  338. package/deps/jq/src/decNumber/decimal128.h +81 -0
  339. package/deps/jq/src/decNumber/decimal32.c +476 -0
  340. package/deps/jq/src/decNumber/decimal32.h +81 -0
  341. package/deps/jq/src/decNumber/decimal64.c +839 -0
  342. package/deps/jq/src/decNumber/decimal64.h +83 -0
  343. package/deps/jq/src/decNumber/decnumber.pdf +0 -0
  344. package/deps/jq/src/decNumber/example1.c +38 -0
  345. package/deps/jq/src/decNumber/example2.c +52 -0
  346. package/deps/jq/src/decNumber/example3.c +64 -0
  347. package/deps/jq/src/decNumber/example4.c +61 -0
  348. package/deps/jq/src/decNumber/example5.c +36 -0
  349. package/deps/jq/src/decNumber/example6.c +61 -0
  350. package/deps/jq/src/decNumber/example7.c +35 -0
  351. package/deps/jq/src/decNumber/example8.c +39 -0
  352. package/deps/jq/src/decNumber/readme.txt +81 -0
  353. package/deps/jq/src/exec_stack.h +5 -3
  354. package/deps/jq/src/execute.c +126 -44
  355. package/deps/jq/src/inject_errors.c +0 -2
  356. package/deps/jq/src/jq.h +10 -1
  357. package/deps/jq/src/jq_test.c +222 -11
  358. package/deps/jq/src/jv.c +807 -176
  359. package/deps/jq/src/jv.h +22 -1
  360. package/deps/jq/src/jv_alloc.c +33 -26
  361. package/deps/jq/src/jv_alloc.h +0 -11
  362. package/deps/jq/src/jv_aux.c +153 -67
  363. package/deps/jq/src/jv_dtoa.c +12 -2
  364. package/deps/jq/src/jv_dtoa_tsd.c +51 -0
  365. package/deps/jq/src/jv_dtoa_tsd.h +4 -0
  366. package/deps/jq/src/jv_parse.c +70 -15
  367. package/deps/jq/src/jv_print.c +56 -60
  368. package/deps/jq/src/jv_private.h +7 -0
  369. package/deps/jq/src/jv_thread.h +76 -0
  370. package/deps/jq/src/jv_unicode.c +18 -0
  371. package/deps/jq/src/jv_unicode.h +2 -0
  372. package/deps/jq/src/lexer.c +782 -543
  373. package/deps/jq/src/lexer.h +438 -64
  374. package/deps/jq/src/lexer.l +10 -3
  375. package/deps/jq/src/libm.h +16 -6
  376. package/deps/jq/src/linker.c +97 -40
  377. package/deps/jq/src/locfile.c +2 -1
  378. package/deps/jq/src/main.c +384 -336
  379. package/deps/jq/src/opcode_list.h +5 -2
  380. package/deps/jq/src/parser.c +2260 -1898
  381. package/deps/jq/src/parser.h +115 -98
  382. package/deps/jq/src/parser.y +124 -89
  383. package/deps/jq/src/util.c +854 -55
  384. package/deps/jq/src/util.h +6 -4
  385. package/deps/jq/tests/jq.test +762 -26
  386. package/deps/jq/tests/jq_fuzz_compile.c +27 -0
  387. package/deps/jq/tests/jq_fuzz_execute.cpp +42 -0
  388. package/deps/jq/tests/jq_fuzz_fixed.cpp +297 -0
  389. package/deps/jq/tests/jq_fuzz_load_file.c +28 -0
  390. package/deps/jq/tests/jq_fuzz_parse.c +21 -0
  391. package/deps/jq/tests/jq_fuzz_parse_extended.c +36 -0
  392. package/deps/jq/tests/jq_fuzz_parse_stream.c +21 -0
  393. package/deps/jq/tests/local.supp +14 -0
  394. package/deps/jq/tests/man.test +979 -0
  395. package/deps/jq/tests/manonig.test +76 -0
  396. package/deps/jq/tests/manonigtest +5 -0
  397. package/deps/jq/tests/mantest +1 -2
  398. package/deps/jq/tests/modules/home2/.jq/g.jq +1 -0
  399. package/deps/jq/tests/modules/shadow1.jq +2 -0
  400. package/deps/jq/tests/modules/shadow2.jq +1 -0
  401. package/deps/jq/tests/modules/test_bind_order0.jq +1 -0
  402. package/deps/jq/tests/modules/test_bind_order1.jq +1 -1
  403. package/deps/jq/tests/modules/test_bind_order2.jq +0 -1
  404. package/deps/jq/tests/no-main-program.jq +1 -0
  405. package/deps/jq/tests/onig.test +77 -2
  406. package/deps/jq/tests/setup +7 -2
  407. package/deps/jq/tests/shtest +478 -59
  408. package/deps/jq/tests/uri.test +38 -0
  409. package/deps/jq/tests/uritest +5 -0
  410. package/deps/jq/tests/yes-main-program.jq +2 -0
  411. package/lib/index.js +3 -0
  412. package/lib/jq.js +15 -1
  413. package/lib/templateAsync.js +137 -0
  414. package/package.json +7 -7
  415. package/src/binding.cc +623 -146
  416. package/src/binding.h +3 -4
  417. package/test/santiy-async.test.js +171 -0
  418. package/test/santiy.test.js +2 -2
  419. package/test/template-async.test.js +182 -0
  420. package/test/template.test.js +3 -3
  421. package/deps/jq/.travis.yml +0 -202
  422. package/deps/jq/NEWS +0 -89
  423. package/deps/jq/appveyor.yml +0 -53
  424. package/deps/jq/docs/Gemfile +0 -7
  425. package/deps/jq/docs/Gemfile.lock +0 -63
  426. package/deps/jq/docs/Rakefile +0 -24
  427. package/deps/jq/docs/Rakefile.manual +0 -49
  428. package/deps/jq/docs/Rakefile.website +0 -76
  429. package/deps/jq/docs/content/1.tutorial/default.yml +0 -327
  430. package/deps/jq/docs/content/2.download/default.yml +0 -193
  431. package/deps/jq/docs/content/index/index.yml +0 -73
  432. package/deps/jq/docs/public/css/base.scss +0 -181
  433. package/deps/jq/docs/public/jq.png +0 -0
  434. package/deps/jq/docs/site.yml +0 -9
  435. package/deps/jq/docs/templates/default.liquid +0 -34
  436. package/deps/jq/docs/templates/index.liquid +0 -73
  437. package/deps/jq/docs/templates/manual.liquid +0 -99
  438. package/deps/jq/docs/templates/shared/_footer.liquid +0 -10
  439. package/deps/jq/docs/templates/shared/_head.liquid +0 -17
  440. package/deps/jq/docs/templates/shared/_navbar.liquid +0 -27
  441. package/deps/jq/modules/oniguruma/README.ja +0 -195
  442. package/deps/jq/modules/oniguruma/cmake/dist.cmake +0 -321
  443. package/deps/jq/modules/oniguruma/contributed/libfuzzer-onig.cpp +0 -31
  444. package/deps/jq/modules/oniguruma/dist.info +0 -10
  445. package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_fold1_key.c +0 -2250
  446. package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_fold2_key.c +0 -203
  447. package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_fold3_key.c +0 -113
  448. package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_fold_data.c +0 -1225
  449. package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_property_data.c +0 -24742
  450. package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_property_data_posix.c +0 -4846
  451. package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_unfold_key.c +0 -2571
  452. /package/deps/jq/sig/{jq-release.key → jq-release-old.key} +0 -0
  453. /package/deps/jq/tests/modules/{.jq → home1/.jq} +0 -0
@@ -1,5 +1,3 @@
1
- #define _BSD_SOURCE
2
- #define _GNU_SOURCE
3
1
  #ifndef __sun__
4
2
  # define _XOPEN_SOURCE
5
3
  # define _XOPEN_SOURCE_EXTENDED 1
@@ -34,6 +32,9 @@ void *alloca (size_t);
34
32
  #endif
35
33
  #include <string.h>
36
34
  #include <time.h>
35
+ #ifdef WIN32
36
+ #include <windows.h>
37
+ #endif
37
38
  #include "builtin.h"
38
39
  #include "compile.h"
39
40
  #include "jq_parser.h"
@@ -42,28 +43,40 @@ void *alloca (size_t);
42
43
  #include "locfile.h"
43
44
  #include "jv_unicode.h"
44
45
  #include "jv_alloc.h"
46
+ #include "jv_dtoa.h"
47
+ #include "jv_dtoa_tsd.h"
48
+ #include "jv_private.h"
49
+ #include "util.h"
50
+
51
+
52
+ #define BINOP(name) \
53
+ static jv f_ ## name(jq_state *jq, jv input, jv a, jv b) { \
54
+ jv_free(input); \
55
+ return binop_ ## name(a, b); \
56
+ }
57
+ BINOPS
58
+ #undef BINOP
45
59
 
46
60
 
47
61
  static jv type_error(jv bad, const char* msg) {
48
62
  char errbuf[15];
49
- jv err = jv_invalid_with_msg(jv_string_fmt("%s (%s) %s",
50
- jv_kind_name(jv_get_kind(bad)),
51
- jv_dump_string_trunc(jv_copy(bad), errbuf, sizeof(errbuf)),
63
+ const char *badkind = jv_kind_name(jv_get_kind(bad));
64
+ jv err = jv_invalid_with_msg(jv_string_fmt("%s (%s) %s", badkind,
65
+ jv_dump_string_trunc(bad, errbuf, sizeof(errbuf)),
52
66
  msg));
53
- jv_free(bad);
54
67
  return err;
55
68
  }
56
69
 
57
70
  static jv type_error2(jv bad1, jv bad2, const char* msg) {
58
71
  char errbuf1[15],errbuf2[15];
72
+ const char *badkind1 = jv_kind_name(jv_get_kind(bad1));
73
+ const char *badkind2 = jv_kind_name(jv_get_kind(bad2));
59
74
  jv err = jv_invalid_with_msg(jv_string_fmt("%s (%s) and %s (%s) %s",
60
- jv_kind_name(jv_get_kind(bad1)),
61
- jv_dump_string_trunc(jv_copy(bad1), errbuf1, sizeof(errbuf1)),
62
- jv_kind_name(jv_get_kind(bad2)),
63
- jv_dump_string_trunc(jv_copy(bad2), errbuf2, sizeof(errbuf2)),
75
+ badkind1,
76
+ jv_dump_string_trunc(bad1, errbuf1, sizeof(errbuf1)),
77
+ badkind2,
78
+ jv_dump_string_trunc(bad2, errbuf2, sizeof(errbuf2)),
64
79
  msg));
65
- jv_free(bad1);
66
- jv_free(bad2);
67
80
  return err;
68
81
  }
69
82
 
@@ -78,8 +91,7 @@ static inline jv ret_error2(jv bad1, jv bad2, jv msg) {
78
91
  return jv_invalid_with_msg(msg);
79
92
  }
80
93
 
81
- static jv f_plus(jq_state *jq, jv input, jv a, jv b) {
82
- jv_free(input);
94
+ jv binop_plus(jv a, jv b) {
83
95
  if (jv_get_kind(a) == JV_KIND_NULL) {
84
96
  jv_free(a);
85
97
  return b;
@@ -87,8 +99,11 @@ static jv f_plus(jq_state *jq, jv input, jv a, jv b) {
87
99
  jv_free(b);
88
100
  return a;
89
101
  } else if (jv_get_kind(a) == JV_KIND_NUMBER && jv_get_kind(b) == JV_KIND_NUMBER) {
90
- return jv_number(jv_number_value(a) +
102
+ jv r = jv_number(jv_number_value(a) +
91
103
  jv_number_value(b));
104
+ jv_free(a);
105
+ jv_free(b);
106
+ return r;
92
107
  } else if (jv_get_kind(a) == JV_KIND_STRING && jv_get_kind(b) == JV_KIND_STRING) {
93
108
  return jv_string_concat(a, b);
94
109
  } else if (jv_get_kind(a) == JV_KIND_ARRAY && jv_get_kind(b) == JV_KIND_ARRAY) {
@@ -100,6 +115,39 @@ static jv f_plus(jq_state *jq, jv input, jv a, jv b) {
100
115
  }
101
116
  }
102
117
 
118
+ #ifdef __APPLE__
119
+ // macOS has a bunch of libm deprecation warnings, so let's clean those up
120
+ #ifdef HAVE_TGAMMA
121
+ #define HAVE_GAMMA
122
+ #define gamma tgamma
123
+ #endif
124
+ #ifdef HAVE___EXP10
125
+ #define HAVE_EXP10
126
+ #define exp10 __exp10
127
+ #endif
128
+ #ifdef HAVE_REMAINDER
129
+ #define HAVE_DREM
130
+ #define drem remainder
131
+ #endif
132
+
133
+ // We replace significand with our own, since there's not a rename-replacement
134
+ #ifdef HAVE_FREXP
135
+ static double __jq_significand(double x) {
136
+ int z;
137
+ return 2*frexp(x, &z);
138
+ }
139
+ #define HAVE_SIGNIFICAND
140
+ #define significand __jq_significand
141
+ #elif defined(HAVE_SCALBN) && defined(HAVE_ILOGB)
142
+ static double __jq_significand(double x) {
143
+ return scalbn(x, -ilogb(x));
144
+ }
145
+ #define HAVE_SIGNIFICAND
146
+ #define significand __jq_significand
147
+ #endif
148
+
149
+ #endif // ifdef __APPLE__
150
+
103
151
  #define LIBM_DD(name) \
104
152
  static jv f_ ## name(jq_state *jq, jv input) { \
105
153
  if (jv_get_kind(input) != JV_KIND_NUMBER) { \
@@ -109,7 +157,11 @@ static jv f_ ## name(jq_state *jq, jv input) { \
109
157
  jv_free(input); \
110
158
  return ret; \
111
159
  }
112
- #define LIBM_DD_NO(name)
160
+ #define LIBM_DD_NO(name) \
161
+ static jv f_ ## name(jq_state *jq, jv input) { \
162
+ jv error = jv_string("Error: " #name "/0 not found at build time"); \
163
+ return ret_error(input, error); \
164
+ }
113
165
 
114
166
  #define LIBM_DDD(name) \
115
167
  static jv f_ ## name(jq_state *jq, jv input, jv a, jv b) { \
@@ -127,7 +179,12 @@ static jv f_ ## name(jq_state *jq, jv input, jv a, jv b) { \
127
179
  jv_free(b); \
128
180
  return ret; \
129
181
  }
130
- #define LIBM_DDD_NO(name)
182
+ #define LIBM_DDD_NO(name) \
183
+ static jv f_ ## name(jq_state *jq, jv input, jv a, jv b) { \
184
+ jv_free(b); \
185
+ jv error = jv_string("Error: " #name "/2 not found at build time"); \
186
+ return ret_error2(input, a, error); \
187
+ }
131
188
 
132
189
  #define LIBM_DDDD(name) \
133
190
  static jv f_ ## name(jq_state *jq, jv input, jv a, jv b, jv c) { \
@@ -153,48 +210,46 @@ static jv f_ ## name(jq_state *jq, jv input, jv a, jv b, jv c) { \
153
210
  jv_free(c); \
154
211
  return ret; \
155
212
  }
156
- #define LIBM_DDDD_NO(name)
213
+ #define LIBM_DDDD_NO(name) \
214
+ static jv f_ ## name(jq_state *jq, jv input, jv a, jv b, jv c) { \
215
+ jv_free(c); \
216
+ jv_free(b); \
217
+ jv error = jv_string("Error: " #name "/3 not found at build time"); \
218
+ return ret_error2(input, a, error); \
219
+ }
220
+
221
+ #define LIBM_DA(name, type) \
222
+ static jv f_ ## name(jq_state *jq, jv input) { \
223
+ if (jv_get_kind(input) != JV_KIND_NUMBER) { \
224
+ return type_error(input, "number required"); \
225
+ } \
226
+ type value; \
227
+ double d = name(jv_number_value(input), &value); \
228
+ jv ret = JV_ARRAY(jv_number(d), jv_number(value)); \
229
+ jv_free(input); \
230
+ return ret; \
231
+ }
232
+ #define LIBM_DA_NO(name, type) \
233
+ static jv f_ ## name(jq_state *jq, jv input) { \
234
+ jv error = jv_string("Error: " #name "/0 not found at build time"); \
235
+ return ret_error(input, error); \
236
+ }
237
+
157
238
  #include "libm.h"
158
239
  #undef LIBM_DDDD_NO
159
240
  #undef LIBM_DDD_NO
160
241
  #undef LIBM_DD_NO
242
+ #undef LIBM_DA_NO
161
243
  #undef LIBM_DDDD
162
244
  #undef LIBM_DDD
163
245
  #undef LIBM_DD
246
+ #undef LIBM_DA
164
247
 
165
- #ifdef HAVE_FREXP
166
- static jv f_frexp(jq_state *jq, jv input) {
167
- if (jv_get_kind(input) != JV_KIND_NUMBER) {
168
- return type_error(input, "number required");
169
- }
170
- int exp;
171
- double d = frexp(jv_number_value(input), &exp);
172
- jv ret = JV_ARRAY(jv_number(d), jv_number(exp));
173
- jv_free(input);
174
- return ret;
175
- }
176
- #endif
177
- #ifdef HAVE_MODF
178
- static jv f_modf(jq_state *jq, jv input) {
179
- if (jv_get_kind(input) != JV_KIND_NUMBER) {
180
- return type_error(input, "number required");
181
- }
182
- double i;
183
- jv ret = JV_ARRAY(jv_number(modf(jv_number_value(input), &i)));
184
- jv_free(input);
185
- return jv_array_append(ret, jv_number(i));
186
- }
187
- #endif
188
- #ifdef HAVE_LGAMMA_R
189
- static jv f_lgamma_r(jq_state *jq, jv input) {
190
- if (jv_get_kind(input) != JV_KIND_NUMBER) {
191
- return type_error(input, "number required");
192
- }
193
- int sign;
194
- jv ret = JV_ARRAY(jv_number(lgamma_r(jv_number_value(input), &sign)));
195
- jv_free(input);
196
- return jv_array_append(ret, jv_number(sign));
197
- }
248
+ #ifdef __APPLE__
249
+ #undef gamma
250
+ #undef drem
251
+ #undef significand
252
+ #undef exp10
198
253
  #endif
199
254
 
200
255
  static jv f_negate(jq_state *jq, jv input) {
@@ -229,7 +284,7 @@ static jv f_endswith(jq_state *jq, jv a, jv b) {
229
284
  const char *bstr = jv_string_value(b);
230
285
  size_t alen = jv_string_length_bytes(jv_copy(a));
231
286
  size_t blen = jv_string_length_bytes(jv_copy(b));
232
- jv ret;;
287
+ jv ret;
233
288
 
234
289
  if (alen < blen ||
235
290
  memcmp(astr + (alen - blen), bstr, blen) != 0)
@@ -241,37 +296,12 @@ static jv f_endswith(jq_state *jq, jv a, jv b) {
241
296
  return ret;
242
297
  }
243
298
 
244
- static jv f_ltrimstr(jq_state *jq, jv input, jv left) {
245
- if (jv_get_kind(f_startswith(jq, jv_copy(input), jv_copy(left))) != JV_KIND_TRUE) {
246
- jv_free(left);
247
- return input;
248
- }
249
- /*
250
- * FIXME It'd be better to share the suffix with the original input --
251
- * that we could do, we just can't share prefixes.
252
- */
253
- int prefixlen = jv_string_length_bytes(left);
254
- jv res = jv_string_sized(jv_string_value(input) + prefixlen,
255
- jv_string_length_bytes(jv_copy(input)) - prefixlen);
256
- jv_free(input);
257
- return res;
258
- }
259
-
260
- static jv f_rtrimstr(jq_state *jq, jv input, jv right) {
261
- if (jv_get_kind(f_endswith(jq, jv_copy(input), jv_copy(right))) == JV_KIND_TRUE) {
262
- jv res = jv_string_sized(jv_string_value(input),
263
- jv_string_length_bytes(jv_copy(input)) - jv_string_length_bytes(right));
264
- jv_free(input);
265
- return res;
266
- }
267
- jv_free(right);
268
- return input;
269
- }
270
-
271
- static jv f_minus(jq_state *jq, jv input, jv a, jv b) {
272
- jv_free(input);
299
+ jv binop_minus(jv a, jv b) {
273
300
  if (jv_get_kind(a) == JV_KIND_NUMBER && jv_get_kind(b) == JV_KIND_NUMBER) {
274
- return jv_number(jv_number_value(a) - jv_number_value(b));
301
+ jv r = jv_number(jv_number_value(a) - jv_number_value(b));
302
+ jv_free(a);
303
+ jv_free(b);
304
+ return r;
275
305
  } else if (jv_get_kind(a) == JV_KIND_ARRAY && jv_get_kind(b) == JV_KIND_ARRAY) {
276
306
  jv out = jv_array();
277
307
  jv_array_foreach(a, i, x) {
@@ -294,12 +324,14 @@ static jv f_minus(jq_state *jq, jv input, jv a, jv b) {
294
324
  }
295
325
  }
296
326
 
297
- static jv f_multiply(jq_state *jq, jv input, jv a, jv b) {
327
+ jv binop_multiply(jv a, jv b) {
298
328
  jv_kind ak = jv_get_kind(a);
299
329
  jv_kind bk = jv_get_kind(b);
300
- jv_free(input);
301
330
  if (ak == JV_KIND_NUMBER && bk == JV_KIND_NUMBER) {
302
- return jv_number(jv_number_value(a) * jv_number_value(b));
331
+ jv r = jv_number(jv_number_value(a) * jv_number_value(b));
332
+ jv_free(a);
333
+ jv_free(b);
334
+ return r;
303
335
  } else if ((ak == JV_KIND_STRING && bk == JV_KIND_NUMBER) ||
304
336
  (ak == JV_KIND_NUMBER && bk == JV_KIND_STRING)) {
305
337
  jv str = a;
@@ -308,18 +340,20 @@ static jv f_multiply(jq_state *jq, jv input, jv a, jv b) {
308
340
  str = b;
309
341
  num = a;
310
342
  }
311
- int n;
312
- size_t alen = jv_string_length_bytes(jv_copy(str));
313
- jv res = str;
314
-
315
- for (n = jv_number_value(num) - 1; n > 0; n--)
316
- res = jv_string_append_buf(res, jv_string_value(str), alen);
317
-
318
- jv_free(num);
319
- if (n < 0) {
320
- jv_free(str);
321
- return jv_null();
343
+ jv res;
344
+ double d = jv_number_value(num);
345
+ if (d < 0 || isnan(d)) {
346
+ res = jv_null();
347
+ } else {
348
+ int n = d;
349
+ size_t alen = jv_string_length_bytes(jv_copy(str));
350
+ res = jv_string_empty(alen * n);
351
+ for (; n > 0; n--) {
352
+ res = jv_string_append_buf(res, jv_string_value(str), alen);
353
+ }
322
354
  }
355
+ jv_free(str);
356
+ jv_free(num);
323
357
  return res;
324
358
  } else if (ak == JV_KIND_OBJECT && bk == JV_KIND_OBJECT) {
325
359
  return jv_object_merge_recursive(a, b);
@@ -328,12 +362,14 @@ static jv f_multiply(jq_state *jq, jv input, jv a, jv b) {
328
362
  }
329
363
  }
330
364
 
331
- static jv f_divide(jq_state *jq, jv input, jv a, jv b) {
332
- jv_free(input);
365
+ jv binop_divide(jv a, jv b) {
333
366
  if (jv_get_kind(a) == JV_KIND_NUMBER && jv_get_kind(b) == JV_KIND_NUMBER) {
334
367
  if (jv_number_value(b) == 0.0)
335
368
  return type_error2(a, b, "cannot be divided because the divisor is zero");
336
- return jv_number(jv_number_value(a) / jv_number_value(b));
369
+ jv r = jv_number(jv_number_value(a) / jv_number_value(b));
370
+ jv_free(a);
371
+ jv_free(b);
372
+ return r;
337
373
  } else if (jv_get_kind(a) == JV_KIND_STRING && jv_get_kind(b) == JV_KIND_STRING) {
338
374
  return jv_string_split(a, b);
339
375
  } else {
@@ -341,24 +377,35 @@ static jv f_divide(jq_state *jq, jv input, jv a, jv b) {
341
377
  }
342
378
  }
343
379
 
344
- static jv f_mod(jq_state *jq, jv input, jv a, jv b) {
345
- jv_free(input);
380
+ #define dtoi(n) ((n) < INTMAX_MIN ? INTMAX_MIN : -(n) < INTMAX_MIN ? INTMAX_MAX : (intmax_t)(n))
381
+ jv binop_mod(jv a, jv b) {
346
382
  if (jv_get_kind(a) == JV_KIND_NUMBER && jv_get_kind(b) == JV_KIND_NUMBER) {
347
- if ((intmax_t)jv_number_value(b) == 0)
383
+ double na = jv_number_value(a);
384
+ double nb = jv_number_value(b);
385
+ if (isnan(na) || isnan(nb)) {
386
+ jv_free(a);
387
+ jv_free(b);
388
+ return jv_number(NAN);
389
+ }
390
+ intmax_t bi = dtoi(nb);
391
+ if (bi == 0)
348
392
  return type_error2(a, b, "cannot be divided (remainder) because the divisor is zero");
349
- return jv_number((intmax_t)jv_number_value(a) % (intmax_t)jv_number_value(b));
393
+ // Check if the divisor is -1 to avoid overflow when the dividend is INTMAX_MIN.
394
+ jv r = jv_number(bi == -1 ? 0 : dtoi(na) % bi);
395
+ jv_free(a);
396
+ jv_free(b);
397
+ return r;
350
398
  } else {
351
399
  return type_error2(a, b, "cannot be divided (remainder)");
352
400
  }
353
401
  }
402
+ #undef dtoi
354
403
 
355
- static jv f_equal(jq_state *jq, jv input, jv a, jv b) {
356
- jv_free(input);
404
+ jv binop_equal(jv a, jv b) {
357
405
  return jv_bool(jv_equal(a, b));
358
406
  }
359
407
 
360
- static jv f_notequal(jq_state *jq, jv input, jv a, jv b) {
361
- jv_free(input);
408
+ jv binop_notequal(jv a, jv b) {
362
409
  return jv_bool(!jv_equal(a, b));
363
410
  }
364
411
 
@@ -369,8 +416,7 @@ enum cmp_op {
369
416
  CMP_OP_GREATEREQ
370
417
  };
371
418
 
372
- static jv order_cmp(jv input, jv a, jv b, enum cmp_op op) {
373
- jv_free(input);
419
+ static jv order_cmp(jv a, jv b, enum cmp_op op) {
374
420
  int r = jv_cmp(a, b);
375
421
  return jv_bool((op == CMP_OP_LESS && r < 0) ||
376
422
  (op == CMP_OP_LESSEQ && r <= 0) ||
@@ -378,20 +424,20 @@ static jv order_cmp(jv input, jv a, jv b, enum cmp_op op) {
378
424
  (op == CMP_OP_GREATER && r > 0));
379
425
  }
380
426
 
381
- static jv f_less(jq_state *jq, jv input, jv a, jv b) {
382
- return order_cmp(input, a, b, CMP_OP_LESS);
427
+ jv binop_less(jv a, jv b) {
428
+ return order_cmp(a, b, CMP_OP_LESS);
383
429
  }
384
430
 
385
- static jv f_greater(jq_state *jq, jv input, jv a, jv b) {
386
- return order_cmp(input, a, b, CMP_OP_GREATER);
431
+ jv binop_greater(jv a, jv b) {
432
+ return order_cmp(a, b, CMP_OP_GREATER);
387
433
  }
388
434
 
389
- static jv f_lesseq(jq_state *jq, jv input, jv a, jv b) {
390
- return order_cmp(input, a, b, CMP_OP_LESSEQ);
435
+ jv binop_lesseq(jv a, jv b) {
436
+ return order_cmp(a, b, CMP_OP_LESSEQ);
391
437
  }
392
438
 
393
- static jv f_greatereq(jq_state *jq, jv input, jv a, jv b) {
394
- return order_cmp(input, a, b, CMP_OP_GREATEREQ);
439
+ jv binop_greatereq(jv a, jv b) {
440
+ return order_cmp(a, b, CMP_OP_GREATEREQ);
395
441
  }
396
442
 
397
443
  static jv f_contains(jq_state *jq, jv a, jv b) {
@@ -420,11 +466,22 @@ static jv f_tonumber(jq_state *jq, jv input) {
420
466
  return input;
421
467
  }
422
468
  if (jv_get_kind(input) == JV_KIND_STRING) {
423
- jv parsed = jv_parse(jv_string_value(input));
424
- if (!jv_is_valid(parsed) || jv_get_kind(parsed) == JV_KIND_NUMBER) {
425
- jv_free(input);
426
- return parsed;
469
+ const char* s = jv_string_value(input);
470
+ #ifdef USE_DECNUM
471
+ jv number = jv_number_with_literal(s);
472
+ if (jv_get_kind(number) == JV_KIND_INVALID) {
473
+ return type_error(input, "cannot be parsed as a number");
427
474
  }
475
+ #else
476
+ char *end = 0;
477
+ double d = jvp_strtod(tsd_dtoa_context_get(), s, &end);
478
+ if (end == 0 || *end != 0) {
479
+ return type_error(input, "cannot be parsed as a number");
480
+ }
481
+ jv number = jv_number(d);
482
+ #endif
483
+ jv_free(input);
484
+ return number;
428
485
  }
429
486
  return type_error(input, "cannot be parsed as a number");
430
487
  }
@@ -437,7 +494,9 @@ static jv f_length(jq_state *jq, jv input) {
437
494
  } else if (jv_get_kind(input) == JV_KIND_STRING) {
438
495
  return jv_number(jv_string_length_codepoints(input));
439
496
  } else if (jv_get_kind(input) == JV_KIND_NUMBER) {
440
- return jv_number(fabs(jv_number_value(input)));
497
+ jv r = jv_number(fabs(jv_number_value(input)));
498
+ jv_free(input);
499
+ return r;
441
500
  } else if (jv_get_kind(input) == JV_KIND_NULL) {
442
501
  jv_free(input);
443
502
  return jv_number(0);
@@ -582,7 +641,7 @@ static jv f_format(jq_state *jq, jv input, jv fmt) {
582
641
  input = f_tostring(jq, input);
583
642
 
584
643
  int unreserved[128] = {0};
585
- const char* p = CHARS_ALPHANUM "-_.!~*'()";
644
+ const char* p = CHARS_ALPHANUM "-_.~";
586
645
  while (*p) unreserved[(int)*p++] = 1;
587
646
 
588
647
  jv line = jv_string("");
@@ -598,6 +657,48 @@ static jv f_format(jq_state *jq, jv input, jv fmt) {
598
657
  }
599
658
  jv_free(input);
600
659
  return line;
660
+ } else if (!strcmp(fmt_s, "urid")) {
661
+ jv_free(fmt);
662
+ input = f_tostring(jq, input);
663
+
664
+ jv line = jv_string("");
665
+ const char *errmsg = "is not a valid uri encoding";
666
+ const char *s = jv_string_value(input);
667
+ while (*s) {
668
+ if (*s != '%') {
669
+ line = jv_string_append_buf(line, s++, 1);
670
+ } else {
671
+ unsigned char unicode[4] = {0};
672
+ int b = 0;
673
+ // check leading bits of first octet to determine length of unicode character
674
+ // (https://datatracker.ietf.org/doc/html/rfc3629#section-3)
675
+ while (b == 0 || (b < 4 && unicode[0] >> 7 & 1 && unicode[0] >> (7-b) & 1)) {
676
+ if (*(s++) != '%') {
677
+ jv_free(line);
678
+ return type_error(input, errmsg);
679
+ }
680
+ for (int i=0; i<2; i++) {
681
+ unicode[b] <<= 4;
682
+ char c = *(s++);
683
+ if ('0' <= c && c <= '9') unicode[b] |= c - '0';
684
+ else if ('a' <= c && c <= 'f') unicode[b] |= c - 'a' + 10;
685
+ else if ('A' <= c && c <= 'F') unicode[b] |= c - 'A' + 10;
686
+ else {
687
+ jv_free(line);
688
+ return type_error(input, errmsg);
689
+ }
690
+ }
691
+ b++;
692
+ }
693
+ if (!jvp_utf8_is_valid((const char *)unicode, (const char *)unicode+b)) {
694
+ jv_free(line);
695
+ return type_error(input, errmsg);
696
+ }
697
+ line = jv_string_append_buf(line, (const char *)unicode, b);
698
+ }
699
+ }
700
+ jv_free(input);
701
+ return line;
601
702
  } else if (!strcmp(fmt_s, "sh")) {
602
703
  jv_free(fmt);
603
704
  if (jv_get_kind(input) != JV_KIND_ARRAY)
@@ -656,7 +757,7 @@ static jv f_format(jq_state *jq, jv input, jv fmt) {
656
757
  input = f_tostring(jq, input);
657
758
  const unsigned char* data = (const unsigned char*)jv_string_value(input);
658
759
  int len = jv_string_length_bytes(jv_copy(input));
659
- size_t decoded_len = (3 * len) / 4; // 3 usable bytes for every 4 bytes of input
760
+ size_t decoded_len = (3 * (size_t)len) / 4; // 3 usable bytes for every 4 bytes of input
660
761
  char *result = jv_mem_calloc(decoded_len, sizeof(char));
661
762
  memset(result, 0, decoded_len * sizeof(char));
662
763
  uint32_t ri = 0;
@@ -862,15 +963,26 @@ static jv f_match(jq_state *jq, jv input, jv regex, jv modifiers, jv testmode) {
862
963
  if (region->end[0] == region->beg[0]) {
863
964
  unsigned long idx;
864
965
  const char *fr = (const char*)input_string;
865
- for (idx = 0; fr != input_string+region->beg[0]; idx++) {
966
+ for (idx = 0; fr < input_string+region->beg[0]; idx++) {
866
967
  fr += jvp_utf8_decode_length(*fr);
867
968
  }
868
969
  jv match = jv_object_set(jv_object(), jv_string("offset"), jv_number(idx));
869
970
  match = jv_object_set(match, jv_string("length"), jv_number(0));
870
971
  match = jv_object_set(match, jv_string("string"), jv_string(""));
871
- match = jv_object_set(match, jv_string("captures"), jv_array());
972
+ jv captures = jv_array();
973
+ for (int i = 1; i < region->num_regs; ++i) {
974
+ jv cap = jv_object();
975
+ cap = jv_object_set(cap, jv_string("offset"), jv_number(idx));
976
+ cap = jv_object_set(cap, jv_string("string"), jv_string(""));
977
+ cap = jv_object_set(cap, jv_string("length"), jv_number(0));
978
+ cap = jv_object_set(cap, jv_string("name"), jv_null());
979
+ captures = jv_array_append(captures, cap);
980
+ }
981
+ onig_foreach_name(reg, f_match_name_iter, &captures);
982
+ match = jv_object_set(match, jv_string("captures"), captures);
872
983
  result = jv_array_append(result, match);
873
- start += 1;
984
+ // ensure '"qux" | match("(?=u)"; "g")' matches just once
985
+ start = (const UChar*)(input_string+region->end[0]+1);
874
986
  continue;
875
987
  }
876
988
 
@@ -899,7 +1011,7 @@ static jv f_match(jq_state *jq, jv input, jv regex, jv modifiers, jv testmode) {
899
1011
  cap = jv_object_set(cap, jv_string("string"), jv_null());
900
1012
  } else {
901
1013
  fr = input_string;
902
- for (idx = 0; fr != input_string+region->beg[i]; idx++) {
1014
+ for (idx = 0; fr < input_string+region->beg[i]; idx++) {
903
1015
  fr += jvp_utf8_decode_length(*fr);
904
1016
  }
905
1017
  cap = jv_object_set(jv_object(), jv_string("offset"), jv_number(idx));
@@ -911,7 +1023,7 @@ static jv f_match(jq_state *jq, jv input, jv regex, jv modifiers, jv testmode) {
911
1023
  continue;
912
1024
  }
913
1025
  fr = input_string;
914
- for (idx = len = 0; fr != input_string+region->end[i]; len++) {
1026
+ for (idx = len = 0; fr < input_string+region->end[i]; len++) {
915
1027
  if (fr == input_string+region->beg[i]) idx = len, len=0;
916
1028
  fr += jvp_utf8_decode_length(*fr);
917
1029
  }
@@ -932,17 +1044,15 @@ static jv f_match(jq_state *jq, jv input, jv regex, jv modifiers, jv testmode) {
932
1044
  break;
933
1045
  } else { /* Error */
934
1046
  UChar ebuf[ONIG_MAX_ERROR_MESSAGE_LEN];
935
- onig_error_code_to_str(ebuf, onigret, einfo);
1047
+ onig_error_code_to_str(ebuf, onigret, &einfo);
936
1048
  jv_free(result);
937
1049
  result = jv_invalid_with_msg(jv_string_concat(jv_string("Regex failure: "),
938
1050
  jv_string((char*)ebuf)));
939
1051
  break;
940
1052
  }
941
- } while (global && start != end);
1053
+ } while (global && start <= end);
942
1054
  onig_region_free(region,1);
943
1055
  region = NULL;
944
- if (region)
945
- onig_region_free(region,1);
946
1056
  onig_free(reg);
947
1057
  jv_free(input);
948
1058
  jv_free(regex);
@@ -950,7 +1060,11 @@ static jv f_match(jq_state *jq, jv input, jv regex, jv modifiers, jv testmode) {
950
1060
  }
951
1061
  #else /* !HAVE_LIBONIG */
952
1062
  static jv f_match(jq_state *jq, jv input, jv regex, jv modifiers, jv testmode) {
953
- return jv_invalid_with_msg(jv_string("jq was compiled without ONIGURUMA regex libary. match/test/sub and related functions are not available."));
1063
+ jv_free(input);
1064
+ jv_free(regex);
1065
+ jv_free(modifiers);
1066
+ jv_free(testmode);
1067
+ return jv_invalid_with_msg(jv_string("jq was compiled without ONIGURUMA regex library. match/test/sub and related functions are not available."));
954
1068
  }
955
1069
  #endif /* HAVE_LIBONIG */
956
1070
 
@@ -1053,9 +1167,8 @@ static jv f_nan(jq_state *jq, jv input) {
1053
1167
  return jv_number(NAN);
1054
1168
  }
1055
1169
 
1056
- static jv f_error(jq_state *jq, jv input, jv msg) {
1057
- jv_free(input);
1058
- return jv_invalid_with_msg(msg);
1170
+ static jv f_error(jq_state *jq, jv input) {
1171
+ return jv_invalid_with_msg(input);
1059
1172
  }
1060
1173
 
1061
1174
  // FIXME Should autoconf check for this!
@@ -1126,11 +1239,84 @@ static jv f_string_indexes(jq_state *jq, jv a, jv b) {
1126
1239
  return jv_string_indexes(a, b);
1127
1240
  }
1128
1241
 
1242
+ enum trim_op {
1243
+ TRIM_LEFT = 1 << 0,
1244
+ TRIM_RIGHT = 1 << 1
1245
+ };
1246
+
1247
+ static jv string_trim(jv a, int op) {
1248
+ if (jv_get_kind(a) != JV_KIND_STRING) {
1249
+ return ret_error(a, jv_string("trim input must be a string"));
1250
+ }
1251
+
1252
+ int len = jv_string_length_bytes(jv_copy(a));
1253
+ const char *start = jv_string_value(a);
1254
+ const char *trim_start = start;
1255
+ const char *end = trim_start + len;
1256
+ const char *trim_end = end;
1257
+ int c;
1258
+
1259
+ if (op & TRIM_LEFT) {
1260
+ for (;;) {
1261
+ const char *ns = jvp_utf8_next(trim_start, end, &c);
1262
+ if (!ns || !jvp_codepoint_is_whitespace(c))
1263
+ break;
1264
+ trim_start = ns;
1265
+ }
1266
+ }
1267
+
1268
+ // make sure not empty string or start trim has trimmed everything
1269
+ if ((op & TRIM_RIGHT) && trim_end > trim_start) {
1270
+ for (;;) {
1271
+ const char *ns = jvp_utf8_backtrack(trim_end-1, trim_start, NULL);
1272
+ jvp_utf8_next(ns, trim_end, &c);
1273
+ if (!jvp_codepoint_is_whitespace(c))
1274
+ break;
1275
+ trim_end = ns;
1276
+ if (ns == trim_start)
1277
+ break;
1278
+ }
1279
+ }
1280
+
1281
+ // no new string needed if there is nothing to trim
1282
+ if (trim_start == start && trim_end == end)
1283
+ return a;
1284
+
1285
+ jv ts = jv_string_sized(trim_start, trim_end - trim_start);
1286
+ jv_free(a);
1287
+ return ts;
1288
+ }
1289
+
1290
+ static jv f_string_trim(jq_state *jq, jv a) { return string_trim(a, TRIM_LEFT | TRIM_RIGHT); }
1291
+ static jv f_string_ltrim(jq_state *jq, jv a) { return string_trim(a, TRIM_LEFT); }
1292
+ static jv f_string_rtrim(jq_state *jq, jv a) { return string_trim(a, TRIM_RIGHT); }
1293
+
1129
1294
  static jv f_string_implode(jq_state *jq, jv a) {
1130
1295
  if (jv_get_kind(a) != JV_KIND_ARRAY) {
1131
1296
  return ret_error(a, jv_string("implode input must be an array"));
1132
1297
  }
1133
- return jv_string_implode(a);
1298
+
1299
+ int len = jv_array_length(jv_copy(a));
1300
+ jv s = jv_string_empty(len);
1301
+
1302
+ for (int i = 0; i < len; i++) {
1303
+ jv n = jv_array_get(jv_copy(a), i);
1304
+ if (jv_get_kind(n) != JV_KIND_NUMBER || jvp_number_is_nan(n)) {
1305
+ jv_free(a);
1306
+ jv_free(s);
1307
+ return type_error(n, "can't be imploded, unicode codepoint needs to be numeric");
1308
+ }
1309
+
1310
+ int nv = jv_number_value(n);
1311
+ jv_free(n);
1312
+ // outside codepoint range or in utf16 surrogate pair range
1313
+ if (nv < 0 || nv > 0x10FFFF || (nv >= 0xD800 && nv <= 0xDFFF))
1314
+ nv = 0xFFFD; // U+FFFD REPLACEMENT CHARACTER
1315
+ s = jv_string_append_codepoint(s, nv);
1316
+ }
1317
+
1318
+ jv_free(a);
1319
+ return s;
1134
1320
  }
1135
1321
 
1136
1322
  static jv f_setpath(jq_state *jq, jv a, jv b, jv c) { return jv_setpath(a, b, c); }
@@ -1171,7 +1357,11 @@ static jv f_debug(jq_state *jq, jv input) {
1171
1357
  }
1172
1358
 
1173
1359
  static jv f_stderr(jq_state *jq, jv input) {
1174
- jv_dumpf(jv_copy(input), stderr, 0);
1360
+ jq_msg_cb cb;
1361
+ void *data;
1362
+ jq_get_stderr_cb(jq, &cb, &data);
1363
+ if (cb != NULL)
1364
+ cb(data, jv_copy(input));
1175
1365
  return input;
1176
1366
  }
1177
1367
 
@@ -1186,6 +1376,27 @@ static jv tm2jv(struct tm *tm) {
1186
1376
  jv_number(tm->tm_yday));
1187
1377
  }
1188
1378
 
1379
+ #if defined(WIN32) && !defined(HAVE_SETENV)
1380
+ static int setenv(const char *var, const char *val, int ovr)
1381
+ {
1382
+ BOOL b;
1383
+ char c[2];
1384
+ if (!ovr)
1385
+ {
1386
+ DWORD d;
1387
+ d = GetEnvironmentVariableA (var, c, 2);
1388
+ if (0 != d && GetLastError () != ERROR_ENVVAR_NOT_FOUND) {
1389
+ return d;
1390
+ }
1391
+ }
1392
+ b = SetEnvironmentVariableA (var, val);
1393
+ if (b) {
1394
+ return 0;
1395
+ }
1396
+ return 1;
1397
+ }
1398
+ #endif
1399
+
1189
1400
  /*
1190
1401
  * mktime() has side-effects and anyways, returns time in the local
1191
1402
  * timezone, not UTC. We want timegm(), which isn't standard.
@@ -1201,10 +1412,23 @@ static jv tm2jv(struct tm *tm) {
1201
1412
  *
1202
1413
  * Returns (time_t)-2 if mktime()'s side-effects cannot be corrected.
1203
1414
  */
1204
- static time_t my_timegm(struct tm *tm) {
1415
+ static time_t my_mktime(struct tm *tm) {
1205
1416
  #ifdef HAVE_TIMEGM
1206
1417
  return timegm(tm);
1207
- #else /* HAVE_TIMEGM */
1418
+ #elif HAVE_TM_TM_GMT_OFF
1419
+
1420
+ time_t t = mktime(tm);
1421
+ if (t == (time_t)-1)
1422
+ return t;
1423
+ return t + tm->tm_gmtoff;
1424
+ #elif HAVE_TM___TM_GMT_OFF
1425
+ time_t t = mktime(tm);
1426
+ if (t == (time_t)-1)
1427
+ return t;
1428
+ return t + tm->__tm_gmtoff;
1429
+ #elif WIN32
1430
+ return _mkgmtime(tm);
1431
+ #else
1208
1432
  char *tz;
1209
1433
 
1210
1434
  tz = (tz = getenv("TZ")) != NULL ? strdup(tz) : NULL;
@@ -1214,18 +1438,6 @@ static time_t my_timegm(struct tm *tm) {
1214
1438
  if (tz != NULL)
1215
1439
  setenv("TZ", tz, 1);
1216
1440
  return t;
1217
- #endif /* !HAVE_TIMEGM */
1218
- }
1219
- static time_t my_mktime(struct tm *tm) {
1220
- time_t t = mktime(tm);
1221
- if (t == (time_t)-1)
1222
- return t;
1223
- #ifdef HAVE_TM_TM_GMT_OFF
1224
- return t + tm->tm_gmtoff;
1225
- #elif HAVE_TM___TM_GMT_OFF
1226
- return t + tm->__tm_gmtoff;
1227
- #else
1228
- return (time_t)-2; /* Not supported */
1229
1441
  #endif
1230
1442
  }
1231
1443
 
@@ -1286,7 +1498,6 @@ static void set_tm_yday(struct tm *tm) {
1286
1498
  tm->tm_yday = yday;
1287
1499
  }
1288
1500
 
1289
- #ifdef HAVE_STRPTIME
1290
1501
  static jv f_strptime(jq_state *jq, jv a, jv b) {
1291
1502
  if (jv_get_kind(a) != JV_KIND_STRING || jv_get_kind(b) != JV_KIND_STRING) {
1292
1503
  return ret_error2(a, b, jv_string("strptime/1 requires string inputs and arguments"));
@@ -1298,9 +1509,14 @@ static jv f_strptime(jq_state *jq, jv a, jv b) {
1298
1509
  tm.tm_yday = 367; // sentinel
1299
1510
  const char *input = jv_string_value(a);
1300
1511
  const char *fmt = jv_string_value(b);
1301
- const char *end = strptime(input, fmt, &tm);
1302
1512
 
1303
- if (end == NULL || (*end != '\0' && !isspace(*end))) {
1513
+ #ifndef HAVE_STRPTIME
1514
+ if (strcmp(fmt, "%Y-%m-%dT%H:%M:%SZ")) {
1515
+ return ret_error2(a, b, jv_string("strptime/1 only supports ISO 8601 on this platform"));
1516
+ }
1517
+ #endif
1518
+ const char *end = strptime(input, fmt, &tm);
1519
+ if (end == NULL || (*end != '\0' && !isspace((unsigned char)*end))) {
1304
1520
  return ret_error2(a, b, jv_string_fmt("date \"%s\" does not match format \"%s\"", input, fmt));
1305
1521
  }
1306
1522
  jv_free(b);
@@ -1324,6 +1540,8 @@ static jv f_strptime(jq_state *jq, jv a, jv b) {
1324
1540
  */
1325
1541
  set_tm_wday(&tm);
1326
1542
  set_tm_yday(&tm);
1543
+ #elif defined(WIN32) || !defined(HAVE_STRPTIME)
1544
+ set_tm_wday(&tm);
1327
1545
  #else
1328
1546
  if (tm.tm_wday == 8 && tm.tm_mday != 0 && tm.tm_mon >= 0 && tm.tm_mon <= 11)
1329
1547
  set_tm_wday(&tm);
@@ -1336,37 +1554,36 @@ static jv f_strptime(jq_state *jq, jv a, jv b) {
1336
1554
  jv_free(a); // must come after `*end` because `end` is a pointer into `a`'s string
1337
1555
  return r;
1338
1556
  }
1339
- #else
1340
- static jv f_strptime(jq_state *jq, jv a, jv b) {
1341
- jv_free(a);
1342
- jv_free(b);
1343
- return jv_invalid_with_msg(jv_string("strptime/1 not implemented on this platform"));
1344
- }
1345
- #endif
1346
-
1347
- #define TO_TM_FIELD(t, j, i) \
1348
- do { \
1349
- jv n = jv_array_get(jv_copy(j), (i)); \
1350
- if (jv_get_kind(n) != (JV_KIND_NUMBER)) { \
1351
- jv_free(j); \
1352
- return 0; \
1353
- } \
1354
- t = jv_number_value(n); \
1355
- jv_free(n); \
1356
- } while (0)
1357
1557
 
1358
1558
  static int jv2tm(jv a, struct tm *tm) {
1359
1559
  memset(tm, 0, sizeof(*tm));
1360
- TO_TM_FIELD(tm->tm_year, a, 0);
1361
- tm->tm_year -= 1900;
1362
- TO_TM_FIELD(tm->tm_mon, a, 1);
1363
- TO_TM_FIELD(tm->tm_mday, a, 2);
1364
- TO_TM_FIELD(tm->tm_hour, a, 3);
1365
- TO_TM_FIELD(tm->tm_min, a, 4);
1366
- TO_TM_FIELD(tm->tm_sec, a, 5);
1367
- TO_TM_FIELD(tm->tm_wday, a, 6);
1368
- TO_TM_FIELD(tm->tm_yday, a, 7);
1369
- jv_free(a);
1560
+ static const size_t offsets[] = {
1561
+ offsetof(struct tm, tm_year),
1562
+ offsetof(struct tm, tm_mon),
1563
+ offsetof(struct tm, tm_mday),
1564
+ offsetof(struct tm, tm_hour),
1565
+ offsetof(struct tm, tm_min),
1566
+ offsetof(struct tm, tm_sec),
1567
+ offsetof(struct tm, tm_wday),
1568
+ offsetof(struct tm, tm_yday),
1569
+ };
1570
+
1571
+ for (size_t i = 0; i < (sizeof offsets / sizeof *offsets); ++i) {
1572
+ jv n = jv_array_get(jv_copy(a), i);
1573
+ if (!jv_is_valid(n))
1574
+ break;
1575
+ if (jv_get_kind(n) != JV_KIND_NUMBER || jvp_number_is_nan(n)) {
1576
+ jv_free(a);
1577
+ jv_free(n);
1578
+ return 0;
1579
+ }
1580
+ double d = jv_number_value(n);
1581
+ if (i == 0) /* year */
1582
+ d -= 1900;
1583
+ *(int *)((void *)tm + offsets[i]) = d < INT_MIN ? INT_MIN :
1584
+ d > INT_MAX ? INT_MAX : (int)d;
1585
+ jv_free(n);
1586
+ }
1370
1587
 
1371
1588
  // We use UTC everywhere (gettimeofday, gmtime) and UTC does not do DST.
1372
1589
  // Setting tm_isdst to 0 is done by the memset.
@@ -1376,6 +1593,7 @@ static int jv2tm(jv a, struct tm *tm) {
1376
1593
  // hope it is okay to initialize them to zero, because the standard does not
1377
1594
  // provide an alternative.
1378
1595
 
1596
+ jv_free(a);
1379
1597
  return 1;
1380
1598
  }
1381
1599
 
@@ -1384,8 +1602,6 @@ static int jv2tm(jv a, struct tm *tm) {
1384
1602
  static jv f_mktime(jq_state *jq, jv a) {
1385
1603
  if (jv_get_kind(a) != JV_KIND_ARRAY)
1386
1604
  return ret_error(a, jv_string("mktime requires array inputs"));
1387
- if (jv_array_length(jv_copy(a)) < 6)
1388
- return ret_error(a, jv_string("mktime requires parsed datetime inputs"));
1389
1605
  struct tm tm;
1390
1606
  if (!jv2tm(a, &tm))
1391
1607
  return jv_invalid_with_msg(jv_string("mktime requires parsed datetime inputs"));
@@ -1408,7 +1624,7 @@ static jv f_gmtime(jq_state *jq, jv a) {
1408
1624
  jv_free(a);
1409
1625
  tmp = gmtime_r(&secs, &tm);
1410
1626
  if (tmp == NULL)
1411
- return jv_invalid_with_msg(jv_string("errror converting number of seconds since epoch to datetime"));
1627
+ return jv_invalid_with_msg(jv_string("error converting number of seconds since epoch to datetime"));
1412
1628
  a = tm2jv(tmp);
1413
1629
  return jv_array_set(a, 5, jv_number(jv_number_value(jv_array_get(jv_copy(a), 5)) + (fsecs - floor(fsecs))));
1414
1630
  }
@@ -1423,7 +1639,7 @@ static jv f_gmtime(jq_state *jq, jv a) {
1423
1639
  jv_free(a);
1424
1640
  tmp = gmtime(&secs);
1425
1641
  if (tmp == NULL)
1426
- return jv_invalid_with_msg(jv_string("errror converting number of seconds since epoch to datetime"));
1642
+ return jv_invalid_with_msg(jv_string("error converting number of seconds since epoch to datetime"));
1427
1643
  a = tm2jv(tmp);
1428
1644
  return jv_array_set(a, 5, jv_number(jv_number_value(jv_array_get(jv_copy(a), 5)) + (fsecs - floor(fsecs))));
1429
1645
  }
@@ -1475,11 +1691,15 @@ static jv f_localtime(jq_state *jq, jv a) {
1475
1691
  static jv f_strftime(jq_state *jq, jv a, jv b) {
1476
1692
  if (jv_get_kind(a) == JV_KIND_NUMBER) {
1477
1693
  a = f_gmtime(jq, a);
1694
+ if (!jv_is_valid(a)) {
1695
+ jv_free(b);
1696
+ return a;
1697
+ }
1478
1698
  } else if (jv_get_kind(a) != JV_KIND_ARRAY) {
1479
1699
  return ret_error2(a, b, jv_string("strftime/1 requires parsed datetime inputs"));
1480
- } else if (jv_get_kind(b) != JV_KIND_STRING) {
1481
- return ret_error2(a, b, jv_string("strftime/1 requires a string format"));
1482
1700
  }
1701
+ if (jv_get_kind(b) != JV_KIND_STRING)
1702
+ return ret_error2(a, b, jv_string("strftime/1 requires a string format"));
1483
1703
  struct tm tm;
1484
1704
  if (!jv2tm(a, &tm))
1485
1705
  return ret_error(b, jv_string("strftime/1 requires parsed datetime inputs"));
@@ -1508,12 +1728,12 @@ static jv f_strflocaltime(jq_state *jq, jv a, jv b) {
1508
1728
  a = f_localtime(jq, a);
1509
1729
  } else if (jv_get_kind(a) != JV_KIND_ARRAY) {
1510
1730
  return ret_error2(a, b, jv_string("strflocaltime/1 requires parsed datetime inputs"));
1511
- } else if (jv_get_kind(b) != JV_KIND_STRING) {
1512
- return ret_error2(a, b, jv_string("strflocaltime/1 requires a string format"));
1513
1731
  }
1732
+ if (jv_get_kind(b) != JV_KIND_STRING)
1733
+ return ret_error2(a, b, jv_string("strflocaltime/1 requires a string format"));
1514
1734
  struct tm tm;
1515
1735
  if (!jv2tm(a, &tm))
1516
- return jv_invalid_with_msg(jv_string("strflocaltime/1 requires parsed datetime inputs"));
1736
+ return ret_error(b, jv_string("strflocaltime/1 requires parsed datetime inputs"));
1517
1737
  const char *fmt = jv_string_value(b);
1518
1738
  size_t alloced = strlen(fmt) + 100;
1519
1739
  char *buf = alloca(alloced);
@@ -1561,104 +1781,133 @@ static jv f_current_line(jq_state *jq, jv a) {
1561
1781
  return jq_util_input_get_current_line(jq);
1562
1782
  }
1563
1783
 
1784
+ static jv f_have_decnum(jq_state *jq, jv a) {
1785
+ jv_free(a);
1786
+ #ifdef USE_DECNUM
1787
+ return jv_true();
1788
+ #else
1789
+ return jv_false();
1790
+ #endif
1791
+ }
1792
+
1793
+ #define CFUNC(func, name, arity) \
1794
+ {.fptr = { .a ## arity = func }, name, arity}
1795
+
1564
1796
  #define LIBM_DD(name) \
1565
- {(cfunction_ptr)f_ ## name, #name, 1},
1566
- #define LIBM_DD_NO(name)
1797
+ CFUNC(f_ ## name, #name, 1),
1798
+ #define LIBM_DD_NO(name) LIBM_DD(name)
1799
+ #define LIBM_DA(name, type) LIBM_DD(name)
1800
+ #define LIBM_DA_NO(name, type) LIBM_DD(name)
1567
1801
 
1568
1802
  #define LIBM_DDD(name) \
1569
- {(cfunction_ptr)f_ ## name, #name, 3},
1570
- #define LIBM_DDD_NO(name)
1803
+ CFUNC(f_ ## name, #name, 3),
1804
+ #define LIBM_DDD_NO(name) LIBM_DDD(name)
1571
1805
 
1572
1806
  #define LIBM_DDDD(name) \
1573
- {(cfunction_ptr)f_ ## name, #name, 4},
1574
- #define LIBM_DDDD_NO(name)
1807
+ CFUNC(f_ ## name, #name, 4),
1808
+ #define LIBM_DDDD_NO(name) LIBM_DDDD(name)
1575
1809
 
1576
1810
  static const struct cfunction function_list[] = {
1577
1811
  #include "libm.h"
1578
- #ifdef HAVE_FREXP
1579
- {(cfunction_ptr)f_frexp,"frexp", 1},
1580
- #endif
1581
- #ifdef HAVE_MODF
1582
- {(cfunction_ptr)f_modf,"modf", 1},
1583
- #endif
1584
- #ifdef HAVE_LGAMMA_R
1585
- {(cfunction_ptr)f_lgamma_r,"lgamma_r", 1},
1586
- #endif
1587
- {(cfunction_ptr)f_plus, "_plus", 3},
1588
- {(cfunction_ptr)f_negate, "_negate", 1},
1589
- {(cfunction_ptr)f_minus, "_minus", 3},
1590
- {(cfunction_ptr)f_multiply, "_multiply", 3},
1591
- {(cfunction_ptr)f_divide, "_divide", 3},
1592
- {(cfunction_ptr)f_mod, "_mod", 3},
1593
- {(cfunction_ptr)f_dump, "tojson", 1},
1594
- {(cfunction_ptr)f_json_parse, "fromjson", 1},
1595
- {(cfunction_ptr)f_tonumber, "tonumber", 1},
1596
- {(cfunction_ptr)f_tostring, "tostring", 1},
1597
- {(cfunction_ptr)f_keys, "keys", 1},
1598
- {(cfunction_ptr)f_keys_unsorted, "keys_unsorted", 1},
1599
- {(cfunction_ptr)f_startswith, "startswith", 2},
1600
- {(cfunction_ptr)f_endswith, "endswith", 2},
1601
- {(cfunction_ptr)f_ltrimstr, "ltrimstr", 2},
1602
- {(cfunction_ptr)f_rtrimstr, "rtrimstr", 2},
1603
- {(cfunction_ptr)f_string_split, "split", 2},
1604
- {(cfunction_ptr)f_string_explode, "explode", 1},
1605
- {(cfunction_ptr)f_string_implode, "implode", 1},
1606
- {(cfunction_ptr)f_string_indexes, "_strindices", 2},
1607
- {(cfunction_ptr)f_setpath, "setpath", 3}, // FIXME typechecking
1608
- {(cfunction_ptr)f_getpath, "getpath", 2},
1609
- {(cfunction_ptr)f_delpaths, "delpaths", 2},
1610
- {(cfunction_ptr)f_has, "has", 2},
1611
- {(cfunction_ptr)f_equal, "_equal", 3},
1612
- {(cfunction_ptr)f_notequal, "_notequal", 3},
1613
- {(cfunction_ptr)f_less, "_less", 3},
1614
- {(cfunction_ptr)f_greater, "_greater", 3},
1615
- {(cfunction_ptr)f_lesseq, "_lesseq", 3},
1616
- {(cfunction_ptr)f_greatereq, "_greatereq", 3},
1617
- {(cfunction_ptr)f_contains, "contains", 2},
1618
- {(cfunction_ptr)f_length, "length", 1},
1619
- {(cfunction_ptr)f_utf8bytelength, "utf8bytelength", 1},
1620
- {(cfunction_ptr)f_type, "type", 1},
1621
- {(cfunction_ptr)f_isinfinite, "isinfinite", 1},
1622
- {(cfunction_ptr)f_isnan, "isnan", 1},
1623
- {(cfunction_ptr)f_isnormal, "isnormal", 1},
1624
- {(cfunction_ptr)f_infinite, "infinite", 1},
1625
- {(cfunction_ptr)f_nan, "nan", 1},
1626
- {(cfunction_ptr)f_sort, "sort", 1},
1627
- {(cfunction_ptr)f_sort_by_impl, "_sort_by_impl", 2},
1628
- {(cfunction_ptr)f_group_by_impl, "_group_by_impl", 2},
1629
- {(cfunction_ptr)f_min, "min", 1},
1630
- {(cfunction_ptr)f_max, "max", 1},
1631
- {(cfunction_ptr)f_min_by_impl, "_min_by_impl", 2},
1632
- {(cfunction_ptr)f_max_by_impl, "_max_by_impl", 2},
1633
- {(cfunction_ptr)f_error, "error", 2},
1634
- {(cfunction_ptr)f_format, "format", 2},
1635
- {(cfunction_ptr)f_env, "env", 1},
1636
- {(cfunction_ptr)f_halt, "halt", 1},
1637
- {(cfunction_ptr)f_halt_error, "halt_error", 2},
1638
- {(cfunction_ptr)f_get_search_list, "get_search_list", 1},
1639
- {(cfunction_ptr)f_get_prog_origin, "get_prog_origin", 1},
1640
- {(cfunction_ptr)f_get_jq_origin, "get_jq_origin", 1},
1641
- {(cfunction_ptr)f_match, "_match_impl", 4},
1642
- {(cfunction_ptr)f_modulemeta, "modulemeta", 1},
1643
- {(cfunction_ptr)f_input, "_input", 1},
1644
- {(cfunction_ptr)f_debug, "debug", 1},
1645
- {(cfunction_ptr)f_stderr, "stderr", 1},
1646
- {(cfunction_ptr)f_strptime, "strptime", 2},
1647
- {(cfunction_ptr)f_strftime, "strftime", 2},
1648
- {(cfunction_ptr)f_strflocaltime, "strflocaltime", 2},
1649
- {(cfunction_ptr)f_mktime, "mktime", 1},
1650
- {(cfunction_ptr)f_gmtime, "gmtime", 1},
1651
- {(cfunction_ptr)f_localtime, "localtime", 1},
1652
- {(cfunction_ptr)f_now, "now", 1},
1653
- {(cfunction_ptr)f_current_filename, "input_filename", 1},
1654
- {(cfunction_ptr)f_current_line, "input_line_number", 1},
1812
+ CFUNC(f_negate, "_negate", 1),
1813
+ #define BINOP(name) CFUNC(f_ ## name, "_" #name, 3),
1814
+ BINOPS
1815
+ #undef BINOP
1816
+ CFUNC(f_dump, "tojson", 1),
1817
+ CFUNC(f_json_parse, "fromjson", 1),
1818
+ CFUNC(f_tonumber, "tonumber", 1),
1819
+ CFUNC(f_tostring, "tostring", 1),
1820
+ CFUNC(f_keys, "keys", 1),
1821
+ CFUNC(f_keys_unsorted, "keys_unsorted", 1),
1822
+ CFUNC(f_startswith, "startswith", 2),
1823
+ CFUNC(f_endswith, "endswith", 2),
1824
+ CFUNC(f_string_split, "split", 2),
1825
+ CFUNC(f_string_explode, "explode", 1),
1826
+ CFUNC(f_string_implode, "implode", 1),
1827
+ CFUNC(f_string_indexes, "_strindices", 2),
1828
+ CFUNC(f_string_trim, "trim", 1),
1829
+ CFUNC(f_string_ltrim, "ltrim", 1),
1830
+ CFUNC(f_string_rtrim, "rtrim", 1),
1831
+ CFUNC(f_setpath, "setpath", 3),
1832
+ CFUNC(f_getpath, "getpath", 2),
1833
+ CFUNC(f_delpaths, "delpaths", 2),
1834
+ CFUNC(f_has, "has", 2),
1835
+ CFUNC(f_contains, "contains", 2),
1836
+ CFUNC(f_length, "length", 1),
1837
+ CFUNC(f_utf8bytelength, "utf8bytelength", 1),
1838
+ CFUNC(f_type, "type", 1),
1839
+ CFUNC(f_isinfinite, "isinfinite", 1),
1840
+ CFUNC(f_isnan, "isnan", 1),
1841
+ CFUNC(f_isnormal, "isnormal", 1),
1842
+ CFUNC(f_infinite, "infinite", 1),
1843
+ CFUNC(f_nan, "nan", 1),
1844
+ CFUNC(f_sort, "sort", 1),
1845
+ CFUNC(f_sort_by_impl, "_sort_by_impl", 2),
1846
+ CFUNC(f_group_by_impl, "_group_by_impl", 2),
1847
+ CFUNC(f_min, "min", 1),
1848
+ CFUNC(f_max, "max", 1),
1849
+ CFUNC(f_min_by_impl, "_min_by_impl", 2),
1850
+ CFUNC(f_max_by_impl, "_max_by_impl", 2),
1851
+ CFUNC(f_error, "error", 1),
1852
+ CFUNC(f_format, "format", 2),
1853
+ CFUNC(f_env, "env", 1),
1854
+ CFUNC(f_halt, "halt", 1),
1855
+ CFUNC(f_halt_error, "halt_error", 2),
1856
+ CFUNC(f_get_search_list, "get_search_list", 1),
1857
+ CFUNC(f_get_prog_origin, "get_prog_origin", 1),
1858
+ CFUNC(f_get_jq_origin, "get_jq_origin", 1),
1859
+ CFUNC(f_match, "_match_impl", 4),
1860
+ CFUNC(f_modulemeta, "modulemeta", 1),
1861
+ CFUNC(f_input, "input", 1),
1862
+ CFUNC(f_debug, "debug", 1),
1863
+ CFUNC(f_stderr, "stderr", 1),
1864
+ CFUNC(f_strptime, "strptime", 2),
1865
+ CFUNC(f_strftime, "strftime", 2),
1866
+ CFUNC(f_strflocaltime, "strflocaltime", 2),
1867
+ CFUNC(f_mktime, "mktime", 1),
1868
+ CFUNC(f_gmtime, "gmtime", 1),
1869
+ CFUNC(f_localtime, "localtime", 1),
1870
+ CFUNC(f_now, "now", 1),
1871
+ CFUNC(f_current_filename, "input_filename", 1),
1872
+ CFUNC(f_current_line, "input_line_number", 1),
1873
+ CFUNC(f_have_decnum, "have_decnum", 1),
1874
+ CFUNC(f_have_decnum, "have_literal_numbers", 1),
1655
1875
  };
1656
1876
  #undef LIBM_DDDD_NO
1657
1877
  #undef LIBM_DDD_NO
1658
1878
  #undef LIBM_DD_NO
1879
+ #undef LIBM_DA_NO
1659
1880
  #undef LIBM_DDDD
1660
1881
  #undef LIBM_DDD
1661
1882
  #undef LIBM_DD
1883
+ #undef LIBM_DA
1884
+
1885
+ // This is a hack to make last(g) yield no output values,
1886
+ // if g yields no output values, without using boxing.
1887
+ static block gen_last_1() {
1888
+ block last_var = gen_op_var_fresh(STOREV, "last");
1889
+ block is_empty_var = gen_op_var_fresh(STOREV, "is_empty");
1890
+ block init = BLOCK(gen_op_simple(DUP),
1891
+ gen_const(jv_null()),
1892
+ last_var,
1893
+ gen_op_simple(DUP),
1894
+ gen_const(jv_true()),
1895
+ is_empty_var);
1896
+ block call_arg = BLOCK(gen_call("arg", gen_noop()),
1897
+ gen_op_simple(DUP),
1898
+ gen_op_bound(STOREV, last_var),
1899
+ gen_const(jv_false()),
1900
+ gen_op_bound(STOREV, is_empty_var),
1901
+ gen_op_simple(BACKTRACK));
1902
+ block if_empty = gen_op_simple(BACKTRACK);
1903
+ return BLOCK(init,
1904
+ gen_op_target(FORK, call_arg),
1905
+ call_arg,
1906
+ BLOCK(gen_op_bound(LOADVN, is_empty_var),
1907
+ gen_op_target(JUMP_F, if_empty),
1908
+ if_empty,
1909
+ gen_op_bound(LOADVN, last_var)));
1910
+ }
1662
1911
 
1663
1912
  struct bytecoded_builtin { const char* name; block code; };
1664
1913
  static block bind_bytecoded_builtins(block b) {
@@ -1679,6 +1928,7 @@ static block bind_bytecoded_builtins(block b) {
1679
1928
  {"path", BLOCK(gen_op_simple(PATH_BEGIN),
1680
1929
  gen_call("arg", gen_noop()),
1681
1930
  gen_op_simple(PATH_END))},
1931
+ {"last", gen_last_1()},
1682
1932
  };
1683
1933
  for (unsigned i=0; i<sizeof(builtin_def_1arg)/sizeof(builtin_def_1arg[0]); i++) {
1684
1934
  builtins = BLOCK(builtins, gen_function(builtin_def_1arg[i].name,
@@ -1703,87 +1953,31 @@ static block bind_bytecoded_builtins(block b) {
1703
1953
  BLOCK(gen_param("start"), gen_param("end")),
1704
1954
  range));
1705
1955
  }
1706
- return block_bind(builtins, b, OP_IS_CALL_PSEUDO);
1956
+ return BLOCK(builtins, b);
1707
1957
  }
1708
1958
 
1709
-
1710
-
1711
- static const char* const jq_builtins =
1959
+ static const char jq_builtins[] = {
1712
1960
  /* Include jq-coded builtins */
1713
1961
  #include "src/builtin.inc"
1714
-
1715
- /* Include unsupported math functions next */
1716
- #define LIBM_DD(name)
1717
- #define LIBM_DDD(name)
1718
- #define LIBM_DDDD(name)
1719
- #define LIBM_DD_NO(name) "def " #name ": \"Error: " #name "/0 not found at build time\"|error;"
1720
- #define LIBM_DDD_NO(name) "def " #name "(a;b): \"Error: " #name "/2 not found at build time\"|error;"
1721
- #define LIBM_DDDD_NO(name) "def " #name "(a;b;c): \"Error: " #name "/3 not found at build time\"|error;"
1722
- #include "libm.h"
1723
- #ifndef HAVE_FREXP
1724
- "def frexp: \"Error: frexp/0 not found found at build time\"|error;"
1725
- #endif
1726
- #ifndef HAVE_MODF
1727
- "def modf: \"Error: modf/0 not found found at build time\"|error;"
1728
- #endif
1729
- #ifndef HAVE_LGAMMA_R
1730
- "def lgamma_r: \"Error: lgamma_r/0 not found found at build time\"|error;"
1731
- #endif
1732
- ;
1733
-
1734
- #undef LIBM_DDDD_NO
1735
- #undef LIBM_DDD_NO
1736
- #undef LIBM_DD_NO
1737
- #undef LIBM_DDDD
1738
- #undef LIBM_DDD
1739
- #undef LIBM_DD
1740
-
1962
+ '\0',
1963
+ };
1741
1964
 
1742
1965
  static block gen_builtin_list(block builtins) {
1743
1966
  jv list = jv_array_append(block_list_funcs(builtins, 1), jv_string("builtins/0"));
1744
1967
  return BLOCK(builtins, gen_function("builtins", gen_noop(), gen_const(list)));
1745
1968
  }
1746
1969
 
1747
- static int builtins_bind_one(jq_state *jq, block* bb, const char* code) {
1748
- struct locfile* src;
1749
- src = locfile_init(jq, "<builtin>", code, strlen(code));
1750
- block funcs;
1751
- int nerrors = jq_parse_library(src, &funcs);
1752
- if (nerrors == 0) {
1753
- *bb = block_bind(funcs, *bb, OP_IS_CALL_PSEUDO);
1754
- }
1755
- locfile_free(src);
1756
- return nerrors;
1757
- }
1758
-
1759
- static int slurp_lib(jq_state *jq, block* bb) {
1760
- int nerrors = 0;
1761
- char* home = getenv("HOME");
1762
- if (home) { // silently ignore no $HOME
1763
- jv filename = jv_string_append_str(jv_string(home), "/.jq");
1764
- jv data = jv_load_file(jv_string_value(filename), 1);
1765
- if (jv_is_valid(data)) {
1766
- nerrors = builtins_bind_one(jq, bb, jv_string_value(data) );
1767
- }
1768
- jv_free(filename);
1769
- jv_free(data);
1770
- }
1771
- return nerrors;
1772
- }
1773
-
1774
1970
  int builtins_bind(jq_state *jq, block* bb) {
1775
- block builtins = gen_noop();
1776
- int nerrors = slurp_lib(jq, bb);
1777
- if (nerrors) {
1778
- block_free(*bb);
1779
- return nerrors;
1780
- }
1781
- nerrors = builtins_bind_one(jq, &builtins, jq_builtins);
1971
+ block builtins;
1972
+ struct locfile* src = locfile_init(jq, "<builtin>", jq_builtins, sizeof(jq_builtins)-1);
1973
+ int nerrors = jq_parse_library(src, &builtins);
1782
1974
  assert(!nerrors);
1975
+ locfile_free(src);
1976
+
1783
1977
  builtins = bind_bytecoded_builtins(builtins);
1784
1978
  builtins = gen_cbinding(function_list, sizeof(function_list)/sizeof(function_list[0]), builtins);
1785
1979
  builtins = gen_builtin_list(builtins);
1786
- *bb = block_bind(builtins, *bb, OP_IS_CALL_PSEUDO);
1787
- *bb = block_drop_unreferenced(*bb);
1980
+
1981
+ *bb = block_bind_referenced(builtins, *bb, OP_IS_CALL_PSEUDO);
1788
1982
  return nerrors;
1789
1983
  }