@port-labs/jq-node-bindings 1.0.4 → 1.1.0-dev

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 (352) hide show
  1. package/.claude/settings.local.json +12 -0
  2. package/configure +6 -5
  3. package/deps/jq/.claude/settings.local.json +7 -0
  4. package/deps/jq/.gitattributes +1 -3
  5. package/deps/jq/AUTHORS +55 -1
  6. package/deps/jq/COPYING +40 -0
  7. package/deps/jq/Makefile.am +40 -36
  8. package/deps/jq/NEWS.md +277 -2
  9. package/deps/jq/README.md +23 -5
  10. package/deps/jq/compile-ios.sh +1 -1
  11. package/deps/jq/config/m4/check-math-func.m4 +2 -2
  12. package/deps/jq/config/m4/find-func-no-libs2.m4 +3 -3
  13. package/deps/jq/configure.ac +10 -18
  14. package/deps/jq/docs/Pipfile.lock +368 -313
  15. package/deps/jq/docs/README.md +3 -4
  16. package/deps/jq/docs/build_manpage.py +1 -1
  17. package/deps/jq/docs/build_mantests.py +1 -1
  18. package/deps/jq/docs/build_website.py +1 -8
  19. package/deps/jq/docs/content/download/default.yml +49 -9
  20. package/deps/jq/docs/content/index.yml +9 -0
  21. package/deps/jq/docs/content/manual/{manual.yml → dev/manual.yml} +218 -61
  22. package/deps/jq/docs/content/manual/v1.3/manual.yml +0 -5
  23. package/deps/jq/docs/content/manual/v1.4/manual.yml +0 -5
  24. package/deps/jq/docs/content/manual/v1.5/manual.yml +3 -8
  25. package/deps/jq/docs/content/manual/v1.6/manual.yml +3 -8
  26. package/deps/jq/docs/content/manual/v1.7/manual.yml +499 -500
  27. package/deps/jq/docs/content/manual/v1.8/manual.yml +3858 -0
  28. package/deps/jq/docs/content/tutorial/default.yml +3 -3
  29. package/deps/jq/docs/manual_schema.yml +0 -3
  30. package/deps/jq/docs/public/CNAME +1 -0
  31. package/deps/jq/docs/templates/index.html.j2 +10 -10
  32. package/deps/jq/docs/templates/manual.html.j2 +14 -3
  33. package/deps/jq/docs/templates/shared/_head.html.j2 +8 -3
  34. package/deps/jq/docs/templates/shared/_navbar.html.j2 +4 -4
  35. package/deps/jq/jq.1.prebuilt +219 -44
  36. package/deps/jq/jq.spec +2 -2
  37. package/deps/jq/libjq.pc.in +1 -1
  38. package/deps/jq/scripts/version +1 -1
  39. package/deps/jq/sig/v1.7.1/jq-1.7.1.tar.gz.asc +16 -0
  40. package/deps/jq/sig/v1.7.1/jq-1.7.1.zip.asc +16 -0
  41. package/deps/jq/sig/v1.7.1/jq-linux-amd64.asc +16 -0
  42. package/deps/jq/sig/v1.7.1/jq-linux-arm64.asc +16 -0
  43. package/deps/jq/sig/v1.7.1/jq-linux-armel.asc +16 -0
  44. package/deps/jq/sig/v1.7.1/jq-linux-armhf.asc +16 -0
  45. package/deps/jq/sig/v1.7.1/jq-linux-i386.asc +16 -0
  46. package/deps/jq/sig/v1.7.1/jq-linux-mips.asc +16 -0
  47. package/deps/jq/sig/v1.7.1/jq-linux-mips64.asc +16 -0
  48. package/deps/jq/sig/v1.7.1/jq-linux-mips64el.asc +16 -0
  49. package/deps/jq/sig/v1.7.1/jq-linux-mips64r6.asc +16 -0
  50. package/deps/jq/sig/v1.7.1/jq-linux-mips64r6el.asc +16 -0
  51. package/deps/jq/sig/v1.7.1/jq-linux-mipsel.asc +16 -0
  52. package/deps/jq/sig/v1.7.1/jq-linux-mipsr6.asc +16 -0
  53. package/deps/jq/sig/v1.7.1/jq-linux-mipsr6el.asc +16 -0
  54. package/deps/jq/sig/v1.7.1/jq-linux-powerpc.asc +16 -0
  55. package/deps/jq/sig/v1.7.1/jq-linux-ppc64el.asc +16 -0
  56. package/deps/jq/sig/v1.7.1/jq-linux-riscv64.asc +16 -0
  57. package/deps/jq/sig/v1.7.1/jq-linux-s390x.asc +16 -0
  58. package/deps/jq/sig/v1.7.1/jq-linux64.asc +16 -0
  59. package/deps/jq/sig/v1.7.1/jq-macos-amd64.asc +16 -0
  60. package/deps/jq/sig/v1.7.1/jq-macos-arm64.asc +16 -0
  61. package/deps/jq/sig/v1.7.1/jq-osx-amd64.asc +16 -0
  62. package/deps/jq/sig/v1.7.1/jq-win64.exe.asc +16 -0
  63. package/deps/jq/sig/v1.7.1/jq-windows-amd64.exe.asc +16 -0
  64. package/deps/jq/sig/v1.7.1/jq-windows-i386.exe.asc +16 -0
  65. package/deps/jq/sig/v1.7.1/sha256sum.txt +26 -0
  66. package/deps/jq/sig/v1.8.0/jq-1.8.0.tar.gz.asc +16 -0
  67. package/deps/jq/sig/v1.8.0/jq-1.8.0.zip.asc +16 -0
  68. package/deps/jq/sig/v1.8.0/jq-linux-amd64.asc +16 -0
  69. package/deps/jq/sig/v1.8.0/jq-linux-arm64.asc +16 -0
  70. package/deps/jq/sig/v1.8.0/jq-linux-armel.asc +16 -0
  71. package/deps/jq/sig/v1.8.0/jq-linux-armhf.asc +16 -0
  72. package/deps/jq/sig/v1.8.0/jq-linux-i386.asc +16 -0
  73. package/deps/jq/sig/v1.8.0/jq-linux-mips.asc +16 -0
  74. package/deps/jq/sig/v1.8.0/jq-linux-mips64.asc +16 -0
  75. package/deps/jq/sig/v1.8.0/jq-linux-mips64el.asc +16 -0
  76. package/deps/jq/sig/v1.8.0/jq-linux-mips64r6.asc +16 -0
  77. package/deps/jq/sig/v1.8.0/jq-linux-mips64r6el.asc +16 -0
  78. package/deps/jq/sig/v1.8.0/jq-linux-mipsel.asc +16 -0
  79. package/deps/jq/sig/v1.8.0/jq-linux-mipsr6.asc +16 -0
  80. package/deps/jq/sig/v1.8.0/jq-linux-mipsr6el.asc +16 -0
  81. package/deps/jq/sig/v1.8.0/jq-linux-powerpc.asc +16 -0
  82. package/deps/jq/sig/v1.8.0/jq-linux-ppc64el.asc +16 -0
  83. package/deps/jq/sig/v1.8.0/jq-linux-riscv64.asc +16 -0
  84. package/deps/jq/sig/v1.8.0/jq-linux-s390x.asc +16 -0
  85. package/deps/jq/sig/v1.8.0/jq-linux64.asc +16 -0
  86. package/deps/jq/sig/v1.8.0/jq-macos-amd64.asc +16 -0
  87. package/deps/jq/sig/v1.8.0/jq-macos-arm64.asc +16 -0
  88. package/deps/jq/sig/v1.8.0/jq-osx-amd64.asc +16 -0
  89. package/deps/jq/sig/v1.8.0/jq-win64.exe.asc +16 -0
  90. package/deps/jq/sig/v1.8.0/jq-windows-amd64.exe.asc +16 -0
  91. package/deps/jq/sig/v1.8.0/jq-windows-i386.exe.asc +16 -0
  92. package/deps/jq/sig/v1.8.0/sha256sum.txt +26 -0
  93. package/deps/jq/src/builtin.c +446 -271
  94. package/deps/jq/src/builtin.jq +25 -60
  95. package/deps/jq/src/bytecode.h +8 -3
  96. package/deps/jq/src/compile.c +22 -43
  97. package/deps/jq/src/compile.h +1 -1
  98. package/deps/jq/src/execute.c +20 -25
  99. package/deps/jq/src/jq_test.c +113 -44
  100. package/deps/jq/src/jv.c +134 -42
  101. package/deps/jq/src/jv.h +10 -3
  102. package/deps/jq/src/jv_alloc.c +8 -5
  103. package/deps/jq/src/jv_alloc.h +0 -1
  104. package/deps/jq/src/jv_aux.c +41 -8
  105. package/deps/jq/src/jv_dtoa.c +4 -12
  106. package/deps/jq/src/jv_dtoa_tsd.c +5 -4
  107. package/deps/jq/src/jv_dtoa_tsd.h +1 -1
  108. package/deps/jq/src/jv_parse.c +5 -3
  109. package/deps/jq/src/jv_print.c +87 -65
  110. package/deps/jq/src/jv_unicode.c +18 -0
  111. package/deps/jq/src/jv_unicode.h +2 -0
  112. package/deps/jq/src/lexer.c +303 -278
  113. package/deps/jq/src/lexer.h +5 -4
  114. package/deps/jq/src/lexer.l +8 -2
  115. package/deps/jq/src/libm.h +15 -5
  116. package/deps/jq/src/linker.c +6 -4
  117. package/deps/jq/src/locfile.c +12 -12
  118. package/deps/jq/src/main.c +204 -270
  119. package/deps/jq/src/parser.c +1105 -1273
  120. package/deps/jq/src/parser.y +149 -181
  121. package/deps/jq/src/util.c +46 -48
  122. package/deps/jq/src/util.h +1 -1
  123. package/deps/jq/tests/base64.test +12 -0
  124. package/deps/jq/tests/jq.test +429 -37
  125. package/deps/jq/tests/jq_fuzz_load_file.c +1 -0
  126. package/deps/jq/tests/man.test +46 -13
  127. package/deps/jq/tests/manonig.test +13 -0
  128. package/deps/jq/tests/onig.test +40 -2
  129. package/deps/jq/tests/optional.test +4 -12
  130. package/deps/jq/tests/setup +5 -1
  131. package/deps/jq/tests/shtest +358 -130
  132. package/deps/jq/tests/uri.test +38 -0
  133. package/deps/jq/tests/uritest +5 -0
  134. package/deps/jq/{src → vendor}/decNumber/decBasic.c +1 -1
  135. package/deps/jq/{src → vendor}/decNumber/decCommon.c +1 -1
  136. package/deps/jq/{src → vendor}/decNumber/decNumber.c +4 -4
  137. package/deps/jq/{modules → vendor}/oniguruma/CMakeLists.txt +5 -3
  138. package/deps/jq/{modules → vendor}/oniguruma/HISTORY +45 -7
  139. package/deps/jq/{modules → vendor}/oniguruma/Makefile.am +1 -1
  140. package/deps/jq/{modules → vendor}/oniguruma/README.md +10 -23
  141. package/deps/jq/{modules → vendor}/oniguruma/compile +29 -13
  142. package/deps/jq/{modules → vendor}/oniguruma/config.guess +91 -27
  143. package/deps/jq/{modules → vendor}/oniguruma/config.sub +716 -242
  144. package/deps/jq/{modules → vendor}/oniguruma/configure.ac +2 -2
  145. package/deps/jq/{modules → vendor}/oniguruma/depcomp +10 -9
  146. package/deps/jq/{modules → vendor}/oniguruma/doc/API +3 -1
  147. package/deps/jq/{modules → vendor}/oniguruma/doc/API.ja +3 -1
  148. package/deps/jq/{modules → vendor}/oniguruma/doc/CALLOUTS.BUILTIN +10 -1
  149. package/deps/jq/{modules → vendor}/oniguruma/doc/CALLOUTS.BUILTIN.ja +9 -1
  150. package/deps/jq/{modules → vendor}/oniguruma/doc/RE +12 -13
  151. package/deps/jq/{modules → vendor}/oniguruma/doc/RE.ja +12 -13
  152. package/deps/jq/{modules → vendor}/oniguruma/doc/SYNTAX.md +202 -167
  153. package/deps/jq/{modules → vendor}/oniguruma/doc/UNICODE_PROPERTIES +33 -1
  154. package/deps/jq/vendor/oniguruma/doc/onig_syn_md.c +667 -0
  155. package/deps/jq/{modules → vendor}/oniguruma/harnesses/base.c +1 -1
  156. package/deps/jq/{modules → vendor}/oniguruma/install-sh +9 -9
  157. package/deps/jq/{modules → vendor}/oniguruma/missing +50 -29
  158. package/deps/jq/{modules → vendor}/oniguruma/sample/callback_each_match.c +1 -3
  159. package/deps/jq/vendor/oniguruma/sbom.cdx.json +44 -0
  160. package/deps/jq/{modules → vendor}/oniguruma/src/ascii.c +4 -1
  161. package/deps/jq/{modules → vendor}/oniguruma/src/gperf_fold_key_conv.py +4 -4
  162. package/deps/jq/{modules → vendor}/oniguruma/src/gperf_unfold_key_conv.py +4 -4
  163. package/deps/jq/vendor/oniguruma/src/make_unicode_egcb.sh +7 -0
  164. package/deps/jq/{modules → vendor}/oniguruma/src/make_unicode_egcb_data.py +20 -19
  165. package/deps/jq/{modules → vendor}/oniguruma/src/make_unicode_fold.sh +5 -5
  166. package/deps/jq/{modules → vendor}/oniguruma/src/make_unicode_fold_data.py +37 -37
  167. package/deps/jq/{modules → vendor}/oniguruma/src/make_unicode_property.sh +2 -2
  168. package/deps/jq/{modules → vendor}/oniguruma/src/make_unicode_property_data.py +66 -65
  169. package/deps/jq/vendor/oniguruma/src/make_unicode_wb.sh +7 -0
  170. package/deps/jq/{modules → vendor}/oniguruma/src/make_unicode_wb_data.py +20 -19
  171. package/deps/jq/{modules → vendor}/oniguruma/src/oniguruma.h +6 -3
  172. package/deps/jq/{modules → vendor}/oniguruma/src/regcomp.c +14 -6
  173. package/deps/jq/{modules → vendor}/oniguruma/src/regerror.c +2 -2
  174. package/deps/jq/{modules → vendor}/oniguruma/src/regexec.c +85 -14
  175. package/deps/jq/{modules → vendor}/oniguruma/src/regint.h +17 -4
  176. package/deps/jq/{modules → vendor}/oniguruma/src/regparse.c +115 -27
  177. package/deps/jq/{modules → vendor}/oniguruma/src/regsyntax.c +10 -7
  178. package/deps/jq/{modules → vendor}/oniguruma/src/st.c +49 -75
  179. package/deps/jq/{modules → vendor}/oniguruma/src/st.h +3 -10
  180. package/deps/jq/{modules → vendor}/oniguruma/src/unicode_egcb_data.c +54 -49
  181. package/deps/jq/{modules → vendor}/oniguruma/src/unicode_fold1_key.c +1567 -1507
  182. package/deps/jq/{modules → vendor}/oniguruma/src/unicode_fold2_key.c +1 -1
  183. package/deps/jq/{modules → vendor}/oniguruma/src/unicode_fold3_key.c +1 -1
  184. package/deps/jq/vendor/oniguruma/src/unicode_fold_data.c +1619 -0
  185. package/deps/jq/{modules → vendor}/oniguruma/src/unicode_property_data.c +5520 -4178
  186. package/deps/jq/{modules → vendor}/oniguruma/src/unicode_property_data_posix.c +239 -83
  187. package/deps/jq/vendor/oniguruma/src/unicode_unfold_key.c +3497 -0
  188. package/deps/jq/{modules → vendor}/oniguruma/src/unicode_wb_data.c +51 -19
  189. package/deps/jq/{modules → vendor}/oniguruma/src/utf16_be.c +3 -2
  190. package/deps/jq/{modules → vendor}/oniguruma/src/utf16_le.c +3 -2
  191. package/deps/jq/{modules → vendor}/oniguruma/test/test_back.c +3 -3
  192. package/deps/jq/{modules → vendor}/oniguruma/test/test_options.c +2 -2
  193. package/deps/jq/{modules → vendor}/oniguruma/test/test_syntax.c +54 -2
  194. package/deps/jq/{modules → vendor}/oniguruma/test/test_utf8.c +19 -5
  195. package/deps/jq/{modules → vendor}/oniguruma/test/testc.c +1 -1
  196. package/deps/jq/{modules → vendor}/oniguruma/test/testp.c +1 -1
  197. package/deps/jq/{modules → vendor}/oniguruma/test-driver +13 -6
  198. package/deps/jq/{modules → vendor}/oniguruma/windows/CMakeLists.txt +1 -1
  199. package/index.d.ts +2 -1
  200. package/lib/index.js +1 -0
  201. package/lib/jq.js +2 -1
  202. package/package.json +4 -3
  203. package/test/santiy-async.test.js +4 -4
  204. package/test/santiy.test.js +4 -4
  205. package/test/template.test.js +6 -6
  206. package/deps/jq/modules/oniguruma/src/make_unicode_egcb.sh +0 -7
  207. package/deps/jq/modules/oniguruma/src/make_unicode_wb.sh +0 -7
  208. package/deps/jq/modules/oniguruma/src/unicode_fold_data.c +0 -1592
  209. package/deps/jq/modules/oniguruma/src/unicode_unfold_key.c +0 -3394
  210. package/deps/jq/scripts/update-website +0 -30
  211. /package/deps/jq/{src → vendor}/decNumber/ICU-license.html +0 -0
  212. /package/deps/jq/{src → vendor}/decNumber/decContext.c +0 -0
  213. /package/deps/jq/{src → vendor}/decNumber/decContext.h +0 -0
  214. /package/deps/jq/{src → vendor}/decNumber/decDPD.h +0 -0
  215. /package/deps/jq/{src → vendor}/decNumber/decDouble.c +0 -0
  216. /package/deps/jq/{src → vendor}/decNumber/decDouble.h +0 -0
  217. /package/deps/jq/{src → vendor}/decNumber/decNumber.h +0 -0
  218. /package/deps/jq/{src → vendor}/decNumber/decNumberLocal.h +0 -0
  219. /package/deps/jq/{src → vendor}/decNumber/decPacked.c +0 -0
  220. /package/deps/jq/{src → vendor}/decNumber/decPacked.h +0 -0
  221. /package/deps/jq/{src → vendor}/decNumber/decQuad.c +0 -0
  222. /package/deps/jq/{src → vendor}/decNumber/decQuad.h +0 -0
  223. /package/deps/jq/{src → vendor}/decNumber/decSingle.c +0 -0
  224. /package/deps/jq/{src → vendor}/decNumber/decSingle.h +0 -0
  225. /package/deps/jq/{src → vendor}/decNumber/decimal128.c +0 -0
  226. /package/deps/jq/{src → vendor}/decNumber/decimal128.h +0 -0
  227. /package/deps/jq/{src → vendor}/decNumber/decimal32.c +0 -0
  228. /package/deps/jq/{src → vendor}/decNumber/decimal32.h +0 -0
  229. /package/deps/jq/{src → vendor}/decNumber/decimal64.c +0 -0
  230. /package/deps/jq/{src → vendor}/decNumber/decimal64.h +0 -0
  231. /package/deps/jq/{src → vendor}/decNumber/decnumber.pdf +0 -0
  232. /package/deps/jq/{src → vendor}/decNumber/example1.c +0 -0
  233. /package/deps/jq/{src → vendor}/decNumber/example2.c +0 -0
  234. /package/deps/jq/{src → vendor}/decNumber/example3.c +0 -0
  235. /package/deps/jq/{src → vendor}/decNumber/example4.c +0 -0
  236. /package/deps/jq/{src → vendor}/decNumber/example5.c +0 -0
  237. /package/deps/jq/{src → vendor}/decNumber/example6.c +0 -0
  238. /package/deps/jq/{src → vendor}/decNumber/example7.c +0 -0
  239. /package/deps/jq/{src → vendor}/decNumber/example8.c +0 -0
  240. /package/deps/jq/{src → vendor}/decNumber/readme.txt +0 -0
  241. /package/deps/jq/{modules → vendor}/oniguruma/.travis.yml +0 -0
  242. /package/deps/jq/{modules → vendor}/oniguruma/AUTHORS +0 -0
  243. /package/deps/jq/{modules → vendor}/oniguruma/COPYING +0 -0
  244. /package/deps/jq/{modules → vendor}/oniguruma/ChangeLog +0 -0
  245. /package/deps/jq/{modules → vendor}/oniguruma/NEWS +0 -0
  246. /package/deps/jq/{modules → vendor}/oniguruma/README +0 -0
  247. /package/deps/jq/{modules → vendor}/oniguruma/README_japanese +0 -0
  248. /package/deps/jq/{modules → vendor}/oniguruma/autogen.sh +0 -0
  249. /package/deps/jq/{modules → vendor}/oniguruma/cmake/Config.cmake.in +0 -0
  250. /package/deps/jq/{modules → vendor}/oniguruma/doc/CALLOUTS.API +0 -0
  251. /package/deps/jq/{modules → vendor}/oniguruma/doc/CALLOUTS.API.ja +0 -0
  252. /package/deps/jq/{modules → vendor}/oniguruma/doc/FAQ +0 -0
  253. /package/deps/jq/{modules → vendor}/oniguruma/doc/FAQ.ja +0 -0
  254. /package/deps/jq/{modules → vendor}/oniguruma/harnesses/ascii_compatible.dict +0 -0
  255. /package/deps/jq/{modules → vendor}/oniguruma/harnesses/deluxe.c +0 -0
  256. /package/deps/jq/{modules → vendor}/oniguruma/harnesses/dict_conv.py +0 -0
  257. /package/deps/jq/{modules → vendor}/oniguruma/harnesses/fuzzer.options +0 -0
  258. /package/deps/jq/{modules → vendor}/oniguruma/harnesses/libfuzzer-onig.cpp +0 -0
  259. /package/deps/jq/{modules → vendor}/oniguruma/harnesses/regset.c +0 -0
  260. /package/deps/jq/{modules → vendor}/oniguruma/index.html +0 -0
  261. /package/deps/jq/{modules → vendor}/oniguruma/index_ja.html +0 -0
  262. /package/deps/jq/{modules → vendor}/oniguruma/m4/.whatever +0 -0
  263. /package/deps/jq/{modules → vendor}/oniguruma/make_win.bat +0 -0
  264. /package/deps/jq/{modules → vendor}/oniguruma/make_win32.bat +0 -0
  265. /package/deps/jq/{modules → vendor}/oniguruma/make_win64.bat +0 -0
  266. /package/deps/jq/{modules → vendor}/oniguruma/onig-config.cmake.in +0 -0
  267. /package/deps/jq/{modules → vendor}/oniguruma/onig-config.in +0 -0
  268. /package/deps/jq/{modules → vendor}/oniguruma/oniguruma.pc.cmake.in +0 -0
  269. /package/deps/jq/{modules → vendor}/oniguruma/oniguruma.pc.in +0 -0
  270. /package/deps/jq/{modules → vendor}/oniguruma/sample/CMakeLists.txt +0 -0
  271. /package/deps/jq/{modules → vendor}/oniguruma/sample/Makefile.am +0 -0
  272. /package/deps/jq/{modules → vendor}/oniguruma/sample/bug_fix.c +0 -0
  273. /package/deps/jq/{modules → vendor}/oniguruma/sample/callout.c +0 -0
  274. /package/deps/jq/{modules → vendor}/oniguruma/sample/count.c +0 -0
  275. /package/deps/jq/{modules → vendor}/oniguruma/sample/crnl.c +0 -0
  276. /package/deps/jq/{modules → vendor}/oniguruma/sample/echo.c +0 -0
  277. /package/deps/jq/{modules → vendor}/oniguruma/sample/encode.c +0 -0
  278. /package/deps/jq/{modules → vendor}/oniguruma/sample/listcap.c +0 -0
  279. /package/deps/jq/{modules → vendor}/oniguruma/sample/names.c +0 -0
  280. /package/deps/jq/{modules → vendor}/oniguruma/sample/posix.c +0 -0
  281. /package/deps/jq/{modules → vendor}/oniguruma/sample/regset.c +0 -0
  282. /package/deps/jq/{modules → vendor}/oniguruma/sample/scan.c +0 -0
  283. /package/deps/jq/{modules → vendor}/oniguruma/sample/simple.c +0 -0
  284. /package/deps/jq/{modules → vendor}/oniguruma/sample/sql.c +0 -0
  285. /package/deps/jq/{modules → vendor}/oniguruma/sample/syntax.c +0 -0
  286. /package/deps/jq/{modules → vendor}/oniguruma/sample/user_property.c +0 -0
  287. /package/deps/jq/{modules → vendor}/oniguruma/src/Makefile.am +0 -0
  288. /package/deps/jq/{modules → vendor}/oniguruma/src/Makefile.windows +0 -0
  289. /package/deps/jq/{modules → vendor}/oniguruma/src/big5.c +0 -0
  290. /package/deps/jq/{modules → vendor}/oniguruma/src/config.h.cmake.in +0 -0
  291. /package/deps/jq/{modules → vendor}/oniguruma/src/config.h.win32 +0 -0
  292. /package/deps/jq/{modules → vendor}/oniguruma/src/config.h.win64 +0 -0
  293. /package/deps/jq/{modules → vendor}/oniguruma/src/config.h.windows.in +0 -0
  294. /package/deps/jq/{modules → vendor}/oniguruma/src/cp1251.c +0 -0
  295. /package/deps/jq/{modules → vendor}/oniguruma/src/euc_jp.c +0 -0
  296. /package/deps/jq/{modules → vendor}/oniguruma/src/euc_jp_prop.c +0 -0
  297. /package/deps/jq/{modules → vendor}/oniguruma/src/euc_jp_prop.gperf +0 -0
  298. /package/deps/jq/{modules → vendor}/oniguruma/src/euc_kr.c +0 -0
  299. /package/deps/jq/{modules → vendor}/oniguruma/src/euc_tw.c +0 -0
  300. /package/deps/jq/{modules → vendor}/oniguruma/src/gb18030.c +0 -0
  301. /package/deps/jq/{modules → vendor}/oniguruma/src/iso8859_1.c +0 -0
  302. /package/deps/jq/{modules → vendor}/oniguruma/src/iso8859_10.c +0 -0
  303. /package/deps/jq/{modules → vendor}/oniguruma/src/iso8859_11.c +0 -0
  304. /package/deps/jq/{modules → vendor}/oniguruma/src/iso8859_13.c +0 -0
  305. /package/deps/jq/{modules → vendor}/oniguruma/src/iso8859_14.c +0 -0
  306. /package/deps/jq/{modules → vendor}/oniguruma/src/iso8859_15.c +0 -0
  307. /package/deps/jq/{modules → vendor}/oniguruma/src/iso8859_16.c +0 -0
  308. /package/deps/jq/{modules → vendor}/oniguruma/src/iso8859_2.c +0 -0
  309. /package/deps/jq/{modules → vendor}/oniguruma/src/iso8859_3.c +0 -0
  310. /package/deps/jq/{modules → vendor}/oniguruma/src/iso8859_4.c +0 -0
  311. /package/deps/jq/{modules → vendor}/oniguruma/src/iso8859_5.c +0 -0
  312. /package/deps/jq/{modules → vendor}/oniguruma/src/iso8859_6.c +0 -0
  313. /package/deps/jq/{modules → vendor}/oniguruma/src/iso8859_7.c +0 -0
  314. /package/deps/jq/{modules → vendor}/oniguruma/src/iso8859_8.c +0 -0
  315. /package/deps/jq/{modules → vendor}/oniguruma/src/iso8859_9.c +0 -0
  316. /package/deps/jq/{modules → vendor}/oniguruma/src/koi8.c +0 -0
  317. /package/deps/jq/{modules → vendor}/oniguruma/src/koi8_r.c +0 -0
  318. /package/deps/jq/{modules → vendor}/oniguruma/src/make_property.sh +0 -0
  319. /package/deps/jq/{modules → vendor}/oniguruma/src/mktable.c +0 -0
  320. /package/deps/jq/{modules → vendor}/oniguruma/src/onig_init.c +0 -0
  321. /package/deps/jq/{modules → vendor}/oniguruma/src/oniggnu.h +0 -0
  322. /package/deps/jq/{modules → vendor}/oniguruma/src/onigposix.h +0 -0
  323. /package/deps/jq/{modules → vendor}/oniguruma/src/regenc.c +0 -0
  324. /package/deps/jq/{modules → vendor}/oniguruma/src/regenc.h +0 -0
  325. /package/deps/jq/{modules → vendor}/oniguruma/src/regext.c +0 -0
  326. /package/deps/jq/{modules → vendor}/oniguruma/src/reggnu.c +0 -0
  327. /package/deps/jq/{modules → vendor}/oniguruma/src/regparse.h +0 -0
  328. /package/deps/jq/{modules → vendor}/oniguruma/src/regposerr.c +0 -0
  329. /package/deps/jq/{modules → vendor}/oniguruma/src/regposix.c +0 -0
  330. /package/deps/jq/{modules → vendor}/oniguruma/src/regtrav.c +0 -0
  331. /package/deps/jq/{modules → vendor}/oniguruma/src/regversion.c +0 -0
  332. /package/deps/jq/{modules → vendor}/oniguruma/src/sjis.c +0 -0
  333. /package/deps/jq/{modules → vendor}/oniguruma/src/sjis_prop.c +0 -0
  334. /package/deps/jq/{modules → vendor}/oniguruma/src/sjis_prop.gperf +0 -0
  335. /package/deps/jq/{modules → vendor}/oniguruma/src/unicode.c +0 -0
  336. /package/deps/jq/{modules → vendor}/oniguruma/src/utf32_be.c +0 -0
  337. /package/deps/jq/{modules → vendor}/oniguruma/src/utf32_le.c +0 -0
  338. /package/deps/jq/{modules → vendor}/oniguruma/src/utf8.c +0 -0
  339. /package/deps/jq/{modules → vendor}/oniguruma/test/CMakeLists.txt +0 -0
  340. /package/deps/jq/{modules → vendor}/oniguruma/test/Makefile.am +0 -0
  341. /package/deps/jq/{modules → vendor}/oniguruma/test/test.sh +0 -0
  342. /package/deps/jq/{modules → vendor}/oniguruma/test/test_regset.c +0 -0
  343. /package/deps/jq/{modules → vendor}/oniguruma/test/testu.c +0 -0
  344. /package/deps/jq/{modules → vendor}/oniguruma/tis-ci/stub.c +0 -0
  345. /package/deps/jq/{modules → vendor}/oniguruma/tis-ci/test_back.config +0 -0
  346. /package/deps/jq/{modules → vendor}/oniguruma/tis-ci/test_regset.config +0 -0
  347. /package/deps/jq/{modules → vendor}/oniguruma/tis-ci/test_syntax.config +0 -0
  348. /package/deps/jq/{modules → vendor}/oniguruma/tis-ci/test_utf8.config +0 -0
  349. /package/deps/jq/{modules → vendor}/oniguruma/tis-ci/testc.config +0 -0
  350. /package/deps/jq/{modules → vendor}/oniguruma/tis-ci/testu.config +0 -0
  351. /package/deps/jq/{modules → vendor}/oniguruma/tis.config +0 -0
  352. /package/deps/jq/{modules → vendor}/oniguruma/windows/testc.c +0 -0
