@poe-platform/safe-bash 0.1.799 → 0.1.800
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.
- package/README.md +32 -17
- package/dist/image-ast/index.browser.js +1384 -23
- package/dist/image-ast/index.js +1384 -23
- package/dist/mp4-ast/types.d.ts +1 -0
- package/dist/office-package/zip.d.ts +2 -0
- package/dist/office-package/zip.js +1 -1
- package/dist/pdf-ast/index.js +1 -1
- package/dist/safe-bash/chunks/{chunk-IUTD5FH5.js → chunk-46UISJCK.js} +1 -6
- package/dist/safe-bash/chunks/chunk-4SEW2Q6H.js +26 -0
- package/dist/safe-bash/chunks/{chunk-AKC46AF6.js → chunk-7YSRXFEG.js} +7 -40
- package/dist/safe-bash/chunks/{chunk-KTGR4U57.js → chunk-BHJE5LPZ.js} +1 -2
- package/dist/safe-bash/chunks/{chunk-TRVGCN3U.js → chunk-HHW7MGS2.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-ZNAFMYIA.js → chunk-I7L3G3NX.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-KMH2DF3I.js → chunk-JJSTTIEZ.js} +6 -1
- package/dist/safe-bash/chunks/{chunk-6IBTC4YL.js → chunk-JTLSUJ7V.js} +57 -20
- package/dist/safe-bash/chunks/chunk-K2VCOJ2B.js +111 -0
- package/dist/safe-bash/chunks/chunk-K4YMYFRJ.js +9802 -0
- package/dist/safe-bash/chunks/{chunk-SPYL72GN.js → chunk-KW24TAIU.js} +446 -5519
- package/dist/safe-bash/chunks/{chunk-ENR3HB2B.js → chunk-NLAW7KDI.js} +0 -1
- package/dist/safe-bash/chunks/{chunk-B3DDEDH2.js → chunk-PPYM75Z3.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-NX2SQVON.js → chunk-RKKRJ54E.js} +19 -7
- package/dist/safe-bash/chunks/{chunk-WUNK5NXJ.js → chunk-RMWLWH7Q.js} +870 -953
- package/dist/safe-bash/chunks/{chunk-JSVX4VIA.js → chunk-TFGRKY43.js} +2 -1
- package/dist/safe-bash/chunks/{chunk-T5KKDMYB.js → chunk-TYD7EVUJ.js} +6 -0
- package/dist/safe-bash/chunks/{csvkit-W2UEKH6P.js → csvkit-QGP3GAOB.js} +1 -1
- package/dist/safe-bash/chunks/{ffmpeg-42CGASMV.js → ffmpeg-JTVH26MK.js} +1 -1
- package/dist/safe-bash/chunks/{gh-26GYLH6D.js → gh-I7QX7N5C.js} +1 -1
- package/dist/safe-bash/chunks/{git-YREKMUVD.js → git-MA7NKYVP.js} +1 -1
- package/dist/safe-bash/chunks/{imagemagick-3YIX4XO2.js → imagemagick-Y4NPWX2Q.js} +1 -1
- package/dist/safe-bash/chunks/{implementation-E3YMKU3Z.js → implementation-BWDKOVQJ.js} +1 -1
- package/dist/safe-bash/chunks/mmdc-44PELHDG.js +118 -0
- package/dist/safe-bash/chunks/{pdfimages-UE2UISP2.js → pdfimages-635TRW4Q.js} +1 -1
- package/dist/safe-bash/chunks/{pdfinfo-RGARKLI5.js → pdfinfo-FSDAA2KY.js} +3 -11
- package/dist/safe-bash/chunks/{pdftk-JY3WVCCC.js → pdftk-GQ5UH3VG.js} +1 -1
- package/dist/safe-bash/chunks/{pdftoppm-GPD3BMPY.js → pdftoppm-YTXQCAYT.js} +1 -1
- package/dist/safe-bash/chunks/{pdftotext-K7GQ2QJZ.js → pdftotext-CVA2G7FY.js} +1 -1
- package/dist/safe-bash/chunks/{qpdf-F4U7WUSU.js → qpdf-HZMIFG4A.js} +1 -1
- package/dist/safe-bash/chunks/{sips-RWENS7X5.js → sips-E7UBDP33.js} +1 -1
- package/dist/safe-bash/chunks/{soffice-IT6W2C5F.js → soffice-ELASUWUK.js} +1 -1
- package/dist/safe-bash/chunks/{wkhtmltopdf-JYNDAHIZ.js → wkhtmltopdf-EPO6YCMG.js} +1 -1
- package/dist/safe-bash/command-chunks/chunk-2FGJYFWZ.js +44 -0
- package/dist/safe-bash/command-chunks/chunk-2H4JTFIL.js +53 -0
- package/dist/safe-bash/command-chunks/{chunk-LLCXZKZ6.js → chunk-2QHG43WJ.js} +2 -2
- package/dist/safe-bash/command-chunks/chunk-364TMWBT.js +946 -0
- package/dist/safe-bash/command-chunks/{chunk-EIVW3X3N.js → chunk-3DT2YOGW.js} +11 -6
- package/dist/safe-bash/command-chunks/chunk-3E2OIS2J.js +7037 -0
- package/dist/safe-bash/command-chunks/{chunk-AIRGA2SU.js → chunk-3HXDA5PT.js} +1 -1
- package/dist/safe-bash/command-chunks/chunk-3LSOYLNV.js +1091 -0
- package/dist/safe-bash/command-chunks/chunk-4B7Y7S6E.js +61 -0
- package/dist/safe-bash/command-chunks/{chunk-HRLIAMXC.js → chunk-4C6QI5BQ.js} +3 -2
- package/dist/safe-bash/command-chunks/chunk-4ZHMW6F5.js +104 -0
- package/dist/safe-bash/command-chunks/{chunk-4ZALPDBV.js → chunk-53P53XFM.js} +2 -2
- package/dist/safe-bash/command-chunks/chunk-5LSGEIZY.js +379 -0
- package/dist/safe-bash/command-chunks/{chunk-MKQVQMXO.js → chunk-5LU4UCBR.js} +1 -1
- package/dist/safe-bash/command-chunks/chunk-5T7CRJHW.js +560 -0
- package/dist/safe-bash/command-chunks/chunk-5TBUOBDE.js +346 -0
- package/dist/safe-bash/command-chunks/chunk-5XY4DTNG.js +34 -0
- package/dist/safe-bash/command-chunks/chunk-5ZMZ573Q.js +140 -0
- package/dist/safe-bash/command-chunks/{chunk-OPUJSTHS.js → chunk-67IQF5GC.js} +200 -66
- package/dist/safe-bash/command-chunks/chunk-67QKREJK.js +347 -0
- package/dist/safe-bash/command-chunks/chunk-6EPHJGGF.js +23 -0
- package/dist/safe-bash/command-chunks/chunk-6F4XCVON.js +266 -0
- package/dist/safe-bash/command-chunks/{chunk-ESMCX3YV.js → chunk-6HMX4CQS.js} +669 -130
- package/dist/safe-bash/command-chunks/chunk-7K6JYKPJ.js +422 -0
- package/dist/safe-bash/command-chunks/chunk-7N2LI2KO.js +206 -0
- package/dist/safe-bash/command-chunks/chunk-7RGB363W.js +362 -0
- package/dist/safe-bash/command-chunks/{pptx-GBPNWNEP-7EQEVXV5.js → chunk-AI5JAXQF.js} +34820 -18029
- package/dist/safe-bash/command-chunks/chunk-AMO3THU4.js +105 -0
- package/dist/safe-bash/command-chunks/chunk-BAGCY35S.js +231 -0
- package/dist/safe-bash/command-chunks/chunk-BAXU7B5Z.js +101 -0
- package/dist/safe-bash/command-chunks/{chunk-KMCZ6P4O.js → chunk-BKCNF5U3.js} +68 -7
- package/dist/safe-bash/command-chunks/chunk-BNOU5YQS.js +182 -0
- package/dist/safe-bash/command-chunks/chunk-C7I25AAL.js +25 -0
- package/dist/safe-bash/command-chunks/chunk-CKXV2CLD.js +65 -0
- package/dist/safe-bash/command-chunks/chunk-CQ5YGOGB.js +150 -0
- package/dist/safe-bash/command-chunks/{chunk-I3K5RYU4.js → chunk-D4OP2BR3.js} +72 -24
- package/dist/safe-bash/command-chunks/chunk-DB453IE6.js +122 -0
- package/dist/safe-bash/command-chunks/chunk-DOKKNRRM.js +87 -0
- package/dist/safe-bash/command-chunks/{chunk-2PX5B7T5.js → chunk-DQAVUDDX.js} +2 -2
- package/dist/safe-bash/command-chunks/chunk-DT7BCTWY.js +249 -0
- package/dist/safe-bash/command-chunks/chunk-E2LB7FRT.js +42 -0
- package/dist/safe-bash/command-chunks/chunk-EK6YNAXT.js +343 -0
- package/dist/safe-bash/command-chunks/chunk-EQ4HV54N.js +22 -0
- package/dist/safe-bash/command-chunks/chunk-ERYJLO6G.js +293 -0
- package/dist/safe-bash/command-chunks/{chunk-4ONEXMD3.js → chunk-EUSPTFAX.js} +1 -1
- package/dist/safe-bash/command-chunks/chunk-FKKB5X5V.js +97 -0
- package/dist/safe-bash/command-chunks/chunk-FXELCPFX.js +195 -0
- package/dist/safe-bash/command-chunks/{chunk-JCNNOMBV.js → chunk-GI4CJED2.js} +3 -2
- package/dist/safe-bash/command-chunks/{chunk-CU5RLO62.js → chunk-GLOZX57Y.js} +92 -18
- package/dist/safe-bash/command-chunks/chunk-GMIHJYDG.js +331 -0
- package/dist/safe-bash/command-chunks/chunk-H622NS6Z.js +11 -0
- package/dist/safe-bash/command-chunks/{chunk-UI32HWGS.js → chunk-HMOZ6XVJ.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-AVSPNLWV.js → chunk-I237SNW5.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-ZS3QPNUL.js → chunk-IR2BY7EL.js} +21 -6
- package/dist/safe-bash/command-chunks/chunk-IYPAQ7PH.js +42 -0
- package/dist/safe-bash/command-chunks/chunk-JN7WIP6S.js +94 -0
- package/dist/safe-bash/command-chunks/chunk-JNZ3CVAE.js +147 -0
- package/dist/safe-bash/command-chunks/{chunk-HLBX5IRS.js → chunk-JQ74HC37.js} +24 -32
- package/dist/safe-bash/command-chunks/chunk-KFVV7ZJO.js +216 -0
- package/dist/safe-bash/command-chunks/{chunk-G4PNVO6Z.js → chunk-KP7AO66M.js} +1 -1
- package/dist/safe-bash/command-chunks/chunk-KWESKQHR.js +25 -0
- package/dist/safe-bash/command-chunks/chunk-KYSPGS33.js +41 -0
- package/dist/safe-bash/command-chunks/{chunk-C7IHMJEW.js → chunk-KZC5UWFF.js} +2 -2
- package/dist/safe-bash/command-chunks/chunk-L6DVEBW3.js +553 -0
- package/dist/safe-bash/command-chunks/chunk-LC2MFKT4.js +2489 -0
- package/dist/safe-bash/command-chunks/chunk-LE5LZNHE.js +204 -0
- package/dist/safe-bash/command-chunks/chunk-MDH5T4OS.js +41 -0
- package/dist/safe-bash/command-chunks/chunk-MM6HU6CX.js +20 -0
- package/dist/safe-bash/command-chunks/{chunk-MYJAZ3U2.js → chunk-MPL2466A.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-VZHRZMS7.js → chunk-NAY27PXB.js} +1 -1
- package/dist/safe-bash/command-chunks/chunk-NCD7PEWH.js +298 -0
- package/dist/safe-bash/command-chunks/chunk-NFGI5IGF.js +266 -0
- package/dist/safe-bash/command-chunks/{chunk-KVFCSLKK.js → chunk-NXEQ3ESQ.js} +6 -0
- package/dist/safe-bash/command-chunks/{chunk-3VGGYEDH.js → chunk-ORYGZYKW.js} +4 -3
- package/dist/safe-bash/command-chunks/{chunk-OLQG7ZCN.js → chunk-PEF7K3UQ.js} +136 -75
- package/dist/safe-bash/command-chunks/chunk-PII4YEZW.js +123 -0
- package/dist/safe-bash/command-chunks/{chunk-43GSSUAY.js → chunk-PJJUYO3R.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-ZT4KSS2V.js → chunk-PTT3I223.js} +1 -1
- package/dist/safe-bash/command-chunks/chunk-Q3DII3Q7.js +174 -0
- package/dist/safe-bash/command-chunks/chunk-Q3EWDEUQ.js +185 -0
- package/dist/safe-bash/command-chunks/{chunk-2FUAW6GO.js → chunk-QI7LGHJJ.js} +58 -9
- package/dist/safe-bash/command-chunks/{chunk-6BETHLXZ.js → chunk-QJAFJP2G.js} +1 -1
- package/dist/safe-bash/command-chunks/chunk-QNIMV57G.js +63 -0
- package/dist/safe-bash/command-chunks/{chunk-VVI4Z73I.js → chunk-QP4R6GLA.js} +5 -1
- package/dist/safe-bash/command-chunks/{chunk-LPORMIZS.js → chunk-QWIDNAAK.js} +8 -8
- package/dist/safe-bash/command-chunks/chunk-RVLO4DYT.js +35 -0
- package/dist/safe-bash/command-chunks/{chunk-X2YQLGKS.js → chunk-SAMH7SQE.js} +4 -4
- package/dist/safe-bash/command-chunks/chunk-SEM36PG5.js +11 -0
- package/dist/safe-bash/command-chunks/chunk-STC3LEWJ.js +634 -0
- package/dist/safe-bash/command-chunks/chunk-SVULUDOP.js +331 -0
- package/dist/safe-bash/command-chunks/chunk-TEVJJPTC.js +1392 -0
- package/dist/safe-bash/command-chunks/{chunk-ZXKW7SJ2.js → chunk-TYCGMRLM.js} +2 -2
- package/dist/safe-bash/command-chunks/chunk-UG7SMZFF.js +178 -0
- package/dist/safe-bash/command-chunks/{chunk-YZ5SVZFD.js → chunk-UMDIOL3O.js} +3 -3
- package/dist/safe-bash/command-chunks/chunk-UXSR5BZH.js +136 -0
- package/dist/safe-bash/command-chunks/chunk-V6BEDRMQ.js +112 -0
- package/dist/safe-bash/command-chunks/chunk-V6MSPQLA.js +362 -0
- package/dist/safe-bash/command-chunks/{chunk-J4PEQWSF.js → chunk-VGG2DL5Q.js} +0 -1
- package/dist/safe-bash/command-chunks/{chunk-SG424QWS.js → chunk-VL67NWNS.js} +1 -1
- package/dist/safe-bash/command-chunks/chunk-WB5SVIG7.js +1034 -0
- package/dist/safe-bash/command-chunks/{src-UJOWAS2S.js → chunk-WD3ERGRY.js} +77 -277
- package/dist/safe-bash/command-chunks/{chunk-YFSDDFGV.js → chunk-WH627NJL.js} +446 -53
- package/dist/safe-bash/command-chunks/chunk-WNE7FPVR.js +236 -0
- package/dist/safe-bash/command-chunks/{chunk-UKS2XJZI.js → chunk-WPYIOKE3.js} +4 -4
- package/dist/safe-bash/command-chunks/chunk-XETLEHZP.js +1227 -0
- package/dist/safe-bash/command-chunks/chunk-XIIBTGC5.js +580 -0
- package/dist/safe-bash/command-chunks/chunk-XJXU3VVH.js +737 -0
- package/dist/safe-bash/command-chunks/chunk-Y5INTD6S.js +220 -0
- package/dist/safe-bash/command-chunks/{chunk-5ZSM4UFN.js → chunk-YGC6OS5O.js} +3 -56
- package/dist/safe-bash/command-chunks/chunk-YJDV76GL.js +262 -0
- package/dist/safe-bash/command-chunks/chunk-YOF7R4OY.js +80 -0
- package/dist/safe-bash/command-chunks/chunk-Z7RVSD5K.js +594 -0
- package/dist/safe-bash/command-chunks/chunk-ZHUWOUWB.js +618 -0
- package/dist/safe-bash/command-chunks/{model-store-L35QTZMJ.js → model-store-WPKMRPV4.js} +2 -2
- package/dist/safe-bash/command-chunks/pptx-7G52EJ6L-4JACH5FB.js +625 -0
- package/dist/safe-bash/command-chunks/python-worker-source-TYOFJMCW.js +4 -0
- package/dist/safe-bash/command-chunks/src-ICMQISAA.js +501 -0
- package/dist/safe-bash/commands/archive/create.d.ts +1 -17
- package/dist/safe-bash/commands/archive/create.js +1 -252
- package/dist/safe-bash/commands/archive/extract.d.ts +1 -11
- package/dist/safe-bash/commands/archive/extract.js +1 -640
- package/dist/safe-bash/commands/archive/format.d.ts +1 -32
- package/dist/safe-bash/commands/archive/format.js +1 -225
- package/dist/safe-bash/commands/archive/index.d.ts +5 -10
- package/dist/safe-bash/commands/archive/index.js +6 -931
- package/dist/safe-bash/commands/archive/listing.d.ts +1 -2
- package/dist/safe-bash/commands/archive/listing.js +1 -21
- package/dist/safe-bash/commands/archive/modes.d.ts +1 -5
- package/dist/safe-bash/commands/archive/modes.js +1 -182
- package/dist/safe-bash/commands/archive/options.d.ts +1 -53
- package/dist/safe-bash/commands/archive/options.js +1 -462
- package/dist/safe-bash/commands/archive/stream.d.ts +1 -22
- package/dist/safe-bash/commands/archive/stream.js +1 -188
- package/dist/safe-bash/commands/archive/transform.d.ts +1 -16
- package/dist/safe-bash/commands/archive/transform.js +1 -85
- package/dist/safe-bash/commands/archive/unzip/arguments.d.ts +1 -53
- package/dist/safe-bash/commands/archive/unzip/arguments.js +1 -322
- package/dist/safe-bash/commands/archive/unzip/safety.d.ts +1 -32
- package/dist/safe-bash/commands/archive/unzip/safety.js +1 -295
- package/dist/safe-bash/commands/archive/unzip.d.ts +1 -3
- package/dist/safe-bash/commands/archive/unzip.js +1 -398
- package/dist/safe-bash/commands/archive/zip/aes.d.ts +1 -17
- package/dist/safe-bash/commands/archive/zip/aes.js +1 -156
- package/dist/safe-bash/commands/archive/zip/comments.d.ts +1 -17
- package/dist/safe-bash/commands/archive/zip/comments.js +1 -83
- package/dist/safe-bash/commands/archive/zip/crc.d.ts +1 -1
- package/dist/safe-bash/commands/archive/zip/crc.js +1 -1
- package/dist/safe-bash/commands/archive/zip/crypto.d.ts +1 -19
- package/dist/safe-bash/commands/archive/zip/crypto.js +1 -118
- package/dist/safe-bash/commands/archive/zip/dates.d.ts +1 -4
- package/dist/safe-bash/commands/archive/zip/dates.js +1 -66
- package/dist/safe-bash/commands/archive/zip/environment.d.ts +1 -2
- package/dist/safe-bash/commands/archive/zip/environment.js +1 -62
- package/dist/safe-bash/commands/archive/zip/grow.d.ts +1 -3
- package/dist/safe-bash/commands/archive/zip/grow.js +1 -2
- package/dist/safe-bash/commands/archive/zip/help.d.ts +1 -4
- package/dist/safe-bash/commands/archive/zip/help.js +1 -182
- package/dist/safe-bash/commands/archive/zip/line-endings.d.ts +1 -2
- package/dist/safe-bash/commands/archive/zip/line-endings.js +1 -194
- package/dist/safe-bash/commands/archive/zip/log.d.ts +1 -22
- package/dist/safe-bash/commands/archive/zip/log.js +1 -159
- package/dist/safe-bash/commands/archive/zip/lzma.d.ts +1 -9
- package/dist/safe-bash/commands/archive/zip/lzma.js +1 -40
- package/dist/safe-bash/commands/archive/zip/move.d.ts +1 -11
- package/dist/safe-bash/commands/archive/zip/move.js +1 -59
- package/dist/safe-bash/commands/archive/zip/names.d.ts +1 -2
- package/dist/safe-bash/commands/archive/zip/names.js +1 -33
- package/dist/safe-bash/commands/archive/zip/options.d.ts +1 -13
- package/dist/safe-bash/commands/archive/zip/options.js +1 -124
- package/dist/safe-bash/commands/archive/zip/repair.d.ts +1 -10
- package/dist/safe-bash/commands/archive/zip/repair.js +1 -392
- package/dist/safe-bash/commands/archive/zip/safety.d.ts +1 -54
- package/dist/safe-bash/commands/archive/zip/safety.js +1 -360
- package/dist/safe-bash/commands/archive/zip/sfx.d.ts +1 -4
- package/dist/safe-bash/commands/archive/zip/sfx.js +1 -52
- package/dist/safe-bash/commands/archive/zip/test-command.d.ts +1 -5
- package/dist/safe-bash/commands/archive/zip/test-command.js +1 -101
- package/dist/safe-bash/commands/archive/zip/volumes.d.ts +1 -21
- package/dist/safe-bash/commands/archive/zip/volumes.js +1 -281
- package/dist/safe-bash/commands/archive/zip/zip64.d.ts +1 -30
- package/dist/safe-bash/commands/archive/zip/zip64.js +1 -227
- package/dist/safe-bash/commands/archive/zip-format.d.ts +1 -68
- package/dist/safe-bash/commands/archive/zip-format.js +1 -1075
- package/dist/safe-bash/commands/archive/zip.d.ts +1 -3
- package/dist/safe-bash/commands/archive/zip.js +1 -1523
- package/dist/safe-bash/commands/awk/index.d.ts +2 -0
- package/dist/safe-bash/commands/awk/index.js +2 -0
- package/dist/safe-bash/commands/bytes/compression/index.js +2 -1
- package/dist/safe-bash/commands/curl/index.d.ts +2 -0
- package/dist/safe-bash/commands/curl/index.js +2 -0
- package/dist/safe-bash/commands/diff/index.d.ts +2 -0
- package/dist/safe-bash/commands/diff/index.js +2 -0
- package/dist/safe-bash/commands/diff-patch/diff-format.d.ts +1 -10
- package/dist/safe-bash/commands/diff-patch/diff-format.js +1 -237
- package/dist/safe-bash/commands/diff-patch/diff-options.d.ts +1 -38
- package/dist/safe-bash/commands/diff-patch/diff-options.js +1 -261
- package/dist/safe-bash/commands/diff-patch/diff-output.d.ts +1 -20
- package/dist/safe-bash/commands/diff-patch/diff-output.js +1 -290
- package/dist/safe-bash/commands/diff-patch/diff.d.ts +1 -2
- package/dist/safe-bash/commands/diff-patch/diff.js +1 -656
- package/dist/safe-bash/commands/diff-patch/index.d.ts +4 -5
- package/dist/safe-bash/commands/diff-patch/index.js +8 -333
- package/dist/safe-bash/commands/diff-patch/patch-envelope.d.ts +1 -2
- package/dist/safe-bash/commands/diff-patch/patch-envelope.js +1 -63
- package/dist/safe-bash/commands/diff-patch/patch-formats.d.ts +1 -7
- package/dist/safe-bash/commands/diff-patch/patch-formats.js +1 -264
- package/dist/safe-bash/commands/diff-patch/patch-gnu-paths.d.ts +1 -41
- package/dist/safe-bash/commands/diff-patch/patch-gnu-paths.js +1 -263
- package/dist/safe-bash/commands/diff-patch/patch-gnu-reject.d.ts +1 -3
- package/dist/safe-bash/commands/diff-patch/patch-gnu-reject.js +1 -100
- package/dist/safe-bash/commands/diff-patch/patch-path.d.ts +1 -3
- package/dist/safe-bash/commands/diff-patch/patch-path.js +1 -91
- package/dist/safe-bash/commands/diff-patch/patch-publication.d.ts +1 -13
- package/dist/safe-bash/commands/diff-patch/patch-publication.js +1 -107
- package/dist/safe-bash/commands/diff-patch/patch.d.ts +1 -2
- package/dist/safe-bash/commands/diff-patch/patch.js +1 -653
- package/dist/safe-bash/commands/diff-patch/shared.d.ts +1 -53
- package/dist/safe-bash/commands/diff-patch/shared.js +1 -267
- package/dist/safe-bash/commands/diff-patch/unified.d.ts +1 -52
- package/dist/safe-bash/commands/diff-patch/unified.js +1 -385
- package/dist/safe-bash/commands/directory-admission.d.ts +1 -3
- package/dist/safe-bash/commands/directory-admission.js +1 -26
- package/dist/safe-bash/commands/find/index.d.ts +2 -0
- package/dist/safe-bash/commands/find/index.js +2 -0
- package/dist/safe-bash/commands/find-format.d.ts +1 -20
- package/dist/safe-bash/commands/find-format.js +1 -161
- package/dist/safe-bash/commands/find.d.ts +2 -18
- package/dist/safe-bash/commands/find.js +2 -1236
- package/dist/safe-bash/commands/gzip/index.d.ts +2 -0
- package/dist/safe-bash/commands/gzip/index.js +2 -0
- package/dist/safe-bash/commands/line-endings/index.browser.js +1 -1
- package/dist/safe-bash/commands/line-endings/index.d.ts +1 -1
- package/dist/safe-bash/commands/line-endings/index.js +1 -262
- package/dist/safe-bash/commands/llm/index.browser.js +3 -1
- package/dist/safe-bash/commands/mdq/index.browser.js +2 -2
- package/dist/safe-bash/commands/metadata/chmod.d.ts +1 -4
- package/dist/safe-bash/commands/metadata/chmod.js +2 -63
- package/dist/safe-bash/commands/network/aggregate.d.ts +1 -4
- package/dist/safe-bash/commands/network/aggregate.js +1 -23
- package/dist/safe-bash/commands/network/args.d.ts +1 -68
- package/dist/safe-bash/commands/network/args.js +1 -321
- package/dist/safe-bash/commands/network/authorizer.d.ts +1 -6
- package/dist/safe-bash/commands/network/authorizer.js +1 -33
- package/dist/safe-bash/commands/network/body.d.ts +1 -9
- package/dist/safe-bash/commands/network/body.js +1 -393
- package/dist/safe-bash/commands/network/curl.d.ts +3 -13
- package/dist/safe-bash/commands/network/curl.js +6 -693
- package/dist/safe-bash/commands/network/deadline.d.ts +1 -2
- package/dist/safe-bash/commands/network/deadline.js +1 -14
- package/dist/safe-bash/commands/network/decode.d.ts +1 -2
- package/dist/safe-bash/commands/network/decode.js +1 -79
- package/dist/safe-bash/commands/network/fetch-transport.d.ts +1 -7
- package/dist/safe-bash/commands/network/fetch-transport.js +1 -94
- package/dist/safe-bash/commands/network/form-content-type.d.ts +1 -5
- package/dist/safe-bash/commands/network/form-content-type.js +1 -63
- package/dist/safe-bash/commands/network/form-headers.d.ts +1 -2
- package/dist/safe-bash/commands/network/form-headers.js +1 -35
- package/dist/safe-bash/commands/network/glob.d.ts +1 -7
- package/dist/safe-bash/commands/network/glob.js +1 -134
- package/dist/safe-bash/commands/network/index.browser.js +2 -10
- package/dist/safe-bash/commands/network/input.d.ts +1 -5
- package/dist/safe-bash/commands/network/input.js +1 -276
- package/dist/safe-bash/commands/network/output.d.ts +1 -6
- package/dist/safe-bash/commands/network/output.js +1 -131
- package/dist/safe-bash/commands/network/private-address.d.ts +1 -1
- package/dist/safe-bash/commands/network/private-address.js +1 -44
- package/dist/safe-bash/commands/network/shared.d.ts +1 -14
- package/dist/safe-bash/commands/network/shared.js +1 -71
- package/dist/safe-bash/commands/network/types.d.ts +1 -37
- package/dist/safe-bash/commands/network/types.js +1 -31
- package/dist/safe-bash/commands/network/url.d.ts +1 -2
- package/dist/safe-bash/commands/network/url.js +1 -30
- package/dist/safe-bash/commands/network/wget.d.ts +3 -3
- package/dist/safe-bash/commands/network/wget.js +10 -331
- package/dist/safe-bash/commands/node/index.browser.js +4 -5
- package/dist/safe-bash/commands/node/index.d.ts +3 -3
- package/dist/safe-bash/commands/node/index.js +5 -0
- package/dist/safe-bash/commands/node/safejs.d.ts +3 -3
- package/dist/safe-bash/commands/node/safejs.js +6 -1
- package/dist/safe-bash/commands/node/types.d.ts +1 -1
- package/dist/safe-bash/commands/node/unconfigured.d.ts +3 -0
- package/dist/safe-bash/commands/node/unconfigured.js +10 -0
- package/dist/safe-bash/commands/op/index.browser.js +2 -2
- package/dist/safe-bash/commands/patch/index.d.ts +2 -0
- package/dist/safe-bash/commands/patch/index.js +2 -0
- package/dist/safe-bash/commands/pdfinfo/index.js +2 -1
- package/dist/safe-bash/commands/predicates.js +3 -4
- package/dist/safe-bash/commands/python/index.browser.js +5 -5
- package/dist/safe-bash/commands/python/llm-capability.d.ts +1 -0
- package/dist/safe-bash/commands/python/llm-capability.js +27 -7
- package/dist/safe-bash/commands/python/llm-module.js +11 -0
- package/dist/safe-bash/commands/python/manifest.d.ts +1 -0
- package/dist/safe-bash/commands/python/manifest.js +9 -5
- package/dist/safe-bash/commands/python/provisioning.js +1 -1
- package/dist/safe-bash/commands/regex-execution/matching.js +1 -2
- package/dist/safe-bash/commands/regex-execution/public.browser.js +5 -5
- package/dist/safe-bash/commands/search/index.d.ts +1 -1
- package/dist/safe-bash/commands/search/index.js +1 -347
- package/dist/safe-bash/commands/search/portable.d.ts +2 -2
- package/dist/safe-bash/commands/search/portable.js +3 -2
- package/dist/safe-bash/commands/sed/index.d.ts +2 -0
- package/dist/safe-bash/commands/sed/index.js +2 -0
- package/dist/safe-bash/commands/tar/index.d.ts +2 -0
- package/dist/safe-bash/commands/tar/index.js +2 -0
- package/dist/safe-bash/commands/text-programs/awk-inspection.d.ts +1 -19
- package/dist/safe-bash/commands/text-programs/awk-inspection.js +1 -50
- package/dist/safe-bash/commands/text-programs/awk-pipes.d.ts +2 -0
- package/dist/safe-bash/commands/text-programs/awk-pipes.js +2 -0
- package/dist/safe-bash/commands/text-programs/awk-pretty.d.ts +1 -3
- package/dist/safe-bash/commands/text-programs/awk-pretty.js +1 -197
- package/dist/safe-bash/commands/text-programs/awk-quote.d.ts +1 -2
- package/dist/safe-bash/commands/text-programs/awk-quote.js +1 -15
- package/dist/safe-bash/commands/text-programs/awk-reader.d.ts +1 -42
- package/dist/safe-bash/commands/text-programs/awk-reader.js +1 -449
- package/dist/safe-bash/commands/text-programs/awk-retention.d.ts +1 -13
- package/dist/safe-bash/commands/text-programs/awk-retention.js +1 -51
- package/dist/safe-bash/commands/text-programs/awk-runtime.d.ts +1 -150
- package/dist/safe-bash/commands/text-programs/awk-runtime.js +1 -2627
- package/dist/safe-bash/commands/text-programs/awk-syntax.d.ts +1 -142
- package/dist/safe-bash/commands/text-programs/awk-syntax.js +1 -509
- package/dist/safe-bash/commands/text-programs/awk-values.d.ts +1 -32
- package/dist/safe-bash/commands/text-programs/awk-values.js +1 -386
- package/dist/safe-bash/commands/text-programs/awk.d.ts +1 -3
- package/dist/safe-bash/commands/text-programs/awk.js +1 -361
- package/dist/safe-bash/commands/text-programs/inplace.d.ts +1 -16
- package/dist/safe-bash/commands/text-programs/inplace.js +1 -155
- package/dist/safe-bash/commands/text-programs/sed.d.ts +1 -3
- package/dist/safe-bash/commands/text-programs/sed.js +1 -1647
- package/dist/safe-bash/commands/unzip/index.d.ts +2 -0
- package/dist/safe-bash/commands/unzip/index.js +2 -0
- package/dist/safe-bash/commands/wget/index.d.ts +2 -0
- package/dist/safe-bash/commands/wget/index.js +2 -0
- package/dist/safe-bash/commands/yq/index.browser.js +7 -2
- package/dist/safe-bash/commands/yq/index.d.ts +1 -6
- package/dist/safe-bash/commands/yq/index.js +1 -36
- package/dist/safe-bash/commands/zip/index.d.ts +2 -0
- package/dist/safe-bash/commands/zip/index.js +2 -0
- package/dist/safe-bash/core.browser.js +1 -1
- package/dist/safe-bash/core.d.ts +8 -1
- package/dist/safe-bash/core.js +7 -1
- package/dist/safe-bash/fs/s3/index.d.ts +2 -2
- package/dist/safe-bash/fs/s3/index.js +1 -1
- package/dist/safe-bash/full-core.browser.js +254 -223
- package/dist/safe-bash/jobs.browser.js +2 -2
- package/dist/safe-bash/lazy-mmdc.d.ts +6 -0
- package/dist/safe-bash/lazy-mmdc.js +23 -0
- package/dist/safe-bash/opt-in/commands/yq/mike.js +6 -13
- package/dist/safe-bash/opt-in/commands/yq/native-work.d.ts +1 -0
- package/dist/safe-bash/opt-in/commands/yq/native-work.js +17 -0
- package/dist/safe-bash/optional-host.browser.js +8 -4
- package/dist/safe-bash/optional-host.d.ts +1 -1
- package/dist/safe-bash/optional-host.js +1 -1
- package/dist/safe-bash/playwright/ability-execution.js +3 -2
- package/dist/safe-bash/playwright/adapter.js +1 -1
- package/dist/safe-bash/playwright/controller.js +9 -8
- package/dist/safe-bash/playwright/modal-capabilities.js +2 -1
- package/dist/safe-bash/playwright/native-json-snapshot.js +4 -3
- package/dist/safe-bash/playwright/native-snapshot.js +5 -4
- package/dist/safe-bash/playwright/open-options.js +3 -3
- package/dist/safe-bash/playwright/resource-limit.d.ts +2 -0
- package/dist/safe-bash/playwright/resource-limit.js +4 -0
- package/dist/safe-bash/playwright/session-configuration.js +8 -3
- package/dist/safe-bash/playwright/snapshot.js +8 -7
- package/dist/safe-bash/playwright/standard-capabilities.js +5 -4
- package/dist/safe-bash/plugins/index.browser.js +14 -16
- package/dist/safe-bash/registry-entry.browser.js +14 -16
- package/dist/safe-bash/shell/arrays/bindings.d.ts +3 -5
- package/dist/safe-bash/shell/arrays/bindings.js +6 -2
- package/dist/safe-bash/shell/input.js +16 -14
- package/dist/safe-bash/shell/runtime.d.ts +3 -0
- package/dist/safe-bash/shell/runtime.js +316 -64
- package/dist/safe-bash/shell/types.d.ts +2 -0
- package/dist/safe-bash/shell/value-state.js +17 -2
- package/dist/safe-bash/shell/worker-limits.js +1 -0
- package/dist/safe-bash/shell-entry.browser.js +13 -15
- package/dist/safe-bash/trap.browser.d.ts +3 -0
- package/dist/safe-bash/trap.browser.js +14 -0
- package/dist/safe-bash/worker/host.js +1 -1
- package/dist/safe-bash-command-apply-patch/apply.js +2 -2
- package/dist/safe-bash-command-apply-patch/index.js +3 -3
- package/dist/safe-bash-command-awk/LICENSE +21 -0
- package/dist/safe-bash-command-awk/awk-inspection.d.ts +19 -0
- package/dist/safe-bash-command-awk/awk-inspection.js +9 -0
- package/dist/safe-bash-command-awk/awk-pipes.d.ts +19 -0
- package/dist/safe-bash-command-awk/awk-pipes.js +8 -0
- package/dist/safe-bash-command-awk/awk-pretty.d.ts +3 -0
- package/dist/safe-bash-command-awk/awk-pretty.js +8 -0
- package/dist/safe-bash-command-awk/awk-quote.d.ts +2 -0
- package/dist/safe-bash-command-awk/awk-quote.js +7 -0
- package/dist/safe-bash-command-awk/awk-reader.d.ts +42 -0
- package/dist/safe-bash-command-awk/awk-reader.js +9 -0
- package/dist/safe-bash-command-awk/awk-retention.d.ts +13 -0
- package/dist/safe-bash-command-awk/awk-retention.js +7 -0
- package/dist/safe-bash-command-awk/awk-runtime.d.ts +151 -0
- package/dist/safe-bash-command-awk/awk-runtime.js +11 -0
- package/dist/safe-bash-command-awk/awk-syntax.d.ts +144 -0
- package/dist/safe-bash-command-awk/awk-syntax.js +14 -0
- package/dist/safe-bash-command-awk/awk-values.d.ts +32 -0
- package/dist/safe-bash-command-awk/awk-values.js +35 -0
- package/dist/safe-bash-command-awk/awk.d.ts +3 -0
- package/dist/safe-bash-command-awk/awk.js +16 -0
- package/dist/safe-bash-command-awk/index.d.ts +7 -0
- package/dist/safe-bash-command-awk/index.js +36 -0
- package/dist/safe-bash-command-bc/index.d.ts +4 -0
- package/dist/safe-bash-command-bc/index.js +15 -176
- package/dist/safe-bash-command-column/column.js +3 -3
- package/dist/safe-bash-command-column/index.js +3 -3
- package/dist/safe-bash-command-column/layout.js +2 -2
- package/dist/safe-bash-command-csplit/command.js +2 -2
- package/dist/safe-bash-command-csplit/index.js +2 -2
- package/dist/safe-bash-command-csvkit/contracts.d.ts +1 -0
- package/dist/safe-bash-command-csvkit/csvpy-interpreter.d.ts +2 -1
- package/dist/safe-bash-command-csvkit/default-csvpy.d.ts +11 -0
- package/dist/safe-bash-command-csvkit/errors.js +22 -0
- package/dist/safe-bash-command-csvkit/index.d.ts +1 -0
- package/dist/safe-bash-command-csvkit/index.js +172 -4
- package/dist/safe-bash-command-csvkit/python-worker-browser.d.ts +3 -0
- package/dist/safe-bash-command-csvkit/python-worker-browser.js +16 -0
- package/dist/safe-bash-command-csvkit/python-worker-contract.d.ts +20 -0
- package/dist/safe-bash-command-csvkit/python-worker-node.d.ts +3 -0
- package/dist/safe-bash-command-csvkit/python-worker-node.js +9 -0
- package/dist/safe-bash-command-csvkit/runtime.d.ts +1 -0
- package/dist/safe-bash-command-curl/LICENSE +21 -0
- package/dist/safe-bash-command-curl/curl.d.ts +13 -0
- package/dist/safe-bash-command-curl/curl.js +9 -0
- package/dist/safe-bash-command-curl/index.d.ts +6 -0
- package/dist/safe-bash-command-curl/index.js +26 -0
- package/dist/safe-bash-command-diff/LICENSE +21 -0
- package/dist/safe-bash-command-diff/diff-format.d.ts +10 -0
- package/dist/safe-bash-command-diff/diff-format.js +10 -0
- package/dist/safe-bash-command-diff/diff-options.d.ts +38 -0
- package/dist/safe-bash-command-diff/diff-options.js +7 -0
- package/dist/safe-bash-command-diff/diff-output.d.ts +20 -0
- package/dist/safe-bash-command-diff/diff-output.js +19 -0
- package/dist/safe-bash-command-diff/diff.d.ts +2 -0
- package/dist/safe-bash-command-diff/diff.js +10 -0
- package/dist/safe-bash-command-diff/index.d.ts +8 -0
- package/dist/safe-bash-command-diff/index.js +34 -0
- package/dist/safe-bash-command-diff/sync.d.ts +2 -0
- package/dist/safe-bash-command-diff/sync.js +9 -0
- package/dist/safe-bash-command-diff3/index.js +5 -5
- package/dist/safe-bash-command-docx/index.d.ts +4 -4
- package/dist/safe-bash-command-docx/index.js +12 -5
- package/dist/safe-bash-command-dos2unix/index.d.ts +1 -0
- package/dist/safe-bash-command-dos2unix/index.js +225 -1
- package/dist/safe-bash-command-dos2unix/sync.d.ts +1 -0
- package/dist/safe-bash-command-exiftool/index.js +2 -2
- package/dist/safe-bash-command-factor/command.js +2 -2
- package/dist/safe-bash-command-factor/index.js +2 -2
- package/dist/safe-bash-command-ffmpeg/index.js +86 -94
- package/dist/safe-bash-command-file/index.js +3 -3
- package/dist/safe-bash-command-find/LICENSE +21 -0
- package/dist/safe-bash-command-find/find-format.d.ts +20 -0
- package/dist/safe-bash-command-find/find-format.js +9 -0
- package/dist/safe-bash-command-find/find.d.ts +18 -0
- package/dist/safe-bash-command-find/find.js +10 -0
- package/dist/safe-bash-command-find/index.d.ts +13 -0
- package/dist/safe-bash-command-find/index.js +45 -0
- package/dist/safe-bash-command-fmt/index.js +7 -4
- package/dist/safe-bash-command-git/git_rust.wasm +0 -0
- package/dist/safe-bash-command-git/index.js +5 -7
- package/dist/safe-bash-command-git/wasm.generated.js +1 -1
- package/dist/safe-bash-command-gzip/LICENSE +21 -0
- package/dist/safe-bash-command-gzip/index.d.ts +11 -0
- package/dist/safe-bash-command-gzip/index.js +94 -0
- package/dist/safe-bash-command-html-to-markdown/index.js +5 -5
- package/dist/safe-bash-command-htmlq/index.js +12 -8
- package/dist/safe-bash-command-imagemagick/index.js +22 -30
- package/dist/safe-bash-command-jq/index.js +1 -1
- package/dist/safe-bash-command-jq/jq.js +1 -1
- package/dist/safe-bash-command-llm/command.js +1 -1
- package/dist/safe-bash-command-llm/index.d.ts +1 -0
- package/dist/safe-bash-command-llm/index.js +16 -14
- package/dist/safe-bash-command-llm/openai.js +3 -3
- package/dist/safe-bash-command-llm/providers/index.js +3 -3
- package/dist/safe-bash-command-llm/providers/openai.js +3 -3
- package/dist/safe-bash-command-llm/stored-schema.d.ts +10 -0
- package/dist/safe-bash-command-mmdc/index.js +13 -604
- package/dist/safe-bash-command-mmdc/settings.d.ts +2 -0
- package/dist/safe-bash-command-mmdc/settings.js +7 -0
- package/dist/safe-bash-command-pandoc/command.js +4 -3
- package/dist/safe-bash-command-pandoc/defaults.d.ts +1 -0
- package/dist/safe-bash-command-pandoc/index.js +4 -3
- package/dist/safe-bash-command-pandoc/lua-filters.js +1 -1
- package/dist/safe-bash-command-pandoc/types.d.ts +3 -1
- package/dist/safe-bash-command-patch/LICENSE +21 -0
- package/dist/safe-bash-command-patch/index.d.ts +8 -0
- package/dist/safe-bash-command-patch/index.js +38 -0
- package/dist/safe-bash-command-patch/patch-envelope.d.ts +2 -0
- package/dist/safe-bash-command-patch/patch-envelope.js +7 -0
- package/dist/safe-bash-command-patch/patch-formats.d.ts +7 -0
- package/dist/safe-bash-command-patch/patch-formats.js +9 -0
- package/dist/safe-bash-command-patch/patch-gnu-paths.d.ts +41 -0
- package/dist/safe-bash-command-patch/patch-gnu-paths.js +26 -0
- package/dist/safe-bash-command-patch/patch-gnu-reject.d.ts +3 -0
- package/dist/safe-bash-command-patch/patch-gnu-reject.js +7 -0
- package/dist/safe-bash-command-patch/patch-path.d.ts +3 -0
- package/dist/safe-bash-command-patch/patch-path.js +11 -0
- package/dist/safe-bash-command-patch/patch-publication.d.ts +13 -0
- package/dist/safe-bash-command-patch/patch-publication.js +7 -0
- package/dist/safe-bash-command-patch/patch.d.ts +2 -0
- package/dist/safe-bash-command-patch/patch.js +14 -0
- package/dist/safe-bash-command-patch/sync.d.ts +2 -0
- package/dist/safe-bash-command-patch/sync.js +7 -0
- package/dist/safe-bash-command-patch/unified.d.ts +52 -0
- package/dist/safe-bash-command-patch/unified.js +16 -0
- package/dist/safe-bash-command-pdfimages/index.js +37 -16
- package/dist/safe-bash-command-pdfinfo/index.d.ts +0 -23
- package/dist/safe-bash-command-pdfinfo/index.js +20 -772
- package/dist/safe-bash-command-pdftk/index.js +37 -9
- package/dist/safe-bash-command-pdftoppm/index.js +50 -20
- package/dist/safe-bash-command-pdftotext/index.js +10 -2
- package/dist/safe-bash-command-pptx/index.d.ts +4 -4
- package/dist/safe-bash-command-pptx/index.js +11 -5
- package/dist/safe-bash-command-pr/command.js +2 -2
- package/dist/safe-bash-command-pr/index.js +4 -4
- package/dist/safe-bash-command-qpdf/index.js +26 -13
- package/dist/safe-bash-command-rg/index.d.ts +1 -0
- package/dist/safe-bash-command-rg/index.js +222 -1
- package/dist/safe-bash-command-rg/rg-command.js +1 -1
- package/dist/safe-bash-command-rg/sync.d.ts +1 -0
- package/dist/safe-bash-command-sed/LICENSE +21 -0
- package/dist/safe-bash-command-sed/index.d.ts +7 -0
- package/dist/safe-bash-command-sed/index.js +28 -0
- package/dist/safe-bash-command-sed/inplace.d.ts +16 -0
- package/dist/safe-bash-command-sed/inplace.js +9 -0
- package/dist/safe-bash-command-sed/sed.d.ts +3 -0
- package/dist/safe-bash-command-sed/sed.js +8 -0
- package/dist/safe-bash-command-sips/index.js +111 -35
- package/dist/safe-bash-command-soffice/index.js +4 -4
- package/dist/safe-bash-command-sqlite3/engine.d.ts +1 -2
- package/dist/safe-bash-command-sqlite3/index.js +152 -452
- package/dist/safe-bash-command-ssconvert/commands.js +1 -1
- package/dist/safe-bash-command-ssconvert/formats/ods.js +2 -2
- package/dist/safe-bash-command-ssconvert/formats/xlsx.js +3 -3
- package/dist/safe-bash-command-ssconvert/index.js +5 -5
- package/dist/safe-bash-command-tar/LICENSE +21 -0
- package/dist/safe-bash-command-tar/create.d.ts +17 -0
- package/dist/safe-bash-command-tar/create.js +14 -0
- package/dist/safe-bash-command-tar/extract.d.ts +11 -0
- package/dist/safe-bash-command-tar/extract.js +14 -0
- package/dist/safe-bash-command-tar/format.d.ts +32 -0
- package/dist/safe-bash-command-tar/format.js +19 -0
- package/dist/safe-bash-command-tar/index.d.ts +8 -0
- package/dist/safe-bash-command-tar/index.js +550 -0
- package/dist/safe-bash-command-tar/listing.d.ts +2 -0
- package/dist/safe-bash-command-tar/listing.js +7 -0
- package/dist/safe-bash-command-tar/modes.d.ts +5 -0
- package/dist/safe-bash-command-tar/modes.js +16 -0
- package/dist/safe-bash-command-tar/options.d.ts +53 -0
- package/dist/safe-bash-command-tar/options.js +10 -0
- package/dist/safe-bash-command-tar/stream.d.ts +22 -0
- package/dist/safe-bash-command-tar/stream.js +15 -0
- package/dist/safe-bash-command-tar/transform.d.ts +16 -0
- package/dist/safe-bash-command-tar/transform.js +9 -0
- package/dist/safe-bash-command-unzip/LICENSE +21 -0
- package/dist/safe-bash-command-unzip/index.d.ts +7 -0
- package/dist/safe-bash-command-unzip/index.js +39 -0
- package/dist/safe-bash-command-unzip/sync.d.ts +3 -0
- package/dist/safe-bash-command-unzip/sync.js +9 -0
- package/dist/safe-bash-command-unzip/unzip/safety.d.ts +32 -0
- package/dist/safe-bash-command-unzip/unzip/safety.js +7 -0
- package/dist/safe-bash-command-unzip/unzip.d.ts +3 -0
- package/dist/safe-bash-command-unzip/unzip.js +8 -0
- package/dist/safe-bash-command-wget/LICENSE +21 -0
- package/dist/safe-bash-command-wget/index.d.ts +6 -0
- package/dist/safe-bash-command-wget/index.js +26 -0
- package/dist/safe-bash-command-wget/wget.d.ts +3 -0
- package/dist/safe-bash-command-wget/wget.js +7 -0
- package/dist/safe-bash-command-xan/argv.d.ts +4 -1
- package/dist/safe-bash-command-xan/argv.js +1 -1
- package/dist/safe-bash-command-xan/commands.js +4 -3
- package/dist/safe-bash-command-xan/index.js +15 -14
- package/dist/safe-bash-command-xan/io.js +2 -2
- package/dist/safe-bash-command-xmllint/index.js +189 -49
- package/dist/safe-bash-command-xz/index.js +3 -2
- package/dist/safe-bash-command-xz/options.d.ts +9 -1
- package/dist/safe-bash-command-xz/options.js +3 -1
- package/dist/safe-bash-command-yq/index.d.ts +4 -11
- package/dist/safe-bash-command-yq/index.js +3367 -670
- package/dist/safe-bash-command-yq/mike.js +6 -13
- package/dist/safe-bash-command-yq/native-work.d.ts +1 -0
- package/dist/safe-bash-command-yq/native-work.js +17 -0
- package/dist/safe-bash-command-yq/query.d.ts +11 -0
- package/dist/safe-bash-command-yq/query.js +735 -0
- package/dist/safe-bash-command-zip/LICENSE +21 -0
- package/dist/safe-bash-command-zip/index.d.ts +7 -0
- package/dist/safe-bash-command-zip/index.js +38 -0
- package/dist/safe-bash-command-zip/sync.d.ts +3 -0
- package/dist/safe-bash-command-zip/sync.js +9 -0
- package/dist/safe-bash-command-zip/zip.d.ts +3 -0
- package/dist/safe-bash-command-zip/zip.js +7 -0
- package/dist/safe-bash-compression-engine/files.js +4 -4
- package/dist/safe-bash-compression-engine/index.js +2 -2
- package/dist/safe-bash-compression-engine/operand.js +6 -6
- package/dist/safe-bash-compression-engine/stream.js +2 -2
- package/dist/safe-bash-compression-engine/zstd-decode.js +1 -1
- package/dist/safe-bash-contracts/command.js +1 -1
- package/dist/safe-bash-contracts/diagnostics.js +4 -4
- package/dist/safe-bash-contracts/escaping.js +11 -11
- package/dist/safe-bash-contracts/filesystem-descriptor.js +1 -1
- package/dist/safe-bash-contracts/filesystem-output.js +8 -8
- package/dist/safe-bash-contracts/index.js +34 -34
- package/dist/safe-bash-contracts/io.js +2 -2
- package/dist/safe-bash-contracts/output.js +3 -3
- package/dist/safe-bash-diff-engine/LICENSE +21 -0
- package/dist/safe-bash-diff-engine/index.d.ts +1 -0
- package/dist/safe-bash-diff-engine/index.js +24 -0
- package/dist/safe-bash-diff-engine/shared.d.ts +53 -0
- package/dist/safe-bash-diff-engine/shared.js +19 -0
- package/dist/safe-bash-io-engine/commands/directory-admission.d.ts +3 -0
- package/dist/safe-bash-io-engine/commands/directory-admission.js +34 -0
- package/dist/safe-bash-io-engine/commands/mode-change.d.ts +4 -0
- package/dist/safe-bash-io-engine/commands/mode-change.js +60 -0
- package/dist/safe-bash-io-engine/commands/text-programs/shared.js +20 -31
- package/dist/safe-bash-io-engine/shell/pattern.js +7 -12
- package/dist/safe-bash-markdown-engine/commonmark-blocks.js +4 -4
- package/dist/safe-bash-markdown-engine/commonmark-inlines.js +4 -4
- package/dist/safe-bash-markdown-engine/commonmark-syntax.js +2 -2
- package/dist/safe-bash-markdown-engine/gfm-syntax.js +3 -3
- package/dist/safe-bash-markdown-engine/index.js +7 -7
- package/dist/safe-bash-mcp/index.browser.d.ts +6 -0
- package/dist/safe-bash-mcp/index.browser.js +1 -0
- package/dist/safe-bash-mcp/index.d.ts +12 -0
- package/dist/safe-bash-mcp/index.js +1558 -36
- package/dist/safe-bash-network-engine/LICENSE +21 -0
- package/dist/safe-bash-network-engine/aggregate.d.ts +4 -0
- package/dist/safe-bash-network-engine/aggregate.js +37 -0
- package/dist/safe-bash-network-engine/args.d.ts +68 -0
- package/dist/safe-bash-network-engine/args.js +19 -0
- package/dist/safe-bash-network-engine/authorizer.d.ts +6 -0
- package/dist/safe-bash-network-engine/authorizer.js +8 -0
- package/dist/safe-bash-network-engine/body.d.ts +9 -0
- package/dist/safe-bash-network-engine/body.js +374 -0
- package/dist/safe-bash-network-engine/deadline.d.ts +2 -0
- package/dist/safe-bash-network-engine/deadline.js +7 -0
- package/dist/safe-bash-network-engine/decode.d.ts +2 -0
- package/dist/safe-bash-network-engine/decode.js +81 -0
- package/dist/safe-bash-network-engine/fetch-transport.d.ts +7 -0
- package/dist/safe-bash-network-engine/fetch-transport.js +9 -0
- package/dist/safe-bash-network-engine/form-content-type.d.ts +5 -0
- package/dist/safe-bash-network-engine/form-content-type.js +8 -0
- package/dist/safe-bash-network-engine/form-headers.d.ts +2 -0
- package/dist/safe-bash-network-engine/form-headers.js +10 -0
- package/dist/safe-bash-network-engine/glob.d.ts +7 -0
- package/dist/safe-bash-network-engine/glob.js +124 -0
- package/dist/safe-bash-network-engine/index.d.ts +3 -0
- package/dist/safe-bash-network-engine/index.js +26 -0
- package/dist/safe-bash-network-engine/input.d.ts +5 -0
- package/dist/safe-bash-network-engine/input.js +255 -0
- package/dist/safe-bash-network-engine/output.d.ts +6 -0
- package/dist/safe-bash-network-engine/output.js +132 -0
- package/dist/safe-bash-network-engine/platform-portable.d.ts +5 -0
- package/dist/safe-bash-network-engine/platform-portable.js +19 -0
- package/dist/safe-bash-network-engine/private-address.d.ts +1 -0
- package/dist/safe-bash-network-engine/private-address.js +7 -0
- package/dist/safe-bash-network-engine/shared.d.ts +14 -0
- package/dist/safe-bash-network-engine/shared.js +23 -0
- package/dist/safe-bash-network-engine/types.d.ts +37 -0
- package/dist/safe-bash-network-engine/types.js +11 -0
- package/dist/safe-bash-network-engine/url.d.ts +2 -0
- package/dist/safe-bash-network-engine/url.js +8 -0
- package/dist/safe-bash-query-engine/capture.d.ts +1 -0
- package/dist/safe-bash-query-engine/capture.js +9 -7
- package/dist/safe-bash-query-engine/dates.d.ts +5 -1
- package/dist/safe-bash-query-engine/dates.js +10 -2
- package/dist/safe-bash-query-engine/delpaths.js +5 -5
- package/dist/safe-bash-query-engine/formats.js +3 -3
- package/dist/safe-bash-query-engine/index.js +15 -15
- package/dist/safe-bash-query-engine/indices.js +5 -5
- package/dist/safe-bash-query-engine/input.d.ts +1 -2
- package/dist/safe-bash-query-engine/input.js +2 -4
- package/dist/safe-bash-query-engine/interpreter.d.ts +5 -0
- package/dist/safe-bash-query-engine/interpreter.js +13 -13
- package/dist/safe-bash-query-engine/limits.js +1 -1
- package/dist/safe-bash-query-engine/parser.d.ts +8 -1
- package/dist/safe-bash-query-engine/parser.js +2 -2
- package/dist/safe-bash-query-engine/query-core.js +15 -15
- package/dist/safe-bash-query-engine/recurse.js +2 -2
- package/dist/safe-bash-query-engine/regex.d.ts +4 -2
- package/dist/safe-bash-query-engine/regex.js +10 -5
- package/dist/safe-bash-query-engine/split.js +2 -2
- package/dist/safe-bash-query-engine/splits.d.ts +1 -1
- package/dist/safe-bash-query-engine/splits.js +7 -6
- package/dist/safe-bash-query-engine/values.js +4 -4
- package/dist/safe-bash-regex-engine/ere/matcher.js +4 -4
- package/dist/safe-bash-regex-engine/index.js +2 -2
- package/dist/safe-bash-regex-engine/text/regex.d.ts +1 -0
- package/dist/safe-bash-regex-engine/text/regex.js +2 -2
- package/dist/safe-bash-search-engine/ergonomic-regex.d.ts +12 -2
- package/dist/safe-bash-search-engine/ergonomic-regex.js +2 -2
- package/dist/safe-bash-search-engine/glob.js +2 -2
- package/dist/safe-bash-search-engine/grep.js +2 -2
- package/dist/safe-bash-search-engine/matcher.d.ts +6 -2
- package/dist/safe-bash-search-engine/matcher.js +30 -8
- package/dist/safe-bash-search-engine/options.js +1 -1
- package/dist/safe-bash-search-engine/output.d.ts +3 -2
- package/dist/safe-bash-search-engine/output.js +111 -30
- package/dist/safe-bash-search-engine/shared.d.ts +2 -0
- package/dist/safe-bash-search-engine/shared.js +2 -2
- package/dist/safe-bash-search-engine/walk.js +11 -10
- package/dist/safe-bash-xml-engine/document.d.ts +1 -1
- package/dist/safe-bash-xml-engine/document.js +3 -3
- package/dist/safe-bash-xml-engine/evaluate.d.ts +1 -0
- package/dist/safe-bash-xml-engine/evaluate.js +4 -1
- package/dist/safe-bash-xml-engine/index.js +8 -6
- package/dist/safe-bash-xml-engine/io.js +1 -1
- package/dist/safe-bash-xml-engine/limits.d.ts +2 -0
- package/dist/safe-bash-xml-engine/limits.js +1 -1
- package/dist/safe-bash-xml-engine/predicate.d.ts +57 -0
- package/dist/safe-bash-xml-engine/query.d.ts +3 -15
- package/dist/safe-bash-xml-engine/query.js +3 -2
- package/dist/safe-bash-zip-engine/LICENSE +21 -0
- package/dist/safe-bash-zip-engine/index.d.ts +1 -0
- package/dist/safe-bash-zip-engine/index.js +32 -0
- package/dist/safe-bash-zip-engine/unzip/arguments.d.ts +53 -0
- package/dist/safe-bash-zip-engine/unzip/arguments.js +270 -0
- package/dist/safe-bash-zip-engine/zip/aes.d.ts +17 -0
- package/dist/safe-bash-zip-engine/zip/aes.js +15 -0
- package/dist/safe-bash-zip-engine/zip/comments.d.ts +17 -0
- package/dist/safe-bash-zip-engine/zip/comments.js +77 -0
- package/dist/safe-bash-zip-engine/zip/crc.d.ts +1 -0
- package/dist/safe-bash-zip-engine/zip/crc.js +7 -0
- package/dist/safe-bash-zip-engine/zip/crypto.d.ts +19 -0
- package/dist/safe-bash-zip-engine/zip/crypto.js +16 -0
- package/dist/safe-bash-zip-engine/zip/dates.d.ts +4 -0
- package/dist/safe-bash-zip-engine/zip/dates.js +68 -0
- package/dist/safe-bash-zip-engine/zip/environment.d.ts +2 -0
- package/dist/safe-bash-zip-engine/zip/environment.js +60 -0
- package/dist/safe-bash-zip-engine/zip/grow.d.ts +3 -0
- package/dist/safe-bash-zip-engine/zip/grow.js +7 -0
- package/dist/safe-bash-zip-engine/zip/help.d.ts +4 -0
- package/dist/safe-bash-zip-engine/zip/help.js +194 -0
- package/dist/safe-bash-zip-engine/zip/line-endings.d.ts +2 -0
- package/dist/safe-bash-zip-engine/zip/line-endings.js +165 -0
- package/dist/safe-bash-zip-engine/zip/log.d.ts +22 -0
- package/dist/safe-bash-zip-engine/zip/log.js +153 -0
- package/dist/safe-bash-zip-engine/zip/lzma.d.ts +9 -0
- package/dist/safe-bash-zip-engine/zip/lzma.js +7 -0
- package/dist/safe-bash-zip-engine/zip/move.d.ts +11 -0
- package/dist/safe-bash-zip-engine/zip/move.js +57 -0
- package/dist/safe-bash-zip-engine/zip/names.d.ts +2 -0
- package/dist/safe-bash-zip-engine/zip/names.js +37 -0
- package/dist/safe-bash-zip-engine/zip/options.d.ts +13 -0
- package/dist/safe-bash-zip-engine/zip/options.js +23 -0
- package/dist/safe-bash-zip-engine/zip/repair.d.ts +10 -0
- package/dist/safe-bash-zip-engine/zip/repair.js +348 -0
- package/dist/safe-bash-zip-engine/zip/safety.d.ts +54 -0
- package/dist/safe-bash-zip-engine/zip/safety.js +19 -0
- package/dist/safe-bash-zip-engine/zip/sfx.d.ts +4 -0
- package/dist/safe-bash-zip-engine/zip/sfx.js +58 -0
- package/dist/safe-bash-zip-engine/zip/test-command.d.ts +5 -0
- package/dist/safe-bash-zip-engine/zip/test-command.js +98 -0
- package/dist/safe-bash-zip-engine/zip/volumes.d.ts +21 -0
- package/dist/safe-bash-zip-engine/zip/volumes.js +255 -0
- package/dist/safe-bash-zip-engine/zip/zip64.d.ts +30 -0
- package/dist/safe-bash-zip-engine/zip/zip64.js +25 -0
- package/dist/safe-bash-zip-engine/zip-format.d.ts +68 -0
- package/dist/safe-bash-zip-engine/zip-format.js +27 -0
- package/dist/safe-playwright-cloudflare/browser-codegen.generated.d.ts +7 -7
- package/dist/safe-playwright-cloudflare/browser-codegen.generated.js +866 -8069
- package/dist/safe-playwright-cloudflare/browser-run-code-budget.d.ts +0 -1
- package/dist/safe-playwright-cloudflare/browser-run-code-budget.js +0 -2
- package/dist/safe-playwright-cloudflare/browser-trace-archive.d.ts +5 -1
- package/dist/safe-playwright-cloudflare/browser-trace-archive.js +2 -1
- package/dist/safe-playwright-cloudflare/browser-trace-budget.js +2 -2
- package/dist/safe-playwright-cloudflare/shell-browser-resource.d.ts +2 -0
- package/dist/safe-playwright-cloudflare/shell-browser-resource.js +3 -11
- package/dist/safe-playwright-cloudflare/shell-playwright.d.ts +2 -0
- package/dist/safe-playwright-cloudflare/shell-playwright.js +1 -1
- package/dist/spreadsheet-engine/io/publication.d.ts +1 -0
- package/package.json +163 -14
- package/dist/safe-bash/chunks/chunk-AZAJJVFX.js +0 -23017
- package/dist/safe-bash/chunks/chunk-O4ZUCRGN.js +0 -13
- package/dist/safe-bash/chunks/chunk-S264DZO2.js +0 -243
- package/dist/safe-bash/chunks/chunk-WVG5SHHQ.js +0 -12
- package/dist/safe-bash/chunks/chunk-ZW6K2J7P.js +0 -2652
- package/dist/safe-bash/command-chunks/chunk-5MPOQ6V3.js +0 -181
- package/dist/safe-bash/command-chunks/chunk-BIXLZ3OG.js +0 -14342
- package/dist/safe-bash/command-chunks/chunk-DUYJE2HY.js +0 -14
- package/dist/safe-bash/command-chunks/chunk-NETECMOF.js +0 -40
- package/dist/safe-bash/command-chunks/chunk-XS3PGJU2.js +0 -343
- package/dist/safe-bash/command-chunks/chunk-XTZALMLR.js +0 -488
- package/dist/safe-bash/commands/archive/zip/aes-primitives-unavailable.d.ts +0 -2
- package/dist/safe-bash/commands/archive/zip/aes-primitives-unavailable.js +0 -3
- package/dist/safe-bash/commands/archive/zip/aes-primitives.d.ts +0 -2
- package/dist/safe-bash/commands/archive/zip/aes-primitives.js +0 -3
- package/dist/safe-bash/commands/xml/document.d.ts +0 -2
- package/dist/safe-bash/commands/xml/document.js +0 -2
- package/dist/safe-bash/commands/xml/evaluate.d.ts +0 -2
- package/dist/safe-bash/commands/xml/evaluate.js +0 -2
- package/dist/safe-bash/commands/xml/json.d.ts +0 -2
- package/dist/safe-bash/commands/xml/json.js +0 -2
- package/dist/safe-bash/commands/xml/limits.d.ts +0 -2
- package/dist/safe-bash/commands/xml/limits.js +0 -2
- package/dist/safe-bash/commands/xml/query.d.ts +0 -2
- package/dist/safe-bash/commands/xml/query.js +0 -2
- package/dist/safe-bash/chunks/{chunk-NHOXKQNE.js → chunk-QVSRRNZT.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-FIUFIDAO.js → chunk-2JRBIDAD.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-B5BKA5WH.js → chunk-B5TAOCKD.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-TYVCKQDH.js → chunk-J5SN3PZ3.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-2ENZ6JGA.js → chunk-KEV7C3KH.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-S62HELHU.js → chunk-PL6O4K6W.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-2WRTLCGK.js → chunk-QZF3SINC.js} +4 -4
- package/dist/safe-bash/command-chunks/{chunk-X7TM3AKW.js → chunk-U6G67N23.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-DDLQ5YDB.js → chunk-YHFXOX6U.js} +9 -9
- package/dist/safe-bash/command-chunks/{chunk-DQMOM72Z.js → chunk-ZRRBXU3M.js} +4 -4
|
@@ -0,0 +1,2489 @@
|
|
|
1
|
+
import {
|
|
2
|
+
decodeString
|
|
3
|
+
} from "./chunk-L6DVEBW3.js";
|
|
4
|
+
import {
|
|
5
|
+
AwkPipes
|
|
6
|
+
} from "./chunk-DB453IE6.js";
|
|
7
|
+
import {
|
|
8
|
+
AwkArray,
|
|
9
|
+
SCALAR_ONE,
|
|
10
|
+
SCALAR_ZERO,
|
|
11
|
+
compare,
|
|
12
|
+
formatted,
|
|
13
|
+
inputValue,
|
|
14
|
+
inputValueFromSlice,
|
|
15
|
+
number,
|
|
16
|
+
numeric,
|
|
17
|
+
scalar,
|
|
18
|
+
string,
|
|
19
|
+
text,
|
|
20
|
+
truth,
|
|
21
|
+
unset
|
|
22
|
+
} from "./chunk-V6MSPQLA.js";
|
|
23
|
+
import {
|
|
24
|
+
Reader
|
|
25
|
+
} from "./chunk-7K6JYKPJ.js";
|
|
26
|
+
import {
|
|
27
|
+
init_buffer
|
|
28
|
+
} from "./chunk-HX3SHTCE.js";
|
|
29
|
+
|
|
30
|
+
// packages/safe-bash-command-awk/src/awk-runtime.ts
|
|
31
|
+
init_buffer();
|
|
32
|
+
import { tryReadMemoryFileViewSync } from "@poe-platform/safe-fs/core";
|
|
33
|
+
import { FsError, writeBytes } from "../../safe-bash-contracts/index.js";
|
|
34
|
+
import { writeFileOutput } from "../../safe-bash-contracts/filesystem-output.js";
|
|
35
|
+
import { isSyncResolved } from "../../safe-bash-contracts/runtime-control.js";
|
|
36
|
+
import { shellValueByteLength } from "../../safe-bash-contracts/value.js";
|
|
37
|
+
import { decodeBytes, encodeBytes, latin1Bytes, latin1Text } from "../../safe-bash-io-engine/byte-encoding.js";
|
|
38
|
+
import { ProgramError, byteString, bytes, input, virtualPath, write } from "../../safe-bash-io-engine/commands/text-programs/shared.js";
|
|
39
|
+
import { Pattern, substitute } from "../../safe-bash-regex-engine/text/regex.js";
|
|
40
|
+
import { TimeZone, nanosecondsPerSecond } from "../../safe-bash-calendar-engine/time-env/calendar.js";
|
|
41
|
+
import { formatDate } from "../../safe-bash-calendar-engine/time-env/format.js";
|
|
42
|
+
var textDecoder = new TextDecoder("utf-8", { ignoreBOM: true });
|
|
43
|
+
function textSize(value) {
|
|
44
|
+
return value && !(value instanceof AwkArray) && (value.kind === "string" || value.kind === "numeric") ? value.text.length : 0;
|
|
45
|
+
}
|
|
46
|
+
function isAsciiText(text2) {
|
|
47
|
+
for (let i = 0; i < text2.length; i++) {
|
|
48
|
+
if (text2.charCodeAt(i) > 127) return false;
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
function isOperandAssignment(text2) {
|
|
53
|
+
const eq = text2.indexOf("=");
|
|
54
|
+
if (eq <= 0) return false;
|
|
55
|
+
const c0 = text2.charCodeAt(0);
|
|
56
|
+
if (!(c0 >= 65 && c0 <= 90 || c0 >= 97 && c0 <= 122 || c0 === 95)) return false;
|
|
57
|
+
for (let i = 1; i < eq; i++) {
|
|
58
|
+
const c = text2.charCodeAt(i);
|
|
59
|
+
if (!(c >= 65 && c <= 90 || c >= 97 && c <= 122 || c >= 48 && c <= 57 || c === 95)) return false;
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
function ownScalar(value) {
|
|
64
|
+
if (value.kind === "string" || value.kind === "numeric") {
|
|
65
|
+
if (value.text.length < 13 && Object.isFrozen(value)) return value;
|
|
66
|
+
const ownedText = value.text.length >= 13 ? latin1Text(latin1Bytes(value.text)) : value.text;
|
|
67
|
+
return value.kind === "numeric" ? { kind: "numeric", text: ownedText, number: value.number } : { kind: "string", text: ownedText };
|
|
68
|
+
}
|
|
69
|
+
if (value.kind === "number" && !Object.isFrozen(value)) {
|
|
70
|
+
return { kind: "number", number: value.number };
|
|
71
|
+
}
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
74
|
+
var DEFAULT_VARIABLES = [
|
|
75
|
+
["FS", Object.freeze({ kind: "string", text: " " })],
|
|
76
|
+
["RS", Object.freeze({ kind: "string", text: "\n" })],
|
|
77
|
+
["OFS", Object.freeze({ kind: "string", text: " " })],
|
|
78
|
+
["ORS", Object.freeze({ kind: "string", text: "\n" })],
|
|
79
|
+
["OFMT", Object.freeze({ kind: "string", text: "%.6g" })],
|
|
80
|
+
["CONVFMT", Object.freeze({ kind: "string", text: "%.6g" })],
|
|
81
|
+
["SUBSEP", Object.freeze({ kind: "string", text: "" })],
|
|
82
|
+
["NR", numeric(0)],
|
|
83
|
+
["FNR", numeric(0)],
|
|
84
|
+
["NF", numeric(0)],
|
|
85
|
+
["FILENAME", string("")],
|
|
86
|
+
["RSTART", numeric(0)],
|
|
87
|
+
["RLENGTH", numeric(0)]
|
|
88
|
+
];
|
|
89
|
+
var AWK_ARGV0 = Object.freeze({ kind: "string", text: "awk" });
|
|
90
|
+
function hasMainGetline(node) {
|
|
91
|
+
if (!node || typeof node !== "object") return false;
|
|
92
|
+
if (node.kind === "getline" && !node.file && !node.pipe) return true;
|
|
93
|
+
return Object.values(node).some((child) => Array.isArray(child) ? child.some(hasMainGetline) : hasMainGetline(child));
|
|
94
|
+
}
|
|
95
|
+
var FAST_AWK_MATCH_OFFSETS = new Int32Array(20);
|
|
96
|
+
var RETURN_SCALAR_ZERO = () => SCALAR_ZERO;
|
|
97
|
+
var RETURN_SCALAR_ONE = () => SCALAR_ONE;
|
|
98
|
+
var RELEASED_AWK_SIGNAL = Object.freeze({
|
|
99
|
+
aborted: false,
|
|
100
|
+
reason: void 0,
|
|
101
|
+
onabort: null,
|
|
102
|
+
throwIfAborted() {
|
|
103
|
+
},
|
|
104
|
+
addEventListener() {
|
|
105
|
+
},
|
|
106
|
+
removeEventListener() {
|
|
107
|
+
},
|
|
108
|
+
dispatchEvent() {
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
var RELEASED_AWK_CONTEXT = Object.freeze({ signal: RELEASED_AWK_SIGNAL });
|
|
113
|
+
var _lastAwkArrayAnchor = new AwkArray();
|
|
114
|
+
var SMALL_ARG_KEYS = ["0", "1", "2", "3", "4", "5", "6", "7", "8"];
|
|
115
|
+
var Flow = class {
|
|
116
|
+
constructor(kind, value = unset) {
|
|
117
|
+
this.kind = kind;
|
|
118
|
+
this.value = value;
|
|
119
|
+
}
|
|
120
|
+
kind;
|
|
121
|
+
value;
|
|
122
|
+
};
|
|
123
|
+
var AwkRuntime = class {
|
|
124
|
+
constructor(program, context, budget, retention, args, assignments, separator, operandAssignments = true, ordchr = false, inspection) {
|
|
125
|
+
this.program = program;
|
|
126
|
+
this.context = context;
|
|
127
|
+
this.budget = budget;
|
|
128
|
+
this.retention = retention;
|
|
129
|
+
this.operandAssignments = operandAssignments;
|
|
130
|
+
this.ordchr = ordchr;
|
|
131
|
+
this.inspection = inspection;
|
|
132
|
+
this.fieldStarts = new Array(64).fill(0);
|
|
133
|
+
this.fieldEnds = new Array(64).fill(0);
|
|
134
|
+
this.lazyFieldGen = new Array(64).fill(0);
|
|
135
|
+
this.lazyFields = new Array(64);
|
|
136
|
+
this.fieldGeneration = 1;
|
|
137
|
+
try {
|
|
138
|
+
for (let i = 0; i < DEFAULT_VARIABLES.length; i++) {
|
|
139
|
+
const pair = DEFAULT_VARIABLES[i];
|
|
140
|
+
this.storeScalar(this.variables, pair[0], pair[1]);
|
|
141
|
+
}
|
|
142
|
+
this.storeScalar(this.variables, "ARGC", numeric(args.length + 1));
|
|
143
|
+
if (inspection !== void 0 || retention.capacity <= 65536 || budget.options.maxArrayEntries !== void 0 || budget.options.maxBufferBytes !== void 0 || budget.options.maxRetainedBytes !== void 0) {
|
|
144
|
+
this.ensureEnviron();
|
|
145
|
+
}
|
|
146
|
+
const argv = this.array("ARGV");
|
|
147
|
+
this.arraySet(argv, "0", AWK_ARGV0);
|
|
148
|
+
for (let index = 0; index < args.length; index++) {
|
|
149
|
+
const k = index + 1 < SMALL_ARG_KEYS.length ? SMALL_ARG_KEYS[index + 1] : String(index + 1);
|
|
150
|
+
this.arraySet(argv, k, inputValue(byteString(args[index])));
|
|
151
|
+
}
|
|
152
|
+
if (separator !== void 0) this.set("FS", string(separator));
|
|
153
|
+
for (const assignment of assignments) this.assignment(assignment);
|
|
154
|
+
} catch (error) {
|
|
155
|
+
this.releaseStore(this.variables);
|
|
156
|
+
throw error;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
program;
|
|
160
|
+
context;
|
|
161
|
+
budget;
|
|
162
|
+
retention;
|
|
163
|
+
operandAssignments;
|
|
164
|
+
ordchr;
|
|
165
|
+
inspection;
|
|
166
|
+
variables = /* @__PURE__ */ new Map();
|
|
167
|
+
frames = [];
|
|
168
|
+
arrays = /* @__PURE__ */ new Map();
|
|
169
|
+
regexes;
|
|
170
|
+
outputs;
|
|
171
|
+
inputs;
|
|
172
|
+
pipes;
|
|
173
|
+
environInitialized = false;
|
|
174
|
+
mainReader;
|
|
175
|
+
argument = 1;
|
|
176
|
+
sawFile = false;
|
|
177
|
+
defaultUsed = false;
|
|
178
|
+
rawFields = [];
|
|
179
|
+
get fields() {
|
|
180
|
+
return this.ensureFields();
|
|
181
|
+
}
|
|
182
|
+
set fields(v) {
|
|
183
|
+
this.rawFields = v;
|
|
184
|
+
}
|
|
185
|
+
fieldStarts;
|
|
186
|
+
fieldEnds;
|
|
187
|
+
fieldCount = 0;
|
|
188
|
+
deferredFieldSeparator = " ";
|
|
189
|
+
fieldsMaterialized = true;
|
|
190
|
+
fieldGeneration;
|
|
191
|
+
lazyFieldGen;
|
|
192
|
+
lazyFields;
|
|
193
|
+
fieldBytes = 0;
|
|
194
|
+
rawRecord = "";
|
|
195
|
+
recordSource = "";
|
|
196
|
+
recordStart = 0;
|
|
197
|
+
recordEnd = 0;
|
|
198
|
+
get record() {
|
|
199
|
+
return this.rawRecord ??= this.recordSource.slice(this.recordStart, this.recordEnd);
|
|
200
|
+
}
|
|
201
|
+
set record(v) {
|
|
202
|
+
this.rawRecord = v;
|
|
203
|
+
this.recordSource = v;
|
|
204
|
+
this.recordStart = 0;
|
|
205
|
+
this.recordEnd = v.length;
|
|
206
|
+
}
|
|
207
|
+
get recordLength() {
|
|
208
|
+
return this.rawRecord !== void 0 ? this.rawRecord.length : this.recordEnd - this.recordStart;
|
|
209
|
+
}
|
|
210
|
+
sliceBox = { source: "", start: 0, end: 0 };
|
|
211
|
+
recordValue = string("");
|
|
212
|
+
entries = 0;
|
|
213
|
+
fsText = " ";
|
|
214
|
+
rsText = "\n";
|
|
215
|
+
convfmtText = "%.6g";
|
|
216
|
+
nrNum = 0;
|
|
217
|
+
nrDirty = false;
|
|
218
|
+
fnrNum = 0;
|
|
219
|
+
fnrDirty = false;
|
|
220
|
+
nfNum = 0;
|
|
221
|
+
nfDirty = false;
|
|
222
|
+
phase = "BEGIN";
|
|
223
|
+
status = 0;
|
|
224
|
+
randomSeed = 1;
|
|
225
|
+
randomState = 1;
|
|
226
|
+
ensureEnviron() {
|
|
227
|
+
if (this.environInitialized) return;
|
|
228
|
+
this.environInitialized = true;
|
|
229
|
+
const environment = new AwkArray();
|
|
230
|
+
this.bindArray(this.variables, "ENVIRON", environment);
|
|
231
|
+
for (const [name, value] of Object.entries(this.context.env)) {
|
|
232
|
+
this.arraySet(environment, byteString(name), inputValue(byteString(value)));
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
store(name) {
|
|
236
|
+
return this.frames.at(-1)?.has(name) ? this.frames.at(-1) : this.variables;
|
|
237
|
+
}
|
|
238
|
+
syncSpecialVars() {
|
|
239
|
+
if (this.nrDirty) {
|
|
240
|
+
this.nrDirty = false;
|
|
241
|
+
this.storeScalar(this.variables, "NR", numeric(this.nrNum));
|
|
242
|
+
}
|
|
243
|
+
if (this.fnrDirty) {
|
|
244
|
+
this.fnrDirty = false;
|
|
245
|
+
this.storeScalar(this.variables, "FNR", numeric(this.fnrNum));
|
|
246
|
+
}
|
|
247
|
+
if (this.nfDirty) {
|
|
248
|
+
if (this.fieldCount < 0) this.ensureSliceFieldsSplit();
|
|
249
|
+
this.nfDirty = false;
|
|
250
|
+
this.storeScalar(this.variables, "NF", numeric(this.nfNum));
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
get(name) {
|
|
254
|
+
if (this.frames.length === 0 || !this.frames.at(-1).has(name)) {
|
|
255
|
+
if (name === "NR" && this.nrDirty) {
|
|
256
|
+
this.nrDirty = false;
|
|
257
|
+
this.storeScalar(this.variables, "NR", numeric(this.nrNum));
|
|
258
|
+
} else if (name === "FNR" && this.fnrDirty) {
|
|
259
|
+
this.fnrDirty = false;
|
|
260
|
+
this.storeScalar(this.variables, "FNR", numeric(this.fnrNum));
|
|
261
|
+
} else if (name === "NF" && this.nfDirty) {
|
|
262
|
+
if (this.fieldCount < 0) this.ensureSliceFieldsSplit();
|
|
263
|
+
this.nfDirty = false;
|
|
264
|
+
this.storeScalar(this.variables, "NF", numeric(this.nfNum));
|
|
265
|
+
} else if (name === "ENVIRON" && !this.environInitialized) this.ensureEnviron();
|
|
266
|
+
}
|
|
267
|
+
return this.store(name).get(name) ?? unset;
|
|
268
|
+
}
|
|
269
|
+
getScalar(name) {
|
|
270
|
+
return scalar(this.get(name));
|
|
271
|
+
}
|
|
272
|
+
asText(value) {
|
|
273
|
+
if (value.kind === "string" || value.kind === "numeric") return value.text;
|
|
274
|
+
if (value.kind === "unset") return "";
|
|
275
|
+
return text(value, text(this.getScalar("CONVFMT"), void 0, this.budget), this.budget);
|
|
276
|
+
}
|
|
277
|
+
varText(name) {
|
|
278
|
+
if (this.frames.length === 0) {
|
|
279
|
+
if (name === "FS") return this.fsText;
|
|
280
|
+
if (name === "RS") return this.rsText;
|
|
281
|
+
if (name === "CONVFMT") return this.convfmtText;
|
|
282
|
+
}
|
|
283
|
+
return this.asText(this.getScalar(name));
|
|
284
|
+
}
|
|
285
|
+
retainName(path) {
|
|
286
|
+
this.context.signal.throwIfAborted();
|
|
287
|
+
return this.retention.replace(0, shellValueByteLength(path), () => path.split("").join(""));
|
|
288
|
+
}
|
|
289
|
+
storeScalar(store, name, value) {
|
|
290
|
+
if (value.kind === "string" || value.kind === "numeric") this.budget.check(value.text);
|
|
291
|
+
this.retention.admit(textSize(store.get(name)), textSize(value));
|
|
292
|
+
const owned = ownScalar(value);
|
|
293
|
+
store.set(name, owned);
|
|
294
|
+
if (store === this.variables) {
|
|
295
|
+
if (name === "FS") this.fsText = this.asText(owned);
|
|
296
|
+
else if (name === "RS") this.rsText = this.asText(owned);
|
|
297
|
+
else if (name === "CONVFMT") this.convfmtText = this.asText(owned);
|
|
298
|
+
else if (name === "NR") {
|
|
299
|
+
this.nrNum = number(owned);
|
|
300
|
+
this.nrDirty = false;
|
|
301
|
+
} else if (name === "FNR") {
|
|
302
|
+
this.fnrNum = number(owned);
|
|
303
|
+
this.fnrDirty = false;
|
|
304
|
+
} else if (name === "NF") {
|
|
305
|
+
this.nfNum = number(owned);
|
|
306
|
+
this.nfDirty = false;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
bindArray(store, name, array) {
|
|
311
|
+
let allocation = this.arrays.get(array);
|
|
312
|
+
if (!allocation) {
|
|
313
|
+
allocation = { bytes: 0, references: 0 };
|
|
314
|
+
this.arrays.set(array, allocation);
|
|
315
|
+
}
|
|
316
|
+
allocation.references++;
|
|
317
|
+
store.set(name, array);
|
|
318
|
+
}
|
|
319
|
+
releaseStore(store) {
|
|
320
|
+
for (const value of store.values()) {
|
|
321
|
+
if (value instanceof AwkArray) {
|
|
322
|
+
const allocation = this.arrays.get(value);
|
|
323
|
+
if (--allocation.references === 0) {
|
|
324
|
+
this.retention.release(allocation.bytes);
|
|
325
|
+
this.entries -= value.entries.size;
|
|
326
|
+
this.arrays.delete(value);
|
|
327
|
+
}
|
|
328
|
+
} else this.retention.release(textSize(value));
|
|
329
|
+
}
|
|
330
|
+
store.clear();
|
|
331
|
+
}
|
|
332
|
+
set(name, value) {
|
|
333
|
+
if (this.get(name) instanceof AwkArray) throw new ProgramError(`cannot assign a scalar to array '${name}'`);
|
|
334
|
+
if (name === "NF" && this.store(name) === this.variables) {
|
|
335
|
+
const length = Math.trunc(number(value));
|
|
336
|
+
if (!Number.isSafeInteger(length) || length < 0 || length > (this.budget.options.maxFields ?? Infinity)) throw new ProgramError("invalid or excessive NF");
|
|
337
|
+
const fields = this.ensureFields().slice(0, length);
|
|
338
|
+
while (fields.length < length) fields.push(string(""));
|
|
339
|
+
this.rebuild(fields);
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
this.storeScalar(this.store(name), name, value);
|
|
343
|
+
}
|
|
344
|
+
setNumber(name, n) {
|
|
345
|
+
const valNum = (n | 0) === n && (n !== 0 || 1 / n > 0) ? n | 0 : n;
|
|
346
|
+
const store = this.store(name);
|
|
347
|
+
if (name === "NF" && store === this.variables) {
|
|
348
|
+
const val = numeric(valNum);
|
|
349
|
+
this.set(name, val);
|
|
350
|
+
return val;
|
|
351
|
+
}
|
|
352
|
+
const existing = store.get(name);
|
|
353
|
+
if (existing instanceof AwkArray) throw new ProgramError(`cannot assign a scalar to array '${name}'`);
|
|
354
|
+
this.retention.admit(textSize(existing), 0);
|
|
355
|
+
const box = numeric(valNum);
|
|
356
|
+
store.set(name, box);
|
|
357
|
+
if (store === this.variables) {
|
|
358
|
+
if (name === "FS") this.fsText = this.asText(box);
|
|
359
|
+
else if (name === "RS") this.rsText = this.asText(box);
|
|
360
|
+
else if (name === "CONVFMT") this.convfmtText = this.asText(box);
|
|
361
|
+
else if (name === "NR") {
|
|
362
|
+
this.nrNum = valNum;
|
|
363
|
+
this.nrDirty = false;
|
|
364
|
+
} else if (name === "FNR") {
|
|
365
|
+
this.fnrNum = valNum;
|
|
366
|
+
this.fnrDirty = false;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
return box;
|
|
370
|
+
}
|
|
371
|
+
array(name) {
|
|
372
|
+
const value = this.get(name);
|
|
373
|
+
if (value instanceof AwkArray) return value;
|
|
374
|
+
if (value.kind !== "unset") throw new ProgramError(`scalar '${name}' used as an array`);
|
|
375
|
+
const array = new AwkArray();
|
|
376
|
+
this.bindArray(this.store(name), name, array);
|
|
377
|
+
return array;
|
|
378
|
+
}
|
|
379
|
+
arraySet(array, key, value) {
|
|
380
|
+
this.budget.check(key);
|
|
381
|
+
if (value.kind === "string" || value.kind === "numeric") this.budget.check(value.text);
|
|
382
|
+
const existingValue = array.entries.get(key);
|
|
383
|
+
if (existingValue !== void 0 && existingValue.kind === "number" && value.kind === "number") {
|
|
384
|
+
if (this.budget.context.signal.aborted) this.budget.context.signal.throwIfAborted();
|
|
385
|
+
array.entries.set(key, ownScalar(value));
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
const existing = existingValue !== void 0 || array.entries.has(key);
|
|
389
|
+
if (!existing && this.entries >= (this.budget.options.maxArrayEntries ?? Infinity)) throw new ProgramError("array entry limit exceeded");
|
|
390
|
+
const previous = textSize(existingValue), next = textSize(value) + (existing ? 0 : key.length);
|
|
391
|
+
this.retention.admit(previous, next);
|
|
392
|
+
const ownedKey = existing || key.length < 13 ? key : latin1Text(latin1Bytes(key));
|
|
393
|
+
array.entries.set(ownedKey, ownScalar(value));
|
|
394
|
+
if (next !== previous) this.arrays.get(array).bytes += next - previous;
|
|
395
|
+
if (!existing) this.entries++;
|
|
396
|
+
}
|
|
397
|
+
pattern(source) {
|
|
398
|
+
const map = this.regexes ??= /* @__PURE__ */ new Map();
|
|
399
|
+
let pattern = map.get(source);
|
|
400
|
+
if (!pattern) {
|
|
401
|
+
pattern = new Pattern(source, true, false, "awk");
|
|
402
|
+
if (map.size >= 256) map.delete(map.keys().next().value);
|
|
403
|
+
map.set(source, pattern);
|
|
404
|
+
}
|
|
405
|
+
return pattern;
|
|
406
|
+
}
|
|
407
|
+
async regex(expression) {
|
|
408
|
+
return expression.kind === "regex" ? expression.pattern : this.pattern(this.asText(await this.scalarExpression(expression)));
|
|
409
|
+
}
|
|
410
|
+
splitSync(value, separator, paragraph) {
|
|
411
|
+
if (!paragraph && value.length < 256 && (separator === " " || separator.length === 1)) {
|
|
412
|
+
this.budget.step(value.length);
|
|
413
|
+
const maxFields = this.budget.options.maxFields ?? Infinity;
|
|
414
|
+
const parts = [];
|
|
415
|
+
if (separator === " ") {
|
|
416
|
+
let start = -1;
|
|
417
|
+
for (let index = 0; index < value.length; index++) {
|
|
418
|
+
const ch = value.charCodeAt(index);
|
|
419
|
+
if (ch === 32 || ch === 9 || ch === 10) {
|
|
420
|
+
if (start >= 0) {
|
|
421
|
+
if (parts.length >= maxFields) throw new ProgramError("field count limit exceeded");
|
|
422
|
+
parts.push(inputValue(value.slice(start, index)));
|
|
423
|
+
start = -1;
|
|
424
|
+
}
|
|
425
|
+
} else if (start < 0) start = index;
|
|
426
|
+
}
|
|
427
|
+
if (start >= 0) {
|
|
428
|
+
if (parts.length >= maxFields) throw new ProgramError("field count limit exceeded");
|
|
429
|
+
parts.push(inputValue(value.slice(start, value.length)));
|
|
430
|
+
}
|
|
431
|
+
return parts;
|
|
432
|
+
}
|
|
433
|
+
if (value !== "") {
|
|
434
|
+
let start = 0;
|
|
435
|
+
let idx;
|
|
436
|
+
while ((idx = value.indexOf(separator, start)) >= 0) {
|
|
437
|
+
if (parts.length >= maxFields) throw new ProgramError("field count limit exceeded");
|
|
438
|
+
parts.push(inputValue(value.slice(start, idx)));
|
|
439
|
+
start = idx + 1;
|
|
440
|
+
}
|
|
441
|
+
if (parts.length >= maxFields) throw new ProgramError("field count limit exceeded");
|
|
442
|
+
parts.push(inputValue(value.slice(start, value.length)));
|
|
443
|
+
}
|
|
444
|
+
return parts;
|
|
445
|
+
}
|
|
446
|
+
return this.split(value, separator, paragraph);
|
|
447
|
+
}
|
|
448
|
+
async split(value, separator, paragraph = false) {
|
|
449
|
+
this.budget.step(value.length);
|
|
450
|
+
const parts = [];
|
|
451
|
+
const append = (start, end) => {
|
|
452
|
+
if (parts.length >= (this.budget.options.maxFields ?? Infinity)) throw new ProgramError("field count limit exceeded");
|
|
453
|
+
parts.push(inputValue(value.slice(start, end)));
|
|
454
|
+
};
|
|
455
|
+
if (separator === " ") {
|
|
456
|
+
let start = -1;
|
|
457
|
+
for (let index = 0; index < value.length; index++) {
|
|
458
|
+
if (index % 256 === 0) await this.budget.checkpointSync();
|
|
459
|
+
if (" \n".includes(value[index])) {
|
|
460
|
+
if (start >= 0) {
|
|
461
|
+
append(start, index);
|
|
462
|
+
start = -1;
|
|
463
|
+
}
|
|
464
|
+
} else if (start < 0) start = index;
|
|
465
|
+
}
|
|
466
|
+
if (start >= 0) append(start, value.length);
|
|
467
|
+
} else if (separator === "") {
|
|
468
|
+
if (value.length > (this.budget.options.maxFields ?? Infinity)) throw new ProgramError("field count limit exceeded");
|
|
469
|
+
for (let index = 0; index < value.length; index++) {
|
|
470
|
+
if (index % 256 === 0) await this.budget.checkpointSync();
|
|
471
|
+
append(index, index + 1);
|
|
472
|
+
}
|
|
473
|
+
} else if (typeof separator === "string" && separator.length === 1) {
|
|
474
|
+
if (!paragraph && value.length < 256) {
|
|
475
|
+
if (value !== "") {
|
|
476
|
+
let start2 = 0;
|
|
477
|
+
let idx;
|
|
478
|
+
while ((idx = value.indexOf(separator, start2)) >= 0) {
|
|
479
|
+
append(start2, idx);
|
|
480
|
+
start2 = idx + 1;
|
|
481
|
+
}
|
|
482
|
+
append(start2, value.length);
|
|
483
|
+
}
|
|
484
|
+
return parts;
|
|
485
|
+
}
|
|
486
|
+
let start = 0;
|
|
487
|
+
for (let index = 0; index < value.length; index++) {
|
|
488
|
+
if (index > 0 && index % 256 === 0) {
|
|
489
|
+
const p = this.budget.checkpointSync();
|
|
490
|
+
if (p) await p;
|
|
491
|
+
}
|
|
492
|
+
if (value[index] === separator || paragraph && value[index] === "\n") {
|
|
493
|
+
append(start, index);
|
|
494
|
+
start = index + 1;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
if (value !== "") append(start, value.length);
|
|
498
|
+
} else {
|
|
499
|
+
const matcher = typeof separator === "string" ? this.pattern(separator) : separator;
|
|
500
|
+
const segment = async (start, end) => {
|
|
501
|
+
if (paragraph) for (let index = start; index < end; index++) {
|
|
502
|
+
if (index % 256 === 0) await this.budget.checkpointSync();
|
|
503
|
+
if (value[index] === "\n") {
|
|
504
|
+
append(start, index);
|
|
505
|
+
start = index + 1;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
append(start, end);
|
|
509
|
+
};
|
|
510
|
+
let consumed = 0;
|
|
511
|
+
let search = 0;
|
|
512
|
+
while (search <= value.length) {
|
|
513
|
+
await this.budget.checkpointSync();
|
|
514
|
+
const match = await matcher.find(value, this.budget, search);
|
|
515
|
+
if (!match) break;
|
|
516
|
+
if (match.start === match.end) {
|
|
517
|
+
search = match.end + 1;
|
|
518
|
+
continue;
|
|
519
|
+
}
|
|
520
|
+
await segment(consumed, match.start);
|
|
521
|
+
consumed = match.end;
|
|
522
|
+
search = match.end;
|
|
523
|
+
}
|
|
524
|
+
if (value !== "") await segment(consumed, value.length);
|
|
525
|
+
}
|
|
526
|
+
return parts;
|
|
527
|
+
}
|
|
528
|
+
parseSliceNumber(record, start, end) {
|
|
529
|
+
const len = end - start;
|
|
530
|
+
if (len <= 0) return 0;
|
|
531
|
+
const first = record.charCodeAt(start);
|
|
532
|
+
if (first >= 48 && first <= 57 && len <= 9) {
|
|
533
|
+
let num = first - 48 | 0;
|
|
534
|
+
for (let i = start + 1; i < end; i++) {
|
|
535
|
+
const c = record.charCodeAt(i);
|
|
536
|
+
if (c < 48 || c > 57) {
|
|
537
|
+
return number(inputValueFromSlice(record, start, end));
|
|
538
|
+
}
|
|
539
|
+
num = Math.imul(num, 10) + (c - 48) | 0;
|
|
540
|
+
}
|
|
541
|
+
return num;
|
|
542
|
+
}
|
|
543
|
+
if (first >= 48 && first <= 57 && len <= 15) {
|
|
544
|
+
let num = first - 48;
|
|
545
|
+
for (let i = start + 1; i < end; i++) {
|
|
546
|
+
const c = record.charCodeAt(i);
|
|
547
|
+
if (c < 48 || c > 57) {
|
|
548
|
+
return number(inputValueFromSlice(record, start, end));
|
|
549
|
+
}
|
|
550
|
+
num = num * 10 + (c - 48);
|
|
551
|
+
}
|
|
552
|
+
return num;
|
|
553
|
+
}
|
|
554
|
+
return number(inputValueFromSlice(record, start, end));
|
|
555
|
+
}
|
|
556
|
+
getFieldNumber(index) {
|
|
557
|
+
if (index === 0) return number(this.getField(0));
|
|
558
|
+
const slot = index - 1;
|
|
559
|
+
if (this.fieldsMaterialized) {
|
|
560
|
+
const f = this.rawFields[slot];
|
|
561
|
+
return f ? number(f) : 0;
|
|
562
|
+
}
|
|
563
|
+
if (this.fieldCount < 0) {
|
|
564
|
+
const sep = this.deferredFieldSeparator;
|
|
565
|
+
if (sep.length === 1 && sep !== " ") {
|
|
566
|
+
const source = this.recordSource;
|
|
567
|
+
const recEnd = this.recordEnd;
|
|
568
|
+
let start = this.recordStart;
|
|
569
|
+
if (start >= recEnd) return 0;
|
|
570
|
+
for (let s = 0; s < slot; s++) {
|
|
571
|
+
const idx = source.indexOf(sep, start);
|
|
572
|
+
if (idx < 0 || idx >= recEnd) return 0;
|
|
573
|
+
start = idx + 1;
|
|
574
|
+
}
|
|
575
|
+
const nextIdx = source.indexOf(sep, start);
|
|
576
|
+
const end = nextIdx >= 0 && nextIdx < recEnd ? nextIdx : recEnd;
|
|
577
|
+
return this.parseSliceNumber(source, start, end);
|
|
578
|
+
}
|
|
579
|
+
this.ensureSliceFieldsSplit();
|
|
580
|
+
}
|
|
581
|
+
if (slot < 0 || slot >= this.fieldCount) return 0;
|
|
582
|
+
if (this.lazyFieldGen[slot] === this.fieldGeneration) {
|
|
583
|
+
return number(this.lazyFields[slot]);
|
|
584
|
+
}
|
|
585
|
+
return this.parseSliceNumber(this.recordSource, this.fieldStarts[slot], this.fieldEnds[slot]);
|
|
586
|
+
}
|
|
587
|
+
getField(index) {
|
|
588
|
+
if (index === 0) {
|
|
589
|
+
return this.recordValue ??= inputValue(this.record);
|
|
590
|
+
}
|
|
591
|
+
if (this.fieldCount < 0) this.ensureSliceFieldsSplit();
|
|
592
|
+
const slot = index - 1;
|
|
593
|
+
if (this.fieldsMaterialized) {
|
|
594
|
+
return this.rawFields[slot] ?? string("");
|
|
595
|
+
}
|
|
596
|
+
if (slot < 0 || slot >= this.fieldCount) return string("");
|
|
597
|
+
if (this.lazyFieldGen[slot] === this.fieldGeneration) {
|
|
598
|
+
return this.lazyFields[slot];
|
|
599
|
+
}
|
|
600
|
+
const val = inputValueFromSlice(this.recordSource, this.fieldStarts[slot], this.fieldEnds[slot]);
|
|
601
|
+
this.lazyFieldGen[slot] = this.fieldGeneration;
|
|
602
|
+
this.lazyFields[slot] = val;
|
|
603
|
+
return val;
|
|
604
|
+
}
|
|
605
|
+
ensureFields() {
|
|
606
|
+
if (this.fieldCount < 0) this.ensureSliceFieldsSplit();
|
|
607
|
+
if (!this.fieldsMaterialized) {
|
|
608
|
+
const out = new Array(this.fieldCount);
|
|
609
|
+
for (let i = 0; i < this.fieldCount; i++) {
|
|
610
|
+
out[i] = this.lazyFieldGen[i] === this.fieldGeneration ? this.lazyFields[i] : inputValueFromSlice(this.recordSource, this.fieldStarts[i], this.fieldEnds[i]);
|
|
611
|
+
}
|
|
612
|
+
this.rawFields = out;
|
|
613
|
+
this.fieldsMaterialized = true;
|
|
614
|
+
}
|
|
615
|
+
return this.rawFields;
|
|
616
|
+
}
|
|
617
|
+
ensureSliceFieldsSplit() {
|
|
618
|
+
if (this.fieldCount >= 0) return;
|
|
619
|
+
const source = this.recordSource;
|
|
620
|
+
const recStart = this.recordStart;
|
|
621
|
+
const recEnd = this.recordEnd;
|
|
622
|
+
const recLen = recEnd - recStart;
|
|
623
|
+
const separator = this.deferredFieldSeparator;
|
|
624
|
+
let count = 0;
|
|
625
|
+
let fieldBytes = 0;
|
|
626
|
+
const starts = this.fieldStarts;
|
|
627
|
+
const ends = this.fieldEnds;
|
|
628
|
+
if (separator === " ") {
|
|
629
|
+
let start = -1;
|
|
630
|
+
for (let index = recStart; index < recEnd; index++) {
|
|
631
|
+
const ch = source.charCodeAt(index);
|
|
632
|
+
if (ch === 32 || ch === 9 || ch === 10) {
|
|
633
|
+
if (start >= 0) {
|
|
634
|
+
starts[count] = start;
|
|
635
|
+
ends[count] = index;
|
|
636
|
+
fieldBytes += index - start;
|
|
637
|
+
count++;
|
|
638
|
+
start = -1;
|
|
639
|
+
}
|
|
640
|
+
} else if (start < 0) start = index;
|
|
641
|
+
}
|
|
642
|
+
if (start >= 0) {
|
|
643
|
+
starts[count] = start;
|
|
644
|
+
ends[count] = recEnd;
|
|
645
|
+
fieldBytes += recEnd - start;
|
|
646
|
+
count++;
|
|
647
|
+
}
|
|
648
|
+
} else if (recLen > 0) {
|
|
649
|
+
let start = recStart;
|
|
650
|
+
let idx;
|
|
651
|
+
while ((idx = source.indexOf(separator, start)) >= 0 && idx < recEnd) {
|
|
652
|
+
starts[count] = start;
|
|
653
|
+
ends[count] = idx;
|
|
654
|
+
fieldBytes += idx - start;
|
|
655
|
+
count++;
|
|
656
|
+
start = idx + 1;
|
|
657
|
+
}
|
|
658
|
+
starts[count] = start;
|
|
659
|
+
ends[count] = recEnd;
|
|
660
|
+
fieldBytes += recEnd - start;
|
|
661
|
+
count++;
|
|
662
|
+
}
|
|
663
|
+
this.retention.admit(0, fieldBytes);
|
|
664
|
+
this.fieldBytes = fieldBytes;
|
|
665
|
+
this.fieldCount = count;
|
|
666
|
+
this.nfNum = count;
|
|
667
|
+
}
|
|
668
|
+
setRecordSliceSync(source, recStart, recEnd) {
|
|
669
|
+
const recLen = recEnd - recStart;
|
|
670
|
+
if (recLen > this.budget.maxBufferBytes) throw new ProgramError("text buffer limit exceeded");
|
|
671
|
+
const separator = this.varText("FS");
|
|
672
|
+
const paragraph = this.varText("RS") === "";
|
|
673
|
+
const maxFields = this.budget.options.maxFields ?? Infinity;
|
|
674
|
+
if (!paragraph && recLen < 256 && (separator === " " || separator.length === 1) && maxFields >= 64) {
|
|
675
|
+
this.budget.step(recLen);
|
|
676
|
+
if (recLen < 64 && this.retention.capacity === Infinity) {
|
|
677
|
+
this.retention.admit(this.recordLength + this.fieldBytes, recLen);
|
|
678
|
+
this.rawRecord = void 0;
|
|
679
|
+
this.recordSource = source;
|
|
680
|
+
this.recordStart = recStart;
|
|
681
|
+
this.recordEnd = recEnd;
|
|
682
|
+
this.fieldBytes = 0;
|
|
683
|
+
this.fieldCount = -1;
|
|
684
|
+
this.deferredFieldSeparator = separator;
|
|
685
|
+
this.fieldsMaterialized = false;
|
|
686
|
+
this.fieldGeneration = this.fieldGeneration + 1 | 0 || 1;
|
|
687
|
+
this.recordValue = void 0;
|
|
688
|
+
this.nfDirty = true;
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
691
|
+
let count = 0;
|
|
692
|
+
let fieldBytes = 0;
|
|
693
|
+
const starts = this.fieldStarts;
|
|
694
|
+
const ends = this.fieldEnds;
|
|
695
|
+
if (separator === " ") {
|
|
696
|
+
let start = -1;
|
|
697
|
+
for (let index = recStart; index < recEnd; index++) {
|
|
698
|
+
const ch = source.charCodeAt(index);
|
|
699
|
+
if (ch === 32 || ch === 9 || ch === 10) {
|
|
700
|
+
if (start >= 0) {
|
|
701
|
+
if (count >= maxFields || count >= 64) return this.setRecordSlow(source.slice(recStart, recEnd), separator, paragraph);
|
|
702
|
+
starts[count] = start;
|
|
703
|
+
ends[count] = index;
|
|
704
|
+
fieldBytes += index - start;
|
|
705
|
+
count++;
|
|
706
|
+
start = -1;
|
|
707
|
+
}
|
|
708
|
+
} else if (start < 0) start = index;
|
|
709
|
+
}
|
|
710
|
+
if (start >= 0) {
|
|
711
|
+
if (count >= maxFields || count >= 64) return this.setRecordSlow(source.slice(recStart, recEnd), separator, paragraph);
|
|
712
|
+
starts[count] = start;
|
|
713
|
+
ends[count] = recEnd;
|
|
714
|
+
fieldBytes += recEnd - start;
|
|
715
|
+
count++;
|
|
716
|
+
}
|
|
717
|
+
} else if (recLen > 0) {
|
|
718
|
+
let start = recStart;
|
|
719
|
+
let idx;
|
|
720
|
+
while ((idx = source.indexOf(separator, start)) >= 0 && idx < recEnd) {
|
|
721
|
+
if (count >= maxFields || count >= 64) return this.setRecordSlow(source.slice(recStart, recEnd), separator, paragraph);
|
|
722
|
+
starts[count] = start;
|
|
723
|
+
ends[count] = idx;
|
|
724
|
+
fieldBytes += idx - start;
|
|
725
|
+
count++;
|
|
726
|
+
start = idx + 1;
|
|
727
|
+
}
|
|
728
|
+
if (count >= maxFields || count >= 64) return this.setRecordSlow(source.slice(recStart, recEnd), separator, paragraph);
|
|
729
|
+
starts[count] = start;
|
|
730
|
+
ends[count] = recEnd;
|
|
731
|
+
fieldBytes += recEnd - start;
|
|
732
|
+
count++;
|
|
733
|
+
}
|
|
734
|
+
this.retention.admit(this.recordLength + this.fieldBytes, recLen + fieldBytes);
|
|
735
|
+
this.rawRecord = void 0;
|
|
736
|
+
this.recordSource = source;
|
|
737
|
+
this.recordStart = recStart;
|
|
738
|
+
this.recordEnd = recEnd;
|
|
739
|
+
this.fieldBytes = fieldBytes;
|
|
740
|
+
this.fieldCount = count;
|
|
741
|
+
this.fieldsMaterialized = false;
|
|
742
|
+
this.fieldGeneration = this.fieldGeneration + 1 | 0 || 1;
|
|
743
|
+
this.recordValue = void 0;
|
|
744
|
+
this.nfNum = count;
|
|
745
|
+
this.nfDirty = true;
|
|
746
|
+
return;
|
|
747
|
+
}
|
|
748
|
+
return this.setRecordSlow(source.slice(recStart, recEnd), separator, paragraph);
|
|
749
|
+
}
|
|
750
|
+
setRecordSync(record, value) {
|
|
751
|
+
if (value === void 0) return this.setRecordSliceSync(record, 0, record.length);
|
|
752
|
+
this.budget.check(record);
|
|
753
|
+
const separator = this.varText("FS");
|
|
754
|
+
const paragraph = this.varText("RS") === "";
|
|
755
|
+
const maxFields = this.budget.options.maxFields ?? Infinity;
|
|
756
|
+
if (value === void 0 && !paragraph && record.length < 256 && (separator === " " || separator.length === 1) && maxFields >= 64) {
|
|
757
|
+
this.budget.step(record.length);
|
|
758
|
+
let count = 0;
|
|
759
|
+
let fieldBytes = 0;
|
|
760
|
+
const starts = this.fieldStarts;
|
|
761
|
+
const ends = this.fieldEnds;
|
|
762
|
+
if (separator === " ") {
|
|
763
|
+
let start = -1;
|
|
764
|
+
for (let index = 0; index < record.length; index++) {
|
|
765
|
+
const ch = record.charCodeAt(index);
|
|
766
|
+
if (ch === 32 || ch === 9 || ch === 10) {
|
|
767
|
+
if (start >= 0) {
|
|
768
|
+
if (count >= maxFields || count >= 64) return this.setRecordSlow(record, separator, paragraph, value);
|
|
769
|
+
starts[count] = start;
|
|
770
|
+
ends[count] = index;
|
|
771
|
+
fieldBytes += index - start;
|
|
772
|
+
count++;
|
|
773
|
+
start = -1;
|
|
774
|
+
}
|
|
775
|
+
} else if (start < 0) start = index;
|
|
776
|
+
}
|
|
777
|
+
if (start >= 0) {
|
|
778
|
+
if (count >= maxFields || count >= 64) return this.setRecordSlow(record, separator, paragraph, value);
|
|
779
|
+
starts[count] = start;
|
|
780
|
+
ends[count] = record.length;
|
|
781
|
+
fieldBytes += record.length - start;
|
|
782
|
+
count++;
|
|
783
|
+
}
|
|
784
|
+
} else if (record !== "") {
|
|
785
|
+
let start = 0;
|
|
786
|
+
let idx;
|
|
787
|
+
while ((idx = record.indexOf(separator, start)) >= 0) {
|
|
788
|
+
if (count >= maxFields || count >= 64) return this.setRecordSlow(record, separator, paragraph, value);
|
|
789
|
+
starts[count] = start;
|
|
790
|
+
ends[count] = idx;
|
|
791
|
+
fieldBytes += idx - start;
|
|
792
|
+
count++;
|
|
793
|
+
start = idx + 1;
|
|
794
|
+
}
|
|
795
|
+
if (count >= maxFields || count >= 64) return this.setRecordSlow(record, separator, paragraph, value);
|
|
796
|
+
starts[count] = start;
|
|
797
|
+
ends[count] = record.length;
|
|
798
|
+
fieldBytes += record.length - start;
|
|
799
|
+
count++;
|
|
800
|
+
}
|
|
801
|
+
this.retention.admit(this.record.length + this.fieldBytes, record.length + fieldBytes);
|
|
802
|
+
this.record = record;
|
|
803
|
+
this.fieldBytes = fieldBytes;
|
|
804
|
+
this.fieldCount = count;
|
|
805
|
+
this.fieldsMaterialized = false;
|
|
806
|
+
this.fieldGeneration = this.fieldGeneration + 1 | 0 || 1;
|
|
807
|
+
this.recordValue = void 0;
|
|
808
|
+
this.variables.set("NF", numeric(count));
|
|
809
|
+
return;
|
|
810
|
+
}
|
|
811
|
+
return this.setRecordSlow(record, separator, paragraph, value);
|
|
812
|
+
}
|
|
813
|
+
setRecordSlow(record, separator, paragraph, value) {
|
|
814
|
+
const resolvedVal = value ?? inputValue(record);
|
|
815
|
+
const fields = this.splitSync(record, separator, paragraph);
|
|
816
|
+
if (!(fields instanceof Promise)) {
|
|
817
|
+
this.replaceRecord(record, fields, resolvedVal);
|
|
818
|
+
return;
|
|
819
|
+
}
|
|
820
|
+
return fields.then((resolved) => {
|
|
821
|
+
this.replaceRecord(record, resolved, resolvedVal);
|
|
822
|
+
});
|
|
823
|
+
}
|
|
824
|
+
async setRecord(record, value) {
|
|
825
|
+
await this.setRecordSync(record, value);
|
|
826
|
+
}
|
|
827
|
+
replaceRecord(record, fields, value = string(record)) {
|
|
828
|
+
let fieldBytes = 0;
|
|
829
|
+
for (const field of fields) {
|
|
830
|
+
if (field.kind === "string" || field.kind === "numeric") this.budget.check(field.text);
|
|
831
|
+
fieldBytes += textSize(field);
|
|
832
|
+
}
|
|
833
|
+
this.retention.admit(this.recordLength + this.fieldBytes, record.length + fieldBytes);
|
|
834
|
+
this.record = record;
|
|
835
|
+
this.fields = fields;
|
|
836
|
+
this.fieldCount = fields.length;
|
|
837
|
+
this.fieldsMaterialized = true;
|
|
838
|
+
this.fieldBytes = fieldBytes;
|
|
839
|
+
this.recordValue = value.kind === "string" || value.kind === "numeric" ? { ...value, text: this.record } : value;
|
|
840
|
+
this.nfNum = fields.length;
|
|
841
|
+
this.nfDirty = true;
|
|
842
|
+
}
|
|
843
|
+
join(parts, separator, suffix = "") {
|
|
844
|
+
this.budget.step(parts.length + 1);
|
|
845
|
+
let used = 0;
|
|
846
|
+
for (let index = 0; index < parts.length; index++) {
|
|
847
|
+
if (index > 0) {
|
|
848
|
+
if (separator.length > this.budget.maxBufferBytes - used) throw new ProgramError("text buffer limit exceeded");
|
|
849
|
+
used += separator.length;
|
|
850
|
+
}
|
|
851
|
+
if (parts[index].length > this.budget.maxBufferBytes - used) throw new ProgramError("text buffer limit exceeded");
|
|
852
|
+
used += parts[index].length;
|
|
853
|
+
}
|
|
854
|
+
if (suffix.length > this.budget.maxBufferBytes - used) throw new ProgramError("text buffer limit exceeded");
|
|
855
|
+
used += suffix.length;
|
|
856
|
+
this.budget.step(used);
|
|
857
|
+
return parts.join(separator) + suffix;
|
|
858
|
+
}
|
|
859
|
+
rebuild(fields) {
|
|
860
|
+
const record = this.join(fields.map((value) => this.asText(value)), this.varText("OFS"));
|
|
861
|
+
this.replaceRecord(record, fields);
|
|
862
|
+
}
|
|
863
|
+
key(items) {
|
|
864
|
+
if (items.length === 1) {
|
|
865
|
+
const first = this.scalarExpression(items[0]);
|
|
866
|
+
if (!(first instanceof Promise)) {
|
|
867
|
+
const k = this.asText(first);
|
|
868
|
+
this.budget.step(2);
|
|
869
|
+
if (k.length > this.budget.maxBufferBytes) throw new ProgramError("text buffer limit exceeded");
|
|
870
|
+
this.budget.step(k.length);
|
|
871
|
+
return k;
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
return this.keySlow(items);
|
|
875
|
+
}
|
|
876
|
+
async keySlow(items) {
|
|
877
|
+
const pieces = [];
|
|
878
|
+
for (const item of items) pieces.push(this.asText(await this.scalarExpression(item)));
|
|
879
|
+
return this.join(pieces, this.varText("SUBSEP"));
|
|
880
|
+
}
|
|
881
|
+
async reference(expression) {
|
|
882
|
+
if (expression.kind === "variable") return { get: () => this.get(expression.name), set: (value) => this.set(expression.name, value) };
|
|
883
|
+
if (expression.kind === "field") {
|
|
884
|
+
const index = Math.trunc(number(await this.scalarExpression(expression.index)));
|
|
885
|
+
if (!Number.isSafeInteger(index) || index < 0 || index > (this.budget.options.maxFields ?? Infinity)) throw new ProgramError("invalid or excessive field index");
|
|
886
|
+
return {
|
|
887
|
+
get: () => this.getField(index),
|
|
888
|
+
set: (value) => {
|
|
889
|
+
if (index === 0) return this.setRecord(this.asText(value), value);
|
|
890
|
+
const fields = this.ensureFields().slice();
|
|
891
|
+
while (fields.length < index) fields.push(string(""));
|
|
892
|
+
fields[index - 1] = value;
|
|
893
|
+
this.rebuild(fields);
|
|
894
|
+
}
|
|
895
|
+
};
|
|
896
|
+
}
|
|
897
|
+
if (expression.kind === "array") {
|
|
898
|
+
const array = this.array(expression.name);
|
|
899
|
+
const key = await this.key(expression.indexes);
|
|
900
|
+
return { get: () => {
|
|
901
|
+
if (!array.entries.has(key)) this.arraySet(array, key, unset);
|
|
902
|
+
return array.entries.get(key);
|
|
903
|
+
}, set: (value) => this.arraySet(array, key, value) };
|
|
904
|
+
}
|
|
905
|
+
throw new ProgramError("expression is not assignable");
|
|
906
|
+
}
|
|
907
|
+
arithmetic(operator, left, right) {
|
|
908
|
+
if ((operator === "/" || operator === "%") && right === 0) throw new ProgramError("division by zero");
|
|
909
|
+
const result = operator === "+" ? left + right : operator === "-" ? left - right : operator === "*" ? left * right : operator === "/" ? left / right : operator === "%" ? left % right : left ** right;
|
|
910
|
+
if (!Number.isFinite(result)) throw new ProgramError("non-finite arithmetic result");
|
|
911
|
+
return result;
|
|
912
|
+
}
|
|
913
|
+
scalarExpression(expression) {
|
|
914
|
+
const val = this.evaluate(expression);
|
|
915
|
+
return val instanceof Promise ? val.then(scalar) : scalar(val);
|
|
916
|
+
}
|
|
917
|
+
evaluate(expression) {
|
|
918
|
+
this.budget.step();
|
|
919
|
+
switch (expression.kind) {
|
|
920
|
+
case "number":
|
|
921
|
+
return numeric(expression.value);
|
|
922
|
+
case "string":
|
|
923
|
+
return string(expression.value);
|
|
924
|
+
case "regex":
|
|
925
|
+
return this.evaluateRegexMatch(expression.pattern);
|
|
926
|
+
case "variable":
|
|
927
|
+
return this.get(expression.name);
|
|
928
|
+
case "field": {
|
|
929
|
+
if (expression.index.kind === "number") {
|
|
930
|
+
this.budget.step();
|
|
931
|
+
const index = Math.trunc(expression.index.value);
|
|
932
|
+
if (!Number.isSafeInteger(index) || index < 0 || index > (this.budget.options.maxFields ?? Infinity)) throw new ProgramError("invalid or excessive field index");
|
|
933
|
+
return this.getField(index);
|
|
934
|
+
}
|
|
935
|
+
const idxVal = this.scalarExpression(expression.index);
|
|
936
|
+
if (!(idxVal instanceof Promise)) {
|
|
937
|
+
const index = Math.trunc(number(idxVal));
|
|
938
|
+
if (!Number.isSafeInteger(index) || index < 0 || index > (this.budget.options.maxFields ?? Infinity)) throw new ProgramError("invalid or excessive field index");
|
|
939
|
+
return this.getField(index);
|
|
940
|
+
}
|
|
941
|
+
return this.evaluateFieldAsync(idxVal);
|
|
942
|
+
}
|
|
943
|
+
case "array": {
|
|
944
|
+
const array = this.array(expression.name);
|
|
945
|
+
const k = this.key(expression.indexes);
|
|
946
|
+
if (!(k instanceof Promise)) {
|
|
947
|
+
let existing = array.entries.get(k);
|
|
948
|
+
if (existing === void 0 && !array.entries.has(k)) {
|
|
949
|
+
this.arraySet(array, k, unset);
|
|
950
|
+
existing = unset;
|
|
951
|
+
}
|
|
952
|
+
return existing;
|
|
953
|
+
}
|
|
954
|
+
return this.evaluateArrayAsync(array, k);
|
|
955
|
+
}
|
|
956
|
+
case "getline":
|
|
957
|
+
return this.getline(expression);
|
|
958
|
+
case "tuple":
|
|
959
|
+
throw new ProgramError("tuple is only valid as an array membership key");
|
|
960
|
+
case "conditional": {
|
|
961
|
+
const cond = this.scalarExpression(expression.condition);
|
|
962
|
+
return cond instanceof Promise ? this.evaluateConditionalAsync(expression, cond) : this.evaluate(truth(cond) ? expression.yes : expression.no);
|
|
963
|
+
}
|
|
964
|
+
case "unary": {
|
|
965
|
+
if (expression.operator === "++" || expression.operator === "--") {
|
|
966
|
+
if (expression.operand.kind === "variable") {
|
|
967
|
+
const name = expression.operand.name;
|
|
968
|
+
const previous = number(scalar(this.get(name)));
|
|
969
|
+
const delta = expression.operator === "++" ? 1 : -1;
|
|
970
|
+
const next = (previous | 0) === previous && previous > -1073741820 && previous < 1073741820 ? previous + delta | 0 : previous + delta;
|
|
971
|
+
const updated = this.setNumber(name, next);
|
|
972
|
+
return expression.postfix ? numeric(previous) : updated;
|
|
973
|
+
}
|
|
974
|
+
if (expression.operand.kind === "array") {
|
|
975
|
+
const array = this.array(expression.operand.name);
|
|
976
|
+
const k = this.key(expression.operand.indexes);
|
|
977
|
+
if (!(k instanceof Promise)) {
|
|
978
|
+
let current = array.entries.get(k);
|
|
979
|
+
if (current === void 0 && !array.entries.has(k)) {
|
|
980
|
+
this.arraySet(array, k, unset);
|
|
981
|
+
current = unset;
|
|
982
|
+
}
|
|
983
|
+
const previous = number(scalar(current));
|
|
984
|
+
const next = previous + (expression.operator === "++" ? 1 : -1);
|
|
985
|
+
this.arraySet(array, k, numeric(next));
|
|
986
|
+
return numeric(expression.postfix ? previous : next);
|
|
987
|
+
}
|
|
988
|
+
return this.evaluateUnaryArrayAsync(expression, array, k);
|
|
989
|
+
}
|
|
990
|
+
return this.evaluateUnarySlow(expression);
|
|
991
|
+
}
|
|
992
|
+
const operand = this.scalarExpression(expression.operand);
|
|
993
|
+
if (!(operand instanceof Promise)) {
|
|
994
|
+
return numeric(expression.operator === "!" ? truth(operand) ? 0 : 1 : expression.operator === "-" ? -number(operand) : number(operand));
|
|
995
|
+
}
|
|
996
|
+
return this.evaluateUnaryValueAsync(expression.operator, operand);
|
|
997
|
+
}
|
|
998
|
+
case "binary": {
|
|
999
|
+
const operator = expression.operator;
|
|
1000
|
+
if (operator === "=" || operator === "+=" || operator === "-=" || operator === "*=" || operator === "/=" || operator === "%=" || operator === "^=") {
|
|
1001
|
+
if (expression.left.kind === "variable") {
|
|
1002
|
+
const name = expression.left.name;
|
|
1003
|
+
if (operator !== "=" && expression.right.kind === "field" && expression.right.index.kind === "number") {
|
|
1004
|
+
this.budget.step(2);
|
|
1005
|
+
const idx = Math.trunc(expression.right.index.value);
|
|
1006
|
+
if (Number.isSafeInteger(idx) && idx > 0 && idx <= (this.budget.options.maxFields ?? Infinity)) {
|
|
1007
|
+
const prevNum = number(scalar(this.get(name)));
|
|
1008
|
+
const rightNum = this.getFieldNumber(idx);
|
|
1009
|
+
const nextNum = operator === "+=" && (prevNum | 0) === prevNum && (rightNum | 0) === rightNum && prevNum > -536870912 && prevNum < 536870912 && rightNum > -536870912 && rightNum < 536870912 ? prevNum + rightNum | 0 : this.arithmetic(operator[0], prevNum, rightNum);
|
|
1010
|
+
return this.setNumber(name, nextNum);
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
const previous = operator === "=" ? unset : scalar(this.get(name));
|
|
1014
|
+
const rightVal = this.scalarExpression(expression.right);
|
|
1015
|
+
if (!(rightVal instanceof Promise)) {
|
|
1016
|
+
if (operator !== "=") {
|
|
1017
|
+
return this.setNumber(name, this.arithmetic(operator[0], number(previous), number(rightVal)));
|
|
1018
|
+
}
|
|
1019
|
+
this.set(name, rightVal);
|
|
1020
|
+
return rightVal;
|
|
1021
|
+
}
|
|
1022
|
+
return this.evaluateAssignVarAsync(operator, name, previous, rightVal);
|
|
1023
|
+
} else if (expression.left.kind === "array") {
|
|
1024
|
+
const array = this.array(expression.left.name);
|
|
1025
|
+
const k = this.key(expression.left.indexes);
|
|
1026
|
+
if (!(k instanceof Promise)) {
|
|
1027
|
+
let current = operator === "=" ? unset : array.entries.get(k);
|
|
1028
|
+
if (operator !== "=" && current === void 0 && !array.entries.has(k)) {
|
|
1029
|
+
this.arraySet(array, k, unset);
|
|
1030
|
+
current = unset;
|
|
1031
|
+
}
|
|
1032
|
+
const previous = scalar(current);
|
|
1033
|
+
const rightVal = this.scalarExpression(expression.right);
|
|
1034
|
+
if (!(rightVal instanceof Promise)) {
|
|
1035
|
+
const value = operator === "=" ? rightVal : numeric(this.arithmetic(operator[0], number(previous), number(rightVal)));
|
|
1036
|
+
this.arraySet(array, k, value);
|
|
1037
|
+
return value;
|
|
1038
|
+
}
|
|
1039
|
+
return this.evaluateAssignArrayRightAsync(operator, array, k, previous, rightVal);
|
|
1040
|
+
}
|
|
1041
|
+
return this.evaluateAssignArrayKeyAsync(expression, operator, array, k);
|
|
1042
|
+
}
|
|
1043
|
+
return this.evaluateBinarySlow(expression);
|
|
1044
|
+
}
|
|
1045
|
+
if (operator === "~" || operator === "!~") {
|
|
1046
|
+
if (expression.right.kind === "regex") {
|
|
1047
|
+
const left2 = this.scalarExpression(expression.left);
|
|
1048
|
+
if (!(left2 instanceof Promise)) {
|
|
1049
|
+
const matched = expression.right.pattern.tryTestSync(this.asText(left2), this.budget);
|
|
1050
|
+
if (!(matched instanceof Promise)) {
|
|
1051
|
+
return numeric((operator === "~" ? matched : !matched) ? 1 : 0);
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
return this.evaluateBinarySlow(expression);
|
|
1056
|
+
}
|
|
1057
|
+
if (operator === "in") {
|
|
1058
|
+
return this.evaluateBinarySlow(expression);
|
|
1059
|
+
}
|
|
1060
|
+
const left = this.scalarExpression(expression.left);
|
|
1061
|
+
if (left instanceof Promise) return this.evaluateBinaryWithLeftPromise(expression, left);
|
|
1062
|
+
if (operator === "&&" && !truth(left)) return numeric(0);
|
|
1063
|
+
if (operator === "||" && truth(left)) return numeric(1);
|
|
1064
|
+
const right = this.scalarExpression(expression.right);
|
|
1065
|
+
if (right instanceof Promise) return this.evaluateBinaryWithRightPromise(operator, left, right);
|
|
1066
|
+
return this.evaluateBinarySyncOperands(operator, left, right);
|
|
1067
|
+
}
|
|
1068
|
+
case "call":
|
|
1069
|
+
return this.call(expression.name, expression.args);
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
evaluateRegexMatch(pattern) {
|
|
1073
|
+
if (pattern.canFindSync() && this.recordLength < 256) {
|
|
1074
|
+
const fastMatched = this.rawRecord !== void 0 ? pattern.findSyncFastInto(this.rawRecord, this.budget, 0, FAST_AWK_MATCH_OFFSETS, this.rawRecord.length, 0) : pattern.findSyncFastInto(this.recordSource, this.budget, this.recordStart, FAST_AWK_MATCH_OFFSETS, this.recordEnd, this.recordStart);
|
|
1075
|
+
const count = ++this.recordChecks;
|
|
1076
|
+
if (count <= 2 || (count & 31) === 0) {
|
|
1077
|
+
const p = this.budget.checkpointSync();
|
|
1078
|
+
if (p) return p.then(fastMatched ? RETURN_SCALAR_ONE : RETURN_SCALAR_ZERO);
|
|
1079
|
+
}
|
|
1080
|
+
return fastMatched ? SCALAR_ONE : SCALAR_ZERO;
|
|
1081
|
+
}
|
|
1082
|
+
const matched = this.rawRecord !== void 0 ? pattern.tryTestSync(this.rawRecord, this.budget, 0, this.rawRecord.length) : pattern.tryTestSync(this.recordSource, this.budget, this.recordStart, this.recordEnd);
|
|
1083
|
+
if (matched instanceof Promise) return matched.then((m) => m ? SCALAR_ONE : SCALAR_ZERO);
|
|
1084
|
+
return matched ? SCALAR_ONE : SCALAR_ZERO;
|
|
1085
|
+
}
|
|
1086
|
+
async evaluateFieldAsync(idxPromise) {
|
|
1087
|
+
const resolved = await idxPromise;
|
|
1088
|
+
const index = Math.trunc(number(resolved));
|
|
1089
|
+
if (!Number.isSafeInteger(index) || index < 0 || index > (this.budget.options.maxFields ?? Infinity)) throw new ProgramError("invalid or excessive field index");
|
|
1090
|
+
return this.getField(index);
|
|
1091
|
+
}
|
|
1092
|
+
async evaluateArrayAsync(array, keyPromise) {
|
|
1093
|
+
const resolvedKey = await keyPromise;
|
|
1094
|
+
let existing = array.entries.get(resolvedKey);
|
|
1095
|
+
if (existing === void 0 && !array.entries.has(resolvedKey)) {
|
|
1096
|
+
this.arraySet(array, resolvedKey, unset);
|
|
1097
|
+
existing = unset;
|
|
1098
|
+
}
|
|
1099
|
+
return existing;
|
|
1100
|
+
}
|
|
1101
|
+
async evaluateConditionalAsync(expression, condPromise) {
|
|
1102
|
+
const c = await condPromise;
|
|
1103
|
+
return this.evaluate(truth(c) ? expression.yes : expression.no);
|
|
1104
|
+
}
|
|
1105
|
+
async evaluateUnaryArrayAsync(expression, array, keyPromise) {
|
|
1106
|
+
const resolvedKey = await keyPromise;
|
|
1107
|
+
let current = array.entries.get(resolvedKey);
|
|
1108
|
+
if (current === void 0 && !array.entries.has(resolvedKey)) {
|
|
1109
|
+
this.arraySet(array, resolvedKey, unset);
|
|
1110
|
+
current = unset;
|
|
1111
|
+
}
|
|
1112
|
+
const previous = number(scalar(current));
|
|
1113
|
+
const next = previous + (expression.operator === "++" ? 1 : -1);
|
|
1114
|
+
this.arraySet(array, resolvedKey, numeric(next));
|
|
1115
|
+
return numeric(expression.postfix ? previous : next);
|
|
1116
|
+
}
|
|
1117
|
+
async evaluateUnaryValueAsync(operator, operandPromise) {
|
|
1118
|
+
const op = await operandPromise;
|
|
1119
|
+
return numeric(operator === "!" ? truth(op) ? 0 : 1 : operator === "-" ? -number(op) : number(op));
|
|
1120
|
+
}
|
|
1121
|
+
async evaluateAssignVarAsync(operator, name, previous, rightPromise) {
|
|
1122
|
+
const resolved = await rightPromise;
|
|
1123
|
+
const value = operator === "=" ? resolved : numeric(this.arithmetic(operator[0], number(previous), number(resolved)));
|
|
1124
|
+
this.set(name, value);
|
|
1125
|
+
return value;
|
|
1126
|
+
}
|
|
1127
|
+
async evaluateAssignArrayRightAsync(operator, array, k, previous, rightPromise) {
|
|
1128
|
+
const resolved = await rightPromise;
|
|
1129
|
+
const value = operator === "=" ? resolved : numeric(this.arithmetic(operator[0], number(previous), number(resolved)));
|
|
1130
|
+
this.arraySet(array, k, value);
|
|
1131
|
+
return value;
|
|
1132
|
+
}
|
|
1133
|
+
async evaluateAssignArrayKeyAsync(expression, operator, array, keyPromise) {
|
|
1134
|
+
const resolvedKey = await keyPromise;
|
|
1135
|
+
let current = operator === "=" ? unset : array.entries.get(resolvedKey);
|
|
1136
|
+
if (operator !== "=" && current === void 0 && !array.entries.has(resolvedKey)) {
|
|
1137
|
+
this.arraySet(array, resolvedKey, unset);
|
|
1138
|
+
current = unset;
|
|
1139
|
+
}
|
|
1140
|
+
const previous = scalar(current);
|
|
1141
|
+
const resolved = await this.scalarExpression(expression.right);
|
|
1142
|
+
const value = operator === "=" ? resolved : numeric(this.arithmetic(operator[0], number(previous), number(resolved)));
|
|
1143
|
+
this.arraySet(array, resolvedKey, value);
|
|
1144
|
+
return value;
|
|
1145
|
+
}
|
|
1146
|
+
async evaluateBinaryWithRightPromise(operator, left, rightPromise) {
|
|
1147
|
+
const r = await rightPromise;
|
|
1148
|
+
return this.evaluateBinarySyncOperands(operator, left, r);
|
|
1149
|
+
}
|
|
1150
|
+
evaluateBinarySyncOperands(operator, left, right) {
|
|
1151
|
+
if (operator === "&&" || operator === "||") return numeric(truth(right) ? 1 : 0);
|
|
1152
|
+
if (operator === "concat") {
|
|
1153
|
+
const leftText = this.asText(left);
|
|
1154
|
+
const rightText = this.asText(right);
|
|
1155
|
+
this.budget.step(0);
|
|
1156
|
+
if (rightText.length > this.budget.maxBufferBytes - leftText.length) throw new ProgramError("text buffer limit exceeded");
|
|
1157
|
+
this.budget.step(leftText.length + rightText.length);
|
|
1158
|
+
return string(leftText + rightText);
|
|
1159
|
+
}
|
|
1160
|
+
if (operator === "==" || operator === "!=" || operator === "<" || operator === "<=" || operator === ">" || operator === ">=") {
|
|
1161
|
+
let order;
|
|
1162
|
+
if (left.kind !== "string" && right.kind !== "string") {
|
|
1163
|
+
const first = number(left);
|
|
1164
|
+
const second = number(right);
|
|
1165
|
+
order = first < second ? -1 : first > second ? 1 : 0;
|
|
1166
|
+
} else {
|
|
1167
|
+
order = compare(left, right, this.varText("CONVFMT"), this.budget);
|
|
1168
|
+
}
|
|
1169
|
+
return numeric((operator === "==" ? order === 0 : operator === "!=" ? order !== 0 : operator === "<" ? order < 0 : operator === "<=" ? order <= 0 : operator === ">" ? order > 0 : order >= 0) ? 1 : 0);
|
|
1170
|
+
}
|
|
1171
|
+
return numeric(this.arithmetic(operator, number(left), number(right)));
|
|
1172
|
+
}
|
|
1173
|
+
async evaluateBinaryWithLeftPromise(expression, leftPromise) {
|
|
1174
|
+
const operator = expression.operator;
|
|
1175
|
+
const left = await leftPromise;
|
|
1176
|
+
if (operator === "&&" && !truth(left)) return numeric(0);
|
|
1177
|
+
if (operator === "||" && truth(left)) return numeric(1);
|
|
1178
|
+
const right = await this.scalarExpression(expression.right);
|
|
1179
|
+
return this.evaluateBinarySyncOperands(operator, left, right);
|
|
1180
|
+
}
|
|
1181
|
+
async evaluateUnarySlow(expression) {
|
|
1182
|
+
if (expression.operator === "++" || expression.operator === "--") {
|
|
1183
|
+
const reference = await this.reference(expression.operand);
|
|
1184
|
+
const previous = number(scalar(reference.get()));
|
|
1185
|
+
const next = previous + (expression.operator === "++" ? 1 : -1);
|
|
1186
|
+
await reference.set(numeric(next));
|
|
1187
|
+
return numeric(expression.postfix ? previous : next);
|
|
1188
|
+
}
|
|
1189
|
+
const operand = await this.scalarExpression(expression.operand);
|
|
1190
|
+
return numeric(expression.operator === "!" ? truth(operand) ? 0 : 1 : expression.operator === "-" ? -number(operand) : number(operand));
|
|
1191
|
+
}
|
|
1192
|
+
async evaluateBinarySlow(expression) {
|
|
1193
|
+
const operator = expression.operator;
|
|
1194
|
+
if (["=", "+=", "-=", "*=", "/=", "%=", "^="].includes(operator)) {
|
|
1195
|
+
const reference = await this.reference(expression.left);
|
|
1196
|
+
const previous = operator === "=" ? unset : scalar(reference.get());
|
|
1197
|
+
let value = await this.scalarExpression(expression.right);
|
|
1198
|
+
if (operator !== "=") value = numeric(this.arithmetic(operator[0], number(previous), number(value)));
|
|
1199
|
+
await reference.set(value);
|
|
1200
|
+
return value;
|
|
1201
|
+
}
|
|
1202
|
+
if (operator === "in") {
|
|
1203
|
+
const array = this.array(expression.right.name);
|
|
1204
|
+
const key = expression.left.kind === "tuple" ? await this.key(expression.left.items) : this.asText(await this.scalarExpression(expression.left));
|
|
1205
|
+
return numeric(array.entries.has(key) ? 1 : 0);
|
|
1206
|
+
}
|
|
1207
|
+
const left = await this.scalarExpression(expression.left);
|
|
1208
|
+
if (operator === "~" || operator === "!~") {
|
|
1209
|
+
const matched = await (await this.regex(expression.right)).find(this.asText(left), this.budget) !== void 0;
|
|
1210
|
+
return numeric((operator === "~" ? matched : !matched) ? 1 : 0);
|
|
1211
|
+
}
|
|
1212
|
+
const right = await this.scalarExpression(expression.right);
|
|
1213
|
+
return this.evaluateBinarySyncOperands(operator, left, right);
|
|
1214
|
+
}
|
|
1215
|
+
async getline(expression) {
|
|
1216
|
+
if (expression.pipe) {
|
|
1217
|
+
const command = textDecoder.decode(latin1Bytes(this.asText(await this.scalarExpression(expression.pipe))));
|
|
1218
|
+
const record2 = await (this.pipes ??= new AwkPipes(this.context, this.budget, this.retention)).read(command, this.varText("RS"));
|
|
1219
|
+
if (record2 === void 0) return numeric(0);
|
|
1220
|
+
if (expression.target) await (await this.reference(expression.target)).set(inputValue(record2));
|
|
1221
|
+
else await this.setRecord(record2);
|
|
1222
|
+
return numeric(1);
|
|
1223
|
+
}
|
|
1224
|
+
if (!expression.file) {
|
|
1225
|
+
const record2 = await this.readMainRecord();
|
|
1226
|
+
if (record2 === void 0) return numeric(0);
|
|
1227
|
+
const target2 = expression.target ? await this.reference(expression.target) : void 0;
|
|
1228
|
+
if (target2) await target2.set(inputValue(record2));
|
|
1229
|
+
else await this.setRecord(record2);
|
|
1230
|
+
return numeric(1);
|
|
1231
|
+
}
|
|
1232
|
+
const target = expression.target ? await this.reference(expression.target) : void 0;
|
|
1233
|
+
const file = textDecoder.decode(latin1Bytes(this.asText(await this.scalarExpression(expression.file))));
|
|
1234
|
+
if (!file) throw new ProgramError("getline requires a nonempty filename");
|
|
1235
|
+
let path;
|
|
1236
|
+
try {
|
|
1237
|
+
path = virtualPath(this.context, file);
|
|
1238
|
+
} catch (error) {
|
|
1239
|
+
if (!(error instanceof FsError)) throw error;
|
|
1240
|
+
this.set("ERRNO", string(byteString(error.message)));
|
|
1241
|
+
return numeric(-1);
|
|
1242
|
+
}
|
|
1243
|
+
const inputs = this.inputs ??= /* @__PURE__ */ new Map();
|
|
1244
|
+
let reader = inputs.get(path);
|
|
1245
|
+
if (!reader) {
|
|
1246
|
+
if (inputs.size >= (this.budget.options.maxGetlineFiles ?? Infinity)) throw new ProgramError("getline open-file limit exceeded");
|
|
1247
|
+
const { context, budget } = this;
|
|
1248
|
+
const name = this.retainName(path);
|
|
1249
|
+
const useStdin = file === "-" || file === "/dev/stdin";
|
|
1250
|
+
const source = (async function* () {
|
|
1251
|
+
if (useStdin) yield* context.stdin;
|
|
1252
|
+
else {
|
|
1253
|
+
budget.step();
|
|
1254
|
+
await budget.checkpointSync();
|
|
1255
|
+
const capabilities = await context.fs.capabilitiesFor?.(name, { signal: context.signal }) ?? context.fs.capabilities;
|
|
1256
|
+
context.signal.throwIfAborted();
|
|
1257
|
+
if (context.fs.readStream && capabilities.streamingRead !== false) yield* context.fs.readStream(name, { signal: context.signal });
|
|
1258
|
+
else yield await context.fs.readFile(name, { signal: context.signal, ...Number.isFinite(budget.maxBufferBytes) ? { maxBytes: budget.maxBufferBytes } : {} });
|
|
1259
|
+
}
|
|
1260
|
+
})();
|
|
1261
|
+
try {
|
|
1262
|
+
reader = new Reader(source, budget, this.retention);
|
|
1263
|
+
inputs.set(name, reader);
|
|
1264
|
+
} catch (error) {
|
|
1265
|
+
this.retention.release(shellValueByteLength(name));
|
|
1266
|
+
throw error;
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
let record;
|
|
1270
|
+
try {
|
|
1271
|
+
record = await reader.read(this.varText("RS"));
|
|
1272
|
+
} catch (error) {
|
|
1273
|
+
this.context.signal.throwIfAborted();
|
|
1274
|
+
if (!(error instanceof FsError)) throw error;
|
|
1275
|
+
inputs.delete(path);
|
|
1276
|
+
this.retention.release(shellValueByteLength(path));
|
|
1277
|
+
await reader.close();
|
|
1278
|
+
this.set("ERRNO", string(byteString(error.message)));
|
|
1279
|
+
return numeric(-1);
|
|
1280
|
+
}
|
|
1281
|
+
if (record === void 0) return numeric(0);
|
|
1282
|
+
if (target) await target.set(inputValue(record));
|
|
1283
|
+
else await this.setRecord(record);
|
|
1284
|
+
return numeric(1);
|
|
1285
|
+
}
|
|
1286
|
+
async call(name, args) {
|
|
1287
|
+
const definition = this.program.functions.get(name);
|
|
1288
|
+
if (definition) {
|
|
1289
|
+
if (this.frames.length >= (this.budget.options.maxRecursionDepth ?? Infinity)) throw new ProgramError("function recursion limit exceeded");
|
|
1290
|
+
const frame = /* @__PURE__ */ new Map();
|
|
1291
|
+
try {
|
|
1292
|
+
for (let index = 0; index < definition.parameters.length; index++) {
|
|
1293
|
+
const parameter = definition.parameters[index];
|
|
1294
|
+
const argument = args[index];
|
|
1295
|
+
if (definition.arrays.has(parameter)) {
|
|
1296
|
+
if (argument !== void 0 && argument.kind !== "variable") throw new ProgramError("array parameter requires an array variable");
|
|
1297
|
+
this.bindArray(frame, parameter, argument ? this.array(argument.name) : new AwkArray());
|
|
1298
|
+
} else {
|
|
1299
|
+
const value = argument ? await this.evaluate(argument) : unset;
|
|
1300
|
+
if (value instanceof AwkArray) this.bindArray(frame, parameter, value);
|
|
1301
|
+
else this.storeScalar(frame, parameter, value);
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
} catch (error) {
|
|
1305
|
+
this.releaseStore(frame);
|
|
1306
|
+
throw error;
|
|
1307
|
+
}
|
|
1308
|
+
this.frames.push(frame);
|
|
1309
|
+
try {
|
|
1310
|
+
await this.execute(definition.body);
|
|
1311
|
+
return unset;
|
|
1312
|
+
} catch (error) {
|
|
1313
|
+
if (error instanceof Flow && error.kind === "return") return error.value;
|
|
1314
|
+
throw error;
|
|
1315
|
+
} finally {
|
|
1316
|
+
this.frames.pop();
|
|
1317
|
+
this.releaseStore(frame);
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
if (name === "length") {
|
|
1321
|
+
const value = args[0] ? await this.evaluate(args[0]) : string(this.record);
|
|
1322
|
+
return numeric(value instanceof AwkArray ? value.entries.size : this.asText(value).length);
|
|
1323
|
+
}
|
|
1324
|
+
if (name === "gensub") {
|
|
1325
|
+
const pattern = await this.regex(args[0]);
|
|
1326
|
+
const rawReplacement = this.asText(await this.scalarExpression(args[1]));
|
|
1327
|
+
let replacement = "";
|
|
1328
|
+
for (let index = 0; index < rawReplacement.length; index++) {
|
|
1329
|
+
const character = rawReplacement[index];
|
|
1330
|
+
if (character === "\\" && index + 1 < rawReplacement.length) {
|
|
1331
|
+
const next = rawReplacement[++index];
|
|
1332
|
+
replacement += "0123456789&\\".includes(next) ? "\\" + next : next;
|
|
1333
|
+
} else replacement += character;
|
|
1334
|
+
}
|
|
1335
|
+
this.budget.step(rawReplacement.length);
|
|
1336
|
+
const how = await this.scalarExpression(args[2]);
|
|
1337
|
+
const target = args[3] ? this.asText(await this.scalarExpression(args[3])) : this.record;
|
|
1338
|
+
const global = this.asText(how).toLowerCase().startsWith("g");
|
|
1339
|
+
const occurrence = Math.max(1, Math.trunc(number(how)) || 1);
|
|
1340
|
+
return string((await substitute(target, pattern, replacement, this.budget, global, occurrence, "sed")).text);
|
|
1341
|
+
}
|
|
1342
|
+
if (name === "asort" || name === "asorti") {
|
|
1343
|
+
const source = this.array(args[0].name);
|
|
1344
|
+
const target = args[1] ? this.array(args[1].name) : source;
|
|
1345
|
+
if (this.entries - target.entries.size + source.entries.size > (this.budget.options.maxArrayEntries ?? Infinity)) throw new ProgramError("array entry limit exceeded");
|
|
1346
|
+
const values2 = [];
|
|
1347
|
+
let size = 0;
|
|
1348
|
+
for (const [key, value] of source.entries) {
|
|
1349
|
+
this.budget.step();
|
|
1350
|
+
const item = name === "asorti" ? string(key) : scalar(value);
|
|
1351
|
+
size += String(values2.length + 1).length + textSize(item);
|
|
1352
|
+
values2.push(item);
|
|
1353
|
+
}
|
|
1354
|
+
const allocation = this.arrays.get(target);
|
|
1355
|
+
const sorted = this.retention.replace(allocation.bytes, size, () => values2.sort((left, right) => {
|
|
1356
|
+
this.budget.step();
|
|
1357
|
+
if (left.kind === "string" && right.kind !== "string") return 1;
|
|
1358
|
+
if (right.kind === "string" && left.kind !== "string") return -1;
|
|
1359
|
+
return compare(left, right, this.varText("CONVFMT"), this.budget);
|
|
1360
|
+
}).map(ownScalar));
|
|
1361
|
+
this.entries += sorted.length - target.entries.size;
|
|
1362
|
+
target.entries.clear();
|
|
1363
|
+
for (let index = 0; index < sorted.length; index++) target.entries.set(String(index + 1), sorted[index]);
|
|
1364
|
+
allocation.bytes = size;
|
|
1365
|
+
return numeric(sorted.length);
|
|
1366
|
+
}
|
|
1367
|
+
if (name === "sub" || name === "gsub") {
|
|
1368
|
+
const pattern = await this.regex(args[0]);
|
|
1369
|
+
const replacement = this.asText(await this.scalarExpression(args[1]));
|
|
1370
|
+
const target = await this.reference(args[2] ?? { kind: "field", index: { kind: "number", value: 0 } });
|
|
1371
|
+
const result2 = await substitute(this.asText(scalar(target.get())), pattern, replacement, this.budget, name === "gsub", 1, "awk");
|
|
1372
|
+
if (result2.count) await target.set(string(result2.text));
|
|
1373
|
+
return numeric(result2.count);
|
|
1374
|
+
}
|
|
1375
|
+
if (name === "split") {
|
|
1376
|
+
const value = this.asText(await this.scalarExpression(args[0]));
|
|
1377
|
+
const target = this.array(args[1].name);
|
|
1378
|
+
const separator = args[2]?.kind === "regex" ? args[2].pattern : args[2] ? this.asText(await this.scalarExpression(args[2])) : this.varText("FS");
|
|
1379
|
+
const parts = await this.split(value, separator);
|
|
1380
|
+
if (this.entries - target.entries.size + parts.length > (this.budget.options.maxArrayEntries ?? Infinity)) throw new ProgramError("array entry limit exceeded");
|
|
1381
|
+
let size = 0;
|
|
1382
|
+
for (let index = 0; index < parts.length; index++) {
|
|
1383
|
+
const part = parts[index];
|
|
1384
|
+
if (part.kind === "string" || part.kind === "numeric") this.budget.check(part.text);
|
|
1385
|
+
const key = String(index + 1);
|
|
1386
|
+
this.budget.check(key);
|
|
1387
|
+
size += key.length + textSize(part);
|
|
1388
|
+
}
|
|
1389
|
+
const allocation = this.arrays.get(target);
|
|
1390
|
+
const entries = this.retention.replace(allocation.bytes, size, () => parts.map((part, index) => [String(index + 1), ownScalar(part)]));
|
|
1391
|
+
this.entries += entries.length - target.entries.size;
|
|
1392
|
+
target.entries.clear();
|
|
1393
|
+
for (const [key, part] of entries) target.entries.set(key, part);
|
|
1394
|
+
allocation.bytes = size;
|
|
1395
|
+
return numeric(parts.length);
|
|
1396
|
+
}
|
|
1397
|
+
if (name === "match") {
|
|
1398
|
+
const value = this.asText(await this.scalarExpression(args[0]));
|
|
1399
|
+
const matched = await (await this.regex(args[1])).find(value, this.budget);
|
|
1400
|
+
this.set("RSTART", numeric(matched ? matched.start + 1 : 0));
|
|
1401
|
+
this.set("RLENGTH", numeric(matched ? matched.end - matched.start : -1));
|
|
1402
|
+
return this.get("RSTART");
|
|
1403
|
+
}
|
|
1404
|
+
const values = [];
|
|
1405
|
+
for (const argument of args) values.push(await this.scalarExpression(argument));
|
|
1406
|
+
const first = values[0] ?? unset;
|
|
1407
|
+
if (name === "systime") return numeric(Math.floor(Date.now() / 1e3));
|
|
1408
|
+
if (name === "strftime" || name === "mktime") {
|
|
1409
|
+
const utc = number(values[name === "strftime" ? 2 : 1] ?? unset) !== 0;
|
|
1410
|
+
const zone = new TimeZone(utc ? "UTC" : this.context.env.TZ ?? "UTC");
|
|
1411
|
+
if (name === "strftime") {
|
|
1412
|
+
const timestamp = values[1] ? Math.trunc(number(values[1])) : Math.floor(Date.now() / 1e3);
|
|
1413
|
+
if (!Number.isFinite(timestamp)) throw new ProgramError("invalid strftime timestamp");
|
|
1414
|
+
const format = values.length ? this.asText(first) : "%a %b %e %H:%M:%S %Z %Y";
|
|
1415
|
+
this.budget.step(format.length);
|
|
1416
|
+
return string(this.budget.check(formatDate(format, BigInt(timestamp) * nanosecondsPerSecond, zone, {
|
|
1417
|
+
maxArguments: Infinity,
|
|
1418
|
+
maxArgumentBytes: Infinity,
|
|
1419
|
+
maxEnvironmentEntries: Infinity,
|
|
1420
|
+
maxOutputBytes: this.budget.maxBufferBytes + 1,
|
|
1421
|
+
maxFormatWidth: this.budget.maxBufferBytes
|
|
1422
|
+
}).slice(0, -1)));
|
|
1423
|
+
}
|
|
1424
|
+
const fields = this.asText(first).trim().split(/\s+/u);
|
|
1425
|
+
if (fields.length < 6 || fields.length > 7 || fields.some((field) => !/^[+-]?\d+$/u.test(field))) return numeric(-1);
|
|
1426
|
+
const parts = fields.map(Number);
|
|
1427
|
+
const date = /* @__PURE__ */ new Date(0);
|
|
1428
|
+
date.setUTCFullYear(parts[0], parts[1] - 1, parts[2]);
|
|
1429
|
+
date.setUTCHours(parts[3], parts[4], parts[5], 0);
|
|
1430
|
+
if (!Number.isFinite(date.getTime())) return numeric(-1);
|
|
1431
|
+
try {
|
|
1432
|
+
const wall = BigInt(date.getTime()) * 1000000n;
|
|
1433
|
+
const offsets = [-183, -2, 0, 2, 183].map((days) => zone.fields(wall + BigInt(days * 86400) * nanosecondsPerSecond).offset);
|
|
1434
|
+
const daylight = parts[6] ?? -1;
|
|
1435
|
+
let offset = daylight > 0 ? Math.max(...offsets) : Math.min(...offsets);
|
|
1436
|
+
if (daylight < 0) {
|
|
1437
|
+
for (const candidate of [...new Set(offsets)].sort((a, b) => b - a)) {
|
|
1438
|
+
const observed = zone.fields(wall - BigInt(candidate) * nanosecondsPerSecond);
|
|
1439
|
+
if (observed.year === date.getUTCFullYear() && observed.month === date.getUTCMonth() + 1 && observed.day === date.getUTCDate() && observed.hour === date.getUTCHours() && observed.minute === date.getUTCMinutes() && observed.second === date.getUTCSeconds()) {
|
|
1440
|
+
offset = candidate;
|
|
1441
|
+
break;
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
return numeric(date.getTime() / 1e3 - offset);
|
|
1446
|
+
} catch {
|
|
1447
|
+
return numeric(-1);
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
if (["and", "or", "xor", "compl", "lshift", "rshift"].includes(name)) {
|
|
1451
|
+
const operands = values.map((value) => {
|
|
1452
|
+
const operand = number(value);
|
|
1453
|
+
if (!Number.isFinite(operand) || operand < 0) throw new ProgramError(`invalid argument in '${name}'`);
|
|
1454
|
+
return BigInt.asUintN(64, BigInt(Math.trunc(operand)));
|
|
1455
|
+
});
|
|
1456
|
+
let result2 = operands[0];
|
|
1457
|
+
if (name === "compl") result2 = ~result2;
|
|
1458
|
+
else if (name === "lshift" || name === "rshift") {
|
|
1459
|
+
const shift = operands[1];
|
|
1460
|
+
result2 = shift >= 64n ? 0n : name === "lshift" ? result2 << shift : result2 >> shift;
|
|
1461
|
+
} else for (const operand of operands.slice(1)) result2 = name === "and" ? result2 & operand : name === "or" ? result2 | operand : result2 ^ operand;
|
|
1462
|
+
result2 = BigInt.asUintN(64, result2);
|
|
1463
|
+
for (let bit = 63n; BigInt(Number(result2)) !== result2; bit--) result2 &= ~(1n << bit);
|
|
1464
|
+
return numeric(Number(result2));
|
|
1465
|
+
}
|
|
1466
|
+
if (name === "srand") {
|
|
1467
|
+
const previous = this.randomSeed;
|
|
1468
|
+
this.randomSeed = values.length ? Math.trunc(number(first)) : Math.floor(Date.now() / 1e3);
|
|
1469
|
+
this.randomState = this.randomSeed >>> 0;
|
|
1470
|
+
return numeric(previous);
|
|
1471
|
+
}
|
|
1472
|
+
if (name === "rand") {
|
|
1473
|
+
this.randomState = Math.imul(this.randomState, 1664525) + 1013904223 >>> 0;
|
|
1474
|
+
return numeric(this.randomState / 4294967296);
|
|
1475
|
+
}
|
|
1476
|
+
if (this.ordchr && name === "ord") return numeric(this.asText(first).charCodeAt(0) || 0);
|
|
1477
|
+
if (this.ordchr && name === "chr") {
|
|
1478
|
+
const value = number(first);
|
|
1479
|
+
if (!Number.isFinite(value)) throw new ProgramError("invalid numeric argument in 'chr'");
|
|
1480
|
+
return string(String.fromCharCode(Math.trunc(value) & 255));
|
|
1481
|
+
}
|
|
1482
|
+
if (name === "sprintf") return string(this.budget.check(formatted(this.asText(first), values.slice(1), (value) => this.asText(value), this.budget)));
|
|
1483
|
+
if (name === "substr") {
|
|
1484
|
+
const start = Math.max(0, Math.trunc(number(values[1])) - 1);
|
|
1485
|
+
const length = values[2] === void 0 ? void 0 : Math.max(0, Math.trunc(number(values[2])));
|
|
1486
|
+
return string(this.asText(first).slice(start, length === void 0 ? void 0 : start + length));
|
|
1487
|
+
}
|
|
1488
|
+
if (name === "index") return numeric(this.asText(first).indexOf(this.asText(values[1])) + 1);
|
|
1489
|
+
if (name === "tolower") return string(this.asText(first).replace(/[A-Z]/gu, (character) => character.toLowerCase()));
|
|
1490
|
+
if (name === "toupper") return string(this.asText(first).replace(/[a-z]/gu, (character) => character.toUpperCase()));
|
|
1491
|
+
if (name === "close") {
|
|
1492
|
+
const pipeStatus = await this.pipes?.close(textDecoder.decode(latin1Bytes(this.asText(first))));
|
|
1493
|
+
if (pipeStatus !== void 0) return numeric(pipeStatus);
|
|
1494
|
+
const path = virtualPath(this.context, textDecoder.decode(latin1Bytes(this.asText(first))));
|
|
1495
|
+
const reader = this.inputs?.get(path);
|
|
1496
|
+
this.inputs?.delete(path);
|
|
1497
|
+
if (reader) this.retention.release(shellValueByteLength(path));
|
|
1498
|
+
await reader?.close();
|
|
1499
|
+
const output = this.outputs?.delete(path) ?? false;
|
|
1500
|
+
if (output) this.retention.release(shellValueByteLength(path));
|
|
1501
|
+
return numeric(output || reader !== void 0 ? 0 : -1);
|
|
1502
|
+
}
|
|
1503
|
+
const amount = number(first);
|
|
1504
|
+
const result = name === "int" ? Math.trunc(amount) : name === "sqrt" ? Math.sqrt(amount) : name === "exp" ? Math.exp(amount) : name === "log" ? Math.log(amount) : name === "sin" ? Math.sin(amount) : name === "cos" ? Math.cos(amount) : name === "atan2" ? Math.atan2(amount, number(values[1])) : NaN;
|
|
1505
|
+
if (!Number.isFinite(result)) throw new ProgramError(`invalid mathematical result in '${name}'`);
|
|
1506
|
+
return numeric(result);
|
|
1507
|
+
}
|
|
1508
|
+
recordChecks = 0;
|
|
1509
|
+
stdoutBuffer = "";
|
|
1510
|
+
flushStdout() {
|
|
1511
|
+
if (this.stdoutBuffer.length === 0) return void 0;
|
|
1512
|
+
const chunk = this.stdoutBuffer;
|
|
1513
|
+
this.stdoutBuffer = "";
|
|
1514
|
+
const p = write(this.context, chunk);
|
|
1515
|
+
return isSyncResolved(p) ? void 0 : p;
|
|
1516
|
+
}
|
|
1517
|
+
executeSync(statement) {
|
|
1518
|
+
if (!this.inspection) {
|
|
1519
|
+
const count = ++this.recordChecks;
|
|
1520
|
+
const p = count <= 2 || (count & 31) === 0 ? this.budget.checkpointSync() : void 0;
|
|
1521
|
+
if (!p) {
|
|
1522
|
+
return this.executeSyncBody(statement);
|
|
1523
|
+
} else return this.executeAfterCheckpoint(p, statement);
|
|
1524
|
+
}
|
|
1525
|
+
return this.execute(statement);
|
|
1526
|
+
}
|
|
1527
|
+
tryFastExpressionStatement(expr) {
|
|
1528
|
+
if (this.frames.length !== 0) return false;
|
|
1529
|
+
if (expr.kind === "unary" && (expr.operator === "++" || expr.operator === "--") && expr.operand.kind === "variable") {
|
|
1530
|
+
const name = expr.operand.name;
|
|
1531
|
+
if (name !== "NF" && name !== "NR" && name !== "FNR" && name !== "FS" && name !== "RS" && name !== "CONVFMT") {
|
|
1532
|
+
this.budget.step();
|
|
1533
|
+
const existing = this.variables.get(name);
|
|
1534
|
+
if (existing === void 0 || !(existing instanceof AwkArray)) {
|
|
1535
|
+
const prevNum = existing !== void 0 ? existing.kind === "number" ? existing.number : number(existing) : 0;
|
|
1536
|
+
const rawNext = prevNum + (expr.operator === "++" ? 1 : -1);
|
|
1537
|
+
const next = (rawNext | 0) === rawNext && (rawNext !== 0 || 1 / rawNext > 0) ? rawNext | 0 : rawNext;
|
|
1538
|
+
this.retention.admit(textSize(existing), 0);
|
|
1539
|
+
const box = numeric(next);
|
|
1540
|
+
this.variables.set(name, box);
|
|
1541
|
+
return true;
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
return false;
|
|
1545
|
+
}
|
|
1546
|
+
if (expr.kind === "binary" && (expr.operator === "+=" || expr.operator === "-=" || expr.operator === "*=" || expr.operator === "/=") && expr.left.kind === "variable") {
|
|
1547
|
+
const name = expr.left.name;
|
|
1548
|
+
if (name !== "NF" && name !== "NR" && name !== "FNR" && name !== "FS" && name !== "RS" && name !== "CONVFMT") {
|
|
1549
|
+
const right = expr.right;
|
|
1550
|
+
let rightNum;
|
|
1551
|
+
if (right.kind === "field" && right.index.kind === "number") {
|
|
1552
|
+
this.budget.step(3);
|
|
1553
|
+
const idx = Math.trunc(right.index.value);
|
|
1554
|
+
if (idx > 0 && idx <= (this.budget.options.maxFields ?? Infinity)) {
|
|
1555
|
+
rightNum = this.getFieldNumber(idx);
|
|
1556
|
+
}
|
|
1557
|
+
} else if (right.kind === "number") {
|
|
1558
|
+
this.budget.step(2);
|
|
1559
|
+
rightNum = right.value;
|
|
1560
|
+
}
|
|
1561
|
+
if (rightNum !== void 0) {
|
|
1562
|
+
const existing = this.variables.get(name);
|
|
1563
|
+
if (existing === void 0 || !(existing instanceof AwkArray)) {
|
|
1564
|
+
const prevNum = existing !== void 0 ? existing.kind === "number" ? existing.number : number(existing) : 0;
|
|
1565
|
+
const rawNext = expr.operator === "+=" && Number.isFinite(prevNum) && Number.isFinite(rightNum) ? prevNum + rightNum : this.arithmetic(expr.operator[0], prevNum, rightNum);
|
|
1566
|
+
const next = (rawNext | 0) === rawNext && (rawNext !== 0 || 1 / rawNext > 0) ? rawNext | 0 : rawNext;
|
|
1567
|
+
this.retention.admit(textSize(existing), 0);
|
|
1568
|
+
const box = numeric(next);
|
|
1569
|
+
this.variables.set(name, box);
|
|
1570
|
+
return true;
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
return false;
|
|
1576
|
+
}
|
|
1577
|
+
executeSyncBody(statement) {
|
|
1578
|
+
if (statement.kind === "expression") {
|
|
1579
|
+
this.budget.step();
|
|
1580
|
+
if (!this.inspection && this.tryFastExpressionStatement(statement.expression)) return void 0;
|
|
1581
|
+
const val = this.evaluate(statement.expression);
|
|
1582
|
+
return val instanceof Promise ? this.ignorePromiseValue(val) : void 0;
|
|
1583
|
+
}
|
|
1584
|
+
if (statement.kind === "block") {
|
|
1585
|
+
this.budget.step();
|
|
1586
|
+
for (let i = 0; i < statement.body.length; i++) {
|
|
1587
|
+
const child = statement.body[i];
|
|
1588
|
+
let res;
|
|
1589
|
+
if (child.kind === "expression" && !this.inspection) {
|
|
1590
|
+
this.budget.step();
|
|
1591
|
+
if (this.tryFastExpressionStatement(child.expression)) continue;
|
|
1592
|
+
const val = this.evaluate(child.expression);
|
|
1593
|
+
res = val instanceof Promise ? this.ignorePromiseValue(val) : void 0;
|
|
1594
|
+
} else {
|
|
1595
|
+
res = this.executeSync(child);
|
|
1596
|
+
}
|
|
1597
|
+
if (res instanceof Promise) {
|
|
1598
|
+
return this.executeBlockRemainder(statement.body, i + 1, res);
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
return void 0;
|
|
1602
|
+
}
|
|
1603
|
+
if (statement.kind === "if") {
|
|
1604
|
+
this.budget.step();
|
|
1605
|
+
const cond = this.scalarExpression(statement.condition);
|
|
1606
|
+
if (!(cond instanceof Promise)) {
|
|
1607
|
+
const branch = truth(cond) ? statement.yes : statement.no;
|
|
1608
|
+
return branch ? this.executeSync(branch) : void 0;
|
|
1609
|
+
}
|
|
1610
|
+
return this.executeIfAsync(statement, cond);
|
|
1611
|
+
}
|
|
1612
|
+
if (statement.kind === "print" && !statement.redirect && !statement.formatted) {
|
|
1613
|
+
this.budget.step();
|
|
1614
|
+
const args = statement.args;
|
|
1615
|
+
const ofs = args.length ? this.varText("OFS") : "";
|
|
1616
|
+
const ors = this.varText("ORS");
|
|
1617
|
+
if (args.length === 0) {
|
|
1618
|
+
const output2 = this.budget.check(this.record + ors);
|
|
1619
|
+
this.stdoutBuffer += output2;
|
|
1620
|
+
if (this.stdoutBuffer.length >= 16384) return this.flushStdout();
|
|
1621
|
+
return void 0;
|
|
1622
|
+
}
|
|
1623
|
+
const ofmt = this.varText("OFMT");
|
|
1624
|
+
let acc = "";
|
|
1625
|
+
for (let i = 0; i < args.length; i++) {
|
|
1626
|
+
const v = this.scalarExpression(args[i]);
|
|
1627
|
+
if (v instanceof Promise) return this.executePrintRemainder(args, i, v, acc, ofs, ors, ofmt);
|
|
1628
|
+
const t = text(v, ofmt, this.budget);
|
|
1629
|
+
acc = i === 0 ? t : acc + ofs + t;
|
|
1630
|
+
}
|
|
1631
|
+
const output = this.budget.check(acc + ors);
|
|
1632
|
+
this.stdoutBuffer += output;
|
|
1633
|
+
if (this.stdoutBuffer.length >= 16384) return this.flushStdout();
|
|
1634
|
+
return void 0;
|
|
1635
|
+
}
|
|
1636
|
+
return this.execute(statement);
|
|
1637
|
+
}
|
|
1638
|
+
async executePrintRemainder(args, index, pending, acc, ofs, ors, ofmt) {
|
|
1639
|
+
const first = text(await pending, ofmt, this.budget);
|
|
1640
|
+
acc = index === 0 ? first : acc + ofs + first;
|
|
1641
|
+
for (let i = index + 1; i < args.length; i++) {
|
|
1642
|
+
acc += ofs + text(await this.scalarExpression(args[i]), ofmt, this.budget);
|
|
1643
|
+
}
|
|
1644
|
+
this.stdoutBuffer += this.budget.check(acc + ors);
|
|
1645
|
+
if (this.stdoutBuffer.length >= 16384) await this.flushStdout();
|
|
1646
|
+
}
|
|
1647
|
+
async ignorePromiseValue(promise) {
|
|
1648
|
+
await promise;
|
|
1649
|
+
}
|
|
1650
|
+
async executeIfAsync(statement, condPromise) {
|
|
1651
|
+
const resolved = await condPromise;
|
|
1652
|
+
const branch = truth(resolved) ? statement.yes : statement.no;
|
|
1653
|
+
if (branch) {
|
|
1654
|
+
const res = this.executeSync(branch);
|
|
1655
|
+
if (res instanceof Promise) await res;
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
async executeAfterCheckpoint(checkpoint, statement) {
|
|
1659
|
+
await checkpoint;
|
|
1660
|
+
const res = this.executeSyncBody(statement);
|
|
1661
|
+
if (res instanceof Promise) await res;
|
|
1662
|
+
}
|
|
1663
|
+
async executeBlockRemainder(body, startIndex, current) {
|
|
1664
|
+
await current;
|
|
1665
|
+
for (let i = startIndex; i < body.length; i++) {
|
|
1666
|
+
const res = this.executeSync(body[i]);
|
|
1667
|
+
if (res instanceof Promise) await res;
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
async execute(statement) {
|
|
1671
|
+
this.budget.step();
|
|
1672
|
+
if (this.inspection) await this.inspection.observe(statement, this.phase);
|
|
1673
|
+
const p = this.budget.checkpointSync();
|
|
1674
|
+
if (p) await p;
|
|
1675
|
+
switch (statement.kind) {
|
|
1676
|
+
case "block":
|
|
1677
|
+
for (const child of statement.body) await this.execute(child);
|
|
1678
|
+
return;
|
|
1679
|
+
case "expression":
|
|
1680
|
+
await this.evaluate(statement.expression);
|
|
1681
|
+
return;
|
|
1682
|
+
case "print": {
|
|
1683
|
+
const values = [];
|
|
1684
|
+
for (const argument of statement.args) values.push(await this.scalarExpression(argument));
|
|
1685
|
+
const output = statement.formatted ? this.budget.check(formatted(this.asText(values[0]), values.slice(1), (value) => this.asText(value), this.budget)) : this.join(values.length ? values.map((value) => text(value, this.varText("OFMT"), this.budget)) : [this.record], values.length ? this.varText("OFS") : "", this.varText("ORS"));
|
|
1686
|
+
if (!statement.redirect) {
|
|
1687
|
+
this.stdoutBuffer += output;
|
|
1688
|
+
if (this.stdoutBuffer.length >= 16384) await this.flushStdout();
|
|
1689
|
+
return;
|
|
1690
|
+
}
|
|
1691
|
+
const destination = textDecoder.decode(latin1Bytes(this.asText(await this.scalarExpression(statement.redirect.destination))));
|
|
1692
|
+
if (statement.redirect.pipe) {
|
|
1693
|
+
if (this.stdoutBuffer.length > 0) await this.flushStdout();
|
|
1694
|
+
await (this.pipes ??= new AwkPipes(this.context, this.budget, this.retention)).write(destination, output);
|
|
1695
|
+
return;
|
|
1696
|
+
}
|
|
1697
|
+
if (destination === "/dev/stdout") {
|
|
1698
|
+
this.stdoutBuffer += output;
|
|
1699
|
+
if (this.stdoutBuffer.length >= 16384) await this.flushStdout();
|
|
1700
|
+
return;
|
|
1701
|
+
}
|
|
1702
|
+
if (this.stdoutBuffer.length > 0) await this.flushStdout();
|
|
1703
|
+
if (destination === "/dev/stderr") {
|
|
1704
|
+
this.context.signal.throwIfAborted();
|
|
1705
|
+
await writeBytes(this.context.stderr, bytes(output), this.context.signal);
|
|
1706
|
+
return;
|
|
1707
|
+
}
|
|
1708
|
+
const path = virtualPath(this.context, destination);
|
|
1709
|
+
const outputs = this.outputs ??= /* @__PURE__ */ new Set();
|
|
1710
|
+
if (outputs.has(path)) await writeFileOutput(this.context, bytes(output), (chunk) => this.context.fs.appendFile(path, chunk, { signal: this.context.signal }));
|
|
1711
|
+
else {
|
|
1712
|
+
const name = this.retainName(path);
|
|
1713
|
+
try {
|
|
1714
|
+
const flag = statement.redirect.append ? "a" : "w";
|
|
1715
|
+
await writeFileOutput(this.context, bytes(output), (chunk) => this.context.fs.writeFile(name, chunk, { flag, signal: this.context.signal }));
|
|
1716
|
+
this.context.signal.throwIfAborted();
|
|
1717
|
+
outputs.add(name);
|
|
1718
|
+
} catch (error) {
|
|
1719
|
+
this.retention.release(shellValueByteLength(name));
|
|
1720
|
+
throw error;
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
return;
|
|
1724
|
+
}
|
|
1725
|
+
case "if": {
|
|
1726
|
+
const branch = truth(await this.scalarExpression(statement.condition)) ? statement.yes : statement.no;
|
|
1727
|
+
if (branch) await this.execute(branch);
|
|
1728
|
+
return;
|
|
1729
|
+
}
|
|
1730
|
+
case "flow": {
|
|
1731
|
+
if ((statement.flow === "next" || statement.flow === "nextfile") && this.phase !== "record") throw new ProgramError(`${statement.flow} is only valid while processing records`);
|
|
1732
|
+
throw new Flow(statement.flow, statement.value ? await this.scalarExpression(statement.value) : unset);
|
|
1733
|
+
}
|
|
1734
|
+
case "delete": {
|
|
1735
|
+
const array = this.array(statement.target.name);
|
|
1736
|
+
const allocation = this.arrays.get(array);
|
|
1737
|
+
if (statement.target.kind === "variable") {
|
|
1738
|
+
this.retention.release(allocation.bytes);
|
|
1739
|
+
allocation.bytes = 0;
|
|
1740
|
+
this.entries -= array.entries.size;
|
|
1741
|
+
array.entries.clear();
|
|
1742
|
+
} else {
|
|
1743
|
+
const key = await this.key(statement.target.indexes);
|
|
1744
|
+
const value = array.entries.get(key);
|
|
1745
|
+
if (array.entries.delete(key)) {
|
|
1746
|
+
const size = key.length + textSize(value);
|
|
1747
|
+
this.retention.release(size);
|
|
1748
|
+
allocation.bytes -= size;
|
|
1749
|
+
this.entries--;
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
return;
|
|
1753
|
+
}
|
|
1754
|
+
case "foreach": {
|
|
1755
|
+
const array = this.array(statement.array);
|
|
1756
|
+
for (const key of [...array.entries.keys()]) {
|
|
1757
|
+
this.budget.step();
|
|
1758
|
+
if (!array.entries.has(key)) continue;
|
|
1759
|
+
this.set(statement.variable, string(key));
|
|
1760
|
+
try {
|
|
1761
|
+
const res = this.executeSync(statement.body);
|
|
1762
|
+
if (res instanceof Promise) await res;
|
|
1763
|
+
} catch (error) {
|
|
1764
|
+
if (error instanceof Flow && error.kind === "break") break;
|
|
1765
|
+
if (!(error instanceof Flow && error.kind === "continue")) throw error;
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1768
|
+
return;
|
|
1769
|
+
}
|
|
1770
|
+
case "while":
|
|
1771
|
+
case "do":
|
|
1772
|
+
case "for": {
|
|
1773
|
+
if (statement.kind === "for" && statement.initial) {
|
|
1774
|
+
const initial = this.evaluate(statement.initial);
|
|
1775
|
+
if (initial instanceof Promise) await initial;
|
|
1776
|
+
}
|
|
1777
|
+
let first = true;
|
|
1778
|
+
while (true) {
|
|
1779
|
+
this.budget.step();
|
|
1780
|
+
if (!(statement.kind === "do" && first) && statement.condition) {
|
|
1781
|
+
const condition = this.scalarExpression(statement.condition);
|
|
1782
|
+
if (!truth(condition instanceof Promise ? await condition : condition)) break;
|
|
1783
|
+
}
|
|
1784
|
+
first = false;
|
|
1785
|
+
try {
|
|
1786
|
+
const body = this.executeSync(statement.body);
|
|
1787
|
+
if (body instanceof Promise) await body;
|
|
1788
|
+
} catch (error) {
|
|
1789
|
+
if (error instanceof Flow && error.kind === "break") break;
|
|
1790
|
+
if (!(error instanceof Flow && error.kind === "continue")) throw error;
|
|
1791
|
+
}
|
|
1792
|
+
if (statement.kind === "for" && statement.update) {
|
|
1793
|
+
const update = this.evaluate(statement.update);
|
|
1794
|
+
if (update instanceof Promise) await update;
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
return;
|
|
1798
|
+
}
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
assignment(assignment) {
|
|
1802
|
+
const match = /^([A-Za-z_][A-Za-z0-9_]*)=([\s\S]*)$/u.exec(assignment);
|
|
1803
|
+
if (!match) throw new ProgramError(`invalid assignment '${assignment}'`);
|
|
1804
|
+
this.set(match[1], inputValue(decodeString(match[2])));
|
|
1805
|
+
}
|
|
1806
|
+
exit(flow) {
|
|
1807
|
+
if (flow.value.kind !== "unset") {
|
|
1808
|
+
const status = Math.trunc(number(flow.value));
|
|
1809
|
+
if (!Number.isFinite(status)) throw new ProgramError("invalid exit status");
|
|
1810
|
+
this.status = (status % 256 + 256) % 256;
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
finishSyncCleanup(status) {
|
|
1814
|
+
this.releaseStore(this.variables);
|
|
1815
|
+
this.retention.release(this.recordLength + this.fieldBytes);
|
|
1816
|
+
this.record = "";
|
|
1817
|
+
if (this.rawFields.length > 0) this.rawFields.length = 0;
|
|
1818
|
+
this.fieldCount = 0;
|
|
1819
|
+
this.fieldsMaterialized = true;
|
|
1820
|
+
this.fieldBytes = 0;
|
|
1821
|
+
this.sliceBox.source = "";
|
|
1822
|
+
this.recordValue = unset;
|
|
1823
|
+
this.context.signal.throwIfAborted();
|
|
1824
|
+
this.context = RELEASED_AWK_CONTEXT;
|
|
1825
|
+
this.budget.context = RELEASED_AWK_CONTEXT;
|
|
1826
|
+
this.budget.signal = RELEASED_AWK_SIGNAL;
|
|
1827
|
+
this.retention.signal = RELEASED_AWK_SIGNAL;
|
|
1828
|
+
return status;
|
|
1829
|
+
}
|
|
1830
|
+
runSyncOrAsync() {
|
|
1831
|
+
if (!this.inspection && this.program.begin.length === 0) {
|
|
1832
|
+
try {
|
|
1833
|
+
const progRes = this.tryRunProgramSync();
|
|
1834
|
+
if (typeof progRes === "number") {
|
|
1835
|
+
if (!this.inputs || this.inputs.size === 0) {
|
|
1836
|
+
if (!this.outputs || this.outputs.size === 0) {
|
|
1837
|
+
if (this.mainReader) {
|
|
1838
|
+
const pendingClose = this.mainReader.closeSyncOrAsync();
|
|
1839
|
+
this.mainReader = void 0;
|
|
1840
|
+
if (pendingClose) {
|
|
1841
|
+
return this.finishRunAfterSyncProgram(progRes, pendingClose);
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1844
|
+
if (this.stdoutBuffer.length > 0) {
|
|
1845
|
+
const flushPending = this.flushStdout();
|
|
1846
|
+
if (flushPending) {
|
|
1847
|
+
return this.finishRunAfterFlush(progRes, flushPending);
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
if (this.inspection) this.syncSpecialVars();
|
|
1851
|
+
else {
|
|
1852
|
+
this.nrDirty = false;
|
|
1853
|
+
this.fnrDirty = false;
|
|
1854
|
+
this.nfDirty = false;
|
|
1855
|
+
}
|
|
1856
|
+
return this.finishSyncCleanup(progRes);
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
return this.finishRunAfterSyncProgram(progRes, void 0);
|
|
1860
|
+
}
|
|
1861
|
+
return this.finishRunFromPromise(progRes);
|
|
1862
|
+
} catch (error) {
|
|
1863
|
+
return this.finishRunFromPromise(Promise.reject(error));
|
|
1864
|
+
}
|
|
1865
|
+
}
|
|
1866
|
+
return this.run();
|
|
1867
|
+
}
|
|
1868
|
+
async finishRunAfterFlush(status, flushPending) {
|
|
1869
|
+
let failed = false;
|
|
1870
|
+
let failure;
|
|
1871
|
+
try {
|
|
1872
|
+
await flushPending;
|
|
1873
|
+
this.syncSpecialVars();
|
|
1874
|
+
} catch (error) {
|
|
1875
|
+
failed = true;
|
|
1876
|
+
failure = error;
|
|
1877
|
+
}
|
|
1878
|
+
const res = this.finishSyncCleanup(status);
|
|
1879
|
+
if (failed) throw failure;
|
|
1880
|
+
return res;
|
|
1881
|
+
}
|
|
1882
|
+
async finishRunAfterSyncProgram(status, pendingClose) {
|
|
1883
|
+
return this.finishRunFromPromise(
|
|
1884
|
+
pendingClose ? pendingClose.then(() => status) : Promise.resolve(status)
|
|
1885
|
+
);
|
|
1886
|
+
}
|
|
1887
|
+
async finishRunFromPromise(programPromise) {
|
|
1888
|
+
let status = 0, failed = false;
|
|
1889
|
+
let failure;
|
|
1890
|
+
try {
|
|
1891
|
+
status = await programPromise;
|
|
1892
|
+
if (this.stdoutBuffer.length > 0) await this.flushStdout();
|
|
1893
|
+
this.syncSpecialVars();
|
|
1894
|
+
await this.inspection?.publish(this.variables);
|
|
1895
|
+
} catch (error) {
|
|
1896
|
+
failed = true;
|
|
1897
|
+
failure = error;
|
|
1898
|
+
}
|
|
1899
|
+
try {
|
|
1900
|
+
await this.pipes?.closeAll(failed);
|
|
1901
|
+
} catch (error) {
|
|
1902
|
+
if (!failed) {
|
|
1903
|
+
failed = true;
|
|
1904
|
+
failure = error;
|
|
1905
|
+
}
|
|
1906
|
+
}
|
|
1907
|
+
if (this.stdoutBuffer.length > 0) {
|
|
1908
|
+
try {
|
|
1909
|
+
await this.flushStdout();
|
|
1910
|
+
} catch (error) {
|
|
1911
|
+
if (!failed) {
|
|
1912
|
+
failed = true;
|
|
1913
|
+
failure = error;
|
|
1914
|
+
}
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
let cleanup;
|
|
1918
|
+
if (this.mainReader && (!this.inputs || this.inputs.size === 0)) {
|
|
1919
|
+
const pendingClose = this.mainReader.closeSyncOrAsync();
|
|
1920
|
+
this.mainReader = void 0;
|
|
1921
|
+
if (pendingClose) {
|
|
1922
|
+
try {
|
|
1923
|
+
await pendingClose;
|
|
1924
|
+
} catch (error) {
|
|
1925
|
+
if (!failed) {
|
|
1926
|
+
failed = true;
|
|
1927
|
+
failure = error;
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
} else if (this.mainReader || this.inputs && this.inputs.size > 0) {
|
|
1932
|
+
const readers = [...this.mainReader ? [this.mainReader] : [], ...this.inputs ? this.inputs.values() : []];
|
|
1933
|
+
this.mainReader = void 0;
|
|
1934
|
+
if (this.inputs) {
|
|
1935
|
+
for (const name of this.inputs.keys()) this.retention.release(shellValueByteLength(name));
|
|
1936
|
+
this.inputs.clear();
|
|
1937
|
+
}
|
|
1938
|
+
cleanup = await Promise.allSettled(readers.map(async (reader) => {
|
|
1939
|
+
await reader.close();
|
|
1940
|
+
}));
|
|
1941
|
+
}
|
|
1942
|
+
if (this.outputs && this.outputs.size > 0) {
|
|
1943
|
+
for (const name of this.outputs) this.retention.release(shellValueByteLength(name));
|
|
1944
|
+
this.outputs.clear();
|
|
1945
|
+
}
|
|
1946
|
+
const res = this.finishSyncCleanup(status);
|
|
1947
|
+
if (failed) throw failure;
|
|
1948
|
+
if (cleanup) {
|
|
1949
|
+
for (const result of cleanup) if (result.status === "rejected") throw result.reason;
|
|
1950
|
+
}
|
|
1951
|
+
return res;
|
|
1952
|
+
}
|
|
1953
|
+
async run() {
|
|
1954
|
+
return this.finishRunFromPromise(this.runProgram());
|
|
1955
|
+
}
|
|
1956
|
+
tryRunProgramSync() {
|
|
1957
|
+
this.phase = "record";
|
|
1958
|
+
let ranges;
|
|
1959
|
+
if (this.program.rules.length || this.program.end.length) {
|
|
1960
|
+
if (!this.mainReader) {
|
|
1961
|
+
this.tryOpenNextMainReaderSync();
|
|
1962
|
+
}
|
|
1963
|
+
while (true) {
|
|
1964
|
+
this.budget.step();
|
|
1965
|
+
if (this.mainReader && this.mainReader.readSliceSync(this.varText("RS"), this.sliceBox)) {
|
|
1966
|
+
this.incrementCounter("NR");
|
|
1967
|
+
this.incrementCounter("FNR");
|
|
1968
|
+
const setRecPromise = this.setRecordSliceSync(this.sliceBox.source, this.sliceBox.start, this.sliceBox.end);
|
|
1969
|
+
if (setRecPromise instanceof Promise) {
|
|
1970
|
+
return this.continueProgramAsyncAfterRecord(setRecPromise, ranges, 0);
|
|
1971
|
+
}
|
|
1972
|
+
} else if (this.mainReader && this.mainReader.isEnded && this.argument >= number(this.getScalar("ARGC"))) {
|
|
1973
|
+
const closePending = this.mainReader.closeSyncOrAsync();
|
|
1974
|
+
this.mainReader = void 0;
|
|
1975
|
+
if (closePending) {
|
|
1976
|
+
return closePending.then(() => this.runEndPhaseSyncOrAsync(0));
|
|
1977
|
+
}
|
|
1978
|
+
break;
|
|
1979
|
+
} else {
|
|
1980
|
+
return this.continueProgramSlowAsync(ranges);
|
|
1981
|
+
}
|
|
1982
|
+
try {
|
|
1983
|
+
for (let index = 0; index < this.program.rules.length; index++) {
|
|
1984
|
+
const rule = this.program.rules[index];
|
|
1985
|
+
let selected = !rule.pattern || ranges !== void 0 && ranges.has(index);
|
|
1986
|
+
if (!selected) {
|
|
1987
|
+
const patVal = this.scalarExpression(rule.pattern);
|
|
1988
|
+
if (patVal instanceof Promise) {
|
|
1989
|
+
return this.continueProgramAsyncAtRule(patVal, ranges, index, "pattern");
|
|
1990
|
+
}
|
|
1991
|
+
selected = truth(patVal);
|
|
1992
|
+
}
|
|
1993
|
+
if (!selected) continue;
|
|
1994
|
+
if (rule.end) {
|
|
1995
|
+
const endVal = this.scalarExpression(rule.end);
|
|
1996
|
+
if (endVal instanceof Promise) {
|
|
1997
|
+
return this.continueProgramAsyncAtRule(endVal, ranges, index, "end");
|
|
1998
|
+
}
|
|
1999
|
+
if (truth(endVal)) ranges?.delete(index);
|
|
2000
|
+
else (ranges ??= /* @__PURE__ */ new Set()).add(index);
|
|
2001
|
+
}
|
|
2002
|
+
const execRes = this.executeSync(rule.action);
|
|
2003
|
+
if (execRes instanceof Promise) {
|
|
2004
|
+
return this.continueProgramAsyncAtRule(execRes, ranges, index, "action");
|
|
2005
|
+
}
|
|
2006
|
+
}
|
|
2007
|
+
} catch (error) {
|
|
2008
|
+
if (!(error instanceof Flow)) throw error;
|
|
2009
|
+
if (error.kind === "exit") {
|
|
2010
|
+
this.exit(error);
|
|
2011
|
+
break;
|
|
2012
|
+
}
|
|
2013
|
+
if (error.kind === "nextfile") {
|
|
2014
|
+
const closePending = this.mainReader?.closeSyncOrAsync();
|
|
2015
|
+
this.mainReader = void 0;
|
|
2016
|
+
if (closePending) return closePending.then(() => this.continueProgramSlowAsync(ranges));
|
|
2017
|
+
} else if (error.kind !== "next") throw error;
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
if (this.mainReader && !hasMainGetline(this.program.end) && ![...this.program.functions.values()].some(hasMainGetline)) {
|
|
2022
|
+
void this.mainReader.close().catch(() => void 0);
|
|
2023
|
+
}
|
|
2024
|
+
return this.runEndPhaseSyncOrAsync(0);
|
|
2025
|
+
}
|
|
2026
|
+
runEndPhaseSyncOrAsync(startIdx) {
|
|
2027
|
+
this.phase = "END";
|
|
2028
|
+
try {
|
|
2029
|
+
for (let i = startIdx; i < this.program.end.length; i++) {
|
|
2030
|
+
const endRes = this.executeSync(this.program.end[i]);
|
|
2031
|
+
if (endRes instanceof Promise) {
|
|
2032
|
+
return this.continueEndPhaseAsync(endRes, i + 1);
|
|
2033
|
+
}
|
|
2034
|
+
}
|
|
2035
|
+
} catch (error) {
|
|
2036
|
+
if (error instanceof Flow && error.kind === "exit") this.exit(error);
|
|
2037
|
+
else throw error;
|
|
2038
|
+
}
|
|
2039
|
+
return this.status;
|
|
2040
|
+
}
|
|
2041
|
+
async continueEndPhaseAsync(pending, nextIdx) {
|
|
2042
|
+
try {
|
|
2043
|
+
await pending;
|
|
2044
|
+
for (let i = nextIdx; i < this.program.end.length; i++) {
|
|
2045
|
+
await this.execute(this.program.end[i]);
|
|
2046
|
+
}
|
|
2047
|
+
} catch (error) {
|
|
2048
|
+
if (error instanceof Flow && error.kind === "exit") this.exit(error);
|
|
2049
|
+
else throw error;
|
|
2050
|
+
}
|
|
2051
|
+
return this.status;
|
|
2052
|
+
}
|
|
2053
|
+
async continueProgramAsyncAfterRecord(pending, ranges, startRule) {
|
|
2054
|
+
await pending;
|
|
2055
|
+
return this.continueProgramAsyncRulesAndLoop(ranges, startRule);
|
|
2056
|
+
}
|
|
2057
|
+
async continueProgramAsyncAtRule(pending, ranges, ruleIdx, step) {
|
|
2058
|
+
const rule = this.program.rules[ruleIdx];
|
|
2059
|
+
try {
|
|
2060
|
+
if (step === "pattern") {
|
|
2061
|
+
if (truth(await pending)) {
|
|
2062
|
+
if (rule.end) {
|
|
2063
|
+
const endVal = this.scalarExpression(rule.end);
|
|
2064
|
+
if (truth(endVal instanceof Promise ? await endVal : endVal)) ranges?.delete(ruleIdx);
|
|
2065
|
+
else (ranges ??= /* @__PURE__ */ new Set()).add(ruleIdx);
|
|
2066
|
+
}
|
|
2067
|
+
const execRes = this.executeSync(rule.action);
|
|
2068
|
+
if (execRes instanceof Promise) await execRes;
|
|
2069
|
+
}
|
|
2070
|
+
} else if (step === "end") {
|
|
2071
|
+
if (truth(await pending)) ranges?.delete(ruleIdx);
|
|
2072
|
+
else (ranges ??= /* @__PURE__ */ new Set()).add(ruleIdx);
|
|
2073
|
+
const execRes = this.executeSync(rule.action);
|
|
2074
|
+
if (execRes instanceof Promise) await execRes;
|
|
2075
|
+
} else {
|
|
2076
|
+
await pending;
|
|
2077
|
+
}
|
|
2078
|
+
} catch (error) {
|
|
2079
|
+
if (!(error instanceof Flow)) throw error;
|
|
2080
|
+
if (error.kind === "exit") {
|
|
2081
|
+
this.exit(error);
|
|
2082
|
+
return this.runEndPhaseSyncOrAsync(0);
|
|
2083
|
+
}
|
|
2084
|
+
if (error.kind === "nextfile") {
|
|
2085
|
+
await this.mainReader?.close();
|
|
2086
|
+
this.mainReader = void 0;
|
|
2087
|
+
return this.continueProgramSlowAsync(ranges);
|
|
2088
|
+
}
|
|
2089
|
+
if (error.kind !== "next") throw error;
|
|
2090
|
+
return this.continueProgramSlowAsync(ranges);
|
|
2091
|
+
}
|
|
2092
|
+
return this.continueProgramAsyncRulesAndLoop(ranges, ruleIdx + 1);
|
|
2093
|
+
}
|
|
2094
|
+
async continueProgramAsyncRulesAndLoop(ranges, startRule) {
|
|
2095
|
+
try {
|
|
2096
|
+
for (let index = startRule; index < this.program.rules.length; index++) {
|
|
2097
|
+
const rule = this.program.rules[index];
|
|
2098
|
+
let selected = !rule.pattern || ranges !== void 0 && ranges.has(index);
|
|
2099
|
+
if (!selected) {
|
|
2100
|
+
const patVal = this.scalarExpression(rule.pattern);
|
|
2101
|
+
selected = truth(patVal instanceof Promise ? await patVal : patVal);
|
|
2102
|
+
}
|
|
2103
|
+
if (!selected) continue;
|
|
2104
|
+
if (rule.end) {
|
|
2105
|
+
const endVal = this.scalarExpression(rule.end);
|
|
2106
|
+
if (truth(endVal instanceof Promise ? await endVal : endVal)) ranges?.delete(index);
|
|
2107
|
+
else (ranges ??= /* @__PURE__ */ new Set()).add(index);
|
|
2108
|
+
}
|
|
2109
|
+
const execRes = this.executeSync(rule.action);
|
|
2110
|
+
if (execRes instanceof Promise) await execRes;
|
|
2111
|
+
}
|
|
2112
|
+
} catch (error) {
|
|
2113
|
+
if (!(error instanceof Flow)) throw error;
|
|
2114
|
+
if (error.kind === "exit") {
|
|
2115
|
+
this.exit(error);
|
|
2116
|
+
return this.runEndPhaseSyncOrAsync(0);
|
|
2117
|
+
}
|
|
2118
|
+
if (error.kind === "nextfile") {
|
|
2119
|
+
await this.mainReader?.close();
|
|
2120
|
+
this.mainReader = void 0;
|
|
2121
|
+
} else if (error.kind !== "next") throw error;
|
|
2122
|
+
}
|
|
2123
|
+
return this.continueProgramSlowAsync(ranges);
|
|
2124
|
+
}
|
|
2125
|
+
async continueProgramSlowAsync(ranges) {
|
|
2126
|
+
while (true) {
|
|
2127
|
+
this.budget.step();
|
|
2128
|
+
if (this.mainReader && this.mainReader.readSliceSync(this.varText("RS"), this.sliceBox)) {
|
|
2129
|
+
this.incrementCounter("NR");
|
|
2130
|
+
this.incrementCounter("FNR");
|
|
2131
|
+
const setRecPromise = this.setRecordSliceSync(this.sliceBox.source, this.sliceBox.start, this.sliceBox.end);
|
|
2132
|
+
if (setRecPromise instanceof Promise) await setRecPromise;
|
|
2133
|
+
} else if (this.mainReader && this.mainReader.isEnded && this.argument >= number(this.getScalar("ARGC"))) {
|
|
2134
|
+
void this.mainReader.close();
|
|
2135
|
+
this.mainReader = void 0;
|
|
2136
|
+
break;
|
|
2137
|
+
} else {
|
|
2138
|
+
const recOrPromise = this.readMainRecordSync();
|
|
2139
|
+
const record = recOrPromise instanceof Promise ? await recOrPromise : recOrPromise;
|
|
2140
|
+
if (record === void 0) break;
|
|
2141
|
+
const setRecPromise = this.setRecordSync(record);
|
|
2142
|
+
if (setRecPromise instanceof Promise) await setRecPromise;
|
|
2143
|
+
}
|
|
2144
|
+
try {
|
|
2145
|
+
for (let index = 0; index < this.program.rules.length; index++) {
|
|
2146
|
+
const rule = this.program.rules[index];
|
|
2147
|
+
let selected = !rule.pattern || ranges !== void 0 && ranges.has(index);
|
|
2148
|
+
if (!selected) {
|
|
2149
|
+
const patVal = this.scalarExpression(rule.pattern);
|
|
2150
|
+
selected = truth(patVal instanceof Promise ? await patVal : patVal);
|
|
2151
|
+
}
|
|
2152
|
+
if (!selected) continue;
|
|
2153
|
+
if (rule.end) {
|
|
2154
|
+
const endVal = this.scalarExpression(rule.end);
|
|
2155
|
+
if (truth(endVal instanceof Promise ? await endVal : endVal)) ranges?.delete(index);
|
|
2156
|
+
else (ranges ??= /* @__PURE__ */ new Set()).add(index);
|
|
2157
|
+
}
|
|
2158
|
+
const execRes = this.executeSync(rule.action);
|
|
2159
|
+
if (execRes instanceof Promise) await execRes;
|
|
2160
|
+
}
|
|
2161
|
+
} catch (error) {
|
|
2162
|
+
if (!(error instanceof Flow)) throw error;
|
|
2163
|
+
if (error.kind === "exit") {
|
|
2164
|
+
this.exit(error);
|
|
2165
|
+
break;
|
|
2166
|
+
}
|
|
2167
|
+
if (error.kind === "nextfile") {
|
|
2168
|
+
await this.mainReader?.close();
|
|
2169
|
+
this.mainReader = void 0;
|
|
2170
|
+
} else if (error.kind !== "next") throw error;
|
|
2171
|
+
}
|
|
2172
|
+
}
|
|
2173
|
+
if (this.mainReader && !hasMainGetline(this.program.end) && ![...this.program.functions.values()].some(hasMainGetline)) {
|
|
2174
|
+
void this.mainReader.close().catch(() => void 0);
|
|
2175
|
+
}
|
|
2176
|
+
return this.runEndPhaseSyncOrAsync(0);
|
|
2177
|
+
}
|
|
2178
|
+
async _unusedOldRun() {
|
|
2179
|
+
let status = 0, failed = false;
|
|
2180
|
+
let failure;
|
|
2181
|
+
try {
|
|
2182
|
+
status = await this.runProgram();
|
|
2183
|
+
if (this.stdoutBuffer.length > 0) await this.flushStdout();
|
|
2184
|
+
this.syncSpecialVars();
|
|
2185
|
+
await this.inspection?.publish(this.variables);
|
|
2186
|
+
} catch (error) {
|
|
2187
|
+
failed = true;
|
|
2188
|
+
failure = error;
|
|
2189
|
+
}
|
|
2190
|
+
if (this.stdoutBuffer.length > 0) {
|
|
2191
|
+
try {
|
|
2192
|
+
await this.flushStdout();
|
|
2193
|
+
} catch (error) {
|
|
2194
|
+
if (!failed) {
|
|
2195
|
+
failed = true;
|
|
2196
|
+
failure = error;
|
|
2197
|
+
}
|
|
2198
|
+
}
|
|
2199
|
+
}
|
|
2200
|
+
let cleanup;
|
|
2201
|
+
if (this.mainReader && (!this.inputs || this.inputs.size === 0)) {
|
|
2202
|
+
const pendingClose = this.mainReader.closeSyncOrAsync();
|
|
2203
|
+
this.mainReader = void 0;
|
|
2204
|
+
if (pendingClose) {
|
|
2205
|
+
try {
|
|
2206
|
+
await pendingClose;
|
|
2207
|
+
} catch (error) {
|
|
2208
|
+
if (!failed) {
|
|
2209
|
+
failed = true;
|
|
2210
|
+
failure = error;
|
|
2211
|
+
}
|
|
2212
|
+
}
|
|
2213
|
+
}
|
|
2214
|
+
} else if (this.mainReader || this.inputs && this.inputs.size > 0) {
|
|
2215
|
+
const readers = [...this.mainReader ? [this.mainReader] : [], ...this.inputs ? this.inputs.values() : []];
|
|
2216
|
+
this.mainReader = void 0;
|
|
2217
|
+
if (this.inputs) {
|
|
2218
|
+
for (const name of this.inputs.keys()) this.retention.release(shellValueByteLength(name));
|
|
2219
|
+
this.inputs.clear();
|
|
2220
|
+
}
|
|
2221
|
+
cleanup = await Promise.allSettled(readers.map(async (reader) => {
|
|
2222
|
+
await reader.close();
|
|
2223
|
+
}));
|
|
2224
|
+
}
|
|
2225
|
+
if (this.outputs && this.outputs.size > 0) {
|
|
2226
|
+
for (const name of this.outputs) this.retention.release(shellValueByteLength(name));
|
|
2227
|
+
this.outputs.clear();
|
|
2228
|
+
}
|
|
2229
|
+
this.releaseStore(this.variables);
|
|
2230
|
+
this.retention.release(this.recordLength + this.fieldBytes);
|
|
2231
|
+
this.record = "";
|
|
2232
|
+
this.fields = [];
|
|
2233
|
+
this.fieldCount = 0;
|
|
2234
|
+
this.fieldsMaterialized = true;
|
|
2235
|
+
this.fieldBytes = 0;
|
|
2236
|
+
this.sliceBox.source = "";
|
|
2237
|
+
this.recordValue = unset;
|
|
2238
|
+
this.context.signal.throwIfAborted();
|
|
2239
|
+
this.context = RELEASED_AWK_CONTEXT;
|
|
2240
|
+
this.budget.context = RELEASED_AWK_CONTEXT;
|
|
2241
|
+
this.budget.signal = RELEASED_AWK_SIGNAL;
|
|
2242
|
+
if (failed) throw failure;
|
|
2243
|
+
if (cleanup) {
|
|
2244
|
+
for (const result of cleanup) if (result.status === "rejected") throw result.reason;
|
|
2245
|
+
}
|
|
2246
|
+
return status;
|
|
2247
|
+
}
|
|
2248
|
+
async readMainRecord() {
|
|
2249
|
+
const syncRes = this.readMainRecordSync();
|
|
2250
|
+
return syncRes instanceof Promise ? await syncRes : syncRes;
|
|
2251
|
+
}
|
|
2252
|
+
incrementCounter(name) {
|
|
2253
|
+
if (this.frames.length === 0 || !this.frames.at(-1).has(name)) {
|
|
2254
|
+
const nrVal = name === "NR" && !this.nrDirty ? this.variables.get("NR") : void 0;
|
|
2255
|
+
if (nrVal && !("entries" in nrVal) && nrVal.kind === "number") {
|
|
2256
|
+
this.nrNum++;
|
|
2257
|
+
this.nrDirty = true;
|
|
2258
|
+
return;
|
|
2259
|
+
}
|
|
2260
|
+
if (name === "NR" && this.nrDirty) {
|
|
2261
|
+
this.nrNum++;
|
|
2262
|
+
return;
|
|
2263
|
+
}
|
|
2264
|
+
const fnrVal = name === "FNR" && !this.fnrDirty ? this.variables.get("FNR") : void 0;
|
|
2265
|
+
if (fnrVal && !("entries" in fnrVal) && fnrVal.kind === "number") {
|
|
2266
|
+
this.fnrNum++;
|
|
2267
|
+
this.fnrDirty = true;
|
|
2268
|
+
return;
|
|
2269
|
+
}
|
|
2270
|
+
if (name === "FNR" && this.fnrDirty) {
|
|
2271
|
+
this.fnrNum++;
|
|
2272
|
+
return;
|
|
2273
|
+
}
|
|
2274
|
+
}
|
|
2275
|
+
this.set(name, numeric(number(this.getScalar(name)) + 1));
|
|
2276
|
+
}
|
|
2277
|
+
readMainRecordSync() {
|
|
2278
|
+
if (this.mainReader) {
|
|
2279
|
+
this.budget.step();
|
|
2280
|
+
const record = this.mainReader.readSync(this.varText("RS"));
|
|
2281
|
+
if (typeof record === "string") {
|
|
2282
|
+
this.incrementCounter("NR");
|
|
2283
|
+
this.incrementCounter("FNR");
|
|
2284
|
+
return record;
|
|
2285
|
+
}
|
|
2286
|
+
if (record instanceof Promise) {
|
|
2287
|
+
return this.readMainRecordAfterPromise(record);
|
|
2288
|
+
}
|
|
2289
|
+
return this.readMainRecordSlowAfterEof();
|
|
2290
|
+
}
|
|
2291
|
+
return this.readMainRecordSlow();
|
|
2292
|
+
}
|
|
2293
|
+
async readMainRecordAfterPromise(recordPromise) {
|
|
2294
|
+
const resolved = await recordPromise;
|
|
2295
|
+
if (resolved !== void 0) {
|
|
2296
|
+
this.incrementCounter("NR");
|
|
2297
|
+
this.incrementCounter("FNR");
|
|
2298
|
+
return resolved;
|
|
2299
|
+
}
|
|
2300
|
+
return this.readMainRecordSlowAfterEof();
|
|
2301
|
+
}
|
|
2302
|
+
async readMainRecordSlowAfterEof() {
|
|
2303
|
+
await this.mainReader?.close();
|
|
2304
|
+
this.mainReader = void 0;
|
|
2305
|
+
return this.readMainRecordSlow();
|
|
2306
|
+
}
|
|
2307
|
+
async readMainRecordSlow() {
|
|
2308
|
+
while (true) {
|
|
2309
|
+
this.budget.step();
|
|
2310
|
+
if (!this.mainReader) {
|
|
2311
|
+
let file;
|
|
2312
|
+
while (this.argument < number(this.getScalar("ARGC"))) {
|
|
2313
|
+
this.budget.step();
|
|
2314
|
+
const argumentOptions = this.budget.options;
|
|
2315
|
+
if (this.argument > (argumentOptions?.maxArguments ?? Infinity)) throw new ProgramError("argument count limit exceeded");
|
|
2316
|
+
const p = this.budget.checkpointSync();
|
|
2317
|
+
if (p) await p;
|
|
2318
|
+
const next = this.asText(this.array("ARGV").entries.get(String(this.argument++)) ?? unset);
|
|
2319
|
+
if (!next) continue;
|
|
2320
|
+
if (this.operandAssignments && /^[A-Za-z_][A-Za-z0-9_]*=/u.test(next)) {
|
|
2321
|
+
this.assignment(next);
|
|
2322
|
+
continue;
|
|
2323
|
+
}
|
|
2324
|
+
file = next;
|
|
2325
|
+
this.sawFile = true;
|
|
2326
|
+
break;
|
|
2327
|
+
}
|
|
2328
|
+
if (file === void 0 && !this.sawFile && !this.defaultUsed) {
|
|
2329
|
+
file = "-";
|
|
2330
|
+
this.defaultUsed = true;
|
|
2331
|
+
}
|
|
2332
|
+
if (file === void 0) return void 0;
|
|
2333
|
+
this.set("FILENAME", string(file));
|
|
2334
|
+
this.set("FNR", numeric(0));
|
|
2335
|
+
this.mainReader = new Reader(input(this.context, decodeBytes(encodeBytes(file, "latin1"), "utf8")), this.budget, this.retention);
|
|
2336
|
+
}
|
|
2337
|
+
const record = await this.mainReader.read(this.varText("RS"));
|
|
2338
|
+
if (record === void 0) {
|
|
2339
|
+
await this.mainReader.close();
|
|
2340
|
+
this.mainReader = void 0;
|
|
2341
|
+
continue;
|
|
2342
|
+
}
|
|
2343
|
+
this.incrementCounter("NR");
|
|
2344
|
+
this.incrementCounter("FNR");
|
|
2345
|
+
return record;
|
|
2346
|
+
}
|
|
2347
|
+
}
|
|
2348
|
+
tryOpenNextMainReaderSync() {
|
|
2349
|
+
const argc = number(this.getScalar("ARGC"));
|
|
2350
|
+
const argumentOptions = this.budget.options;
|
|
2351
|
+
const maxArgs = argumentOptions?.maxArguments ?? Infinity;
|
|
2352
|
+
while (this.argument < argc) {
|
|
2353
|
+
this.budget.step();
|
|
2354
|
+
if (this.argument > maxArgs) throw new ProgramError("argument count limit exceeded");
|
|
2355
|
+
{
|
|
2356
|
+
const cp = this.budget.checkpointSync();
|
|
2357
|
+
if (cp) {
|
|
2358
|
+
cp.catch(() => {
|
|
2359
|
+
});
|
|
2360
|
+
return false;
|
|
2361
|
+
}
|
|
2362
|
+
}
|
|
2363
|
+
const argIdx = this.argument++;
|
|
2364
|
+
const argKey = argIdx < SMALL_ARG_KEYS.length ? SMALL_ARG_KEYS[argIdx] : String(argIdx);
|
|
2365
|
+
const next = this.asText(this.array("ARGV").entries.get(argKey) ?? unset);
|
|
2366
|
+
if (!next) continue;
|
|
2367
|
+
if (this.operandAssignments && isOperandAssignment(next)) {
|
|
2368
|
+
this.assignment(next);
|
|
2369
|
+
continue;
|
|
2370
|
+
}
|
|
2371
|
+
this.sawFile = true;
|
|
2372
|
+
this.set("FILENAME", string(next));
|
|
2373
|
+
if (this.fnrNum !== 0 || this.fnrDirty || this.variables.get("FNR") !== SCALAR_ZERO) {
|
|
2374
|
+
this.set("FNR", SCALAR_ZERO);
|
|
2375
|
+
}
|
|
2376
|
+
const utf8File = isAsciiText(next) ? next : decodeBytes(encodeBytes(next, "latin1"), "utf8");
|
|
2377
|
+
if (utf8File !== "-") {
|
|
2378
|
+
const fastMem = this.context._fastMemoryBackingFs;
|
|
2379
|
+
if (fastMem && fastMem.capabilitiesFor === void 0 && !Object.prototype.hasOwnProperty.call(fastMem, "readStream") && !Object.prototype.hasOwnProperty.call(fastMem, "readFile")) {
|
|
2380
|
+
const resolvedPath = virtualPath(this.context, utf8File);
|
|
2381
|
+
if (resolvedPath !== "/dev" && !resolvedPath.startsWith("/dev/")) {
|
|
2382
|
+
let rawView;
|
|
2383
|
+
try {
|
|
2384
|
+
rawView = tryReadMemoryFileViewSync(fastMem, resolvedPath, void 0, this.context.signal, true);
|
|
2385
|
+
} catch {
|
|
2386
|
+
rawView = void 0;
|
|
2387
|
+
}
|
|
2388
|
+
if (rawView !== void 0 && rawView.byteLength <= this.budget.maxBufferBytes) {
|
|
2389
|
+
this.context.inputBudget?.check(rawView.byteLength);
|
|
2390
|
+
this.context._chargeFastFsOp?.();
|
|
2391
|
+
this.mainReader = Reader.fromMemoryView(rawView, this.budget, this.retention);
|
|
2392
|
+
return true;
|
|
2393
|
+
}
|
|
2394
|
+
}
|
|
2395
|
+
}
|
|
2396
|
+
}
|
|
2397
|
+
this.mainReader = new Reader(input(this.context, utf8File), this.budget, this.retention);
|
|
2398
|
+
return true;
|
|
2399
|
+
}
|
|
2400
|
+
if (!this.sawFile && !this.defaultUsed) {
|
|
2401
|
+
this.defaultUsed = true;
|
|
2402
|
+
this.set("FILENAME", string("-"));
|
|
2403
|
+
this.set("FNR", numeric(0));
|
|
2404
|
+
this.mainReader = new Reader(input(this.context, "-"), this.budget, this.retention);
|
|
2405
|
+
return true;
|
|
2406
|
+
}
|
|
2407
|
+
return false;
|
|
2408
|
+
}
|
|
2409
|
+
async runProgram() {
|
|
2410
|
+
let stopped = false;
|
|
2411
|
+
try {
|
|
2412
|
+
for (const statement of this.program.begin) await this.execute(statement);
|
|
2413
|
+
} catch (error) {
|
|
2414
|
+
if (error instanceof Flow && error.kind === "exit") {
|
|
2415
|
+
this.exit(error);
|
|
2416
|
+
stopped = true;
|
|
2417
|
+
} else throw error;
|
|
2418
|
+
}
|
|
2419
|
+
this.phase = "record";
|
|
2420
|
+
let ranges;
|
|
2421
|
+
if (!stopped && (this.program.rules.length || this.program.end.length)) {
|
|
2422
|
+
if (!this.mainReader) {
|
|
2423
|
+
this.tryOpenNextMainReaderSync();
|
|
2424
|
+
}
|
|
2425
|
+
while (true) {
|
|
2426
|
+
this.budget.step();
|
|
2427
|
+
if (this.mainReader && this.mainReader.readSliceSync(this.varText("RS"), this.sliceBox)) {
|
|
2428
|
+
this.incrementCounter("NR");
|
|
2429
|
+
this.incrementCounter("FNR");
|
|
2430
|
+
const setRecPromise = this.setRecordSliceSync(this.sliceBox.source, this.sliceBox.start, this.sliceBox.end);
|
|
2431
|
+
if (setRecPromise instanceof Promise) await setRecPromise;
|
|
2432
|
+
} else if (this.mainReader && this.mainReader.isEnded && this.argument >= number(this.getScalar("ARGC"))) {
|
|
2433
|
+
void this.mainReader.close();
|
|
2434
|
+
this.mainReader = void 0;
|
|
2435
|
+
break;
|
|
2436
|
+
} else {
|
|
2437
|
+
const recOrPromise = this.readMainRecordSync();
|
|
2438
|
+
const record = recOrPromise instanceof Promise ? await recOrPromise : recOrPromise;
|
|
2439
|
+
if (record === void 0) break;
|
|
2440
|
+
const setRecPromise = this.setRecordSync(record);
|
|
2441
|
+
if (setRecPromise instanceof Promise) await setRecPromise;
|
|
2442
|
+
}
|
|
2443
|
+
try {
|
|
2444
|
+
for (let index = 0; index < this.program.rules.length; index++) {
|
|
2445
|
+
const rule = this.program.rules[index];
|
|
2446
|
+
let selected = !rule.pattern || ranges !== void 0 && ranges.has(index);
|
|
2447
|
+
if (!selected) {
|
|
2448
|
+
const patVal = this.scalarExpression(rule.pattern);
|
|
2449
|
+
selected = truth(patVal instanceof Promise ? await patVal : patVal);
|
|
2450
|
+
}
|
|
2451
|
+
if (!selected) continue;
|
|
2452
|
+
if (rule.end) {
|
|
2453
|
+
const endVal = this.scalarExpression(rule.end);
|
|
2454
|
+
if (truth(endVal instanceof Promise ? await endVal : endVal)) ranges?.delete(index);
|
|
2455
|
+
else (ranges ??= /* @__PURE__ */ new Set()).add(index);
|
|
2456
|
+
}
|
|
2457
|
+
const execRes = this.executeSync(rule.action);
|
|
2458
|
+
if (execRes instanceof Promise) await execRes;
|
|
2459
|
+
}
|
|
2460
|
+
} catch (error) {
|
|
2461
|
+
if (!(error instanceof Flow)) throw error;
|
|
2462
|
+
if (error.kind === "exit") {
|
|
2463
|
+
this.exit(error);
|
|
2464
|
+
break;
|
|
2465
|
+
}
|
|
2466
|
+
if (error.kind === "nextfile") {
|
|
2467
|
+
await this.mainReader?.close();
|
|
2468
|
+
this.mainReader = void 0;
|
|
2469
|
+
} else if (error.kind !== "next") throw error;
|
|
2470
|
+
}
|
|
2471
|
+
}
|
|
2472
|
+
}
|
|
2473
|
+
if (this.mainReader && !hasMainGetline(this.program.end) && ![...this.program.functions.values()].some(hasMainGetline)) {
|
|
2474
|
+
void this.mainReader.close().catch(() => void 0);
|
|
2475
|
+
}
|
|
2476
|
+
this.phase = "END";
|
|
2477
|
+
try {
|
|
2478
|
+
for (const statement of this.program.end) await this.execute(statement);
|
|
2479
|
+
} catch (error) {
|
|
2480
|
+
if (error instanceof Flow && error.kind === "exit") this.exit(error);
|
|
2481
|
+
else throw error;
|
|
2482
|
+
}
|
|
2483
|
+
return this.status;
|
|
2484
|
+
}
|
|
2485
|
+
};
|
|
2486
|
+
|
|
2487
|
+
export {
|
|
2488
|
+
AwkRuntime
|
|
2489
|
+
};
|