@@ -5,24 +5,12 @@
5
5
  # define _XPG6
6
6
  # define __EXTENSIONS__
7
7
  #endif
8
+ #ifdef __OpenBSD__
9
+ # define _BSD_SOURCE
10
+ #endif
8
11
  #include <sys/time.h>
9
12
  #include <stdlib.h>
10
13
  #include <stddef.h>
11
- #ifdef HAVE_ALLOCA_H
12
- # include <alloca.h>
13
- #elif !defined alloca
14
- # ifdef __GNUC__
15
- # define alloca __builtin_alloca
16
- # elif defined _MSC_VER
17
- # include <malloc.h>
18
- # define alloca _alloca
19
- # elif !defined HAVE_ALLOCA
20
- # ifdef __cplusplus
21
- extern "C"
22
- # endif
23
- void *alloca (size_t);
24
- # endif
25
- #endif
26
14
  #include <assert.h>
27
15
  #include <ctype.h>
28
16
  #include <limits.h>
@@ -43,6 +31,8 @@ void *alloca (size_t);
43
31
  #include "locfile.h"
44
32
  #include "jv_unicode.h"
45
33
  #include "jv_alloc.h"
34
+ #include "jv_dtoa.h"
35
+ #include "jv_dtoa_tsd.h"
46
36
  #include "jv_private.h"
47
37
  #include "util.h"
48
38
 
@@ -155,7 +145,11 @@ static jv f_ ## name(jq_state *jq, jv input) { \
155
145
  jv_free(input); \
156
146
  return ret; \
157
147
  }
158
- #define LIBM_DD_NO(name)
148
+ #define LIBM_DD_NO(name) \
149
+ static jv f_ ## name(jq_state *jq, jv input) { \
150
+ jv error = jv_string("Error: " #name "/0 not found at build time"); \
151
+ return ret_error(input, error); \
152
+ }
159
153
 
160
154
  #define LIBM_DDD(name) \
161
155
  static jv f_ ## name(jq_state *jq, jv input, jv a, jv b) { \
@@ -173,7 +167,12 @@ static jv f_ ## name(jq_state *jq, jv input, jv a, jv b) { \
173
167
  jv_free(b); \
174
168
  return ret; \
175
169
  }
176
- #define LIBM_DDD_NO(name)
170
+ #define LIBM_DDD_NO(name) \
171
+ static jv f_ ## name(jq_state *jq, jv input, jv a, jv b) { \
172
+ jv_free(b); \
173
+ jv error = jv_string("Error: " #name "/2 not found at build time"); \
174
+ return ret_error2(input, a, error); \
175
+ }
177
176
 
178
177
  #define LIBM_DDDD(name) \
179
178
  static jv f_ ## name(jq_state *jq, jv input, jv a, jv b, jv c) { \
@@ -199,14 +198,40 @@ static jv f_ ## name(jq_state *jq, jv input, jv a, jv b, jv c) { \
199
198
  jv_free(c); \
200
199
  return ret; \
201
200
  }
202
- #define LIBM_DDDD_NO(name)
201
+ #define LIBM_DDDD_NO(name) \
202
+ static jv f_ ## name(jq_state *jq, jv input, jv a, jv b, jv c) { \
203
+ jv_free(c); \
204
+ jv_free(b); \
205
+ jv error = jv_string("Error: " #name "/3 not found at build time"); \
206
+ return ret_error2(input, a, error); \
207
+ }
208
+
209
+ #define LIBM_DA(name, type) \
210
+ static jv f_ ## name(jq_state *jq, jv input) { \
211
+ if (jv_get_kind(input) != JV_KIND_NUMBER) { \
212
+ return type_error(input, "number required"); \
213
+ } \
214
+ type value; \
215
+ double d = name(jv_number_value(input), &value); \
216
+ jv ret = JV_ARRAY(jv_number(d), jv_number(value)); \
217
+ jv_free(input); \
218
+ return ret; \
219
+ }
220
+ #define LIBM_DA_NO(name, type) \
221
+ static jv f_ ## name(jq_state *jq, jv input) { \
222
+ jv error = jv_string("Error: " #name "/0 not found at build time"); \
223
+ return ret_error(input, error); \
224
+ }
225
+
203
226
  #include "libm.h"
204
227
  #undef LIBM_DDDD_NO
205
228
  #undef LIBM_DDD_NO
206
229
  #undef LIBM_DD_NO
230
+ #undef LIBM_DA_NO
207
231
  #undef LIBM_DDDD
208
232
  #undef LIBM_DDD
209
233
  #undef LIBM_DD
234
+ #undef LIBM_DA
210
235
 
211
236
  #ifdef __APPLE__
212
237
  #undef gamma
@@ -215,46 +240,11 @@ static jv f_ ## name(jq_state *jq, jv input, jv a, jv b, jv c) { \
215
240
  #undef exp10
216
241
  #endif
217
242
 
218
- #ifdef HAVE_FREXP
219
- static jv f_frexp(jq_state *jq, jv input) {
220
- if (jv_get_kind(input) != JV_KIND_NUMBER) {
221
- return type_error(input, "number required");
222
- }
223
- int exp;
224
- double d = frexp(jv_number_value(input), &exp);
225
- jv ret = JV_ARRAY(jv_number(d), jv_number(exp));
226
- jv_free(input);
227
- return ret;
228
- }
229
- #endif
230
- #ifdef HAVE_MODF
231
- static jv f_modf(jq_state *jq, jv input) {
232
- if (jv_get_kind(input) != JV_KIND_NUMBER) {
233
- return type_error(input, "number required");
234
- }
235
- double i;
236
- jv ret = JV_ARRAY(jv_number(modf(jv_number_value(input), &i)));
237
- jv_free(input);
238
- return jv_array_append(ret, jv_number(i));
239
- }
240
- #endif
241
- #ifdef HAVE_LGAMMA_R
242
- static jv f_lgamma_r(jq_state *jq, jv input) {
243
- if (jv_get_kind(input) != JV_KIND_NUMBER) {
244
- return type_error(input, "number required");
245
- }
246
- int sign;
247
- jv ret = JV_ARRAY(jv_number(lgamma_r(jv_number_value(input), &sign)));
248
- jv_free(input);
249
- return jv_array_append(ret, jv_number(sign));
250
- }
251
- #endif
252
-
253
243
  static jv f_negate(jq_state *jq, jv input) {
254
244
  if (jv_get_kind(input) != JV_KIND_NUMBER) {
255
245
  return type_error(input, "cannot be negated");
256
246
  }
257
- jv ret = jv_number(-jv_number_value(input));
247
+ jv ret = jv_number_negate(input);
258
248
  jv_free(input);
259
249
  return ret;
260
250
  }
@@ -294,37 +284,6 @@ static jv f_endswith(jq_state *jq, jv a, jv b) {
294
284
  return ret;
295
285
  }
296
286
 
297
- static jv f_ltrimstr(jq_state *jq, jv input, jv left) {
298
- jv startswith = f_startswith(jq, jv_copy(input), jv_copy(left));
299
- if (jv_get_kind(startswith) != JV_KIND_TRUE) {
300
- jv_free(startswith);
301
- jv_free(left);
302
- return input;
303
- }
304
- /*
305
- * FIXME It'd be better to share the suffix with the original input --
306
- * that we could do, we just can't share prefixes.
307
- */
308
- int prefixlen = jv_string_length_bytes(left);
309
- jv res = jv_string_sized(jv_string_value(input) + prefixlen,
310
- jv_string_length_bytes(jv_copy(input)) - prefixlen);
311
- jv_free(input);
312
- return res;
313
- }
314
-
315
- static jv f_rtrimstr(jq_state *jq, jv input, jv right) {
316
- jv endswith = f_endswith(jq, jv_copy(input), jv_copy(right));
317
- if (jv_get_kind(endswith) == JV_KIND_TRUE) {
318
- jv res = jv_string_sized(jv_string_value(input),
319
- jv_string_length_bytes(jv_copy(input)) - jv_string_length_bytes(right));
320
- jv_free(input);
321
- return res;
322
- }
323
- jv_free(endswith);
324
- jv_free(right);
325
- return input;
326
- }
327
-
328
287
  jv binop_minus(jv a, jv b) {
329
288
  if (jv_get_kind(a) == JV_KIND_NUMBER && jv_get_kind(b) == JV_KIND_NUMBER) {
330
289
  jv r = jv_number(jv_number_value(a) - jv_number_value(b));
@@ -369,21 +328,10 @@ jv binop_multiply(jv a, jv b) {
369
328
  str = b;
370
329
  num = a;
371
330
  }
372
- jv res;
373
331
  double d = jv_number_value(num);
374
- if (d < 0 || isnan(d)) {
375
- res = jv_null();
376
- } else {
377
- int n = d;
378
- size_t alen = jv_string_length_bytes(jv_copy(str));
379
- res = jv_string_empty(alen * n);
380
- for (; n > 0; n--) {
381
- res = jv_string_append_buf(res, jv_string_value(str), alen);
382
- }
383
- }
384
- jv_free(str);
385
332
  jv_free(num);
386
- return res;
333
+ return jv_string_repeat(str,
334
+ d < 0 || isnan(d) ? -1 : d > INT_MAX ? INT_MAX : (int)d);
387
335
  } else if (ak == JV_KIND_OBJECT && bk == JV_KIND_OBJECT) {
388
336
  return jv_object_merge_recursive(a, b);
389
337
  } else {
@@ -495,15 +443,43 @@ static jv f_tonumber(jq_state *jq, jv input) {
495
443
  return input;
496
444
  }
497
445
  if (jv_get_kind(input) == JV_KIND_STRING) {
498
- jv parsed = jv_parse(jv_string_value(input));
499
- if (!jv_is_valid(parsed) || jv_get_kind(parsed) == JV_KIND_NUMBER) {
500
- jv_free(input);
501
- return parsed;
446
+ const char* s = jv_string_value(input);
447
+ #ifdef USE_DECNUM
448
+ jv number = jv_number_with_literal(s);
449
+ if (jv_get_kind(number) == JV_KIND_INVALID) {
450
+ return type_error(input, "cannot be parsed as a number");
451
+ }
452
+ #else
453
+ char *end = 0;
454
+ double d = jvp_strtod(tsd_dtoa_context_get(), s, &end);
455
+ if (end == 0 || *end != 0) {
456
+ return type_error(input, "cannot be parsed as a number");
502
457
  }
458
+ jv number = jv_number(d);
459
+ #endif
460
+ jv_free(input);
461
+ return number;
503
462
  }
504
463
  return type_error(input, "cannot be parsed as a number");
505
464
  }
506
465
 
466
+ static jv f_toboolean(jq_state *jq, jv input) {
467
+ if (jv_get_kind(input) == JV_KIND_TRUE || jv_get_kind(input) == JV_KIND_FALSE) {
468
+ return input;
469
+ }
470
+ if (jv_get_kind(input) == JV_KIND_STRING) {
471
+ const char *s = jv_string_value(input);
472
+ if (strcmp(s, "true") == 0) {
473
+ jv_free(input);
474
+ return jv_true();
475
+ } else if (strcmp(s, "false") == 0) {
476
+ jv_free(input);
477
+ return jv_false();
478
+ }
479
+ }
480
+ return type_error(input, "cannot be parsed as a boolean");
481
+ }
482
+
507
483
  static jv f_length(jq_state *jq, jv input) {
508
484
  if (jv_get_kind(input) == JV_KIND_ARRAY) {
509
485
  return jv_number(jv_array_length(input));
@@ -512,7 +488,7 @@ static jv f_length(jq_state *jq, jv input) {
512
488
  } else if (jv_get_kind(input) == JV_KIND_STRING) {
513
489
  return jv_number(jv_string_length_codepoints(input));
514
490
  } else if (jv_get_kind(input) == JV_KIND_NUMBER) {
515
- jv r = jv_number(fabs(jv_number_value(input)));
491
+ jv r = jv_number_abs(input);
516
492
  jv_free(input);
517
493
  return r;
518
494
  } else if (jv_get_kind(input) == JV_KIND_NULL) {
@@ -675,6 +651,48 @@ static jv f_format(jq_state *jq, jv input, jv fmt) {
675
651
  }
676
652
  jv_free(input);
677
653
  return line;
654
+ } else if (!strcmp(fmt_s, "urid")) {
655
+ jv_free(fmt);
656
+ input = f_tostring(jq, input);
657
+
658
+ jv line = jv_string("");
659
+ const char *errmsg = "is not a valid uri encoding";
660
+ const char *s = jv_string_value(input);
661
+ while (*s) {
662
+ if (*s != '%') {
663
+ line = jv_string_append_buf(line, s++, 1);
664
+ } else {
665
+ unsigned char unicode[4] = {0};
666
+ int b = 0;
667
+ // check leading bits of first octet to determine length of unicode character
668
+ // (https://datatracker.ietf.org/doc/html/rfc3629#section-3)
669
+ while (b == 0 || (b < 4 && unicode[0] >> 7 & 1 && unicode[0] >> (7-b) & 1)) {
670
+ if (*(s++) != '%') {
671
+ jv_free(line);
672
+ return type_error(input, errmsg);
673
+ }
674
+ for (int i=0; i<2; i++) {
675
+ unicode[b] <<= 4;
676
+ char c = *(s++);
677
+ if ('0' <= c && c <= '9') unicode[b] |= c - '0';
678
+ else if ('a' <= c && c <= 'f') unicode[b] |= c - 'a' + 10;
679
+ else if ('A' <= c && c <= 'F') unicode[b] |= c - 'A' + 10;
680
+ else {
681
+ jv_free(line);
682
+ return type_error(input, errmsg);
683
+ }
684
+ }
685
+ b++;
686
+ }
687
+ if (!jvp_utf8_is_valid((const char *)unicode, (const char *)unicode+b)) {
688
+ jv_free(line);
689
+ return type_error(input, errmsg);
690
+ }
691
+ line = jv_string_append_buf(line, (const char *)unicode, b);
692
+ }
693
+ }
694
+ jv_free(input);
695
+ return line;
678
696
  } else if (!strcmp(fmt_s, "sh")) {
679
697
  jv_free(fmt);
680
698
  if (jv_get_kind(input) != JV_KIND_ARRAY)
@@ -733,9 +751,8 @@ static jv f_format(jq_state *jq, jv input, jv fmt) {
733
751
  input = f_tostring(jq, input);
734
752
  const unsigned char* data = (const unsigned char*)jv_string_value(input);
735
753
  int len = jv_string_length_bytes(jv_copy(input));
736
- size_t decoded_len = (3 * len) / 4; // 3 usable bytes for every 4 bytes of input
754
+ size_t decoded_len = MAX((3 * (size_t)len) / 4, (size_t)1); // 3 usable bytes for every 4 bytes of input
737
755
  char *result = jv_mem_calloc(decoded_len, sizeof(char));
738
- memset(result, 0, decoded_len * sizeof(char));
739
756
  uint32_t ri = 0;
740
757
  int input_bytes_read=0;
741
758
  uint32_t code = 0;
@@ -811,6 +828,40 @@ static jv f_sort_by_impl(jq_state *jq, jv input, jv keys) {
811
828
  }
812
829
  }
813
830
 
831
+ /*
832
+ * Assuming the input array is sorted, bsearch/1 returns
833
+ * the index of the target if the target is in the input array; and otherwise
834
+ * (-1 - ix), where ix is the insertion point that would leave the array sorted.
835
+ * If the input is not sorted, bsearch will terminate but with irrelevant results.
836
+ */
837
+ static jv f_bsearch(jq_state *jq, jv input, jv target) {
838
+ if (jv_get_kind(input) != JV_KIND_ARRAY) {
839
+ jv_free(target);
840
+ return type_error(input, "cannot be searched from");
841
+ }
842
+ int start = 0;
843
+ int end = jv_array_length(jv_copy(input));
844
+ jv answer = jv_invalid();
845
+ while (start < end) {
846
+ int mid = start + (end - start) / 2;
847
+ int result = jv_cmp(jv_copy(target), jv_array_get(jv_copy(input), mid));
848
+ if (result == 0) {
849
+ answer = jv_number(mid);
850
+ break;
851
+ } else if (result < 0) {
852
+ end = mid;
853
+ } else {
854
+ start = mid + 1;
855
+ }
856
+ }
857
+ if (!jv_is_valid(answer)) {
858
+ answer = jv_number(-1 - start);
859
+ }
860
+ jv_free(input);
861
+ jv_free(target);
862
+ return answer;
863
+ }
864
+
814
865
  static jv f_group_by_impl(jq_state *jq, jv input, jv keys) {
815
866
  if (jv_get_kind(input) == JV_KIND_ARRAY &&
816
867
  jv_get_kind(keys) == JV_KIND_ARRAY &&
@@ -821,6 +872,24 @@ static jv f_group_by_impl(jq_state *jq, jv input, jv keys) {
821
872
  }
822
873
  }
823
874
 
875
+ static jv f_unique(jq_state *jq, jv input) {
876
+ if (jv_get_kind(input) == JV_KIND_ARRAY) {
877
+ return jv_unique(input, jv_copy(input));
878
+ } else {
879
+ return type_error(input, "cannot be sorted, as it is not an array");
880
+ }
881
+ }
882
+
883
+ static jv f_unique_by_impl(jq_state *jq, jv input, jv keys) {
884
+ if (jv_get_kind(input) == JV_KIND_ARRAY &&
885
+ jv_get_kind(keys) == JV_KIND_ARRAY &&
886
+ jv_array_length(jv_copy(input)) == jv_array_length(jv_copy(keys))) {
887
+ return jv_unique(input, keys);
888
+ } else {
889
+ return type_error2(input, keys, "cannot be sorted, as they are not both arrays");
890
+ }
891
+ }
892
+
824
893
  #ifdef HAVE_LIBONIG
825
894
  static int f_match_name_iter(const UChar* name, const UChar *name_end, int ngroups,
826
895
  int *groups, regex_t *reg, void *arg) {
@@ -948,8 +1017,13 @@ static jv f_match(jq_state *jq, jv input, jv regex, jv modifiers, jv testmode) {
948
1017
  jv captures = jv_array();
949
1018
  for (int i = 1; i < region->num_regs; ++i) {
950
1019
  jv cap = jv_object();
951
- cap = jv_object_set(cap, jv_string("offset"), jv_number(idx));
952
- cap = jv_object_set(cap, jv_string("string"), jv_string(""));
1020
+ if (region->beg[i] == -1) {
1021
+ cap = jv_object_set(cap, jv_string("offset"), jv_number(-1));
1022
+ cap = jv_object_set(cap, jv_string("string"), jv_null());
1023
+ } else {
1024
+ cap = jv_object_set(cap, jv_string("offset"), jv_number(idx));
1025
+ cap = jv_object_set(cap, jv_string("string"), jv_string(""));
1026
+ }
953
1027
  cap = jv_object_set(cap, jv_string("length"), jv_number(0));
954
1028
  cap = jv_object_set(cap, jv_string("name"), jv_null());
955
1029
  captures = jv_array_append(captures, cap);
@@ -1215,6 +1289,58 @@ static jv f_string_indexes(jq_state *jq, jv a, jv b) {
1215
1289
  return jv_string_indexes(a, b);
1216
1290
  }
1217
1291
 
1292
+ enum trim_op {
1293
+ TRIM_LEFT = 1 << 0,
1294
+ TRIM_RIGHT = 1 << 1
1295
+ };
1296
+
1297
+ static jv string_trim(jv a, int op) {
1298
+ if (jv_get_kind(a) != JV_KIND_STRING) {
1299
+ return ret_error(a, jv_string("trim input must be a string"));
1300
+ }
1301
+
1302
+ int len = jv_string_length_bytes(jv_copy(a));
1303
+ const char *start = jv_string_value(a);
1304
+ const char *trim_start = start;
1305
+ const char *end = trim_start + len;
1306
+ const char *trim_end = end;
1307
+ int c;
1308
+
1309
+ if (op & TRIM_LEFT) {
1310
+ for (;;) {
1311
+ const char *ns = jvp_utf8_next(trim_start, end, &c);
1312
+ if (!ns || !jvp_codepoint_is_whitespace(c))
1313
+ break;
1314
+ trim_start = ns;
1315
+ }
1316
+ }
1317
+
1318
+ // make sure not empty string or start trim has trimmed everything
1319
+ if ((op & TRIM_RIGHT) && trim_end > trim_start) {
1320
+ for (;;) {
1321
+ const char *ns = jvp_utf8_backtrack(trim_end-1, trim_start, NULL);
1322
+ jvp_utf8_next(ns, trim_end, &c);
1323
+ if (!jvp_codepoint_is_whitespace(c))
1324
+ break;
1325
+ trim_end = ns;
1326
+ if (ns == trim_start)
1327
+ break;
1328
+ }
1329
+ }
1330
+
1331
+ // no new string needed if there is nothing to trim
1332
+ if (trim_start == start && trim_end == end)
1333
+ return a;
1334
+
1335
+ jv ts = jv_string_sized(trim_start, trim_end - trim_start);
1336
+ jv_free(a);
1337
+ return ts;
1338
+ }
1339
+
1340
+ static jv f_string_trim(jq_state *jq, jv a) { return string_trim(a, TRIM_LEFT | TRIM_RIGHT); }
1341
+ static jv f_string_ltrim(jq_state *jq, jv a) { return string_trim(a, TRIM_LEFT); }
1342
+ static jv f_string_rtrim(jq_state *jq, jv a) { return string_trim(a, TRIM_RIGHT); }
1343
+
1218
1344
  static jv f_string_implode(jq_state *jq, jv a) {
1219
1345
  if (jv_get_kind(a) != JV_KIND_ARRAY) {
1220
1346
  return ret_error(a, jv_string("implode input must be an array"));
@@ -1359,8 +1485,10 @@ static time_t my_mktime(struct tm *tm) {
1359
1485
  if (tz != NULL)
1360
1486
  setenv("TZ", "", 1);
1361
1487
  time_t t = mktime(tm);
1362
- if (tz != NULL)
1488
+ if (tz != NULL) {
1363
1489
  setenv("TZ", tz, 1);
1490
+ free(tz);
1491
+ }
1364
1492
  return t;
1365
1493
  #endif
1366
1494
  }
@@ -1431,16 +1559,11 @@ static jv f_strptime(jq_state *jq, jv a, jv b) {
1431
1559
  memset(&tm, 0, sizeof(tm));
1432
1560
  tm.tm_wday = 8; // sentinel
1433
1561
  tm.tm_yday = 367; // sentinel
1562
+
1434
1563
  const char *input = jv_string_value(a);
1435
1564
  const char *fmt = jv_string_value(b);
1436
-
1437
- #ifndef HAVE_STRPTIME
1438
- if (strcmp(fmt, "%Y-%m-%dT%H:%M:%SZ")) {
1439
- return ret_error2(a, b, jv_string("strptime/1 only supports ISO 8601 on this platform"));
1440
- }
1441
- #endif
1442
1565
  const char *end = strptime(input, fmt, &tm);
1443
- if (end == NULL || (*end != '\0' && !isspace(*end))) {
1566
+ if (end == NULL || (*end != '\0' && !isspace((unsigned char)*end))) {
1444
1567
  return ret_error2(a, b, jv_string_fmt("date \"%s\" does not match format \"%s\"", input, fmt));
1445
1568
  }
1446
1569
  jv_free(b);
@@ -1464,7 +1587,7 @@ static jv f_strptime(jq_state *jq, jv a, jv b) {
1464
1587
  */
1465
1588
  set_tm_wday(&tm);
1466
1589
  set_tm_yday(&tm);
1467
- #elif defined(WIN32)
1590
+ #elif defined(WIN32) || !defined(HAVE_STRPTIME)
1468
1591
  set_tm_wday(&tm);
1469
1592
  #else
1470
1593
  if (tm.tm_wday == 8 && tm.tm_mday != 0 && tm.tm_mon >= 0 && tm.tm_mon <= 11)
@@ -1479,39 +1602,57 @@ static jv f_strptime(jq_state *jq, jv a, jv b) {
1479
1602
  return r;
1480
1603
  }
1481
1604
 
1482
- #define TO_TM_FIELD(t, j, i) \
1483
- do { \
1484
- jv n = jv_array_get(jv_copy(j), (i)); \
1485
- if (jv_get_kind(n) != (JV_KIND_NUMBER)) { \
1486
- jv_free(n); \
1487
- jv_free(j); \
1488
- return 0; \
1489
- } \
1490
- t = jv_number_value(n); \
1491
- jv_free(n); \
1492
- } while (0)
1493
-
1494
- static int jv2tm(jv a, struct tm *tm) {
1605
+ static int jv2tm(jv a, struct tm *tm, int localtime) {
1495
1606
  memset(tm, 0, sizeof(*tm));
1496
- TO_TM_FIELD(tm->tm_year, a, 0);
1497
- tm->tm_year -= 1900;
1498
- TO_TM_FIELD(tm->tm_mon, a, 1);
1499
- TO_TM_FIELD(tm->tm_mday, a, 2);
1500
- TO_TM_FIELD(tm->tm_hour, a, 3);
1501
- TO_TM_FIELD(tm->tm_min, a, 4);
1502
- TO_TM_FIELD(tm->tm_sec, a, 5);
1503
- TO_TM_FIELD(tm->tm_wday, a, 6);
1504
- TO_TM_FIELD(tm->tm_yday, a, 7);
1505
- jv_free(a);
1607
+ static const size_t offsets[] = {
1608
+ offsetof(struct tm, tm_year),
1609
+ offsetof(struct tm, tm_mon),
1610
+ offsetof(struct tm, tm_mday),
1611
+ offsetof(struct tm, tm_hour),
1612
+ offsetof(struct tm, tm_min),
1613
+ offsetof(struct tm, tm_sec),
1614
+ offsetof(struct tm, tm_wday),
1615
+ offsetof(struct tm, tm_yday),
1616
+ };
1617
+
1618
+ for (size_t i = 0; i < (sizeof offsets / sizeof *offsets); ++i) {
1619
+ jv n = jv_array_get(jv_copy(a), i);
1620
+ if (!jv_is_valid(n))
1621
+ break;
1622
+ if (jv_get_kind(n) != JV_KIND_NUMBER || jvp_number_is_nan(n)) {
1623
+ jv_free(a);
1624
+ jv_free(n);
1625
+ return 0;
1626
+ }
1627
+ double d = jv_number_value(n);
1628
+ if (i == 0) /* year */
1629
+ d -= 1900;
1630
+ *(int *)((void *)tm + offsets[i]) = d < INT_MIN ? INT_MIN :
1631
+ d > INT_MAX ? INT_MAX : (int)d;
1632
+ jv_free(n);
1633
+ }
1506
1634
 
1507
- // We use UTC everywhere (gettimeofday, gmtime) and UTC does not do DST.
1508
- // Setting tm_isdst to 0 is done by the memset.
1509
- // tm->tm_isdst = 0;
1635
+ if (localtime) {
1636
+ tm->tm_isdst = -1;
1637
+ mktime(tm);
1638
+ } else {
1639
+ #ifdef HAVE_TIMEGM
1640
+ timegm(tm);
1641
+ #elif HAVE_TM_TM_GMT_OFF
1642
+ // tm->tm_gmtoff = 0;
1643
+ tm->tm_zone = "GMT";
1644
+ #elif HAVE_TM___TM_GMT_OFF
1645
+ // tm->__tm_gmtoff = 0;
1646
+ tm->__tm_zone = "GMT";
1647
+ #endif
1648
+ // tm->tm_isdst = 0;
1510
1649
 
1511
- // The standard permits the tm structure to contain additional members. We
1512
- // hope it is okay to initialize them to zero, because the standard does not
1513
- // provide an alternative.
1650
+ // The standard permits the tm structure to contain additional members. We
1651
+ // hope it is okay to initialize them to zero, because the standard does not
1652
+ // provide an alternative.
1653
+ }
1514
1654
 
1655
+ jv_free(a);
1515
1656
  return 1;
1516
1657
  }
1517
1658
 
@@ -1520,10 +1661,8 @@ static int jv2tm(jv a, struct tm *tm) {
1520
1661
  static jv f_mktime(jq_state *jq, jv a) {
1521
1662
  if (jv_get_kind(a) != JV_KIND_ARRAY)
1522
1663
  return ret_error(a, jv_string("mktime requires array inputs"));
1523
- if (jv_array_length(jv_copy(a)) < 6)
1524
- return ret_error(a, jv_string("mktime requires parsed datetime inputs"));
1525
1664
  struct tm tm;
1526
- if (!jv2tm(a, &tm))
1665
+ if (!jv2tm(a, &tm, 0))
1527
1666
  return jv_invalid_with_msg(jv_string("mktime requires parsed datetime inputs"));
1528
1667
  time_t t = my_mktime(&tm);
1529
1668
  if (t == (time_t)-1)
@@ -1617,22 +1756,42 @@ static jv f_strftime(jq_state *jq, jv a, jv b) {
1617
1756
  }
1618
1757
  } else if (jv_get_kind(a) != JV_KIND_ARRAY) {
1619
1758
  return ret_error2(a, b, jv_string("strftime/1 requires parsed datetime inputs"));
1620
- } else if (jv_get_kind(b) != JV_KIND_STRING) {
1621
- return ret_error2(a, b, jv_string("strftime/1 requires a string format"));
1622
1759
  }
1760
+ if (jv_get_kind(b) != JV_KIND_STRING)
1761
+ return ret_error2(a, b, jv_string("strftime/1 requires a string format"));
1623
1762
  struct tm tm;
1624
- if (!jv2tm(a, &tm))
1763
+ if (!jv2tm(a, &tm, 0))
1625
1764
  return ret_error(b, jv_string("strftime/1 requires parsed datetime inputs"));
1626
1765
 
1627
1766
  const char *fmt = jv_string_value(b);
1628
- size_t alloced = strlen(fmt) + 100;
1629
- char *buf = alloca(alloced);
1630
- size_t n = strftime(buf, alloced, fmt, &tm);
1767
+ int fmt_not_empty = *fmt != '\0';
1768
+ size_t max_size = strlen(fmt) + 100;
1769
+ char *buf = jv_mem_alloc(max_size);
1770
+ #ifdef __APPLE__
1771
+ /* Apple Libc (as of version 1669.40.2) contains a bug which causes it to
1772
+ * ignore the `tm.tm_gmtoff` in favor of the global timezone. To print the
1773
+ * proper timezone offset we temporarily switch the TZ to UTC. */
1774
+ char *tz = (tz = getenv("TZ")) != NULL ? strdup(tz) : NULL;
1775
+ setenv("TZ", "UTC", 1);
1776
+ #endif
1777
+ size_t n = strftime(buf, max_size, fmt, &tm);
1778
+ #ifdef __APPLE__
1779
+ if (tz) {
1780
+ setenv("TZ", tz, 1);
1781
+ free(tz);
1782
+ } else {
1783
+ unsetenv("TZ");
1784
+ }
1785
+ #endif
1631
1786
  jv_free(b);
1632
1787
  /* POSIX doesn't provide errno values for strftime() failures; weird */
1633
- if (n == 0 || n > alloced)
1788
+ if ((n == 0 && fmt_not_empty) || n > max_size) {
1789
+ free(buf);
1634
1790
  return jv_invalid_with_msg(jv_string("strftime/1: unknown system failure"));
1635
- return jv_string(buf);
1791
+ }
1792
+ jv ret = jv_string_sized(buf, n);
1793
+ free(buf);
1794
+ return ret;
1636
1795
  }
1637
1796
  #else
1638
1797
  static jv f_strftime(jq_state *jq, jv a, jv b) {
@@ -1648,21 +1807,26 @@ static jv f_strflocaltime(jq_state *jq, jv a, jv b) {
1648
1807
  a = f_localtime(jq, a);
1649
1808
  } else if (jv_get_kind(a) != JV_KIND_ARRAY) {
1650
1809
  return ret_error2(a, b, jv_string("strflocaltime/1 requires parsed datetime inputs"));
1651
- } else if (jv_get_kind(b) != JV_KIND_STRING) {
1652
- return ret_error2(a, b, jv_string("strflocaltime/1 requires a string format"));
1653
1810
  }
1811
+ if (jv_get_kind(b) != JV_KIND_STRING)
1812
+ return ret_error2(a, b, jv_string("strflocaltime/1 requires a string format"));
1654
1813
  struct tm tm;
1655
- if (!jv2tm(a, &tm))
1814
+ if (!jv2tm(a, &tm, 1))
1656
1815
  return ret_error(b, jv_string("strflocaltime/1 requires parsed datetime inputs"));
1657
1816
  const char *fmt = jv_string_value(b);
1658
- size_t alloced = strlen(fmt) + 100;
1659
- char *buf = alloca(alloced);
1660
- size_t n = strftime(buf, alloced, fmt, &tm);
1817
+ int fmt_not_empty = *fmt != '\0';
1818
+ size_t max_size = strlen(fmt) + 100;
1819
+ char *buf = jv_mem_alloc(max_size);
1820
+ size_t n = strftime(buf, max_size, fmt, &tm);
1661
1821
  jv_free(b);
1662
1822
  /* POSIX doesn't provide errno values for strftime() failures; weird */
1663
- if (n == 0 || n > alloced)
1823
+ if ((n == 0 && fmt_not_empty) || n > max_size) {
1824
+ free(buf);
1664
1825
  return jv_invalid_with_msg(jv_string("strflocaltime/1: unknown system failure"));
1665
- return jv_string(buf);
1826
+ }
1827
+ jv ret = jv_string_sized(buf, n);
1828
+ free(buf);
1829
+ return ret;
1666
1830
  }
1667
1831
  #else
1668
1832
  static jv f_strflocaltime(jq_state *jq, jv a, jv b) {
@@ -1701,96 +1865,137 @@ static jv f_current_line(jq_state *jq, jv a) {
1701
1865
  return jq_util_input_get_current_line(jq);
1702
1866
  }
1703
1867
 
1868
+ static jv f_have_decnum(jq_state *jq, jv a) {
1869
+ jv_free(a);
1870
+ #ifdef USE_DECNUM
1871
+ return jv_true();
1872
+ #else
1873
+ return jv_false();
1874
+ #endif
1875
+ }
1876
+
1877
+ #define CFUNC(func, name, arity) \
1878
+ {.fptr = { .a ## arity = func }, name, arity}
1879
+
1704
1880
  #define LIBM_DD(name) \
1705
- {f_ ## name, #name, 1},
1706
- #define LIBM_DD_NO(name)
1881
+ CFUNC(f_ ## name, #name, 1),
1882
+ #define LIBM_DD_NO(name) LIBM_DD(name)
1883
+ #define LIBM_DA(name, type) LIBM_DD(name)
1884
+ #define LIBM_DA_NO(name, type) LIBM_DD(name)
1707
1885
 
1708
1886
  #define LIBM_DDD(name) \
1709
- {f_ ## name, #name, 3},
1710
- #define LIBM_DDD_NO(name)
1887
+ CFUNC(f_ ## name, #name, 3),
1888
+ #define LIBM_DDD_NO(name) LIBM_DDD(name)
1711
1889
 
1712
1890
  #define LIBM_DDDD(name) \
1713
- {f_ ## name, #name, 4},
1714
- #define LIBM_DDDD_NO(name)
1891
+ CFUNC(f_ ## name, #name, 4),
1892
+ #define LIBM_DDDD_NO(name) LIBM_DDDD(name)
1715
1893
 
1716
1894
  static const struct cfunction function_list[] = {
1717
1895
  #include "libm.h"
1718
- #ifdef HAVE_FREXP
1719
- {f_frexp,"frexp", 1},
1720
- #endif
1721
- #ifdef HAVE_MODF
1722
- {f_modf,"modf", 1},
1723
- #endif
1724
- #ifdef HAVE_LGAMMA_R
1725
- {f_lgamma_r,"lgamma_r", 1},
1726
- #endif
1727
- {f_negate, "_negate", 1},
1728
- #define BINOP(name) {f_ ## name, "_" #name, 3},
1896
+ CFUNC(f_negate, "_negate", 1),
1897
+ #define BINOP(name) CFUNC(f_ ## name, "_" #name, 3),
1729
1898
  BINOPS
1730
1899
  #undef BINOP
1731
- {f_dump, "tojson", 1},
1732
- {f_json_parse, "fromjson", 1},
1733
- {f_tonumber, "tonumber", 1},
1734
- {f_tostring, "tostring", 1},
1735
- {f_keys, "keys", 1},
1736
- {f_keys_unsorted, "keys_unsorted", 1},
1737
- {f_startswith, "startswith", 2},
1738
- {f_endswith, "endswith", 2},
1739
- {f_ltrimstr, "ltrimstr", 2},
1740
- {f_rtrimstr, "rtrimstr", 2},
1741
- {f_string_split, "split", 2},
1742
- {f_string_explode, "explode", 1},
1743
- {f_string_implode, "implode", 1},
1744
- {f_string_indexes, "_strindices", 2},
1745
- {f_setpath, "setpath", 3}, // FIXME typechecking
1746
- {f_getpath, "getpath", 2},
1747
- {f_delpaths, "delpaths", 2},
1748
- {f_has, "has", 2},
1749
- {f_contains, "contains", 2},
1750
- {f_length, "length", 1},
1751
- {f_utf8bytelength, "utf8bytelength", 1},
1752
- {f_type, "type", 1},
1753
- {f_isinfinite, "isinfinite", 1},
1754
- {f_isnan, "isnan", 1},
1755
- {f_isnormal, "isnormal", 1},
1756
- {f_infinite, "infinite", 1},
1757
- {f_nan, "nan", 1},
1758
- {f_sort, "sort", 1},
1759
- {f_sort_by_impl, "_sort_by_impl", 2},
1760
- {f_group_by_impl, "_group_by_impl", 2},
1761
- {f_min, "min", 1},
1762
- {f_max, "max", 1},
1763
- {f_min_by_impl, "_min_by_impl", 2},
1764
- {f_max_by_impl, "_max_by_impl", 2},
1765
- {f_error, "error", 1},
1766
- {f_format, "format", 2},
1767
- {f_env, "env", 1},
1768
- {f_halt, "halt", 1},
1769
- {f_halt_error, "halt_error", 2},
1770
- {f_get_search_list, "get_search_list", 1},
1771
- {f_get_prog_origin, "get_prog_origin", 1},
1772
- {f_get_jq_origin, "get_jq_origin", 1},
1773
- {f_match, "_match_impl", 4},
1774
- {f_modulemeta, "modulemeta", 1},
1775
- {f_input, "input", 1},
1776
- {f_debug, "debug", 1},
1777
- {f_stderr, "stderr", 1},
1778
- {f_strptime, "strptime", 2},
1779
- {f_strftime, "strftime", 2},
1780
- {f_strflocaltime, "strflocaltime", 2},
1781
- {f_mktime, "mktime", 1},
1782
- {f_gmtime, "gmtime", 1},
1783
- {f_localtime, "localtime", 1},
1784
- {f_now, "now", 1},
1785
- {f_current_filename, "input_filename", 1},
1786
- {f_current_line, "input_line_number", 1},
1900
+ CFUNC(f_dump, "tojson", 1),
1901
+ CFUNC(f_json_parse, "fromjson", 1),
1902
+ CFUNC(f_tonumber, "tonumber", 1),
1903
+ CFUNC(f_toboolean, "toboolean", 1),
1904
+ CFUNC(f_tostring, "tostring", 1),
1905
+ CFUNC(f_keys, "keys", 1),
1906
+ CFUNC(f_keys_unsorted, "keys_unsorted", 1),
1907
+ CFUNC(f_startswith, "startswith", 2),
1908
+ CFUNC(f_endswith, "endswith", 2),
1909
+ CFUNC(f_string_split, "split", 2),
1910
+ CFUNC(f_string_explode, "explode", 1),
1911
+ CFUNC(f_string_implode, "implode", 1),
1912
+ CFUNC(f_string_indexes, "_strindices", 2),
1913
+ CFUNC(f_string_trim, "trim", 1),
1914
+ CFUNC(f_string_ltrim, "ltrim", 1),
1915
+ CFUNC(f_string_rtrim, "rtrim", 1),
1916
+ CFUNC(f_setpath, "setpath", 3),
1917
+ CFUNC(f_getpath, "getpath", 2),
1918
+ CFUNC(f_delpaths, "delpaths", 2),
1919
+ CFUNC(f_has, "has", 2),
1920
+ CFUNC(f_contains, "contains", 2),
1921
+ CFUNC(f_length, "length", 1),
1922
+ CFUNC(f_utf8bytelength, "utf8bytelength", 1),
1923
+ CFUNC(f_type, "type", 1),
1924
+ CFUNC(f_isinfinite, "isinfinite", 1),
1925
+ CFUNC(f_isnan, "isnan", 1),
1926
+ CFUNC(f_isnormal, "isnormal", 1),
1927
+ CFUNC(f_infinite, "infinite", 1),
1928
+ CFUNC(f_nan, "nan", 1),
1929
+ CFUNC(f_sort, "sort", 1),
1930
+ CFUNC(f_sort_by_impl, "_sort_by_impl", 2),
1931
+ CFUNC(f_group_by_impl, "_group_by_impl", 2),
1932
+ CFUNC(f_unique, "unique", 1),
1933
+ CFUNC(f_unique_by_impl, "_unique_by_impl", 2),
1934
+ CFUNC(f_bsearch, "bsearch", 2),
1935
+ CFUNC(f_min, "min", 1),
1936
+ CFUNC(f_max, "max", 1),
1937
+ CFUNC(f_min_by_impl, "_min_by_impl", 2),
1938
+ CFUNC(f_max_by_impl, "_max_by_impl", 2),
1939
+ CFUNC(f_error, "error", 1),
1940
+ CFUNC(f_format, "format", 2),
1941
+ CFUNC(f_env, "env", 1),
1942
+ CFUNC(f_halt, "halt", 1),
1943
+ CFUNC(f_halt_error, "halt_error", 2),
1944
+ CFUNC(f_get_search_list, "get_search_list", 1),
1945
+ CFUNC(f_get_prog_origin, "get_prog_origin", 1),
1946
+ CFUNC(f_get_jq_origin, "get_jq_origin", 1),
1947
+ CFUNC(f_match, "_match_impl", 4),
1948
+ CFUNC(f_modulemeta, "modulemeta", 1),
1949
+ CFUNC(f_input, "input", 1),
1950
+ CFUNC(f_debug, "debug", 1),
1951
+ CFUNC(f_stderr, "stderr", 1),
1952
+ CFUNC(f_strptime, "strptime", 2),
1953
+ CFUNC(f_strftime, "strftime", 2),
1954
+ CFUNC(f_strflocaltime, "strflocaltime", 2),
1955
+ CFUNC(f_mktime, "mktime", 1),
1956
+ CFUNC(f_gmtime, "gmtime", 1),
1957
+ CFUNC(f_localtime, "localtime", 1),
1958
+ CFUNC(f_now, "now", 1),
1959
+ CFUNC(f_current_filename, "input_filename", 1),
1960
+ CFUNC(f_current_line, "input_line_number", 1),
1961
+ CFUNC(f_have_decnum, "have_decnum", 1),
1962
+ CFUNC(f_have_decnum, "have_literal_numbers", 1),
1787
1963
  };
1788
1964
  #undef LIBM_DDDD_NO
1789
1965
  #undef LIBM_DDD_NO
1790
1966
  #undef LIBM_DD_NO
1967
+ #undef LIBM_DA_NO
1791
1968
  #undef LIBM_DDDD
1792
1969
  #undef LIBM_DDD
1793
1970
  #undef LIBM_DD
1971
+ #undef LIBM_DA
1972
+
1973
+ // This is a hack to make last(g) yield no output values,
1974
+ // if g yields no output values, without using boxing.
1975
+ static block gen_last_1(void) {
1976
+ block last_var = gen_op_var_fresh(STOREV, "last");
1977
+ block is_empty_var = gen_op_var_fresh(STOREV, "is_empty");
1978
+ block init = BLOCK(gen_op_simple(DUP),
1979
+ gen_const(jv_null()),
1980
+ last_var,
1981
+ gen_op_simple(DUP),
1982
+ gen_const(jv_true()),
1983
+ is_empty_var);
1984
+ block call_arg = BLOCK(gen_call("arg", gen_noop()),
1985
+ gen_op_simple(DUP),
1986
+ gen_op_bound(STOREV, last_var),
1987
+ gen_const(jv_false()),
1988
+ gen_op_bound(STOREV, is_empty_var),
1989
+ gen_op_simple(BACKTRACK));
1990
+ block if_empty = gen_op_simple(BACKTRACK);
1991
+ return BLOCK(init,
1992
+ gen_op_target(FORK, call_arg),
1993
+ call_arg,
1994
+ BLOCK(gen_op_bound(LOADVN, is_empty_var),
1995
+ gen_op_target(JUMP_F, if_empty),
1996
+ if_empty,
1997
+ gen_op_bound(LOADVN, last_var)));
1998
+ }
1794
1999
 
1795
2000
  struct bytecoded_builtin { const char* name; block code; };
1796
2001
  static block bind_bytecoded_builtins(block b) {
@@ -1811,6 +2016,7 @@ static block bind_bytecoded_builtins(block b) {
1811
2016
  {"path", BLOCK(gen_op_simple(PATH_BEGIN),
1812
2017
  gen_call("arg", gen_noop()),
1813
2018
  gen_op_simple(PATH_END))},
2019
+ {"last", gen_last_1()},
1814
2020
  };
1815
2021
  for (unsigned i=0; i<sizeof(builtin_def_1arg)/sizeof(builtin_def_1arg[0]); i++) {
1816
2022
  builtins = BLOCK(builtins, gen_function(builtin_def_1arg[i].name,
@@ -1838,42 +2044,11 @@ static block bind_bytecoded_builtins(block b) {
1838
2044
  return BLOCK(builtins, b);
1839
2045
  }
1840
2046
 
1841
- static const char jq_builtins[] =
2047
+ static const char jq_builtins[] = {
1842
2048
  /* Include jq-coded builtins */
1843
2049
  #include "src/builtin.inc"
1844
-
1845
- /* Include unsupported math functions next */
1846
- #define LIBM_DD(name)
1847
- #define LIBM_DDD(name)
1848
- #define LIBM_DDDD(name)
1849
- #define LIBM_DD_NO(name) "def " #name ": \"Error: " #name "/0 not found at build time\"|error;"
1850
- #define LIBM_DDD_NO(name) "def " #name "(a;b): \"Error: " #name "/2 not found at build time\"|error;"
1851
- #define LIBM_DDDD_NO(name) "def " #name "(a;b;c): \"Error: " #name "/3 not found at build time\"|error;"
1852
- #include "libm.h"
1853
- #ifndef HAVE_FREXP
1854
- "def frexp: \"Error: frexp/0 not found at build time\"|error;"
1855
- #endif
1856
- #ifndef HAVE_MODF
1857
- "def modf: \"Error: modf/0 not found at build time\"|error;"
1858
- #endif
1859
- #ifndef HAVE_LGAMMA_R
1860
- "def lgamma_r: \"Error: lgamma_r/0 not found at build time\"|error;"
1861
- #endif
1862
- ;
1863
-
1864
- #undef LIBM_DDDD_NO
1865
- #undef LIBM_DDD_NO
1866
- #undef LIBM_DD_NO
1867
- #undef LIBM_DDDD
1868
- #undef LIBM_DDD
1869
- #undef LIBM_DD
1870
-
1871
- #ifdef __APPLE__
1872
- #undef HAVE_GAMMA
1873
- #undef HAVE_EXP10
1874
- #undef HAVE_DREM
1875
- #undef HAVE_SIGNIFICAND
1876
- #endif
2050
+ '\0',
2051
+ };
1877
2052
 
1878
2053
  static block gen_builtin_list(block builtins) {
1879
2054
  jv list = jv_array_append(block_list_funcs(builtins, 1), jv_string("builtins/0"));