@preventive/triage 1.0.0-alpha.15 → 1.0.0-alpha.16
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/common/scan-server.ts +13 -0
- package/common/server-info.ts +1 -0
- package/common/utf8.d.ts +3 -0
- package/common/utf8.js +45 -0
- package/out/client-managed.js +83 -1
- package/out/client-sync.js +14 -14
- package/out/graph.js +11 -11
- package/out/index.html +3 -2
- package/out/provider-icons/claude.svg +1 -0
- package/out/provider-icons/deepseek.svg +1 -0
- package/out/provider-icons/google.svg +1 -0
- package/out/provider-icons/grok.svg +1 -0
- package/out/provider-icons/moonshot.svg +1 -0
- package/out/provider-icons/nvidia.svg +1 -0
- package/out/provider-icons/openai.svg +1 -0
- package/out/provider-icons/openrouter.svg +1 -0
- package/out/provider-icons/qwen.svg +1 -0
- package/out/provider-icons/zai.svg +1 -0
- package/out/terminal.js +202 -191
- package/out/view.css +1 -1
- package/out/view.js +138 -135
- package/package.json +6 -3
- package/report/index.js +1 -1
- package/report/src/md-structure.js +1 -1
- package/report/src/meta.js +25 -0
- package/report/src/parse-md.js +71 -2
- package/server-common/scan-config.ts +19 -0
- package/server-e2e/config.ts +6 -0
- package/server-e2e/http.ts +1 -1
- package/server-e2e/index.ts +1 -2
- package/server-e2e/static.ts +19 -11
- package/out/client-admin.js +0 -28
package/out/terminal.js
CHANGED
|
@@ -1,136 +1,147 @@
|
|
|
1
|
-
var
|
|
1
|
+
var Uh=Object.defineProperty;var Bh=(e,t)=>{for(var n in t)Uh(e,n,{get:t[n],enumerable:!0})};var Wu=globalThis[Symbol.for("@rray/frontend")];if(!Wu)throw new Error("@rray/frontend global not installed; view.js must run before lazy bundles import this wrapper");var{LitElement:ju,html:Re,nothing:ji,unsafeCSS:zu,render:ZS,StateElement:YS,classMap:VS,repeat:Hu,styleMap:KS}=Wu;var C=(e="")=>({stdout:e,stderr:"",exitCode:0}),y=(e,t=1)=>({stdout:"",stderr:e.endsWith(`
|
|
2
2
|
`)?e:e+`
|
|
3
|
-
`,exitCode:t}),oe=(e,t=1)=>y(`usage: ${e}`,t);function P(e,t,n){let r=$(e.cwd,n,e.fs);return D(e,t,n,r.error),r}function D(e,t,n,r){if(r!=="No such file or directory"||typeof n!="string")return;let i=n.startsWith("/"),o=i?"/":e.cwd,s=n.replace(/^\/+/u,""),u=new Set;for(let c of new Set(["/",e.mount??"/",e.home??"/"])){if(c===o)continue;let f=$(c,s,e.fs);f.error||u.add(f.path)}if(!u.size)return;let a=i?"":` from cwd ${JSON.stringify(e.cwd)}`,l=`${i?"absolute":"relative"} path ${JSON.stringify(n)} was not found${a}`;e.notes?.add(`${t}: ${l}. ${Yh(e,u)}`)}function Yh(e,t){let n=[...t].sort(U),r=n.map(u=>JSON.stringify(u));if(n.length===1)return`A ${e.fs.isDir(n[0])?"dir":"file"} exists at ${r[0]}.`;let o=n.every(u=>!e.fs.isDir(u)&&e.fs.isFile(u))&&n.some(u=>!e.fs.sameFileContents(n[0],u)),s=`${r.slice(0,-1).join(", ")} and ${r.at(-1)}`;return`${n.length===2?"Both":"All"} of ${s} exist${o?", and they differ in contents":""}.`}function Pt(){let e=new Set;return{add:t=>e.add(t),collect(t,n){for(let r of n)r.startsWith(".")&&e.add(L(t,r))},emit(t,n,r,i=""){st(t,{command:n,action:"omitted",noun:["hidden entry","hidden entries"],explanation:r,context:i,paths:e})}}}var vu=/^(?<command>[^:]+): (?<operand>.+): (?<reason>no such file or directory|not a directory|is a directory)$/iu;function ku(e,t){for(let n of t.split(`
|
|
4
|
-
`))
|
|
5
|
-
`){if(e==="")return[];let n=e.split(t);return n.at(-1)===""&&n.pop(),n}var
|
|
6
|
-
`)=>e.length===0?"":e.join(t)+t;function
|
|
7
|
-
`){let n=[];for(let r=0;r<e.length;){let i=e.indexOf(t,r),o=i<0?e.length:i+t.length;n.push(e.slice(r,o)),r=o}return n}function
|
|
8
|
-
`}function te(e,t,n,r,i){if(t.length===0){z(r);let o=[{name:null,content:n,kind:"file"}];return{inputs:o,entries:o,stderr:"",failed:!1}}return Ye(e,t,r,n,i)}function Uu(e,t){return e===null||e==="-"||e==="/dev/stdin"?t.stdinHandle?.path?JSON.stringify(t.stdinHandle.path):"standard input":JSON.stringify($(t.cwd,e,t.fs).path??e)}function mn(e,t,n,r){let i=te(e,t,n,r);return{content:i.inputs.map(o=>o.content).join(""),stderr:i.stderr,failed:i.failed}}var ue=(e,t)=>({stdout:e,stderr:t.stderr,exitCode:t.failed?1:0});function pe(e,t,n=e,{max:r=1/0,digitsOnly:i=!1}={}){if(typeof e!="string"||!(i?/^\d+$/u:/^[ \t\n\r\f\v]*\+?\d+$/u).test(e))return{error:y(`${t}: invalid count: ${n}`)};let o=Number(e);return o>r?{error:y(`${t}: out of range: ${n}`)}:{value:Math.min(o,Number.MAX_SAFE_INTEGER)}}function Bu(e,t){if(typeof e!="string")return{error:y(`${t}: invalid count: ${e}`)};let n=e[0]==="+"||e[0]==="-"?e[0]:"",r=n==="-"?e.slice(1):e,i=/^[ \t\n\r\v\f]*\+?(\d+)(b|[kKMGTPEZYRQ](?:i?B)?)?$/u.exec(r),o=!n&&/^(?:b|[kKMGTPEZYRQ](?:i?B)?)$/u.test(r);if(!i&&!o)return{error:y(`${t}: invalid count: ${e}`)};let s=i?.[2]??(o?r:""),u=Di(BigInt(i?.[1]??"1"),s,t,e);return u.error?u:{...u,sign:n}}function Di(e,t,n,r){let i=1n;t==="b"?i=512n:t&&(i=(t.length===2?1000n:1024n)**BigInt("KMGTPEZYRQ".indexOf(t[0].toUpperCase())+1));let o=e*i;return o>Ze?{error:y(`${n}: count out of range: ${r}`)}:{value:Number(o>BigInt(Number.MAX_SAFE_INTEGER)?BigInt(Number.MAX_SAFE_INTEGER):o)}}function G(e){try{let t=e?.message;return typeof t=="string"&&t!==""?t:String(e)}catch{return"threw a value with no message"}}function gn(e){let t=e.startsWith("/"),n=e.split("/").filter(Boolean),r=[];for(let i of n)if(i!=="."){if(i===".."){r.length>0&&r.at(-1)!==".."?r.pop():t||r.push("..");continue}r.push(i)}return t?"/"+r.join("/"):r.length===0?".":r.join("/")}function L(e,t){return t.startsWith("/")?gn(t):gn(e+"/"+t)}function $(e,t,n){let r={path:null,error:"No such file or directory"},i={path:null,error:"Not a directory"};if(t===""||t.includes("\0"))return r;let o=(t.startsWith("/")?t:e+"/"+t).split("/").filter(Boolean),s="/";for(let u of o){if(!n.isDir(s))return n.isFile(s)?i:r;u===".."?s=vt(s):u!=="."&&(s=Ce(s,u))}return!n.isDir(s)&&!n.isFile(s)?r:t.endsWith("/")&&!n.isDir(s)?i:{path:s,error:null}}function Ke(e,t,n,r=$(e,t,n)){if(r.path!==null)return null;if(t===""||t.includes("\0")||t.endsWith("/")||r.error!=="No such file or directory")return r.error;let i=t.lastIndexOf("/"),o=$(e,i<0?".":t.slice(0,i)||"/",n);return o.error??(n.isDir(o.path)?null:"Not a directory")}function vt(e){let t=gn(e);if(t==="/")return"/";let n=t.lastIndexOf("/");return n<0?".":n===0?"/":t.slice(0,n)}function kt(e){let t=gn(e);if(t==="/")return"/";let n=t.lastIndexOf("/");return t.slice(n+1)}function U(e,t){for(let n=0;n<Math.min(e.length,t.length);n++)if(e[n]!==t[n])return e.codePointAt(n)-t.codePointAt(n);return e.length-t.length}function Ce(e,t){return e==="/"?"/"+t:e+"/"+t}function ut(e,t){return e==="/"?t.slice(1):t.slice(e.length+1)}function zu(e,t="/"){let n=new Map;for(let[o,s]of om(e)){if(typeof s!="string")continue;let u=String(o);if(u.includes("\0"))throw new TypeError("createTerminal: source paths must not contain NUL characters");let a=gn("/"+u);n.set(t==="/"?a:a==="/"?t:t+a,s)}let r=new Map([["/",{dirs:[],files:[]}]]);Wu(r,t);for(let o of n.keys()){let s=o.lastIndexOf("/"),u=o.slice(0,s)||"/";Wu(r,u),r.get(u).files.push(o==="/"?"/":o.slice(s+1))}for(let o of r.values())o.dirs.sort(U),o.files.sort(U);let i={isFile:o=>n.has(o),isDir:o=>r.has(o),readFile:o=>n.get(o),fileSize:o=>n.has(o)&&!r.has(o)?ee(n.get(o)).length:void 0,sameFileContents:(o,s)=>n.get(o)===n.get(s),listDir:o=>{let s=r.get(o);if(!s)throw new Error(`not a directory: ${o}`);return s},walkFiles:o=>sm(i,o)};return i}function om(e){try{return Map.prototype.entries.call(e)}catch{return Object.entries(e??{})}}function*Fe(e,t,n=Number.POSITIVE_INFINITY,r=()=>!0){if(e.isFile(t)){yield{path:t,kind:"file",depth:0};return}if(!e.isDir(t))return;let i=[{path:t,kind:"dir",depth:0}];for(;i.length;){let o=i.pop();if(yield o,o.kind!=="dir"||o.depth>=n||!r(o.path))continue;let{dirs:s,files:u}=e.listDir(o.path),a=s.length-1,l=u.length-1;for(;a>=0||l>=0;){let c=l<0||a>=0&&U(s[a],u[l])>0,f=c?s[a--]:u[l--];i.push({path:Ce(o.path,f),kind:c?"dir":"file",depth:o.depth+1})}}}function*sm(e,t){for(let n of Fe(e,t))n.kind==="file"&&(yield n.path)}function Wu(e,t){let n=[],r=t;for(;r!=="/"&&!e.has(r);)n.push(r),r=r.slice(0,r.lastIndexOf("/"))||"/";for(let i=n.length-1;i>=0;i--){let o=n[i];e.set(o,{dirs:[],files:[]});let s=o.lastIndexOf("/");e.get(o.slice(0,s)||"/").dirs.push(o.slice(s+1))}}var at=e=>e==="/tmp"||e.startsWith("/tmp/");function qu(e){let t=new Map,n=new Set(["/tmp"]),r,i=e.listDir("/"),o={dirs:[...i.dirs,"tmp"].sort(U),files:i.files},s=cm(n,t),u=s.reshaped,a=(c,f)=>{if(!c.startsWith("/tmp/"))throw new Error("writable overlay paths must start with /tmp/");t.has(c)||u(),t.set(c,f)},l={observeIo:c=>{r=c},fileIdentity:c=>t.get(c),fileSize:c=>t.get(c)?.bytes.length??e.fileSize(c),readIdentity:c=>(r?.read(c),M(c.bytes)),isFile:c=>t.has(c)||e.isFile(c),isDir:c=>n.has(c)||e.isDir(c),readFile:c=>{let f=t.get(c);return r?.read(f??c),f?M(f.bytes):e.readFile(c)},sameFileContents:(c,f)=>fm(e,t,c,f),listDir:c=>c==="/"?o:n.has(c)?s.of(c):e.listDir(c),*walkFiles(c){for(let f of Fe(l,c))f.kind==="file"&&(yield f.path)},openWritable(c,f,d=!1){let p=L(c,f);if(p!=="/tmp"&&!p.startsWith("/tmp/"))return null;wn(l,c,f);let m=t.get(p);return m?d||(r?.write(m),m.bytes=new Uint8Array):(m={bytes:new Uint8Array},a(p,m)),dm(p,m,d,()=>r?.write(m))},makeWritableDir:(c,f)=>um(l,{dirs:n,files:t,reshaped:u},c,f),removeWritableDir:(c,f)=>lm(l,{dirs:n,reshaped:u},c,f),copyWritable(c,f,d){let p=L(c,d);if(!p.startsWith("/tmp/"))return!1;wn(l,c,d);let m=t.get(f);if(f===p||m&&m===t.get(p))throw new Error("source and destination are the same file");r?.read(m??f);let h=m?m.bytes:ee(e.readFile(f));return l.openWritable(c,d).writeBytes(h),!0},replaceWritable:(c,f,d,p)=>am(l,{files:t,put:a},c,f,d,p),removeWritable(c,f){let d=L(c,f);if(d!=="/tmp"&&!d.startsWith("/tmp/"))return!1;let p=$(c,f,l);if(p.error)throw xn(f,p.error);if(l.isDir(p.path))throw new Error(`${f}: Is a directory`);return t.delete(p.path),u(),!0}};return l}function um(e,t,n,r){let i=L(n,r);if(i!=="/tmp"&&!i.startsWith("/tmp/"))return!1;if(t.dirs.has(i))return!0;if(wn(e,n,r),t.files.has(i))throw new Error(`${r}: File exists`);return t.dirs.add(i),t.reshaped(),!0}function am(e,t,n,r,i,o){let s=L(n,r),u=o===void 0?null:L(n,o);if(!s.startsWith("/tmp/")||u!==null&&!u.startsWith("/tmp/"))return!1;wn(e,n,r);let a=t.files.get(s);if(!a)throw xn(r,"No such file or directory");u!==null&&wn(e,n,o);let l={bytes:ee(i)};return u!==null&&t.put(u,a),t.put(s,l),!0}function lm(e,t,n,r){let i=L(n,r);if(i!=="/tmp"&&!i.startsWith("/tmp/"))return!1;let o=$(n,r,e);if(o.error)throw xn(r,o.error);if(!t.dirs.has(o.path))throw new Error(`${r}: Not a directory`);if(o.path==="/tmp")throw new Error(`${r}: Device or resource busy`);let{dirs:s,files:u}=e.listDir(o.path);if(s.length||u.length)throw new Error(`${r}: Directory not empty`);return t.dirs.delete(o.path),t.reshaped(),!0}function cm(e,t){let n=new Map,r=(i,o)=>[...i].filter(s=>s.startsWith(o)&&!s.slice(o.length).includes("/")).map(s=>s.slice(o.length)).sort(U);return{reshaped:()=>{n=new Map},of(i){let o=n.get(i);if(o)return o;let s={dirs:r(e,i+"/"),files:r(t.keys(),i+"/")};return n.set(i,s),s}}}function fm(e,t,n,r){let i=t.get(n),o=t.get(r);if(!i&&!o)return e.sameFileContents(n,r);let s=(l,c)=>{if(c)return c.bytes;let f=e.readFile(l);return f.isWellFormed()?ee(f):null},u=s(n,i),a=s(r,o);return u!==null&&a!==null&&u.length===a.length&&u.every((l,c)=>l===a[c])}function wn(e,t,n){let r=$(t,n,e);if(r.path!==null){if(e.isDir(r.path))throw new Error(`${n}: Is a directory`);return}if(r.error!=="No such file or directory"||n.includes("\0")||n.endsWith("/"))throw xn(n,r.error);let i=n.lastIndexOf("/"),o=i<0?".":n.slice(0,i)||"/",s=$(t,o,e);if(s.error)throw xn(n,s.error);if(!e.isDir(s.path))throw new Error(`${n}: Not a directory`)}function xn(e,t){return Object.assign(new Error(`${e}: ${t}`),{path:e,fsError:t})}function dm(e,t,n,r){let i=0,o=s=>{let u=t.bytes,a=n?u.length:i,l=Math.max(u.length,a+s.length),c=u.buffer;c.byteLength<l&&(c=new ArrayBuffer(Math.max(l,c.byteLength*2)),new Uint8Array(c).set(u));let f=new Uint8Array(c,0,l);f.set(s,a),t.bytes=f,i=a+s.length};return{path:e,identity:t,get position(){return n?t.bytes.length:i},write(s){s!==""&&(r(),o(ee(s)))},writeBytes(s){s.length!==0&&(r(),o(s))}}}var ju=["cwd","home","user","inherit"];function Hu(e,t){let n=yn(t,"mount","/"),r=yn(t,"home",n),i=yn(t,"cwd",n);if(t.writable!==void 0&&t.writable!==!1&&t.writable!=="/tmp/")throw new TypeError("createTerminal: writable must be '/tmp/', false, or undefined");let o=t.writable==="/tmp/";if(o&&(n==="/"||n==="/tmp"||n.startsWith("/tmp/")))throw new Error("createTerminal: mount must not be /, /tmp, or inside /tmp when writable is '/tmp/'");let s=zu(e,n);return{fs:o?qu(s):s,cwd:i,home:r,mount:n,writable:o,locale:Pu(t)}}function Gu(e,t){if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(`fork: options must be an object (got ${t===null?"null":Array.isArray(t)?"an array":typeof t})`);for(let n of Object.keys(t))if(!ju.includes(n))throw new Error(`fork: unknown option \`${n}\` (known: ${ju.join(", ")}; the sources, the mount, the /tmp/ overlay and the commands come from the parent)`);if(t.inherit!==void 0&&typeof t.inherit!="boolean")throw new TypeError(`fork: inherit must be true or false (got ${t.inherit===null?"null":typeof t.inherit})`);return{cwd:yn(t,"cwd",e.cwd,"fork",e.cwd),home:yn(t,"home",e.home,"fork",e.cwd),user:t.user??e.user,locale:e.locale,inherit:t.inherit??!0}}function yn(e,t,n,r="createTerminal",i="/"){let o=e[t]===void 0?n:e[t];if(typeof o!="string"||o.includes("\0"))throw new TypeError(`${r}: ${t} must be a string without NUL characters`);return L(i,o)}function fe(e,t=0,n=e.value.length){return{value:e.value.slice(t,n),mask:e.mask===null?null:e.mask.slice(t,n),...e.empty?{empty:e.empty.filter(r=>r>=t&&r<=n).map(r=>r-t)}:{}}}function bn(e){let t=/^([A-Za-z_][A-Za-z0-9_]*)=/u.exec(e.value);return!t||e.mask!==null&&/[12]/u.test(e.mask.slice(0,t[0].length))||e.empty?.some(n=>n<t[0].length)?null:{name:t[1],end:t[0].length}}var Xu=(e,t)=>e.mask===null?"0":e.mask[t];function mr(e,t=!1){let n=new Set;if(!e.value.includes("~"))return n;let r=e.value,i=u=>Xu(e,u)==="0",o=t?null:bn(e)?.end??null,s=u=>t===!0||o!==null&&u>=o;for(let u=0;u<r.length;u++){let a=u===0||u===o||s(u)&&r[u-1]===":"&&i(u-1),l=s(u)||t==="parameterAssign";if(!a||r[u]!=="~"||!i(u)||!pm(e,u,l))continue;let c=r[u+1];if(c&&c!=="/"&&c!==":"&&i(u+1))throw new w("feature","tilde prefix","named-user and directory-stack tilde prefixes are not supported");(c===void 0||i(u+1)&&(c==="/"||c===":"&&l))&&n.add(u)}return n}function pm(e,t,n){for(let r=t;r<=e.value.length;r++){if(e.empty?.includes(r))return!1;if(r===e.value.length)return!0;if(Xu(e,r)!=="0")return!1;if(e.value[r]==="/"||n&&e.value[r]===":")return!0}return!0}function Zu(...e){let t="",n="",r=[];for(let i of e){for(let o of i.empty??[])r.push(t.length+o);t+=i.value,n+=i.mask??"0".repeat(i.value.length)}return{value:t,mask:e.every(i=>i.mask===null)?null:n,...r.length?{empty:r}:{}}}var Dt=64;function Te(e,t){let n="";for(let r=t+1;r<e.length;r++){let i=e[r];if(i==="`")return{command:n,raw:e.slice(t,r+1),backtick:!0};if(i!=="\\"){n+=i;continue}let o=e[r+1];if(o==="`")throw new w("feature","\\`","nested backtick command substitution is not supported; use `$( )` instead");if(o==="$"||o==="\\"){n+=o,r++;continue}if(o===`
|
|
9
|
-
`){r++;continue}n+=i}throw new Error("unterminated backtick substitution")}var
|
|
3
|
+
`,exitCode:t}),de=(e,t=1)=>y(`usage: ${e}`,t);var Gu=Symbol("unsupported");function O(e){if(e==null)return null;try{return e[Gu]??null}catch{return null}}function k(e,t,n,r,i=1){return re(y(r,i),e,t,n,r)}function re(e,t,n,r,i){return Object.defineProperty(e,Gu,{value:{kind:t,command:n,detail:r,message:i},enumerable:!1,configurable:!0}),e}function Y(e,t,n,r){let i=O(e);return i?k(i.kind,t,i.detail,n,r):y(n,r)}var w=class extends Error{constructor(t,n,r){super(r),this.name="UnsupportedError",re(this,t,null,n,r)}};function zi(){let e=new Set,t=[];return{entries:t,add(n,r=n.command){let i=JSON.stringify([n.kind,r,n.detail]);e.has(i)||(e.add(i),t.push(Object.freeze(n)))}}}var{Buffer:Xu}=globalThis,Yu=Xu&&!Xu.TYPED_ARRAY_SUPPORT;var Zu=e=>e&&(Yu||`${e}`.includes("[native code]"));!Yu&&Zu(()=>{})&&(Zu=()=>!1);function Hi(e,t){let n=e.length;for(let r=0;r<n;r++)t[r]=e.charCodeAt(r);return t}var gn=null,wn=!1,Vu=!1,qe=new TextEncoder,We=new TextDecoder("utf-8",{ignoreBOM:!0}),Gi=new TextDecoder("latin1",{ignoreBOM:!0});var Xi=globalThis.Buffer;function kr(e){if(!(e&&e instanceof Uint8Array))throw new TypeError("Expected an Uint8Array")}var vr="Input is not a string",Zi="Input is not well-formed Unicode";function Nt(e,t){switch(t){case"uint8":if(e.constructor!==Uint8Array)throw new Error("Unexpected");return e;case"arraybuffer":if(e.byteLength!==e.buffer.byteLength)throw new Error("Unexpected");return e.buffer;case"buffer":return e.length<=64?Xi.from(e):Xi.from(e.buffer,e.byteOffset,e.byteLength)}throw new TypeError("Unexpected format")}function Ku(e,t){switch(t){case"uint8":return e.length<=64||e.byteOffset!==0||e.byteLength!==e.buffer.byteLength?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength);case"arraybuffer":return e.buffer.byteLength===e.byteLength?e.buffer:e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength);case"buffer":if(e.constructor!==Xi)throw new Error("Unexpected");return e}throw new TypeError("Unexpected format")}var jh=We,zh=We?new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}):null,{isWellFormed:Qu}=String.prototype;function Hh(e,t,n){if(t||e.length===n.length)return n;if(Qu){if(Qu.call(e))return n;throw new TypeError(Zi)}let r=0,i=n.length-3;for(;r<=i;){let o=n.indexOf(239,r);if(o===-1||o>i)break;if(r=o+1,n[o+1]===191&&n[o+2]===189){if(null)try{if(encodeURI(e)!==null)return n}catch{}else if(e===Yi(n))return n;throw new TypeError(Zi)}}return n}function ea(e,t=!1){if(typeof e!="string")throw new TypeError(vr);return e.length===0?new Uint8Array:qe||!null?Hh(e,t,qe.encode(e)):null(e,t)}function Yi(e,t=!1){return kr(e),e.byteLength===0?"":We||!null?t?jh.decode(e):zh.decode(e):null(e,t)}var ta=(e,t="uint8")=>Nt(ea(e,!1),t),A=(e,t="uint8")=>Nt(ea(e,!0),t),Vi=e=>Yi(e,!1),na=e=>Yi(e,!0);function q(e){try{return ta(e)}catch(t){throw t instanceof TypeError?new w("feature","unpaired surrogate","unpaired UTF-16 surrogates cannot be encoded as UTF-8"):t}}var Gh=e=>e<128?1:e>=194&&e<=223?2:e>=224&&e<=239?3:e>=240&&e<=244?4:0;function*Sr(e){for(let t=0;t<e.length;){let n=Gh(e[t]),r=n===1?e[t]:n===0?-1:Zh(e,t,n);yield r,t+=r<0?1:n}}var Xh=[0,0,128,2048,65536];function Zh(e,t,n){if(t+n>e.length)return-1;let r=e[t]&127>>n;for(let i=1;i<n;i++){if((e[t+i]&192)!==128)return-1;r=r<<6|e[t+i]&63}return r<Xh[n]||r>1114111||r>=55296&&r<=57343?-1:r}var Ki=e=>na(e);function pt(e){let t;try{t=Vi(e)}catch{}return t}function P(e){try{return Vi(e)}catch{throw new w("feature","partial UTF-8 byte sequence","byte output that is not valid UTF-8 cannot be represented by this string-based terminal")}}function ra(e){if(Object.keys(e).length>0)throw new TypeError("Unexpected extra options")}var h$=Object.getPrototypeOf(Uint8Array);var oa=globalThis.atob,sa=Uint8Array.prototype.toBase64,ia=8192,Yh=sa&&oa;function Ji(e,t=0,n=e.length){t|=0,n|=0;let r=n-t;if(r===0)return"";if(Yh&&r>=256&&r<1e8&&e.toBase64===sa&&e.BYTES_PER_ELEMENT===1){let o=t===0&&n===e.length?e:e.subarray(t,n);return oa(o.toBase64())}if(r>ia){let o="";for(let s=t;s<n;){let u=Math.min(n,s+ia);o+=String.fromCharCode.apply(String,e.subarray(s,u)),s=u}return o}let i=t===0&&n===e.length?e:e.subarray(t,n);return String.fromCharCode.apply(String,i)}var ua=gn?e=>e.byteLength>=768&&!Vu?gn.from(e.buffer,e.byteOffset,e.byteLength).latin1Slice(0,e.byteLength):We.decode(e):Gi?e=>Gi.decode(e):e=>Ji(e instanceof Uint8Array?e:new Uint8Array(e.buffer,e.byteOffset,e.byteLength));var aa=e=>Hi(e,new Uint8Array(e.length)),Vh=wn&&qe?.encodeInto,la=Vh?(e,t)=>{let n=new Uint8Array(e.length+4),r=qe.encodeInto(e,n);if(r.read!==e.length||r.written!==e.length)throw new SyntaxError(t);return n.subarray(0,e.length)}:gn?(e,t)=>{let n=gn.from(e,"utf8");if(n.length!==e.length)throw new SyntaxError(t);return new Uint8Array(n.buffer,n.byteOffset,n.byteLength)}:(e,t)=>{let n=qe.encode(e);if(n.length!==e.length)throw new SyntaxError(t);return n};var no={};Bh(no,{E_CHAR:()=>Ht,E_LAST:()=>Qi,E_LENGTH:()=>ma,E_PADDING:()=>ha,fromBase64:()=>to,toBase64:()=>eo});var fa=[..."ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"],ca=[..."ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"],da={},pa={},Ht="Invalid character in base64 input",ha="Invalid base64 padding",ma="Invalid base64 length",Qi="Invalid last chunk";function eo(e,t,n){let r=e.length/3|0,i=r*3,o="",s=0,u=t?ca:fa,a=t?pa:da;if(!a.pairs)if(a.pairs=[],We){a.codepairs=new Uint16Array(4096);let h=a.codepairs,m=new Uint8Array(h.buffer,h.byteOffset,h.byteLength);for(let g=0;g<64;g++){let b=u[g].charCodeAt(0);for(let x=0;x<64;x++)m[g<<7|x<<1]=m[x<<7|(g<<1)+1]=b}}else{let h=a.pairs;for(let m=0;m<64;m++)for(let g=0;g<64;g++)h.push(`${u[m]}${u[g]}`)}let{pairs:l,codepairs:f}=a;if(We){let h=new Uint16Array(r*2),m=0;for(let g=e.length-11;s<g;s+=12,m+=8){let b=e[s],x=e[s+1],S=e[s+2],E=e[s+3],M=e[s+4],D=e[s+5],T=e[s+6],ne=e[s+7],Le=e[s+8],z=e[s+9],ce=e[s+10],zt=e[s+11];h[m]=f[b<<4|x>>4],h[m+1]=f[(x&15)<<8|S],h[m+2]=f[E<<4|M>>4],h[m+3]=f[(M&15)<<8|D],h[m+4]=f[T<<4|ne>>4],h[m+5]=f[(ne&15)<<8|Le],h[m+6]=f[z<<4|ce>>4],h[m+7]=f[(ce&15)<<8|zt]}for(let g=e.length-2;s<g;s+=3,m+=2){let b=e[s],x=e[s+1],S=e[s+2];h[m]=f[b<<4|x>>4],h[m+1]=f[(x&15)<<8|S]}o=ua(h)}else for(;s<i;s+=3){let h=e[s],m=e[s+1],g=e[s+2];o+=l[h<<4|m>>4],o+=l[(m&15)<<8|g]}let c=0,d=2,p=e.length;for(;s<p;s++){let h=e[s];o+=u[c|h>>d],d===6&&(d=0,o+=u[h&63]),c=h<<6-d&63,d+=2}return d!==2&&(o+=u[c]),n&&(o+=["","==","="][p-i]),o}var Kh=qe?128:65536;function to(e,t){let n=e.length;for(;e[n-1]==="=";)n--;let r=e.length-n,i=n%4,o=n-i;if(i===1)throw new SyntaxError(ma);if(r>3||r!==0&&e.length%4!==0)throw new SyntaxError(ha);let s=t?ca:fa,u=t?pa:da;u.fromMap||(u.fromMap=new Int8Array(Kh).fill(-1),s.forEach((h,m)=>u.fromMap[h.charCodeAt(0)]=m));let a=u.fromMap,l=new Uint8Array(Math.floor(n*3/4)),f=0,c=0;if(qe){let h=la(e,Ht);for(;c<o;c+=4){let m=h[c],g=h[c+1],b=h[c+2],x=h[c+3],S=a[m]<<18|a[g]<<12|a[b]<<6|a[x];if(S<0)throw new SyntaxError(Ht);l[f]=S>>16,l[f+1]=S>>8&255,l[f+2]=S&255,f+=3}}else for(;c<o;c+=4){let h=e.charCodeAt(c),m=e.charCodeAt(c+1),g=e.charCodeAt(c+2),b=e.charCodeAt(c+3),x=a[h]<<18|a[m]<<12|a[g]<<6|a[b];if(x<0)throw new SyntaxError(Ht);l[f]=x>>16,l[f+1]=x>>8&255,l[f+2]=x&255,f+=3}if(i<2)return l;let d=a[e.charCodeAt(c++)]<<6|a[e.charCodeAt(c++)];if(d<0)throw new SyntaxError(Ht);if(l[f++]=d>>4,i<3){if(d&15)throw new SyntaxError(Qi);return l}let p=a[e.charCodeAt(c++)];if(p<0)throw new SyntaxError(Ht);if(l[f++]=d<<4&255|p>>2,p&3)throw new SyntaxError(Qi);return l}var{Buffer:At,atob:ya,btoa:xa}=globalThis,ka=At&&!At.TYPED_ARRAY_SUPPORT,{toBase64:ga}=Uint8Array.prototype,{E_CHAR:bn,E_PADDING:$r,E_LENGTH:Jh,E_LAST:Qh}=no,em=xa&&wn,tm=ya&&wn,nm=e=>e.constructor===At&&At.isBuffer(e),rm=e=>nm(e)?e:At.from(e.buffer,e.byteOffset,e.byteLength);function ro(e,t){if(t)return e;let n=e.indexOf("=",e.length-3);return n===-1?e:e.slice(0,n)}function im(e,t){return t&&e.length%4!==0?e+"=".repeat(4-e.length%4):e}var om=e=>ga&&e.toBase64===ga;function io(e,{padding:t=!0}={}){return kr(e),om(e)?t?e.toBase64():e.toBase64({omitPadding:!t}):ka?ro(rm(e).base64Slice(0,e.byteLength),t):em?ro(xa(Ji(e)),t):eo(e,!1,t)}function xn(e,t){if(typeof t=="string"&&(t={format:t}),!t)return wa(e,!1,"both","uint8",null);let{format:n="uint8",padding:r="both",...i}=t;return wa(e,!1,r,n,i)}function wa(e,t,n,r,i){if(typeof e!="string")throw new TypeError(vr);i!==null&&ra(i);let o=n==="both"?e.endsWith("="):void 0;if(n===!0||o===!0){if(e.length%4!==0)throw new SyntaxError($r);if(e[e.length-3]==="=")throw new SyntaxError($r)}else if(n===!1||o===!1){if(e.length%4===1)throw new SyntaxError(Jh);if(n===!1&&e.endsWith("="))throw new SyntaxError("Did not expect padding in base64 input")}else throw new TypeError("Invalid padding option");return yn(e,t,n,r)}var sm=/[\t\n\f\r ]/;function ba(e,t){let n=e.indexOf("=",e.length-3),r=n>=0?e.length-n:0,i=e.length-r,o=i%4,s=t.length-(i-o)/4*3;return o===0&&s===0||o===2&&s===1||o===3&&s===2}var yn;Uint8Array.fromBase64?yn=(e,t,n,r)=>{let i=t?"base64url":"base64",o;if(n===!0)o=Uint8Array.fromBase64(e,{alphabet:i,lastChunkHandling:"strict"});else try{let s=e.length%4>0?`${e}${"=".repeat(4-e.length%4)}`:e;o=Uint8Array.fromBase64(s,{alphabet:i,lastChunkHandling:"strict"})}catch(s){throw sm.test(e)?new SyntaxError(bn):s}if(!ba(e,o))throw new SyntaxError(bn);return Nt(o,r)}:ka?yn=(e,t,n,r)=>{let i=At.byteLength(e,"base64"),o=At.allocUnsafeSlow(i);if(o.base64Write(e)!==i)throw new SyntaxError($r);let s=t?ro(e,n===!1):im(e,n!==!0),u=t?o.base64urlSlice(0,o.length):o.base64Slice(0,o.length);if(s!==u)throw new SyntaxError($r);return Ku(o,r)}:tm?yn=(e,t,n,r)=>{let i;if(t){if(/[\t\n\f\r +/]/.test(e))throw new SyntaxError(bn);e=e.replaceAll("-","+").replaceAll("_","/")}try{i=aa(ya(e))}catch{throw new SyntaxError(bn)}if(!t&&!ba(e,i))throw new SyntaxError(bn);if(i.length%3!==0){let o=io(i.subarray(-(i.length%3))),s=e.length%4===0?e.slice(-4):e.slice(-(e.length%4)).padEnd(4,"=");if(o!==s)throw new SyntaxError(Qh)}return Nt(i,r)}:yn=(e,t,n,r)=>Nt(to(e,t),r);function kn(e){let t=e.startsWith("/"),n=e.split("/").filter(Boolean),r=[];for(let i of n)if(i!=="."){if(i===".."){r.length>0&&r.at(-1)!==".."?r.pop():t||r.push("..");continue}r.push(i)}return t?"/"+r.join("/"):r.length===0?".":r.join("/")}function G(e,t){return t.startsWith("/")?kn(t):kn(e+"/"+t)}var um=40,Er=(e,t)=>e.isLink?.(t)===!0;function v(e,t,n,{follow:r=!0}={}){let i=je(e,t,n,{follow:r});return i.error?{path:null,error:i.error}:t.endsWith("/")&&!n.isDir(i.path)?{path:null,error:"Not a directory"}:{path:i.path,error:null}}function je(e,t,n,{follow:r=!0,lenient:i=!1}={}){if(t===""||t.includes("\0"))return{path:"/",error:"No such file or directory",rest:[]};let o=(t.startsWith("/")?t:e+"/"+t).split("/").filter(Boolean),s=r||t.endsWith("/"),u=um,a="/";for(;o.length>0;){let f=o.shift();if(!n.isDir(a)){if(!i){let d=n.isFile(a)||Er(n,a)?"Not a directory":"No such file or directory";return{path:a,error:d,rest:[f,...o]}}f===".."?a=ge(a):f!=="."&&(a=Ae(a,f));continue}if(f===".."){a=ge(a);continue}if(f!=="."&&(a=Ae(a,f)),!Er(n,a)||n.isDir(a)||o.length===0&&!s)continue;if(u--===0)return{path:a,error:"Too many levels of symbolic links",rest:[...o]};let c=n.readLink(a);a=c.startsWith("/")?"/":ge(a),o.unshift(...c.split("/").filter(Boolean),...c.endsWith("/")?["."]:[])}let l=!n.isDir(a)&&!n.isFile(a)&&!Er(n,a);return{path:a,error:l?"No such file or directory":null,rest:[]}}var ie=(e,t,n,r=!0)=>n===""||n.includes("\0")?G(t,n):je(t,n,e,{follow:r,lenient:!0}).path;function Qe(e,t,n,r=v(e,t,n)){if(r.path!==null)return null;if(t===""||t.includes("\0")||t.endsWith("/")||r.error!=="No such file or directory")return r.error;let i=je(e,t,n);return i.rest.length>0?i.error:n.isDir(ge(i.path))?null:"Not a directory"}function ge(e){let t=kn(e);if(t==="/")return"/";let n=t.lastIndexOf("/");return n<0?".":n===0?"/":t.slice(0,n)}function et(e){let t=kn(e);if(t==="/")return"/";let n=t.lastIndexOf("/");return t.slice(n+1)}function B(e,t){for(let n=0;n<Math.min(e.length,t.length);n++)if(e[n]!==t[n])return e.codePointAt(n)-t.codePointAt(n);return e.length-t.length}function Ae(e,t){return e==="/"?"/"+t:e+"/"+t}function ze(e,t){return e==="/"?t.slice(1):t.slice(e.length+1)}function Sa(e,t="/"){let n=new Map,r=new Map;for(let[u,a]of fm(e)){let l=String(u),f=cm(a,l);if(f===null)continue;if(l.includes("\0"))throw new TypeError("createTerminal: source paths must not contain NUL characters");let c=kn("/"+l),d=t==="/"?c:c==="/"?t:t+c;f.link===void 0?(n.set(d,f.content),r.delete(d)):(r.set(d,f.link),n.delete(d))}let i=new Map([["/",{dirs:[],files:[],links:[]}]]);va(i,t);for(let[u,a]of[["files",n],["links",r]])for(let l of a.keys()){let f=l.lastIndexOf("/"),c=l.slice(0,f)||"/";va(i,c),i.get(c)[u].push(l==="/"?"/":l.slice(f+1))}for(let u of i.values())u.dirs.sort(B),u.files.sort(B),u.links.sort(B);let o=(u,a=!1)=>{let l=n.get(u);if(!(l instanceof Nr))return l;let f;try{f=l.decode()}catch(c){if(!(c instanceof SyntaxError))throw c;if(a)return;throw new w("feature","base64 source",`${JSON.stringify(u)} declares base64 that does not decode, so its bytes cannot be read`)}return n.set(u,f),f},s={isFile:u=>n.has(u),isDir:u=>i.has(u),isLink:u=>r.has(u),readLink:u=>r.get(u),readFile:u=>{let a=o(u);return a===void 0||typeof a=="string"?a:Gt(a,JSON.stringify(u))},readBytes:(u,a=!1)=>{let l=o(u);return typeof l!="string"?l:a?A(l):q(l)},fileSize:u=>i.has(u)?void 0:r.has(u)?q(r.get(u)).length:n.has(u)?am(n.get(u)):void 0,sameFileContents:(u,a)=>lm(o(u,!0),o(a,!0)),exactBytes:u=>oo(o(u,!0)),isBytes:u=>typeof n.get(u)=="object",isEmptyFile:u=>{let a=n.get(u);return typeof a=="string"?a==="":a?.length===0},listDir:u=>{let a=i.get(u);if(!a)throw new Error(`not a directory: ${u}`);return a},walkFiles:u=>hm(s,u)};return s}var am=e=>typeof e=="string"?q(e).length:e.length,oo=e=>typeof e=="string"?e.isWellFormed()?q(e):void 0:e;function Gt(e,t,n="reading them as text"){let r=pt(e);if(r===void 0)throw new w("feature","binary file",`${t} holds bytes that spell no text, and ${n} is not supported`);return r}var vn=(e,t)=>e!==void 0&&t!==void 0&&e.length===t.length&&e.every((n,r)=>n===t[r]);function lm(e,t){return e===void 0||t===void 0?!1:typeof e=="string"&&typeof t=="string"?e===t:vn(oo(e),oo(t))}function fm(e){try{return Map.prototype.entries.call(e)}catch{return Object.entries(e??{})}}function cm(e,t){if(typeof e=="string")return{content:e};if(ArrayBuffer.isView(e))return{content:pm(e,t)};if(e===null||typeof e!="object"||Array.isArray(e))return null;if(e instanceof ArrayBuffer)throw new TypeError(`createTerminal: source ${JSON.stringify(t)} is an ArrayBuffer; declare a file's bytes as a Uint8Array over it`);if(e.format!==void 0||e.data!==void 0)return{content:dm(e,t)};if(e.type===void 0&&e.target===void 0)return null;let n=JSON.stringify(t);if(e.type!=="link")throw new TypeError(`createTerminal: source ${n} declares type ${JSON.stringify(e.type??null)}; the only declaration is { type: 'link', target }`);let{target:r}=e;if(typeof r!="string"||r===""||r.includes("\0"))throw new TypeError(`createTerminal: link ${n} must declare a non-empty target without NUL characters`);return{link:r}}function dm(e,t){let n=JSON.stringify(t);if(e.format!=="base64")throw new TypeError(`createTerminal: source ${n} declares format ${JSON.stringify(e.format??null)}; the only format is { format: 'base64', data }`);if(typeof e.data!="string")throw new TypeError(`createTerminal: source ${n} must declare its base64 as a string in \`data\``);return new Nr(e.data)}var Nr=class{constructor(t){this.text=t;let n=t.endsWith("==")?2:t.endsWith("=")?1:0;this.length=Math.floor((t.length-n)*3/4)}decode(){return xn(this.text)}};function pm(e,t){if(e.BYTES_PER_ELEMENT!==1)throw new TypeError(`createTerminal: source ${JSON.stringify(t)} is a ${e[Symbol.toStringTag]??"view"}; declare a file's bytes as a Uint8Array`);return new Uint8Array(e.buffer,e.byteOffset,e.byteLength).slice()}function*Oe(e,t,n=Number.POSITIVE_INFINITY,r=()=>!0){if(e.isFile(t)){yield{path:t,kind:"file",depth:0};return}if(!e.isDir(t)){Er(e,t)&&(yield{path:t,kind:"link",depth:0});return}let i=[{path:t,kind:"dir",depth:0}];for(;i.length;){let o=i.pop();if(yield o,o.kind!=="dir"||o.depth>=n||!r(o.path))continue;let{dirs:s,files:u,links:a=[]}=e.listDir(o.path),l=s.length-1,f=u.length-1,c=a.length-1;for(;l>=0||f>=0||c>=0;){let d=l>=0?"dir":null,p=l>=0?s[l]:null;f>=0&&(p===null||B(u[f],p)>=0)&&(d="file",p=u[f]),c>=0&&(p===null||B(a[c],p)>=0)&&(d="link",p=a[c]),d==="dir"?l--:d==="file"?f--:c--,i.push({path:Ae(o.path,p),kind:d,depth:o.depth+1})}}}function*hm(e,t){for(let n of Oe(e,t))n.kind==="file"&&(yield n.path)}function va(e,t){let n=[],r=t;for(;r!=="/"&&!e.has(r);)n.push(r),r=r.slice(0,r.lastIndexOf("/"))||"/";for(let i=n.length-1;i>=0;i--){let o=n[i];e.set(o,{dirs:[],files:[],links:[]});let s=o.lastIndexOf("/");e.get(o.slice(0,s)||"/").dirs.push(o.slice(s+1))}}var Ot={__proto__:null,alpha:"A-Za-z",digit:"0-9",alnum:"0-9A-Za-z",upper:"A-Z",lower:"a-z",space:" \\t\\n\\v\\f\\r",blank:" \\t",punct:"!-\\/:-@\\[-`{-~",xdigit:"0-9A-Fa-f",cntrl:"\\x00-\\x1F\\x7F",print:"\\x20-\\x7E",graph:"\\x21-\\x7E",word:"0-9A-Za-z_"},so={__proto__:null};for(let[e,t]of Object.entries(Ot)){let n=new RegExp(`[${t}]`,"u"),r=[];for(let i=0;i<128;i++){if(!n.test(String.fromCodePoint(i)))continue;let o=r.at(-1);o&&o[1]===i-1?o[1]=i:r.push([i,i])}so[e]=r}var Ar=32767;function $a(e,t){if(e>Ar||t!==void 0&&t>Ar)throw new Error("Regular expression too big")}function Ea(e,t,n=!1){let r=t+1;e[r]==="^"&&r++;let i=!0,o=!1;for(;r<e.length;){let s=e[r];if(s==="]"&&!i)return r;if(i=!1,s==="["&&":.=".includes(e[r+1]??"")){let l=e[r+1],f=e.indexOf(l+"]",r+2);if(f===-1)throw new Error("Unmatched [, [^, [:, [., or [=");if(l===":"&&!(e.slice(r+2,f)in Ot))throw new Error("Invalid character class name");if(l!==":"&&n&&/\P{ASCII}/u.test(e.slice(r+2,f)))throw new Error("Invalid collation character");r=f+2,o=l!==".";continue}if(s==="-"&&o&&r+1<e.length&&e[r+1]!=="]")throw new Error("Invalid range end");let u=s==="\\"&&r+1<e.length?2:1;if(e[r+u]==="-"&&e[r+u+1]!==void 0&&e[r+u+1]!=="]"){let l=r+u+1,f=e[l]==="["?e[l+1]:void 0;if(f===":"||f==="=")throw new Error("Invalid range end");let c=f==="."?e.indexOf(".]",l+2):-1;if(f==="."&&c===-1)throw new Error("Unmatched [, [^, [:, [., or [=");let d=f==="."?l+2:l+(e[l]==="\\"?1:0);if(n&&(e.codePointAt(r+u-1)>127||e.codePointAt(d)>127))throw new Error("Invalid collation character");r=c===-1?l+(e[l]==="\\"?2:1):c+2,o=!0;continue}r+=u,o=!1}throw new Error("Unmatched [, [^, [:, [., or [=")}function Xt(e,t,n={}){let r=/^\[:([a-z]+):\]/u.exec(e.slice(t));if(!r)return null;let i=n.classes?n.classes.body(r[1]):Ot[r[1]];if(i===void 0){if(n?.unknown!=="empty")throw new Error(`invalid character class \`[:${r[1]}:]\``);return{body:"",end:t+r[0].length}}return{body:i,end:t+r[0].length}}var Or={alpha:"1t:p,6:p,1b:0,a:0,4:0,5:m,1:u,1:cp,4:b,e:4,7:0,1:0,2e:0,16:4,1:1,2:3,1:0,6:0,1:2,1:0,1:j,1:2a,1:3u,8:4l,1:11,2:0,6:14,13:d,1:0,1:1,1:1,1:0,8:q,4:3,t:a,5:1j,1:g,4:2t,1:7,4:7,4:f,2:0,g:1b,d:2s,e:16,9:1,4:0,5:n,2:i,j:o,7:a,5:n,1:5,h:15,a:b,3:6,6:23,1:f,1:2,4:e,2:9,1:i,1:7,2:1,2:l,1:6,1:0,3:3,3:7,2:1,2:1,1:0,8:0,4:1,1:4,2:b,a:0,4:2,1:5,4:1,2:l,1:6,1:1,1:1,1:1,4:4,4:1,2:1,4:0,7:3,1:0,7:f,b:2,1:8,1:2,1:l,1:6,1:1,1:4,3:8,1:2,1:1,3:0,f:3,2:9,9:3,4:2,1:7,2:1,2:l,1:6,1:1,1:4,3:7,2:1,2:1,9:1,4:1,1:4,2:9,1:0,g:1,1:5,3:2,1:3,3:1,1:0,1:1,3:1,3:2,3:b,4:4,3:2,1:2,3:0,6:0,e:9,g:c,1:2,1:m,1:f,3:7,1:2,1:2,8:1,1:2,2:0,2:3,2:9,g:3,1:7,1:2,1:m,1:9,1:4,3:7,1:2,1:2,8:1,6:1,1:3,2:9,1:2,c:c,1:2,1:14,2:7,1:2,1:2,1:0,5:3,7:4,2:9,a:5,1:2,1:h,3:n,1:8,1:0,2:6,8:5,1:0,1:7,6:9,2:1,d:1l,5:6,6:0,2:9,13:1,1:0,1:4,1:n,1:0,1:i,1:2,2:4,1:0,6:0,2:9,2:3,w:0,v:9,m:7,1:z,4:i,4:f,1:z,1v:1i,1:0,2:e,6:25,2:11,1:0,5:0,2:16,1:98,1:3,2:6,1:0,1:3,2:14,1:3,2:w,1:3,2:6,1:0,1:3,2:e,1:1k,1:3,2:1u,11:f,g:2d,2:5,3:h7,2:g,1:p,5:22,3:a,7:j,b:k,c:j,c:c,1:2,1:1,c:1f,2:i,e:0,4:0,3:9,12:9,6:2g,7:16,5:1x,a:u,1:b,4:8,d:13,2:4,b:17,4:p,6:9,12:r,4:1q,2:j,b:9,6:9,d:0,n:1,b:2,1d:1f,1:e,1:7,3:9,12:15,2:1l,1:a,e:1i,9:9,3:1c,2:8,7:16,2:2,15:3,1:5,1:1,3:0,5:5b,13:d,b:7p,2:5,2:11,2:5,2:7,1:0,1:0,1:0,1:u,2:1g,1:6,1:0,3:2,1:6,3:3,2:5,4:c,5:2,1:6,38:0,d:0,g:c,2t:0,4:0,2:9,1:0,3:4,6:0,1:0,1:0,1:3,1:a,2:3,5:4,4:0,h:14,ml:1f,1ee:6c,6:3,3:1,c:11,1:0,5:0,2:1j,7:0,g:m,9:6,1:6,1:6,1:6,1:6,1:6,1:6,1:6,1:v,1b:0,d1:2,p:8,7:4,2:4,4:2d,6:2,1:2h,1:3,5:16,1:2l,h:v,1c:f,e8:533,1s:h3g,1v:19,2:7g,3:r,k:1a,5:7,3:34,13:8,2:2u,2:1r,5:1,1:0,1:4,o:j,1:w,o:1f,c:1v,1:0,a:9,o:5,3:0,1:19,5:y,d:s,3:1e,1:b,f:a,6:u,1:1i,9:d,2:9,6:m,3:1w,1:0,1:0,o:2,2:f,2:3,b:5,2:5,2:5,9:6,1:6,1:16,1:d,6:3e,5:9,6:8mb,c:m,4:1c,6is:a5,2:2x,12:6,c:4,5:b,1:c,1:4,1:0,1:1,1:1,1:2z,x:a2,i:1r,2:1h,14:b,38:4,1:3q,j:9,7:p,6:p,b:2g,3:5,2:5,2:5,2:2,z:b,1:p,1:i,1:1,1:e,2:d,y:3e,1x:1g,7f:s,3:1c,1b:v,d:t,5:16,5:t,2:z,4:7,1:4,16:4d,2:9,6:z,4:z,4:13,8:1f,c:a,1:e,1:6,1:1,1:a,1:e,1:6,1:1,1v:8m,9:l,a:7,o:5,1:15,1:8,1x:5,2:0,1:17,1:1,3:0,2:m,a:m,9:u,1t:i,1:1,a:l,a:p,1y:1j,6:1,1s:3,1:1,5:7,1:2,1:s,16:s,3:s,z:7,1:r,r:1h,a:l,a:i,d:h,32:20,1j:1e,d:1e,d:13,8:9,92:15,1:1,3:1,26:s,a:0,8:l,16:h,1a:k,r:m,9:1x,w:9,1:4,a:1k,9:0,d:o,7:9,6:1e,3:9,4:3,8:y,3:0,9:1r,1:3,9:c,1:0,z:h,1:x,2:0,6:3,1q:6,1:0,1:3,1:e,1:9,7:1k,7:9,6:3,1:7,2:1,2:l,1:6,1:1,1:4,3:7,2:1,2:1,3:0,6:0,5:6,4c:1t,1:2,1:3,5:9,5:2,u:1t,2:1,1:0,8:9,4m:1h,2:6,p:5,y:1q,1:0,3:0,b:9,12:1h,2:0,7:9,1i:q,2:d,5:9,6:6,55:1k,2v:21,l:7,2:0,2:7,1:1,1:t,1:1,2:1,2:3,d:9,1y:7,2:19,2:5,1:0,1:1,r:1e,2:9,h:1z,5:0,i:20,7b:8,1:18,1:6,1:0,f:9,o:t,2:l,1:d,21:6,1:1,1:17,3:0,1:1,1:2,1:0,2:1,8:9,6:5,1:1,1:10,1:1,1:3,1:0,7:9,8m:m,9:g,1:14,3:2,f:9,2e:0,27:pl,2u:32,h:5f,218:2o,f:tr,h:5,33t:g6,6nt:fs,7:u,1:9,6:26,1:9,6:t,i:1b,g:3,c:9,9:k,5:i,j4:1r,3k:22,4:1k,7:g,1s:1,1:0,c:1,e:4qf,8:yd,16:8,6w7:3,1:6,1:1,1:82,f:0,t:2,2:0,e:3,8:az,1s4:2y,5:c,3:8,7:9,4:0,4m9:2c,1:1y,1:1,2:0,2:1,2:3,1:b,1:0,1:6,1:1s,1:3,2:7,1:6,1:r,1:3,1:4,1:0,3:6,1:9f,2:o,1:o,1:u,1:o,1:u,1:o,1:u,1:o,1:u,1:o,1:7,2:1d,1ds:u,6:5,5x:6,1:g,2:6,1:1,1:4,5:1p,x:0,34:18,a:6,2:9,4:0,8x:t,i:17,4:9,d2:r,4:9,km:6,1:3,1:1,1:e,1:5g,1n:1v,3:0,3:0,4:9,x2:3,1:q,1:1,1:0,2:0,1:9,1:3,1:0,1:0,6:0,4:0,1:0,1:0,1:2,1:1,1:0,2:0,1:0,1:0,1:0,1:0,1:1,1:0,2:3,1:6,1:3,1:3,1:0,1:9,1:g,5:2,1:4,1:g,hg:p,6:p,6:p,21y:9,sm:wyn,w:37d,6:65,2:4g1,e:5rk,f:h9,1wi:f1,15u:3t6,5:38f",digit:"1c:9",alnum:"1c:9,7:p,6:p,1b:0,a:0,4:0,5:m,1:u,1:cp,4:b,e:4,7:0,1:0,2e:0,16:4,1:1,2:3,1:0,6:0,1:2,1:0,1:j,1:2a,1:3u,8:4l,1:11,2:0,6:14,13:d,1:0,1:1,1:1,1:0,8:q,4:3,t:a,5:1j,1:g,4:2t,1:7,4:7,4:f,2:0,g:1b,d:2s,e:16,9:1,4:0,5:n,2:i,j:o,7:a,5:n,1:5,h:15,a:b,3:6,6:23,1:f,1:2,4:e,2:9,1:i,1:7,2:1,2:l,1:6,1:0,3:3,3:7,2:1,2:1,1:0,8:0,4:1,1:4,2:b,a:0,4:2,1:5,4:1,2:l,1:6,1:1,1:1,1:1,4:4,4:1,2:1,4:0,7:3,1:0,7:f,b:2,1:8,1:2,1:l,1:6,1:1,1:4,3:8,1:2,1:1,3:0,f:3,2:9,9:3,4:2,1:7,2:1,2:l,1:6,1:1,1:4,3:7,2:1,2:1,9:1,4:1,1:4,2:9,1:0,g:1,1:5,3:2,1:3,3:1,1:0,1:1,3:1,3:2,3:b,4:4,3:2,1:2,3:0,6:0,e:9,g:c,1:2,1:m,1:f,3:7,1:2,1:2,8:1,1:2,2:0,2:3,2:9,g:3,1:7,1:2,1:m,1:9,1:4,3:7,1:2,1:2,8:1,6:1,1:3,2:9,1:2,c:c,1:2,1:14,2:7,1:2,1:2,1:0,5:3,7:4,2:9,a:5,1:2,1:h,3:n,1:8,1:0,2:6,8:5,1:0,1:7,6:9,2:1,d:1l,5:6,6:0,2:9,13:1,1:0,1:4,1:n,1:0,1:i,1:2,2:4,1:0,6:0,2:9,2:3,w:0,v:9,m:7,1:z,4:i,4:f,1:z,1v:1i,1:0,2:e,6:25,2:11,1:0,5:0,2:16,1:98,1:3,2:6,1:0,1:3,2:14,1:3,2:w,1:3,2:6,1:0,1:3,2:e,1:1k,1:3,2:1u,11:f,g:2d,2:5,3:h7,2:g,1:p,5:22,3:a,7:j,b:k,c:j,c:c,1:2,1:1,c:1f,2:i,e:0,4:0,3:9,12:9,6:2g,7:16,5:1x,a:u,1:b,4:8,d:13,2:4,b:17,4:p,6:9,12:r,4:1q,2:j,b:9,6:9,d:0,n:1,b:2,1d:1f,1:e,1:7,3:9,12:15,2:1l,1:a,e:1i,9:9,3:1c,2:8,7:16,2:2,15:3,1:5,1:1,3:0,5:5b,13:d,b:7p,2:5,2:11,2:5,2:7,1:0,1:0,1:0,1:u,2:1g,1:6,1:0,3:2,1:6,3:3,2:5,4:c,5:2,1:6,38:0,d:0,g:c,2t:0,4:0,2:9,1:0,3:4,6:0,1:0,1:0,1:3,1:a,2:3,5:4,4:0,h:14,ml:1f,1ee:6c,6:3,3:1,c:11,1:0,5:0,2:1j,7:0,g:m,9:6,1:6,1:6,1:6,1:6,1:6,1:6,1:6,1:v,1b:0,d1:2,p:8,7:4,2:4,4:2d,6:2,1:2h,1:3,5:16,1:2l,h:v,1c:f,e8:533,1s:h3g,1v:19,2:7g,3:r,k:1a,5:7,3:34,13:8,2:2u,2:1r,5:1,1:0,1:4,o:j,1:w,o:1f,c:1v,1:0,a:9,o:5,3:0,1:19,5:y,d:s,3:1e,1:b,f:a,6:u,1:1i,9:d,2:9,6:m,3:1w,1:0,1:0,o:2,2:f,2:3,b:5,2:5,2:5,9:6,1:6,1:16,1:d,6:3e,5:9,6:8mb,c:m,4:1c,6is:a5,2:2x,12:6,c:4,5:b,1:c,1:4,1:0,1:1,1:1,1:2z,x:a2,i:1r,2:1h,14:b,38:4,1:3q,j:9,7:p,6:p,b:2g,3:5,2:5,2:5,2:2,z:b,1:p,1:i,1:1,1:e,2:d,y:3e,1x:1g,7f:s,3:1c,1b:v,d:t,5:16,5:t,2:z,4:7,1:4,16:4d,2:9,6:z,4:z,4:13,8:1f,c:a,1:e,1:6,1:1,1:a,1:e,1:6,1:1,1v:8m,9:l,a:7,o:5,1:15,1:8,1x:5,2:0,1:17,1:1,3:0,2:m,a:m,9:u,1t:i,1:1,a:l,a:p,1y:1j,6:1,1s:3,1:1,5:7,1:2,1:s,16:s,3:s,z:7,1:r,r:1h,a:l,a:i,d:h,32:20,1j:1e,d:1e,d:13,8:9,92:15,1:1,3:1,26:s,a:0,8:l,16:h,1a:k,r:m,9:1x,w:9,1:4,a:1k,9:0,d:o,7:9,6:1e,3:9,4:3,8:y,3:0,9:1r,1:3,9:c,1:0,z:h,1:x,2:0,6:3,1q:6,1:0,1:3,1:e,1:9,7:1k,7:9,6:3,1:7,2:1,2:l,1:6,1:1,1:4,3:7,2:1,2:1,3:0,6:0,5:6,4c:1t,1:2,1:3,5:9,5:2,u:1t,2:1,1:0,8:9,4m:1h,2:6,p:5,y:1q,1:0,3:0,b:9,12:1h,2:0,7:9,1i:q,2:d,5:9,6:6,55:1k,2v:21,l:7,2:0,2:7,1:1,1:t,1:1,2:1,2:3,d:9,1y:7,2:19,2:5,1:0,1:1,r:1e,2:9,h:1z,5:0,i:20,7b:8,1:18,1:6,1:0,f:9,o:t,2:l,1:d,21:6,1:1,1:17,3:0,1:1,1:2,1:0,2:1,8:9,6:5,1:1,1:10,1:1,1:3,1:0,7:9,8m:m,9:g,1:14,3:2,f:9,2e:0,27:pl,2u:32,h:5f,218:2o,f:tr,h:5,33t:g6,6nt:fs,7:u,1:9,6:26,1:9,6:t,i:1b,g:3,c:9,9:k,5:i,j4:1r,3k:22,4:1k,7:g,1s:1,1:0,c:1,e:4qf,8:yd,16:8,6w7:3,1:6,1:1,1:82,f:0,t:2,2:0,e:3,8:az,1s4:2y,5:c,3:8,7:9,4:0,4m9:2c,1:1y,1:1,2:0,2:1,2:3,1:b,1:0,1:6,1:1s,1:3,2:7,1:6,1:r,1:3,1:4,1:0,3:6,1:9f,2:o,1:o,1:u,1:o,1:u,1:o,1:u,1:o,1:u,1:o,1:7,2:1d,1ds:u,6:5,5x:6,1:g,2:6,1:1,1:4,5:1p,x:0,34:18,a:6,2:9,4:0,8x:t,i:17,4:9,d2:r,4:9,km:6,1:3,1:1,1:e,1:5g,1n:1v,3:0,3:0,4:9,x2:3,1:q,1:1,1:0,2:0,1:9,1:3,1:0,1:0,6:0,4:0,1:0,1:0,1:2,1:1,1:0,2:0,1:0,1:0,1:0,1:0,1:1,1:0,2:3,1:6,1:3,1:3,1:0,1:9,1:g,5:2,1:4,1:g,hg:p,6:p,6:p,21y:9,sm:wyn,w:37d,6:65,2:4g1,e:5rk,f:h9,1wi:f1,15u:3t6,5:38f",upper:"1t:p,2t:m,1:6,x:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,2:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,2:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:1,1:0,1:0,3:1,1:0,1:1,1:2,2:3,1:1,1:2,3:1,1:1,1:0,1:0,1:1,1:0,2:0,1:1,1:2,1:0,1:1,3:0,7:1,1:1,1:1,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,2:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,2:1,1:0,1:2,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,7:1,1:1,2:0,1:3,1:0,1:0,1:0,1:0,81:0,1:0,3:0,8:0,6:0,1:2,1:0,1:1,1:g,1:8,z:0,2:2,3:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,5:0,2:0,1:1,2:1e,1c:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,9:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:1,1:0,1:0,1:0,1:0,1:0,1:0,2:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,2:11,289:11,1:0,5:0,k2:2d,1p6:16,2:2,8w:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,9:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,9:7,8:5,a:7,8:7,8:5,b:0,1:0,1:0,1:0,8:7,o:7,8:7,8:7,8:4,b:4,b:3,c:4,b:4,79:0,4:0,3:2,2:2,2:0,3:4,6:0,1:0,1:0,1:3,2:3,a:1,5:0,q:f,j:0,mq:p,1f4:1b,1c:0,1:2,2:0,1:0,1:0,1:3,1:0,2:0,8:2,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,8:0,1:0,4:0,nyl:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,j:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,3r:0,1:0,1:0,1:0,1:0,1:0,1:0,3:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,a:0,1:0,1:1,1:0,1:0,1:0,1:0,4:0,1:0,2:0,1:0,3:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:4,1:4,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:3,1:0,6:0,5:0,1:0,s:0,h7v:p,xx:13,3s:z,4c:a,1:e,1:6,1:1,1d6:1e,2ct:v,gw0:v,k2o:p,q:p,q:p,q:0,1:1,2:0,2:1,2:3,1:7,q:p,q:1,1:3,2:7,1:6,r:1,1:3,1:4,1:0,3:6,r:p,q:p,q:p,q:p,q:p,q:p,u:o,x:o,x:o,x:o,x:o,x:0,3ed:x,1la:p,6:p,6:p",lower:"2p:p,1b:0,a:0,4:0,10:n,1:7,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:1,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:1,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,2:0,1:0,1:2,2:0,1:0,2:0,3:1,4:0,2:0,3:2,2:0,2:0,1:0,1:0,2:0,1:1,1:0,2:0,3:0,1:0,2:1,2:2,5:1,1:1,1:1,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:1,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:1,1:1,1:0,3:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:6,2:0,2:1,1:0,4:0,1:0,1:0,1:0,1:1w,1:z,7:1,u:4,2o:0,17:0,1:0,3:0,2:3,i:0,r:y,1:1,3:2,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:4,1:0,2:0,2:1,1f:1b,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,9:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,2:0,1:0,1:0,1:0,1:0,1:0,1:1,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1c:14,287:16,1:3,l4:5,1oi:8,3b:5b,1t:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:8,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:8,8:5,a:7,8:7,8:5,a:7,8:7,8:d,2:7,8:7,8:7,8:4,1:1,6:0,3:2,1:1,8:3,2:1,8:7,a:2,1:1,3d:0,d:0,g:c,31:0,3:1,3:0,r:0,4:0,4:0,2:1,8:3,4:0,x:f,4:0,nf:p,1fq:1b,1:0,3:1,1:0,1:0,1:0,4:0,1:1,1:7,3:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:1,7:0,1:0,4:0,c:11,1:0,5:0,nwz:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,j:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:2,3p:0,1:0,1:0,1:0,1:0,1:0,1:2,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:9,1:0,1:0,2:0,1:0,1:0,1:0,1:0,4:0,1:0,2:0,1:2,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,5:0,5:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0,4:0,1:0,6:0,1:0,1:0,1:0,1:0,o:2,1:0,1:2,mt:16,1:d,6:27,fnk:6,c:4,tl:p,y5:13,3s:z,4b:a,1:e,1:6,1:1,cj:0,2:2,1:15,1:8,zp:1e,2bx:v,gw0:v,k2i:p,q:6,1:h,q:p,q:3,1:0,1:6,1:a,q:p,q:p,q:p,q:p,q:p,q:p,q:p,q:p,q:r,s:o,1:5,q:o,1:5,q:o,1:5,q:o,1:5,q:o,1:5,1:0,1f8:9,1:j,6:5,79:1p,1pw:x",space:"9:4,i:0,4f3:0,1vj:6,1:2,t:1,1h:0,334:0",blank:"9:0,m:0,4f3:0,1vj:6,1:2,2c:0,334:0",punct:"x:e,a:6,q:5,q:3,x:9,1:9,1:3,1:4,n:0,v:0,cq:3,c:d,5:6,1:0,1:2d,1:15,5:0,8:0,5:1,1:0,32:0,3v:7,5s:5,15:1,2:2,1:u,e:0,1:0,2:0,2:0,18:1,b:f,b:4,1k:0,h:3,2u:0,8:3,8:3,g:1,1:d,1:0,1c:a,4g:8,2:3,3:2,o:1,j:0,2:e,q:2,2:0,15:0,7:1,6:7,16:9,c:2,7:5,24:0,g:0,3:3,f:1,a:0,23:0,g:0,10:9,1:1,1p:0,g:0,14:0,1x:0,g:0,y:1,b:2,1o:0,g:0,7:0,q:0,1:5,2d:0,y:a,1t:0,g:0,15:8,4:0,1j:0,g:0,31:1,g:0,1:0,8:6,h:9,28:0,15:0,22:0,7:5,1:1,a:1,2m:0,d:4,1:0,1e:u,a:l,1w:3,1i:e,1:c,2k:0,1:1,f:5,26:1,2j:0,gx:v,j:9,2u:0,h8:1,18:1,26:2,12:1,u:2,3h:1,j:d,1:3,1:0,i:9,6:f,89:2,4:0,3:1,44:0,3:x,u:1,1s:0,k:7,2:0,w:6,1:5,2:e,2:a,2w:0,f:0,l:10,17:1,1m:0,b:1,8:3,1j:0,3:4,1q:1,1s:7,8:o,4:0,6:0,2:2,5i:12,e:a,cd:0,1:2,b:2,d:2,d:2,d:1,8:0,3:s,2:1g,1:4,1:a,3:a,1:e,h:w,f:w,f:1,1:3,1:1,a:0,1:2,5:5,1:0,1:0,1:0,4:0,b:1,4:4,5:3,1:g,15:2,4:ie,p:a,l:2d,1g:1ah,2:v,1:2w,6d:5,4:2,7:6,34:0,e:0,3k:1a,1:19,y:p,1:2g,c:5x,q:f,1:3,3:o,9:6,5:1,5:2,2h:3,3:0,2i:0,44:f,w:z,b:0,g:u,1:db,534:1r,h3k:1i,1j:1,7h:2,2n:4,8:2,35:7,8:m,9:1,2v:1,3f:0,x:4,3:9,1m:3,24:0,9:1,g:h,6:2,1:0,1a:4,z:0,b:0,2b:0,c:d,g:1,3g:3,n:2,1x:0,1:0,s:1,g:1,4:0,2s:0,e:1,3j:2,aaa:4xr,fd:0,3s:g,aj:h,3j:0,18:t,6:1e,1:i,1:3,43:0,1:e,a:6,q:5,q:a,3e:6,1:6,a:4,76:2,4:18,3:8,1h:p,1:c,3:0,1b:19,6a:r,10:3,3f:0,1c:0,bi:0,kn:8,n:8,13:8,23:4,m:5,3:0,v:0,3g:1,2:f,2:19,1k:2,4:9,7:8,10:2,t:2,14:0,s:1,4:b,1u:6,o:7,o:7,p:3,c:6,96:5,9s:u,1a:0,27:2,t:9,v:j,14:7,1n:6,3e:7,4:j,a:0,e:0,1l:8,b:0,2t:1,b:3,1b:2,22:0,4:8,d:0,1:2,1:j,1s:1,1:5,2z:0,1r:1,28:1,g:0,o:6,3:4,5p:0,3:0,4:4,a:1,1:1,2r:1,2:0,6w:o,2v:0,1:2,s:c,21:1,1:0,35:0,e:5,6x:2,4u:8,22:1,4:3,49:0,1:0,28:1,a:8,28:4,1:4,2l:9,8l:0,1:4,k:i,3:1,5s:0,1:1,29:0,9r:1,20:e,34:1d,d:0,vk:4,29o:1,u5:g,6:e,aoo:1,3k:5,1m:f,4:1,l:6,m6:q,93:0,1:0,f5j:1,1:4,3mk:19,2:m,9:37,1o:6t,a:12,2:5d,l:1x,3e:j,c:j,c:2e,9:o,nc:0,p:0,v:0,p:0,v:0,p:0,v:0,p:0,v:0,p:0,1o:i3,f:4,1:e,1a8:6,o:0,9q:0,1p:3,f:0,do:3,rb:f,31:2,1:2,j:1,lt:1v,24:1o,c2:1,7i:17,4:2r,c:e,2:e,1:e,1:10,a:1b,q:5,q:5,q:z,1k:s,d:17,4:8,7:1,e:5,4a:rb,4:g,3:c,3:3a,4:2m,6:b,4:0,f:b,4:1j,8:9,6:13,8:t,2:1,26:9f,c:d,2:c,3:8,7:19,1:6,8:d,4:8,7:8,7:42,1:1i,gvna:0,u:2n,3k:6n,1e6o:1ekd,2:1ekd",xdigit:"1c:9,7:5,q:5",cntrl:"0:v,2n:w,688:1",print:"w:2m,x:k7,2:5,4:6,1:0,1:j,1:b0,1:11,2:1d,2:2,1:1i,8:q,4:5,b:7h,1:1n,2:2s,e:1m,2:1c,2:e,1:r,2:0,1:a,5:u,1:1,6:6j,1:7,2:1,2:l,1:6,1:0,3:3,2:8,2:1,2:3,8:0,4:1,1:4,2:o,2:2,1:5,4:1,2:l,1:6,1:1,1:1,1:1,2:0,1:4,4:1,2:2,3:0,7:3,1:0,7:g,a:2,1:8,1:2,1:l,1:6,1:1,1:4,2:9,1:2,1:2,2:0,f:3,2:b,7:6,1:2,1:7,2:1,2:l,1:6,1:1,1:4,2:8,2:1,2:2,7:2,4:1,1:4,2:h,a:1,1:5,3:2,1:3,3:1,1:0,1:1,3:1,3:2,3:b,4:4,3:2,1:3,2:0,6:0,e:k,5:c,1:2,1:m,1:f,2:8,1:2,1:3,7:1,1:2,2:0,2:3,2:9,7:l,1:2,1:m,1:9,1:4,2:8,1:2,1:3,7:1,6:1,1:3,2:9,1:2,c:c,1:2,1:1e,1:2,1:5,4:f,2:p,1:2,1:h,3:n,1:8,1:0,2:6,3:0,4:5,1:0,1:7,6:9,2:2,c:1l,4:s,11:1,1:0,1:4,1:n,1:0,1:m,2:4,1:0,1:6,1:9,2:3,w:1z,1:z,4:12,1:z,1:e,1:c,11:5h,1:0,5:0,2:ag,1:3,2:6,1:0,1:3,2:14,1:3,2:w,1:3,2:6,1:0,1:3,2:e,1:1k,1:3,2:1u,2:v,3:p,6:2d,2:5,2:ik,3:2g,7:l,9:n,9:j,c:c,1:2,1:1,c:2l,2:9,6:9,6:p,6:2g,7:16,5:1x,a:u,1:b,4:b,4:0,3:15,2:4,b:17,4:p,6:a,3:1p,2:1s,1:s,2:a,6:9,6:d,2:u,1d:24,3:1a,1:37,8:1n,3:e,3:1n,7:16,2:a,8:16,5:et,2:5,2:11,2:5,2:7,1:0,1:0,1:0,1:u,2:1g,1:e,1:d,2:5,1:i,2:2,1:8,1:13,2:1m,1:b,2:q,1:c,3:w,f:w,f:3v,4:ie,p:a,l:1eb,2:v,1:9o,5:18,1:0,5:0,2:1j,7:1,e:n,9:6,1:6,1:6,1:6,1:6,1:6,1:6,1:6,1:3h,y:p,1:2g,c:5x,q:27,1:2d,2:2u,5:16,1:2l,1:2b,b:1b,1:mlo,3:1i,9:9n,k:53,8:5m,5:1,1:0,1:4,o:1m,3:9,6:1j,8:1x,8:b,6:37,b:t,3:25,1:a,4:w,1:1i,9:d,2:9,2:2u,o:r,a:5,2:5,2:5,9:6,1:6,1:1n,4:3h,2:9,6:8mb,c:m,4:1c,1l0:57x,2:2x,12:6,c:4,5:p,1:4,1:0,1:1,1:1,1:3g,g:cc,2:1h,7:0,w:15,6:1e,1:i,1:3,4:4,1:3q,2:0,1:59,3:5,2:5,2:5,2:2,3:6,1:6,a:4,2:b,1:p,1:i,1:1,1:e,2:d,y:3e,5:2,4:18,3:2f,1:c,3:0,1b:19,3m:s,3:1c,f:r,4:z,9:t,5:16,5:t,1:10,4:d,16:4d,2:9,6:z,4:z,4:13,8:1f,b:b,1:e,1:6,1:1,1:a,1:e,1:6,1:1,1v:8m,9:l,a:7,o:5,1:15,1:8,1x:5,2:0,1:17,1:1,3:0,2:m,1:1z,8:8,1c:i,1:1,5:w,3:q,5:0,1s:1j,4:j,2:1d,1:1,5:7,1:2,1:s,2:2,4:9,7:8,7:1r,w:12,4:b,9:1h,3:s,2:q,5:p,7:3,c:6,28:20,1j:1e,d:1e,7:19,8:9,86:u,1:15,1:2,2:1,23:16,8:15,m:p,12:r,k:m,9:25,4:z,9:1v,a:0,2:o,7:9,6:1g,1:h,8:12,9:2n,1:j,b:h,1:1a,1q:6,1:0,1:3,1:e,1:a,6:1m,5:9,6:3,1:7,2:1,2:l,1:6,1:1,1:4,1:9,2:1,2:2,2:0,6:0,5:6,2:6,3:4,3v:2j,1:4,u:1z,8:9,4m:1h,2:11,y:1w,b:9,6:c,j:1l,6:9,1i:q,2:e,4:m,55:1n,2s:2a,c:7,2:0,2:7,1:1,1:t,1:1,2:b,9:9,1y:7,2:19,2:a,r:1z,8:2a,d:20,7:9,6u:8,1:18,1:d,a:s,3:v,2:l,1:d,21:6,1:1,1:17,3:0,1:1,1:8,8:9,6:5,1:1,1:10,1:1,1:5,7:9,8m:o,7:g,1:14,3:r,2e:0,f:1d,d:pm,2u:32,1:4,b:5f,218:2q,d:ut,33e:g6,6nt:fs,7:u,1:9,4:28,1:9,6:t,2:5,a:1x,a:9,1:6,1:k,5:i,j4:2i,2t:22,4:1k,7:g,1s:4,b:1,e:4qf,8:yd,16:8,6w7:3,1:6,1:1,1:82,f:0,t:2,2:0,e:3,8:az,1s4:2y,5:c,3:8,7:9,2:7,3mk:19,2:m,9:37,1o:6t,a:12,2:5d,l:1x,3e:j,c:j,c:2e,9:o,3r:2c,1:1y,1:1,2:0,2:1,2:3,1:b,1:0,1:6,1:1s,1:3,2:7,1:6,1:r,1:3,1:4,1:0,3:6,1:9f,2:83,2:jh,f:4,1:e,uo:u,6:5,5x:6,1:g,2:6,1:1,1:4,5:1p,x:0,34:18,3:d,2:9,4:1,8w:u,h:1l,5:0,cw:15,km:6,1:3,1:1,1:e,1:5g,2:f,15:23,4:9,4:1,lt:1v,24:1o,5e:3,1:q,1:1,1:0,2:0,1:9,1:3,1:0,1:0,6:0,4:0,1:0,1:0,1:2,1:1,1:0,2:0,1:0,1:0,1:0,1:0,1:1,1:0,2:3,1:6,1:3,1:3,1:0,1:9,1:g,5:2,1:4,1:g,1g:1,7i:17,4:2r,c:e,2:e,1:e,1:10,a:4t,1k:s,d:17,4:8,7:1,e:5,4a:rb,4:g,3:c,3:3a,4:2m,6:b,4:0,f:b,4:1j,8:9,6:13,8:t,2:1,26:9f,c:d,2:c,3:8,7:19,1:6,8:d,4:8,7:8,7:42,1:1i,11:9,sm:wyn,w:37d,6:65,2:4g1,e:5rk,f:h9,1wi:f1,15u:3t6,5:38f,f975:0,u:2n,3k:6n,1e6o:1ekd,2:1ekd",graph:"x:2l,x:k7,2:5,4:6,1:0,1:j,1:b0,1:11,2:1d,2:2,1:1i,8:q,4:5,b:7h,1:1n,2:2s,e:1m,2:1c,2:e,1:r,2:0,1:a,5:u,1:1,6:6j,1:7,2:1,2:l,1:6,1:0,3:3,2:8,2:1,2:3,8:0,4:1,1:4,2:o,2:2,1:5,4:1,2:l,1:6,1:1,1:1,1:1,2:0,1:4,4:1,2:2,3:0,7:3,1:0,7:g,a:2,1:8,1:2,1:l,1:6,1:1,1:4,2:9,1:2,1:2,2:0,f:3,2:b,7:6,1:2,1:7,2:1,2:l,1:6,1:1,1:4,2:8,2:1,2:2,7:2,4:1,1:4,2:h,a:1,1:5,3:2,1:3,3:1,1:0,1:1,3:1,3:2,3:b,4:4,3:2,1:3,2:0,6:0,e:k,5:c,1:2,1:m,1:f,2:8,1:2,1:3,7:1,1:2,2:0,2:3,2:9,7:l,1:2,1:m,1:9,1:4,2:8,1:2,1:3,7:1,6:1,1:3,2:9,1:2,c:c,1:2,1:1e,1:2,1:5,4:f,2:p,1:2,1:h,3:n,1:8,1:0,2:6,3:0,4:5,1:0,1:7,6:9,2:2,c:1l,4:s,11:1,1:0,1:4,1:n,1:0,1:m,2:4,1:0,1:6,1:9,2:3,w:1z,1:z,4:12,1:z,1:e,1:c,11:5h,1:0,5:0,2:ag,1:3,2:6,1:0,1:3,2:14,1:3,2:w,1:3,2:6,1:0,1:3,2:e,1:1k,1:3,2:1u,2:v,3:p,6:2d,2:5,2:hr,1:r,3:2g,7:l,9:n,9:j,c:c,1:2,1:1,c:2l,2:9,6:9,6:p,6:2g,7:16,5:1x,a:u,1:b,4:b,4:0,3:15,2:4,b:17,4:p,6:a,3:1p,2:1s,1:s,2:a,6:9,6:d,2:u,1d:24,3:1a,1:37,8:1n,3:e,3:1n,7:16,2:a,8:16,5:et,2:5,2:11,2:5,2:7,1:0,1:0,1:0,1:u,2:1g,1:e,1:d,2:5,1:i,2:2,1:8,8:0,3:s,2:1g,1:4,1:b,2:q,1:c,3:w,f:w,f:3v,4:ie,p:a,l:1eb,2:v,1:9o,5:18,1:0,5:0,2:1j,7:1,e:n,9:6,1:6,1:6,1:6,1:6,1:6,1:6,1:6,1:3h,y:p,1:2g,c:5x,q:f,1:1q,1:2d,2:2u,5:16,1:2l,1:2b,b:1b,1:mlo,3:1i,9:9n,k:53,8:5m,5:1,1:0,1:4,o:1m,3:9,6:1j,8:1x,8:b,6:37,b:t,3:25,1:a,4:w,1:1i,9:d,2:9,2:2u,o:r,a:5,2:5,2:5,9:6,1:6,1:1n,4:3h,2:9,6:8mb,c:m,4:1c,1l0:57x,2:2x,12:6,c:4,5:p,1:4,1:0,1:1,1:1,1:3g,g:cc,2:1h,7:0,w:15,6:1e,1:i,1:3,4:4,1:3q,2:0,1:59,3:5,2:5,2:5,2:2,3:6,1:6,a:4,2:b,1:p,1:i,1:1,1:e,2:d,y:3e,5:2,4:18,3:2f,1:c,3:0,1b:19,3m:s,3:1c,f:r,4:z,9:t,5:16,5:t,1:10,4:d,16:4d,2:9,6:z,4:z,4:13,8:1f,b:b,1:e,1:6,1:1,1:a,1:e,1:6,1:1,1v:8m,9:l,a:7,o:5,1:15,1:8,1x:5,2:0,1:17,1:1,3:0,2:m,1:1z,8:8,1c:i,1:1,5:w,3:q,5:0,1s:1j,4:j,2:1d,1:1,5:7,1:2,1:s,2:2,4:9,7:8,7:1r,w:12,4:b,9:1h,3:s,2:q,5:p,7:3,c:6,28:20,1j:1e,d:1e,7:19,8:9,86:u,1:15,1:2,2:1,23:16,8:15,m:p,12:r,k:m,9:25,4:z,9:1v,a:0,2:o,7:9,6:1g,1:h,8:12,9:2n,1:j,b:h,1:1a,1q:6,1:0,1:3,1:e,1:a,6:1m,5:9,6:3,1:7,2:1,2:l,1:6,1:1,1:4,1:9,2:1,2:2,2:0,6:0,5:6,2:6,3:4,3v:2j,1:4,u:1z,8:9,4m:1h,2:11,y:1w,b:9,6:c,j:1l,6:9,1i:q,2:e,4:m,55:1n,2s:2a,c:7,2:0,2:7,1:1,1:t,1:1,2:b,9:9,1y:7,2:19,2:a,r:1z,8:2a,d:20,7:9,6u:8,1:18,1:d,a:s,3:v,2:l,1:d,21:6,1:1,1:17,3:0,1:1,1:8,8:9,6:5,1:1,1:10,1:1,1:5,7:9,8m:o,7:g,1:14,3:r,2e:0,f:1d,d:pm,2u:32,1:4,b:5f,218:2q,d:ut,33e:g6,6nt:fs,7:u,1:9,4:28,1:9,6:t,2:5,a:1x,a:9,1:6,1:k,5:i,j4:2i,2t:22,4:1k,7:g,1s:4,b:1,e:4qf,8:yd,16:8,6w7:3,1:6,1:1,1:82,f:0,t:2,2:0,e:3,8:az,1s4:2y,5:c,3:8,7:9,2:7,3mk:19,2:m,9:37,1o:6t,a:12,2:5d,l:1x,3e:j,c:j,c:2e,9:o,3r:2c,1:1y,1:1,2:0,2:1,2:3,1:b,1:0,1:6,1:1s,1:3,2:7,1:6,1:r,1:3,1:4,1:0,3:6,1:9f,2:83,2:jh,f:4,1:e,uo:u,6:5,5x:6,1:g,2:6,1:1,1:4,5:1p,x:0,34:18,3:d,2:9,4:1,8w:u,h:1l,5:0,cw:15,km:6,1:3,1:1,1:e,1:5g,2:f,15:23,4:9,4:1,lt:1v,24:1o,5e:3,1:q,1:1,1:0,2:0,1:9,1:3,1:0,1:0,6:0,4:0,1:0,1:0,1:2,1:1,1:0,2:0,1:0,1:0,1:0,1:0,1:1,1:0,2:3,1:6,1:3,1:3,1:0,1:9,1:g,5:2,1:4,1:g,1g:1,7i:17,4:2r,c:e,2:e,1:e,1:10,a:4t,1k:s,d:17,4:8,7:1,e:5,4a:rb,4:g,3:c,3:3a,4:2m,6:b,4:0,f:b,4:1j,8:9,6:13,8:t,2:1,26:9f,c:d,2:c,3:8,7:19,1:6,8:d,4:8,7:8,7:42,1:1i,11:9,sm:wyn,w:37d,6:65,2:4g1,e:5rk,f:h9,1wi:f1,15u:3t6,5:38f,f975:0,u:2n,3k:6n,1e6o:1ekd,2:1ekd"},Na="2p:q:-w:1,51:1:kn:1,68:n:-w:1,6w:7:-w:1,73:1:3d:1,75:o:-1:2,8h:1:-6g:1,8j:3:-1:2,8q:8:-1:2,97:n:-1:2,ai:3:-1:2,an:1:-8c:1,ao:1:5f:1,ar:2:-1:2,aw:1:-1:1,b0:1:-1:1,b6:1:-1:1,b9:1:2p:1,bd:1:-1:1,be:1:4j:1,bi:1:3m:1,bl:3:-1:2,bs:1:-1:1,bx:1:-1:1,c0:1:-1:1,c4:2:-1:2,c9:1:-1:1,cd:1:-1:1,cf:1:1k:1,cl:1:-1:1,cm:1:-2:1,co:1:-1:1,cp:1:-2:1,cr:1:-1:1,cs:1:-2:1,cu:8:-1:2,d9:1:-27:1,db:9:-1:2,du:1:-1:1,dv:1:-2:1,dx:1:-1:1,e1:k:-1:2,f7:9:-1:2,fw:1:-1:1,fz:2:8cf:1,g2:1:-1:1,g7:5:-1:2,gg:1:8bj:1,gh:1:8bg:1,gi:1:8bi:1,gj:1:-5u:1,gk:1:-5q:1,gm:2:-5p:1,gp:1:-5m:1,gr:1:-5n:1,gs:1:wnj:1,gw:1:-5p:1,gx:1:wnf:1,gz:1:-5r:1,h1:1:wmg:1,h2:1:wn8:1,h4:1:-5t:1,h5:1:-5v:1,h6:1:wn8:1,h7:1:8af:1,h8:1:wn5:1,hb:1:-5v:1,hd:1:8al:1,he:1:-5x:1,hh:1:-5y:1,hp:1:89z:1,hs:1:-62:1,hu:1:wn7:1,hv:1:-62:1,hz:1:wmi:1,i0:1:-62:1,i1:1:-1x:1,i2:2:-61:1,i4:1:-1z:1,ia:1:-63:1,il:1:wlx:1,im:1:wlu:1,n9:1:2c:1,oh:2:-1:2,on:1:-1:1,or:3:3m:1,q4:1:-12:1,q5:3:-11:1,q9:h:-w:1,qq:1:-v:1,qr:9:-w:1,r0:1:-1s:1,r1:2:-1r:1,r4:1:-1q:1,r5:1:-1l:1,r9:1:-1b:1,ra:1:-1i:1,rb:1:-8:1,rd:c:-1:2,s0:1:-2e:1,s1:1:-28:1,s2:1:7:1,s3:1:-38:1,s5:1:-2o:1,s8:1:-1:1,sb:1:-1:1,ts:w:-w:1,uo:g:-28:1,v5:h:-1:2,wb:r:-1:2,xu:7:-1:2,y7:1:-f:1,y9:1c:-1:2,129:12:-1c:1,3bk:17:2bk:1,3ct:3:2bk:1,3y0:6:-8:1,5mo:1:-4tq:1,5mp:1:-4tp:1,5mq:1:-4tg:1,5mr:2:-4te:1,5mt:1:-4tf:1,5mu:1:-4t8:1,5mv:1:-4rp:1,5mw:1:r7m:1,5tl:1:r9g:1,5tp:1:2xy:1,5u6:1:raw:1,5xd:23:-1:2,61n:1:-1n:1,61t:1c:-1:2,64g:8:8:1,64w:6:8:1,65c:8:8:1,65s:8:8:1,668:6:8:1,66p:4:8:2,674:8:8:1,67k:2:22:1,67m:4:2e:1,67q:2:2s:1,67s:2:3k:1,67u:2:34:1,67w:2:3i:1,680:8:8:1,68g:8:8:1,68w:8:8:1,69c:2:8:1,69f:1:9:1,69q:1:-5k5:1,69v:1:9:1,6a8:2:8:1,6ao:2:8:1,6at:1:7:1,6b7:1:9:1,6ku:1:-s:1,6ls:g:-g:1,6mc:1:-1:1,79s:q:-q:1,8q8:1c:-1c:1,8rl:1:-1:1,8rp:1:-8bv:1,8rq:1:-8bs:1,8rs:3:-1:2,8s3:1:-1:1,8s6:1:-1:1,8sh:1e:-1:2,8vg:2:-1:2,8vn:1:-1:1,8w0:12:-5ls:1,8x3:1:-5ls:1,8x9:1:-5ls:1,wu9:n:-1:2,ww1:e:-1:2,x0j:7:-1:2,x0z:v:-1:2,x2y:2:-1:2,x33:5:-1:2,x3g:1:-1:1,x3l:2:-1:2,x3o:1:1c:1,x3r:a:-1:2,x4l:8:-1:2,x54:2:-1:2,x5d:1:-1:1,x5j:2:-1:2,x6e:1:-1:1,xub:1:-ps:1,xv4:28:-tzk:1,1ef5:q:-w:1,1fe0:14:-14:1,1fiw:10:-14:1,1fo7:b:-13:1,1foj:f:-13:1,1foz:7:-13:1,1fp7:2:-13:1,1h34:1f:-1s:1,1jgg:w:-w:1,20dc:w:-w:1,2oma:y:-y:1",Aa="1t:q:w:1,5c:n:w:1,60:7:w:1,74:o:1:2,8g:1:-5j:1,8i:3:1:2,8p:8:1:2,96:n:1:2,ag:1:-3d:1,ah:3:1:2,ap:1:5u:1,aq:2:1:2,au:1:5q:1,av:1:1:1,ax:2:5p:1,az:1:1:1,b2:1:27:1,b3:1:5m:1,b4:1:5n:1,b5:1:1:1,b7:1:5p:1,b8:1:5r:1,ba:1:5v:1,bb:1:5t:1,bc:1:1:1,bg:1:5v:1,bh:1:5x:1,bj:1:5y:1,bk:3:1:2,bq:1:62:1,br:1:1:1,bt:1:62:1,bw:1:1:1,by:1:62:1,bz:1:1:1,c1:2:61:1,c3:2:1:2,c7:1:63:1,c8:1:1:1,cc:1:1:1,ck:1:2:1,cl:1:1:1,cn:1:2:1,co:1:1:1,cq:1:2:1,cr:9:1:2,da:9:1:2,dt:1:2:1,du:2:1:2,dy:1:-2p:1,dz:1:-1k:1,e0:k:1:2,f4:1:-3m:1,f6:9:1:2,fu:1:8bv:1,fv:1:1:1,fx:1:-4j:1,fy:1:8bs:1,g1:1:1:1,g3:1:-5f:1,g4:1:1x:1,g5:1:1z:1,g6:5:1:2,og:2:1:2,om:1:1:1,ov:1:38:1,p2:1:12:1,p4:3:11:1,p8:1:1s:1,pa:2:1r:1,pd:h:w:1,pv:9:w:1,r3:1:8:1,rc:c:1:2,s4:1:-1o:1,s7:1:1:1,s9:1:-7:1,sa:1:1:1,sd:3:-3m:1,sg:g:28:1,sw:w:w:1,v4:h:1:2,wa:r:1:2,xs:1:f:1,xt:7:1:2,y8:1c:1:2,10x:12:1c:1,3a8:12:5ls:1,3bb:1:5ls:1,3bh:1:5ls:1,3vk:28:tzk:1,3xs:6:8:1,5n4:17:-2bk:1,5od:3:-2bk:1,5xc:23:1:2,61q:1:-5vj:1,61s:1c:1:2,64o:8:-8:1,654:6:-8:1,65k:8:-8:1,660:8:-8:1,66g:6:-8:1,66x:4:-8:2,67c:8:-8:1,688:8:-8:1,68o:8:-8:1,694:8:-8:1,69k:2:-8:1,69m:2:-22:1,69o:1:-9:1,6a0:4:-2e:1,6a4:1:-9:1,6ag:2:-8:1,6ai:2:-2s:1,6aw:2:-8:1,6ay:2:-34:1,6b0:1:-7:1,6bc:2:-3k:1,6be:2:-3i:1,6bg:1:-9:1,6jq:1:-5st:1,6ju:1:-6gv:1,6jv:1:-6di:1,6k2:1:s:1,6lc:g:g:1,6mb:1:1:1,792:q:q:1,8ow:1c:1c:1,8rk:1:1:1,8rm:1:-8af:1,8rn:1:-2xy:1,8ro:1:-89z:1,8rr:3:1:2,8rx:1:-8bg:1,8ry:1:-8al:1,8rz:1:-8bj:1,8s0:1:-8bi:1,8s2:1:1:1,8s5:1:1:1,8se:2:-8cf:1,8sg:1e:1:2,8vf:2:1:2,8vm:1:1:1,wu8:n:1:2,ww0:e:1:2,x0i:7:1:2,x0y:v:1:2,x2x:2:1:2,x31:1:-r9g:1,x32:5:1:2,x3f:1:1:1,x3h:1:-wmg:1,x3k:2:1:2,x3q:a:1:2,x4a:1:-wn8:1,x4b:1:-wnj:1,x4c:1:-wnf:1,x4d:1:-wn5:1,x4e:1:-wn8:1,x4g:1:-wlu:1,x4h:1:-wmi:1,x4i:1:-wlx:1,x4j:1:ps:1,x4k:8:1:2,x50:1:-1c:1,x51:1:-wn7:1,x52:1:-raw:1,x53:2:1:2,x5c:1:1:1,x5i:2:1:2,x6d:1:1:1,1ee9:q:w:1,1fcw:14:14:1,1fhs:10:14:1,1fn4:b:13:1,1fng:f:13:1,1fnw:7:13:1,1fo4:2:13:1,1h1c:1f:1s:1,1jfk:w:w:1,20cg:w:w:1,2olc:y:y:1";var J="C.UTF-8",Ir="only the C.UTF-8 locale is supported",ao=e=>typeof e=="string"&&/^C\.UTF-?8$/iu.test(e),mm=new Set(["LANG","LC_ALL","LC_CTYPE"]);function Ca(e){if(e.locale===void 0||ao(e.locale))return J;throw new TypeError(`createTerminal: ${Ir} (got ${JSON.stringify(e.locale)})`)}function Fa(e,t){if(!(mm.has(e)?ao(t)||e!=="LANG"&&t==="":ao(t)||t==="C"||t==="POSIX"||t===""))throw new w("feature",e,`${e}: ${Ir}`)}var Cr=e=>e==="C"||e==="POSIX",ae=e=>Cr(e.locale);function Oa(e){let t=[],n=-1;for(let r of e.split(",")){let[i,o]=r.split(":").map(u=>parseInt(u,36)),s=n+1+i;t.push([s,s+o]),n=s+o}return t}function gm(e){let t=e.findIndex(([n])=>n>95);return[...e.slice(0,t),[95,95],...e.slice(t)]}function uo(e){return e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122?String.fromCodePoint(e):e<128?"\\x"+e.toString(16).padStart(2,"0"):String.fromCodePoint(e)}var wm=e=>e.map(([t,n])=>t===n?uo(t):`${uo(t)}-${uo(n)}`).join("");function bm(e,t){let n=e.length-1,r=0;for(;r<=n;){let i=r+n>>1;if(t<e[i][0])n=i-1;else if(t>e[i][1])r=i+1;else return!0}return!1}var Fr=e=>e==="upper"||e==="lower"?"alpha":e,ym=[181,305,383,453,456,459,498,837,962,976,977,981,982,1008,1009,1010,1013,7835,8126],It=/[\u1C80-\u1C88]/u;function Ia(e){let t=new Map;for(let n of e.split(",")){let[r,i,o,s]=n.split(":").map(u=>parseInt(u,36));for(let u=0;u<i;u++)t.set(r+u*s,r+u*s+o)}return t}var Ta=(e,t)=>({up:e,low:t,folds:new Map});function xm(){let e=new Map,t=new Map;for(let n=97;n<=122;n++)e.set(n,n-32),t.set(n-32,n);return Ta(e,t)}function km(e){let t=[];for(let[n,r]of e.sort((i,o)=>i[0]-o[0])){let i=t.at(-1);i&&n<=i[1]+1?i[1]=Math.max(i[1],r):t.push([n,r])}return t}function _a(e,t,n,r,i){let o=new Map,s=new Map,u=null,a=c=>(s.has(c)||s.set(c,n(c)),s.get(c)),l=()=>u??=i(),f={name:e,multibyte:t,ranges:a,body(c){return o.has(c)||o.set(c,r(c,a(c))),o.get(c)},has(c,d){let p=a(c);return p!==void 0&&bm(p,d)},assertions(){if(f.js)return f.js;let c=f.body("space"),d=`[${f.body("word")}]`;return f.js={__proto__:null,"<":`(?<!${d})(?=${d})`,">":`(?<=${d})(?!${d})`,boundary:`(?:(?<!${d})(?=${d})|(?<=${d})(?!${d}))`,inside:`(?:(?<=${d})(?=${d})|(?<!${d})(?!${d}))`,word:d,nonWord:`[^${f.body("word")}]`,space:`[${c}]`,nonSpace:`[^${c}]`},f.js},up:c=>l().up.get(c)??c,low:c=>l().low.get(c)??c,fold(c){let{folds:d}=l(),p=d.get(c);if(p===void 0){let h=f.up(c),m=f.low(h),g=new Set([c,h]);m!==h&&f.up(m)===h&&g.add(m);for(let b of ym)f.up(b)===h&&g.add(b);p=[...g].sort((b,x)=>b-x),d.set(c,p)}return p},foldRange(c,d){let{up:p}=l(),h=p.get(c)??c,m=p.get(d)??d;if(h>m)return null;let g=[],b=[];for(let[E,M]of p){let D=E>=h&&E<=m;D!==(M>=h&&M<=m)&&(D?g:b).push(E)}let x=[],S=h;for(let E of g.sort((M,D)=>M-D))E>S&&x.push([S,E-1]),S=E+1;return S<=m&&x.push([S,m]),km([...x,...b.map(E=>[E,E])])}};return f}var vm=_a("C",!1,e=>so[e],e=>Ot[e],xm),Sm=_a(J,!0,e=>e==="word"?gm(Oa(Or.alnum)):Object.hasOwn(Or,e)?Oa(Or[e]):void 0,(e,t)=>t===void 0?void 0:wm(t),()=>Ta(Ia(Na),Ia(Aa)));function Q(e){if(e===J)return Sm;if(Cr(e))return vm;throw new w("feature","locale",`matching in the ${e} locale is not supported`)}var oe=(1n<<63n)-1n,tt=-oe-1n,nt=(1n<<64n)-1n;function R(e,t,n,r){let i=v(e.cwd,n,e.fs,r);return L(e,t,n,i.error),i}function L(e,t,n,r){if(r!=="No such file or directory"||typeof n!="string")return;let i=n.startsWith("/"),o=i?"/":e.cwd,s=n.replace(/^\/+/u,""),u=new Set;for(let f of new Set(["/",e.mount??"/",e.home??"/"])){if(f===o)continue;let c=v(f,s,e.fs);c.error||u.add(c.path)}if(!u.size)return;let a=i?"":` from cwd ${JSON.stringify(e.cwd)}`,l=`${i?"absolute":"relative"} path ${JSON.stringify(n)} was not found${a}`;e.notes?.add(`${t}: ${l}. ${$m(e,u)}`)}function $m(e,t){let n=[...t].sort(B),r=n.map(u=>JSON.stringify(u));if(n.length===1)return`A ${e.fs.isDir(n[0])?"dir":"file"} exists at ${r[0]}.`;let o=n.every(u=>!e.fs.isDir(u)&&e.fs.isFile(u))&&n.some(u=>!e.fs.sameFileContents(n[0],u)),s=`${r.slice(0,-1).join(", ")} and ${r.at(-1)}`;return`${n.length===2?"Both":"All"} of ${s} exist${o?", and they differ in contents":""}.`}function Zt(){let e=new Set;return{add:t=>e.add(t),collect(t,n){for(let r of n)r.startsWith(".")&&e.add(G(t,r))},emit(t,n,r,i=""){ht(t,{command:n,action:"omitted",noun:["hidden entry","hidden entries"],explanation:r,context:i,paths:e})}}}var La=/^(?<command>[^:]+): (?<operand>.+): (?<reason>no such file or directory|not a directory|is a directory)$/iu;function Ra(e,t){for(let n of t.split(`
|
|
4
|
+
`))La.test(n)&&e.discarded?.add(n)}function lo(e,t,n){let r=new Map;for(let i of e){if(t.includes(i))continue;let{command:o,operand:s,reason:u}=La.exec(i).groups,a=/'([^']*)'$/u.exec(s)?.[1]??s;if([...n].some(f=>f.includes(JSON.stringify(a))))continue;let l=`${o}: ${u}`;r.has(l)||r.set(l,new Set),r.get(l).add(a)}return[...r].map(([i,o])=>`${i}: ${[...o].map(s=>JSON.stringify(s)).join(", ")}.`)}function Ma(e,t){return e==="status"?null:{name:t,search:e==="search"}}function Pa(){let e=null,t=0;return{skip(n,r){!t&&n&&(e={...n,exitCode:r}),t++},flush(n){if(t&&e){let r=t===1?"the command":`the ${t} commands`,i=e.search&&e.exitCode===1?" A search that selects no lines exits 1, which is not a failure.":"";n.add(`${e.name}: exited ${e.exitCode}, so ${r} after && did not run.${i}`)}e=null,t=0}}}function ht(e,t){Em(e,t,t.paths.size,t.paths)}function Em(e,{command:t,action:n,noun:r,explanation:i="",context:o=""},s,u){if(!s)return;let a=s<10?": "+[...u].sort(B).map(f=>JSON.stringify(f)).join(", "):"",l=Array.isArray(r)?r[s===1?0:1]:r;e.add(`${t}: ${n} ${s} ${l}${o}${a}.${i?" "+i:""}`)}function pe(e,t=`
|
|
5
|
+
`){if(e==="")return[];let n=e.split(t);return n.at(-1)===""&&n.pop(),n}var he=(e,t=`
|
|
6
|
+
`)=>e.length===0?"":e.join(t)+t;function He(e,t=`
|
|
7
|
+
`){let n=[];for(let r=0;r<e.length;){let i=e.indexOf(t,r),o=i<0?e.length:i+t.length;n.push(e.slice(r,o)),r=o}return n}function X(e,t=""){e.io?.read(e.stdinHandle?.identity),e.stdinLeft=t}function rt(e,t,n,r="",i={}){let o=[],s="",u=r,a=i.read??"text",l=a==="bytes"||a==="loose-bytes",f=l?"bytes":"content",c=p=>l?a==="loose-bytes"?A(p):q(p):p,d=(p,h)=>{if(l){p.bytes=Me(n.fs,h,a==="loose-bytes");return}if(a==="text"||n.fs.isBytes?.(h)!==!0){p.content=n.fs.readFile(h);return}p.bytes=n.fs.readBytes(h),p.content=a==="maybe-text"?pt(p.bytes):void 0};for(let p of t){let h={name:p,[f]:c(""),kind:"file"},m;if(p==="/dev/stdin"&&n.stdinFile)n.io?.read(n.stdinHandle?.identity),h[f]=c(n.stdinOrigin);else if(p==="-"||p==="/dev/stdin")h[f]=c(u),h.shared=!0,u="",X(n);else if(p!=="/dev/null"){let g=R(n,e,p);g.error?(h.kind="missing",m=g.error):n.fs.isDir(g.path)?(h.kind="dir",i.noRead||(m="Is a directory")):d(h,g.path)}if(o.push(h),m&&(s+=fo(e,p,m,h.kind==="dir")),h.kind!=="file"&&(i.stopOnError||h.kind==="dir"&&i.stopOnDir))break}return{inputs:o.filter(p=>p.kind==="file"),entries:o,stderr:s,failed:s!==""}}var Nm={head:["cannot open '%s' for reading: %r","error reading '%s': Is a directory"],tail:["cannot open '%s' for reading: %r","error reading '%s': Is a directory"],sort:["cannot read: %s: %r","read failed: %s: Is a directory"],sed:["can't read %s: %r","read error on %s: Is a directory"],tac:["failed to open '%s' for reading: %r","%s: read error: Invalid argument"],base64:[null,"read error: Is a directory"],uniq:[null,"error reading '%s': Is a directory"]};function fo(e,t,n,r=!1){let i=Nm[e]?.[r?1:0],o=i?i.replace(/%[sr]/gu,s=>s==="%s"?t:n):`${t}: ${n}`;return`${e}: ${o}
|
|
8
|
+
`}function Me(e,t,n=!1){let r=e.readBytes?.(t,n);if(r!==void 0)return r;let i=e.readFile(t);if(i!==void 0)return n?A(i):q(i)}function mt(e,t){if(e.isBytes?.(t)!==!0)return{text:e.readFile(t),bytes:void 0};let n=e.readBytes(t);return{text:pt(n),bytes:n}}function se(e,t,n,r,i){if(t.length===0){X(r);let o=i?.read,a=[{name:null,kind:"file",...o==="bytes"||o==="loose-bytes"?{bytes:o==="loose-bytes"?A(n):q(n)}:{content:n}}];return{inputs:a,entries:a,stderr:"",failed:!1}}return rt(e,t,r,n,i)}function Da(e,t){return e===null||e==="-"||e==="/dev/stdin"?t.stdinHandle?.path?JSON.stringify(t.stdinHandle.path):"standard input":JSON.stringify(v(t.cwd,e,t.fs).path??e)}function Sn(e,t,n,r){let i=se(e,t,n,r);return{content:i.inputs.map(o=>o.content).join(""),stderr:i.stderr,failed:i.failed}}var ee=(e,t)=>({stdout:e,stderr:t.stderr,exitCode:t.failed?1:0});function we(e,t,n=e,{max:r=1/0,digitsOnly:i=!1}={}){if(typeof e!="string"||!(i?/^\d+$/u:/^[ \t\n\r\f\v]*\+?\d+$/u).test(e))return{error:y(`${t}: invalid count: ${n}`)};let o=Number(e);return o>r?{error:y(`${t}: out of range: ${n}`)}:{value:Math.min(o,Number.MAX_SAFE_INTEGER)}}function Ua(e,t){if(typeof e!="string")return{error:y(`${t}: invalid count: ${e}`)};let n=e[0]==="+"||e[0]==="-"?e[0]:"",r=n==="-"?e.slice(1):e,i=/^[ \t\n\r\v\f]*\+?(\d+)(b|[kKMGTPEZYRQ](?:i?B)?)?$/u.exec(r),o=!n&&/^(?:b|[kKMGTPEZYRQ](?:i?B)?)$/u.test(r);if(!i&&!o)return{error:y(`${t}: invalid count: ${e}`)};let s=i?.[2]??(o?r:""),u=co(BigInt(i?.[1]??"1"),s,t,e);return u.error?u:{...u,sign:n}}function co(e,t,n,r){let i=1n;t==="b"?i=512n:t&&(i=(t.length===2?1000n:1024n)**BigInt("KMGTPEZYRQ".indexOf(t[0].toUpperCase())+1));let o=e*i;return o>nt?{error:y(`${n}: count out of range: ${r}`)}:{value:Number(o>BigInt(Number.MAX_SAFE_INTEGER)?BigInt(Number.MAX_SAFE_INTEGER):o)}}function Z(e){try{let t=e?.message;return typeof t=="string"&&t!==""?t:String(e)}catch{return"threw a value with no message"}}var it=e=>e==="/tmp"||e.startsWith("/tmp/");function Ba(e){let t=new Map,n=new Map,r=new Set(["/tmp"]),i,o=e.listDir("/"),s={dirs:[...o.dirs,"tmp"].sort(B),files:o.files,links:o.links??[]},u=Tm(r,t,n),a=u.reshaped,l=(c,d)=>{if(!c.startsWith("/tmp/"))throw new Error("writable overlay paths must start with /tmp/");t.has(c)||a(),n.delete(c),t.set(c,d)},f={observeIo:c=>{i=c},fileIdentity:c=>t.get(c),fileSize:c=>t.get(c)?.bytes.length??(n.has(c)?q(n.get(c)).length:e.fileSize(c)),readIdentity:c=>(i?.read(c),P(c.bytes)),isFile:c=>t.has(c)||e.isFile(c),isDir:c=>r.has(c)||e.isDir(c),isLink:c=>n.has(c)||e.isLink?.(c)===!0,readLink:c=>n.get(c)??e.readLink?.(c),...Am(e,t,c=>i?.read(c)),sameFileContents:(c,d)=>_m(e,t,c,d),listDir:c=>c==="/"?s:r.has(c)?u.of(c):e.listDir(c),*walkFiles(c){for(let d of Oe(f,c))d.kind==="file"&&(yield d.path)},openWritable(c,d,p=!1){let h=ie(f,c,d);if(h!=="/tmp"&&!h.startsWith("/tmp/"))return null;$n(f,c,d);let m=t.get(h);return m?p||(i?.write(m),m.bytes=new Uint8Array):(m={bytes:new Uint8Array},l(h,m)),Rm(h,m,p,()=>i?.write(m))},makeWritableDir:(c,d)=>Om(f,{dirs:r,files:t,links:n,reshaped:a},c,d),makeWritableLink:(c,d,p)=>Im(f,{links:n,reshaped:a},c,d,p),removeWritableDir:(c,d)=>Fm(f,{dirs:r,reshaped:a},c,d),copyWritable(c,d,p){let h=ie(f,c,p);if(!h.startsWith("/tmp/"))return!1;$n(f,c,p);let m=t.get(d);if(d===h||m&&m===t.get(h))throw new Error("source and destination are the same file");i?.read(m??d);let g=m?m.bytes:Me(e,d);return f.openWritable(c,p).writeBytes(g),!0},replaceWritable:(c,d,p,h)=>Cm(f,{files:t,links:n,put:l},c,d,p,h),removeWritable(c,d){let p=ie(f,c,d,!1);if(p!=="/tmp"&&!p.startsWith("/tmp/"))return!1;let h=v(c,d,f,{follow:!1});if(h.error)throw Ge(d,h.error);if(f.isDir(h.path))throw new Error(`${d}: Is a directory`);return n.delete(h.path)||t.delete(h.path),a(),!0}};return f}function Am(e,t,n){return{readFile:r=>{let i=t.get(r);return n(i??r),i?Gt(i.bytes,JSON.stringify(r)):e.readFile(r)},readBytes:(r,i=!1)=>{let o=t.get(r);return n(o??r),o?o.bytes:Me(e,r,i)},exactBytes:r=>t.get(r)?.bytes??e.exactBytes(r),isEmptyFile:r=>{let i=t.get(r);return i?i.bytes.length===0:e.isEmptyFile(r)},isBytes:r=>t.has(r)||e.isBytes?.(r)===!0}}function Om(e,t,n,r){let i=ie(e,n,r,!1);if(i!=="/tmp"&&!i.startsWith("/tmp/"))return!1;if(t.dirs.has(i))return!0;if($n(e,n,r),t.files.has(i)||t.links.has(i))throw new Error(`${r}: File exists`);return t.dirs.add(i),t.reshaped(),!0}function Im(e,t,n,r,i){let o=ie(e,n,r,!1);return o.startsWith("/tmp/")?(Lm(e,n,r),t.links.set(o,i),t.reshaped(),!0):!1}function Cm(e,t,n,r,i,o){let s=ie(e,n,r,!1),u=o===void 0?null:ie(e,n,o,!1);if(!s.startsWith("/tmp/")||u!==null&&!u.startsWith("/tmp/"))return!1;$n(e,n,r);let a=t.files.get(s),l=t.links.get(s);if(!a&&l===void 0)throw Ge(r,"No such file or directory");u!==null&&$n(e,n,o);let f={bytes:q(i)};return l===void 0?u!==null&&t.put(u,a):(t.links.delete(s),u!==null&&(t.links.set(u,l),t.files.delete(u))),t.put(s,f),!0}function Fm(e,t,n,r){let i=ie(e,n,r,!1);if(i!=="/tmp"&&!i.startsWith("/tmp/"))return!1;let o=v(n,r,e);if(o.error)throw Ge(r,o.error);if(!t.dirs.has(o.path))throw new Error(`${r}: Not a directory`);if(o.path==="/tmp")throw new Error(`${r}: Device or resource busy`);let{dirs:s,files:u,links:a}=e.listDir(o.path);if(s.length||u.length||a.length)throw new Error(`${r}: Directory not empty`);return t.dirs.delete(o.path),t.reshaped(),!0}function Tm(e,t,n){let r=new Map,i=(o,s)=>[...o].filter(u=>u.startsWith(s)&&!u.slice(s.length).includes("/")).map(u=>u.slice(s.length)).sort(B);return{reshaped:()=>{r=new Map},of(o){let s=r.get(o);if(s)return s;let u={dirs:i(e,o+"/"),files:i(t.keys(),o+"/"),links:i(n.keys(),o+"/")};return r.set(o,u),u}}}function _m(e,t,n,r){let i=t.get(n),o=t.get(r);if(!i&&!o)return e.sameFileContents(n,r);let s=(u,a)=>a?a.bytes:e.exactBytes(u);return vn(s(n,i),s(r,o))}function $n(e,t,n){let r=je(t,n,e);if(r.error===null){if(e.isDir(r.path))throw new Error(`${n}: Is a directory`);if(n.endsWith("/"))throw Ge(n,"Not a directory");return}if(r.rest.length>0||n.endsWith("/")||n.includes("\0"))throw Ge(n,r.error);if(!e.isDir(ge(r.path)))throw Ge(n,"No such file or directory")}function Lm(e,t,n){if(n===""||n.includes("\0"))throw Ge(n,"No such file or directory");let r=je(t,n,e,{follow:!1});if(r.error===null)throw Ge(n,"File exists");if(r.rest.length>0||n.endsWith("/"))throw Ge(n,r.error);if(!e.isDir(ge(r.path)))throw Ge(n,"Not a directory")}function Ge(e,t){return Object.assign(new Error(`${e}: ${t}`),{path:e,fsError:t})}function Rm(e,t,n,r){let i=0,o=s=>{let u=t.bytes,a=n?u.length:i,l=Math.max(u.length,a+s.length),f=u.buffer;f.byteLength<l&&(f=new ArrayBuffer(Math.max(l,f.byteLength*2)),new Uint8Array(f).set(u));let c=new Uint8Array(f,0,l);c.set(s,a),t.bytes=c,i=a+s.length};return{path:e,identity:t,get position(){return n?t.bytes.length:i},write(s){s!==""&&(r(),o(q(s)))},writeBytes(s){s.length!==0&&(r(),o(s))}}}var qa=["cwd","home","user","inherit"];function Wa(e,t){let n=En(t,"mount","/"),r=En(t,"home",n),i=En(t,"cwd",n);if(t.writable!==void 0&&t.writable!==!1&&t.writable!=="/tmp/")throw new TypeError("createTerminal: writable must be '/tmp/', false, or undefined");let o=t.writable==="/tmp/";if(o&&(n==="/"||n==="/tmp"||n.startsWith("/tmp/")))throw new Error("createTerminal: mount must not be /, /tmp, or inside /tmp when writable is '/tmp/'");let s=Sa(e,n);return{fs:o?Ba(s):s,cwd:i,home:r,mount:n,writable:o,locale:Ca(t)}}function ja(e,t){if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(`fork: options must be an object (got ${t===null?"null":Array.isArray(t)?"an array":typeof t})`);for(let n of Object.keys(t))if(!qa.includes(n))throw new Error(`fork: unknown option \`${n}\` (known: ${qa.join(", ")}; the sources, the mount, the /tmp/ overlay and the commands come from the parent)`);if(t.inherit!==void 0&&typeof t.inherit!="boolean")throw new TypeError(`fork: inherit must be true or false (got ${t.inherit===null?"null":typeof t.inherit})`);return{cwd:En(t,"cwd",e.cwd,"fork",e.cwd),home:En(t,"home",e.home,"fork",e.cwd),user:t.user??e.user,locale:e.locale,inherit:t.inherit??!0}}function En(e,t,n,r="createTerminal",i="/"){let o=e[t]===void 0?n:e[t];if(typeof o!="string"||o.includes("\0"))throw new TypeError(`${r}: ${t} must be a string without NUL characters`);return G(i,o)}function be(e,t=0,n=e.value.length){return{value:e.value.slice(t,n),mask:e.mask===null?null:e.mask.slice(t,n),...e.empty?{empty:e.empty.filter(r=>r>=t&&r<=n).map(r=>r-t)}:{}}}function Nn(e){let t=/^([A-Za-z_][A-Za-z0-9_]*)=/u.exec(e.value);return!t||e.mask!==null&&/[12]/u.test(e.mask.slice(0,t[0].length))||e.empty?.some(n=>n<t[0].length)?null:{name:t[1],end:t[0].length}}var za=(e,t)=>e.mask===null?"0":e.mask[t];function Ha(e,t=!1){let n=new Set;if(!e.value.includes("~"))return n;let r=e.value,i=u=>za(e,u)==="0",o=t?null:Nn(e)?.end??null,s=u=>t===!0||o!==null&&u>=o;for(let u=0;u<r.length;u++){let a=u===0||u===o||s(u)&&r[u-1]===":"&&i(u-1),l=s(u)||t==="parameterAssign";if(!a||r[u]!=="~"||!i(u)||!Mm(e,u,l))continue;let f=r[u+1];if(f&&f!=="/"&&f!==":"&&i(u+1))throw new w("feature","tilde prefix","named-user and directory-stack tilde prefixes are not supported");(f===void 0||i(u+1)&&(f==="/"||f===":"&&l))&&n.add(u)}return n}function Mm(e,t,n){for(let r=t;r<=e.value.length;r++){if(e.empty?.includes(r))return!1;if(r===e.value.length)return!0;if(za(e,r)!=="0")return!1;if(e.value[r]==="/"||n&&e.value[r]===":")return!0}return!0}function Ga(...e){let t="",n="",r=[];for(let i of e){for(let o of i.empty??[])r.push(t.length+o);t+=i.value,n+=i.mask??"0".repeat(i.value.length)}return{value:t,mask:e.every(i=>i.mask===null)?null:n,...r.length?{empty:r}:{}}}var Yt=64;function ot(e,t){let n="";for(let r=t+1;r<e.length;r++){let i=e[r];if(i==="`")return{command:n,raw:e.slice(t,r+1),backtick:!0};if(i!=="\\"){n+=i;continue}let o=e[r+1];if(o==="`")throw new w("feature","\\`","nested backtick command substitution is not supported; use `$( )` instead");if(o==="$"||o==="\\"){n+=o,r++;continue}if(o===`
|
|
9
|
+
`){r++;continue}n+=i}throw new Error("unterminated backtick substitution")}var Xa=()=>({value:"",quoted:!1,started:!1}),Za=()=>new w("feature","command substitution depth",`command substitution nesting above ${Yt} is not supported`);function po(e,t,n,r,i){if(r>=Yt)throw Za();let o={line:e,i:n+1,depth:r,helpers:i,parens:0,quote:null,word:Xa(),command:!0,target:null,heredocs:[]};for(;o.i<e.length;)if(Pm(o))return{raw:e.slice(t,o.i+1),command:e.slice(n+1,o.i)};throw o.quote?new Error(`unterminated ${o.quote==="'"?"single":"double"} quote`):new Error("unterminated command substitution")}function gt(e,t,n=!1){e.word.value+=t,e.word.quoted||=n,e.word.started=!0}function ho(e){let t=e.word;if(t.started){if(e.target)e.target.op==="heredoc"&&(e.target.delim=t.value,e.target.quotedDelim=t.quoted),e.target=null;else if(e.command&&!t.quoted){if(t.value==="case")throw new w("feature","case","`case` patterns inside command substitutions are not supported");e.command=["!","{","do","then","else","elif","if","while","until"].includes(t.value)||/^[A-Za-z_][A-Za-z0-9_]*=/u.test(t.value)}else e.command=!1;e.word=Xa()}}function Pm(e){let{line:t,i:n,quote:r}=e,i=t[n];if(r&&i===r)return e.quote=null,e.word.quoted=!0,e.i++,!1;if(r==="'")return gt(e,i,!0),e.i++,!1;if(i==="\\")return Dm(e),!1;if(i==="$")return Um(e),!1;if(i==="`")return Bm(e),!1;if(r)return gt(e,i,!0),e.i++,!1;if(i==="'"||i==='"')return e.quote=i,e.word.started=!0,e.i++,!1;if(e.command&&!e.target&&!e.word.started&&t.startsWith("[[",n)&&/[ \t\n()<>;&|]|^$/u.test(t[n+2]??"")){let s=e.helpers.readConditional(t,n,e.helpers,e.depth+e.parens+1);return e.i+=s.raw.length,e.command=!1,!1}if(i==="#"&&!e.word.started){let s=t.indexOf(`
|
|
10
10
|
`,n);return e.i=s===-1?t.length:s,!1}if(i===`
|
|
11
|
-
`)return
|
|
12
|
-
`){e.i+=2;return}t!==void 0&&(!e.quote||'$`"\\'.includes(t))?(
|
|
13
|
-
`,"");if(t.startsWith("#")&&t.length>1&&
|
|
14
|
-
`?n+=2:(t--,n++);return n}var
|
|
15
|
-
`;)
|
|
16
|
-
`;)a+=2;if(e[a]!==")")throw
|
|
11
|
+
`)return Wm(e),!1;if(i===" "||i===" ")return ho(e),e.i++,!1;let o;try{o=e.helpers.readOperator(t,n,!e.word.started)}catch(s){if(!(s instanceof w))throw s;return e.i++,!1}return o?qm(e,o):(gt(e,i),e.i++,!1)}function Dm(e){let t=e.line[e.i+1];if(t===`
|
|
12
|
+
`){e.i+=2;return}t!==void 0&&(!e.quote||'$`"\\'.includes(t))?(gt(e,t,!0),e.i+=2):(gt(e,"\\",!!e.quote),e.i++)}function Um(e){let{line:t,i:n}=e,r=e.helpers.skipContinuations(t,n+1);if(!e.quote&&t[r]==="'"){let s=e.helpers.decodeAnsiC(t,r+1);gt(e,s.text,!0),e.i=s.end;return}if(!e.quote&&t[r]==='"'){e.quote='"',e.word.started=!0,e.i=r+1;return}let o=e.helpers.readExpansion(t,n,e.depth+e.parens+1,e.quote==='"')?.raw??"$";gt(e,o,!!e.quote),e.i+=o.length}function Bm(e){let t=e.i++;for(;e.i<e.line.length;){let n=e.line[e.i++];if(n==="`"){gt(e,e.line.slice(t,e.i),!!e.quote);return}n==="\\"&&e.i<e.line.length&&e.i++}throw new Error("unterminated backtick substitution")}function qm(e,t){ho(e);let n=t.token;if(n.kind==="paren_close"){if(e.parens===0){if(e.heredocs.length)throw new w("feature","command substitution heredoc","a command substitution heredoc must finish before its closing parenthesis");return!0}e.parens--,e.command=!1}else if(n.kind==="paren_open"){if(e.depth+ ++e.parens>=Yt)throw Za();e.command=!0}else n.kind==="redir"?(e.command=!1,n.op==="heredoc"&&e.heredocs.push(n),["dup","close"].includes(n.op)||(e.target=n)):e.command=!0;return e.i=t.end,!1}function Wm(e){if(ho(e),e.heredocs.some(t=>t.delim===null))throw new Error("heredoc requires a delimiter");e.heredocs.length&&(e.i=e.helpers.readHeredocBodies(e.line,e.i,e.heredocs),e.heredocs=[]),e.command=!0,e.i++}function Xe(e){return Number.isInteger(e)&&e>=0&&e<=1114111&&(e<55296||e>57343)}var Pe=e=>e>65535?2:1,Ie=(e,t)=>Pe(e.codePointAt(t));var jm=/^(?:[A-Za-z_][A-Za-z0-9_]*|[0-9]+|[?*@#$!-])(?![\s\S])/u,zm=/^(?:[A-Za-z_][A-Za-z0-9_]*|[0-9]+|[?*@#$!-])/u;function Ct(e,t="unsupported or malformed parameter expansion"){return new w("feature","${",`${t}: \${${e}}`)}var mo=e=>/^[0-9]+$/u.test(e)?e.replace(/^0+(?=[0-9])/u,""):e;function go(e){let t=e.replaceAll(`\\
|
|
13
|
+
`,"");if(t.startsWith("#")&&t.length>1&&jm.test(t.slice(1)))return{name:mo(t.slice(1)),operator:"length"};if(/^#[A-Za-z_0-9]/u.test(t))throw Ct(e);let n=zm.exec(t)?.[0];if(!n)throw Ct(e);let r=t.slice(n.length);if(!r)return{name:mo(n),operator:""};if(n==="#"&&/^[%:=+/]$/u.test(r))throw Ct(e);let i=/^(?::[-+=?]|[-+=?]|##?|%%?|:|\/\/?)/u.exec(r)?.[0];if(!i)throw Ct(e);return{name:mo(n),operator:i,word:e.slice(Hm(e,n.length+i.length))}}function Hm(e,t){let n=0;for(;t>0;)e[n]==="\\"&&e[n+1]===`
|
|
14
|
+
`?n+=2:(t--,n++);return n}var wt=(e,t)=>new w("feature",e,t),Ya=e=>{if(e>=64)throw wt("expansion depth","shell expansion nesting above 64 levels is not supported")};function Va(e,t,n,r,i,o){Ya(r);let s=n+1,u=null;for(let a=s;a<e.length;a++){let l=e[a];if(u==="'"){l==="'"&&(u=null);continue}if(l==="\\"){a++;continue}if(l==='"'){u=u==='"'?null:'"';continue}if(l==="'"&&!u){u="'";continue}if(l==="`")throw wt("`","command substitution (backticks) is not supported");if(l==="$"){let f=a+1;for(;e[f]==="\\"&&e[f+1]===`
|
|
15
|
+
`;)f+=2;if(e[f]==="'"&&!u){let d=o.decodeAnsiC(e,f+1),p=go(e.slice(s,a)).operator;if(i&&/[-+?=]/u.test(p)&&/[$`"'\\}]/u.test(d.text))throw wt("${","active characters in ANSI-C quoted parameter operands are not supported");a=d.end-1;continue}let c=o.readExpansion(e,a,r+1,i||u==='"');if(c){a+=c.raw.length-1;continue}}if(l==="}"&&!u){let f=go(e.slice(s,a));return{raw:e.slice(t,a+1),parameter:f}}}throw wt("${","unterminated parameter expansion")}function Ka(e,t,n,r,i){Ya(r);let o=0;for(let s=n+1;s<e.length;s++){let u=e[s];if(u==="\\"){s++;continue}if(u==="$"){let l=i.readExpansion(e,s,r+1,!0);if(l){s+=l.raw.length-1;continue}}if(u==="`")throw wt("`","command substitution (backticks) is not supported");if(u==='"'||u==="'")throw wt("$((","quotes in arithmetic expressions are not supported");if(u==="("&&o++,u!==")")continue;if(o){o--;continue}let a=s+1;for(;e[a]==="\\"&&e[a+1]===`
|
|
16
|
+
`;)a+=2;if(e[a]!==")")throw wt("$((","arithmetic expansion requires a closing `))`");return{raw:e.slice(t,a+1),arithmetic:e.slice(n+1,s)}}throw wt("$((","unterminated arithmetic expansion")}var Gm=/^-[abcdefghknoprstuvwxzGLNORS]$/u,Xm=new Set(["=","==","!=","=~","<",">","-eq","-ne","-lt","-le","-gt","-ge","-nt","-ot","-ef"]),Zm=new Set(["end","&&","||",")"]),Ym=/^[A-Za-z_][A-Za-z0-9_]*$/u;function An(e,t,n,r=0){let i={line:e,i:t+2,helpers:n,token:null,depth:0,terms:0,removed:0,expansionDepth:r};try{Ze(i,!0);let o=tl(i);return i.token.kind!=="end"&&bt(`unexpected token \`${i.token.value??i.token.kind}\``),{raw:e.slice(t,i.i+i.removed),expression:o}}catch(o){if(o instanceof w||o.conditional)throw o;bt(o.message)}}function tl(e){let t=Ja(e);for(;e.token.kind==="||";)Ze(e,!0),t={kind:"or",left:t,right:Ja(e)};return t}function Ja(e){let t=wo(e);for(;e.token.kind==="&&";)Ze(e,!0),t={kind:"and",left:t,right:wo(e)};return t}function wo(e){if(++e.terms>128)throw new w("feature","[[ complexity","conditional expressions above 128 terms are not supported");if(++e.depth>64)throw new w("feature","[[ nesting","conditional nesting above 64 levels is not supported");try{let t=e.token;if(t.kind==="("){Ze(e,!0);let i=tl(e);return e.token.kind!==")"&&bt("expected `)`"),Ze(e,!0),i}if(nl(t,"!"))return Ze(e,!0),{kind:"not",expression:wo(e)};if(t.kind!=="word"&&bt("expected an operand"),Ze(e),!t.quoted&&Gm.test(t.value)){let i=Qa(e);return Ze(e,!0),{kind:"unary",op:t.value,word:i}}if(Zm.has(e.token.kind))return{kind:"unary",op:"-n",word:t};let n=e.token;if((n.quoted||!Xm.has(n.value))&&bt("conditional binary operator expected"),n.value==="=~")throw new w("feature","[[ =~","regular expression comparisons in [[ are not supported");Ze(e);let r=Qa(e);return Ze(e,!0),{kind:"binary",op:n.value,left:t,right:r}}finally{e.depth--}}var nl=(e,t)=>e.kind==="word"&&!e.quoted&&e.value===t,bt=e=>{throw Object.assign(new Error(`[[ ${e}`),{conditional:!0})};function Qa(e){return e.token.kind!=="word"&&bt("expected an operand"),e.token}function Ze(e,t=!1){if(e.token=el(e),t)for(;e.token.kind==="newline";)e.token=el(e)}function el(e){for(;e.i<e.line.length;){let t=e.line[e.i];if(t===" "||t===" "){e.i++;continue}if(t==="\\"&&e.line[e.i+1]===`
|
|
17
17
|
`){e.i+=2;continue}if(t==="#"){let i=e.line.indexOf(`
|
|
18
18
|
`,e.i);e.i=i<0?e.line.length:i;continue}if(t===`
|
|
19
|
-
`)return e.i++,{kind:"newline"};let n=e.line.slice(e.i,e.i+2);if(n==="<("||n===">(")throw new w("feature",n,`process substitution (\`${n}\u2026\`) is not supported`);if(n==="&&"||n==="||")return e.i+=2,{kind:n};if("()<>;&|".includes(t))return e.i++,{kind:t,value:t};let r=
|
|
20
|
-
`){e.i+=2;return}r!==void 0&&(!n||'$`"\\'.includes(r))?(
|
|
21
|
-
`;)e.line=e.line.slice(0,e.i+1)+e.line.slice(e.i+3),e.removed+=2}function
|
|
22
|
-
`;)t+=2;return t}function
|
|
23
|
-
`,r:"\r",t:" ",v:"\v","\\":"\\","'":"'",'"':'"',"?":"?"};function
|
|
24
|
-
`,r);let l=u===-1?e.length:u;if(a+=e.slice(r,l),r=l+1,i.quotedDelim||u===-1||!
|
|
19
|
+
`)return e.i++,{kind:"newline"};let n=e.line.slice(e.i,e.i+2);if(n==="<("||n===">(")throw new w("feature",n,`process substitution (\`${n}\u2026\`) is not supported`);if(n==="&&"||n==="||")return e.i+=2,{kind:n};if("()<>;&|".includes(t))return e.i++,{kind:t,value:t};let r=Vm(e);return nl(r,"]]")?{kind:"end"}:r}bt("missing `]]`")}function Vm(e){let t={kind:"word",value:"",mask:"",quoted:!1,empty:[]},n=null,r=0;for(;e.i<e.line.length;){let i=e.line[e.i];if(n&&i===n){t.value.length===r&&t.empty.push(r),t.quoted=!0,n=null,e.i++;continue}if(n==="'"){Ce(t,i,"1"),e.i++;continue}if(i==="\\"){Km(e,t,n);continue}if(i==="$"){if(Jm(e),!n&&e.line[e.i+1]==='"'){n='"',r=t.value.length,e.i+=2;continue}Qm(e,t,n);continue}if(i==="`"){let o=ot(e.line,e.i);Ce(t,"`",n?"2":"0"),Ce(t,o.raw.slice(1),"1"),e.i+=o.raw.length;continue}if(n){Ce(t,i,"2"),e.i++;continue}if(i==="'"||i==='"'){n=i,r=t.value.length,e.i++;continue}if(i==="("&&t.mask.at(-1)==="0"&&/[?*+@!]/u.test(t.value.at(-1))&&!t.empty.includes(t.value.length))throw new w("feature","[[ extglob","extended glob patterns in [[ are not supported");if(/[ \t\n()<>;&|]/u.test(i))break;Ce(t,i,"0"),e.i++}return n&&bt(`unterminated ${n==="'"?"single":"double"} quote`),!t.quoted&&!/[12]/u.test(t.mask)&&(t.mask=null),t.empty.length===0&&delete t.empty,t}function Ce(e,t,n,r=n!=="0"){e.value+=t,e.mask+=n.repeat(t.length),e.quoted||=r}function Km(e,t,n){let r=e.line[e.i+1];if(r===`
|
|
20
|
+
`){e.i+=2;return}r!==void 0&&(!n||'$`"\\'.includes(r))?(Ce(t,r,"1"),e.i+=2):(Ce(t,"\\",n?"2":"1"),e.i++)}function Jm(e){for(;e.line[e.i+1]==="\\"&&e.line[e.i+2]===`
|
|
21
|
+
`;)e.line=e.line.slice(0,e.i+1)+e.line.slice(e.i+3),e.removed+=2}function Qm(e,t,n){let r=n?"2":"0";if(!n&&e.line[e.i+1]==="'"){let o=e.helpers.decodeAnsiC(e.line,e.i+2);o.text===""&&t.empty.push(t.value.length),Ce(t,o.text,"1"),e.i=o.end;return}let i=e.helpers.readExpansion(e.line,e.i,e.expansionDepth+1,!!n);if(!i){Ce(t,"$","1"),e.i++;return}if(i.command!==void 0||i.parameter!==void 0||i.arithmetic!==void 0)Ce(t,"$",r),Ce(t,i.raw.slice(1),"1",!1);else{let o=e.line[e.i+i.raw.length],s=Ym.test(i.name)&&(o==="'"||o==='"')?"${"+i.name+"}":i.raw;Ce(t,s,r)}e.i+=i.raw.length}var Ft=/^[A-Za-z_][A-Za-z0-9_]*$/u,e0=/[A-Za-z0-9_]/u,t0=/[?#@*$!0-9-]/u;function ue(e,t){for(;e[t]==="\\"&&e[t+1]===`
|
|
22
|
+
`;)t+=2;return t}function bo(e,t,n=null){let r=s=>s<e.length&&(n===null||n[s]===n[t]);if(!r(t+1))return null;let i=e[t+1];if(t0.test(i))return{name:i,raw:e.slice(t,t+2)};if(!/[A-Za-z_]/u.test(i))return null;let o=t+2;for(;r(o)&&e0.test(e[o]);)o++;return{name:e.slice(t+1,o),raw:e.slice(t,o)}}function ut(e,t,n=0,r=!1,i={}){let o=(a,l,f,c)=>ut(a,l,f,c,i),s=ue(e,t+1),u=e[s];if(u==="("){let a=ue(e,s+1);if(e[a]==="(")return Ka(e,t,a,n,{readExpansion:o});let l=po(e,t,s,n,{readExpansion:o,decodeAnsiC:Vt,readHeredocBodies:In,readOperator:Tr,readConditional:An,skipContinuations:ue});return i.validateSubstitution?.(l.command),l}if(u==="{")return Va(e,t,s,n,r,{readExpansion:o,decodeAnsiC:Vt});if(u==="[")throw new w("feature","$[","arithmetic expansion (`$[\u2026]`) is not supported");return bo(e,t)}function ol(e,t,n={}){let r=(s,u,a,l)=>ut(s,u,a,l,n),i=ue(e,t+1),o=po(e,t,i,0,{readExpansion:r,decodeAnsiC:Vt,readHeredocBodies:In,readOperator:Tr,readConditional:An,skipContinuations:ue});return n.validateSubstitution?.(o.command),o}var rl={a:"\x07",b:"\b",e:"\x1B",E:"\x1B",f:"\f",n:`
|
|
23
|
+
`,r:"\r",t:" ",v:"\v","\\":"\\","'":"'",'"':'"',"?":"?"};function n0(e,t){for(let n=t;n<e.length;n++)if(e[n]==="\\")n++;else if(e[n]==="'")return n;throw new Error("unterminated single quote")}function Vt(e,t){let n=n0(e,t),r=[],i=s=>{for(let u of A(s))r.push(u)};for(let s=t;s<n;s++){if(e[s]!=="\\"){let l=String.fromCodePoint(e.codePointAt(s));i(l),s+=l.length-1;continue}let u=e[s+1];if(u in rl){i(rl[u]),s++;continue}if(u==="x"&&e[s+2]==="{")throw new w("feature","ANSI-C hexadecimal escape","braced hexadecimal escapes in ANSI-C quotes are not supported");let a=/^(?:[0-7]{1,3}|x[0-9a-fA-F]{1,2}|u[0-9a-fA-F]{1,4}|U[0-9a-fA-F]{1,8})/u.exec(e.slice(s+1,n));if(a){let l=a[0],f=/^[0-7]/u.test(l),c=f?parseInt(l,8):parseInt(l.slice(1),16);if(f||l[0]==="x")r.push(c&255);else{if(!Xe(c))throw new w("feature","ANSI-C Unicode escape","ANSI-C escapes outside Unicode scalar values are not supported");i(String.fromCodePoint(c))}s+=l.length;continue}if(u==="c"&&s+2<n){let l=e.codePointAt(s+2);if(l>127)throw new w("feature","ANSI-C control escape","ANSI-C control escapes require an ASCII character");r.push(l===63?127:l&31),s+=2,l===92&&e[s+1]==="\\"&&s++;continue}i("\\")}let o=r.indexOf(0);return{text:P(Uint8Array.from(o===-1?r:r.slice(0,o))),end:n+1}}function Tr(e,t,n){let r=e[t];if(n&&/[0-9]/u.test(r)){let s="",u=t;for(;/[0-9]/u.test(e[u]??"");)s+=e[u],u=ue(e,u+1);return e[u]!==">"&&e[u]!=="<"||e[ue(e,u+1)]==="("?null:il(e,u,Number(s))}let i=ue(e,t+1),o=e[i];switch(r){case"|":return o==="|"?st("or",i+1):o==="&"?st("pipe_err",i+1):st("pipe",t+1);case"&":if(o==="&")return st("and",i+1);if(o===">"){let s=ue(e,i+1),u=e[s]===">";return yt(1,u?"bothAppend":"both",(u?s:i)+1)}return st("amp",t+1);case";":return o===";"?st("dsemi",i+1):st("semi",t+1);case"(":return st("paren_open",t+1);case")":return st("paren_close",t+1);case"<":case">":return il(e,t,r==="<"?0:1);default:return null}}var r0={semi:";",dsemi:";;",pipe:"|",pipe_err:"|&",and:"&&",or:"||",amp:"&",paren_open:"(",paren_close:")"},i0={write:">",append:">>",read:"<",heredoc:"<<",herestring:"<<<",both:"&>",bothAppend:"&>>",dup:">&",close:">&-"};function On(e){if(e.kind==="word")return e.quoted?`"${e.value}"`:e.value;if(e.kind==="redir"){let t=i0[e.op];if(e.op==="both"||e.op==="bothAppend")return t;let n=e.fd===(e.op==="read"||e.op==="heredoc"||e.op==="herestring"?0:1)?"":String(e.fd);return e.op==="dup"?`${n}${e.fd===0?"<&":">&"}${e.toFd}`:e.op==="close"?`${n}${e.fd===0?"<&-":">&-"}`:n+t}return r0[e.kind]}var st=(e,t)=>({token:{kind:e},end:t}),yt=(e,t,n,r)=>({token:{kind:"redir",fd:e,op:t,...r},end:n});function il(e,t,n){let r=e[t],i=ue(e,t+1),o=e[i];if(o==="&")return o0(e,i,n,r==="<"?"<&":`${n===1&&r===">"?"":n}>&`);if(r==="<"){if(o===">")throw new w("feature","<>","read/write file redirects are not supported");if(o==="<"){let s=ue(e,i+1);if(e[s]==="<")return yt(n,"herestring",s+1);let u=e[s]==="-";return yt(n,"heredoc",(u?s:i)+1,{strip:u,delim:null,body:null})}return yt(n,"read",t+1)}return o===">"?yt(n,"append",i+1):yt(n,"write",(o==="|"?i:t)+1)}function o0(e,t,n,r){let i=ue(e,t+1),o=e[i],s=e[ue(e,i+1)],u=s===void 0||/[ \t\n|&>;()<]/u.test(s);if(/[0-9]/u.test(o??"")&&u)return yt(n,"dup",i+1,{toFd:Number(o)});if(o==="-"&&u)return yt(n,"close",i+1);throw new w("feature","redirect target",`redirect \`${r}\` requires a file descriptor number (or \`-\`) followed by a token boundary`)}function In(e,t,n){let r=t+1;for(let i of n){let o=[],s=!1;for(;r<e.length;){let u,a="";for(;;){u=e.indexOf(`
|
|
24
|
+
`,r);let l=u===-1?e.length:u;if(a+=e.slice(r,l),r=l+1,i.quotedDelim||u===-1||!s0(a))break;a=a.slice(0,-1)}if(u===-1&&a==="")break;if(i.strip&&(a=a.replace(/^\t+/u,"")),a===i.delim){s=!0;break}if(o.push(a),u===-1)break}i.body=o.length===0?"":o.join(`
|
|
25
25
|
`)+`
|
|
26
26
|
`,s||(i.warning=`warning: here-document delimited by end-of-file (wanted \`${i.delim}')
|
|
27
|
-
`)}return r-1}function
|
|
28
|
-
`){if(
|
|
29
|
-
`){e.i+=2;return}t!==void 0&&(!(e.quote||e.fragmentQuoted)||'$`"\\'.includes(t)||e.fragment&&t==="}")?(
|
|
30
|
-
`;)e.i++}function Hm(e){En(e),e.heredocs.length>0&&(e.i=Sn(e.line,e.i,e.heredocs),e.heredocs=[]);let t=e.tokens.at(-1);t&&!Dm.has(t.kind)?e.tokens.push({kind:"semi",newline:!0}):(t?.kind==="semi"||t?.kind==="amp")&&(t.lineEnd=!0),e.i++}function yr(e,t,n){let r={aliases:new Set(t),hasCommand:n};return pt(e,r),r.aliases}var $n=(e,t)=>new Set([...e,...t]);function pt(e,t){let n=null;for(let r of e){let i=r.gate==="and"||r.gate==="or";if(i&&n!==null&&r.gate==="and"!=(n===0))continue;let o=i&&n===null?new Set(t.aliases):null,s=r.stages.length===1?r.stages[0]:null;n=s&&!s.isolate?Gm(s,t):null,r.negate&&n!==null&&(n=+(n===0)),o&&(t.aliases=$n(o,t.aliases),n=null)}return n}function Gm(e,t){if(e.group)return pt(e.group,t);if(e.conditional)return Xm(e.conditional,t);if(e.loop){if(e.loop.condition&&pt(e.loop.condition,t),e.loop.words===void 0||e.loop.words.length>0){let i=new Set(t.aliases);pt(e.loop.body,t),t.aliases=$n(i,t.aliases)}return null}let n=e.words[0]?.value;if(e.redirs.length===0&&(n==="true"||n==="false"))return+(n==="false");if(!["alias","unalias"].includes(n)||t.hasCommand(n))return null;let r=e.words.slice(1).map(i=>i.value);for(;r[0]?.startsWith("-")&&r[0]!=="-";){let i=r.shift();if(i==="--")break;if(!(n==="alias"?/^-p+$/u:/^-a+$/u).test(i))return null;if(n==="unalias")return t.aliases.clear(),null}for(let i of r)if(n==="unalias")t.aliases.delete(i);else{let o=i.indexOf("="),s=i.slice(0,o);o>0&&!/[ \t\n/$`=;'"\\|&()<>]/u.test(s)&&t.aliases.add(s)}return null}function Xm(e,t){let n=new Set;for(let r of e.branches){let i=pt(r.condition,t);if(i===0)return pt(r.body,t),t.aliases=$n(n,t.aliases),null;if(i===null){let o={...t,aliases:new Set(t.aliases)};pt(r.body,o),n=$n(n,o.aliases)}}return e.otherwise&&pt(e.otherwise,t),t.aliases=$n(n,t.aliases),null}var Le=class extends Error{constructor(t){super(t.message),this.finalError=t}},ht=e=>new Le(new Error(e));function he(e,t=e.i){for(;t>=e.raw.length&&!e.done;){let n=e.read();e.raw=n.tokens,e.done=n.done}return e.raw[t]}function ma(e,t,n){let r=t.validation??new Map;return{validateSubstitution(i){r.has(i)||(Zi(i,!0,e,{validation:r,syntaxOnly:!0},n),r.set(i,!0))}}}function Zi(e,t,n,r,i){try{return i(xr(e,ma(n,r,i)),t,n,r)}catch(o){throw o instanceof Le?o.finalError:o}}function ga(e,t,n,r){let i=aa(e,ma(n,{},r)),o=new Set,s=!1;return()=>{let u={aliases:o,aliasUsed:s,read:i.read,unit:!0},a=r([],t,n,u);return s=u.aliasUsed,o=yr(a,o,n),i.reset(),{steps:a,done:u.done}}}function*wa(e,t,n,r){let i=ga(e,t,n,r);for(;;){let o;try{o=i()}catch(s){throw s instanceof Le?s.finalError:s}if(o.steps.length>0&&(yield o.steps),o.done)return}}function xa(e,t,n,r){let i=ga(e,t,n,r),o=[];for(;;){let s;try{s=i()}catch(u){let a=u instanceof Le;return{units:o,error:a?u.finalError:u,incomplete:a}}if(s.steps.length>0&&o.push(s.steps),s.done)return{units:o,error:null,incomplete:!1}}}var Zm=["elif","else","fi"];function ba(e,t){let n=[],r;do{je(e);let o=t(e,"then");je(e);let s=t(e,Zm);n.push({condition:o,body:s}),r=e.raw[e.i-1].value}while(r==="elif");let i=null;return r==="else"&&(je(e),i=t(e,"fi")),{branches:n,otherwise:i}}function va(e,t){let{raw:n}=e,r=e.loop;e.loop="for";let i=he(e);if(i?.kind==="paren_open")throw new w("feature","for ((","arithmetic `for ((\u2026))` loops are not supported; use `for NAME in WORD...`");if(i===void 0||i.kind!=="word")throw new Error("for: expected a variable name");let o=i.value;if(i.quoted||!$t.test(o))throw new Error(`for: \`${o}\` is not a valid variable name`);e.i++;let s=he(e);s?.kind==="semi"&&e.i++;let u=he(e);if(s?.kind==="semi"&&!s.newline&&Bt(u,"in"))throw new Error("for: unexpected `in` after `;`");if(!Bt(u,"in")){if(Bt(u,"do")||u===void 0){let d=new w("feature","for NAME; do",`\`for ${o}; do \u2026\` iterates the positional parameters, which this shell does not have; write \`for ${o} in WORD...\``);throw u===void 0?new Le(d):d}throw new Error(`for: expected \`in\` after \`${o}\``)}e.i++;let a=[],l=!1;for(let d;(d=he(e))&&d.kind!=="semi";e.i++){if(d.kind!=="word")throw new Error(`for: unexpected \`${kn(d)}\` in word list`);Bt(d,"do")&&(l=!0),a.push(fe(d))}n[e.i]?.kind==="semi"&&e.i++;let c=he(e);if(!Bt(c,"do"))throw c===void 0?ht(l?"for: expected `;` or newline before `do`":"for: missing `do`"):l?new Error("for: expected `;` or newline before `do`"):new Error(`for: expected \`do\`, got \`${kn(c)}\``);e.i++,je(e);let f={name:o,words:a,body:t(e,"done")};return e.loop=r,f}function ka(e,t,n){let r=e.loop;e.loop=t,je(e);let i=n(e,"do");je(e);let o={until:t==="until",condition:i,body:n(e,"done")};return e.loop=r,o}function Sa(e,t,n){if(t.quoted||!$t.test(t.value))throw new w("feature","function",`shell functions named \`${t.value}\` are not supported`);e.i+=2,je(e);let r=he(e);if(!Bt(r,"{"))throw new w("feature","function",`\`${t.value}()\` needs a \`{ \u2026 }\` body`);e.i++,je(e);let i=n(e,"}");if(!Nt(i))throw new w("feature","function",`\`${t.value}()\` is supported only while its body reads and writes no variable`);return{name:t.value,body:i}}var Nt=e=>e.every(t=>t.stages.every(Vm));function Vm(e){return e.assigns.length>0||e.define?!1:e.test?br(e.test)&&e.redirs.every(ya):e.group?Nt(e.group):e.conditional?e.conditional.branches.every(t=>Nt(t.condition)&&Nt(t.body))&&Nt(e.conditional.otherwise??[]):e.loop?(e.loop.words??[]).every(Wt)&&Nt(e.loop.condition??[])&&Nt(e.loop.body):e.words.every(Wt)&&e.redirs.every(ya)}function br(e){return e.kind==="and"||e.kind==="or"?br(e.left)&&br(e.right):e.kind==="not"?br(e.expression):e.kind==="unary"?Wt(e.word):Wt(e.left)&&Wt(e.right)}var ya=e=>e.op==="text"?!e.expand||!/[$`]/u.test(e.body):e.word===void 0||Wt(e.word);function Wt(e){for(let t=0;t<e.value.length;t++){let n=e.value[t];if((n==="$"||n==="`")&&(e.mask===null||e.mask[t]!=="1"))return!1}return!0}function je(e){for(let t;(t=he(e))?.kind==="semi"&&t.newline;)e.i++}function Bt(e,t){return e!==void 0&&e.kind==="word"&&!e.quoted&&e.value===t}var Oa=(e,t=!1,n=()=>!1,r={})=>Zi(e,t,n,r,Ji),Ca=(e,t=!1,n=()=>!1)=>wa(e,t,n,Ji),kr=(e,t=!1,n=()=>!1)=>xa(e,t,n,Ji);function Ji(e,t,n,r){let i={raw:e,i:0,done:!r.read,read:r.read,unitOnly:r.unit,emptyStage:!1,writable:t,aliases:r.aliases??new Set,aliasUsed:r.aliasUsed??!1,hasCommand:n,syntaxOnly:r.syntaxOnly};try{let o=he(i)?At(i,null):[];if(i.emptyStage)throw new Error("empty pipeline stage");return r.aliasUsed=i.aliasUsed,r.done=i.done,o}catch(o){if(i.aliasUsed&&!(o instanceof w)){let s=new w("feature","alias expansion","alias expansion is not supported; input using aliases cannot be parsed");throw o instanceof Le?new Le(s):s}throw o}}function Yi(e,t,n){t.stages.push(n),!vr(n)&&!Ki(n)&&(e.emptyStage=!0)}var Ki=e=>e.words.length>0||e.assigns.length>0||e.redirs.length>0,vr=e=>e.group||e.loop||e.conditional||e.test||e.define,Ea=()=>({words:[],assigns:[],redirs:[]}),Vi=e=>({gate:e,stages:[],negate:!1,bang:!1}),$a=(e,t)=>e.bang&&e.stages.length===0&&zt(t)&&t.redirs.length===0,zt=e=>!vr(e)&&e.words.length===0&&e.assigns.length===0,Ym=new Set(["for","while","until","do","done","if","{","}","!"]),Km=new Set(["then","else","elif","fi","esac","in"]),Na=new Map([["case","`case` statements are not supported; gate on exit status with `&&` / `||` instead"],["select","`select` loops are not supported"],["function","shell functions are not supported"],["time","`time` is not supported"],["coproc","`coproc` is not supported"]]),Jm=new Set(["alias","declare","typeset","local","readonly","export","eval","let"]),Qm=new Set(["pipe","pipe_err","and","or","semi","amp"]),Aa=new Set(["semi","amp"]);function At(e,t){let{raw:n}=e,r=[Vi("first")];t===null&&(e.unit=r[0]);let i=0,o=Ea();for(let s;s=he(e);){if(s.kind==="condition"){if(!zt(o))throw new Error("unexpected `[[`");o.test=s.expression,e.i++;continue}if(s.kind==="paren_close"){if(t!==")")throw new Error("unexpected `)`");return e.i++,Ia(e,r,o,t)}if(s.kind==="paren_open"){eg(e,o);continue}if(Qm.has(s.kind)){if(s.kind==="pipe_err"&&(Ki(o)||vr(o))&&o.redirs.push({fd:2,op:"dup",toFd:1}),s.kind==="semi"&&$a(r.at(-1),o)||Yi(e,r.at(-1),o),s.kind==="amp"&&(r.at(-1).background=!0),o=Ea(),s.kind==="and"||s.kind==="or"?r.push(Vi(s.kind)):Aa.has(s.kind)&&r.push(Vi("seq")),t===null&&(s.newline||s.lineEnd)){if(e.unitOnly)return e.i++,r.pop(),r;e.aliases=yr(r.slice(i,-1),e.aliases,e.hasCommand),i=r.length-1,e.unit=r.at(-1)}e.i++;continue}if(s.kind==="dsemi")throw new Error("syntax error near unexpected token `;;`");if(s.kind==="redir"){if(s.warning&&(e.unit.warnings=(e.unit.warnings??"")+s.warning),o.define)throw new w("feature","function",`\`${o.define.name}()\` with a redirect of its own is not supported`);let a=og(e);a&&o.redirs.push(a);continue}if(o.group||o.define)throw new Error(`unexpected token after \`${o.isolate?")":"}"}\``);if(o.loop)throw new Error("unexpected token after `done`");if(o.conditional)throw new Error("unexpected token after `fi`");if(o.test)throw new Error("unexpected token after `]]`");if(!s.quoted&&o.words.length===0&&e.aliases.has(s.value)&&(e.aliasUsed=!0),!s.quoted&&zt(o)){if(Array.isArray(t)?t.includes(s.value):s.value===t)return e.i++,Ia(e,r,o,t);if(tg(s,e,r.at(-1),o))continue}let u=o.words.length===0?bn(s):null;u===null?o.words.push(fe(s)):o.assigns.push({name:u.name,word:fe(s,u.end)}),e.i++}if(t===")")throw ht("unmatched `(`");if(t==="}")throw ht("unmatched `{`");if(t==="do"||t==="done")throw ht(`${e.loop}: missing \`${t}\``);if(t)throw ht(`if: missing \`${t==="then"?"then":"fi"}\``);if(!e.emptyStage&&!vr(o)&&!Ki(o)&&["and","or","pipe","pipe_err"].includes(n.at(-1)?.kind))throw ht("empty pipeline stage");return Aa.has(n.at(-1)?.kind)?r.pop():$a(r.at(-1),o)||Yi(e,r.at(-1),o),r}function eg(e,t){let{raw:n,i:r}=e,i=he(e,r+1),o=n[r-1],s=t.words[0],u=t.words.at(-1);if(!(n[r-2]?.kind==="redir"&&!["dup","close"].includes(n[r-2].op))&&(t.words.length===0&&t.assigns.length>0||u&&u.value===o?.value&&(t.words.length===1||s.mask===null&&Jm.has(s.value)))&&n[r].wordAdjacent&&o?.kind==="word"&&!o.quoted&&/^[A-Za-z_][A-Za-z0-9_]*\+?=$/u.test(o.value))throw new w("feature","array assignment","shell array assignments are not supported");if(i?.kind==="paren_open"&&i.adjacent&&zt(t))throw new w("feature","((","arithmetic evaluation (`((\u2026))`) is not supported");if(t.words.length===1&&t.assigns.length===0&&t.redirs.length===0&&i?.kind==="paren_close"){t.define=Sa(e,t.words.pop(),At);return}if(!zt(t))throw new Error("unexpected `(`");e.i++,t.group=At(e,")"),t.isolate=!0}function tg(e,t,n,r){let i=e.value;if(Na.has(i))throw new w("feature",i,Na.get(i));if(Km.has(i))throw new Error(`syntax error near unexpected token \`${i}\``);if(!Ym.has(i))return!1;if(t.i++,i==="!"){if(n.stages.length>0||r.redirs.length>0)throw new Error("syntax error near unexpected token `!`");return n.negate=!n.negate,n.bang=!0,!0}if(i==="{")return je(t),r.group=At(t,"}"),r.isolate=!1,!0;if(i==="}")throw new Error("syntax error near unexpected token `}`");if(i==="done")throw new Error("unexpected `done`");if(i==="do")throw new Error("unexpected `do`");return i==="if"?r.conditional=ba(t,At):r.loop=i==="for"?va(t,At):ka(t,i,At),!0}var ng={")":"empty subshell `()`","}":"empty group `{ }`"},rg=(e,t)=>t==="do"?`${e.loop}: empty condition`:t==="done"?`${e.loop}: empty loop body`:t==="then"?"if: empty condition":"if: empty branch body";function Ia(e,t,n,r){let i=t.at(-1),o=zt(n)&&n.redirs.length===0&&i.stages.length===0;if(o&&t.length===1)throw new Error(ng[r]??rg(e,r));if(o&&i.bang)throw new Error("syntax error near unexpected token after `!`");return o&&i.gate==="seq"?t.pop():Yi(e,i,n),t}var ig=new Set(["/dev/null","/dev/stdout","/dev/stderr"]);function og(e){let t=e.raw[e.i++],n=kn(t);if(e.syntaxOnly){if(!["dup","close"].includes(t.op)){let u=he(e,e.i++);if(!u||u.kind!=="word")throw new Error(`redirect \`${n}\` requires a target`)}return t}if(t.fd>2)throw new w("feature",n,`only file descriptors 0, 1 and 2 are supported (got \`${n}\`)`);if(t.op==="dup"){if(t.fd===0&&t.toFd===0)return null;if(t.fd===0||t.toFd===0)throw new w("feature",n,`duplicating file descriptor 0 (\`${n}\`) is not supported`);return{fd:t.fd,op:"dup",toFd:t.toFd}}if(t.op==="close"){if(t.fd===0)throw new w("feature","0<&-","closing standard input is not supported");return{fd:t.fd,op:"close"}}let r=he(e,e.i++);if(!r||r.kind!=="word")throw new Error(`redirect \`${n}\` requires a target`);if(t.op==="heredoc"||t.op==="herestring"||t.op==="read"){if(t.fd!==0)throw new w("feature",n,`reading into file descriptor ${t.fd} (\`${n}\`) is not supported`);return t.op==="heredoc"?{fd:0,op:"text",body:t.body??"",expand:!t.quotedDelim}:{fd:0,op:t.op,word:fe(r)}}if(t.fd===0)throw new w("feature",n,`writing to file descriptor 0 (\`${n}\`) is not supported`);let i=t.op==="both"||t.op==="bothAppend",o=t.op==="append"||t.op==="bothAppend",s=fe(r);if(sg(s))return{fd:t.fd,op:"to",word:s,both:i,append:o,label:n};if(!e.writable&&!ig.has(s.value))throw Qi(n,s.value,e.writable);return{fd:t.fd,op:"to",target:s.value,both:i,append:o,label:n}}function sg(e){for(let t=0;t<e.value.length;t++){let n=e.value[t],r=e.mask===null?"0":e.mask[t];if((n==="$"||n==="`")&&r!=="1"||r==="0"&&(/[~*?[{]/u.test(n)||(n==="<"||n===">")&&e.value[t+1]==="("))return!0}return!1}function Qi(e,t,n){let r=n?"only `/tmp/` is writable":"the filesystem is read-only";return new w("feature",e,`\`${e}\` cannot write to \`${t}\`: ${r}`)}var ug=/^[a-zA-Z0-9][\w.+-]*$/u,eo=["run","pipe","hidden"],to=["stdout","stderr","exitCode"];function Fa(e,t){let n={__proto__:null},r=[],i=[];for(let[o,s]of ag(e)){let{run:u,pipe:a,hidden:l}=lg(o,s,t);l&&r.includes(o)||(n[o]=(c,f,d)=>cg(o,u,c,f,d),!l&&(r.push(o),a&&i.push(o)))}return{handlers:n,names:r,pipeNames:i}}function ag(e){if(e==null)return[];if(Array.isArray(e))throw new TypeError("createTerminal: opts.commands must be an object or a Map (got an array)");if(typeof e!="object")throw new TypeError(`createTerminal: opts.commands must be an object or a Map (got ${typeof e})`);if(typeof e.entries=="function")return[...e.entries()];let t=Object.getPrototypeOf(e);if(t!==Object.prototype&&t!==null)throw new TypeError("createTerminal: opts.commands must be a plain object or a Map (own enumerable properties only)");return Object.entries(e)}function lg(e,t,n){if(typeof e!="string")throw new TypeError(`createTerminal: command names must be strings (got ${typeof e})`);if(!ug.test(e))throw new Error(`createTerminal: invalid command name: ${JSON.stringify(e)}`);if(n(e))throw new Error(`createTerminal: ${e}: cannot redefine a built-in command`);if(typeof t=="function"){for(let i of Object.keys(t))if(eo.includes(i))throw new Error(`createTerminal: ${e}: \`${i}\` belongs on a { run } descriptor, not on the handler function`);return{run:t,pipe:!1,hidden:!1}}if(t===null||typeof t!="object")throw new TypeError(`createTerminal: ${e}: expected a function or a { run } object`);let r=t.run;if(typeof r!="function")throw new TypeError(`createTerminal: ${e}: \`run\` must be a function`);for(let i of Object.keys(t))if(!eo.includes(i))throw new Error(`createTerminal: ${e}: unknown option \`${i}\` (known: ${eo.join(", ")})`);return{run:r,pipe:!!t.pipe,hidden:!!t.hidden}}function cg(e,t,n,r,i){i.io?.bufferOutput(),z(i);let o={cwd:i.cwd,fs:i.fs,mount:i.mount,home:i.home,get notes(){return i.notes},command:e,stdinFile:i.stdinFile,stdinOrigin:i.stdinOrigin},s={name:e,args:r,stdin:n,cwd:o.cwd,fs:fg(o),readInputs:(u=[])=>{if(typeof u=="string")throw new TypeError(`readInputs: expected an array of paths, got a string: ${u}`);return te(e,[...u],n,o)}};return dg(t(s))}function fg(e){let t=n=>$(e.cwd,n,e.fs).path;return{resolve:n=>L(e.cwd,n),isFile:n=>e.fs.isFile(t(n)),isDir:n=>e.fs.isDir(t(n)),readFile:n=>e.fs.readFile(t(n)),listDir:n=>{let{path:r,error:i}=P(e,e.command,n);if(!e.fs.isDir(r))throw new Error(`${n}: ${i??"Not a directory"}`);let{dirs:o,files:s}=e.fs.listDir(r);return{dirs:[...o],files:[...s]}},walkFiles:n=>[...e.fs.walkFiles(t(n))]}}function dg(e){if(e==null)return C();if(typeof e=="string")return C(e);if(typeof e!="object")throw new TypeError(`invalid result: expected a string or an object (got ${typeof e})`);if(typeof e.then=="function")throw new TypeError("invalid result: commands are synchronous, a promise cannot be awaited");if(Array.isArray(e))throw new TypeError("invalid result: expected a string or an object, got an array (join the lines first)");let t=Object.keys(e);for(let o of t)if(!to.includes(o))throw new TypeError(`invalid result: unknown field \`${o}\` (known: ${to.join(", ")})`);if(t.length===0)throw new TypeError(`invalid result: an object with none of ${to.join(", ")} \u2014 return a string for plain output`);let{stdout:n="",stderr:r="",exitCode:i=0}=e;if(typeof n!="string")throw new TypeError(`invalid result: stdout must be a string (got ${typeof n})`);if(typeof r!="string")throw new TypeError(`invalid result: stderr must be a string (got ${typeof r})`);if(!Number.isInteger(i)||i<0)throw new TypeError(`invalid result: exitCode must be a non-negative integer (got ${i})`);return{stdout:n,stderr:r===""||r.endsWith(`
|
|
27
|
+
`)}return r-1}function s0(e){let t=0;for(;t<e.length&&e[e.length-1-t]==="\\";)t++;return t%2===1}var u0=new Set(["semi","amp","and","or","pipe","pipe_err","paren_open"]),a0=e=>e===" "||e===" ";function _r(e,t={}){return al(yo(e,t),!1).tokens}function ul(e,t={}){let n=yo(e,t);return{read:()=>al(n,!0),reset:()=>{n.tokens=[]}}}function al(e,t){for(;e.i<e.line.length;){let n=e.line[e.i];if(e.quote&&n===e.quote){ll(e),e.i++;continue}if(e.quote==="'"){le(e,n,"1"),e.i++;continue}if(n==="\\"){fl(e);continue}if(n==="$"){dl(e);continue}if(n==="`"){pl(e);continue}if(e.quote){le(e,n,"2"),e.i++;continue}if(n==="'"||n==='"'){ko(e,n),e.i++;continue}let r=e.cur!==""||e.empty.length>0;if(!r&&e.line.startsWith("[[",e.i)&&/[ \t\n()<>;&|]|^$/u.test(e.line[e.i+2]??"")&&c0(e.tokens)){let o=An(e.line,e.i,{readExpansion:e.readExpansion,decodeAnsiC:Vt});sl(e,{kind:"condition",expression:o.expression}),e.i+=o.raw.length;continue}if(n==="#"&&!r){p0(e);continue}if(n===`
|
|
28
|
+
`){if(h0(e),t)return{tokens:e.tokens,done:e.i>=e.line.length};continue}if(a0(n)){Cn(e),e.i++;continue}if(n==="("&&e.mask.at(-1)==="0"&&/[?*+@!]/u.test(e.cur.at(-1))&&!e.empty.includes(e.cur.length))throw new w("feature","extglob","extended glob patterns are not supported");if((n==="<"||n===">")&&e.line[ue(e.line,e.i+1)]==="("){d0(e);continue}let i=Tr(e.line,e.i,!r);if(i?.token.kind==="paren_open"&&(i.token.wordAdjacent=r),i){Cn(e),sl(e,i.token),e.i=i.end;continue}le(e,n,"0"),e.i++}if(e.quote)throw new Error(`unterminated ${e.quote==="'"?"single":"double"} quote`);return Cn(e),e.heredocs.length>0&&In(e.line,e.line.length,e.heredocs),{tokens:e.tokens,done:!0}}function yo(e,t={}){return{line:e,i:0,tokens:[],cur:"",mask:"",empty:[],quoted:!1,quoteStart:0,quote:null,heredocs:[],lastParenAt:-2,readExpansion:(n,r,i=0,o=!1)=>ut(n,r,i,o,t),readProcess:(n,r)=>ol(n,r,t)}}function xo(e,t=!1){let n={...yo(e),fragment:!0,fragmentQuoted:t};for(;n.i<n.line.length;){let r=n.line[n.i];if(n.quote&&r===n.quote){ll(n),n.i++;continue}if(n.quote==="'"){le(n,r,"1"),n.i++;continue}if(r==="\\"){fl(n);continue}if(r==="$"){dl(n);continue}if(r==="`"){pl(n);continue}if(n.quote){le(n,r,"2"),n.i++;continue}if(r==='"'||r==="'"&&!t){ko(n,r),n.i++;continue}if(!t&&(r==="<"||r===">")&&n.line[ue(n.line,n.i+1)]==="(")throw new w("feature",`${r}(`,"process substitution in parameter operands is not supported");le(n,r,t?"2":"0"),n.i++}if(n.quote)throw new w("feature","${","unterminated quote in parameter operand");return Cn(n),n.tokens[0]??{value:"",mask:t?"":null}}var l0=new Set(["semi","and","or","pipe","pipe_err","amp","paren_open"]),f0=new Set(["!","{","if","then","else","elif","while","until","do"]);function c0(e){let t=!0,n=null,r=!1;for(let i of e){let o=l0.has(i.kind)||i.kind==="paren_close"&&n?.kind==="paren_open";if(n=i,o){t=!0,r=!1;continue}if(i.kind==="redir"){t=!1,r=!["dup","close"].includes(i.op);continue}if(r){r=!1;continue}(!t||i.kind!=="word"||i.quoted||!f0.has(i.value))&&(t=!1)}return t&&!r}function ko(e,t){e.quoteStart=e.cur.length,e.quote=t}function ll(e){e.cur.length===e.quoteStart&&e.empty.push(e.cur.length),e.quote=null}function le(e,t,n,r=n!=="0"){e.cur+=t,e.mask+=n.repeat(t.length),e.quoted||=r}function Cn(e){if(e.cur!==""||e.empty.length>0){let t=e.empty.length>0||e.quoted,n={kind:"word",value:e.cur,mask:/[12]/u.test(e.mask)||t?e.mask:null,quoted:t,...e.empty.length?{empty:e.empty}:{}};e.tokens.push(n);let r=e.heredocs.find(i=>i.delim===null);r&&(r.delim=n.value,r.quotedDelim=t)}e.cur="",e.mask="",e.empty=[],e.quoted=!1}function sl(e,t){t.kind==="paren_open"&&(t.adjacent=ue(e.line,e.lastParenAt+1)===e.i,e.lastParenAt=e.i),t.kind==="redir"&&t.op==="heredoc"&&e.heredocs.push(t),e.tokens.push(t)}function fl(e){let t=e.line[e.i+1];if(t===`
|
|
29
|
+
`){e.i+=2;return}t!==void 0&&(!(e.quote||e.fragmentQuoted)||'$`"\\'.includes(t)||e.fragment&&t==="}")?(le(e,t,"1"),e.i+=2):(le(e,"\\",e.quote||e.fragmentQuoted?"2":"1"),e.i++)}function cl(e,t){let n=ue(e.line,t);n!==t&&(e.line=e.line.slice(0,t)+e.line.slice(n))}function dl(e){cl(e,e.i+1);let{line:t}=e,n=e.quote==='"'||e.fragmentQuoted?"2":"0",r=t[e.i+1];if((n==="0"||e.fragmentQuoted&&!e.quote)&&r==="'"){let u=Vt(t,e.i+2);if(e.fragmentQuoted&&/[$`"\\]/u.test(u.text))throw new w("feature","${","active characters in ANSI-C quoted parameter operands are not supported");u.text===""&&e.empty.push(e.cur.length),le(e,u.text,"1"),e.i=u.end;return}if((n==="0"||e.fragmentQuoted&&!e.quote)&&r==='"'){ko(e,'"'),e.i+=2;return}let i=e.readExpansion(t,e.i,0,n==="2");if(!i){le(e,"$","1"),e.i++;return}if(i.command!==void 0||i.parameter!==void 0||i.arithmetic!==void 0){le(e,"$",n),le(e,i.raw.slice(1),"1",!1),e.i+=i.raw.length;return}let o=t[e.i+i.raw.length],s=Ft.test(i.name)&&(o==='"'||o==="'")?"${"+i.name+"}":i.raw;le(e,s,n),e.i+=i.raw.length}function d0(e){cl(e,e.i+1);let{raw:t}=e.readProcess(e.line,e.i);le(e,e.line[e.i],"0"),le(e,t.slice(1),"1",!1),e.i+=t.length}function pl(e){let t=e.quote==='"'||e.fragmentQuoted?"2":"0",{raw:n}=ot(e.line,e.i);le(e,"`",t),le(e,n.slice(1),"1",!1),e.i+=n.length}function p0(e){for(;e.i<e.line.length&&e.line[e.i]!==`
|
|
30
|
+
`;)e.i++}function h0(e){Cn(e),e.heredocs.length>0&&(e.i=In(e.line,e.i,e.heredocs),e.heredocs=[]);let t=e.tokens.at(-1);t&&!u0.has(t.kind)?e.tokens.push({kind:"semi",newline:!0}):(t?.kind==="semi"||t?.kind==="amp")&&(t.lineEnd=!0),e.i++}function Lr(e,t,n){let r={aliases:new Set(t),hasCommand:n};return xt(e,r),r.aliases}var Fn=(e,t)=>new Set([...e,...t]);function xt(e,t){let n=null;for(let r of e){let i=r.gate==="and"||r.gate==="or";if(i&&n!==null&&r.gate==="and"!=(n===0))continue;let o=i&&n===null?new Set(t.aliases):null,s=r.stages.length===1?r.stages[0]:null;n=s&&!s.isolate?m0(s,t):null,r.negate&&n!==null&&(n=+(n===0)),o&&(t.aliases=Fn(o,t.aliases),n=null)}return n}function m0(e,t){if(e.group)return xt(e.group,t);if(e.conditional)return g0(e.conditional,t);if(e.loop){if(e.loop.condition&&xt(e.loop.condition,t),e.loop.words===void 0||e.loop.words.length>0){let i=new Set(t.aliases);xt(e.loop.body,t),t.aliases=Fn(i,t.aliases)}return null}let n=e.words[0]?.value;if(e.redirs.length===0&&(n==="true"||n==="false"))return+(n==="false");if(!["alias","unalias"].includes(n)||t.hasCommand(n))return null;let r=e.words.slice(1).map(i=>i.value);for(;r[0]?.startsWith("-")&&r[0]!=="-";){let i=r.shift();if(i==="--")break;if(!(n==="alias"?/^-p+$/u:/^-a+$/u).test(i))return null;if(n==="unalias")return t.aliases.clear(),null}for(let i of r)if(n==="unalias")t.aliases.delete(i);else{let o=i.indexOf("="),s=i.slice(0,o);o>0&&!/[ \t\n/$`=;'"\\|&()<>]/u.test(s)&&t.aliases.add(s)}return null}function g0(e,t){let n=new Set;for(let r of e.branches){let i=xt(r.condition,t);if(i===0)return xt(r.body,t),t.aliases=Fn(n,t.aliases),null;if(i===null){let o={...t,aliases:new Set(t.aliases)};xt(r.body,o),n=Fn(n,o.aliases)}}return e.otherwise&&xt(e.otherwise,t),t.aliases=Fn(n,t.aliases),null}var Ye=class extends Error{constructor(t){super(t.message),this.finalError=t}},kt=e=>new Ye(new Error(e));function ye(e,t=e.i){for(;t>=e.raw.length&&!e.done;){let n=e.read();e.raw=n.tokens,e.done=n.done}return e.raw[t]}function hl(e,t,n){let r=t.validation??new Map;return{validateSubstitution(i){r.has(i)||(vo(i,!0,e,{validation:r,syntaxOnly:!0},n),r.set(i,!0))}}}function vo(e,t,n,r,i){try{return i(_r(e,hl(n,r,i)),t,n,r)}catch(o){throw o instanceof Ye?o.finalError:o}}function w0(e,t,n,r){let i=ul(e,hl(n,{},r)),o=new Set,s=!1;return()=>{let u={aliases:o,aliasUsed:s,read:i.read,unit:!0},a=r([],t,n,u);return s=u.aliasUsed,o=Lr(a,o,n),i.reset(),{steps:a,done:u.done}}}function*ml(e,t,n,r){let i=w0(e,t,n,r);for(;;){let o;try{o=i()}catch(s){throw s instanceof Ye?s.finalError:s}if(o.steps.length>0&&(yield o.steps),o.done)return}}var b0=["elif","else","fi"];function wl(e,t){let n=[],r;do{Ve(e);let o=t(e,"then");Ve(e);let s=t(e,b0);n.push({condition:o,body:s}),r=e.raw[e.i-1].value}while(r==="elif");let i=null;return r==="else"&&(Ve(e),i=t(e,"fi")),{branches:n,otherwise:i}}function bl(e,t){let{raw:n}=e,r=e.loop;e.loop="for";let i=ye(e);if(i?.kind==="paren_open")throw new w("feature","for ((","arithmetic `for ((\u2026))` loops are not supported; use `for NAME in WORD...`");if(i===void 0||i.kind!=="word")throw new Error("for: expected a variable name");let o=i.value;if(i.quoted||!Ft.test(o))throw new Error(`for: \`${o}\` is not a valid variable name`);e.i++;let s=ye(e);s?.kind==="semi"&&e.i++;let u=ye(e);if(s?.kind==="semi"&&!s.newline&&Kt(u,"in"))throw new Error("for: unexpected `in` after `;`");if(!Kt(u,"in")){if(Kt(u,"do")||u===void 0){let d=new w("feature","for NAME; do",`\`for ${o}; do \u2026\` iterates the positional parameters, which this shell does not have; write \`for ${o} in WORD...\``);throw u===void 0?new Ye(d):d}throw new Error(`for: expected \`in\` after \`${o}\``)}e.i++;let a=[],l=!1;for(let d;(d=ye(e))&&d.kind!=="semi";e.i++){if(d.kind!=="word")throw new Error(`for: unexpected \`${On(d)}\` in word list`);Kt(d,"do")&&(l=!0),a.push(be(d))}n[e.i]?.kind==="semi"&&e.i++;let f=ye(e);if(!Kt(f,"do"))throw f===void 0?kt(l?"for: expected `;` or newline before `do`":"for: missing `do`"):l?new Error("for: expected `;` or newline before `do`"):new Error(`for: expected \`do\`, got \`${On(f)}\``);e.i++,Ve(e);let c={name:o,words:a,body:t(e,"done")};return e.loop=r,c}function yl(e,t,n){let r=e.loop;e.loop=t,Ve(e);let i=n(e,"do");Ve(e);let o={until:t==="until",condition:i,body:n(e,"done")};return e.loop=r,o}function xl(e,t,n){if(t.quoted||!Ft.test(t.value))throw new w("feature","function",`shell functions named \`${t.value}\` are not supported`);e.i+=2,Ve(e);let r=ye(e);if(!Kt(r,"{"))throw new w("feature","function",`\`${t.value}()\` needs a \`{ \u2026 }\` body`);e.i++,Ve(e);let i=n(e,"}");if(!Tt(i))throw new w("feature","function",`\`${t.value}()\` is supported only while its body reads and writes no variable`);return{name:t.value,body:i}}var Tt=e=>e.every(t=>t.stages.every(y0));function y0(e){return e.assigns.length>0||e.define?!1:e.test?Rr(e.test)&&e.redirs.every(gl):e.group?Tt(e.group):e.conditional?e.conditional.branches.every(t=>Tt(t.condition)&&Tt(t.body))&&Tt(e.conditional.otherwise??[]):e.loop?(e.loop.words??[]).every(Jt)&&Tt(e.loop.condition??[])&&Tt(e.loop.body):e.words.every(Jt)&&e.redirs.every(gl)}function Rr(e){return e.kind==="and"||e.kind==="or"?Rr(e.left)&&Rr(e.right):e.kind==="not"?Rr(e.expression):e.kind==="unary"?Jt(e.word):Jt(e.left)&&Jt(e.right)}var gl=e=>e.op==="text"?!e.expand||!/[$`]/u.test(e.body):e.word===void 0||Jt(e.word);function Jt(e){for(let t=0;t<e.value.length;t++){let n=e.value[t];if((n==="$"||n==="`")&&(e.mask===null||e.mask[t]!=="1"))return!1}return!0}function Ve(e){for(let t;(t=ye(e))?.kind==="semi"&&t.newline;)e.i++}function Kt(e,t){return e!==void 0&&e.kind==="word"&&!e.quoted&&e.value===t}var Nl=(e,t=!1,n=()=>!1,r={})=>vo(e,t,n,r,Ol),Al=(e,t=!1,n=()=>!1)=>ml(e,t,n,Ol);function Ol(e,t,n,r){let i={raw:e,i:0,done:!r.read,read:r.read,unitOnly:r.unit,emptyStage:!1,writable:t,aliases:r.aliases??new Set,aliasUsed:r.aliasUsed??!1,hasCommand:n,syntaxOnly:r.syntaxOnly};try{let o=ye(i)?_t(i,null):[];if(i.emptyStage)throw new Error("empty pipeline stage");return r.aliasUsed=i.aliasUsed,r.done=i.done,o}catch(o){if(i.aliasUsed&&!(o instanceof w)){let s=new w("feature","alias expansion","alias expansion is not supported; input using aliases cannot be parsed");throw o instanceof Ye?new Ye(s):s}throw o}}function $o(e,t,n){t.stages.push(n),!Mr(n)&&!Eo(n)&&(e.emptyStage=!0)}var Eo=e=>e.words.length>0||e.assigns.length>0||e.redirs.length>0,Mr=e=>e.group||e.loop||e.conditional||e.test||e.define,kl=()=>({words:[],assigns:[],redirs:[]}),So=e=>({gate:e,stages:[],negate:!1,bang:!1}),vl=(e,t)=>e.bang&&e.stages.length===0&&Qt(t)&&t.redirs.length===0,Qt=e=>!Mr(e)&&e.words.length===0&&e.assigns.length===0,x0=new Set(["for","while","until","do","done","if","{","}","!"]),k0=new Set(["then","else","elif","fi","esac","in"]),Sl=new Map([["case","`case` statements are not supported; gate on exit status with `&&` / `||` instead"],["select","`select` loops are not supported"],["function","shell functions are not supported"],["time","`time` is not supported"],["coproc","`coproc` is not supported"]]),v0=new Set(["alias","declare","typeset","local","readonly","export","eval","let"]),S0=new Set(["pipe","pipe_err","and","or","semi","amp"]),$l=new Set(["semi","amp"]);function _t(e,t){let{raw:n}=e,r=[So("first")];t===null&&(e.unit=r[0]);let i=0,o=kl();for(let s;s=ye(e);){if(s.kind==="condition"){if(!Qt(o))throw new Error("unexpected `[[`");o.test=s.expression,e.i++;continue}if(s.kind==="paren_close"){if(t!==")")throw new Error("unexpected `)`");return e.i++,El(e,r,o,t)}if(s.kind==="paren_open"){$0(e,o);continue}if(S0.has(s.kind)){if(s.kind==="pipe_err"&&(Eo(o)||Mr(o))&&o.redirs.push({fd:2,op:"dup",toFd:1}),s.kind==="semi"&&vl(r.at(-1),o)||$o(e,r.at(-1),o),s.kind==="amp"&&(r.at(-1).background=!0),o=kl(),s.kind==="and"||s.kind==="or"?r.push(So(s.kind)):$l.has(s.kind)&&r.push(So("seq")),t===null&&(s.newline||s.lineEnd)){if(e.unitOnly)return e.i++,r.pop(),r;e.aliases=Lr(r.slice(i,-1),e.aliases,e.hasCommand),i=r.length-1,e.unit=r.at(-1)}e.i++;continue}if(s.kind==="dsemi")throw new Error("syntax error near unexpected token `;;`");if(s.kind==="redir"){if(s.warning&&(e.unit.warnings=(e.unit.warnings??"")+s.warning),o.define)throw new w("feature","function",`\`${o.define.name}()\` with a redirect of its own is not supported`);let a=I0(e);a&&o.redirs.push(a);continue}if(o.group||o.define)throw new Error(`unexpected token after \`${o.isolate?")":"}"}\``);if(o.loop)throw new Error("unexpected token after `done`");if(o.conditional)throw new Error("unexpected token after `fi`");if(o.test)throw new Error("unexpected token after `]]`");if(!s.quoted&&o.words.length===0&&e.aliases.has(s.value)&&(e.aliasUsed=!0),!s.quoted&&Qt(o)){if(Array.isArray(t)?t.includes(s.value):s.value===t)return e.i++,El(e,r,o,t);if(E0(s,e,r.at(-1),o))continue}let u=o.words.length===0?Nn(s):null;u===null?o.words.push(be(s)):o.assigns.push({name:u.name,word:be(s,u.end)}),e.i++}if(t===")")throw kt("unmatched `(`");if(t==="}")throw kt("unmatched `{`");if(t==="do"||t==="done")throw kt(`${e.loop}: missing \`${t}\``);if(t)throw kt(`if: missing \`${t==="then"?"then":"fi"}\``);if(!e.emptyStage&&!Mr(o)&&!Eo(o)&&["and","or","pipe","pipe_err"].includes(n.at(-1)?.kind))throw kt("empty pipeline stage");return $l.has(n.at(-1)?.kind)?r.pop():vl(r.at(-1),o)||$o(e,r.at(-1),o),r}function $0(e,t){let{raw:n,i:r}=e,i=ye(e,r+1),o=n[r-1],s=t.words[0],u=t.words.at(-1);if(!(n[r-2]?.kind==="redir"&&!["dup","close"].includes(n[r-2].op))&&(t.words.length===0&&t.assigns.length>0||u&&u.value===o?.value&&(t.words.length===1||s.mask===null&&v0.has(s.value)))&&n[r].wordAdjacent&&o?.kind==="word"&&!o.quoted&&/^[A-Za-z_][A-Za-z0-9_]*\+?=$/u.test(o.value))throw new w("feature","array assignment","shell array assignments are not supported");if(i?.kind==="paren_open"&&i.adjacent&&Qt(t))throw new w("feature","((","arithmetic evaluation (`((\u2026))`) is not supported");if(t.words.length===1&&t.assigns.length===0&&t.redirs.length===0&&i?.kind==="paren_close"){t.define=xl(e,t.words.pop(),_t);return}if(!Qt(t))throw new Error("unexpected `(`");e.i++,t.group=_t(e,")"),t.isolate=!0}function E0(e,t,n,r){let i=e.value;if(Sl.has(i))throw new w("feature",i,Sl.get(i));if(k0.has(i))throw new Error(`syntax error near unexpected token \`${i}\``);if(!x0.has(i))return!1;if(t.i++,i==="!"){if(n.stages.length>0||r.redirs.length>0)throw new Error("syntax error near unexpected token `!`");return n.negate=!n.negate,n.bang=!0,!0}if(i==="{")return Ve(t),r.group=_t(t,"}"),r.isolate=!1,!0;if(i==="}")throw new Error("syntax error near unexpected token `}`");if(i==="done")throw new Error("unexpected `done`");if(i==="do")throw new Error("unexpected `do`");return i==="if"?r.conditional=wl(t,_t):r.loop=i==="for"?bl(t,_t):yl(t,i,_t),!0}var N0={")":"empty subshell `()`","}":"empty group `{ }`"},A0=(e,t)=>t==="do"?`${e.loop}: empty condition`:t==="done"?`${e.loop}: empty loop body`:t==="then"?"if: empty condition":"if: empty branch body";function El(e,t,n,r){let i=t.at(-1),o=Qt(n)&&n.redirs.length===0&&i.stages.length===0;if(o&&t.length===1)throw new Error(N0[r]??A0(e,r));if(o&&i.bang)throw new Error("syntax error near unexpected token after `!`");return o&&i.gate==="seq"?t.pop():$o(e,i,n),t}var O0=new Set(["/dev/null","/dev/stdout","/dev/stderr"]);function I0(e){let t=e.raw[e.i++],n=On(t);if(e.syntaxOnly){if(!["dup","close"].includes(t.op)){let u=ye(e,e.i++);if(!u||u.kind!=="word")throw new Error(`redirect \`${n}\` requires a target`)}return t}if(t.fd>2)throw new w("feature",n,`only file descriptors 0, 1 and 2 are supported (got \`${n}\`)`);if(t.op==="dup"){if(t.fd===0&&t.toFd===0)return null;if(t.fd===0||t.toFd===0)throw new w("feature",n,`duplicating file descriptor 0 (\`${n}\`) is not supported`);return{fd:t.fd,op:"dup",toFd:t.toFd}}if(t.op==="close"){if(t.fd===0)throw new w("feature","0<&-","closing standard input is not supported");return{fd:t.fd,op:"close"}}let r=ye(e,e.i++);if(!r||r.kind!=="word")throw new Error(`redirect \`${n}\` requires a target`);if(t.op==="heredoc"||t.op==="herestring"||t.op==="read"){if(t.fd!==0)throw new w("feature",n,`reading into file descriptor ${t.fd} (\`${n}\`) is not supported`);return t.op==="heredoc"?{fd:0,op:"text",body:t.body??"",expand:!t.quotedDelim}:{fd:0,op:t.op,word:be(r)}}if(t.fd===0)throw new w("feature",n,`writing to file descriptor 0 (\`${n}\`) is not supported`);let i=t.op==="both"||t.op==="bothAppend",o=t.op==="append"||t.op==="bothAppend",s=be(r);if(C0(s))return{fd:t.fd,op:"to",word:s,both:i,append:o,label:n};if(!e.writable&&!O0.has(s.value))throw No(n,s.value,e.writable);return{fd:t.fd,op:"to",target:s.value,both:i,append:o,label:n}}function C0(e){for(let t=0;t<e.value.length;t++){let n=e.value[t],r=e.mask===null?"0":e.mask[t];if((n==="$"||n==="`")&&r!=="1"||r==="0"&&(/[~*?[{]/u.test(n)||(n==="<"||n===">")&&e.value[t+1]==="("))return!0}return!1}function No(e,t,n){let r=n?"only `/tmp/` is writable":"the filesystem is read-only";return new w("feature",e,`\`${e}\` cannot write to \`${t}\`: ${r}`)}var F0=/^[a-zA-Z0-9][\w.+-]*$/u,Ao=["run","pipe","hidden"],Oo=["stdout","stderr","exitCode"];function Cl(e,t){let n={__proto__:null},r=[],i=[];for(let[o,s]of T0(e)){let{run:u,pipe:a,hidden:l}=_0(o,s,t);l&&r.includes(o)||(n[o]=(f,c,d)=>L0(o,u,f,c,d),!l&&(r.push(o),a&&i.push(o)))}return{handlers:n,names:r,pipeNames:i}}function T0(e){if(e==null)return[];if(Array.isArray(e))throw new TypeError("createTerminal: opts.commands must be an object or a Map (got an array)");if(typeof e!="object")throw new TypeError(`createTerminal: opts.commands must be an object or a Map (got ${typeof e})`);if(typeof e.entries=="function")return[...e.entries()];let t=Object.getPrototypeOf(e);if(t!==Object.prototype&&t!==null)throw new TypeError("createTerminal: opts.commands must be a plain object or a Map (own enumerable properties only)");return Object.entries(e)}function _0(e,t,n){if(typeof e!="string")throw new TypeError(`createTerminal: command names must be strings (got ${typeof e})`);if(!F0.test(e))throw new Error(`createTerminal: invalid command name: ${JSON.stringify(e)}`);if(n(e))throw new Error(`createTerminal: ${e}: cannot redefine a built-in command`);if(typeof t=="function"){for(let i of Object.keys(t))if(Ao.includes(i))throw new Error(`createTerminal: ${e}: \`${i}\` belongs on a { run } descriptor, not on the handler function`);return{run:t,pipe:!1,hidden:!1}}if(t===null||typeof t!="object")throw new TypeError(`createTerminal: ${e}: expected a function or a { run } object`);let r=t.run;if(typeof r!="function")throw new TypeError(`createTerminal: ${e}: \`run\` must be a function`);for(let i of Object.keys(t))if(!Ao.includes(i))throw new Error(`createTerminal: ${e}: unknown option \`${i}\` (known: ${Ao.join(", ")})`);return{run:r,pipe:!!t.pipe,hidden:!!t.hidden}}function L0(e,t,n,r,i){i.io?.bufferOutput(),X(i);let o={cwd:i.cwd,fs:i.fs,mount:i.mount,home:i.home,get notes(){return i.notes},command:e,stdinFile:i.stdinFile,stdinOrigin:i.stdinOrigin},s=!0,u=()=>{s=!1},a={name:e,args:r,stdin:n,cwd:o.cwd,fs:R0(o),readInputs:(f=[])=>{if(typeof f=="string")throw new TypeError(`readInputs: expected an array of paths, got a string: ${f}`);return se(e,[...f],n,o)},run:f=>{if(!s)throw new Error("run: the command this belongs to has finished, and its turn with it");return i.runLine(f)}},l=t(a);return typeof l?.then!="function"?(u(),Il(l)):l.then(Il).finally(u)}function R0(e){let t=n=>v(e.cwd,n,e.fs).path;return{resolve:n=>G(e.cwd,n),isFile:n=>e.fs.isFile(t(n)),isDir:n=>e.fs.isDir(t(n)),isLink:n=>e.fs.isLink?.(v(e.cwd,n,e.fs,{follow:!1}).path)===!0,readLink:n=>e.fs.readLink?.(v(e.cwd,n,e.fs,{follow:!1}).path),readFile:n=>e.fs.readFile(t(n)),isBytes:n=>e.fs.isBytes?.(t(n))===!0,readBytes:n=>Me(e.fs,t(n))?.slice(),listDir:n=>{let{path:r,error:i}=R(e,e.command,n);if(!e.fs.isDir(r))throw new Error(`${n}: ${i??"Not a directory"}`);let{dirs:o,files:s,links:u=[]}=e.fs.listDir(r);return{dirs:[...o],files:[...s],links:[...u]}},walkFiles:n=>[...e.fs.walkFiles(t(n))]}}function Il(e){if(e==null)return C();if(typeof e=="string")return C(e);if(typeof e!="object")throw new TypeError(`invalid result: expected a string or an object (got ${typeof e})`);if(Array.isArray(e))throw new TypeError("invalid result: expected a string or an object, got an array (join the lines first)");let t=Object.keys(e);for(let o of t)if(!Oo.includes(o))throw new TypeError(`invalid result: unknown field \`${o}\` (known: ${Oo.join(", ")})`);if(t.length===0)throw new TypeError(`invalid result: an object with none of ${Oo.join(", ")} \u2014 return a string for plain output`);let{stdout:n="",stderr:r="",exitCode:i=0}=e;if(typeof n!="string")throw new TypeError(`invalid result: stdout must be a string (got ${typeof n})`);if(typeof r!="string")throw new TypeError(`invalid result: stderr must be a string (got ${typeof r})`);if(!Number.isInteger(i)||i<0)throw new TypeError(`invalid result: exitCode must be a non-negative integer (got ${i})`);return{stdout:n,stderr:r===""||r.endsWith(`
|
|
31
31
|
`)?r:r+`
|
|
32
|
-
`,exitCode:i}}function E(e,t={}){let n=Nn(t.short),r=Nn(t.long),i=Nn(t.valueShort),o=Nn(t.valueLong),s=Nn(t.repeatable),u=new Set,a=new Map,l=[],c=[],f=0;function d(p,m,h=!1){let g=(h?"--":"-")+p,x=(h?o:i).has(p)||s.has(p)&&(!h||p.length>1);if(x){let b=m??e[++f];if(m===null&&f>=e.length)throw new Error(g+" requires an argument");if(s.has(p)){let S=a.get(p);S?S.push(b):a.set(p,[b])}else a.set(p,b);c.push({name:p,value:b})}else{if(!(h?r:n).has(p))throw new w("option",g,"unknown option: "+g);if(h&&m!==null)throw new Error("option "+g+" doesn't allow an argument");u.add(p),c.push({name:p})}return x}for(;f<e.length;f++){let p=e[f];if(p==="--"){l.push(...e.slice(f+1));break}if(p.startsWith("--")&&p.length>2){let m=p.indexOf("=");d(m===-1?p.slice(2):p.slice(2,m),m===-1?null:p.slice(m+1),!0);continue}if(p.startsWith("-")&&p.length>1&&!(t.numericOperands&&pg(p,n,i,s))){for(let m=1;m<p.length&&!d(p[m],m+1<p.length?p.slice(m+1):null);m++);continue}if(t.stopAtFirstPositional){l.push(...e.slice(f));break}l.push(p)}return{flags:u,values:a,positional:l,order:c}}function pg(e,t,n,r){if(!/^-\d/u.test(e))return!1;let i=e[1];return!t.has(i)&&!n.has(i)&&!r.has(i)}function Nn(e){return e instanceof Set?e:new Set(e??[])}function Sr(e,t,n,r,i){let o=Ta(e,i.skip,i.skipFlag,0),s=Ta(e,i.len,i.lenFlag,Number.POSITIVE_INFINITY);if(o.error||s.error)return{error:o.error??s.error};let u=s.value,a=o.value,l=0,c=n,f=[],d={stderr:"",failed:!1};for(let h of t.length?t:[null]){let g=te(e,h===null?[]:[h],c,r,{noRead:u===0&&a===0}),x=g.entries[0]?.kind==="dir";if(d.stderr+=g.stderr,d.failed||=g.failed&&!(e==="hexdump"&&x),a&&x)return{error:v("feature",e,"skip across unreadable input",`${e}: skipping across a directory operand is not supported`)};if(x&&e==="xxd")return{error:y(d.stderr,2)};if(!g.inputs.length&&!x)continue;let b=g.inputs[0],S=b&&(b.shared||b.name===null);if(e==="hexdump"&&a&&S&&!r.stdinFile)return z(r,c),{error:y("hexdump: standard input: Illegal seek")};let A=S&&r.stdinFile&&i.skip!==void 0&&(e==="xxd"||e==="hexdump"&&o.value>0),V=I(A?r.stdinOrigin:b?.content??""),q=Math.min(a,V.length);a-=q,l+=q;let T=Math.min(u,V.length-q);if(f.push(V.subarray(q,q+T)),u-=T,S&&(c=M(V.subarray(q+T)),z(r,c)),A&&a&&(l=o.value,a=0),u===0&&a===0)break}if(a&&i.skipPastEofErrors)return{error:y(d.stderr+`${e}: cannot skip past end of combined input`)};let p=new Uint8Array(f.reduce((h,g)=>h+g.length,0)),m=0;for(let h of f)p.set(h,m),m+=h.length;return{bytes:p,start:l,r:d}}function Ta(e,t,n,r){if(t===void 0)return{value:r};if(e==="xxd"&&!/^(?:0[xX][\da-fA-F]+|0[0-7]*|[1-9]\d*)$/u.test(t))return{error:v("feature",e,`${n} ${t}`,`xxd: this offset/count spelling is not supported: ${t}`)};if(e==="hexdump")return/^[ \t\n\r\v\f]*[+\d-]/u.test(t)?!/^\d+$/u.test(t)||/^0\d/u.test(t)?{error:v("feature",e,`${n} ${t}`,`hexdump: this offset/count spelling is not supported: ${t}`)}:BigInt(t)>BigInt(Number.MAX_SAFE_INTEGER)?{error:v("feature",e,"large byte count","hexdump: counts beyond exact integer precision are not supported")}:{value:Number(t)}:{error:y(`${e}: ${n}: invalid count: ${t}`)};let i=/^[ \t\n\r\v\f]*\+?(0[xX][\da-fA-F]+|0[0-7]*|[1-9]\d*)(b|[kKMGTPEZYRQ](?:i?B)?)?$/u.exec(t);if(!i)return{error:y(`${e}: ${n}: invalid count: ${t}`)};let o=/^0\d/u.test(i[1])?"0o"+i[1].slice(1):i[1];return Di(BigInt(o),i[2],`${e}: ${n}`,t)}var Er=16,hg=47,mg=39;function Ra(e,t,n){let{flags:r,values:i,positional:o}=E(t,{short:["C","v"],valueShort:["n","s"]});if(o.includes("-"))return v("feature","hexdump","hyphen input operand","hexdump: a hyphen input operand is not supported; omit operands to read stdin");let s=Sr("hexdump",o,e,n,{skip:i.get("s"),len:i.get("n"),skipFlag:"-s",lenFlag:"-n"});return s.error?s.error:ue(ro(s.bytes,s.start,r.has("v"),r.has("C")?wg:gg),s.r)}function Ma(e,t,n){let{flags:r,values:i,positional:o}=E(t,{short:["v"],valueShort:["j","N"]});if(!r.size&&!i.size&&(o.length===1&&/^\+\d/u.test(o[0])||o.length===2&&/^\+?\d/u.test(o[1])))return v("feature","od","legacy offset operand","od: legacy offset operands are not supported; use -j OFFSET");let s=Sr("od",o,e,n,{skip:i.get("j"),len:i.get("N"),skipFlag:"-j",lenFlag:"-N",skipPastEofErrors:!0});return s.error?s.error:ue(ro(s.bytes,s.start,r.has("v"),xg),s.r)}function Pa(e,t,n){let{values:r,positional:i}=E(t,{valueShort:["s","l"]});if(i.length>2)return y("xxd: too many operands");if(i.length===2&&i[1]!=="-")return v("feature","xxd","output file","xxd: output files are not supported (filesystem is read-only)");let o=Sr("xxd",i.slice(0,1),e,n,{skip:r.get("s"),len:r.get("l"),skipFlag:"-s",lenFlag:"-l"});return o.error?o.error:ue(ro(o.bytes,o.start,!1,yg),o.r)}function ro(e,t,n,r){let i=[],o=null,s=!1;for(let a=0;a<e.length;a+=Er){let l=e.subarray(a,a+Er);r.compress&&!n&&o!==null&&l.length===Er&&kg(l,o)?s||(i.push("*"),s=!0):(i.push(r.row(t+a,l)),s=!1),o=l}let u=t+e.length;return(r.trailer==="always"||r.trailer==="nonzero"&&u>0)&&i.push(r.addr(u)),ce(i)}var gg={compress:!0,trailer:"nonzero",addr:_a,row:(e,t)=>(_a(e)+" "+Da(t).map(Sg).join(" ")).padEnd(hg)},wg={compress:!0,trailer:"nonzero",addr:io,row:bg},xg={compress:!0,trailer:"always",addr:La,row:(e,t)=>La(e)+" "+Da(t).map(Eg).join(" ")},yg={compress:!1,trailer:"never",row:(e,t)=>`${io(e)}: ${vg(t).join(" ").padEnd(mg)} ${Ua(t)}`};function _a(e){return e.toString(16).padStart(7,"0")}function io(e){return e.toString(16).padStart(8,"0")}function La(e){return e.toString(8).padStart(7,"0")}function bg(e,t){let n=[];for(let o=0;o<Er;o++)n.push(o<t.length?no(t[o]):" ");let r=n.slice(0,8).join(" "),i=n.slice(8).join(" ");return`${io(e)} ${r} ${i} |${Ua(t)}|`}function Da(e){let t=[];for(let n=0;n<e.length;n+=2)t.push(n+1<e.length?e[n]|e[n+1]<<8:e[n]);return t}function vg(e){let t=[];for(let n=0;n<e.length;n+=2)t.push(no(e[n])+(n+1<e.length?no(e[n+1]):""));return t}function Ua(e){let t="";for(let n of e)t+=n>=32&&n<=126?String.fromCodePoint(n):".";return t}function kg(e,t){return e.length===t.length&&e.every((n,r)=>n===t[r])}var no=e=>e.toString(16).padStart(2,"0"),Sg=e=>e.toString(16).padStart(4,"0"),Eg=e=>e.toString(8).padStart(6,"0");function Ba(e){if(Object.keys(e).length>0)throw new TypeError("Unexpected extra options")}var c$=Object.getPrototypeOf(Uint8Array);var za=globalThis.atob,qa=Uint8Array.prototype.toBase64,Wa=8192,$g=qa&&za;function oo(e,t=0,n=e.length){t|=0,n|=0;let r=n-t;if(r===0)return"";if($g&&r>=256&&r<1e8&&e.toBase64===qa&&e.BYTES_PER_ELEMENT===1){let o=t===0&&n===e.length?e:e.subarray(t,n);return za(o.toBase64())}if(r>Wa){let o="";for(let s=t;s<n;){let u=Math.min(n,s+Wa);o+=String.fromCharCode.apply(String,e.subarray(s,u)),s=u}return o}let i=t===0&&n===e.length?e:e.subarray(t,n);return String.fromCharCode.apply(String,i)}var ja=pn?e=>e.byteLength>=768&&!Ou?pn.from(e.buffer,e.byteOffset,e.byteLength).latin1Slice(0,e.byteLength):Be.decode(e):Ti?e=>Ti.decode(e):e=>oo(e instanceof Uint8Array?e:new Uint8Array(e.buffer,e.byteOffset,e.byteLength));var Ha=e=>Fi(e,new Uint8Array(e.length)),Ng=hn&&Ue?.encodeInto,Ga=Ng?(e,t)=>{let n=new Uint8Array(e.length+4),r=Ue.encodeInto(e,n);if(r.read!==e.length||r.written!==e.length)throw new SyntaxError(t);return n.subarray(0,e.length)}:pn?(e,t)=>{let n=pn.from(e,"utf8");if(n.length!==e.length)throw new SyntaxError(t);return new Uint8Array(n.buffer,n.byteOffset,n.byteLength)}:(e,t)=>{let n=Ue.encode(e);if(n.length!==e.length)throw new SyntaxError(t);return n};var lo={};Vh(lo,{E_CHAR:()=>qt,E_LAST:()=>so,E_LENGTH:()=>Ja,E_PADDING:()=>Ka,fromBase64:()=>ao,toBase64:()=>uo});var Xa=[..."ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"],Za=[..."ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"],Va={},Ya={},qt="Invalid character in base64 input",Ka="Invalid base64 padding",Ja="Invalid base64 length",so="Invalid last chunk";function uo(e,t,n){let r=e.length/3|0,i=r*3,o="",s=0,u=t?Za:Xa,a=t?Ya:Va;if(!a.pairs)if(a.pairs=[],Be){a.codepairs=new Uint16Array(4096);let m=a.codepairs,h=new Uint8Array(m.buffer,m.byteOffset,m.byteLength);for(let g=0;g<64;g++){let x=u[g].charCodeAt(0);for(let b=0;b<64;b++)h[g<<7|b<<1]=h[b<<7|(g<<1)+1]=x}}else{let m=a.pairs;for(let h=0;h<64;h++)for(let g=0;g<64;g++)m.push(`${u[h]}${u[g]}`)}let{pairs:l,codepairs:c}=a;if(Be){let m=new Uint16Array(r*2),h=0;for(let g=e.length-11;s<g;s+=12,h+=8){let x=e[s],b=e[s+1],S=e[s+2],A=e[s+3],V=e[s+4],q=e[s+5],T=e[s+6],Y=e[s+7],Ie=e[s+8],X=e[s+9],ve=e[s+10],Xh=e[s+11];m[h]=c[x<<4|b>>4],m[h+1]=c[(b&15)<<8|S],m[h+2]=c[A<<4|V>>4],m[h+3]=c[(V&15)<<8|q],m[h+4]=c[T<<4|Y>>4],m[h+5]=c[(Y&15)<<8|Ie],m[h+6]=c[X<<4|ve>>4],m[h+7]=c[(ve&15)<<8|Xh]}for(let g=e.length-2;s<g;s+=3,h+=2){let x=e[s],b=e[s+1],S=e[s+2];m[h]=c[x<<4|b>>4],m[h+1]=c[(b&15)<<8|S]}o=ja(m)}else for(;s<i;s+=3){let m=e[s],h=e[s+1],g=e[s+2];o+=l[m<<4|h>>4],o+=l[(h&15)<<8|g]}let f=0,d=2,p=e.length;for(;s<p;s++){let m=e[s];o+=u[f|m>>d],d===6&&(d=0,o+=u[m&63]),f=m<<6-d&63,d+=2}return d!==2&&(o+=u[f]),n&&(o+=["","==","="][p-i]),o}var Ag=Ue?128:65536;function ao(e,t){let n=e.length;for(;e[n-1]==="=";)n--;let r=e.length-n,i=n%4,o=n-i;if(i===1)throw new SyntaxError(Ja);if(r>3||r!==0&&e.length%4!==0)throw new SyntaxError(Ka);let s=t?Za:Xa,u=t?Ya:Va;u.fromMap||(u.fromMap=new Int8Array(Ag).fill(-1),s.forEach((m,h)=>u.fromMap[m.charCodeAt(0)]=h));let a=u.fromMap,l=new Uint8Array(Math.floor(n*3/4)),c=0,f=0;if(Ue){let m=Ga(e,qt);for(;f<o;f+=4){let h=m[f],g=m[f+1],x=m[f+2],b=m[f+3],S=a[h]<<18|a[g]<<12|a[x]<<6|a[b];if(S<0)throw new SyntaxError(qt);l[c]=S>>16,l[c+1]=S>>8&255,l[c+2]=S&255,c+=3}}else for(;f<o;f+=4){let m=e.charCodeAt(f),h=e.charCodeAt(f+1),g=e.charCodeAt(f+2),x=e.charCodeAt(f+3),b=a[m]<<18|a[h]<<12|a[g]<<6|a[x];if(b<0)throw new SyntaxError(qt);l[c]=b>>16,l[c+1]=b>>8&255,l[c+2]=b&255,c+=3}if(i<2)return l;let d=a[e.charCodeAt(f++)]<<6|a[e.charCodeAt(f++)];if(d<0)throw new SyntaxError(qt);if(l[c++]=d>>4,i<3){if(d&15)throw new SyntaxError(so);return l}let p=a[e.charCodeAt(f++)];if(p<0)throw new SyntaxError(qt);if(l[c++]=d<<4&255|p>>2,p&3)throw new SyntaxError(so);return l}var{Buffer:It,atob:nl,btoa:rl}=globalThis,il=It&&!It.TYPED_ARRAY_SUPPORT,{toBase64:Qa}=Uint8Array.prototype,{E_CHAR:An,E_PADDING:$r,E_LENGTH:Ig,E_LAST:Og}=lo,Cg=rl&&hn,Fg=nl&&hn,Tg=e=>e.constructor===It&&It.isBuffer(e),_g=e=>Tg(e)?e:It.from(e.buffer,e.byteOffset,e.byteLength);function co(e,t){if(t)return e;let n=e.indexOf("=",e.length-3);return n===-1?e:e.slice(0,n)}function Lg(e,t){return t&&e.length%4!==0?e+"=".repeat(4-e.length%4):e}var Rg=e=>Qa&&e.toBase64===Qa;function fo(e,{padding:t=!0}={}){return dr(e),Rg(e)?t?e.toBase64():e.toBase64({omitPadding:!t}):il?co(_g(e).base64Slice(0,e.byteLength),t):Cg?co(rl(oo(e)),t):uo(e,!1,t)}function po(e,t){if(typeof t=="string"&&(t={format:t}),!t)return el(e,!1,"both","uint8",null);let{format:n="uint8",padding:r="both",...i}=t;return el(e,!1,r,n,i)}function el(e,t,n,r,i){if(typeof e!="string")throw new TypeError(pr);i!==null&&Ba(i);let o=n==="both"?e.endsWith("="):void 0;if(n===!0||o===!0){if(e.length%4!==0)throw new SyntaxError($r);if(e[e.length-3]==="=")throw new SyntaxError($r)}else if(n===!1||o===!1){if(e.length%4===1)throw new SyntaxError(Ig);if(n===!1&&e.endsWith("="))throw new SyntaxError("Did not expect padding in base64 input")}else throw new TypeError("Invalid padding option");return In(e,t,n,r)}var Mg=/[\t\n\f\r ]/;function tl(e,t){let n=e.indexOf("=",e.length-3),r=n>=0?e.length-n:0,i=e.length-r,o=i%4,s=t.length-(i-o)/4*3;return o===0&&s===0||o===2&&s===1||o===3&&s===2}var In;Uint8Array.fromBase64?In=(e,t,n,r)=>{let i=t?"base64url":"base64",o;if(n===!0)o=Uint8Array.fromBase64(e,{alphabet:i,lastChunkHandling:"strict"});else try{let s=e.length%4>0?`${e}${"=".repeat(4-e.length%4)}`:e;o=Uint8Array.fromBase64(s,{alphabet:i,lastChunkHandling:"strict"})}catch(s){throw Mg.test(e)?new SyntaxError(An):s}if(!tl(e,o))throw new SyntaxError(An);return bt(o,r)}:il?In=(e,t,n,r)=>{let i=It.byteLength(e,"base64"),o=It.allocUnsafeSlow(i);if(o.base64Write(e)!==i)throw new SyntaxError($r);let s=t?co(e,n===!1):Lg(e,n!==!0),u=t?o.base64urlSlice(0,o.length):o.base64Slice(0,o.length);if(s!==u)throw new SyntaxError($r);return Cu(o,r)}:Fg?In=(e,t,n,r)=>{let i;if(t){if(/[\t\n\f\r +/]/.test(e))throw new SyntaxError(An);e=e.replaceAll("-","+").replaceAll("_","/")}try{i=Ha(nl(e))}catch{throw new SyntaxError(An)}if(!t&&!tl(e,i))throw new SyntaxError(An);if(i.length%3!==0){let o=fo(i.subarray(-(i.length%3))),s=e.length%4===0?e.slice(-4):e.slice(-(e.length%4)).padEnd(4,"=");if(o!==s)throw new SyntaxError(Og)}return bt(i,r)}:In=(e,t,n,r)=>bt(ao(e,t),r);var ho="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Pg=76;function ol(e,t,n){let{flags:r,positional:i,order:o}=E(t,{short:["d","i"],long:["decode","ignore-garbage"],valueShort:["w"],valueLong:["wrap"]}),s=Pg;for(let{name:f,value:d}of o){if(f!=="w"&&f!=="wrap")continue;if(!/^[ \t\n\r\f\v]*[+-]?\d+$/u.test(d)||BigInt(d)<0n)return y(`base64: invalid wrap size: ${d}`);let p=BigInt(d);s=p>J?0:Number(p)}if(i.length>1)return y(`base64: extra operand: ${i[1]}`);let u=te("base64",i,e,n);if(u.failed)return y(u.stderr);let a=u.inputs[0].content;if(r.has("d")||r.has("decode"))return Dg(a,r.has("i")||r.has("ignore-garbage"));let l=fo(ee(a));if(!s||l==="")return C(l);let c=[];for(let f=0;f<l.length;f+=s)c.push(l.slice(f,f+s));return C(c.join(`
|
|
32
|
+
`,exitCode:i}}function N(e,t={}){let n=Tn(t.short),r=Tn(t.long),i=Tn(t.valueShort),o=Tn(t.valueLong),s=Tn(t.repeatable),u=new Set,a=new Map,l=[],f=[],c=0;function d(p,h,m=!1){let g=(m?"--":"-")+p,b=(m?o:i).has(p)||s.has(p)&&(!m||p.length>1);if(b){let x=h??e[++c];if(h===null&&c>=e.length)throw new Error(g+" requires an argument");if(s.has(p)){let S=a.get(p);S?S.push(x):a.set(p,[x])}else a.set(p,x);f.push({name:p,value:x})}else{if(!(m?r:n).has(p))throw new w("option",g,"unknown option: "+g);if(m&&h!==null)throw new Error("option "+g+" doesn't allow an argument");u.add(p),f.push({name:p})}return b}for(;c<e.length;c++){let p=e[c];if(p==="--"){l.push(...e.slice(c+1));break}if(p.startsWith("--")&&p.length>2){let h=p.indexOf("=");d(h===-1?p.slice(2):p.slice(2,h),h===-1?null:p.slice(h+1),!0);continue}if(p.startsWith("-")&&p.length>1&&!(t.numericOperands&&M0(p,n,i,s))){for(let h=1;h<p.length&&!d(p[h],h+1<p.length?p.slice(h+1):null);h++);continue}if(t.stopAtFirstPositional){l.push(...e.slice(c));break}l.push(p)}return{flags:u,values:a,positional:l,order:f}}function M0(e,t,n,r){if(!/^-\d/u.test(e))return!1;let i=e[1];return!t.has(i)&&!n.has(i)&&!r.has(i)}function Tn(e){return e instanceof Set?e:new Set(e??[])}function P0(e){try{return typeof DecompressionStream=="function"&&!!new DecompressionStream(e)}catch{return!1}}function D0(e){try{return typeof CompressionStream=="function"&&!!new CompressionStream(e)}catch{return!1}}var Pr=e=>P0(e)&&D0(e);async function Fl(e,t){let{readable:n,writable:r}=e,i=r.getWriter(),o=(async()=>{try{await i.write(t),await i.close()}catch{}})(),s=n.getReader(),u=[],a=null;try{for(;;){let{done:c,value:d}=await s.read();if(c)break;u.push(d)}}catch(c){a=c?.cause?.message??c?.message??"corrupt input"}await o;let l=new Uint8Array(u.reduce((c,d)=>c+d.length,0)),f=0;for(let c of u)l.set(c,f),f+=c.length;return{bytes:l,error:a}}var Dr=(e,t)=>Fl(new DecompressionStream(t),e),_n=async(e,t)=>(await Fl(new CompressionStream(t),e)).bytes;var Ur="gzip",Ll=Pr(Ur)?{gzip:j0}:{},Tl=Object.freeze([31,139]),U0=e=>e!==void 0&&e.length>=2&&e[0]===Tl[0]&&e[1]===Tl[1],B0={__proto__:null,"unexpected end of file":"unexpected end of file","incorrect data check":"invalid compressed data--crc error"},q0=e=>B0[e]??"invalid compressed data--format violated",Rl=Object.freeze({__proto__:null,".gz":"",".tgz":".tar",".taz":".tar","-gz":"",".z":"","-z":"",_z:""}),W0=".gz",_l=Object.freeze(["1","2","3","4","5","6","7","8","9"]);async function j0(e,t,n){let{flags:r,positional:i}=N(t,{short:[..._l,"d","c","k"],long:["decompress","uncompress","stdout","to-stdout","keep"]}),o=_l.find(a=>r.has(a));if(o!==void 0)return k("option","gzip",`-${o}`,`gzip: -${o}: choosing a compression level is not supported`,1);let s={decompressing:["d","decompress","uncompress"].some(a=>r.has(a)),stdout:["c","stdout","to-stdout"].some(a=>r.has(a)),keep:r.has("k")||r.has("keep")},u={ctx:n,stdout:"",stderr:"",status:0,gap:null};if(i.length===0)await z0(e,s,u);else for(let a of i)await H0(a,s,u);return u.gap?u.gap:{stdout:u.stdout,stderr:u.stderr,exitCode:u.status}}async function z0(e,t,n){return t.decompressing?Io(n,e===""?"stdin: unexpected end of file":"stdin: not in gzip format"):Co(await _n(q(e),Ur),n)}function H0(e,t,n){let{ctx:r}=n,i=R(r,"gzip",e);return i.error?Lt(n,`${e}: ${i.error}`,1):r.fs.isDir(i.path)?Lt(n,`${e} is a directory -- ignored`,2):t.decompressing?V0(e,i.path,t,n):G0(e,i.path,t,n)}async function G0(e,t,n,r){let{ctx:i}=r,o=Ml(e);if(!n.stdout&&o!==void 0)return J0(r,`${e} already has ${o} suffix -- unchanged`);let s=Y0(await _n(Me(i.fs,t),Ur),e.slice(e.lastIndexOf("/")+1),X0(i));return n.stdout?Co(s,r):Pl(e+W0,s,e,n,r)}var X0=e=>Math.floor(e.createdAt/1e3),Ln=10,Z0=8;function Y0(e,t,n){let r=q(t);if(e.length<Ln||e[3]!==0||r.includes(0))return e;let i=new Uint8Array(e.length+r.length+1);i.set(e.subarray(0,Ln)),i[3]=Z0;for(let o=0;o<4;o++)i[4+o]=n>>>8*o&255;return i.set(r,Ln),i.set(e.subarray(Ln),Ln+r.length+1),i}async function V0(e,t,n,r){let{ctx:i}=r,o=i.fs.isBytes?.(t)===!0?Me(i.fs,t):void 0;if(!U0(o))return Io(r,`${e}: ${K0(o,t,i)?"unexpected end of file":"not in gzip format"}`);let s=await Dr(o,Ur),u=Ml(e);(n.stdout?Co(s.bytes,r):u===void 0?Lt(r,`${e}: unknown suffix -- ignored`,2):Pl(e.slice(0,-u.length)+Rl[u],s.bytes,e,n,r))&&s.error&&Io(r,`${e}: ${q0(s.error)}`)}var Ml=e=>Object.keys(Rl).find(t=>e.length>t.length&&e.endsWith(t));function K0(e,t,n){if(e!==void 0)return e.length<2;let r=n.fs.readFile(t);return r.length<2&&A(r).length<2}var Co=(e,t)=>(t.stdout+=P(e),!0);function Pl(e,t,n,r,i){let{ctx:o}=i;if(R(o,"gzip",e).error===null)return Lt(i,`${e} already exists; not overwritten`,2);let s;try{s=o.writable&&o.fs.openWritable?.(o.cwd,e)}catch(u){return Lt(i,`${e}: ${u.message}`,1)}return s?(s.writeBytes(t),r.keep||o.fs.removeWritable(o.cwd,n),!0):(i.gap??=k("feature","gzip","read-only target",`gzip: ${e}: file system is read-only`,1),!1)}var Io=(e,t)=>Lt(e,t,1,`
|
|
33
|
+
`),J0=(e,t)=>Lt(e,t,e.status);function Lt(e,t,n,r=""){return e.stderr+=`${r}gzip: ${t}
|
|
34
|
+
`,e.status=e.status===1?1:n,!1}var Fo="brotli",Br=".br",Ul=Pr(Fo)?{brotli:eg}:{},Bl="con",ql=Object.freeze(["0","1","2","3","4","5","6","7","8","9"]),Q0=`Usage: brotli [OPTION]... [FILE]...
|
|
35
|
+
`;async function eg(e,t,n){let{flags:r,values:i,positional:o}=N(t,{short:[...ql,"d","c","k","j","f","Z"],long:["decompress","stdout","keep","rm","force","best"],valueShort:["q"],valueLong:["quality"]}),s=tg(r,i);if(s!==void 0)return k("option","brotli",s,`brotli: ${s}: choosing a compression level is not supported`,1);let u={decompressing:r.has("d")||r.has("decompress"),stdout:r.has("c")||r.has("stdout"),remove:r.has("j")||r.has("rm"),force:r.has("f")||r.has("force")};if(u.stdout&&o.length>1)return{stdout:Q0,stderr:"",exitCode:1};let a={ctx:n,stdout:"",stderr:"",status:0,gap:null};for(let l of o.length===0?["-"]:o)if(!await ng(l,e,u,a))break;return a.gap?a.gap:{stdout:a.stdout,stderr:a.stderr,exitCode:a.status}}function tg(e,t){let n=[...ql,"Z"].find(r=>e.has(r));return n!==void 0?"-"+n:e.has("best")?"--best":t.has("q")?"-q":t.has("quality")?"--quality":void 0}function ng(e,t,n,r){let{ctx:i}=r;if(e==="-")return Dl(q(t),Bl,null,n,r);let o=null;if(!n.stdout)if(!n.decompressing)o=e+Br;else{if(e.length<=Br.length)return Rt(r,`empty output file name for [${e}] input file`);if(e.endsWith(Br))o=e.slice(0,-Br.length);else return Rt(r,`input file [${e}] suffix mismatch`)}let s=R(i,"brotli",e);return s.error?Rt(r,`failed to open input file [${e}]: ${s.error}`):o!==null&&!n.force&&R(i,"brotli",o).error===null?Rt(r,`failed to open output file [${o}]: File exists`):i.fs.isDir(s.path)?Rt(r,`failed to read input [${e}]: Is a directory`):Dl(Me(i.fs,s.path),e,o,n,r)}async function Dl(e,t,n,r,i){let{ctx:o}=i,s=r.decompressing?await Dr(e,Fo):{bytes:await _n(e,Fo),error:null};if(s.error)return Rt(i,`corrupt input [${t}]`);if(n===null)i.stdout+=P(s.bytes);else if(!rg(n,s.bytes,i))return!1;return r.remove&&t!==Bl&&o.fs.removeWritable(o.cwd,t),!0}function rg(e,t,n){let{ctx:r}=n,i;try{i=r.writable&&r.fs.openWritable?.(r.cwd,e)}catch(o){return Rt(n,`failed to open output file [${e}]: ${o.message}`)}return i?(i.writeBytes(t),!0):(n.gap??=k("feature","brotli","read-only target",`brotli: ${e}: file system is read-only`,1),!1)}function Rt(e,t){return e.stderr+=`${t}
|
|
36
|
+
`,e.status=1,!1}var ig=new Uint8Array;function qr(e,t,n,r,i){let o=Wl(e,i.skip,i.skipFlag,0),s=Wl(e,i.len,i.lenFlag,Number.POSITIVE_INFINITY);if(o.error||s.error)return{error:o.error??s.error};let u=s.value,a=o.value,l=0,f=n,c=[],d={stderr:"",failed:!1};for(let m of t.length?t:[null]){let g=se(e,m===null?[]:[m],f,r,{read:"loose-bytes",noRead:u===0&&a===0}),b=g.entries[0]?.kind==="dir";if(d.stderr+=g.stderr,d.failed||=g.failed&&!(e==="hexdump"&&b),a&&b)return{error:k("feature",e,"skip across unreadable input",`${e}: skipping across a directory operand is not supported`)};if(b&&e==="xxd")return{error:y(d.stderr,2)};if(!g.inputs.length&&!b)continue;let x=g.inputs[0],S=x&&(x.shared||x.name===null);if(e==="hexdump"&&a&&S&&!r.stdinFile)return X(r,f),{error:y("hexdump: standard input: Illegal seek")};let E=S&&r.stdinFile&&i.skip!==void 0&&(e==="xxd"||e==="hexdump"&&o.value>0),M=E?A(r.stdinOrigin):x?.bytes??ig,D=Math.min(a,M.length);a-=D,l+=D;let T=Math.min(u,M.length-D);if(c.push(M.subarray(D,D+T)),u-=T,S&&(f=P(M.subarray(D+T)),X(r,f)),E&&a&&(l=o.value,a=0),u===0&&a===0)break}if(a&&i.skipPastEofErrors)return{error:y(d.stderr+`${e}: cannot skip past end of combined input`)};let p=new Uint8Array(c.reduce((m,g)=>m+g.length,0)),h=0;for(let m of c)p.set(m,h),h+=m.length;return{bytes:p,start:l,r:d}}function Wl(e,t,n,r){if(t===void 0)return{value:r};if(e==="xxd"&&!/^(?:0[xX][\da-fA-F]+|0[0-7]*|[1-9]\d*)$/u.test(t))return{error:k("feature",e,`${n} ${t}`,`xxd: this offset/count spelling is not supported: ${t}`)};if(e==="hexdump")return/^[ \t\n\r\v\f]*[+\d-]/u.test(t)?!/^\d+$/u.test(t)||/^0\d/u.test(t)?{error:k("feature",e,`${n} ${t}`,`hexdump: this offset/count spelling is not supported: ${t}`)}:BigInt(t)>BigInt(Number.MAX_SAFE_INTEGER)?{error:k("feature",e,"large byte count","hexdump: counts beyond exact integer precision are not supported")}:{value:Number(t)}:{error:y(`${e}: ${n}: invalid count: ${t}`)};let i=/^[ \t\n\r\v\f]*\+?(0[xX][\da-fA-F]+|0[0-7]*|[1-9]\d*)(b|[kKMGTPEZYRQ](?:i?B)?)?$/u.exec(t);if(!i)return{error:y(`${e}: ${n}: invalid count: ${t}`)};let o=/^0\d/u.test(i[1])?"0o"+i[1].slice(1):i[1];return co(BigInt(o),i[2],`${e}: ${n}`,t)}var Wr=16,og=47,sg=39;function Hl(e,t,n){let{flags:r,values:i,positional:o}=N(t,{short:["C","v"],valueShort:["n","s"]});if(o.includes("-"))return k("feature","hexdump","hyphen input operand","hexdump: a hyphen input operand is not supported; omit operands to read stdin");let s=qr("hexdump",o,e,n,{skip:i.get("s"),len:i.get("n"),skipFlag:"-s",lenFlag:"-n"});return s.error?s.error:ee(_o(s.bytes,s.start,r.has("v"),r.has("C")?ag:ug),s.r)}function Gl(e,t,n){let{flags:r,values:i,positional:o}=N(t,{short:["v"],valueShort:["j","N"]});if(!r.size&&!i.size&&(o.length===1&&/^\+\d/u.test(o[0])||o.length===2&&/^\+?\d/u.test(o[1])))return k("feature","od","legacy offset operand","od: legacy offset operands are not supported; use -j OFFSET");let s=qr("od",o,e,n,{skip:i.get("j"),len:i.get("N"),skipFlag:"-j",lenFlag:"-N",skipPastEofErrors:!0});return s.error?s.error:ee(_o(s.bytes,s.start,r.has("v"),lg),s.r)}function Xl(e,t,n){let{values:r,positional:i}=N(t,{valueShort:["s","l"]});if(i.length>2)return y("xxd: too many operands");if(i.length===2&&i[1]!=="-")return k("feature","xxd","output file","xxd: output files are not supported (filesystem is read-only)");let o=qr("xxd",i.slice(0,1),e,n,{skip:r.get("s"),len:r.get("l"),skipFlag:"-s",lenFlag:"-l"});return o.error?o.error:ee(_o(o.bytes,o.start,!1,fg),o.r)}function _o(e,t,n,r){let i=[],o=null,s=!1;for(let a=0;a<e.length;a+=Wr){let l=e.subarray(a,a+Wr);r.compress&&!n&&o!==null&&l.length===Wr&&pg(l,o)?s||(i.push("*"),s=!0):(i.push(r.row(t+a,l)),s=!1),o=l}let u=t+e.length;return(r.trailer==="always"||r.trailer==="nonzero"&&u>0)&&i.push(r.addr(u)),he(i)}var ug={compress:!0,trailer:"nonzero",addr:jl,row:(e,t)=>(jl(e)+" "+Zl(t).map(hg).join(" ")).padEnd(og)},ag={compress:!0,trailer:"nonzero",addr:Lo,row:cg},lg={compress:!0,trailer:"always",addr:zl,row:(e,t)=>zl(e)+" "+Zl(t).map(mg).join(" ")},fg={compress:!1,trailer:"never",row:(e,t)=>`${Lo(e)}: ${dg(t).join(" ").padEnd(sg)} ${Yl(t)}`};function jl(e){return e.toString(16).padStart(7,"0")}function Lo(e){return e.toString(16).padStart(8,"0")}function zl(e){return e.toString(8).padStart(7,"0")}function cg(e,t){let n=[];for(let o=0;o<Wr;o++)n.push(o<t.length?To(t[o]):" ");let r=n.slice(0,8).join(" "),i=n.slice(8).join(" ");return`${Lo(e)} ${r} ${i} |${Yl(t)}|`}function Zl(e){let t=[];for(let n=0;n<e.length;n+=2)t.push(n+1<e.length?e[n]|e[n+1]<<8:e[n]);return t}function dg(e){let t=[];for(let n=0;n<e.length;n+=2)t.push(To(e[n])+(n+1<e.length?To(e[n+1]):""));return t}function Yl(e){let t="";for(let n of e)t+=n>=32&&n<=126?String.fromCodePoint(n):".";return t}function pg(e,t){return e.length===t.length&&e.every((n,r)=>n===t[r])}var To=e=>e.toString(16).padStart(2,"0"),hg=e=>e.toString(16).padStart(4,"0"),mg=e=>e.toString(8).padStart(6,"0");var Ro="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",gg=76;function Vl(e,t,n){let{flags:r,positional:i,order:o}=N(t,{short:["d","i"],long:["decode","ignore-garbage"],valueShort:["w"],valueLong:["wrap"]}),s=gg;for(let{name:d,value:p}of o){if(d!=="w"&&d!=="wrap")continue;if(!/^[ \t\n\r\f\v]*[+-]?\d+$/u.test(p)||BigInt(p)<0n)return y(`base64: invalid wrap size: ${p}`);let h=BigInt(p);s=h>oe?0:Number(h)}if(i.length>1)return y(`base64: extra operand: ${i[1]}`);let u=se("base64",i,e,n,{read:"as-held"});if(u.failed)return y(u.stderr);let{content:a,bytes:l}=u.inputs[0];if(r.has("d")||r.has("decode"))return wg(a??Ki(l),r.has("i")||r.has("ignore-garbage"));let f=io(l??q(a));if(!s||f==="")return C(f);let c=[];for(let d=0;d<f.length;d+=s)c.push(f.slice(d,d+s));return C(c.join(`
|
|
33
37
|
`)+`
|
|
34
|
-
`)}function
|
|
35
|
-
`;return{stdout:i,stderr:o,exitCode:1,events:[...i?[{fd:1,text:i}]:[],{fd:2,text:o}]}}function
|
|
36
|
-
`)return!0;if(n!=="\\")continue;let r=e[t+1];if(r==="n"||r==="x"&&/^x\{?0*a\}?/iu.test(e.slice(t+1)))return!0;t++}return!1}function cl(e,t){if(!t)for(let n of e){for(let[r,i]of Gg)if(r.test(n))throw On(i,`${i} is not supported; ripgrep's regex engine rejects it too`);if(Xg(n))throw On("newline in a pattern","a newline in a pattern is not supported; ripgrep rejects one outside multiline mode")}}var k=class extends Error{constructor(t,n=null,r=null){super(t),this.line=n,this.gap=r}},fl=new Set(["BEGIN","END","BEGINFILE","ENDFILE","function","func","if","else","while","for","do","break","continue","next","nextfile","exit","return","delete","in","getline","print","printf","switch","case","default"]),go={__proto__:null,length:[0,1],substr:[2,3],index:[2,2],split:[2,3],sub:[2,3],gsub:[2,3],gensub:[3,4],match:[2,3],sprintf:[1,1/0],sin:[1,1],cos:[1,1],atan2:[2,2],exp:[1,1],log:[1,1],sqrt:[1,1],int:[1,1],rand:[0,0],srand:[0,1],tolower:[1,1],toupper:[1,1],close:[1,2],fflush:[0,1],systime:[0,0],strtonum:[1,1],and:[2,1/0],or:[2,1/0],xor:[2,1/0],lshift:[2,2],rshift:[2,2],compl:[1,1],typeof:[1,1],isarray:[1,1]},Nr=new Map([["system","system() is not supported: this terminal runs no processes"],["strftime","strftime() is not supported (gawk extension)"],["mktime","mktime() is not supported (gawk extension)"],["asort","asort() is not supported (gawk extension)"],["asorti","asorti() is not supported (gawk extension)"],["patsplit","patsplit() is not supported (gawk extension)"]]),dl=new Set([...Object.keys(go),...Nr.keys()]),Cn=5e6,wo=100,ye=1e6,Ar="this terminal runs no processes";function Ir(e,t,n){switch(e){case"+":return t+n;case"-":return t-n;case"*":return t*n;case"/":return t/n;case"%":return t%n;default:return t**n}}var Fn={__proto__:null,alpha:"A-Za-z",digit:"0-9",alnum:"0-9A-Za-z",upper:"A-Z",lower:"a-z",space:" \\t\\n\\v\\f\\r",blank:" \\t",punct:"!-\\/:-@\\[-`{-~",xdigit:"0-9A-Fa-f",cntrl:"\\x00-\\x1F\\x7F",print:"\\x20-\\x7E",graph:"\\x21-\\x7E",word:"0-9A-Za-z_"},jt={__proto__:null};for(let[e,t]of Object.entries(Fn)){let n=new RegExp(`[${t}]`,"u"),r=[];for(let i=0;i<128;i++){if(!n.test(String.fromCodePoint(i)))continue;let o=r.at(-1);o&&o[1]===i-1?o[1]=i:r.push([i,i])}jt[e]=r}var Or=32767;function pl(e,t){if(e>Or||t!==void 0&&t>Or)throw new Error("Regular expression too big")}function hl(e,t){let n=t+1;e[n]==="^"&&n++;let r=!0,i=!1;for(;n<e.length;){let o=e[n];if(o==="]"&&!r)return n;if(r=!1,o==="["&&":.=".includes(e[n+1]??"")){let a=e[n+1],l=e.indexOf(a+"]",n+2);if(l===-1)throw new Error("Unmatched [, [^, [:, [., or [=");if(a===":"&&!(e.slice(n+2,l)in Fn))throw new Error("Invalid character class name");n=l+2,i=a!==".";continue}if(o==="-"&&i&&n+1<e.length&&e[n+1]!=="]")throw new Error("Invalid range end");let s=o==="\\"&&n+1<e.length?2:1;if(e[n+s]==="-"&&e[n+s+1]!==void 0&&e[n+s+1]!=="]"){let a=n+s+1,l=e[a]==="["?e[a+1]:void 0;if(l===":"||l==="=")throw new Error("Invalid range end");let c=l==="."?e.indexOf(".]",a+2):-1;if(l==="."&&c===-1)throw new Error("Unmatched [, [^, [:, [., or [=");n=c===-1?a+(e[a]==="\\"?2:1):c+2,i=!0;continue}n+=s,i=!1}throw new Error("Unmatched [, [^, [:, [., or [=")}function Ht(e,t,n={}){let r=/^\[:([a-z]+):\]/u.exec(e.slice(t));if(!r)return null;let i=Fn[r[1]];if(i===void 0){if(n?.unknown!=="empty")throw new Error(`invalid character class \`[:${r[1]}:]\``);return{body:"",end:t+r[0].length}}return{body:i,end:t+r[0].length}}var ml={__proto__:null,n:10,t:9,r:13,f:12,v:11,a:7,b:8},Zg='^$.[]|()*+?{}\\/"',xo=1e3,gl=e=>e!==void 0&&/[0-9a-fA-F]/u.test(e),wl=e=>e!==void 0&&e>="0"&&e<="7",yo=class{constructor(t,n){this.src=t,this.i=0,this.warn=n,this.groups=0}fail(t){throw new k(`invalid regex /${this.src}/: ${t}`)}peek(){return this.src[this.i]}literal(){let t=this.src.codePointAt(this.i);return this.i+=St(t),{type:"char",code:t}}parse(){return this.alternation(0)}alternation(t){let n=[this.concatenation(t)];for(;this.peek()==="|";)this.i++,n.push(this.concatenation(t));return n.length===1?n[0]:{type:"alt",nodes:n}}concatenation(t){let n=[];for(;!this.endsConcatenation(t);)n.push(this.quantified(this.atom(n.length===0,t)));return n.length===1?n[0]:{type:"cat",nodes:n}}endsConcatenation(t){let n=this.peek();return n===void 0||n==="|"||n===")"&&t>0}quantified(t){let n=t;for(;;){let r=this.peek();if(r==="*"){this.i++,n={type:"rep",node:n,min:0,max:null};continue}if(r==="+"){this.i++,n={type:"rep",node:n,min:1,max:null};continue}if(r==="?"){this.i++,n={type:"rep",node:n,min:0,max:1};continue}if(r==="{"){let i=/^\{(\d*)(?:(,)(\d*))?\}/u.exec(this.src.slice(this.i));if(!i&&/^\{[\d,]*\}/u.test(this.src.slice(this.i))&&this.fail("invalid content of {}"),!i||i[1]===""&&i[2]===void 0)return n;let o=i[1]===""?0:Number(i[1]),s=i[2]===void 0?o:i[3]===""?null:Number(i[3]);if(s!==null&&s<o&&this.fail(`invalid interval {${o},${s}}`),o>xo||s!==null&&s>xo)throw new k(`interval count above ${xo} is not supported`,null,"regex interval limit");this.i+=i[0].length,n={type:"rep",node:n,min:o,max:s};continue}return n}}atom(t,n){let r=this.peek();if(r==="("){this.i++;let i=++this.groups,o=this.alternation(n+1);return this.peek()!==")"&&this.fail("missing `)`"),this.i++,{type:"group",index:i,node:o}}return r==="["?this.bracket():r==="\\"?this.escape():(this.i++,r==="."?{type:"any"}:r==="^"||r==="$"?{type:"assert",kind:r}:((r==="*"||r==="+"||r==="?")&&!t&&this.fail(`unexpected \`${r}\``),this.i--,this.literal()))}escape(){this.i++;let t=this.peek();return t===void 0&&this.fail("trailing backslash"),this.i++,t==="y"?{type:"assert",kind:"y"}:t==="<"||t===">"||t==="B"?{type:"assert",kind:t}:t==="`"?{type:"assert",kind:"^"}:t==="'"?{type:"assert",kind:"$"}:t==="s"||t==="S"?{type:"set",negate:t==="S",items:jt.space}:t==="w"||t==="W"?{type:"set",negate:t==="W",items:jt.word}:(t==="b"&&this.warn?.("regexp escape sequence `\\b' is a backspace here, as in gawk; `\\y' is the word boundary"),{type:"char",code:this.escapedCode(t,!0)})}escapedCode(t,n){if(t in ml)return ml[t];if(wl(t)){let i=t;for(;i.length<3&&wl(this.peek());)i+=this.src[this.i++];return xl(i,8)}if(t==="x"&&gl(this.peek())){let i="";for(;i.length<2&&gl(this.peek());)i+=this.src[this.i++];return xl(i,16)}let r=this.src.codePointAt(this.i-1);return!Zg.includes(t)&&n&&this.warn?.(`regexp escape sequence \`\\${String.fromCodePoint(r)}' is not a known regexp operator`),this.i+=St(r)-1,r}bracket(){this.i++;let t=!1;this.peek()==="^"&&(t=!0,this.i++);let n=[],r=!0;for(;;){this.i>=this.src.length&&this.fail("unterminated bracket expression");let i=this.peek();if(i==="]"&&!r){this.i++;break}if(r=!1,i==="["&&this.src[this.i+1]===":"){let s=this.src.indexOf(":]",this.i+2);if(s!==-1){let u=this.src.slice(this.i+2,s);u in jt||this.fail(`invalid character class \`[:${u}:]\``),n.push(...jt[u]),this.i=s+2;continue}}let o=this.bracketChar();if(this.peek()==="-"&&this.src[this.i+1]!=="]"&&this.src[this.i+1]!==void 0){this.i++;let s=this.bracketChar();s<o&&this.fail("invalid range end"),n.push([o,s])}else n.push([o,o])}return{type:"set",negate:t,items:n}}bracketChar(){let t=this.peek();if(t==="["&&(this.src[this.i+1]==="."||this.src[this.i+1]==="=")){let r=this.src.indexOf(this.src[this.i+1]+"]",this.i+2);if(r!==-1&&r>this.i+2){Array.from(this.src.slice(this.i+2,r)).length!==1&&this.fail("invalid collation character");let i=this.src.codePointAt(this.i+2);return this.i=r+2,i}}if(t==="\\"){this.i++,this.peek()===void 0&&this.fail("trailing backslash");let r=this.src[this.i++];return this.escapedCode(r,!1)}let n=this.src.codePointAt(this.i);return this.i+=St(n),n}};function Xt(e,t=null){let n=new yo(e,t);return{ast:n.parse(),groups:n.groups}}function xl(e,t){let n=Number.parseInt(e,t);if(n>=128)throw new k("non-ASCII regex byte escapes are not supported",null,"regex byte escapes");return n}var Vg=e=>`\\u{${e.toString(16)}}`,Cr=e=>e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122?String.fromCodePoint(e):Vg(e),Yg={__proto__:null,"^":"^",$:"$",y:"\\b",B:"\\B","<":"(?<!\\w)(?=\\w)",">":"(?<=\\w)(?!\\w)"};function Gt(e){switch(e.type){case"char":return Cr(e.code);case"any":return".";case"set":return`[${e.negate?"^":""}${e.items.map(([t,n])=>t===n?Cr(t):`${Cr(t)}-${Cr(n)}`).join("")}]`;case"assert":return Yg[e.kind];case"group":return`(${Gt(e.node)})`;case"cat":return e.nodes.map(Gt).join("");case"alt":return`(?:${e.nodes.map(Gt).join("|")})`;case"rep":{let t=`(?:${Gt(e.node)})`;return e.max===null?e.min===0?`${t}*`:e.min===1?`${t}+`:`${t}{${e.min},}`:e.min===0&&e.max===1?`${t}?`:`${t}{${e.min},${e.max}}`}default:throw new k(`internal: unknown regex node ${e.type}`)}}var Kg=5e4,yl=e=>e>=48&&e<=57||e>=65&&e<=90||e===95||e>=97&&e<=122;function bl(e){let t=String.fromCodePoint(e);return[e,t.toLowerCase().codePointAt(0),t.toUpperCase().codePointAt(0)]}function Jg(e,t,n){let r=o=>{for(let s=0;s<e.length;s++)if(o>=e[s][0]&&o<=e[s][1])return!0;return!1};if(!n)return t?o=>!r(o):r;let i=o=>bl(o).some(r);return t?o=>!i(o):i}function vl(e,t){let n=[],r=l=>{if(n.length>=Kg)throw new k("regex too large",null,"regex state limit");return n.push(l),n.length-1};function i(l,c){switch(l.type){case"char":return r({op:"char",codes:t?bl(l.code):[l.code],next:c});case"any":return r({op:"any",next:c});case"set":return r({op:"set",test:Jg(l.items,l.negate,t),next:c});case"assert":return r({op:"assert",kind:l.kind,next:c});case"group":return i(l.node,c);case"cat":{let f=c;for(let d=l.nodes.length-1;d>=0;d--)f=i(l.nodes[d],f);return f}case"alt":{let f=l.nodes.map(p=>i(p,c)),d=f.at(-1);for(let p=f.length-2;p>=0;p--)d=r({op:"split",x:f[p],y:d});return d}case"rep":return o(l,c);default:throw new k(`internal: unknown regex node ${l.type}`)}}function o(l,c){let f=c;if(l.max===null){let d=r({op:"split",x:-1,y:c});n[d].x=i(l.node,d),f=d}else for(let d=l.max-l.min;d>0;d--)f=r({op:"split",x:i(l.node,f),y:c});for(let d=0;d<l.min;d++)f=i(l.node,f);return f}let s=i(e,r({op:"match"})),u="",a=s;for(;n[a].op==="char"&&n[a].codes.length===1&&n[a].codes[0]<128;)u+=String.fromCodePoint(n[a].codes[0]),a=n[a].next;return(n[a].op!=="match"||u==="")&&(u=null),{states:n,start:s,literal:u,gen:new Int32Array(n.length).fill(-1),stamp:0}}function Qg(e,t){if(t<=0)return-1;let n=e.codePointAt(t-1);return n>=56320&&n<=57343&&t>=2?e.codePointAt(t-2):n}function ew(e,t,n){if(e==="^")return n===0;if(e==="$")return n===t.length;let r=yl(Qg(t,n)),i=n<t.length&&yl(t.codePointAt(n));return e==="y"?r!==i:e==="B"?r===i:e==="<"?!r&&i:r&&!i}function tw(e,t){return e.op==="char"?e.codes.includes(t):e.op==="any"?!0:e.test(t)}function kl(e,t,n){if(e.literal!==null&&Number.isInteger(n)&&n>=0&&n<=t.length&&!Object.is(n,-0)){let p=t.indexOf(e.literal,n);return p<0?null:{start:p,end:p+e.literal.length}}let{states:r,gen:i}=e,o=t.length,s=[],u=(p,m,h,g,x)=>{for(s.push(m);s.length>0;){let b=s.pop();if(i[b]===x)continue;i[b]=x;let S=r[b];S.op==="split"?s.push(S.y,S.x):S.op==="assert"?ew(S.kind,t,g)&&s.push(S.next):p.push(b,h)}},a=[],l=[],c=null,f=n,d=++e.stamp;for(;;){c===null&&u(a,e.start,f,f,d);let p=f<o?t.codePointAt(f):-1,m=St(p);if(a.length===0){if(c!==null||f>=o)break;f+=m,d=++e.stamp;continue}let h=++e.stamp;for(let g=0;g<a.length;g+=2){let x=a[g],b=a[g+1];if(c!==null&&b>c.start)continue;let S=r[x];if(S.op==="match"){(c===null||b<c.start||b===c.start&&f>c.end)&&(c={start:b,end:f});continue}p!==-1&&tw(S,p)&&u(l,S.next,b,f+m,h)}if(a.length=0,[a,l]=[l,a],d=h,f>=o)break;f+=m}return c}var Fr=new Map,Sl=/[\u0080-\u{10FFFF}]/u,Qe=class{constructor(t,n,r){let{ast:i,groups:o}=Xt(t,r);this.src=t,this.ignoreCase=n,this.groupCount=o,this.source=Gt(i),this.flags=n?"siu":"su";try{this.js=new RegExp(this.source,this.flags)}catch(s){throw new k(`cannot compile regex /${t}/: ${s.message}`,null,"regex engine limit")}this.ast=i,this.nfa=null,this.capture=null,this.captureShape=El(i)}test(t){return this.checkLocale(t),this.js.test(t)}checkLocale(t){if(this.src.includes("[:")&&Sl.test(t))throw new k("POSIX character classes on non-ASCII input require locale support",null,"locale-sensitive character classes");if((this.ignoreCase||/\\[sSwWyB<>]/u.test(this.src))&&Sl.test(t+this.src))throw new k("non-ASCII case folding, classes and word boundaries require locale support",null,"locale-sensitive regex")}search(t,n=0){return this.checkLocale(t),this.nfa===null&&(this.nfa=vl(this.ast,this.ignoreCase)),kl(this.nfa,t,n)}groups(t,n,r){if(this.captureShape.unsafe)throw new k("capture extraction across repeated or alternative groups is not supported",null,"regex capture semantics");let i=this.capture??=new RegExp(this.source,this.flags+"dy");i.lastIndex=n;let o=i.exec(t);if(!o||o.index!==n||n+o[0].length!==r){let s=Array.from(t.slice(r)).length,u=new RegExp(`(?:${this.source})(?=.{${s}}(?![^]))`,this.flags+"dy");u.lastIndex=n,o=u.exec(t)}if(!o)throw new k("capture extraction for this match is not supported",null,"regex capture semantics");return o.indices.map((s,u)=>s===void 0?void 0:{text:o[u],start:s[0],end:s[1]})}};function El(e){let n=(e.nodes??(e.node?[e.node]:[])).map(El),r=n.reduce((s,u)=>s+u.groups,e.type==="group"?1:0),i=e.type==="assert"||(e.type==="group"||e.type==="cat")&&n.every(s=>s.nullable)||e.type==="alt"&&n.some(s=>s.nullable)||e.type==="rep"&&(e.min===0||n[0].nullable),o=e.type==="rep"&&(e.max===null||e.max>1)&&(r>1||r>0&&n[0].nullable);return{groups:r,nullable:i,unsafe:o||e.type==="alt"&&r>0||n.some(s=>s.unsafe)}}function Ee(e,t=!1,n=null){let r=(t?"i":"c")+e,i=Fr.get(r);if(i)return i;Fr.size>=500&&Fr.clear();let o=new Qe(e,t,n);return Fr.set(r,o),o}function bo(e,t,n){for(;;){let r=t.search(e,n);if(!r||r.start!==r.end)return r;if(r.end>=e.length)return null;n=r.end+ke(e,r.end)}}function vo(e,t){let n=[],r=0;for(;;){let i=bo(e,t,r);if(!i)break;n.push(e.slice(r,i.start)),r=i.end}return n.push(e.slice(r)),n}function Tn(e,t,n,r){let i=r!=="first",o=e.length,s="",u=0,a=-1,l=0;for(;u<=o;){let c=t.search(e,u);if(!c)break;let f=c.start===c.end;if(f&&c.start===a&&r!=="nth"){if(c.start>=o)break;let p=ke(e,c.start);s+=e.slice(u,c.start+p),u=c.start+p;continue}l++;let d=n(c.start,c.end,l);if(s+=e.slice(u,c.start)+(d===null?e.slice(c.start,c.end):d),a=c.end,f){if(c.end>=o){u=o;break}let p=ke(e,c.end);s+=e.slice(c.end,c.end+p),u=c.end+p}else u=c.end;if(!i)break}return{out:s+e.slice(u),count:l}}function Tr(e){let t="(){}+?|",n=!1,r=0,i=!1,o="";for(let s=0;s<e.length;s++){let u=e[s];if(i){if(u==="["&&(e[s+1]==="."||e[s+1]==="="))throw new w("feature","regex collating or equivalence class","grep: collating and equivalence classes are not supported");if(u==="["){let a=Ht(e,s);if(a){o+=a.body,s=a.end-1;continue}}o+=u,u==="]"&&(i=!1,n=!0);continue}if(u==="["){o+=u,i=!0,e[s+1]==="^"&&(o+="^",s++),e[s+1]==="]"&&(o+="\\]",s++);continue}if(u==="\\"){let a=e[++s];if(a===void 0)return{error:"trailing backslash (\\)"};if(t.includes(a)){if((a==="+"||a==="?")&&!n){o+="\\"+a,n=!0;continue}if(a==="("&&r++,a===")"&&r--===0)return{error:"Unmatched ) or \\)"};(a==="("||a==="|")&&(n=!1),(a===")"||a==="}")&&(n=!0),o+=a}else o+="^$\\.*[]/bBsSwW<>`'123456789".includes(a)?"\\"+a:a,n=!"bB<>`'".includes(a);continue}if(u==="*"){o+=n?"*":"\\*",n=!0;continue}if(u==="^"){n=!nw(e,s),o+=n?"\\^":"^";continue}if(u==="$"){n=!(s===e.length-1||e[s+1]==="\\"&&(e[s+2]===")"||e[s+2]==="|")),o+=n?"\\$":"$";continue}o+=t.includes(u)?"\\"+u:u,n=!0}return r>0?{error:"Unmatched ( or \\("}:{source:o}}function nw(e,t){if(t===0)return!0;if(t<2||e[t-2]!=="\\"||e[t-1]!=="("&&e[t-1]!=="|")return!1;let n=0;for(let r=t-3;r>=0&&e[r]==="\\";r--)n++;return n%2===0}function _r(e){if(!/\\[1-9]/u.test(e))return!1;let t=new Set,n=[],r=new Set,i=!1,o=0,s=!1,u=[],a=new Set,l=!1;for(let c=0;c<e.length;c++){let f=e[c];if(f==="\\"){let d=e[++c];if(!i&&/[1-9]/u.test(d??"")){let p=Number(d);if(!t.has(p))throw new Error("Invalid back reference");(!a.has(p)||r.has(p))&&(s=!0)}u=[];continue}if(i){f==="]"&&(i=!1);continue}if(f==="["){i=!0,u=[];continue}if(f==="(")n.push({id:++o,entry:new Set(a),branches:[],start:c}),u=[];else if(f==="|"){let d=n.at(-1);d&&d.branches.push(a),a=new Set(d?.entry),u=[]}else if(f===")"){let d=n.pop();if(!d)continue;a=d.branches.reduce((p,m)=>p.intersection(m),a),a.add(d.id),t.add(d.id),u=[...a.difference(d.entry)],l=rw(e.slice(d.start,c+1))}else if(f==="*"||f==="?"||f==="+"){if(f!=="?"&&l)for(let d of u)r.add(d);if(f!=="+")for(let d of u)a.delete(d)}else if(f==="{"){let d=/^\{(\d*)(?:,(\d*))?\}/u.exec(e.slice(c));if(d){Number(d[1])===0&&(a=a.difference(new Set(u)));let p=d[2]===void 0?Number(d[1]):d[2]===""?1/0:Number(d[2]);l&&p>1&&u.forEach(m=>r.add(m)),c+=d[0].length-1}else u=[]}else u=[]}return s}function rw(e){try{return new RegExp(`^(?:${e})$`,"su").test("")}catch{return!0}}var iw=e=>e.type==="set"&&e.items.every(([,t])=>t<128),ow=e=>e?.type==="char"&&e.code<128;function ko(e){return ow(e)||e.type==="any"||iw(e)?!0:e.type==="assert"?e.kind==="^"||e.kind==="$":e.type==="group"||e.type==="rep"?ko(e.node):e.type==="alt"||e.type==="cat"?e.nodes.every(ko):!1}function Lr(e,t){if([...t.matchAll(/\[:([a-z]+):\]/gu)].map(r=>r[1]).some(r=>r!=="space"&&r!=="blank")||/[\u0080-\u{10FFFF}]|\\[1-9bBwW<>]/u.test(t))return!1;try{return ko(Xt(e).ast)}catch{return!1}}function Rr(e){return/[\u0085\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000]/u.test(e)}function be(e){throw new w("feature","PCRE "+e,`PCRE ${e} is not supported`)}function $l(e){let t={captures:0,closed:new Set,names:new Map,stack:[],behind:0,references:!1,risky:!1},n="";for(let r=0;r<e.length;){let i=e[r];if(i==="\\"){let o=Nl(e,r,t,!1);n+=o.source,r=o.end;continue}if(i==="["){let o=aw(e,r,t);n+=o.source,r=o.end;continue}if(i==="("){let o=sw(e,r,t);n+=o.source,r=o.end;continue}if(i===")"){let o=t.stack.pop();o?.capture&&t.closed.add(o.capture),o?.behind&&t.behind--}if("*+?".includes(i)&&(t.behind&&be("variable-length lookbehind"),e[r+1]==="+"&&be("possessive repetition"),i!=="+"&&(t.risky=!0)),i==="|"&&(t.risky=!0),i==="{"){let o=uw(e,r,t);n+=o.source,r=o.end;continue}n+=i==="]"||i==="}"?"\\"+i:i,r++}return t.references&&t.risky&&be("conditional backreference"),n}function sw(e,t,n){let r=!1,i=null,o="(";if(e[t+1]==="*"&&be("control verb"),e[t+1]==="?"){let s=/^\(\?(?:[:=!]|<[=!]|<([A-Za-z_]\w*)>)/u.exec(e.slice(t));if(s||be("group"),o=s[0],r=o==="(?<="||o==="(?<!",!s[1]&&o!=="(?:"&&(n.risky=!0),s[1]){if(i=++n.captures,n.names.has(s[1]))throw new Error("duplicate PCRE capture name");n.names.set(s[1],i)}}else i=++n.captures;return r&&n.behind++,n.stack.push({capture:i,behind:r}),{source:o,end:t+o.length}}function uw(e,t,n){let r=/^\{(\d+)(?:,(\d*))?\}/u.exec(e.slice(t));if(!r)return/^\{[\d, \t]*\}/u.test(e.slice(t))&&be("repetition"),{source:"\\{",end:t+1};if(n.behind&&r[2]!==void 0&&r[1]!==r[2]&&be("variable-length lookbehind"),Number(r[1])>65535||Number(r[2])>65535)throw new Error("PCRE repetition count exceeds 65535");return Number(r[1])===0&&(n.risky=!0),e[t+r[0].length]==="+"&&be("possessive repetition"),{source:r[0],end:t+r[0].length}}function aw(e,t,n){let r=t+1,i="[";for(e[r]==="^"&&(i+="^",r++),e[r]==="]"&&(i+="\\]",r++);r<e.length&&e[r]!=="]";)if(e[r]==="["&&":.=".includes(e[r+1]??"")&&be("character class"),e[r]==="\\"){let o=Nl(e,r,n,!0);i+=o.source,r=o.end}else i+=e[r]==="["?"\\[":e[r],r++;return{source:i+(e[r]==="]"?"]":""),end:r+1}}function Nl(e,t,n,r){let i=e[t+1];if(i===void 0)throw new Error("trailing backslash");if(i==="Q"){let s=e.indexOf("\\E",t+2);return{source:RegExp.escape(e.slice(t+2,s<0?void 0:s)),end:s<0?e.length:s+2}}if(i==="E")return{source:"",end:t+2};if(i==="x"||i==="0"||r&&/[1-7]/u.test(i))return lw(e,t);if(i==="a"||i==="e")return{source:i==="a"?"\\u0007":"\\u001B",end:t+2};if("AzZ".includes(i)&&!r)return{source:i==="A"?"^":"$",end:t+2};if(/[1-9]/u.test(i)&&!r)return(/\d/u.test(e[t+2]??"")||!n.closed.has(Number(i)))&&be("forward or ambiguous backreference"),n.references=!0,{source:"\\"+i,end:t+2};if(i==="k"&&!r){let s=/^\\k<([A-Za-z_]\w*)>/u.exec(e.slice(t));return(!s||!n.closed.has(n.names.get(s[1])))&&be("named backreference"),n.references=!0,{source:s[0],end:t+s[0].length}}if("dDsSwWfnrtbB".includes(i))return{source:"\\"+i,end:t+2};/[A-Za-z0-9]/u.test(i)&&be("escape \\"+i);let o=String.fromCodePoint(e.codePointAt(t+1));return{source:RegExp.escape(o),end:t+1+o.length}}function lw(e,t){let n=e[t+1]==="x",r=(n?/^\\x(?:\{([\da-fA-F]+)\}|([\da-fA-F]{1,2}))/u:/^\\([0-7]{1,3})/u).exec(e.slice(t));if(!r)throw new Error("invalid PCRE character escape");let i=n?16:8,o=parseInt(r[1]??r[2],i);return ze(o)||be("character escape"),{source:`\\u{${o.toString(16)}}`,end:t+r[0].length}}function Eo(e){let t="",n=!1;for(let r=0;r<e.length;r++){let i=e[r];if(i==="\\"){let o=e[++r]??"";t+=n?i+o:cw(o);continue}if(n&&i==="["){if(e[r+1]==="."||e[r+1]==="=")throw new w("feature","regex collating or equivalence class","grep: collating and equivalence classes are not supported");let o=Ht(e,r);if(o){t+=o.body,r=o.end-1;continue}}if(i==="["&&!n){t+="[",n=!0,e[r+1]==="^"&&(t+="^",r++),e[r+1]==="]"&&(t+="\\]",r++);continue}i==="]"&&(n=!1),t+=i}return t}function cw(e){return"^$\\.*+?()[]{}|/bBsSwW<>`'123456789".includes(e)?"\\"+e:RegExp.escape(e)}function fw(e){for(let t=0;t<e.length;t++)if(e[t]==="\\"){if("bBsSwW<>".includes(e[++t]??""))return!0}else if(".[*+?{".includes(e[t]))return!0;return!1}function Zt(e,t=!1){let n=t?{b:"\\y"}:{"<":"(?<!\\w)(?=\\w)",">":"(?<=\\w)(?!\\w)","`":"^","'":"$",s:"[ \\t\\n\\r\\f\\v]",S:"[^ \\t\\n\\r\\f\\v]"},r="",i=!1;for(let o=0;o<e.length;o++){let s=e[o];if(s==="\\"){let u=e[++o];r+=!i&&Object.hasOwn(n,u)?n[u]:s+u,!t&&!i&&/[1-9]/u.test(u)&&/\d/u.test(e[o+1]??"")&&(r+="(?:)")}else s==="["&&(i=!0),s==="]"&&(i=!1),r+=s}return r}var $o=/^\{(?=\d|,)(\d*)(?:,(\d*))?\}/u,dw=/^\\\{(?=\d|,)(\d*)(?:,(\d*))?\\\}/u;function Al(e,t,n){let r=(n?$o:dw).exec(e.slice(t));if(!r&&!n)throw new Error("invalid repetition count");r&&pl(Number(r[1]),r[2]===void 0||r[2]===""?void 0:Number(r[2]))}var Il={__proto__:null,"*":{min:0,max:1/0},"+":{min:1,max:1/0},"?":{min:0,max:1}};function pw(e){if(Il[e])return Il[e];let t=$o.exec(e),n=Number(t[1]);return{min:n,max:t[2]===void 0?n:t[2]===""?1/0:Number(t[2])}}var Ol=(e,t)=>e===0||t===0?0:e===1/0||t===1/0?1/0:e*t;function hw(e,t){let n=Math.max(t.min,1);if(n>t.max)return{min:0,max:0};if(e.min>0&&(t.min===0&&e.min>1||e.max!==1/0&&t.max>n&&(n+1)*e.min>n*e.max+1))return null;let r=Ol(t.max,e.max);return r!==1/0&&r>Or?null:{min:Ol(t.min,e.min),max:r}}function So(e){return e.max===1/0?e.min===0?"*":e.min===1?"+":`{${e.min},}`:e.min===0&&e.max===1?"?":e.min===e.max?`{${e.min}}`:`{${e.min},${e.max}}`}var mw=e=>!e.startsWith("(")&&!/^\\[1-9]/u.test(e);function gw(e,t){if(t.length===1)return e+So(t[0].bounds);let n=t[0].bounds,r=null;for(let i=1;i<t.length;i++){let{bounds:o,text:s}=t[i],u=r===null?hw(n,o):null;if(u){n=u;continue}if(!(r===null&&n.min===n.max&&mw(e))&&o.max>1)throw new Error("stacked quantifier needs ambiguous nesting");r=`(?:${r??e+So(n)})${s}`}return r??e+So(n)}function ww(e,t){let n=t+1;for(e[n]==="^"&&n++;n<e.length;n++){if(e[n]==="\\"){n++;continue}if(e[n]==="]")return n}return e.length-1}function xw(e){let t="",n=-1,r=-1,i=[],o=()=>{i.length>0&&(t=t.slice(0,n)+gw(t.slice(n,r),i)),i=[]},s=a=>{o(),n=t.length,r=-1,t+=a},u=[];for(let a=0;a<e.length;a++){let l=e[a];if(l==="\\"){s(l+(e[++a]??""));continue}if(l==="["){let f=ww(e,a);s(e.slice(a,f+1)),a=f;continue}if(l==="("){o(),u.push(t.length),n=-1,t+=l;continue}if(l===")"){o(),t+=l,n=u.pop()??-1,r=-1;continue}if(l==="|"||l==="^"||l==="$"){o(),t+=l,n=-1;continue}let c=l==="{"?$o.exec(e.slice(a)):null;if(l==="*"||l==="+"||l==="?"||c){let f=c?c[0]:l;if(a+=f.length-1,n<0){t+=f;continue}i.length===0&&(r=t.length),i.push({bounds:pw(f),text:f});continue}s(l)}return o(),t}function No(e,t){let n=-1;for(let r=0;r<e.length;r++){let i=r<=n,o=e[r];if(o==="\\"){let s=e[++r];if(s===void 0)throw new Error("trailing backslash");if(i||s&&"dDxXuUpPkKcC".includes(s))throw new w("feature","regex escape","grep: this regex escape is not supported with GNU semantics");!t&&s==="{"&&Al(e,r-1,!1)}else if(o==="["&&!i)n=hl(e,r);else{if(i)continue;if(t&&o==="{")Al(e,r,!0);else if(t&&o==="("&&e[r+1]==="?")throw new w("feature","regex extension","grep: ECMAScript group extensions are not supported in ERE")}}}function Cl(e,t){let n=[],r=t.has("i")?"isu":"su",i=t.has("x"),o=t.has("w")&&!i;if(t.has("P")&&new Set(e).size>1)return{error:y("grep: -P only supports a single pattern",2)};for(let s of e){!t.has("F")&&!t.has("P")&&No(s,t.has("E"));let u;if(t.has("F"))u=RegExp.escape(s);else if(t.has("P"))u=$l(s);else if(t.has("E"))u=Eo(s);else{let l=Tr(s);if(l.error)return{error:y(`grep: ${l.error}`,2)};u=l.source}let a=u;if(!t.has("F")&&!t.has("P")&&_r(a))return{error:v("feature","grep","conditional backreference","grep: backreferences with conditional or repeated-empty captures are not supported",2)};o&&(u=`(?<![A-Za-z0-9_])(?:${u})(?![A-Za-z0-9_])`),i&&(u=`^(?:${u})$`);try{let l=new RegExp(t.has("F")||t.has("P")?u:Zt(xw(u)),r);if(l.pcre=t.has("P"),l.localeSensitive=t.has("i")||o||!t.has("F")&&fw(a)||l.pcre&&/\\[dD]/u.test(a),l.asciiCompatible=!l.pcre&&l.localeSensitive&&!t.has("i")&&!o&&Lr(Zt(a,!0),s),l.spaceClass=/\[:(?:space|blank):\]|\\[sS]/u.test(s),l.unicodePattern=/[\u0080-\u{10FFFF}]/u.test(s),l.binaryLiteral=!i&&(t.has("F")||!/[\\.^$*+?()[\]{}|]/u.test(u)),t.has("o")&&!t.has("F")&&!t.has("P")&&!i){if(o||/\\[1-9]|\(\?/u.test(u))return{error:v("feature","grep","-o regex extent","grep: only-matching with backreferences, lookarounds or word constraints is not supported",2)};try{l.extent=new Qe(Zt(u,!0),t.has("i"))}catch{return{error:v("feature","grep","-o regex extent","grep: POSIX match extent for this pattern is not supported",2)}}}n.push(l)}catch(l){if(!t.has("P")&&yw(a,t))return{error:v("feature","grep","GNU regex syntax","grep: this GNU regular expression cannot be represented by the JavaScript matcher",2)};let c=t.has("F")?`fixed-string /${r}`:t.has("P")?`PCRE subset /${r}`:t.has("E")?`ERE / ECMAScript /${r}`:`BRE /${r}`;return{error:y(`grep: invalid pattern (${c}): ${l.message}`,2)}}}return{res:n}}function yw(e,t){if(!t.has("E")&&/(?<!\\)\{(?!\d*(?:,\d*)?\})/u.test(e))return!1;try{return Xt(Zt(e,!0)),!0}catch(n){return!!n.gap}}function Ao(e,t,n,r=!1,i=Ve){if(e.length===0)return null;if(!r&&e.some(l=>l.content.includes("\0")&&(n||t.some(c=>!c.binaryLiteral||c.test(l.content)))))return v("feature","grep","binary input","grep: binary input detection and output are not supported",2);let o=/[\u0080-\u{10FFFF}]/u;if(i!==Ve&&t.some(l=>l.localeSensitive)&&(t.some(l=>l.unicodePattern)||e.some(l=>o.test(l.content))))return v("feature","grep","locale",`grep: matching non-ASCII text in the ${i} locale is not supported`,2);let s=t.filter(l=>l.localeSensitive&&(!l.asciiCompatible||l.spaceClass));if(s.length===0)return null;let u=s.some(l=>!l.unicodePattern)&&e.some(l=>/[\u0080-\u{10FFFF}]/u.test(l.content)),a=s.some(l=>l.asciiCompatible&&l.spaceClass)&&e.some(l=>Rr(l.content));return s.some(l=>(u||l.unicodePattern)&&(!l.asciiCompatible||l.spaceClass&&a))?v("feature","grep","non-ASCII regex semantics","grep: locale-sensitive regular expression matching on non-ASCII input is not supported",2):null}var Io=/[*?[]/u,Oo=/\P{ASCII}/u,bw=/[.+*?^${}()|[\]\\/]/u;function $e(e,t={}){try{return vw(e,t)}catch(n){throw n instanceof w?n:new w("feature","glob pattern",`unsupported glob pattern: ${n.message}`)}}function vw(e,t){let n="^",r=!1;for(let i=0;i<e.length;i++){let o=e[i];if(o==="\\"&&i+1<e.length){let s=e[i+1];n+=Fl(s,t.ignoreCase),i++}else if(o==="*"){for(;e[i+1]==="*";)i++;n+=".*"}else if(o==="?")n+=".";else if(o==="["){let s=Tl(e,i,t);if(s?.voided)return/^(?!)$/u;s?(n+=s.source,i=s.end,r||=s.nonAsciiRange):n+="\\["}else n+=Fl(o,t.ignoreCase)}return Sw(new RegExp(n+"(?![\\s\\S])","us"),e,t,r)}function Fl(e,t){return t&&/[a-zA-Z]/u.test(e)?`[${e.toLowerCase()}${e.toUpperCase()}]`:bw.test(e)?"\\"+e:e}function kw(e,t,n){let r=new RegExp(`[${e}]`,"ui"),i=new RegExp(`[${t}]`,"u"),o="";for(let s=0;s<128;s++){let u=String.fromCodePoint(s);(r.test(u)||i.test(u))&&(o+="\\x"+s.toString(16).padStart(2,"0"))}return`[${n?"^":""}${o}]`}function Sw(e,t,n,r){let i=/[?[]/u.test(t),o=Oo.test(t);return{test(s){if(r||n.ignoreCase&&o||(i||n.ignoreCase)&&Oo.test(s))throw new w("feature","non-ASCII glob matching","locale-dependent glob matching of non-ASCII names is not supported");return e.test(s)}}}function Tl(e,t,n){let{ignoreCase:r}=n,i=t+1,o=!1;(e[i]==="!"||e[i]==="^")&&(o=!0,i++);let s="",u="",a=!1,l=!1,c=!1,f=!1,d="",p=0,m="",h=0;for(e[i]==="]"&&(s+="\\]",i++,a=!0,d="]");i<e.length&&e[i]!=="]";i++){let g=e[i];if(g==="["&&(e[i+1]==="."||e[i+1]==="="))throw new w("feature","glob collating or equivalence class","glob collating symbols and equivalence classes are not supported");if(g==="["&&e[i+1]===":"){let x=n.bash?Ew(e,i):Ht(e,i,{unknown:"empty"});if(x){if(!n.bash&&x.body==="")throw new w("feature","glob character class","unknown POSIX classes in command filename patterns are not supported");l&&(f=!0),r?u+=x.body:s+=x.body,i=x.end-1,a=!1,l=!1;continue}if(n.bash)continue}if(g==="-"&&a)h=p,m=d,s+="-",l=!0,a=!1;else{let x=g==="\\"&&i+1<e.length?e[++i]:g;p=s.length,d=x,l&&Oo.test(m+x)&&(c=!0),l&&x.codePointAt(0)<m.codePointAt(0)?s=s.slice(0,h):s+=/[\]\\^[-]/u.test(x)?`\\${x}`:x,a=!l,l=!1}}return i>=e.length?null:f?{voided:!0,end:i}:{source:r?kw(s,u,o):`[${o?"^":""}${s}]`,end:i,nonAsciiRange:c}}function Ew(e,t){let n=e.indexOf(":]",t+2);if(n===-1)return null;let r=e.slice(t+2,n).replace(/\\([\s\S]|$)/gu,"$1");return{body:r==="ascii"?"\\x00-\\x7F":Fn[r]??"",end:n+2}}function _l(e,t){return $e(t).test(e)}function Ll(e){let{value:t,mask:n}=e;if(n===null)return Io.test(t);for(let r=0;r<t.length;r++)if(n[r]==="0"&&Io.test(t[r]))return!0;return!1}function _n(e){let t=n=>!e.mask||e.mask[n]==="0";for(let n=0;n<e.value.length;n++){let r=e.value[n];if(t(n)){if(r==="\\")n++;else if(r==="[")n=$w(e,n,t);else if(/[?*+@!]/u.test(r)&&e.value[n+1]==="("&&t(n+1))return!0}}return!1}function $w(e,t,n){let{value:r}=e,i=t+1;for(/[!^]/u.test(r[i])&&n(i)&&i++,r[i]==="]"&&n(i)&&i++;i<r.length;i++)if(n(i))if(r[i]==="\\")i++;else{if(r[i]==="]")return i;if(r[i]==="["&&/[.:=]/u.test(r[i+1])&&n(i+1)){let o=r.indexOf(r[i+1]+"]",i+2);o!==-1&&(i=o+1)}}return t}var Nw=/[*?[\]^!\\:.=-]/u;function Vt(e){let{value:t,mask:n}=e;if(n===null)return t;let r="";for(let i=0;i<t.length;i++){let o=t[i];r+=n[i]!=="0"&&Nw.test(o)?"\\"+o:o}return r}function Rl(e,t){let n=Vt(e),r=n.match(/[^/]+|\/+/gu)??[],i=Pt(),o=new Set,s=[{path:"",marks:null}],u;try{for(let l=0;l<r.length;l++){let c=r[l];if(c.startsWith("/")||!Io.test(c)){s=s.map(f=>({...f,path:f.path+Iw(c)}));continue}s=Ow(s,c,l===r.length-1,t,o)}let a=s.filter(l=>$(t.cwd,l.path,t.fs).path!==null);for(let l of a)for(let c of l.marks??[])i.add(c);return u=a.filter(l=>l.marks===null).map(l=>l.path).sort(U),u}finally{if(u===void 0)for(let a of o)i.add(a);i.emit(t.notes,"glob","",` while expanding ${JSON.stringify(n)}`),u?.length===0&&r.some(Aw)&&t.notes.add(`glob: no paths matched ${JSON.stringify(n)}; the pattern was left literal.`)}}function Aw(e){for(let t=0;t<e.length;t++)if(e[t]==="\\")t++;else{if(e[t]==="*"||e[t]==="?")return!0;if(e[t]==="[")try{if(Tl(e,t,{bash:!0}))return!0}catch{return!0}}return!1}var Iw=e=>e.replace(/\\(.)/gu,"$1");function Ow(e,t,n,r,i){let o=$e(t,{bash:!0}),s=t.startsWith(".")||t.startsWith("\\."),u=[];for(let a of e){let l=$(r.cwd,a.path||".",r.fs).path;if(!r.fs.isDir(l))continue;let{dirs:c,files:f}=r.fs.listDir(l);for(let d of n?[...c,...f]:c){let p=!s&&d.startsWith(".");if(!p&&a.marks===null)o.test(d)&&u.push({path:a.path+d,marks:null});else if(Cw(o,d)){if(!p){u.push({path:a.path+d,marks:a.marks});continue}let m=L(l,d);i.add(m),u.push({path:a.path+d,marks:[...a.marks??[],m]})}}}return u}function Cw(e,t){try{return e.test(t)}catch{return!0}}var Fo=(e,t)=>e.some(n=>n.test(t)),To=()=>({stdout:"",stderr:"",exitCode:1});function _o(e,t,n,r){let i=0;if(r===1/0){for(let s of se(e))Fo(t,s)!==n&&i++;return i}let o=0;for(;o<e.length&&i<r;){let s=e.indexOf(`
|
|
37
|
-
`,o);s<0&&(s=e.length),
|
|
38
|
-
`),rest:i.slice(1),stdin:t}:null;let o=new Set;for(let{name:s,value:u}of r){if(s==="e"){for(let
|
|
39
|
-
`))o.add(
|
|
40
|
-
or: grep ${
|
|
41
|
-
`,u=!0;continue}if(
|
|
38
|
+
`)}function wg(e,t){let{bytes:n,valid:r}=bg(e,t),i=P(n);if(r)return C(i);let o=`base64: invalid input
|
|
39
|
+
`;return{stdout:i,stderr:o,exitCode:1,events:[...i?[{fd:1,text:i}]:[],{fd:2,text:o}]}}function bg(e,t=!1){let n=e.replace(t?/[^A-Za-z0-9+/=]/gu:/\n/gu,"");try{return{bytes:xn(n),valid:!0}}catch(r){if(!(r instanceof SyntaxError))throw r;return yg(n)}}function yg(e){let t=new Uint8Array(Math.ceil(e.length/4)*3),n=/[A-Za-z0-9+/]*/uy,r=0,i=0,o=!0;for(;i<e.length;){n.lastIndex=i;let s=n.exec(e)[0].length,u=s-s%4;if(u){let h=xn(e.slice(i,i+u));t.set(h,r),r+=h.length,i+=u}if(i===e.length)break;let a=s%4;if(a<2){o=!1;break}let l=Ro.indexOf(e[i]),f=Ro.indexOf(e[i+1]),c=a===3?Ro.indexOf(e[i+2]):0;t[r++]=l<<2|f>>4,a===3&&(t[r++]=f<<4|c>>2);let d=4-a,p=(a===2?f&15:c&3)===0;if(i+=a,i===e.length){o=p;break}if(!p||e.slice(i,i+d)!=="=".repeat(d)){o=!1;break}i+=d}return{bytes:t.subarray(0,r),valid:o}}var xg=["n","N","i","s","w","F","v","l","c","q","u","a","H","I"],kg=["line-number","no-line-number","ignore-case","case-sensitive","word-regexp","fixed-strings","invert-match","files-with-matches","files-without-match","count","quiet","hidden","no-ignore","no-heading","with-filename","no-filename","text","unrestricted"],Jl={short:xg,long:kg,valueShort:["A","B","C"],valueLong:["after-context","before-context","context"],repeatable:["e","regexp"]},vg=new Map(Object.entries({"line-number":"n","no-line-number":"N","ignore-case":"i","case-sensitive":"s","word-regexp":"w","fixed-strings":"F","invert-match":"v","files-with-matches":"l","files-without-match":"L",count:"c",quiet:"q",text:"a",unrestricted:"u","with-filename":"H","no-filename":"I",regexp:"e","after-context":"A","before-context":"B",context:"C"})),Sg=new Set(["no-heading","no-ignore"]),Rn=(e,t)=>new w("feature",e,`rg: ${t}`);function Ql(e){let t={patterns:[],context:[],mode:null,showName:null,ignoreCase:!1,lineNumbers:!1,word:!1,literal:!1,invert:!1,quiet:!1,text:!1,hidden:!1,unrestricted:0};for(let{name:i,value:o}of e.order)Sg.has(i)||$g(t,vg.get(i)??i,o,Mo(i));let n=i=>t.context.findLast(([o])=>o===i)?.[1],r=i=>t.context.findLast(([o])=>o===i)?.[2]??"-"+i;if(t.after=Kl(n("A")??n("C"),n("A")===void 0?r("C"):r("A")),t.before=Kl(n("B")??n("C"),n("B")===void 0?r("C"):r("B")),t.unrestricted>=2&&(t.hidden=!0),t.unrestricted>=3)throw Rn("-uuu","searching binary files is not supported");return t}function $g(e,t,n,r){switch(t){case"i":e.ignoreCase=!0;return;case"s":e.ignoreCase=!1;return;case"n":e.lineNumbers=!0;return;case"N":e.lineNumbers=!1;return;case"l":case"L":case"c":e.mode=t;return;case"H":e.showName="H";return;case"I":e.showName="h";return;case"w":e.word=!0;return;case"F":e.literal=!0;return;case"v":e.invert=!0;return;case"q":e.quiet=!0;return;case"a":e.text=!0;return;case"e":e.patterns.push(n);return;case"hidden":e.hidden=!0;return;case"u":e.unrestricted++;return;case"A":case"B":case"C":e.context.push([t,n,r]);return;default:throw Rn(Mo(t),`${Mo(t)} is not supported`)}}function Kl(e,t){if(e===void 0)return 0;if(!/^\d+$/u.test(e))throw Rn(`${t} value`,`error parsing flag ${t}: value is not a valid number`);return Number(e)}var Mo=e=>(e.length===1?"-":"--")+e;function ef(e,t){return t?e.flatMap(n=>["-e",n]):["-e",e.length===1?e[0]:e.map(n=>`(?:${n})`).join("|")]}var Eg=[[/\\[1-9]/u,"backreference"],[/\(\?<?[=!]/u,"look-around"],[/\\[QE]/u,String.raw`\Q…\E literal span`]];function Ng(e){for(let t=0;t<e.length;t++){let n=e[t];if(n===`
|
|
40
|
+
`)return!0;if(n!=="\\")continue;let r=e[t+1];if(r==="n"||r==="x"&&/^x\{?0*a\}?/iu.test(e.slice(t+1)))return!0;t++}return!1}function tf(e,t){if(!t)for(let n of e){for(let[r,i]of Eg)if(r.test(n))throw Rn(i,`${i} is not supported; ripgrep's regex engine rejects it too`);if(Ng(n))throw Rn("newline in a pattern","a newline in a pattern is not supported; ripgrep rejects one outside multiline mode")}}var $=class extends Error{constructor(t,n=null,r=null){super(t),this.line=n,this.gap=r}},nf=new Set(["BEGIN","END","BEGINFILE","ENDFILE","function","func","if","else","while","for","do","break","continue","next","nextfile","exit","return","delete","in","getline","print","printf","switch","case","default"]),Po={__proto__:null,length:[0,1],substr:[2,3],index:[2,2],split:[2,3],sub:[2,3],gsub:[2,3],gensub:[3,4],match:[2,3],sprintf:[1,1/0],sin:[1,1],cos:[1,1],atan2:[2,2],exp:[1,1],log:[1,1],sqrt:[1,1],int:[1,1],rand:[0,0],srand:[0,1],tolower:[1,1],toupper:[1,1],close:[1,2],fflush:[0,1],systime:[0,0],strtonum:[1,1],and:[2,1/0],or:[2,1/0],xor:[2,1/0],lshift:[2,2],rshift:[2,2],compl:[1,1],typeof:[1,1],isarray:[1,1]},jr=new Map([["system","system() is not supported: this terminal runs no processes"],["strftime","strftime() is not supported (gawk extension)"],["mktime","mktime() is not supported (gawk extension)"],["asort","asort() is not supported (gawk extension)"],["asorti","asorti() is not supported (gawk extension)"],["patsplit","patsplit() is not supported (gawk extension)"]]),rf=new Set([...Object.keys(Po),...jr.keys()]),Mn=5e6,Do=100,Ee=1e6,zr="this terminal runs no processes";function Hr(e,t,n){switch(e){case"+":return t+n;case"-":return t-n;case"*":return t*n;case"/":return t/n;case"%":return t%n;default:return t**n}}var of={__proto__:null,n:10,t:9,r:13,f:12,v:11,a:7,b:8},Ag='^$.[]|()*+?{}\\/"',Uo=1e3,sf=e=>e!==void 0&&/[0-9a-fA-F]/u.test(e),uf=e=>e!==void 0&&e>="0"&&e<="7",Bo=class{constructor(t,n,r,i){this.src=t,this.i=0,this.warn=n,this.tables=r,this.ignoreCase=i,this.groups=0}fail(t){throw new $(`invalid regex /${this.src}/: ${t}`)}peek(){return this.src[this.i]}literal(){let t=this.src.codePointAt(this.i);return this.i+=Pe(t),this.charNode(t)}charNode(t){let n=this.ignoreCase?this.tables.fold(t):[t];return n.length===1?{type:"char",code:t}:{type:"set",negate:!1,items:n.map(r=>[r,r])}}parse(){return this.alternation(0)}alternation(t){let n=[this.concatenation(t)];for(;this.peek()==="|";)this.i++,n.push(this.concatenation(t));return n.length===1?n[0]:{type:"alt",nodes:n}}concatenation(t){let n=[];for(;!this.endsConcatenation(t);)n.push(this.quantified(this.atom(n.length===0,t)));return n.length===1?n[0]:{type:"cat",nodes:n}}endsConcatenation(t){let n=this.peek();return n===void 0||n==="|"||n===")"&&t>0}quantified(t){let n=t;for(;;){let r=this.peek();if(r==="*"){this.i++,n={type:"rep",node:n,min:0,max:null};continue}if(r==="+"){this.i++,n={type:"rep",node:n,min:1,max:null};continue}if(r==="?"){this.i++,n={type:"rep",node:n,min:0,max:1};continue}if(r==="{"){let i=/^\{(\d*)(?:(,)(\d*))?\}/u.exec(this.src.slice(this.i));if(!i&&/^\{[\d,]*\}/u.test(this.src.slice(this.i))&&this.fail("invalid content of {}"),!i||i[1]===""&&i[2]===void 0)return n;let o=i[1]===""?0:Number(i[1]),s=i[2]===void 0?o:i[3]===""?null:Number(i[3]);if(s!==null&&s<o&&this.fail(`invalid interval {${o},${s}}`),o>Uo||s!==null&&s>Uo)throw new $(`interval count above ${Uo} is not supported`,null,"regex interval limit");this.i+=i[0].length,n={type:"rep",node:n,min:o,max:s};continue}return n}}atom(t,n){let r=this.peek();if(r==="("){this.i++;let i=++this.groups,o=this.alternation(n+1);return this.peek()!==")"&&this.fail("missing `)`"),this.i++,{type:"group",index:i,node:o}}return r==="["?this.bracket():r==="\\"?this.escape():(this.i++,r==="."?{type:"any"}:r==="^"||r==="$"?{type:"assert",kind:r}:((r==="*"||r==="+"||r==="?")&&!t&&this.fail(`unexpected \`${r}\``),this.i--,this.literal()))}escape(){this.i++;let t=this.peek();return t===void 0&&this.fail("trailing backslash"),this.i++,t==="y"?{type:"assert",kind:"y"}:t==="<"||t===">"||t==="B"?{type:"assert",kind:t}:t==="`"?{type:"assert",kind:"^"}:t==="'"?{type:"assert",kind:"$"}:t==="s"||t==="S"?{type:"set",negate:t==="S",items:this.tables.ranges("space")}:t==="w"||t==="W"?{type:"set",negate:t==="W",items:this.tables.ranges("word")}:(t==="b"&&this.warn?.("regexp escape sequence `\\b' is a backspace here, as in gawk; `\\y' is the word boundary"),this.charNode(this.escapedCode(t,!0)))}escapedCode(t,n){if(t in of)return of[t];if(uf(t)){let i=t;for(;i.length<3&&uf(this.peek());)i+=this.src[this.i++];return af(i,8)}if(t==="x"&&sf(this.peek())){let i="";for(;i.length<2&&sf(this.peek());)i+=this.src[this.i++];return af(i,16)}let r=this.src.codePointAt(this.i-1);return!Ag.includes(t)&&n&&this.warn?.(`regexp escape sequence \`\\${String.fromCodePoint(r)}' is not a known regexp operator`),this.i+=Pe(r)-1,r}bracket(){this.i++;let t=!1;this.peek()==="^"&&(t=!0,this.i++);let n=[],r=!0;for(;;){this.i>=this.src.length&&this.fail("unterminated bracket expression");let i=this.peek();if(i==="]"&&!r){this.i++;break}if(r=!1,i==="["&&this.src[this.i+1]===":"){let s=this.src.indexOf(":]",this.i+2);if(s!==-1){let u=this.src.slice(this.i+2,s),a=this.tables.ranges(this.ignoreCase?Fr(u):u);a===void 0&&this.fail(`invalid character class \`[:${u}:]\``),n.push(...a),this.i=s+2;continue}}let o=this.bracketChar();if(this.peek()==="-"&&this.src[this.i+1]!=="]"&&this.src[this.i+1]!==void 0){this.i++;let s=this.bracketChar(),u=this.ignoreCase?this.tables.foldRange(o,s):s<o?null:[[o,s]];u===null&&this.fail("invalid range end"),n.push(...u)}else this.ignoreCase?n.push(...this.tables.fold(o).map(s=>[s,s])):n.push([o,o])}return{type:"set",negate:t,items:n}}bracketChar(){let t=this.peek();if(t==="["&&(this.src[this.i+1]==="."||this.src[this.i+1]==="=")){let r=this.src.indexOf(this.src[this.i+1]+"]",this.i+2);if(r!==-1&&r>this.i+2){Array.from(this.src.slice(this.i+2,r)).length!==1&&this.fail("invalid collation character");let i=this.src.codePointAt(this.i+2);return this.i=r+2,i}}if(t==="\\"){this.i++,this.peek()===void 0&&this.fail("trailing backslash");let r=this.src[this.i++];return this.escapedCode(r,!1)}let n=this.src.codePointAt(this.i);return this.i+=Pe(n),n}};function Xr(e,t=null,n=Q(J),r=!1){let i=new Bo(e,t,n,r);return{ast:i.parse(),groups:i.groups}}function af(e,t){let n=Number.parseInt(e,t);if(n>=128)throw new $("non-ASCII regex byte escapes are not supported",null,"regex byte escapes");return n}var Og=e=>`\\u{${e.toString(16)}}`,Gr=e=>e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122?String.fromCodePoint(e):Og(e);function Ig(e,t){if(e==="^"||e==="$")return e;let n=t.assertions();return e==="y"?n.boundary:e==="B"?n.inside:n[e]}function qo(e,t=Q(J)){let n=r=>qo(r,t);switch(e.type){case"char":return Gr(e.code);case"any":return".";case"set":return`[${e.negate?"^":""}${e.items.map(([r,i])=>r===i?Gr(r):`${Gr(r)}-${Gr(i)}`).join("")}]`;case"assert":return Ig(e.kind,t);case"group":return`(${n(e.node)})`;case"cat":return e.nodes.map(n).join("");case"alt":return`(?:${e.nodes.map(n).join("|")})`;case"rep":{let r=`(?:${n(e.node)})`;return e.max===null?e.min===0?`${r}*`:e.min===1?`${r}+`:`${r}{${e.min},}`:e.min===0&&e.max===1?`${r}?`:`${r}{${e.min},${e.max}}`}default:throw new $(`internal: unknown regex node ${e.type}`)}}var Cg=5e4;function Fg(e,t){let n=r=>{for(let i=0;i<e.length;i++)if(r>=e[i][0]&&r<=e[i][1])return!0;return!1};return t?r=>!n(r):n}function lf(e,t=Q(J)){let n=[],r=l=>{if(n.length>=Cg)throw new $("regex too large",null,"regex state limit");return n.push(l),n.length-1};function i(l,f){switch(l.type){case"char":return r({op:"char",codes:[l.code],next:f});case"any":return r({op:"any",next:f});case"set":return r({op:"set",test:Fg(l.items,l.negate),next:f});case"assert":return r({op:"assert",kind:l.kind,next:f});case"group":return i(l.node,f);case"cat":{let c=f;for(let d=l.nodes.length-1;d>=0;d--)c=i(l.nodes[d],c);return c}case"alt":{let c=l.nodes.map(p=>i(p,f)),d=c.at(-1);for(let p=c.length-2;p>=0;p--)d=r({op:"split",x:c[p],y:d});return d}case"rep":return o(l,f);default:throw new $(`internal: unknown regex node ${l.type}`)}}function o(l,f){let c=f;if(l.max===null){let d=r({op:"split",x:-1,y:f});n[d].x=i(l.node,d),c=d}else for(let d=l.max-l.min;d>0;d--)c=r({op:"split",x:i(l.node,c),y:f});for(let d=0;d<l.min;d++)c=i(l.node,c);return c}let s=i(e,r({op:"match"})),u="",a=s;for(;n[a].op==="char"&&n[a].codes.length===1&&n[a].codes[0]<128;)u+=String.fromCodePoint(n[a].codes[0]),a=n[a].next;return(n[a].op!=="match"||u==="")&&(u=null),{states:n,start:s,literal:u,isWord:l=>t.has("word",l),gen:new Int32Array(n.length).fill(-1),stamp:0}}function Tg(e,t){if(t<=0)return-1;let n=e.codePointAt(t-1);return n>=56320&&n<=57343&&t>=2?e.codePointAt(t-2):n}function _g(e,t,n,r){if(e==="^")return n===0;if(e==="$")return n===t.length;let i=r(Tg(t,n)),o=n<t.length&&r(t.codePointAt(n));return e==="y"?i!==o:e==="B"?i===o:e==="<"?!i&&o:i&&!o}function Lg(e,t){return e.op==="char"?e.codes.includes(t):e.op==="any"?!0:e.test(t)}function ff(e,t,n){if(e.literal!==null&&Number.isInteger(n)&&n>=0&&n<=t.length&&!Object.is(n,-0)){let p=t.indexOf(e.literal,n);return p<0?null:{start:p,end:p+e.literal.length}}let{states:r,gen:i}=e,o=t.length,s=[],u=(p,h,m,g,b)=>{for(s.push(h);s.length>0;){let x=s.pop();if(i[x]===b)continue;i[x]=b;let S=r[x];S.op==="split"?s.push(S.y,S.x):S.op==="assert"?_g(S.kind,t,g,e.isWord)&&s.push(S.next):p.push(x,m)}},a=[],l=[],f=null,c=n,d=++e.stamp;for(;;){f===null&&u(a,e.start,c,c,d);let p=c<o?t.codePointAt(c):-1,h=Pe(p);if(a.length===0){if(f!==null||c>=o)break;c+=h,d=++e.stamp;continue}let m=++e.stamp;for(let g=0;g<a.length;g+=2){let b=a[g],x=a[g+1];if(f!==null&&x>f.start)continue;let S=r[b];if(S.op==="match"){(f===null||x<f.start||x===f.start&&c>f.end)&&(f={start:x,end:c});continue}p!==-1&&Lg(S,p)&&u(l,S.next,x,c+h,m)}if(a.length=0,[a,l]=[l,a],d=m,c>=o)break;c+=h}return f}var Zr=new Map,at=class{constructor(t,n,r,i=Q(J)){let{ast:o,groups:s}=Xr(t,r,i,n);this.src=t,this.ignoreCase=n,this.tables=i,this.groupCount=s,this.source=qo(o,i),this.flags="su";try{this.js=new RegExp(this.source,this.flags)}catch(u){throw new $(`cannot compile regex /${t}/: ${u.message}`,null,"regex engine limit")}this.ast=o,this.nfa=null,this.capture=null,this.captureShape=cf(o)}test(t){return this.checkCase(t),this.js.test(t)}checkCase(t){if(this.ignoreCase&&It.test(t+this.src))throw new $("case-insensitive matching over Cyrillic Extended-C letters is not supported",null,"locale-sensitive regex")}search(t,n=0){return this.checkCase(t),this.nfa===null&&(this.nfa=lf(this.ast,this.tables)),ff(this.nfa,t,n)}groups(t,n,r){if(this.captureShape.unsafe)throw new $("capture extraction across repeated or alternative groups is not supported",null,"regex capture semantics");let i=this.capture??=new RegExp(this.source,this.flags+"dy");i.lastIndex=n;let o=i.exec(t);if(!o||o.index!==n||n+o[0].length!==r){let s=Array.from(t.slice(r)).length,u=new RegExp(`(?:${this.source})(?=.{${s}}(?![^]))`,this.flags+"dy");u.lastIndex=n,o=u.exec(t)}if(!o)throw new $("capture extraction for this match is not supported",null,"regex capture semantics");return o.indices.map((s,u)=>s===void 0?void 0:{text:o[u],start:s[0],end:s[1]})}};function cf(e){let n=(e.nodes??(e.node?[e.node]:[])).map(cf),r=n.reduce((s,u)=>s+u.groups,e.type==="group"?1:0),i=e.type==="assert"||(e.type==="group"||e.type==="cat")&&n.every(s=>s.nullable)||e.type==="alt"&&n.some(s=>s.nullable)||e.type==="rep"&&(e.min===0||n[0].nullable),o=e.type==="rep"&&(e.max===null||e.max>1)&&(r>1||r>0&&n[0].nullable);return{groups:r,nullable:i,unsafe:o||e.type==="alt"&&r>0||n.some(s=>s.unsafe)}}function Fe(e,t=!1,n=null,r=Q(J)){let i=(t?"i":"c")+r.name+"\0"+e,o=Zr.get(i);if(o)return o;Zr.size>=500&&Zr.clear();let s=new at(e,t,n,r);return Zr.set(i,s),s}function Wo(e,t,n){for(;;){let r=t.search(e,n);if(!r||r.start!==r.end)return r;if(r.end>=e.length)return null;n=r.end+Ie(e,r.end)}}function jo(e,t){let n=[],r=0;for(;;){let i=Wo(e,t,r);if(!i)break;n.push(e.slice(r,i.start)),r=i.end}return n.push(e.slice(r)),n}function Pn(e,t,n,r){let i=r!=="first",o=e.length,s="",u=0,a=-1,l=0;for(;u<=o;){let f=t.search(e,u);if(!f)break;let c=f.start===f.end;if(c&&f.start===a&&r!=="nth"){if(f.start>=o)break;let p=Ie(e,f.start);s+=e.slice(u,f.start+p),u=f.start+p;continue}l++;let d=n(f.start,f.end,l);if(s+=e.slice(u,f.start)+(d===null?e.slice(f.start,f.end):d),a=f.end,c){if(f.end>=o){u=o;break}let p=Ie(e,f.end);s+=e.slice(f.end,f.end+p),u=f.end+p}else u=f.end;if(!i)break}return{out:s+e.slice(u),count:l}}function Yr(e,t){let n="(){}+?|",r=!1,i=0,o=!1,s="";for(let u=0;u<e.length;u++){let a=e[u];if(o){if(a==="["&&(e[u+1]==="."||e[u+1]==="="))throw new w("feature","regex collating or equivalence class","grep: collating and equivalence classes are not supported");if(a==="["){let l=Xt(e,u,{classes:t});if(l){s+=l.body,u=l.end-1;continue}}s+=a,a==="]"&&(o=!1,r=!0);continue}if(a==="["){s+=a,o=!0,e[u+1]==="^"&&(s+="^",u++),e[u+1]==="]"&&(s+="\\]",u++);continue}if(a==="\\"){let l=e[++u];if(l===void 0)return{error:"trailing backslash (\\)"};if(n.includes(l)){if((l==="+"||l==="?")&&!r){s+="\\"+l,r=!0;continue}if(l==="("&&i++,l===")"&&i--===0)return{error:"Unmatched ) or \\)"};(l==="("||l==="|")&&(r=!1),(l===")"||l==="}")&&(r=!0),s+=l}else s+="^$\\.*[]/bBsSwW<>`'123456789".includes(l)?"\\"+l:l,r=!"bB<>`'".includes(l);continue}if(a==="*"){s+=r?"*":"\\*",r=!0;continue}if(a==="^"){r=!Rg(e,u),s+=r?"\\^":"^";continue}if(a==="$"){r=!(u===e.length-1||e[u+1]==="\\"&&(e[u+2]===")"||e[u+2]==="|")),s+=r?"\\$":"$";continue}s+=n.includes(a)?"\\"+a:a,r=!0}return i>0?{error:"Unmatched ( or \\("}:{source:s}}function Rg(e,t){if(t===0)return!0;if(t<2||e[t-2]!=="\\"||e[t-1]!=="("&&e[t-1]!=="|")return!1;let n=0;for(let r=t-3;r>=0&&e[r]==="\\";r--)n++;return n%2===0}function Vr(e){if(!/\\[1-9]/u.test(e))return!1;let t=new Set,n=[],r=new Set,i=!1,o=0,s=!1,u=[],a=new Set,l=!1;for(let f=0;f<e.length;f++){let c=e[f];if(c==="\\"){let d=e[++f];if(!i&&/[1-9]/u.test(d??"")){let p=Number(d);if(!t.has(p))throw new Error("Invalid back reference");(!a.has(p)||r.has(p))&&(s=!0)}u=[];continue}if(i){c==="]"&&(i=!1);continue}if(c==="["){i=!0,u=[];continue}if(c==="(")n.push({id:++o,entry:new Set(a),branches:[],start:f}),u=[];else if(c==="|"){let d=n.at(-1);d&&d.branches.push(a),a=new Set(d?.entry),u=[]}else if(c===")"){let d=n.pop();if(!d)continue;a=d.branches.reduce((p,h)=>p.intersection(h),a),a.add(d.id),t.add(d.id),u=[...a.difference(d.entry)],l=Mg(e.slice(d.start,f+1))}else if(c==="*"||c==="?"||c==="+"){if(c!=="?"&&l)for(let d of u)r.add(d);if(c!=="+")for(let d of u)a.delete(d)}else if(c==="{"){let d=/^\{(\d*)(?:,(\d*))?\}/u.exec(e.slice(f));if(d){Number(d[1])===0&&(a=a.difference(new Set(u)));let p=d[2]===void 0?Number(d[1]):d[2]===""?1/0:Number(d[2]);l&&p>1&&u.forEach(h=>r.add(h)),f+=d[0].length-1}else u=[]}else u=[]}return s}function Mg(e){try{return new RegExp(`^(?:${e})$`,"su").test("")}catch{return!0}}var Pg="bBsSwW";function Dn(e,t){let n="";for(let r=0;r<e.length;){let i=e[r];if(i==="["){let l=Dg(e,r,t);n+=l.text,r=l.end;continue}let o=i==="\\",s=e.codePointAt(r+(o?1:0)),u=(o?1:0)+Pe(s),a=o&&Pg.includes(e[r+1])?null:t.fold(s);n+=a===null||a.length===1?e.slice(r,r+u):`[${String.fromCodePoint(...a)}]`,r+=u}return n}function df(e,t){let n="";for(let r of e){let i=t.fold(r.codePointAt(0));n+=i.length===1?RegExp.escape(r):`[${String.fromCodePoint(...i)}]`}return n}function Dg(e,t,n){let r=t+1,i="[";e[r]==="^"&&(i+="^",r++);let o=!0;for(;;){let s=e[r];if(s==="]"&&!o)return{text:i+"]",end:r+1};if(o=!1,s==="["&&":.=".includes(e[r+1])){let l=e[r+1],f=e.indexOf(l+"]",r+2);i+=l===":"?`[:${Fr(e.slice(r+2,f))}:]`:e.slice(r,f+2),r=f+2;continue}let u=e.codePointAt(r),a=r+Pe(u);if(e[a]==="-"&&e[a+1]!==void 0&&e[a+1]!=="]"){let l=e.codePointAt(a+1),f=a+1+Pe(l);i+=Ug(u,l,e.slice(r,f),n),r=f;continue}i+=String.fromCodePoint(...n.fold(u)),r=a}}function Ug(e,t,n,r){let i=r.foldRange(e,t);if(i===null)throw new Error("Invalid range end");return i.length===1&&i[0][0]===e&&i[0][1]===t?n:i.map(([o,s])=>o===s?String.fromCodePoint(o):`${String.fromCodePoint(o)}-${String.fromCodePoint(s)}`).join("")}function Ne(e){throw new w("feature","PCRE "+e,`PCRE ${e} is not supported`)}function pf(e){let t={captures:0,closed:new Set,names:new Map,stack:[],behind:0,references:!1,risky:!1},n="";for(let r=0;r<e.length;){let i=e[r];if(i==="\\"){let o=hf(e,r,t,!1);n+=o.source,r=o.end;continue}if(i==="["){let o=Wg(e,r,t);n+=o.source,r=o.end;continue}if(i==="("){let o=Bg(e,r,t);n+=o.source,r=o.end;continue}if(i===")"){let o=t.stack.pop();o?.capture&&t.closed.add(o.capture),o?.behind&&t.behind--}if("*+?".includes(i)&&(t.behind&&Ne("variable-length lookbehind"),e[r+1]==="+"&&Ne("possessive repetition"),i!=="+"&&(t.risky=!0)),i==="|"&&(t.risky=!0),i==="{"){let o=qg(e,r,t);n+=o.source,r=o.end;continue}n+=i==="]"||i==="}"?"\\"+i:i,r++}return t.references&&t.risky&&Ne("conditional backreference"),n}function Bg(e,t,n){let r=!1,i=null,o="(";if(e[t+1]==="*"&&Ne("control verb"),e[t+1]==="?"){let s=/^\(\?(?:[:=!]|<[=!]|<([A-Za-z_]\w*)>)/u.exec(e.slice(t));if(s||Ne("group"),o=s[0],r=o==="(?<="||o==="(?<!",!s[1]&&o!=="(?:"&&(n.risky=!0),s[1]){if(i=++n.captures,n.names.has(s[1]))throw new Error("duplicate PCRE capture name");n.names.set(s[1],i)}}else i=++n.captures;return r&&n.behind++,n.stack.push({capture:i,behind:r}),{source:o,end:t+o.length}}function qg(e,t,n){let r=/^\{(\d+)(?:,(\d*))?\}/u.exec(e.slice(t));if(!r)return/^\{[\d, \t]*\}/u.test(e.slice(t))&&Ne("repetition"),{source:"\\{",end:t+1};if(n.behind&&r[2]!==void 0&&r[1]!==r[2]&&Ne("variable-length lookbehind"),Number(r[1])>65535||Number(r[2])>65535)throw new Error("PCRE repetition count exceeds 65535");return Number(r[1])===0&&(n.risky=!0),e[t+r[0].length]==="+"&&Ne("possessive repetition"),{source:r[0],end:t+r[0].length}}function Wg(e,t,n){let r=t+1,i="[";for(e[r]==="^"&&(i+="^",r++),e[r]==="]"&&(i+="\\]",r++);r<e.length&&e[r]!=="]";)if(e[r]==="["&&":.=".includes(e[r+1]??"")&&Ne("character class"),e[r]==="\\"){let o=hf(e,r,n,!0);i+=o.source,r=o.end}else i+=e[r]==="["?"\\[":e[r],r++;return{source:i+(e[r]==="]"?"]":""),end:r+1}}function hf(e,t,n,r){let i=e[t+1];if(i===void 0)throw new Error("trailing backslash");if(i==="Q"){let s=e.indexOf("\\E",t+2);return{source:RegExp.escape(e.slice(t+2,s<0?void 0:s)),end:s<0?e.length:s+2}}if(i==="E")return{source:"",end:t+2};if(i==="x"||i==="0"||r&&/[1-7]/u.test(i))return jg(e,t);if(i==="a"||i==="e")return{source:i==="a"?"\\u0007":"\\u001B",end:t+2};if("AzZ".includes(i)&&!r)return{source:i==="A"?"^":"$",end:t+2};if(/[1-9]/u.test(i)&&!r)return(/\d/u.test(e[t+2]??"")||!n.closed.has(Number(i)))&&Ne("forward or ambiguous backreference"),n.references=!0,{source:"\\"+i,end:t+2};if(i==="k"&&!r){let s=/^\\k<([A-Za-z_]\w*)>/u.exec(e.slice(t));return(!s||!n.closed.has(n.names.get(s[1])))&&Ne("named backreference"),n.references=!0,{source:s[0],end:t+s[0].length}}if("dDsSwWfnrtbB".includes(i))return{source:"\\"+i,end:t+2};/[A-Za-z0-9]/u.test(i)&&Ne("escape \\"+i);let o=String.fromCodePoint(e.codePointAt(t+1));return{source:RegExp.escape(o),end:t+1+o.length}}function jg(e,t){let n=e[t+1]==="x",r=(n?/^\\x(?:\{([\da-fA-F]+)\}|([\da-fA-F]{1,2}))/u:/^\\([0-7]{1,3})/u).exec(e.slice(t));if(!r)throw new Error("invalid PCRE character escape");let i=n?16:8,o=parseInt(r[1]??r[2],i);return Xe(o)||Ne("character escape"),{source:`\\u{${o.toString(16)}}`,end:t+r[0].length}}function Ho(e,t){let n="",r=!1;for(let i=0;i<e.length;i++){let o=e[i];if(o==="\\"){let s=e[++i]??"";n+=r?o+s:zg(s);continue}if(r&&o==="["){if(e[i+1]==="."||e[i+1]==="=")throw new w("feature","regex collating or equivalence class","grep: collating and equivalence classes are not supported");let s=Xt(e,i,{classes:t});if(s){n+=s.body,i=s.end-1;continue}}if(o==="["&&!r){n+="[",r=!0,e[i+1]==="^"&&(n+="^",i++),e[i+1]==="]"&&(n+="\\]",i++);continue}o==="]"&&(r=!1),n+=o}return n}function zg(e){return"^$\\.*+?()[]{}|/bBsSwW<>`'123456789".includes(e)?"\\"+e:RegExp.escape(e)}function Hg(e){for(let t=0;t<e.length;t++)if(e[t]==="\\"){if("bBsSwW<>".includes(e[++t]??""))return!0}else if(".[*+?{".includes(e[t]))return!0;return!1}function Un(e,t=!1,n=Q(J)){let r=n.assertions(),i=t?{b:"\\y"}:{"<":r["<"],">":r[">"],b:r.boundary,B:r.inside,w:r.word,W:r.nonWord,s:r.space,S:r.nonSpace,"`":"^","'":"$"},o="",s=!1;for(let u=0;u<e.length;u++){let a=e[u];if(a==="\\"){let l=e[++u];o+=!s&&Object.hasOwn(i,l)?i[l]:a+l,!t&&!s&&/[1-9]/u.test(l)&&/\d/u.test(e[u+1]??"")&&(o+="(?:)")}else a==="["&&(s=!0),a==="]"&&(s=!1),o+=a}return o}var Go=/^\{(?=\d|,)(\d*)(?:,(\d*))?\}/u,Gg=/^\\\{(?=\d|,)(\d*)(?:,(\d*))?\\\}/u;function mf(e,t,n){let r=(n?Go:Gg).exec(e.slice(t));if(!r&&!n)throw new Error("invalid repetition count");r&&$a(Number(r[1]),r[2]===void 0||r[2]===""?void 0:Number(r[2]))}var gf={__proto__:null,"*":{min:0,max:1/0},"+":{min:1,max:1/0},"?":{min:0,max:1}};function Xg(e){if(gf[e])return gf[e];let t=Go.exec(e),n=Number(t[1]);return{min:n,max:t[2]===void 0?n:t[2]===""?1/0:Number(t[2])}}var wf=(e,t)=>e===0||t===0?0:e===1/0||t===1/0?1/0:e*t;function Zg(e,t){let n=Math.max(t.min,1);if(n>t.max)return{min:0,max:0};if(e.min>0&&(t.min===0&&e.min>1||e.max!==1/0&&t.max>n&&(n+1)*e.min>n*e.max+1))return null;let r=wf(t.max,e.max);return r!==1/0&&r>Ar?null:{min:wf(t.min,e.min),max:r}}function zo(e){return e.max===1/0?e.min===0?"*":e.min===1?"+":`{${e.min},}`:e.min===0&&e.max===1?"?":e.min===e.max?`{${e.min}}`:`{${e.min},${e.max}}`}var Yg=e=>!e.startsWith("(")&&!/^\\[1-9]/u.test(e);function Vg(e,t){if(t.length===1)return e+zo(t[0].bounds);let n=t[0].bounds,r=null;for(let i=1;i<t.length;i++){let{bounds:o,text:s}=t[i],u=r===null?Zg(n,o):null;if(u){n=u;continue}if(!(r===null&&n.min===n.max&&Yg(e))&&o.max>1)throw new Error("stacked quantifier needs ambiguous nesting");r=`(?:${r??e+zo(n)})${s}`}return r??e+zo(n)}function Kg(e,t){let n=t+1;for(e[n]==="^"&&n++;n<e.length;n++){if(e[n]==="\\"){n++;continue}if(e[n]==="]")return n}return e.length-1}function Jg(e){let t="",n=-1,r=-1,i=[],o=()=>{i.length>0&&(t=t.slice(0,n)+Vg(t.slice(n,r),i)),i=[]},s=a=>{o(),n=t.length,r=-1,t+=a},u=[];for(let a=0;a<e.length;a++){let l=e[a];if(l==="\\"){s(l+(e[++a]??""));continue}if(l==="["){let c=Kg(e,a);s(e.slice(a,c+1)),a=c;continue}if(l==="("){o(),u.push(t.length),n=-1,t+=l;continue}if(l===")"){o(),t+=l,n=u.pop()??-1,r=-1;continue}if(l==="|"||l==="^"||l==="$"){o(),t+=l,n=-1;continue}let f=l==="{"?Go.exec(e.slice(a)):null;if(l==="*"||l==="+"||l==="?"||f){let c=f?f[0]:l;if(a+=c.length-1,n<0){t+=c;continue}i.length===0&&(r=t.length),i.push({bounds:Xg(c),text:c});continue}s(l)}return o(),t}function Xo(e,t,n=!1){let r=-1;for(let i=0;i<e.length;i++){let o=i<=r,s=e[i];if(s==="\\"){let u=e[++i];if(u===void 0)throw new Error("trailing backslash");if(o||u&&"dDxXuUpPkKcC".includes(u))throw new w("feature","regex escape","grep: this regex escape is not supported with GNU semantics");!t&&u==="{"&&mf(e,i-1,!1)}else if(s==="["&&!o)r=Ea(e,i,n);else{if(o)continue;if(t&&s==="{")mf(e,i,!0);else if(t&&s==="("&&e[i+1]==="?")throw new w("feature","regex extension","grep: ECMAScript group extensions are not supported in ERE")}}}function Qg(e){for(let t=0;t<e.length;t++)if(e[t]==="\\"&&/[1-9]/u.test(e[++t]??""))return!0;return!1}function bf(e,t,n=J){let r=Q(n),i=[],o=t.has("x"),s=t.has("w")&&!o;if(t.has("P")&&new Set(e).size>1)return{error:y("grep: -P only supports a single pattern",2)};for(let u of e){let a=!t.has("F")&&!t.has("P");a&&Xo(u,t.has("E"),r.multibyte);let l=a&&Qg(u),f=t.has("i")&&!t.has("P")&&!l,c=t.has("i")&&!f?"isu":"su",d;if(t.has("F"))d=f?df(u,r):RegExp.escape(u);else if(t.has("P"))d=pf(u);else if(t.has("E"))d=Ho(f?Dn(u,r):u,r);else{let h=Yr(f?Dn(u,r):u,r);if(h.error)return{error:y(`grep: ${h.error}`,2)};d=h.source}let p=d;if(a&&Vr(p))return{error:k("feature","grep","conditional backreference","grep: backreferences with conditional or repeated-empty captures are not supported",2)};s&&(d=`(?<!${r.assertions().word})(?:${d})(?!${r.assertions().word})`),o&&(d=`^(?:${d})$`);try{let h=new RegExp(a?Un(Jg(d),!1,r):d,c);h.pcre=t.has("P"),h.localeSensitive=h.pcre?t.has("i")||s||Hg(p)||/\\[dD]/u.test(p):t.has("i")&&l,h.folded=f,h.extendedC=f&&It.test(u),h.unicodePattern=/[\u0080-\u{10FFFF}]/u.test(u);let m=t.has("F")||!$f.test(u);if(h.binaryLiteral=!o&&!s&&m,m&&u.isWellFormed()&&(f||!t.has("i"))&&(h.literal={pattern:u,tables:r}),t.has("o")&&a&&!o){if(s||/\\[1-9]|\(\?/u.test(d))return{error:k("feature","grep","-o regex extent","grep: only-matching with backreferences, lookarounds or word constraints is not supported",2)};try{h.extent=new at(Un(d,!0,r),!1,null,r)}catch{return{error:k("feature","grep","-o regex extent","grep: POSIX match extent for this pattern is not supported",2)}}}i.push(h)}catch(h){if(!t.has("P")&&ew(p,t))return{error:k("feature","grep","GNU regex syntax","grep: this GNU regular expression cannot be represented by the JavaScript matcher",2)};let m=t.has("F")?`fixed-string /${c}`:t.has("P")?`PCRE subset /${c}`:t.has("E")?`ERE / ECMAScript /${c}`:`BRE /${c}`;return{error:y(`grep: invalid pattern (${m}): ${h.message}`,2)}}}return{res:i}}function ew(e,t){if(!t.has("E")&&/(?<!\\)\{(?!\d*(?:,\d*)?\})/u.test(e))return!1;try{return Xr(Un(e,!0)),!0}catch(n){return!!n.gap}}function yf({pattern:e,tables:t},n){return[...e].map(r=>(n?t.fold(r.codePointAt(0)):[r.codePointAt(0)]).map(o=>q(String.fromCodePoint(o))))}function xf(e,t){return t.every(n=>n.literal?(n.literalMask??=yf(n.literal,n.folded),!vf(e,n.literalMask)):!1)}function kf(e,t,n,r=J){let i=Q(r);return t.every(o=>(n||!$f.test(o))&&o.isWellFormed()&&!vf(e,yf({pattern:o,tables:i},!1)))}function vf(e,t){for(let n=0;n+t.length<=e.length;n++)if(Sf(e,n,t,0))return!0;return!1}function Sf(e,t,n,r){return r===n.length?!0:n[r].some(i=>i.every((o,s)=>e[t+s]===o)&&Sf(e,t+i.length,n,r+1))}var $f=/[\\.^$*+?()[\]{}|]/u;function Zo(e,t,n,r=!1,i=J){if(e.length===0)return null;if(e.some(a=>a.content===void 0))return k("feature","grep","binary input","grep: binary input detection and output are not supported",2);if(!r&&e.some(a=>a.content.includes("\0")&&(n||t.some(l=>!l.binaryLiteral||l.test(a.content)))))return k("feature","grep","binary input","grep: binary input detection and output are not supported",2);let o=/[\u0080-\u{10FFFF}]/u;if(i!==J&&t.some(a=>a.localeSensitive||a.folded)&&(t.some(a=>a.unicodePattern)||e.some(a=>o.test(a.content))))return k("feature","grep","locale",`grep: matching non-ASCII text in the ${i} locale is not supported`,2);if(t.some(a=>a.extendedC)||t.some(a=>a.folded)&&e.some(a=>It.test(a.content)))return k("feature","grep","locale-sensitive regex","grep: case-insensitive matching over Cyrillic Extended-C letters is not supported",2);let s=t.filter(a=>a.localeSensitive);if(s.length===0||!(s.some(a=>a.unicodePattern)||e.some(a=>o.test(a.content))))return null;let u=s.some(a=>a.pcre)?"PCRE matching":"case-insensitive matching with backreferences";return k("feature","grep","non-ASCII regex semantics",`grep: ${u} on non-ASCII input is not supported`,2)}var Yo=/[*?[]/u,Vo=/\P{ASCII}/u,tw=/[.+*?^${}()|[\]\\/]/u;function Te(e,t={}){try{return nw(e,t)}catch(n){throw n instanceof w?n:new w("feature","glob pattern",`unsupported glob pattern: ${n.message}`)}}function nw(e,t){let n="^",r=!1;for(let i=0;i<e.length;i++){let o=e[i];if(o==="\\"&&i+1<e.length){let s=e[i+1];n+=Ef(s,t.ignoreCase),i++}else if(o==="*"){for(;e[i+1]==="*";)i++;n+=".*"}else if(o==="?")n+=".";else if(o==="["){let s=Nf(e,i,t);if(s?.voided)return/^(?!)$/u;s?(n+=s.source,i=s.end,r||=s.nonAsciiRange):n+="\\["}else n+=Ef(o,t.ignoreCase)}return iw(new RegExp(n+"(?![\\s\\S])","us"),e,t,r)}function Ef(e,t){return t&&/[a-zA-Z]/u.test(e)?`[${e.toLowerCase()}${e.toUpperCase()}]`:tw.test(e)?"\\"+e:e}function rw(e,t,n){let r=new RegExp(`[${e}]`,"ui"),i=new RegExp(`[${t}]`,"u"),o="";for(let s=0;s<128;s++){let u=String.fromCodePoint(s);(r.test(u)||i.test(u))&&(o+="\\x"+s.toString(16).padStart(2,"0"))}return`[${n?"^":""}${o}]`}function iw(e,t,n,r){let i=/[?[]/u.test(t),o=Vo.test(t);return{test(s){if(r||n.ignoreCase&&o||(i||n.ignoreCase)&&Vo.test(s))throw new w("feature","non-ASCII glob matching","locale-dependent glob matching of non-ASCII names is not supported");return e.test(s)}}}function Nf(e,t,n){let{ignoreCase:r}=n,i=t+1,o=!1;(e[i]==="!"||e[i]==="^")&&(o=!0,i++);let s="",u="",a=!1,l=!1,f=!1,c=!1,d="",p=0,h="",m=0;for(e[i]==="]"&&(s+="\\]",i++,a=!0,d="]");i<e.length&&e[i]!=="]";i++){let g=e[i];if(g==="["&&(e[i+1]==="."||e[i+1]==="="))throw new w("feature","glob collating or equivalence class","glob collating symbols and equivalence classes are not supported");if(g==="["&&e[i+1]===":"){let b=n.bash?ow(e,i):Xt(e,i,{unknown:"empty"});if(b){if(!n.bash&&b.body==="")throw new w("feature","glob character class","unknown POSIX classes in command filename patterns are not supported");l&&(c=!0),r?u+=b.body:s+=b.body,i=b.end-1,a=!1,l=!1;continue}if(n.bash)continue}if(g==="-"&&a)m=p,h=d,s+="-",l=!0,a=!1;else{let b=g==="\\"&&i+1<e.length?e[++i]:g;p=s.length,d=b,l&&Vo.test(h+b)&&(f=!0),l&&b.codePointAt(0)<h.codePointAt(0)?s=s.slice(0,m):s+=/[\]\\^[-]/u.test(b)?`\\${b}`:b,a=!l,l=!1}}return i>=e.length?null:c?{voided:!0,end:i}:{source:r?rw(s,u,o):`[${o?"^":""}${s}]`,end:i,nonAsciiRange:f}}function ow(e,t){let n=e.indexOf(":]",t+2);if(n===-1)return null;let r=e.slice(t+2,n).replace(/\\([\s\S]|$)/gu,"$1");return{body:r==="ascii"?"\\x00-\\x7F":Ot[r]??"",end:n+2}}function Af(e,t){return Te(t).test(e)}function Of(e){let{value:t,mask:n}=e;if(n===null)return Yo.test(t);for(let r=0;r<t.length;r++)if(n[r]==="0"&&Yo.test(t[r]))return!0;return!1}function Bn(e){let t=n=>!e.mask||e.mask[n]==="0";for(let n=0;n<e.value.length;n++){let r=e.value[n];if(t(n)){if(r==="\\")n++;else if(r==="[")n=sw(e,n,t);else if(/[?*+@!]/u.test(r)&&e.value[n+1]==="("&&t(n+1))return!0}}return!1}function sw(e,t,n){let{value:r}=e,i=t+1;for(/[!^]/u.test(r[i])&&n(i)&&i++,r[i]==="]"&&n(i)&&i++;i<r.length;i++)if(n(i))if(r[i]==="\\")i++;else{if(r[i]==="]")return i;if(r[i]==="["&&/[.:=]/u.test(r[i+1])&&n(i+1)){let o=r.indexOf(r[i+1]+"]",i+2);o!==-1&&(i=o+1)}}return t}var uw=/[*?[\]^!\\:.=-]/u;function en(e){let{value:t,mask:n}=e;if(n===null)return t;let r="";for(let i=0;i<t.length;i++){let o=t[i];r+=n[i]!=="0"&&uw.test(o)?"\\"+o:o}return r}function If(e,t){let n=en(e),r=n.match(/[^/]+|\/+/gu)??[],i=Zt(),o=new Set,s=[{path:"",marks:null}],u;try{for(let l=0;l<r.length;l++){let f=r[l];if(f.startsWith("/")||!Yo.test(f)){s=s.map(c=>({...c,path:c.path+lw(f)}));continue}s=fw(s,f,l===r.length-1,t,o)}let a=s.filter(l=>v(t.cwd,l.path,t.fs,{follow:!1}).path!==null);for(let l of a)for(let f of l.marks??[])i.add(f);return u=a.filter(l=>l.marks===null).map(l=>l.path).sort(B),u}finally{if(u===void 0)for(let a of o)i.add(a);i.emit(t.notes,"glob","",` while expanding ${JSON.stringify(n)}`),u?.length===0&&r.some(aw)&&t.notes.add(`glob: no paths matched ${JSON.stringify(n)}; the pattern was left literal.`)}}function aw(e){for(let t=0;t<e.length;t++)if(e[t]==="\\")t++;else{if(e[t]==="*"||e[t]==="?")return!0;if(e[t]==="[")try{if(Nf(e,t,{bash:!0}))return!0}catch{return!0}}return!1}var lw=e=>e.replace(/\\(.)/gu,"$1");function fw(e,t,n,r,i){let o=Te(t,{bash:!0}),s=t.startsWith(".")||t.startsWith("\\."),u=[];for(let a of e){let l=v(r.cwd,a.path||".",r.fs).path;if(!r.fs.isDir(l))continue;let{dirs:f,files:c,links:d}=r.fs.listDir(l),p=n?d:d.filter(h=>r.fs.isDir(v(l,h,r.fs).path));for(let h of n?[...f,...c,...p]:[...f,...p]){let m=!s&&h.startsWith(".");if(!m&&a.marks===null)o.test(h)&&u.push({path:a.path+h,marks:null});else if(cw(o,h)){if(!m){u.push({path:a.path+h,marks:a.marks});continue}let g=G(l,h);i.add(g),u.push({path:a.path+h,marks:[...a.marks??[],g]})}}}return u}function cw(e,t){try{return e.test(t)}catch{return!0}}var Jo=(e,t)=>e.some(n=>n.test(t)),Qo=()=>({stdout:"",stderr:"",exitCode:1});function es(e,t,n,r){let i=0;if(r===1/0){for(let s of pe(e))Jo(t,s)!==n&&i++;return i}let o=0;for(;o<e.length&&i<r;){let s=e.indexOf(`
|
|
41
|
+
`,o);s<0&&(s=e.length),Jo(t,e.slice(o,s))!==n&&i++,o=s+1}return i}function Ff(e,t,n){let r=[],i=!1;for(let{name:o,content:s,recursive:u}of e){let a={...n,showName:n.showName??u,separate:i&&n.hasContext};dw(pe(s),t,o,a,r)&&(i=!0)}return i?C(he(r)):Qo()}function dw(e,t,n,r,i){let{invert:o,after:s,before:u,max:a,hasContext:l}=r,f=-1,c=0,d=0;for(let p=0;p<e.length&&!(c===a&&d===0);p++){let h=Jo(t,e[p])!==o,m=a!==void 0&&c>=a;if(h&&!m){c++,c===1&&r.separate&&i.push("--");let g=Math.max(0,p-u);l&&f>=0&&g>f+1&&i.push("--");for(let b=Math.max(g,f+1);b<p;b++)Ko(e[b],n,b+1,t,r,!1,i);Ko(e[p],n,p+1,t,r,!0,i),f=p,d=s;continue}d>0&&(Ko(e[p],n,p+1,t,r,!1,i),f=p,d--)}return c>0}function Ko(e,t,n,r,i,o,s){if(!i.only){s.push(Cf(e,t,n,o,i));return}if(o===i.invert)return;let u=0;for(;u<e.length;){let a=null;for(let l of r){let f;if(l.extent)f=l.extent.search(e,u);else{let c=l.scan??=new RegExp(l.source,l.flags+"g");c.lastIndex=u;let d=c.exec(e);if(d&&d[0]===""&&l.pcre)throw new w("feature","PCRE empty match extent","only-matching with empty PCRE matches is not supported");f=d?{start:d.index,end:d.index+d[0].length}:null}f&&(!a||f.start<a.start||f.start===a.start&&f.end>a.end)&&(a=f)}if(!a)break;if(a.end===a.start){u=a.end+Ie(e,a.end);continue}s.push(Cf(e.slice(a.start,a.end),t,n,o,i)),u=a.end}}function Cf(e,t,n,r,i){let o=r?":":"-";return(i.showName?(t??"(standard input)")+o:"")+(i.showLine?n+o:"")+e}function Tf(e,t,{mode:n,invert:r,showName:i,max:o=1/0}){let s=[],u=!1,a=n==="c"?o:Math.min(1,o);for(let{name:l,content:f,recursive:c}of e){let d=es(f,t,r,a);d>0&&(u=!0);let p=l??"(standard input)";n==="c"?s.push(i??c?p+":"+d:String(d)):d>0==(n==="l")&&s.push(p)}return{stdout:he(s),stderr:"",exitCode:u?0:1}}function _f(e,t,n){let r=e.order.filter(s=>["e","f","file"].includes(s.name)),i=e.positional;if(r.length===0)return i.length?{patterns:i[0].split(`
|
|
42
|
+
`),rest:i.slice(1),stdin:t}:null;let o=new Set;for(let{name:s,value:u}of r){if(s==="e"){for(let f of u.split(`
|
|
43
|
+
`))o.add(f);continue}let a=rt("grep",[u],n,t);if(a.failed)return{error:y(a.stderr,2)};let l=a.inputs[0];for(let f of pe(l.content))o.add(f);l.shared&&(t="")}return{patterns:[...o],rest:i,stdin:t}}var Lf="[-i] [-a|-I] [-s] [-v] [-n] [-r|-R] [-w] [-x] [-o] [-E|-F|-G|-P] [-l] [-L] [-c] [-q] [-m N] [-h] [-H] [-A N] [-B N] [-C N] [--include=GLOB] [--exclude=GLOB] [--exclude-dir=GLOB]",pw=`grep ${Lf} PATTERN [PATH...]
|
|
44
|
+
or: grep ${Lf} [-e PATTERN] [-f FILE] ... [PATH...]`,hw=["i","v","n","r","R","l","L","c","w","x","h","H","o","E","F","G","P","q","I","a","s"],mw=["A","B","C","m"],Df={short:hw,long:["text","no-messages"],valueShort:mw,repeatable:["e","f","file","include","exclude","exclude-dir"]};function Uf(e){try{return N(e,Df).flags.has("q")}catch{return!1}}function Kr(e,t,n){let r;try{r=N(t,Df)}catch(m){return Y(m,"grep",`grep: ${m.message}`,2)}let{flags:i,values:o}=r,s=_f(r,e,n);if(!s)return de(pw,2);if(s.error)return s.error;let{patterns:u,rest:a}=s;e=s.stdin;let l=xw(i);if(l)return l;let f;try{f=bf(u,i,n.locale)}catch(m){return Y(m,"grep",`grep: ${m.message}`,2)}if(f.error)return f.error;let c=kw(o);if(c.error)return c.error;if(c.max===0&&(!i.has("L")||i.has("q")))return Qo();if(c.max!==0&&n.stdinFile&&(i.has("q")||i.has("l")||i.has("L")||o.has("m"))&&(a.length===0||a.includes("-")))return k("feature","grep","partial stdin reads","grep: early termination on shared file input is not supported",2);let d=i.has("r")||i.has("R"),p=$w(r,n),h=r.order.findLast(m=>["a","I","text"].includes(m.name))?.name;p.ignoreBinary=h==="I"&&c.max!==0,p.forceText=h==="a"||h==="text",p.silent=i.has("s")||i.has("no-messages"),p.follow=i.has("R");try{return gw(e,a,n,d,p,f,i,c)}finally{yw(p,n.notes)}}function gw(e,t,n,r,i,o,s,u){if(s.has("q"))return ww(e,t,n,r,i,o.res,s.has("v"));let a=qf(r,e,t,n,i);u.max===0&&X(n,e);let l=a.inputs;i.name.length>0&&(l=l.filter(g=>Wf(g,i))),u.max!==0&&(l=l.map(g=>Bf(g,i,o.res,s.has("v"))));let f=u.max===0?null:Zo(l,o.res,s.has("v"),i.forceText,n.locale);if(f)return f;let c=vw(s,t.length),d=s.has("v"),p={showName:c,invert:d,showLine:s.has("n"),only:s.has("o"),...u},h=["l","L","c"].find(g=>s.has(g)),m;try{m=h?Tf(l,o.res,{...p,mode:h}):Ff(l,o.res,p)}catch(g){return g instanceof $&&g.gap?k("feature","grep",g.gap,`grep: ${g.message}`,2):Y(g,"grep",`grep: ${g.message}`,2)}return a.failed?{stdout:m.stdout,stderr:a.stderr+m.stderr,exitCode:2}:m}function ww(e,t,n,r,i,o,s){let u="",a=!1;for(let l of t.length?t.map(f=>[f]):[[]]){let f=qf(r,e,l,n,i);u+=f.stderr,a||=f.failed,(l.includes("-")||l.includes("/dev/stdin")&&!n.stdinFile)&&(e="");for(let c of f.inputs){if(!Wf(c,i))continue;let d=Bf(c,i,o,s),p=Zo([d],o,s,i.forceText,n.locale);if(p)return p.stderr=u+p.stderr,p;if(es(d.content,o,s,1)>0)return{stdout:"",stderr:u,exitCode:0}}}return{stdout:"",stderr:u,exitCode:a?2:1}}function Bf(e,t,n,r){if(e.content===void 0){if(!r&&xf(e.bytes,n))return{...e,content:""};if(!t.ignoreBinary)return e;if(!bw(e.bytes,Rf))throw new w("feature","late binary detection","grep: binary detection after the initial input buffer is not supported");return Mf(e,t)}if(!e.content.includes("\0")||t.forceText)return e;if(!t.ignoreBinary)return/^[\0\n]+$/u.test(e.content)&&n.some(i=>i.test(""))===r?{...e,content:""}:e;if(A(e.content.slice(0,e.content.indexOf("\0"))).length>=Rf)throw new w("feature","late binary detection","grep: binary detection after the initial input buffer is not supported");return Mf(e,t)}var Rf=96*1024;function Mf(e,t){let n=e.name===null||e.name==="/dev/stdin"?t.stdinPath:G(t.cwd,e.name);return n?t.binary.add(n):t.binaryStdin=!0,{...e,content:""}}function bw(e,t){if(e.length<=t)return!0;for(let n=t;n<=t+3&&n<=e.length;n++)if(pt(e.subarray(0,n))!==void 0)return!1;return!0}function yw(e,t){let n="Binary input is treated as text with -a.";ht(t,{command:"grep",action:"skipped",noun:["binary file","binary files"],paths:e.binary,explanation:n}),e.binaryStdin&&t.add("grep: skipped binary standard input. "+n),ht(t,{command:"grep",action:"excluded",noun:["entry","entries"],paths:e.excluded,context:" by --include/--exclude/--exclude-dir rules"})}function xw(e){if(e.has("h")&&e.has("H"))return k("option","grep","-h -H","grep: combining -h and -H is not supported");let t=["l","L","c"].filter(r=>e.has(r));if(t.length>1)return k("option","grep","combined output modes",`grep: ${t.map(r=>`-${r}`).join(" / ")} are mutually exclusive`);let n=["E","F","G","P"].filter(r=>e.has(r));return n.length>1?y(`grep: ${n.map(r=>`-${r}`).join(" / ")} are mutually exclusive`,2):null}function kw(e){let t={A:0,B:0,m:void 0};for(let n of["C","A","B","m"]){if(!e.has(n))continue;let r=we(e.get(n),"grep: -"+n);if(r.error)return n==="m"&&(r.error.exitCode=2),r;n==="C"?t.A=t.B=r.value:t[n]=r.value}return{after:t.A,before:t.B,max:t.m,hasContext:["A","B","C"].some(n=>e.has(n))}}function vw(e,t){return e.has("h")?!1:e.has("H")||t>1?!0:void 0}function qf(e,t,n,r,i){if(!e){let a=se("grep",n,t,r,{read:"maybe-text"});return{...a,stderr:i.silent?"":a.stderr,inputs:a.inputs.map(l=>l.name==="-"?{...l,name:null}:l)}}let o=[],s="",u=!1;for(let a of n.length?n:["."]){if(a==="-"||a==="/dev/stdin"||a==="/dev/null"){let d=rt("grep",[a],r,t);o.push(...d.inputs.map(p=>({...p,name:a==="-"?null:a}))),(a==="-"||a==="/dev/stdin")&&(t="");continue}let{path:l,error:f}=R(r,"grep",a);if(r.fs.isFile(l)){o.push({name:a,...ts(r,l)});continue}if(f){s+=`grep: ${a}: ${f}
|
|
45
|
+
`,u=!0;continue}if(Ew(a,i.dir)){i.excluded.add(l);continue}let c=d=>d===l||i.dir.length===0||!ns(i.dir,et(d))?!0:(i.excluded.add(d),!1);for(let d of Oe(r.fs,l,1/0,c)){if(d.kind==="link"){if(!i.follow)continue;let h=Sw(d.path,Pf(n.length?a:"",l,d.path),r,i);h?.input&&o.push(h.input),h?.error&&(s+=h.error,u=!0);continue}if(d.kind!=="file")continue;let p=d.path;o.push({name:Pf(n.length?a:"",l,p),...ts(r,p),recursive:!0})}}return{inputs:o,stderr:i.silent?"":s,failed:u}}function Sw(e,t,n,r){let i=v(n.cwd,e,n.fs),o=n.fs.isDir(i.path);if(!(o?r.dir.length===0||!ns(r.dir,et(e)):jf(et(e),r.name)))return r.excluded.add(e),null;if(o)throw new w("option","-R",`following a symbolic link to a directory is not supported: ${t}`);return i.error?{error:`grep: ${t}: ${i.error}
|
|
46
|
+
`}:{input:{name:t,...ts(n,i.path),recursive:!0}}}function ts(e,t){let{text:n,bytes:r}=mt(e.fs,t);return n===void 0?{content:void 0,bytes:r}:{content:n}}function $w(e,t){let n=e.order.filter(i=>i.name==="include"||i.name==="exclude").map(i=>({include:i.name==="include",re:Te(i.value)})),r=(e.values.get("exclude-dir")??[]).map(i=>Te(i));return{name:n,dir:r,binary:new Set,excluded:new Set,cwd:t.cwd,stdinPath:t.stdinHandle?.path}}function ns(e,t){return e.some(n=>n.test(t))}function Wf(e,t){return e.name===null||jf(et(e.name),t.name)?!0:(t.excluded.add(G(t.cwd,e.name)),!1)}function jf(e,t){if(t.length===0)return!0;let n=null;for(let r of t)r.re.test(e)&&(n=r);return n?n.include:!t[0].include}function Ew(e,t){return t.length===0||e.endsWith("/")?!1:ns(t,e.slice(e.lastIndexOf("/")+1))}function Pf(e,t,n){let r=ze(t,n);return e===""?r:e.endsWith("/")?e+r:e+"/"+r}var qn=(e,t)=>k("feature","rg",e,`rg: ${t}`,2);function zf(e,t,n){let r=O(e)??e.note;return r?k(r.kind,"rg",r.detail,t,2):k(n,"rg",e.detail??t.replace(/^rg: /u,""),t,2)}function Gf(e,t,n){let r,i;try{i=N(t,Jl),r=Ql(i)}catch(d){return zf(d,d.message.startsWith("rg: ")?d.message:`rg: ${d.message}`,"option")}let o=[...i.positional];if(!r.patterns.length){if(!o.length)return qn("usage","a pattern is required");r.patterns.push(o.shift())}try{tf(r.patterns,r.literal)}catch(d){return zf(d,d.message,"feature")}let u=!o.length&&!!n.stdinPiped?{roots:[],recursive:!1,stdin:!0}:Ow(o,n,r.hidden);if(u.error)return u.error;if(!i.flags.has("no-ignore")&&!r.unrestricted&&u.recursive){let d=Iw(u.roots,n);if(d)return qn("ignore rules",`${JSON.stringify(d)} would change which files are searched, and its rules are not implemented`)}let a=Nw(o,u,r,n),l=r.text?null:Cw(o,n);if(l)return qn("named binary file",`${JSON.stringify(l)} is binary, and reporting a binary match is not supported`);let f=Aw(a,r,n);return f?qn(f.detail,f.message):(u.stdin||o.length?1:a.length)===0?{stdout:"",exitCode:2,stderr:`rg: No files were searched, which means ripgrep probably applied a filter you didn't expect.
|
|
42
47
|
Running with --debug will show why files are being skipped.
|
|
43
|
-
`}:
|
|
44
|
-
`).some(
|
|
48
|
+
`}:Fw(e,r,o,u,n)}function Nw(e,t,n,r){let i=e.map(o=>v(r.cwd,o,r.fs).path).filter(Boolean).map(o=>({path:o,named:!0}));for(let o of t.roots)for(let s of Oe(r.fs,o)){if(s.kind!=="file")continue;let u=ze(o==="/"?"/":o,s.path).split("/");(n.hidden||u.every(a=>!a.startsWith(".")))&&i.push({path:s.path,named:!1})}return i}function Aw(e,t,n){for(let{path:r,named:i}of e){if(n.fs.isDir(r))continue;let{text:o,bytes:s}=mt(n.fs,r);if(o!==void 0&&!o.startsWith("\uFEFF")||(s===void 0?o.includes("\0"):s.includes(0))&&!i&&!t.text)continue;let a=JSON.stringify(ze(n.cwd==="/"?"/":n.cwd,r)||r);if(o===void 0){if(!t.invert&&!t.ignoreCase&&kf(s,t.patterns,t.literal,n.locale))continue;return{detail:"unreadable bytes",message:`${a} holds bytes that are not text, and searching them is not supported`}}if(o.startsWith("\uFEFF"))return{detail:"byte-order mark",message:`${a} begins with a byte-order mark, which ripgrep strips before matching`}}return null}function Ow(e,t,n){let r=[],i=!1;for(let s of e){let u=v(t.cwd,s,t.fs);u.path!==null&&t.fs.isDir(u.path)&&r.push(u.path),s.split("/").some(a=>a.startsWith(".")&&a!=="."&&a!=="..")&&(i=!0)}e.length||r.push(t.cwd);let o=r.length>0;return!n&&o&&i&&e.length?{error:qn("named hidden path","a hidden path named beside a directory is searched by ripgrep but skipped while walking, and both cannot apply at once")}:{roots:r,recursive:o}}function Iw(e,t){let n=l=>ze(t.cwd==="/"?"/":t.cwd,l)||l,r=(l,f=!0)=>{for(let c of e){for(let d of Oe(t.fs,c))if(et(d.path)===l&&rs(d.path,f,t))return d.path;for(let d=c;d!=="/";d=ge(d)){let p=v(ge(d),l,t.fs);if(p.path!==null&&rs(p.path,f,t))return p.path}}return null},i=r(".ignore")??r(".rgignore");if(i)return n(i);let o=r(".git",!1);if(!o)return null;let s=v(o,"info/exclude",t.fs).path,u=s!==null&&rs(s,!0,t)?s:null,a=r(".gitignore")??u;return a?n(a):null}function rs(e,t,n){if(!t||n.fs.isDir(e))return!0;let r=v("/",e,n.fs).path,{text:i}=mt(n.fs,r??e);return(i??" ").split(`
|
|
49
|
+
`).some(o=>o.trim()!==""&&!o.trimStart().startsWith("#"))}function Cw(e,t){for(let n of e){let r=v(t.cwd,n,t.fs);if(r.path===null||t.fs.isDir(r.path))continue;let{text:i,bytes:o}=mt(t.fs,r.path);if(o===void 0?i?.includes("\0"):o.includes(0))return n}return null}function Fw(e,t,n,r,i){let o=t.literal?["-F"]:["-P"];t.ignoreCase&&o.push("-i"),t.lineNumbers&&o.push("-n"),t.word&&o.push("-w"),t.invert&&o.push("-v"),t.quiet&&o.push("-q"),t.mode&&o.push("-"+t.mode),t.showName&&o.push("-"+t.showName),o.push(t.text?"-a":"-I"),t.after&&o.push("-A",String(t.after)),t.before&&o.push("-B",String(t.before)),r.recursive&&o.push("-r"),r.recursive&&!t.hidden&&o.push("--exclude=.*","--exclude-dir=.[!.]*","--exclude-dir=..?*"),o.push(...ef(t.patterns,t.literal)),r.stdin||o.push("--",...n.length?n:["."]);let s=new Set(i.notes),u=Kr(e,o,i);return Mw(i.notes,s,r),Rw(Tw(u,t),n,t.patterns)}function Tw(e,t){if(t.mode!=="c")return e;let n=e.stdout.split(`
|
|
45
50
|
`).filter(r=>r!==""&&r!=="0"&&!r.endsWith(":0"));return{...e,stdout:n.length?n.join(`
|
|
46
51
|
`)+`
|
|
47
|
-
`:""}}var
|
|
48
|
-
`;o&&i.push({fd:2,text:o});let s={...t,stdout:"",stderr:t.stderr+o,exitCode:r||t.exitCode,events:i,unordered:!1},u=
|
|
49
|
-
`,"n"],["\r","r"],[" ","t"],["\v","v"]]);function
|
|
50
|
-
`,"n"],["\r","r"],[" ","t"],["\v","v"],['"','"'],["\\","\\"]]);function
|
|
51
|
-
`,!0)}}return p.result.exitCode=p.failed?1:0,p.result}function
|
|
52
|
-
`,!0);if(u.error)return a(`cannot stat ${o}: ${u.error}`);if(i.fs.isDir(u.path))return n.recursive?
|
|
53
|
-
`,!1,!0);n.sources.add(u.path)}let l
|
|
54
|
-
`,!0),
|
|
55
|
-
`,!1,!0);r.sources.add(t)}let{dirs:p,files:m}=s.fs.listDir(t);if(
|
|
56
|
-
`,!0),!1),
|
|
57
|
-
`))}function ec(e){if(e.outputOverlap)throw new w("feature","copy output buffering","buffered verbose output sharing a copied file is not supported")}function tc(e,t,n){if(e===t)return!0;let r=n.fileIdentity?.(e);return r!==void 0&&r===n.fileIdentity(t)}function
|
|
58
|
-
`);if(r.path==="/tmp")i="Device or resource busy";else if(!n.writable||!
|
|
59
|
-
`);n.verbose&&
|
|
60
|
-
`,1)}function
|
|
61
|
-
`),!1),s=e.replace(/\/+$/u,"")||e,u
|
|
62
|
-
`,1),!0}function oc(e,t,n=2){n===1?e.stdout+=t:e.stderr+=t,e.events.push({fd:n,text:t})}function uc(e,t,n){let{flags:r,positional:i}=
|
|
63
|
-
`,r.failed=!0}function
|
|
64
|
-
`,e.failed=!0}
|
|
52
|
+
`:""}}var Hf=new Map([["No such file or directory",2],["Not a directory",20],["Is a directory",21]]),_w=e=>e.replaceAll(/^(rg: .*: )([A-Z][a-z].*)$/gmu,(t,n,r)=>Hf.has(r)?`${n}${r} (os error ${Hf.get(r)})`:t),Lw=/^rg: (?:invalid pattern[^\n]*|trailing backslash)$/mu;function Rw(e,t,n){let r=s=>t.length?s:s.replaceAll(/^\.\//gmu,""),i={...e,stdout:r(e.stdout),stderr:_w(r(e.stderr).replaceAll(/^grep: /gmu,"rg: "))},o=O(e);return o?.detail==="non-ASCII regex semantics"?k("feature","rg","non-ASCII matching","rg: Unicode-aware matching on non-ASCII input is not supported",2):o?k(o.kind,"rg",o.detail,i.stderr.trimEnd()||o.message,e.exitCode):Lw.test(i.stderr)?k("feature","rg","regex parse error",`rg: regex parse error in ${JSON.stringify(n.join(" "))}; the reason ripgrep gives is not reproduced here`,2):i}function Mw(e,t,n){let r=[];for(let i of e)!t.has(i)&&i.startsWith("grep: excluded ")&&r.push(i);for(let i of r)e.delete(i),n.recursive&&e.add(i.replace(/^grep: excluded (\d+) (entry|entries) by --include\/--exclude\/--exclude-dir rules/u,"rg: skipped $1 hidden $2").replace(/\.$/u,". Hidden entries are searched with --hidden."))}var Wn=e=>e.events??[...e.stdout?[{fd:1,text:e.stdout}]:[],...e.stderr?[{fd:2,text:e.stderr}]:[]],is=e=>e.unordered??(!e.events&&e.stdout!==""&&e.stderr!==""),U=(e="")=>({stdout:"",stderr:e,exitCode:0,ignored:!1,events:e?[{fd:2,text:e}]:[],unordered:!1});function _(e,t){e.stdout+=t.stdout,e.stderr+=t.stderr,e.exitCode=t.exitCode,e.ignored=t.ignored??!1,e.events.push(...Wn(t)),e.unordered||=is(t)}function Jr(e,t){t&&_(e.expansionOutput,tn(U(t),{fds:e.expansionFds},e))}function tn(e,t,n){let r=i=>Pw(e,t,n,i);return n.io?n.io.output(e,t,r):r((i,o)=>o.write(i.text))}function Pw(e,t,n,r){let i=e,o=t.fds[1],s=t.fds[2];(o===s&&o!=="null"&&o!=="closed"||(o?.identity&&s?.identity?o.identity===s.identity:o?.path&&o.path===s?.path))&&is(i)&&(i=k("feature",null,"combined output ordering","error: merging this command\u2019s stdout and stderr in order is not supported"),n.unsupported.add(O(i)));let a=[],l="",f="";for(let c of Wn(i)){let d=t.fds[c.fd];if(typeof d=="object"){r(c,d);continue}if(d!=="out"&&d!=="err"){c.fd===2&&Ra(n,c.text);continue}a.push({fd:d==="out"?1:2,text:c.text}),d==="out"?f+=c.text:l+=c.text}return{...i,stdout:f,stderr:l,events:a,unordered:is(i)&&f!==""&&l!==""}}var Dw=new Map([["ls",2],["grep",2],["egrep",2],["fgrep",2],["sort",2],["xxd",3],["sed",4],["diff",2],["patch",2],["xargs",123],["hexdump",0],["tree",0]]);function os(e,t,n){return n.closed.out&&t.stdout!==""?Uw(e,t,n):t}function Uw(e,t,n){let r=Dw.get(n.registry.resolveCommand(e))??1,i=Wn(t).filter(a=>a.fd!==1),o=r===0?"":`${e}: write error: Bad file descriptor
|
|
53
|
+
`;o&&i.push({fd:2,text:o});let s={...t,stdout:"",stderr:t.stderr+o,exitCode:r||t.exitCode,events:i,unordered:!1},u=O(t);return u?re(s,u.kind,u.command,u.detail,u.message):s}var Bw=new Map([["\0","0"],["\x07","a"],["\b","b"],["\f","f"],[`
|
|
54
|
+
`,"n"],["\r","r"],[" ","t"],["\v","v"]]);function H(e,t){let n=ae(t),r=n?Array.from(q(e),s=>String.fromCodePoint(s)):[...e];if(!n&&r.some(s=>s.codePointAt(0)>127&&/[\p{C}\p{Zl}\p{Zp}]/u.test(s)))throw new w("feature","filename quoting","quoting nonprinting Unicode filenames is not supported");if(e.includes("'")&&r.every(s=>/[-a-zA-Z0-9 %+,./:_\]']/u.test(s)||!n&&s.codePointAt(0)>127))return'"'+e+'"';let i=!1,o="'";for(let s of r){let u=s.codePointAt(0),a=Bw.get(s)??(u<32||u===127||n&&u>127?u.toString(8).padStart(3,"0"):null);a!==null?(i||(o+="'$'"),i=!0,o+="\\"+a):s==="'"?(o+="'\\''",i=!1):(i&&(o+="''"),i=!1,o+=s)}return o+"'"}var qw=/^[#%+,\-./0-9@A-Z\]_a-z{}~]+$/u;function te(e,t){return qw.test(e)&&!"#~".includes(e[0])?e:H(e,t)}var Ww=new Map([["\x07","a"],["\b","b"],["\f","f"],[`
|
|
55
|
+
`,"n"],["\r","r"],[" ","t"],["\v","v"],['"','"'],["\\","\\"]]);function ss(e,t){let n=ae(t),r="",i=!1;for(let o of e){let s=o.codePointAt(0),u=Ww.get(o);if(u!==void 0)r+="\\"+u,i=!0;else if(o===" ")r+=o,i=!0;else if(s<32||s===127||s>127&&(n||/[\p{C}\p{Zl}\p{Zp}]/u.test(o))){for(let a of A(o))r+="\\"+a.toString(8).padStart(3,"0");i=!0}else r+=o}return i?`"${r}"`:e}var jw=new Set(["/dev/null","/dev/stdin","/dev/stdout","/dev/stderr"]);function Zf(e,t,n){let r=N(t,{short:["f","n","v","T","r","R"],long:["force","no-clobber","verbose","no-target-directory","recursive"],valueShort:["t"],valueLong:["target-directory"]}),i=zw(r,n);if(i.error)return y("cp: "+i.error);let{sources:o,target:s,directory:u}=i,{flags:a}=r,l=a.has("v")||a.has("verbose"),f=a.has("r")||a.has("R")||a.has("recursive"),c=o.map(h=>[h,u?s.replace(/\/+$/u,"")+"/"+Xw(h):s]),d=a.has("n")||a.has("no-clobber"),p={ctx:n,result:U(),failed:!1,sources:new Set,copied:new Set,noClobber:d,force:a.has("f")||a.has("force"),verbose:l,recursive:f,outputOverlap:l&&Vw(c,n,{recursive:f,noClobber:d})};for(let[h,m]of c){n.io.setReads([]);try{Jf(h,m,p)}catch(g){L(n,"cp",g?.path,g?.fsError);let b=O(g),x="cp: "+Z(g);if(b)return n.unsupported.add({...b,command:b.command??"cp",message:x}),_(p.result,y(x)),p.result;Mt(p,x+`
|
|
56
|
+
`,!0)}}return p.result.exitCode=p.failed?1:0,p.result}function zw({positional:e,flags:t,order:n},r){let i=n.filter(({name:f})=>f==="t"||f==="target-directory");if(i.length>1)return{error:"multiple target directories specified"};let o=i[0]?.value,s=t.has("T")||t.has("no-target-directory");if(e.length===0)return{error:"missing file operand"};if(o===void 0&&e.length===1)return{error:"missing destination file operand after "+H(e[0],r)};if(o!==void 0&&s)return{error:"cannot combine --target-directory (-t) and --no-target-directory (-T)"};if(s&&e.length>2)return{error:"extra operand "+H(e[2],r)};let u=o??e.at(-1),a=v(r.cwd,u,r.fs),l=!s&&r.fs.isDir(a.path);return!l&&(o!==void 0||e.length>2)?(L(r,"cp",u,a.error),{error:`${o===void 0?"target":"target directory"} ${H(u,r)}: ${a.error??"Not a directory"}`}):{target:u,directory:l,sources:o===void 0?e.slice(0,-1):e}}function Hw(e,t,n){let{ctx:r}=n,i=v(r.cwd,e,r.fs,{follow:!1}).path;if(i===null)return;let o=e.replace(/\/+$/u,""),s=t.replace(/\/+$/u,"");for(let u of Oe(r.fs,i)){if(u.kind!=="link")continue;let a=u.path===i?null:ze(i,u.path);if(!Yf(a===null?t:`${s}/${a}`,n)&&!(a!==null&&Gw(s,a,n)))throw Vf(a===null?e:`${o}/${a}`)}}var Yf=(e,t)=>t.noClobber&&v(t.ctx.cwd,e,t.ctx.fs,{follow:!1}).path!==null;function Gw(e,t,n){let{ctx:r}=n,i=t.split("/");for(let o=1;o<i.length;o++){let s=v(r.cwd,`${e}/${i.slice(0,o).join("/")}`,r.fs,{follow:!1});if(s.path!==null&&!r.fs.isDir(s.path))return!0}return!1}var Vf=e=>new w("feature","symbolic link",`copying a symbolic link is not supported: ${e} (a recursive copy keeps the link, which cp does not make here)`),Kf=(e,t,n)=>n.path===null&&e.fs.isLink?.(v(e.cwd,t,e.fs,{follow:!1}).path)===!0,Xw=e=>{let t=e.replace(/\/+$/u,"").split("/").at(-1);return t===".."?".":t};function Jf(e,t,n,r=null){let{ctx:i}=n;if(Xf(e,i.cwd)||Xf(t,i.cwd))throw new w("feature","special file","copying special files is not supported");let o=H(e,i),s=H(t,i);if(n.recursive&&i.fs.isLink?.(v(i.cwd,e,i.fs,{follow:!1}).path)){if(!Yf(t,n))throw Vf(e);return}let u=R(i,"cp",e),a=d=>Mt(n,"cp: "+d+`
|
|
57
|
+
`,!0);if(u.error)return a(`cannot stat ${o}: ${u.error}`);if(i.fs.isDir(u.path))return n.recursive?Zw(e,u.path,t,n,r??{source:o,target:s},r===null):a(`-r not specified; omitting directory ${o}`);if(r===null){if(n.sources.has(u.path))return Mt(n,`cp: warning: source file ${o} specified more than once
|
|
58
|
+
`,!1,!0);n.sources.add(u.path)}let l=v(i.cwd,t,i.fs);if(l.error&&l.error!=="No such file or directory")return a(`cannot stat ${s}: ${l.error}`);if(n.noClobber&&l.path!==null)return;if(tc(u.path,l.path,i.fs))return a(`${o} and ${s} are the same file`);if(i.fs.isDir(l.path))return a(`cannot overwrite directory ${s} with non-directory ${o}`);let f=ie(i.fs,i.cwd,t);if(r===null&&n.copied.has(f))return a(`will not overwrite just-created ${s} with ${o}`);let c=Qe(i.cwd,t,i.fs,l);if(Qf(o,s,n),Kf(i,t,l))return a(`not writing through dangling symlink ${s}`);if(c)return L(i,"cp",t,c),a(`cannot create regular file ${s}: ${c}`);try{if(!i.fs.copyWritable?.(i.cwd,u.path,t))return a(`${n.force&&l.path!==null?"cannot remove":"cannot create regular file"} ${s}: Read-only file system`)}catch(d){if(O(d))throw d;L(i,"cp",d?.path,d?.fsError);let p=Z(d);return a(`cannot create regular file ${s}: ${p.startsWith(t+": ")?p.slice(t.length+2):p}`)}r===null&&n.copied.add(f)}function Zw(e,t,n,r,i,o){let{ctx:s}=r,u=H(e,s),a=H(n,s),l=x=>Mt(r,"cp: "+x+`
|
|
59
|
+
`,!0),f=v(s.cwd,n,s.fs,{follow:!1});if(f.error&&f.error!=="No such file or directory")return l(`cannot stat ${a}: ${f.error}`);let c=n.replace(/\/+$/u,"")||n;if(ie(s.fs,s.cwd,c,!0)===t)return l(`${u} and ${a} are the same file`);if(f.path!==null&&!s.fs.isDir(f.path))return l(`cannot overwrite non-directory ${a} with directory ${u}`);let d=ie(s.fs,s.cwd,c,!1);if(f.path===null){let x=Qe(s.cwd,c,s.fs);if(x)return L(s,"cp",c,x),l(`cannot create directory ${a}: ${x}`);if(!s.writable||!it(d))return l(`cannot create directory ${a}: Read-only file system`)}if(d.startsWith(t==="/"?"/":t+"/"))return l(`cannot copy a directory, ${i.source}, into itself, ${i.target}`);if(o){if(r.sources.has(t))return Mt(r,`cp: warning: source directory ${u} specified more than once
|
|
60
|
+
`,!1,!0);r.sources.add(t)}o&&Hw(e,n,r);let{dirs:p,files:h,links:m}=s.fs.listDir(t);if(f.path===null&&!Yw(e,n,c,d,r))return;let g=e.replace(/\/+$/u,""),b=n.replace(/\/+$/u,"");for(let x of[...p,...h,...m].sort(B))s.io.setReads([]),Jf(`${g}/${x}`,`${b}/${x}`,r,i)}function Yw(e,t,n,r,i){let{ctx:o}=i,s=H(t,o),u=l=>(Mt(i,"cp: cannot create directory "+s+": "+l+`
|
|
61
|
+
`,!0),!1),a=o.writable&&it(r);a&&ec(i);try{if(!a||!o.fs.makeWritableDir?.(o.cwd,n))return u("Read-only file system")}catch(l){if(O(l))throw l;L(o,"cp",l?.path,l?.fsError);let f=Z(l);return u(f.startsWith(n+": ")?f.slice(n.length+2):f)}return Qf(H(e,o),s,i),!0}function Qf(e,t,n){n.verbose&&(ec(n),Mt(n,`${e} -> ${t}
|
|
62
|
+
`))}function ec(e){if(e.outputOverlap)throw new w("feature","copy output buffering","buffered verbose output sharing a copied file is not supported")}function tc(e,t,n){if(e===t)return!0;let r=n.fileIdentity?.(e);return r!==void 0&&r===n.fileIdentity(t)}function Vw(e,t,{recursive:n,noClobber:r}){let i=t.outputFds[1];if(typeof i!="object")return!1;let o={ctx:t,recursive:n,noClobber:r,holds:s=>i.identity===void 0?i.path===s:i.identity===t.fs.fileIdentity?.(s),made:new Set,sources:new Set,copied:new Set};return e.some(([s,u])=>Kw(s,u,o))}function Kw(e,t,n){let{ctx:r}=n,i=v(r.cwd,e,r.fs),o=i.path??G(r.cwd,e),s=i.error==="No such file or directory"&&(n.made.has(o)||eb(o,n));if(i.error&&!s)return!1;let u=ie(r.fs,r.cwd,t);return(i.error===null?r.fs.isDir(i.path):!n.made.has(o))?!n.recursive||!nb(o,t,r)||n.sources.has(o)?!1:(n.sources.add(o),Jw(o,u,n)):n.sources.has(o)||(n.sources.add(o),n.copied.has(u)||!tb(o,u,t,r,n.noClobber))?!1:(n.copied.add(u),n.made.add(u),n.holds(o)||n.holds(u))}function Jw(e,t,n){let{ctx:r}=n,i=e==="/"?0:e.length;for(let o of Qw(e,n)){let s=t+o.slice(i);if(!nc(o,s,v(r.cwd,s,r.fs),r,n.noClobber)&&(n.made.add(s),n.holds(o)||n.holds(s)))return!0}return!1}function Qw(e,t){let n=e==="/"?"/":e+"/",r=t.ctx.fs.isDir(e)?[...t.ctx.fs.walkFiles(e)]:[];return new Set([...r,...[...t.made].filter(i=>i.startsWith(n))])}var eb=(e,t)=>[...t.made].some(n=>n.startsWith(e+"/"));function nc(e,t,n,r,i){return n.error&&n.error!=="No such file or directory"||i&&n.path!==null||tc(e,n.path,r.fs)||r.fs.isDir(n.path)?!0:!r.writable||!it(t)}function tb(e,t,n,r,i){let o=v(r.cwd,n,r.fs);return!nc(e,t,o,r,i)&&!Kf(r,n,o)&&!Qe(r.cwd,n,r.fs,o)}function nb(e,t,n){let r=v(n.cwd,t,n.fs,{follow:!1});if(r.error&&r.error!=="No such file or directory")return!1;let i=t.replace(/\/+$/u,"")||t;if(r.path!==null&&!n.fs.isDir(r.path)||r.path===null&&Qe(n.cwd,i,n.fs))return!1;let o=ie(n.fs,n.cwd,i,!1);return ie(n.fs,n.cwd,i,!0)===e||o.startsWith(e==="/"?"/":e+"/")?!1:!!n.writable&&it(o)}function Xf(e,t){let n=e.startsWith("/")?e:t+"/"+e;return jw.has(n.replace(/\/\.(?=\/)/gu,"").replace(/\/+/gu,"/"))}function Mt(e,t,n=!1,r=!1){let i=n||r?U(t):{...U(),stdout:t,events:[{fd:1,text:t}]};_(e.result,e.ctx.flushOutput(i)),e.failed||=n}function rc(e,t,n){let{flags:r,positional:i}=N(t,{short:["f","v","r","R"],long:["force","verbose","recursive"]}),o=r.has("f")||r.has("force"),s=r.has("v")||r.has("verbose"),u=r.has("r")||r.has("R")||r.has("recursive");if(i.length===0)return o?C(""):y("rm: missing operand");let a={ctx:n,force:o,verbose:s,recursive:u,events:[],stdout:"",stderr:""};try{for(let l of i)rb(l,a)}catch(l){L(n,"rm",l?.path,l?.fsError);let f=Y(l,"rm","rm: "+Z(l));return f.events=[...a.events,{fd:2,text:f.stderr}],f.stdout=a.stdout,f.stderr=a.stderr+f.stderr,f}return{stdout:a.stdout,stderr:a.stderr,events:a.events,exitCode:a.stderr?1:0}}function rb(e,t){let{ctx:n}=t,r=v(n.cwd,e,n.fs,{follow:!1}),i=r.error;if(!(t.force&&(i==="No such file or directory"||i==="Not a directory"))){if(L(n,"rm",e,i),i===null&&n.fs.isDir(r.path))if(!t.recursive)i="Is a directory";else{if([".",".."].includes(e.replace(/\/+$/u,"").split("/").at(-1)))return as(t,`rm: refusing to remove '.' or '..' directory: skipping ${H(e,n)}
|
|
63
|
+
`);if(r.path==="/tmp")i="Device or resource busy";else if(!n.writable||!it(r.path))i="Read-only file system";else return ic(e,r.path,t,ib(n,e)?"Not a directory":null)}us(e,r.path,t,!1,i)}}function ib(e,t){let n=t.replace(/\/+$/u,"");return n===t||n===""?!1:e.fs.isLink?.(v(e.cwd,n,e.fs,{follow:!1}).path)===!0}function ic(e,t,n,r=null){let{ctx:i}=n,{dirs:o,files:s,links:u=[]}=i.fs.listDir(t),a=e.replace(/\/+$/u,"");for(let l of[...o,...s,...u].sort(B)){let f=Ae(t,l);i.fs.isDir(f)?ic(`${a}/${l}`,f,n):us(`${a}/${l}`,f,n,!1,null)}us(e,t,n,!0,r)}function us(e,t,n,r,i){let{ctx:o}=n,s=n.verbose||i!==null||!o.writable||!t?.startsWith("/tmp/")?H(e,o):"",u=()=>r?o.fs.removeWritableDir?.(o.cwd,e):o.fs.removeWritable?.(o.cwd,e);try{i===null&&!u()&&(i="Read-only file system")}catch(a){if(O(a))throw a;L(o,"rm",a?.path,a?.fsError);let l=Z(a);i=a?.fsError??(l.startsWith(e+": ")?l.slice(e.length+2):l)}if(i)return as(n,`rm: cannot remove ${s}: ${i}
|
|
64
|
+
`);n.verbose&&as(n,`removed ${r?"directory ":""}${s}
|
|
65
|
+
`,1)}function as(e,t,n=2){n===1?e.stdout+=t:e.stderr+=t,e.events.push({fd:n,text:t})}function sc(e,t,n){let{flags:r,positional:i}=N(t,{short:["p","v"],long:["parents","verbose"]});if(i.length===0)return y("mkdir: missing operand");let o={ctx:n,events:[],stdout:"",stderr:"",parents:r.has("p")||r.has("parents"),verbose:r.has("v")||r.has("verbose")};try{for(let s of i)o.parents?ob(s,o):ls(s,o,!0)}catch(s){L(n,"mkdir",s?.path,s?.fsError);let u=Y(s,"mkdir","mkdir: "+Z(s));return u.events=[...o.events,{fd:2,text:u.stderr}],u.stdout=o.stdout,u.stderr=o.stderr+u.stderr,u}return{stdout:o.stdout,stderr:o.stderr,events:o.events,exitCode:o.stderr?1:0}}function ob(e,t){let n=e.split("/"),r=[];for(let i=0;i<n.length;i++)n[i]!==""&&r.push(n.slice(0,i+1).join("/"));if(r.length===0){e===""&&ls(e,t,!0);return}r[r.length-1]=e;for(let[i,o]of r.entries())if(!ls(o,t,i===r.length-1))return}function ls(e,t,n){let{ctx:r}=t,i=H(e,r),o=l=>(oc(t,`mkdir: cannot create directory ${i}: ${l}
|
|
66
|
+
`),!1),s=e.replace(/\/+$/u,"")||e,u=v(r.cwd,s,r.fs);if(u.error===null)return t.parents?r.fs.isDir(u.path)?!0:o(n?"File exists":"Not a directory"):o("File exists");if(v(r.cwd,s,r.fs,{follow:!1}).error===null)return o(!t.parents||n||u.error!=="Not a directory"?"File exists":"Not a directory");let a=Qe(r.cwd,s,r.fs,u);if(a)return L(r,"mkdir",s,a),o(a);try{if(!r.fs.makeWritableDir?.(r.cwd,s))return o("Read-only file system")}catch(l){if(O(l))throw l;L(r,"mkdir",l?.path,l?.fsError);let f=Z(l);return o(f.startsWith(s+": ")?f.slice(s.length+2):f)}return t.verbose&&oc(t,`mkdir: created directory ${i}
|
|
67
|
+
`,1),!0}function oc(e,t,n=2){n===1?e.stdout+=t:e.stderr+=t,e.events.push({fd:n,text:t})}function uc(e,t,n){let{flags:r,positional:i}=N(t,{short:["c"],long:["no-create"]});if(i.length===0)return y("touch: missing file operand");let o=r.has("c")||r.has("no-create"),s={ctx:n,stderr:"",failed:!1,gap:null};for(let a of i)sb(a,o,s);let u={stdout:"",stderr:s.stderr,exitCode:s.failed?1:0};return s.gap?re(u,"feature","touch","times",s.gap):u}function sb(e,t,n){let{ctx:r}=n,i=H(e,r),o=v(r.cwd,e,r.fs);if(o.error===null)return ub(e,i,o.path,n);let s=t||e.endsWith("/");if(t&&o.error==="No such file or directory")return;if(L(r,"touch",e,o.error),s)return jn(n,`setting times of ${i}: ${o.error}`);let u=Qe(r.cwd,e,r.fs,o);if(u)return jn(n,`cannot touch ${i}: ${u}`);try{r.fs.openWritable?.(r.cwd,e,!0)||jn(n,`cannot touch ${i}: Read-only file system`)}catch(a){if(O(a))throw a;L(r,"touch",a?.path,a?.fsError);let l=Z(a);jn(n,`cannot touch ${i}: ${l.startsWith(e+": ")?l.slice(e.length+2):l}`)}}function ub(e,t,n,r){let{ctx:i}=r;if(!i.writable||!it(n))return jn(r,`setting times of ${t}: Read-only file system`);let o=`touch: setting the times of ${t} is not supported (every entry here carries the one time this filesystem keeps)`;r.gap??=o,r.stderr+=o+`
|
|
68
|
+
`,r.failed=!0}function jn(e,t){e.stderr+=`touch: ${t}
|
|
69
|
+
`,e.failed=!0}function zn(e,t,n,r){if(t===""||t.includes("\0"))return{error:"No such file or directory"};if(r==="none")return ab(e,t,n);let i=t;if(r==="logical"){let s=n==="m"?{path:G(e.cwd,t)}:fc(e,t);if(s.error)return s;i=s.path+(t.endsWith("/")?"/":"")}let o=je(e.cwd,i,e.fs,{lenient:n==="m"});return n==="m"?{path:o.rest.length?G(o.path,o.rest.join("/")):o.path}:o.error==="No such file or directory"&&o.rest.length===0&&n!=="e"?{path:o.path}:o.error?{error:o.error}:t.endsWith("/")&&!e.fs.isDir(o.path)?{error:"Not a directory"}:{path:o.path}}function ab(e,t,n){if(n==="m")return{path:G(e.cwd,t)};let r=fc(e,t);if(r.error||n!=="e")return r;let i=v("/",r.path,e.fs);return i.error?{error:i.error}:r}function fc(e,t){let n=(t.startsWith("/")?t:e.cwd+"/"+t).split("/").filter(Boolean),r="/";for(let i=0;i<n.length;i++){let o=n[i];if(o==="..")r=ge(r);else if(o!=="."){r=Ae(r,o);let s=i+1;for(;n[s]===".";)s++;let u=n[s]===".."||s===n.length&&(i<n.length-1||t.endsWith("/"));if(u||i===n.length-1){let a=v("/",r+(u?"/":""),e.fs);if(a.error&&!(a.error==="No such file or directory"&&i===n.length-1))return a}}}return{path:r}}function fs(e,t){let n=e.split("/").filter(Boolean),r=t.split("/").filter(Boolean),i=0;for(;i<n.length&&i<r.length&&n[i]===r[i];)i++;return[...n.slice(i).map(()=>".."),...r.slice(i)].join("/")||"."}var cc=(e,t)=>e==="/"||t===e||t.startsWith(e+"/"),ac={e:"e","canonicalize-existing":"e",m:"m","canonicalize-missing":"m"},lc={P:"physical",physical:"physical",L:"logical",logical:"logical",s:"none",strip:"none","no-symlinks":"none"};function lb(e,t,n,r){let i=t.get("relative-base"),o=t.get("relative-to")??i,s={};for(let[u,a]of[["target",o],["base",i]]){if(a===void 0)continue;let l=zn(e,a,n,r),f=l.error??(n==="e"&&!e.fs.isDir(l.path)?"Not a directory":null);if(f)return L(e,"realpath",a,f),{error:y(`realpath: ${te(a,e)}: ${f}`)};s[u]=l.path}return s.base&&!cc(s.base,s.target)&&delete s.target,s}function dc(e,t,n){let{flags:r,values:i,positional:o,order:s}=N(t,{short:["e","m","L","P","s","q","z"],long:["canonicalize-existing","canonicalize-missing","logical","physical","strip","no-symlinks","quiet","zero"],valueLong:["relative-to","relative-base"]});if(!o.length)return y("realpath: missing operand");let u="physical",a="E";for(let{name:h}of s)Object.hasOwn(ac,h)&&(a=ac[h]),Object.hasOwn(lc,h)&&(u=lc[h]);let l=lb(n,i,a,u);if(l.error)return l.error;let f=r.has("q")||r.has("quiet"),c=r.has("z")||r.has("zero")?"\0":`
|
|
70
|
+
`,d=U(),p=!1;for(let h of o){let m=zn(n,h,a,u);if(m.error)L(n,"realpath",h,m.error),f||_(d,y(`realpath: ${te(h,n)}: ${m.error}`)),p=!0;else{let g=l.target&&(!l.base||cc(l.base,m.path))?fs(l.target,m.path):m.path;_(d,C(g+c))}}return d.exitCode=p?1:0,d}var Qr={symbolic:"s",force:"f","no-dereference":"n","no-target-directory":"T",verbose:"v",relative:"r",logical:"L",physical:"P"};function hc(e,t,n){let r=N(t,{short:Object.values(Qr),long:Object.keys(Qr),valueShort:["t"],valueLong:["target-directory"]}),i=l=>r.flags.has(l)||r.flags.has(Object.keys(Qr).find(f=>Qr[f]===l)),o={force:i("f"),noDereference:i("n"),noTargetDirectory:i("T"),verbose:i("v"),relative:i("r")},s=r.order.findLast(({name:l})=>l==="t"||l==="target-directory")?.value??null,u=r.positional;if(s!==null&&o.noTargetDirectory)return y("ln: cannot combine --target-directory and --no-target-directory");if(o.relative&&!i("s"))return y("ln: cannot do --relative without --symbolic");if(u.length===0)return y("ln: missing file operand");if(!i("s"))return k("feature","ln","hard link",`ln: hard links are not supported: ${H(u[0],n)} (ln -s makes a symbolic one)`);let a={ctx:n,events:[],stdout:"",stderr:""};try{let l=fb(u,s,o,n);if(l.error)return l.error;for(let[f,c,d]of l)cb(f,c,o,a,d)}catch(l){L(n,"ln",l?.path,l?.fsError);let f=Y(l,"ln","ln: "+Z(l));return f.events=[...a.events,{fd:2,text:f.stderr}],f.stdout=a.stdout,f.stderr=a.stderr+f.stderr,f}return{stdout:a.stdout,stderr:a.stderr,events:a.events,exitCode:a.stderr?1:0}}function fb(e,t,n,r){let i=a=>H(a,r);if(t!==null){let a=v(r.cwd,t,r.fs);return a.error?(L(r,"ln",t,a.error),{error:y(`ln: failed to access ${i(t)}: ${a.error}`)}):r.fs.isDir(a.path)?e.map(l=>cs(t,l)):{error:y(`ln: target ${i(t)} is not a directory`)}}if(e.length===1)return n.noTargetDirectory?{error:y(`ln: missing destination file operand after ${i(e[0])}`)}:[cs(".",e[0])];if(e.length===2){let a=v(r.cwd,e[1],r.fs,{follow:!n.noDereference});if(n.noTargetDirectory||a.error!==null||!r.fs.isDir(a.path))return[[e[0],e[1]]]}if(n.noTargetDirectory)return{error:y(`ln: extra operand ${i(e[2])}`)};let o=e.at(-1),s=v(r.cwd,o,r.fs),u=s.error??(r.fs.isDir(s.path)?null:"Not a directory");return u?(L(r,"ln",o,u),{error:y(`ln: target ${i(o)}: ${u}`)}):e.slice(0,-1).map(a=>cs(o,a))}function cs(e,t){let n=t.replace(/\/+$/u,"").split("/").at(-1);return[t,e+(e.endsWith("/")?"":"/")+n,n===""]}function cb(e,t,n,r,i=!1){let{ctx:o}=r,s=H(t,o),u=n.relative?pb(o,e,t):e,a=f=>ds(r,`ln: failed to create symbolic link ${s}${f}
|
|
71
|
+
`);if(u==="")return a(` -> ${H(u,o)}: No such file or directory`);if(i)return a(": No such file or directory");if(n.force){let f=v(o.cwd,t,o.fs,{follow:!1});if(f.error===null){if(o.fs.isDir(f.path))return ds(r,`ln: ${te(t,o)}: cannot overwrite directory
|
|
72
|
+
`);try{if(!o.fs.removeWritable?.(o.cwd,t))return a(": Read-only file system")}catch(c){if(O(c))throw c;return a(`: ${pc(c,t)}`)}}}let l=db(o,t);if(l)return L(o,"ln",t,l),a(`: ${l}`);try{if(!o.fs.makeWritableLink?.(o.cwd,t,u))return a(": Read-only file system")}catch(f){if(O(f))throw f;return L(o,"ln",f?.path,f?.fsError),a(`: ${pc(f,t)}`)}n.verbose&&ds(r,`${s} -> ${H(u,o)}
|
|
73
|
+
`,1)}function db(e,t){if(t===""||t.includes("\0"))return"No such file or directory";let n=t.replace(/\/+$/u,"");if(n==="")return"File exists";let r=v(e.cwd,n,e.fs,{follow:!1});if(r.error===null)return"File exists";if(r.error!=="No such file or directory"||t!==n)return r.error;let i=je(e.cwd,n,e.fs);return i.rest.length>0?i.error:null}function pb(e,t,n){let r=zn(e,ge(n),"m","physical"),i=zn(e,t,"m","physical");return r.error||i.error?t:fs(r.path,i.path)}function pc(e,t){let n=Z(e);return e?.fsError??(n.startsWith(t+": ")?n.slice(t.length+2):n)}function ds(e,t,n=2){n===1?e.stdout+=t:e.stderr+=t,e.events.push({fd:n,text:t})}var mc={cp:Zf,rm:rc,mkdir:sc,touch:uc,ln:hc};function hb(e,t,n){let{positional:r}=N(t),i=se("tac",r,e,n),o=[];for(let{content:s}of i.inputs)o.push(...He(s).toReversed());return ee(o.join(""),i)}var gc=1e6;function mb(e,t){let{flags:n,values:r,positional:i}=N(t,{short:["w"],valueShort:["s"],numericOperands:!0});if(i.length===0||i.length>3)return de("seq [-w] [-s SEP] LAST | seq FIRST LAST | seq FIRST INCR LAST");let o=[];for(let p of i){if(!/^[+-]?\d+$/u.test(p))return Number.isFinite(Number(p))&&p.trim()!==""||/^[+-]?inf(?:inity)?$/iu.test(p)?k("feature","seq","non-integer operands","seq: non-integer operands are not supported"):y(`seq: invalid integer: ${p}`);o.push(BigInt(p))}let s=o.length===1?1n:o[0],u=o.length===3?o[1]:1n,a=o.at(-1);if(u===0n)return y("seq: increment must be non-zero");let f=(u>0?s<=a:s>=a)?(a>s?a-s:s-a)/(u>0n?u:-u)+1n:0;if(f>gc)return k("feature","seq","sequence limit",`seq: range too large: ${f} elements exceeds limit of ${gc}`);let c=n.has("w")?Math.max(...[i[0],i.at(-1)].map(p=>p.replace(/^\+/u,"").length)):0,d=[];for(let p=0,h=s;p<f;p++,h+=u)d.push(gb(String(h),c));return C(d.length===0?"":d.join(r.get("s")??`
|
|
65
74
|
`)+`
|
|
66
|
-
`)}function
|
|
67
|
-
`,exitCode:1};l.push(`${String(u).padStart(
|
|
68
|
-
`?d===""?[]:[d]:
|
|
69
|
-
`?
|
|
70
|
-
`:i==="t"?" ":i==="\\"?"\\":i==="0"?"\0":i};for(;n<e.length;){let i=r();if(e[n]==="-"&&n+1<e.length){n++;let o=r();if(o===null)return{error:y("tr: trailing backslash in set")};let s=i.codePointAt(0),u=o.codePointAt(0);if(u<s)return{error:y(`tr: range-endpoints of '${i}-${o}' are in reverse collating sequence order`)};for(let a=s;a<=u;a++)t.push(String.fromCodePoint(a))}else t.push(i)}return{chars:t}}function
|
|
71
|
-
`)}function
|
|
72
|
-
`)}var
|
|
73
|
-
`,t:" ","%":"%"};return t.replace(/%./gu,p=>{let
|
|
75
|
+
`)}function gb(e,t){if(e.length>=t)return e;let n=e.startsWith("-"),r=n?e.slice(1):e;return(n?"-":"")+r.padStart(t-(n?1:0),"0")}var bc=6,yc=" ",wb=" ".repeat(bc+yc.length);function bb(e,t,n){let{values:r,positional:i,order:o}=N(t,{valueShort:["b","v"],valueLong:["starting-line-number"]}),s=r.get("b")??"t";if(!["a","t","n"].includes(s)){let f=`nl: -b: only \`a\`, \`t\` and \`n\` are supported (got \`${s}\`)`;return s.startsWith("p")?k("option","nl","-b p",f):y(f)}let u=1n;for(let{name:f,value:c}of o)if(!(f!=="v"&&f!=="starting-line-number")){if(!/^[ \t\n\r\f\v]*[+-]?\d+$/u.test(c))return y(`nl: invalid starting line number: ${c}`);if(u=BigInt(c),u<tt||u>oe)return y(`nl: invalid starting line number: ${c}`)}let a=se("nl",i,e,n);if(a.inputs.some(({content:f})=>/(?:^|\n)(?:\\:){1,3}(?:\n|$)/u.test(f)))return k("feature","nl","logical pages","nl: logical page delimiters are not supported");let l=[];for(let{content:f}of a.inputs)for(let c of pe(f))if(s==="a"||s==="t"&&c!==""){if(u>oe)return{stdout:he(l),stderr:a.stderr+`nl: line number overflow
|
|
76
|
+
`,exitCode:1};l.push(`${String(u).padStart(bc)}${yc}${c}`),u++}else l.push(wb+c);return ee(he(l),a)}function yb(e,t,n){let{flags:r,values:i,positional:o}=N(t,{short:["s"],valueShort:["d","f","c"]}),s=i.has("f"),u=i.has("c");if(s===u)return de("cut -f LIST [-d DELIM] [-s] [file...] | cut -c LIST [file...]");if(u&&i.has("d"))return y("cut: -d is only valid with -f");if(u&&r.has("s"))return y("cut: -s is only valid with -f");let a=Sb(s?i.get("f"):i.get("c"),s?"field":"position");if(a.error)return a.error;let l=i.get("d")===""?"\0":i.get("d")??" ";if(s&&A(l).length!==1)return y("cut: -d delimiter must be a single byte");let f=se("cut",o,e,n),c=[];for(let{content:d}of f.inputs)for(let p of s&&l===`
|
|
77
|
+
`?d===""?[]:[d]:pe(d)){if(s&&!p.includes(l)){r.has("s")||c.push(p);continue}c.push(s?$b(p,l,a.ranges):xb(p,a.ranges))}return ee(he(c),f)}function xb(e,t){let n=A(e);return P(Uint8Array.from(xc(n,t)))}var kb={field:{zero:"fields are numbered from 1",range:"invalid field range",value:e=>`invalid field value '${e}'`,large:e=>`field number '${e}' is too large`},position:{zero:"byte/character positions are numbered from 1",range:"invalid byte or character range",value:e=>`invalid byte/character position '${e}'`,large:e=>`byte/character offset '${e}' is too large`}},vb=/^(\d*)(-?)(\d*)/u;function Sb(e,t){let n=kb[t],r=s=>({error:y(`cut: ${s}`)}),i=[];for(let s of e.split(/[, \t]/u)){if(s==="")return r(n.zero);let[u,a,l,f]=vb.exec(s),c=s.slice(u.length);if(c!=="")return r(c.startsWith("-")?n.range:n.value(c));for(let h of[a,f])if(h!==""&&BigInt(h)>nt)return r(n.large(h));if(a===""&&f===""&&l==="")return r(n.value(s));let d=a===""?1:Number(a),p=l===""?d:f===""?1/0:Number(f);if(d<1)return r(n.zero);if(p<d)return r("invalid decreasing range");i.push([d,p])}i.sort((s,u)=>s[0]-u[0]);let o=[];for(let s of i){let u=o.at(-1);u&&s[0]<=u[1]+1?u[1]=Math.max(u[1],s[1]):o.push(s)}return{ranges:o}}function xc(e,t){return t.flatMap(([n,r])=>Array.from(e.slice(n-1,r)))}function $b(e,t,n){let r=t===`
|
|
78
|
+
`?pe(e):e.split(t);return xc(r,n).join(t)}function Eb(e,t,n){let{flags:r,positional:i}=N(t,{short:["c","d","s"]}),o=r.has("d"),s=r.has("s"),u=r.has("c");if(o&&s)return k("option","tr","-d -s","tr: -d combined with -s is not supported");if(s&&!o&&i.length===2)return k("feature","tr","translate and squeeze","tr: combined translation and squeezing is not supported");let a=o||s?1:2;if(i.length!==a)return de("tr [-c] SET1 SET2 | tr [-c] -d SET | tr [-c] -s SET");if(/\P{ASCII}/u.test(e+i.join("")))return k("feature","tr","non-ASCII bytes","tr: translation of non-ASCII bytes is not supported");if(i.some(g=>/\[[:.=]|\[[^\]]*\*/u.test(g)))return k("feature","tr","set expressions","tr: character classes, equivalence classes and repetition expressions are not supported");if(i.some(g=>/\\[0-7]{2}|\\[1-7abfrv]/u.test(g)))return k("feature","tr","set escapes","tr: these set escape sequences are not supported");if(i.some(g=>/(?:^|[^\\])(?:\\\\)*\\$/u.test(g)))return k("feature","tr","trailing backslash","tr: an unescaped trailing backslash in a set is not supported");let l=wc(i[0]);if(l.error)return l.error;let f=new Set(l.chars),c=g=>u!==f.has(g);if(o)return X(n),C([...e].filter(g=>!c(g)).join(""));if(s)return X(n),C(Nb(e,c));let d=wc(i[1]);if(d.error)return d.error;if(d.chars.length===0)return y("tr: when not truncating set1, string2 must be non-empty");X(n);let p=u?Array.from({length:256},(g,b)=>String.fromCodePoint(b)).filter(g=>!f.has(g)):l.chars,h=new Map,m=d.chars.at(-1);for(let g=0;g<p.length;g++)h.set(p[g],d.chars[g]??m);return C([...e].map(g=>h.get(g)??g).join(""))}function wc(e){let t=[],n=0,r=()=>{if(e[n]!=="\\")return e[n++];if(n+1>=e.length)return null;let i=e[n+1];return n+=2,i==="n"?`
|
|
79
|
+
`:i==="t"?" ":i==="\\"?"\\":i==="0"?"\0":i};for(;n<e.length;){let i=r();if(e[n]==="-"&&n+1<e.length){n++;let o=r();if(o===null)return{error:y("tr: trailing backslash in set")};let s=i.codePointAt(0),u=o.codePointAt(0);if(u<s)return{error:y(`tr: range-endpoints of '${i}-${o}' are in reverse collating sequence order`)};for(let a=s;a<=u;a++)t.push(String.fromCodePoint(a))}else t.push(i)}return{chars:t}}function Nb(e,t){let n="",r=null;for(let i of e)t(i)&&i===r||(n+=i,r=i);return n}function Ab(e,t,n){let{positional:r}=N(t);if(r.length===0)return de("which COMMAND...");let i=[],o=0;for(let s of r)n.hasCommand(s)?i.push(`/usr/bin/${s}`):(i.push(`${s} not found`),o=1);return{stdout:he(i),stderr:"",exitCode:o}}function Ob(e,t,n){let{positional:r}=N(t);return r.length>0?y(`whoami: extra operand: ${r[0]}`):C((n.user??"user")+`
|
|
80
|
+
`)}function Ib(e,t,n){let{flags:r,positional:i}=N(t,{short:["u"]});if(i.length>1)return y(`date: at most one +FORMAT argument is supported (got: ${i[1]})`);let o="%a %b %e %T %Z %Y";if(i.length===1){if(!i[0].startsWith("+"))return de("date [-u] [+FORMAT]");o=i[0].slice(1)}return(o.match(/%./gu)??[]).some(s=>/%[-_0^#0-9:EOcCDgGhIjklNpPrRuUVwWxXy+]/u.test(s))?k("feature","date","format","date: this format directive or modifier is not supported"):C(ps(new Date,o,r.has("u")||n.vars.has("TZ"))+`
|
|
81
|
+
`)}var Cb=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],Fb=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],Tb=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],_b=["January","February","March","April","May","June","July","August","September","October","November","December"];function ps(e,t,n){let r="get"+(n?"UTC":""),[i,o,s,u,a,l,f]=["FullYear","Month","Date","Hours","Minutes","Seconds","Day"].map(p=>e[r+p]()),c=(p,h="0")=>String(p).padStart(2,h),d={__proto__:null,Y:String(i),m:c(o+1),d:c(s),e:c(s," "),H:c(u),M:c(a),S:c(l),T:[u,a,l].map(p=>c(p)).join(":"),F:[i,c(o+1),c(s)].join("-"),q:String(Math.floor(o/3)+1),s:String(Math.floor(e.getTime()/1e3)),a:Cb[f],A:Fb[f],b:Tb[o],B:_b[o],Z:()=>Lb(e,n),z:()=>Rb(e,n),n:`
|
|
82
|
+
`,t:" ","%":"%"};return t.replace(/%./gu,p=>{let h=d[p[1]];return typeof h=="function"?h():h??p})}function Lb(e,t){if(t)return"UTC";try{return new Intl.DateTimeFormat("en-US",{timeZoneName:"short"}).formatToParts(e).find(i=>i.type==="timeZoneName")?.value??"Local"}catch{return"Local"}}function Rb(e,t){if(t)return"+0000";let n=-e.getTimezoneOffset(),r=n>=0?"+":"-",i=Math.abs(n);return`${r}${String(Math.floor(i/60)).padStart(2,"0")}${String(i%60).padStart(2,"0")}`}var kc={rg:Gf,cut:yb,tac:hb,tr:Eb,seq:mb,nl:bb,which:Ab,hexdump:Hl,base64:Vl,...mc},vc={whoami:Ob,date:Ib,od:Gl,xxd:Xl,...Ll,...Ul};var hs=new Map(Object.entries({all:"a","apparent-size":"A",bytes:"b",total:"c",null:"0","count-links":"l",summarize:"s","separate-dirs":"S","human-readable":"h","max-depth":"d","block-size":"B",dereference:"L","dereference-args":"D","no-dereference":"P"})),Sc={P:"none",D:"args",H:"args",L:"all"};function Ec(e,t){let n=N(e,{short:["0","a","A","b","c","h","H","k","l","m","s","S","L","D","P"],long:[...hs.keys()].filter(o=>!["d","B"].includes(hs.get(o))).concat(["inodes","si"]),valueShort:["d","B"],valueLong:["max-depth","block-size"]}),r={operands:n.positional.length?n.positional:["."],depth:1/0,flags:new Set,links:"none",scale:null,stderr:""};for(let{name:o,value:s}of n.order){let u=hs.get(o)??o;r.flags.add(u),Object.hasOwn(Sc,u)&&(r.links=Sc[u]),u==="d"&&(r.depth=Mb(s)),u==="B"&&(r.scale=$c(s)),u==="b"&&(r.flags.add("A"),r.scale={unit:1n}),(u==="k"||u==="m")&&(r.scale={unit:u==="k"?1024n:1024n**2n}),(u==="h"||u==="si")&&(r.scale={base:u==="h"?1024n:1000n,unit:1n})}let{flags:i}=r;if(i.has("a")&&i.has("s"))throw new Error("cannot both summarize and show all entries");if(i.has("s")&&i.has("d")){if(r.depth!==0)throw new Error(`summarizing conflicts with --max-depth=${r.depth}`);r.stderr+=`du: warning: summarizing is the same as using --max-depth=0
|
|
74
83
|
`}if(i.has("s")&&(r.depth=0),i.has("inodes")&&i.has("A")&&(r.stderr+=`du: warning: options --apparent-size and -b are ineffective with --inodes
|
|
75
|
-
`),!r.scale){let o=t.vars.get("DU_BLOCK_SIZE")??t.vars.get("BLOCK_SIZE")??t.vars.get("BLOCKSIZE");try{r.scale=o===void 0?{unit:t.vars.has("POSIXLY_CORRECT")?512n:1024n}
|
|
84
|
+
`),!r.scale){let o=t.vars.get("DU_BLOCK_SIZE")??t.vars.get("BLOCK_SIZE")??t.vars.get("BLOCKSIZE");try{r.scale=o===void 0?{unit:t.vars.has("POSIXLY_CORRECT")?512n:1024n}:$c(o)}catch(s){throw s instanceof w?s:new w("feature","invalid block size environment","invalid block size environment settings are not supported")}}return i.has("inodes")&&(r.scale={...r.scale,unit:1n,suffix:r.scale.suffix?.endsWith("B")?"B":""}),r.scale.base&&gs(t,r.scale.base),r}function gs(e,t=1024n){let n=e.vars.get("LC_ALL")||e.vars.get("LC_NUMERIC")||e.locale;if(!/^(?:C|POSIX|C\.UTF-?8)$/iu.test(n))throw new w("feature","numeric locale","human-readable sizes in this numeric locale are not supported");return{base:t,unit:1n}}function Mb(e){let t=/^[ \t\n\r\v\f]*([+-]?)(0[xX][\da-fA-F]+|0[0-7]*|[1-9]\d*)$/u.exec(e);if(!t)throw new Error(`invalid maximum depth: ${e}`);let n=Nc(t[2]);if(n>oe||t[1]==="-"&&n!==0n)throw new Error(`invalid maximum depth: ${e}`);return Number(n)}function Nc(e){return BigInt(/^0[0-7]+$/u.test(e)?"0o"+e:e)}function $c(e){let t=e&&["human-readable","si"].find(a=>a.startsWith(e));if(t)return{base:t==="si"?1000n:1024n,unit:1n};if(e.startsWith("'"))throw new w("feature","grouped block sizes","grouped block sizes are not supported");let n=/^[ \t\n\r\v\f]*\+?(0[xX][\da-fA-F]+|0[0-7]*|[1-9]\d*)?([kKmMgGtTPEZYRQ](?:i?B|D)?)?$/u.exec(e);if(!n||!n[1]&&e!==n[2])throw new Error(`invalid block size: ${e}`);let r=n[2]??"",i=r?"KMGTPEZYRQ".indexOf(r[0].toUpperCase())+1:0,o=/[BD]$/u.test(r)&&!r.endsWith("iB")?1000n:1024n,s=(n[1]?Nc(n[1]):1n)*o**BigInt(i);if(s===0n||s>nt)throw new Error(`invalid block size: ${e}`);let u=n[1]||!r?"":(i===1&&r.endsWith("B")&&o===1000n?"k":r[0].toUpperCase())+(r.endsWith("B")?o===1000n?"B":"iB":"");return{unit:s,suffix:u}}var Hn=4096,Pb=60,ei=(e,t)=>t==="dir"?Hn:t==="link"&&e<Pb?0:Math.ceil(e/Hn)*Hn,ms=(e,t)=>(e+t-1n)/t;function Gn(e,{base:t,unit:n,suffix:r=""}){if(!t)return String(ms(e,n))+r;let i=1n,o=0;for(;e>=i*t;)i*=t,o++;if(!o)return String(e);let s=ms(e*10n,i),u;return s<100n?u=`${s/10n}.${s%10n}`:(s=ms(e,i),s===t?(o++,u="1.0"):u=String(s)),u+(o===1&&t===1000n?"k":"KMGTPEZYRQ"[o-1])}var Db=31556952*1e3/2;function Ac(e,t){for(let f of["LS_BLOCK_SIZE","BLOCK_SIZE","BLOCKSIZE"])if(e.vars.has(f))throw new w("feature","block size environment",`${f} is not supported in a long listing`);let n=t?gs(e):null,r=e.user??"user",i=e.createdAt,o=Date.now(),s=i<=o&&o-i<Db,u=ps(new Date(i),s?"%b %e %H:%M":"%b %e %Y",e.vars.has("TZ")),a=f=>n?Gn(BigInt(f),n):String(f),l=f=>Math.max(0,...f.map(c=>c.length));return{lines(f,c){let d=f.map(({name:g,abs:b,kind:x,target:S})=>{let E=x==="dir",M=E?Hn:e.fs.fileSize(b)??q(e.fs.readFile(b)).length,D=E?"drwx------":x==="link"?"lrwxrwxrwx":"-rw-------",T=ei(M,x)/512;return{name:x==="link"?`${g} -> ${S}`:g,mode:D,units:T,links:String(E?2+e.fs.listDir(b).dirs.length:1),size:a(M)}}),p=l(d.map(g=>g.links)),h=l(d.map(g=>g.size)),m=d.map(g=>`${g.mode} ${g.links.padStart(p)} ${r} ${r} ${g.size.padStart(h)} ${u} ${g.name}`);if(c){let g=d.reduce((b,x)=>b+x.units,0);m.unshift("total "+(n?Gn(BigInt(g)*512n,n):String(g/2)))}return m}}}function Oc(e,t,n){let{flags:r,values:i,positional:o}=N(t,{short:["a","d","F"],long:["noreport"],valueShort:["L"]});if(o.length>1)return k("feature","tree","multiple roots","tree: multiple roots are not supported");let s=i.has("L")?we(i.get("L"),"tree: -L",i.get("L"),{max:2147483647}):{value:Number.POSITIVE_INFINITY};if(s.error)return s.error;if(!s.value)return y("tree: -L must be greater than zero");let u=o[0]??".",{path:a,error:l}=R(n,"tree",u),f=!l&&n.fs.isDir(a),c=v(n.cwd,u,n.fs,{follow:!1}),d=!!l&&!!c.error,p={dirs:f&&ti(n.fs,a,r).length?1:0,files:!d&&!f?1:0},h=[u+Ub(n,r,c,f)+(f?"":" [error opening dir]")];if(f){let m=new Set,g=Zt();try{let b=Bb(n.fs,a,h,r,s.value,p,m,g);if(b)return b}finally{ht(n.notes,{command:"tree",action:"depth limit omitted contents of",noun:["directory","directories"],paths:m}),g.emit(n.notes,"tree","Hidden entries are included with -a.")}}if(!r.has("noreport")){let m=`${p.dirs} ${p.dirs===1?"directory":"directories"}`,g=`${p.files} ${p.files===1?"file":"files"}`;h.push("",r.has("d")?m:`${m}, ${g}`)}return{stdout:h.join(`
|
|
76
85
|
`)+`
|
|
77
|
-
`,stderr:"",exitCode:
|
|
78
|
-
`))),l.exitCode=1;continue}let
|
|
79
|
-
`:"\0"),stderr:"",exitCode:0})),!0):e.mode==="batch"?(e.collected.push(t.path),!0):
|
|
80
|
-
`,set:!0}:e==="PWD"?{value:t.cwd,set:!0}:e==="HOME"?{value:t.home,set:!0}:e==="USER"||e==="LOGNAME"?{value:t.user,set:!0}:e==="LANG"?{value:t.locale,set:!0}:null}function
|
|
81
|
-
`),e.unsupported.add({kind:"feature",command:null,detail:t,message:n})}var
|
|
82
|
-
`;)o+=2;let s=
|
|
83
|
-
`;)
|
|
86
|
+
`,stderr:"",exitCode:d?2:0}}function Ub(e,t,n,r){return t.has("F")?!n.error&&e.fs.isLink?.(n.path)===!0?"@":r&&!t.has("d")?"/":"":""}function Bb(e,t,n,r,i,o,s,u){let a=[{dir:t,prefix:"",items:ti(e,t,r,u),i:0,depth:0}];for(;a.length;){let l=a.at(-1);if(l.i>=l.items.length){a.pop();continue}let{n:f,isDir:c,target:d}=l.items[l.i++];if([...f+(d??"")].some(b=>b.codePointAt(0)<32||b.codePointAt(0)===127||b==="\\"))return k("feature","tree","filename escaping","tree: listing names requiring escaping is not supported");let p=l.i===l.items.length,h=c&&r.has("F")&&!r.has("d")?"/":"";if(n.push(l.prefix+(p?"\u2514\u2500\u2500 ":"\u251C\u2500\u2500 ")+f+(d===void 0?h:" -> "+d+h)),o[c?"dirs":"files"]++,!c||d!==void 0)continue;let m=Ae(l.dir,f);if(l.depth+1>=i){ti(e,m,r).length&&s.add(m);continue}let g=ti(e,m,r,u);a.push({dir:m,prefix:l.prefix+(p?" ":"\u2502\xA0\xA0 "),items:g,i:0,depth:l.depth+1})}}function ti(e,t,n,r=null){let{dirs:i,files:o,links:s}=e.listDir(t),u=s.map(l=>{let f=v(t,l,e);return{n:l,isDir:!f.error&&e.isDir(f.path),target:e.readLink(Ae(t,l))}}),a=n.has("d")?u.filter(({isDir:l})=>l):[...o.map(l=>({n:l,isDir:!1})),...u];return r&&!n.has("a")&&r.collect(t,[...i,...a.map(({n:l})=>l)]),[...i.map(l=>({n:l,isDir:!0})),...a].filter(({n:l})=>n.has("a")||!l.startsWith(".")).sort((l,f)=>B(l.n,f.n))}var qb=new Set(["name","iname","type","path","ipath","mindepth","maxdepth"]),Xn=(e,t)=>e==="-"+t||e==="--"+t;function Cc(e){let t={tokens:e,i:0,depth:{minDepth:0,maxDepth:Number.POSITIVE_INFINITY},hasAction:!1,batches:[],error:null},n=[];for(e[0]==="--"&&t.i++;t.i<e.length&&!/^(?:-.+|!|\()$/u.test(e[t.i]);)n.push(e[t.i++]);let r=Fc(t,0);if(t.error)return{error:t.error};if(!t.hasAction)for(let i of r)i.push({kind:"print"});return{starts:n.length?n:["."],...t.depth,groups:r,batches:t.batches}}function Fc(e,t){let n=[[]],r=!1;if(t>128)return e.error=k("feature","find","expression depth","find: expression nesting above 128 is not supported"),n;for(;e.i<e.tokens.length&&!e.error;){let i=e.tokens[e.i];if(i===")"){t||(e.error=y("find: unexpected closing parenthesis"));break}if(i==="-a"||Xn(i,"and")||i==="-o"||Xn(i,"or")){if(r||n.at(-1).length===0){e.error=y(`find: ${i} with no left-hand expression`);break}(i==="-o"||Xn(i,"or"))&&n.push([]),e.i++,r=i;continue}let o=Wb(e,t);o&&n.at(-1).push(o),r=!1}return!e.error&&r&&(e.error=y(`find: ${r} with no right-hand expression`)),!e.error&&t&&n.at(-1).length===0&&(e.error=y("find: expected an expression")),!e.error&&t&&(e.tokens[e.i]===")"?e.i++:e.error=y("find: missing closing parenthesis")),n}function Wb(e,t){let n=e.i,r=!1;for(;e.tokens[e.i]==="!"||e.tokens[e.i]==="-not";)r=!r,e.i++;let i=e.tokens[e.i++];if(i==="(")return{kind:"group",groups:Fc(e,t+1),negate:r};if(i===void 0||i===")"||i==="-a"||i==="-o"||Xn(i,"and")||Xn(i,"or"))return e.error=y(`find: -not or operator ${i??""} must be followed by a primary`),null;let o=i.startsWith("--")?i.slice(2):i.startsWith("-")?i.slice(1):null;if(["print","print0","prune","empty"].includes(o))return(o==="print"||o==="print0")&&(e.hasAction=!0),{kind:o,negate:r};if(o==="exec"){let s=Gb(e.tokens,e.i-1,r);return s.error?(e.error=s.error,null):(e.i=s.nextI+1,e.hasAction=!0,s.pred.mode==="batch"&&e.batches.push(s.pred),s.pred)}if(qb.has(o)){if(e.i===e.tokens.length)return e.error=y(`find: ${i} requires a value`),null;let s=jb(o,e.tokens[e.i++],r,e.depth);return s.error?(e.error=s.error,null):s}return i===","?(e.error=k("feature","find","comma operator","find: comma expressions are not supported"),null):e.i-1>n&&!i.startsWith("-")?(e.error=y(`find: -not must be followed by a primary, got: ${i}`),null):(e.error=i==="--"||!i.startsWith("-")?y(`find: paths must precede expression: ${i}`):k("option","find",i,`find: unknown option: ${i}`),null)}function jb(e,t,n,r){if(e==="type"){let i=Hb(t);return i.error?i:{kind:e,negate:n,types:i.types}}if(e==="mindepth"||e==="maxdepth"){let i=we(t,`find: -${e}`,t,{max:2147483647,digitsOnly:!0});return i.error?i:(r[e==="mindepth"?"minDepth":"maxDepth"]=i.value,{kind:"true",negate:n})}return{kind:e,negate:n,re:Te(t,{ignoreCase:e==="iname"||e==="ipath"})}}var Ic="fdl",zb="bcps";function Hb(e){let t=e.split(","),n=t.find((o,s)=>t.indexOf(o)!==s);if(n!==void 0)return{error:y(`find: Duplicate file type '${n}' in the argument list to -type.`)};if(t.every(o=>o.length===1&&Ic.includes(o)))return{types:t};let r=`find: -type/--type expects 'f', 'd' or 'l', got: ${e}`;return{error:t.every(o=>o.length===1&&(Ic+zb).includes(o))?k("option","find",`-type ${e}`,r):y(r)}}function Gb(e,t,n){let r=t+1;for(;r<e.length&&e[r]!==";"&&!(e[r]==="+"&&e[r-1]==="{}");)r++;if(r>=e.length)return{error:y("find: -exec: missing terminator (`;` or `{} +`); quote or escape `;`")};if(r===t+1)return{error:y("find: -exec: requires a command")};let i=e.slice(t+1,r),o=e[r]===";"?"each":"batch";if(o==="batch"){if(i.slice(0,-1).some(u=>u.includes("{}")))return{error:y("find: -exec ... +: only one instance of `{}` is supported")};if(n)return{error:k("feature","find","-not -exec ... +","find: `-not -exec ... +` is not supported (the `+` form has no meaningful negation)")}}let s={kind:"exec",mode:o,cmd:i[0],args:i.slice(1),negate:n};return o==="batch"&&(s.collected=[]),{pred:s,nextI:r}}var Xb={file:"f",dir:"d",link:"l"};async function Tc(e,t,n){let r=Cc(t);if(r.error)return r.error;if(e!==""&&t.some(c=>c==="-exec"||c==="--exec"))return k("feature","find","-exec stdin","find: passing shared standard input to -exec is not supported");let{starts:i,minDepth:o,maxDepth:s,groups:u,batches:a}=r,l=U(),f=new Set;try{for(let c of i){let{path:d,error:p}=R(n,"find",c,{follow:!1});if(p){ws(l,n.flushOutput(U(`find: '${c}': ${p}
|
|
87
|
+
`))),l.exitCode=1;continue}let h=new Set;for(let m of Oe(n.fs,d,s,g=>!h.has(g))){let g=Yb(c,d,m.path);if(m.depth>=o&&await _c(u,{kind:m.kind,path:g,abs:m.path,prune:h},n,l),m.kind!=="dir"||m.depth!==s||h.has(m.path))continue;let{dirs:b,files:x,links:S}=n.fs.listDir(m.path);(b.length||x.length||S.length)&&f.add(g)}}for(let c of a){if(c.collected.length===0)continue;let d=c.args.slice(0,-1).concat(c.collected);await Lc(c.cmd,d,n,l)||(l.exitCode=1)}}finally{ht(n.notes,{command:"find",action:"depth limit omitted contents of",noun:["directory","directories"],paths:f})}return l}async function _c(e,t,n,r){for(let i of e){let o=!0;for(let s of i)if(await Zb(s,t,n,r)===!!s.negate){o=!1;break}if(o)return!0}return!1}function Zb(e,t,n,r){if(e.kind==="group")return _c(e.groups,t,n,r);if(e.kind==="true")return!0;if(e.kind==="type")return e.types.includes(Xb[t.kind]);if(e.kind==="name"||e.kind==="iname")return e.re.test(t.path.replace(/\/+$/u,"").split("/").at(-1)||"/");if(e.kind==="prune")return t.kind==="dir"&&t.prune.add(t.abs),!0;if(e.kind==="empty"){if(t.kind==="link")return!1;if(t.kind==="file")return n.fs.isEmptyFile(t.abs);let{dirs:i,files:o,links:s}=n.fs.listDir(t.abs);return i.length+o.length+s.length===0}return e.kind==="path"||e.kind==="ipath"?e.re.test(t.path):e.kind==="print"||e.kind==="print0"?(ws(r,n.flushOutput({stdout:t.path+(e.kind==="print"?`
|
|
88
|
+
`:"\0"),stderr:"",exitCode:0})),!0):e.mode==="batch"?(e.collected.push(t.path),!0):Lc(e.cmd,e.args.map(i=>i.replaceAll("{}",t.path)),n,r)}async function Lc(e,t,n,r){let i=await n.dispatch(e,t,"");return ws(r,i),i.exitCode===0}function ws(e,t){let n=e.exitCode;_(e,t),e.exitCode=n}function Yb(e,t,n){if(n===t)return e;let r=ze(t,n);return e.endsWith("/")?e+r:e+"/"+r}var ys=1e5,Vb=/^([+-]?\d+)\.\.([+-]?\d+)(?:\.\.([+-]?\d+))?$/u,Kb=/^([A-Za-z])\.\.([A-Za-z])(?:\.\.([+-]?\d+))?$/u,Rc=2n**63n-1n,Mc=-(2n**63n),bs=e=>{let t=BigInt(e);return t>Rc||t<Mc?null:t},Pc=(e,t)=>e.mask===null?"0":e.mask[t];function xs(e,t=ys){if(!e.value.includes("{"))return[e];let n=Jb(e);for(let r=0;r<e.value.length;r++){if(e.value[r]!=="{"||Pc(e,r)!=="0")continue;let i=n.get(r);if(!i)continue;let{end:o,commas:s}=i,u=s.length?[]:ey(be(e,r+1,o));if(s.length){let c=r+1;for(let d of[...s,o])u.push(be(e,c,d)),c=d+1}if(u===null)continue;let a=be(e,0,r),l=be(e,o+1),f=[];for(let c of u)if(f.push(...xs(Ga(a,c,l),t)),f.length>t)throw new w("feature","brace expansion limit",`brace expansion \`${e.value}\` would produce more than ${t} words`);return f}return[e]}function Jb(e){let t=[],n=new Map;for(let r=0;r<e.value.length;r++){if(Pc(e,r)!=="0")continue;let i=e.value[r];if(i==="{")t.push({start:r,commas:[]});else if(i==="}"&&t.length){let{start:o,commas:s}=t.pop();n.set(o,{end:r,commas:s})}else i===","&&t.length&&t.at(-1).commas.push(r)}return n}function Qb(e){if(e.mask!==null&&/[12]/u.test(e.mask))return null;let t=Vb.exec(e.value),n=t??Kb.exec(e.value);if(!n)return null;let[r,i]=t?[bs(t[1]),bs(t[2])]:[BigInt(n[1].codePointAt(0)),BigInt(n[2].codePointAt(0))],o=n[3]===void 0?1n:bs(n[3]);if(r===null||i===null||o===null||o===Mc)return null;let s=i>=r?i-r:r-i;return s>Rc?null:{num:t,range:n,from:r,to:i,step:(o<0n?-o:o)||1n,span:s}}function ey(e){let t=Qb(e);if(t===null)return null;let{num:n,from:r,to:i,step:o,span:s}=t,u=s/o+1n;if(u>ys)throw new w("feature","brace expansion limit",`brace expansion \`{${e.value}}\` would produce ${u} words (limit ${ys})`);let a=n?ty(n[1],n[2]):0,l=[],f=i>=r?1n:-1n;for(let c=0n;c<u;c++){let d=r+f*c*o,p=n?ny(d,a):String.fromCodePoint(Number(d));l.push({value:p,mask:null})}return l}function ty(e,t){let n=r=>/^-?0\d/u.test(r);return n(e)||n(t)?Math.max(e.length,t.length):0}function ny(e,t){let n=String(e<0n?-e:e),r=e<0n?"-":"";return r+n.padStart(t-r.length,"0")}var ks=new Set(["CDPATH","GLOBIGNORE","GLOBSORT","BASH_COMPAT","POSIXLY_CORRECT","PATH","RANDOM","SRANDOM","SECONDS","EPOCHSECONDS","EPOCHREALTIME","BASHOPTS","SHELLOPTS","OPTIND"]),Ke=class extends Map{constructor(t){super(t),this.unsetNames=new Set(t?.unsetNames)}set(t,n){if(this.expansionTargets?.has(t))throw new w("feature","temporary assignment side effects","modifying a temporary assignment target while expanding assignment values is not supported");if(ks.has(t)||t==="TZ"&&!["UTC","UTC0",""].includes(n))throw new w("feature",t,`shell variable ${t} is not supported with this value`);return(t==="LANG"||t.startsWith("LC_"))&&Fa(t,n),this.bound?.add(t),this.unsetNames?.delete(t),super.set(t,n)}delete(t){return this.unsetNames.add(t),super.delete(t)}};var Dc=new Set(["$","!","0","-","_"]),ry=new Set(["PPID","UID","EUID","BASHPID","BASH_SUBSHELL","BASH_VERSION","BASH_VERSINFO","BASH_REMATCH","DIRSTACK","PIPESTATUS","FUNCNAME","LINENO","REPLY","BASH","BASH_COMMAND","BASH_ARGV0","BASH_ARGC","BASH_ARGV","BASH_SOURCE","BASH_LINENO","BASH_ALIASES","BASH_CMDS","GROUPS","HOSTTYPE","OSTYPE","MACHTYPE","HOSTNAME","SHLVL","SHELL","TERM","PS4","OPTERR","HISTCMD","BASH_EXECUTION_STRING","BASH_LOADABLES_PATH","COMP_WORDBREAKS"]);function vt(e,t){if(Dc.has(e))throw vs(e);let n=Ss(e,t);if(n)return n;if(Uc(e))throw vs(e);return{value:"",set:!1}}var Uc=e=>ks.has(e)||ry.has(e),vs=e=>new w("feature",`$${e}`,`shell parameter ${e} is not supported`),Bc=(e,t)=>Ss(e,t)?.value??"";function Ss(e,t){return e==="?"?{value:String(t.lastExit),set:!0}:e==="#"?{value:"0",set:!0}:e==="@"?{value:"",set:!1,omit:!0}:e==="*"?{value:"",set:!1}:/^[1-9][0-9]*$/u.test(e)?{value:"",set:!1}:t.vars.has(e)?{value:t.vars.get(e),set:!0}:t.vars.unsetNames.has(e)?{value:"",set:!1}:e==="IFS"?{value:`
|
|
89
|
+
`,set:!0}:e==="PWD"?{value:t.cwd,set:!0}:e==="HOME"?{value:t.home,set:!0}:e==="USER"||e==="LOGNAME"?{value:t.user,set:!0}:e==="LANG"?{value:t.locale,set:!0}:null}function $s(e,t){if(Dc.has(e))throw new w("feature",`$${e}`,`shell parameter ${e} is not supported (this terminal runs no process)`);let n=Ss(e,t);if(n)return n;if(Uc(e))throw vs(e);return iy(t,`$${e}`,`warning: $${e} is unset (this shell has no environment variables; only \`for\` bindings and \`NAME=value\` assignments)`),{value:""}}function iy(e,t,n){Jr(e,n+`
|
|
90
|
+
`),e.unsupported.add({kind:"feature",command:null,detail:t,message:n})}var qc=16e6,Zn=e=>new w("feature","${",e);function Wc(e,t,n){if(Bn(t))throw Zn("extended glob patterns in parameter expansion are not supported");let r=en({value:t.value,mask:t.mask??null}),i=n[0]==="#",o=zc(r);if(o!==null)return i?e.startsWith(o)?e.slice(o.length):e:e.endsWith(o)?e.slice(0,e.length-o.length):e;let s=Te(r,{bash:!0}),u=n.length===2,a=i===u,l=a?e.length:0,f=0;for(;l>=0&&l<=e.length;){let c=i?e.slice(0,l):e.slice(l);if(f+=c.length+r.length,f>qc)throw Zn("parameter pattern removal exceeds the matching work limit");if(s.test(c))return i?e.slice(l):e.slice(0,l);l=ni(e,l,a)}return e}function jc(e,t,n,r){let i="";if(!r&&/^[#%]/u.test(t.value)&&(!t.mask||t.mask[0]==="0")&&(i=t.value[0],t={value:t.value.slice(1),mask:t.mask?.slice(1)??null}),Bn(t))throw Zn("extended glob patterns in parameter expansion are not supported");let o=en({value:t.value,mask:t.mask??null}),s={work:0},u=uy(n,s);if(!o)return i==="#"?u("")+e:i==="%"?e+u(""):e;if((/\\+$/u.exec(o)?.[0].length??0)%2)throw Zn("unescaped trailing backslashes in replacement patterns are not supported");let a=zc(o),l=a===null?sy(e,o,i,s):oy(e,a,i),f=[],c=0;do{let d=l(c);if(!d)break;let[p,h]=d,m=u(e.slice(p,h));if(Es(s,p-c),f.push(e.slice(c,p),m),c=h,!r)break;if(p===h){let g=ni(e,c,!1);f.push(e.slice(c,g)),c=g}}while(c<e.length);return f.push(e.slice(c)),f.join("")}function oy(e,t,n){return r=>{let i=n==="%"?e.length-t.length:e.indexOf(t,r);return i<r||n==="#"&&i!==0||e.slice(i,i+t.length)!==t?null:[i,i+t.length]}}function sy(e,t,n,r){let i=Te(t,{bash:!0});return o=>{for(let s=o;s<=e.length;s=ni(e,s,!1)){for(let u=e.length;u>=s;u=ni(e,u,!0)){if(Es(r,u-s+t.length),i.test(e.slice(s,u)))return[s,u];if(n==="%")break}if(n==="#")break}return null}}function Es(e,t){if(e.work+=t,e.work>qc)throw Zn("parameter replacement exceeds the matching work limit")}function uy(e,t){let n="";for(let r=0;r<e.value.length;r++){let i=e.value[r];e.mask?.[r]!==void 0&&e.mask[r]!=="0"&&(i==="&"||i==="\\")&&(n+="\\"),n+=i}return r=>{let i=[];for(let o=0;o<n.length;o++){let s=n[o],u=s==="\\"&&/[&\\]/u.test(n[o+1]??"")?n[++o]:s==="&"?r:s;Es(t,u.length),i.push(u)}return i.join("")}}function ni(e,t,n){let r=t+(n?-1:1);return r>0&&r<e.length&&/[\uDC00-\uDFFF]/u.test(e[r])&&/[\uD800-\uDBFF]/u.test(e[r-1])?r+(n?-1:1):r}function zc(e){let t="";for(let n=0;n<e.length;n++){let r=e[n];if(r==="\\"&&n+1<e.length)t+=e[++n];else{if(/[*?[]/u.test(r))return null;t+=r}}return t}var De=e=>BigInt.asIntN(64,e),V=(e,t)=>new w("feature","arithmetic "+e,"arithmetic expansion: "+t);function Hc(e){let t=10n,n=!1,r=0n,i=0;if(e[0]==="0"&&(i=1,t=8n,n=!0,(e[1]==="x"||e[1]==="X")&&(t=16n,i=2)),i===2&&e.length===2)throw V("number","hexadecimal constant has no digits");for(;i<e.length;i++){let o=e[i];if(o==="#"){if(n||r<2n||r>64n||i===e.length-1)throw V("number","invalid arithmetic base or integer constant");t=r,r=0n,n=!0;continue}let s=o.codePointAt(0),u=s>=48&&s<=57?s-48:s>=97&&s<=122?s-87:s>=65&&s<=90?s-(t<=36n?55:29):o==="@"?62:o==="_"?63:-1;if(u<0||BigInt(u)>=t)throw V("number","value too great for base in "+e.slice(0,40));r=De(r*t+BigInt(u))}return r}function ay(e,t){if(t<0n)throw V("exponent","exponent less than zero");let n=1n;for(let r=t,i=e;r!==0n;r>>=1n,i=De(i*i))r&1n&&(n=De(n*i));return n}function Ns(e,t,n,r){switch(e){case"+":return De(t+n);case"-":return De(t-n);case"*":return De(t*n);case"/":case"%":{if(n===0n&&r)throw V("division","division by zero");let i=n===0n?1n:n;return De(e==="/"?t/i:t%i)}case"**":return ay(t,n);case"<<":case">>":{if(n<0n||n>63n)throw V("shift count","shift counts outside 0..63 are not supported");return De(e==="<<"?t<<n:t>>n)}case"&":return t&n;case"^":return t^n;case"|":return t|n;case"<":return BigInt(t<n);case"<=":return BigInt(t<=n);case">":return BigInt(t>n);case">=":return BigInt(t>=n);case"==":return BigInt(t===n);case"!=":return BigInt(t!==n);default:throw V("operator","unsupported operator "+e)}}var ly=new Set(["=","+=","-=","*=","/=","%=","<<=",">>=","&=","^=","|="]),fy=[["||"],["&&"],["|"],["^"],["&"],["==","!="],["<","<=",">",">="],["<<",">>"],["+","-"],["*","/","%"],["**"]],cy=new Map(fy.flatMap((e,t)=>e.map(n=>[n,t+3]))),dy=/^(?:<<=|>>=|\+\+|--|\*\*|&&|\|\||<<|>>|[+\-*/%&^|=!<>]=|[+\-*/%&^|=!~<>?:,()])/u;function py(e){let t=[];for(let n=0;n<e.length;){if(t.length>=1e4)throw V("limit","expression token limit exceeded");let r=e.slice(n),i=/^[ \t\n]+/u.exec(r);if(i){n+=i[0].length;continue}let o=/^[0-9][A-Za-z0-9#@_]*/u.exec(r),s=/^[A-Za-z_][A-Za-z0-9_]*/u.exec(r),u=dy.exec(r);if(o)t.push({type:"number",value:Hc(o[0]),raw:o[0]});else if(s)t.push({type:"name",value:s[0],raw:s[0]});else if(u)t.push({type:"operator",value:u[0],raw:u[0]});else throw V(r[0]==="["||r[0]==="]"?"arrays":"syntax","unsupported expression token "+JSON.stringify(r[0]));n+=t.at(-1).raw.length}return t.push({type:"end",value:""}),t}function Gc(e){let t=new As(py(e));if(t.token.type==="end")return{type:"number",value:0n};let n=t.expression();if(t.token.type!=="end")throw V("syntax","unexpected token "+t.token.value);return n}var As=class{constructor(t){this.tokens=t,this.at=0,this.depth=0}get token(){return this.tokens[this.at]}next(){return this.tokens[this.at++]}accept(t){return this.token.value===t?this.next():null}expect(t){if(!this.accept(t))throw V("syntax","expected "+t)}expression(t=0){if(++this.depth>128)throw V("limit","expression nesting limit exceeded");let n=this.prefix();for(;;){let r=this.token.value;if(r==="?"&&t<=2){this.next();let u=this.expression();this.expect(":"),n={type:"condition",test:n,consequent:u,alternate:this.expression(2)};continue}let i=ly.has(r),o=r===","?0:i?1:cy.get(r);if(o===void 0||o<t)break;if(this.next(),i&&n.type!=="name")throw V("assignment","attempted assignment to non-variable");let s=this.expression(o+(i||r==="**"?0:1));n={type:i?"assignment":"binary",op:r,left:n,right:s}}return this.depth--,n}prefix(){let t=this.next();if(["+","-","!","~"].includes(t.value))return{type:"unary",op:t.value,value:this.expression(14)};if(t.value==="++"||t.value==="--"){let n=this.next();if(n.type!=="name")throw V("increment","increment requires a scalar variable");return{type:"increment",op:t.value,name:n.value,post:!1}}if(t.value==="("){let n=this.expression();return this.expect(")"),{type:"group",value:n}}if(t.type!=="number"&&t.type!=="name")throw V("syntax","operand expected");return t.type==="name"&&(this.token.value==="++"||this.token.value==="--")?{type:"increment",op:this.next().value,name:t.value,post:!0}:t}};function Pt(e,t,n=0){return Zc(e,{ctx:t,steps:1e4,characters:2e5},n,!0)}function Zc(e,t,n,r){if(typeof e!="string")throw V("value","expression must be a string");if(t.characters-=e.length,e.length>1e5||t.characters<0)throw V("limit","expression size limit exceeded");if(n>128)throw V("limit","variable recursion limit exceeded");return Yc(Gc(e),t,n+1,r)}function Os(e,t,n,r){if(!r)return 0n;let i;try{i=vt(e,t.ctx)}catch(o){throw V("variable",Z(o))}return i.set&&i.value!==""?Zc(i.value,t,n+1,!0):0n}function Xc(e,t,n,r){if(r)try{vt(e,n.ctx),n.ctx.vars.set(e,t.toString())}catch(i){throw V("assignment",Z(i))}return t}function Yc(e,t,n,r){if(--t.steps<0||n>128)throw V("limit","expression evaluation limit exceeded");let i=(o,s=r)=>Yc(o,t,n+1,s);switch(e.type){case"number":return e.value;case"name":return Os(e.value,t,n,r);case"group":return i(e.value);case"unary":{let o=i(e.value);return e.op==="+"?o:e.op==="-"?De(-o):e.op==="!"?BigInt(o===0n):~o}case"increment":{let o=Os(e.name,t,n,r),s=Xc(e.name,De(o+(e.op==="++"?1n:-1n)),t,r);return e.post?o:s}case"assignment":{let o=e.left.value,s=e.op==="="?0n:Os(o,t,n,r),u=i(e.right);return Xc(o,e.op==="="?u:Ns(e.op.slice(0,-1),s,u,r),t,r)}case"condition":{let o=i(e.test)!==0n,s=i(e.consequent,r&&o),u=i(e.alternate,r&&!o);return o?s:u}case"binary":{let o=i(e.left),s=r&&(e.op==="&&"?o!==0n:e.op==="||"?o===0n:!0),u=i(e.right,s);return e.op===","?u:e.op==="&&"?BigInt(o!==0n&&u!==0n):e.op==="||"?BigInt(o!==0n||u!==0n):Ns(e.op,o,u,r)}default:throw V("syntax","unsupported expression")}}var ri=e=>new w("feature","${",e);async function Vc(e,t,n,r){if(e.name==="@"||e.name==="*")throw ri("substring and replacement of positional parameter lists are not supported");if(!t.set)return t;if(e.operator===":")try{return{value:await hy(t.value,e.word,n,r)}}catch(l){throw l.halt=!0,l}let i=e.word,o=0;for(;i[o]==="\\"&&i[o+1]===`
|
|
91
|
+
`;)o+=2;let s=Kc(i,"/",r.readExpansion,i[o]==="/"?o+1:0),u=await r.expand(i.slice(0,s),{pattern:!0}),a=await r.expand(s<i.length?i.slice(s+1):"",{replacement:!0});return{value:jc(t.value,u,a,e.operator==="//")}}async function hy(e,t,n,r){if(/\P{ASCII}/u.test(e))throw ri("locale-dependent slicing of non-ASCII parameters is not supported");let i=Kc(t,":",r.readExpansion),o=async l=>Pt((await r.expand(l,{arithmetic:!0})).value,n),s=await o(t.slice(0,i)),u=BigInt(e.length);if(s<0n&&(s+=u),s<0n||s>u)return"";let a=u;if(i<t.length){let l=await o(t.slice(i+1));if(a=l<0n?u+l:s+l,a>oe)throw ri("substring length overflows the shell integer range");if(a<s){let f=new Error(`${t.slice(i+1)}: substring expression < 0`);throw f.exitCode=1,f.halt=!0,f}}return e.slice(Number(s),Number(a>u?u:a))}function Kc(e,t,n,r=0){let i=0,o=null,s=0;for(let u=r;u<e.length;u++){let a=e[u];if(o==="'"){a==="'"&&(o=null);continue}if(o==="ansi"){a==="\\"?u++:a==="'"&&(o=null);continue}if(a==="\\"){u++;continue}if(t===":"&&(a==="'"||a==='"'))throw ri("quoted substring arithmetic is not supported");if(a==='"'){o=o==='"'?null:'"';continue}if(a==="'"&&!o){o=a;continue}if(a==="$"){let l=n(e,u,0,t===":"||o==='"');if(l){u+=l.raw.length-1;continue}let f=u+1;for(;e[f]==="\\"&&e[f+1]===`
|
|
92
|
+
`;)f+=2;if(!o&&e[f]==="'"){o="ansi",u=f;continue}}if(!o){if(t===":"){if(a==="(")i++;else if(a===")")i--;else if(i===0&&a==="?")s++;else if(i===0&&a===":"&&s){s--;continue}if(i!==0)continue}if(a===t)return u}}return e.length}var my=/^[A-Za-z_][A-Za-z0-9_]*$/u;async function Jc(e,t,n){let{lookup:r,expand:i}=n,{name:o,operator:s,word:u=""}=e,a=r(o,{quiet:s!==""});if(!s)return a;if(s==="length")return gy(o,a.value);if(s===":"||s.startsWith("/"))return Vc(e,a,t,n);if(s[0]==="#"||s[0]==="%")return!a.value||!u?a:{value:Wc(a.value,await i(u,{pattern:!0}),s)};let l=!a.set||s.startsWith(":")&&a.value==="",f=s[s.length-1];if(f==="+")return l?{value:"",...a.omit?{omit:!0}:{}}:i(u,{});if(!l)return a;if(f==="?")throw await wy(o,u,s.startsWith(":"),i,t);if(f!=="=")return i(u,{});if(!my.test(o)){let d=new Error(`$${o}: cannot assign in this way`);throw d.exitCode=1,d.halt=!0,d}let c=await i(u,{assignment:!0});return t.vars.set(o,c.value),{value:t.vars.get(o)}}function gy(e,t){if(e==="*"||e==="@")return{value:"0"};if(/\P{ASCII}/u.test(t))throw Ct("#"+e,"locale-dependent length of non-ASCII parameters is not supported");return{value:String(t.length)}}async function wy(e,t,n,r,i){let o=t?by(await r(t,{error:!0}),i):n?"parameter null or not set":"parameter not set",s=new Error(`${e}: ${o}`);return s.exitCode=1,s.halt=!0,s}function by(e,t){let n=t.vars.get("IFS")??`
|
|
84
93
|
`;if(n==="")return e.value;if(n!==`
|
|
85
|
-
`)throw
|
|
94
|
+
`)throw Ct("?","custom IFS separators in parameter errors are not supported");let r=new Set(e.empty),i=[],o=!1,s="",u=()=>{(s||o)&&i.push(s),s="",o=!1};for(let a=0;a<=e.value.length&&(r.has(a)&&(o=!0),a!==e.value.length);a++){let l=e.value[a],f=!e.mask||e.mask[a]==="0";f&&/[ \t\n]/u.test(l)?u():(s+=l,o||=!f)}return u(),i.join(" ")}function St(e,t){return fe(e,{cwd:e.cwd,lastExit:e.lastExit,vars:new Ke(e.vars),functions:new Map(e.functions),loopDepth:0,errexit:e.errexit,errexitOff:e.errexitOff},t)}async function fe(e,t,n){let r=Object.fromEntries(Object.keys(t).map(i=>[i,e[i]]));Object.assign(e,t);try{return await n()}finally{Object.assign(e,r)}}async function Yn(e,t){let n=[],r=e[0],i=r?.value==="export"&&!/[12]/u.test(r.mask??"")&&!r.empty?.length;for(let o of e)for(let s of xs(o)){let u=i&&s===o&&Nn(o);if(u){let a=await xy(s,u.end,t);n.push({value:a,mask:"1".repeat(a.length),q:!0})}else n.push(...await ed(ii(s,t,s===o?!1:"word"),t,!0))}return{argv:yy(n,t)}}function yy(e,t){let n=[];for(let r of e){if(Of(r)){let i=If(r,t);if(i.length>0){n.push(...i);continue}}(r.value!==""||r.q)&&n.push(r.value)}return n}async function Is(e,t){let{argv:n}=await Yn([e],t);return n.length===1?{value:n[0]}:{error:`${e.value}: ambiguous redirect`}}async function xy(e,t,n){let r=be(e,t);return e.value.slice(0,t)+await Dt(r,n,!0)}async function Dt(e,t,n=!1){return(await ed(ii(e,t,n),t,!1,n))[0].value}var rn=e=>e.vars.get("HOME")??e.home,Qc=(e,t)=>e.mask===null?"0":e.mask[t];function ii(e,t,n=!1){let r=Ha(e,n);if(r.size===0)return e;let i=e.value,o=rn(t),s="",u="",a=[];for(let l=0;l<i.length;l++){if(e.empty?.includes(l)&&a.push(s.length),r.has(l)){let f=o==="/"&&i[l+1]==="/"?"":o;s+=f,u+="1".repeat(f.length);continue}s+=i[l],u+=Qc(e,l)}return e.empty?.includes(i.length)&&a.push(s.length),{value:s,mask:/[12]/u.test(u)?u:null,...a.length?{empty:a}:{}}}function Cs(e,t){return fe(t,{strictExpansion:!0},()=>Fs(ii(e,t),t))}async function ed(e,t,n,r=!1){let i=await Fs(e,t,r);return n?Sy(i,t):[i]}async function Fs(e,t,n=!1){let r={value:"",mask:"",empty:[],split:!1},i=(o,s)=>{r.value+=o,r.mask+=s};e.value===""&&e.mask!==null&&r.empty.push(0);for(let o=0;o<=e.value.length&&(e.empty?.includes(o)&&r.empty.push(r.value.length),o!==e.value.length);o++){let s=Qc(e,o),u=e.value[o];if(s==="0"&&(u==="<"||u===">")&&e.value[o+1]==="(")throw new w("feature",`${u}(`,`process substitution (\`${u}(\u2026)\`) is not supported`);let a=s!=="1"&&(u==="$"||u==="`"),l=e.value[o+1]==="("||e.value[o+1]==="{",f=a?ky(e,o,u,s,l):null;if(!f){i(e.value[o],s);continue}o+=f.raw.length-1;let c=await vy(f,t,s==="2",n);if(c.literal){i(f.raw,s.repeat(f.raw.length));continue}if(!c.omit)if(s==="2")c.value===""&&r.empty.push(r.value.length),i(c.value,"2".repeat(c.value.length));else{r.split=!0;for(let d of c.empty??[])r.empty.push(r.value.length+d);c.q&&!c.value&&!c.empty?.length&&r.empty.push(r.value.length),i(c.value,c.mask??"0".repeat(c.value.length))}}return r.q=r.empty.length>0||/[12]/u.test(r.mask),r}function ky(e,t,n,r,i){return n==="`"?ot(e.value,t):i?ut(e.value,t,0,r==="2"):bo(e.value,t,e.mask)}async function vy(e,t,n,r){if(e.command!==void 0)return{value:await t.substitute(e.command,e.backtick)};if(e.arithmetic!==void 0)try{let i=await fe(t,{strictExpansion:!0},()=>Dt(xo(e.arithmetic,!0),t));return{value:String(Pt(i,t))}}catch(i){throw i.halt=!0,i}return e.parameter!==void 0?e.parameter.operator===""&&!t.strictExpansion&&!/^[0-9]{2,}$/u.test(e.parameter.name)?$s(e.parameter.name,t):Jc(e.parameter,t,{lookup:i=>vt(i,t),readExpansion:ut,expand:(i,o={})=>{let s=o.pattern||o.error||o.replacement||o.arithmetic,u=xo(i,o.arithmetic||!s&&n),a=!s&&(o.assignment||r),l=o.assignment?"parameterAssign":a?!0:"parameter";return fe(t,{strictExpansion:!0},()=>Fs(o.arithmetic?u:ii(u,t,l),t,a))}}):t.strictExpansion?vt(e.name,t):$s(e.name,t)}function Sy(e,t){if(!e.split)return e.value!==""||e.q?[e]:[];let n=t.vars.get("IFS")??`
|
|
86
95
|
`;if(n!==""&&n!==`
|
|
87
|
-
`)throw new w("feature","IFS","custom IFS separators are not supported");let r=[],i={value:"",mask:"",q:!1},o=()=>{(i.value!==""||i.q)&&r.push(i),i={value:"",mask:"",q:!1}},s=new Set(e.empty);for(let u=0;u<=e.value.length&&(s.has(u)&&(i.q=!0),u!==e.value.length);u++){let a=e.value[u],l=e.mask[u];if(n!==""&&l==="0"&&/[ \t\n]/u.test(a)){o();continue}i.value+=a,i.mask+=l,i.q||=l!=="0"}return o(),r}function
|
|
88
|
-
`}`;_(n.result,n.ctx.flushOutput({...
|
|
89
|
-
`),t.byteLocale?r[0]:n.codePointAt(0)}function
|
|
90
|
-
`,n.failed=!0),i||"0"}var
|
|
91
|
-
`,n.failed=!0,t?
|
|
92
|
-
`,
|
|
93
|
-
|
|
94
|
-
`?
|
|
95
|
-
|
|
96
|
-
`)throw new Ne("'---' expected",f);f++}return d(l,">","+"),{hunk:c,next:f}}function Qx(e,t){let n=_t.exec(e[t]??"");if(!n)return null;let r=Xr.exec(e[t+1]??"");if(!r)throw new Ne("'*** ' range expected",t+1);let i=t+2,o=$f(e,i,zn,"-");i=o.next;let s=zn.exec(e[i]??"");if(!s)throw new Ne("'--- ' range expected",i);let u=$f(e,i+1,null,"+"),a=o.lines.length===0?u.lines.filter(d=>d.tag===" "):o.lines,l=u.lines.length===0?o.lines.filter(d=>d.tag===" "):u.lines,c=Ef(r,a.length),f=Ef(s,l.length);return{hunk:{oldStart:c,newStart:f,label:n[1]||null,lines:ey(a,l)},next:u.next}}var Ef=(e,t)=>t===0?Number(e[1]):Number(e[1])-1;function $f(e,t,n,r){let i=[],o=t;for(;o<e.length;o++){let s=e[o];if(n&&n.test(s)||_t.test(s)||Xr.test(s)||!n&&zn.test(s))break;if(ls(s)){i[i.length-1].text=cs(i.at(-1).text);continue}let u=s===`
|
|
96
|
+
`)throw new w("feature","IFS","custom IFS separators are not supported");let r=[],i={value:"",mask:"",q:!1},o=()=>{(i.value!==""||i.q)&&r.push(i),i={value:"",mask:"",q:!1}},s=new Set(e.empty);for(let u=0;u<=e.value.length&&(s.has(u)&&(i.q=!0),u!==e.value.length);u++){let a=e.value[u],l=e.mask[u];if(n!==""&&l==="0"&&/[ \t\n]/u.test(a)){o();continue}i.value+=a,i.mask+=l,i.q||=l!=="0"}return o(),r}function td(e,t,n){let r=Ec(t,n),i={ctx:n,options:r,seen:new Set,result:U(),total:0n,failed:!1};r.stderr&&_(i.result,n.flushOutput(U(r.stderr)));for(let o of r.operands){let s=o.length>2?o.replace(/\/+$/u,"/"):o,u=R(n,"du",s,{follow:r.links!=="none"});if(u.error){_(i.result,n.flushOutput(y(`du: cannot access ${H(s,n)}: ${u.error}`))),i.failed=!0;continue}try{$y(u.path,s,i)}catch(a){let l=O(a),f="du: "+Z(a);if(l&&n.unsupported.add({...l,command:l.command??"du",message:f}),_(i.result,n.flushOutput(y(f))),i.failed=!0,l)return i.result}}return r.flags.has("c")&&Ts(i.total,"total",i),i.result.exitCode=i.failed?1:0,i.result}function $y(e,t,n){let{ctx:r,options:i}=n;if(!i.flags.has("inodes")&&r.fs.isDir(e)&&Object.values(r.outputFds??{}).some(s=>typeof s=="object"&&s.path?.startsWith(e==="/"?"/":e+"/")))throw new w("feature","recursive metadata output overlap","output within a measured directory is not supported");let o=[{path:e,name:t,depth:0}];for(;o.length;){let s=o.pop();if(s.total!==void 0){s.depth<=i.depth&&Ts(s.total,s.name,n),s.parent&&!i.flags.has("S")&&(s.parent.total+=s.total);continue}let u=r.fs.isDir(s.path);if(u&&r.fs.isFile(s.path))throw new w("feature","ambiguous file type",`path is both a file and a directory: ${s.name}`);if(!u&&i.links==="all"&&r.fs.isLink?.(s.path))throw new w("option","dereference",`following symbolic links is not supported: ${s.name}`);let a=u?s.path:r.fs.fileIdentity?.(s.path)??s.path;if(!i.flags.has("l")&&n.seen.has(a))continue;n.seen.add(a);let l=u?"dir":r.fs.isLink?.(s.path)?"link":"file",f=u?0:r.fs.fileSize(s.path),c=i.flags.has("inodes")?1n:i.flags.has("A")?BigInt(f):BigInt(ei(f,l));if(n.total+=c,u){s.total=c,o.push(s);let d=r.fs.listDir(s.path),p=[...new Set([...d.dirs,...d.files,...d.links])].sort(B),h=s.name.endsWith("/")?s.name:s.name+"/";for(let m=p.length-1;m>=0;m--)o.push({path:Ae(s.path,p[m]),name:h+p[m],depth:s.depth+1,parent:s})}else s.parent&&(s.parent.total+=c),(s.depth===0||i.flags.has("a")&&s.depth<=i.depth)&&Ts(c,s.name,n)}}function Ts(e,t,n){let r=`${Gn(e,n.options.scale)} ${t}${n.options.flags.has("0")?"\0":`
|
|
97
|
+
`}`;_(n.result,n.ctx.flushOutput({...U(),stdout:r,events:[{fd:1,text:r}]}))}var Ey=/^%([-+ 0#']*)(\d+|\*)?'?(?:\.(\d+|\*)?)?[hlL]?(.)?/su,Ny="diouxXeEfFgGcs";function si(e){let t=[],n="";for(let r=0;r<e.length;r++){if(e[r]!=="%"){n+=e[r];continue}if(e[r+1]==="%"){n+="%",r++;continue}if(/^%[^a-zA-Z%]*\$/u.test(e.slice(r)))throw new $("positional printf arguments are not supported",null,"positional format arguments");let i=Ey.exec(e.slice(r)),o=i[4];if(o==="a"||o==="A")throw new $("hexadecimal floating-point formats are not supported",null,"hexadecimal float format");if(o==="%"){n+="%",r+=i[0].length-1;continue}if(o===void 0||!Ny.includes(o)){n+=i[0],r+=i[0].length-1;continue}n!==""&&(t.push(n),n="");let s=i[1];t.push({minus:s.includes("-"),plus:s.includes("+"),space:s.includes(" "),zero:s.includes("0"),alt:s.includes("#"),width:i[2]===void 0?null:i[2]==="*"?"*":Number(i[2]),precision:i[3]===void 0?i[0].includes(".")?0:null:i[3]==="*"?"*":Number(i[3]),conv:o}),r+=i[0].length-1}return n!==""&&t.push(n),t}function $t(e,t,n,r){let i=n.width??0;if(i>Ee)throw new $("format width exceeds the output limit",null,"format size limit");let o=i-e.length-[...t].length;return o<=0?e+t:n.minus?e+t+" ".repeat(o):n.zero&&r?e+"0".repeat(o)+t:" ".repeat(o)+e+t}var id=e=>e.plus?"+":e.space?" ":"",od=e=>e==="X"||e==="E"||e==="G"||e==="F";function Ut(e,t){if(t.precision>Ee)throw new $("format precision exceeds the output limit",null,"format size limit");let{conv:n}=t;if(!Number.isFinite(e)){if(Number.isNaN(e))throw new $("formatting signed NaN is not supported",null,"signed NaN");let r=e<0?"-inf":"+inf";return od(n)?r.toUpperCase():r}return"ouxX".includes(n)&&(e>=2**64||e<-(2**63))?nd(e,{...t,conv:"g"}):"diouxX".includes(n)?Ay(e,t):nd(e,t)}function Ay(e,t){let{conv:n}=t,r=n==="d"||n==="i",i=r?Math.trunc(e)===0:e===0,o=BigInt(Math.trunc(e)),s=!1;o<0n&&(r?(s=!0,o=-o):o=BigInt.asUintN(64,o));let u=n==="o"?8:n==="x"||n==="X"?16:10,a=o.toString(u);n==="X"&&(a=a.toUpperCase()),t.precision!==null&&(t.precision===0&&i?a=t.alt&&!r?"0":"":a=a.padStart(t.precision,"0"));let l=s?"-":r&&a!==""?id(t):"";return t.alt&&!i&&(n==="o"&&(a="0"+a),(n==="x"||n==="X")&&(l+=n==="x"?"0x":"0X")),$t(l,a,t,t.precision===null)}var oi=100;function nd(e,t){let{conv:n}=t;if(t.precision>oi)throw new $(`floating-point precision above ${oi} is not supported`,null,"float precision limit");let r=t.precision??6,i=e<0||Object.is(e,-0),o=Math.abs(e),s;return n==="e"||n==="E"?s=ud(o,r):n==="f"||n==="F"?s=ad(o,r):s=Oy(o,r,t.alt),t.alt&&r===0&&n!=="g"&&n!=="G"&&(s=n==="e"||n==="E"?s.replace("e",".e"):s+"."),od(n)&&(s=s.toUpperCase()),$t(i?"-":id(t),s,t,!0)}function sd(e,t,n,r){let i=t.slice(r);if(!/^50*$/u.test(i))return e;let o=t.slice(0,n),s=o.at(-1);return Number(s)%2===0?o:e}function ud(e,t){let n=e.toExponential(oi),r=n.indexOf("."),i=n.indexOf("e"),[o,s]=e.toExponential(t).split("e"),u=sd(o,n.slice(0,i),t===0?r:r+1+t,r+1+t),a=Number(u===o?s:n.slice(i+1));return`${u}e${a<0?"-":"+"}${String(Math.abs(a)).padStart(2,"0")}`}function ad(e,t){if(e>=1e21)return BigInt(e).toString()+(t>0?"."+"0".repeat(t):"");let n=e.toFixed(oi),r=n.indexOf(".");return sd(e.toFixed(t),n,t===0?r:r+1+t,r+1+t)}function Oy(e,t,n){let r=t===0?1:t;if(e===0)return n?"0."+"0".repeat(r-1):"0";let i=ud(e,r-1),o=i.indexOf("e"),s=Number(i.slice(o+1));if(s<-4||s>=r)return n?i.includes(".")?i:i.slice(0,o)+"."+i.slice(o):rd(i.slice(0,o))+i.slice(o);let u=ad(e,r-1-s);return n?u.includes(".")?u:u+".":rd(u)}var rd=e=>e.includes(".")?e.replace(/\.?0+$/u,""):e;var Iy=/^[+-]?(?:0[bB][01]+|0[xX][\da-fA-F]+|0[0-7]*|[1-9]\d*)/u,Cy=/^[+-]?(?:0[xX](?:[\da-fA-F]+(?:\.[\da-fA-F]*)?|\.[\da-fA-F]+)(?:[pP][+-]?\d+)?|(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?|inf(?:inity)?|nan(?:\([\w]*\))?)/iu;function cd(e,t){if(e?.[0]!=="'"&&e?.[0]!=='"')return null;let n=e.slice(1);if(n==="")return null;let r=A(n),i=t.byteLocale?1:A(String.fromCodePoint(n.codePointAt(0))).length;return r.length>i&&(t.stderr+=`printf: warning: ${P(r.slice(i))}: character(s) following character constant have been ignored
|
|
98
|
+
`),t.byteLocale?r[0]:n.codePointAt(0)}function dd(e,t,n){if(e===void 0||e==="")return"0";let r=e.replace(/^[ \t\n\r\f\v]+/u,""),i=t.exec(r)?.[0]??"";return(i.length!==r.length||i==="")&&(n.stderr+=`printf: ${pd(e,n)}: ${i?"value not completely converted":"expected a numeric value"}
|
|
99
|
+
`,n.failed=!0),i||"0"}var ld={"\x07":"\\a","\b":"\\b"," ":"\\t","\n":"\\n","\v":"\\v","\f":"\\f","\r":"\\r","\\":"\\\\","'":"\\'"},fd=e=>"\\"+e.toString(8).padStart(3,"0");function pd(e,t){let n="";for(let r of e){if(ld[r]!==void 0){n+=ld[r];continue}let i=r.codePointAt(0);if(i<32||i===127){n+=fd(i);continue}n+=i>127&&t.byteLocale?A(r).map(fd).join(""):r}return`'${n}'`}function ui(e,t,n){let r=cd(e,n);if(r!==null)return BigInt(r);let i=dd(e,Iy,n),o=i[0]==="-",s=i.replace(/^[+-]/u,""),u=BigInt(/^0[0-7]+$/u.test(s)?"0o"+s:s),a=o?-u:u;return(t?u>nt:a<tt||a>oe)?(n.stderr+=`printf: ${pd(e,n)}: Numerical result out of range
|
|
100
|
+
`,n.failed=!0,t?nt:o?tt:oe):t?BigInt.asUintN(64,a):a}function ai(e,t){let{conv:n}=t,r=n==="d"||n==="i",i=e<0n,o=n==="o"?8:n==="x"||n==="X"?16:10,s=(i?-e:e).toString(o);n==="X"&&(s=s.toUpperCase()),e===0n&&t.precision===0&&(s=""),s=s.padStart(t.precision??0,"0");let u=i?"-":r?t.plus?"+":t.space?" ":"":"";return t.alt&&(n==="o"&&!s.startsWith("0")&&(s="0"+s),e!==0n&&(n==="x"||n==="X")&&(u=n==="x"?"0x":"0X")),$t(u,s,t,t.precision===null)}function hd(e,t,n){let r=cd(e,n),i=r===null?dd(e,Cy,n):String(r),o=i.replace(/^[+-]/u,"");if(/^(?:inf|nan)/iu.test(o)){let a=i.startsWith("-")?"-":t.plus?"+":t.space?" ":"",l=/^nan/iu.test(o)?"nan":"inf";return t.conv===t.conv.toUpperCase()&&(l=l.toUpperCase()),$t(a,l,t,!1)}let s=Ry(o),u=i.startsWith("-")?-s.value:s.value;if(t.precision>100||"gG".includes(t.conv)&&t.precision>96)throw new w("feature","float precision limit","floating-point precision exceeds the supported limit");try{let a=Ut(u,t);if(!s.exact){let[l,f]=Fy(s.value);for(let c of[l,f])if(Ut(i.startsWith("-")?-c:c,t)!==a)throw new w("feature","floating-point precision","floating-point formatting at this precision is not supported")}return a}catch(a){throw a.gap?new w("feature",a.gap,a.message):a}}var on=new DataView(new ArrayBuffer(8));function md(e){return on.setFloat64(0,e),on.getBigUint64(0)}function Fy(e){let t=md(e);on.setBigUint64(0,t-1n);let n=on.getFloat64(0);return on.setBigUint64(0,t+1n),[n,on.getFloat64(0)]}function Ty(e){let t=md(e),n=Number(t>>52n);return{coefficient:t&(1n<<52n)-1n|(n?1n<<52n:0n),exponent:n?n-1075:-1074}}function _s(e,t){let n=e.replace(/^0+|0+$/gu,"");return{digits:n||"0",exponent:n?t+e.length-e.replace(/0+$/u,"").length:0}}function _y({coefficient:e,exponent:t}){return t<0?_s((e*5n**BigInt(-t)).toString(),t):_s((e<<BigInt(t)).toString(),0)}function Ly(e,t){let n=e.exponent-t.exponent;return n>=0?e.coefficient<<BigInt(n)===t.coefficient:e.coefficient===t.coefficient<<BigInt(-n)}function Ry(e){let t=/^0x/iu.test(e),n,r;if(t)n=My(e),r=Py(n);else{let[u,a="0"]=e.split(/[eE]/u),[l,f=""]=u.split(".");n=_s(l+f,Number(a)-f.length),r=Number(e)}if(!Number.isFinite(r))throw new w("feature","floating-point range","floating-point values outside the JavaScript number range are not supported");if(r===0){if(t?n.coefficient!==0n:n.digits!=="0")throw new w("feature","floating-point range","floating-point underflow is not supported");return{value:r,exact:!0}}let i=Ty(r),o=_y(i),s=t?Ly(n,i):n.digits===o.digits&&n.exponent===o.exponent;return{value:r,exact:s&&o.exponent>=-100&&o.digits.length<=101}}function My(e){let[t,n="0"]=e.slice(2).split(/[pP]/u),[r,i=""]=t.split("."),o=(r+i).replace(/^0+/u,"")||"0";if(o.length>4096)throw new w("feature","floating-point input limit","hexadecimal floating-point significands above 4096 digits are not supported");return{coefficient:BigInt("0x"+o),exponent:Number(n)-4*i.length}}function Py({coefficient:e,exponent:t}){if(e===0n)return 0;let n=e.toString(2).length,r=t+n-1;if(r>1023)return 1/0;if(r<-1075)return 0;let i=Math.max(0,n-53,-1074-t),o=e>>BigInt(i);if(i>0){let s=e-(o<<BigInt(i)),u=1n<<BigInt(i-1);(s>u||s===u&&o%2n!==0n)&&o++}return Number(o)*2**(t+i)}var gd={a:7,b:8,e:27,f:12,n:10,r:13,t:9,v:11,'"':34,"\\":92};function bd(e,t){let n=[];for(let r=0;r<e.length;)if(e[r]==="%"){if(e[r+1]==="%"||r+1===e.length){n.push([37]),r+=2;continue}let i=/^%([-+ #0']*)(\d+)?(?:\.(\d*))?([\s\S])?/u.exec(e.slice(r)),[,o,s,u,a]=i;if(!a||a==="%")throw new Error(`invalid directive: ${i[0]}`);if(!"nsF".includes(a))throw new w("feature","%"+a,`format %${a} is not supported`);if(o.includes("'"))throw new w("feature","grouped format","digit grouping in stat formats is not supported");let l={field:a,conv:"u",width:Number(s??0),precision:u===void 0?null:Number(u||0),minus:o.includes("-"),zero:o.includes("0"),plus:o.includes("+"),space:o.includes(" "),alt:o.includes("#")};if(l.width>Ee||l.precision>Ee)throw new w("feature","format size limit","format width or precision exceeds the output limit");n.push(l),r+=i[0].length}else if(e[r]==="\\"&&t){let i=e[r+1],o=/^(?:[0-7]{1,3}|x[\da-fA-F]{1,2})/u.exec(e.slice(r+1))?.[0];if(o){let s=o[0]==="x"?16:8;n.push([parseInt(s===16?o.slice(1):o,s)&255]),r+=o.length+1}else if(Object.hasOwn(gd,i))n.push([gd[i]]),r+=2;else throw new w("feature","format escape",`format escape ${JSON.stringify(e.slice(r,r+2))} is not supported`)}else{let i=r+1;for(;i<e.length&&e[i]!=="%"&&!(t&&e[i]==="\\");)i++;n.push(q(e.slice(r,i))),r=i}return t||n.push([10]),n}function yd(e,t,n,r){let i=r.isDir(n);if(i&&r.isFile(n))throw new w("feature","ambiguous file type",`path is both a file and a directory: ${t}`);let o=!i&&r.isLink?.(n)===!0,s,u=e.map(f=>{if(!f.field)return f;if(f.field==="n")return wd(t,f);if(f.field==="s"&&i)throw new w("feature","directory byte size",`directory byte sizes are not available: ${t}`);return s??=i?0:r.fileSize(n),f.field==="F"?wd(i?"directory":o?"symbolic link":s===0?"regular empty file":"regular file",f):q(ai(BigInt(s),f))}),a=new Uint8Array(u.reduce((f,c)=>f+c.length,0)),l=0;for(let f of u)a.set(f,l),l+=f.length;return P(a)}function wd(e,t){let n=q(e);t.precision!==null&&(n=n.subarray(0,t.precision));let r=Math.max(0,t.width-n.length);if(!r)return n;let i=new Uint8Array(n.length+r).fill(32);return i.set(n,t.minus?0:r),i}function xd(e,t,n){let{order:r,positional:i}=N(t,{short:["L","t"],long:["dereference","terse"],valueShort:["c"],valueLong:["format","printf","cached"]});if(!i.length)return y("stat: missing operand");let o=r.some(({name:f})=>f==="L"||f==="dereference"),s;for(let f of r)if(f.name==="cached"){if(!f.value||!["always","never","default"].some(c=>c.startsWith(f.value)))return y(`stat: invalid cache mode: ${f.value}`)}else["c","format","printf"].includes(f.name)&&(s=f);if(!s)return k("feature","stat","default metadata","stat: default output requires filesystem metadata that is not available");let u=bd(s.value,s.name==="printf");if(u.some(f=>f.field==="s"||f.field==="F")&&Uy(i,n,o))return k("feature","stat","metadata output overlap","stat: buffered output sharing a measured file is not supported");let a=U(),l=!1;for(let f of i){let c=Dy(u,f,n,o);_(a,c),l||=c.exitCode!==0}return a.exitCode=l?1:0,a}function Dy(e,t,n,r){if(t==="-"){let o=k("feature","stat","standard input metadata","stat: standard input metadata is not supported");return n.unsupported.add({kind:"feature",command:"stat",detail:"standard input metadata",message:o.stderr.trimEnd()}),o}let i=R(n,"stat",t,{follow:r});if(i.error)return y(`stat: cannot statx ${H(t,n)}: ${i.error}`);try{return C(yd(e,t,i.path,n.fs))}catch(o){let s=Y(o,"stat","stat: "+Z(o)),u=O(s);return u&&n.unsupported.add(u),s}}function Uy(e,t,n){let r=Object.values(t.outputFds).filter(i=>typeof i=="object");return r.length?e.some(i=>{let o=v(t.cwd,i,t.fs,{follow:n});return!o.error&&r.some(s=>s.path===o.path||s.identity!==void 0&&s.identity===t.fs.fileIdentity?.(o.path))}):!1}var By=/[ \t\n\v\f\r]/gu,qy=/[ \t\n\v\f\r]+/gu,kd=/[ \t\n\v\f\r]+$/u,vd=e=>e.replace(/[A-Z]/gu,t=>t.toLowerCase());function li({ignoreCase:e=!1,whitespace:t="none"}={}){let n=null;return t==="all"?n=r=>r.replace(By,""):t==="change"?n=r=>r.replace(kd,"").replace(qy," "):t==="trailing"&&(n=r=>r.replace(kd,"")),e?n?r=>vd(n(r)):vd:n}function Et(e){let t=[];for(let n=0;n<e.length;){let r=e.indexOf(`
|
|
101
|
+
`,n),i=r<0?e.length:r+1;t.push(e.slice(n,i)),n=i}return t}var sn=/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(?: ?(.*?))?\n?$/u,Bt=/^\*{15,}(?: (.*?))?\n?$/u,fi=/^\*{3} (\d+)(?:,(\d+))? \*{4}\n?$/u,Vn=/^--- (\d+)(?:,(\d+))? ----\n?$/u,un=/^(\d+)(?:,(\d+))?([acd])(\d+)(?:,(\d+))?[ \t]*\r?\n?$/u;var _e=class extends Error{constructor(t,n){super(n===void 0?t:`${t} at line ${n+1}`),this.name="PatchError",this.line=n}},Sd=(e,t)=>t===0?Number(e):Number(e)-1,Ls=e=>e!==void 0&&e.startsWith("\\"),Rs=e=>e.replace(/\n$/u,"");function Ms(e){let t=Et(e),n=[],r={old:null,new:null},i=!1;for(let o=0;o<t.length;){let s=t[o],u=$d(s,i);if(i=s.startsWith("***************")?!1:s.startsWith("*** "),u){r=u.names??{...r,[u.slot]:u.name},o++;continue}let a=sn.test(s)?"unified":Bt.test(s)?"context":un.test(s)?"normal":null;if(a===null){o++;continue}let l=[],f=Xy[a];for(let c=f(t,o);c!==null&&(l.push(c.hunk),o=c.next,!(o>=t.length||$d(t[o],!1)));c=f(t,o));n.push({old:r.old,new:r.new,format:a,hunks:l,blocks:Wy(l)}),r={old:null,new:null}}return n}function $d(e,t){let n=/^diff --git (\S+) (\S+)\n?$/u.exec(e);if(n)return{names:{old:n[1],new:n[2]}};if(fi.test(e)||Vn.test(e))return null;let r=/^(\*\*\* |--- |\+\+\+ )(.*?)(?:\t.*)?\n?$/u.exec(e);return r?r[1]==="--- "?{slot:t?"new":"old",name:r[2]}:{slot:r[1]==="*** "?"old":"new",name:r[2]}:null}function Wy(e){let t=[];for(let n of e){let r=n.oldStart,i=n.newStart,o=null,s=()=>{o&&(t.push(o),r=o.a1,i=o.b1,o=null)};for(let{tag:u,text:a}of n.lines){if(u===" "){s(),r++,i++;continue}u==="-"&&o?.insert.length&&s(),o??={a0:r,a1:r,b0:i,b1:i,remove:[],insert:[]},u==="-"?(o.a1++,o.remove.push(a)):(o.b1++,o.insert.push(a))}s()}return t}function jy(e,t){let n=sn.exec(e[t]??"");if(!n)return null;let r=n[2]===void 0?1:Number(n[2]),i=n[4]===void 0?1:Number(n[4]),o={oldStart:Sd(n[1],r),newStart:Sd(n[3],i),label:n[5]||null,lines:[]},s=0,u=t+1,a=0;for(;a<r||s<i;u++){let l=e[u];if(l===void 0)throw new _e("the patch ends inside a hunk",u);let f=l===`
|
|
102
|
+
`?" ":l[0];if(f!==" "&&f!=="-"&&f!=="+")throw new _e(`a hunk line begins with ${JSON.stringify(f)}`,u);let c=l===`
|
|
103
|
+
`?l:l.slice(1);if(Ls(e[u+1])&&(c=Rs(c),u++),f!=="+"&&a++,f!=="-"&&s++,a>r||s>i)throw new _e("a hunk has more lines than its header says",u);o.lines.push({tag:f,text:c})}return{hunk:o,next:u}}function zy(e,t){let n=un.exec(e[t]??"");if(!n)return null;let[,r,i,o,s,u]=n,a=o==="a"?0:Number(i??r)-Number(r)+1,l=o==="d"?0:Number(u??s)-Number(s)+1;if(a<0||l<0)throw new _e("a change command counts backwards",t);let f={oldStart:o==="a"?Number(r):Number(r)-1,newStart:o==="d"?Number(s):Number(s)-1,label:null,lines:[]},c=t+1,d=(p,h,m)=>{for(let g=0;g<p;g++,c++){let b=e[c];if(b===void 0)throw new _e("the patch ends inside a hunk",c);if(b[0]!==h)throw new _e(`${JSON.stringify(h)} expected`,c);let x=b.slice(2);Ls(e[c+1])&&(x=Rs(x),c++),f.lines.push({tag:m,text:x})}};if(d(a,"<","-"),o==="c"){if(e[c]!==`---
|
|
104
|
+
`)throw new _e("'---' expected",c);c++}return d(l,">","+"),{hunk:f,next:c}}function Hy(e,t){let n=Bt.exec(e[t]??"");if(!n)return null;let r=fi.exec(e[t+1]??"");if(!r)throw new _e("'*** ' range expected",t+1);let i=t+2,o=Nd(e,i,Vn,"-");i=o.next;let s=Vn.exec(e[i]??"");if(!s)throw new _e("'--- ' range expected",i);let u=Nd(e,i+1,null,"+"),a=o.lines.length===0?u.lines.filter(d=>d.tag===" "):o.lines,l=u.lines.length===0?o.lines.filter(d=>d.tag===" "):u.lines,f=Ed(r,a.length),c=Ed(s,l.length);return{hunk:{oldStart:f,newStart:c,label:n[1]||null,lines:Gy(a,l)},next:u.next}}var Ed=(e,t)=>t===0?Number(e[1]):Number(e[1])-1;function Nd(e,t,n,r){let i=[],o=t;for(;o<e.length;o++){let s=e[o];if(n&&n.test(s)||Bt.test(s)||fi.test(s)||!n&&Vn.test(s))break;if(Ls(s)){i[i.length-1].text=Rs(i.at(-1).text);continue}let u=s===`
|
|
97
105
|
`?" ":s[0];if(u!==" "&&u!=="!"&&u!=="-"&&u!=="+")break;i.push({tag:u===" "?" ":r,text:s===`
|
|
98
|
-
`?s:s.slice(2)})}return{lines:i,next:o}}function
|
|
106
|
+
`?s:s.slice(2)})}return{lines:i,next:o}}function Gy(e,t){let n=[],r=0,i=0;for(;r<e.length||i<t.length;){if(e[r]?.tag===" "&&t[i]?.tag===" "){n.push(e[r]),r++,i++;continue}for(;r<e.length&&e[r].tag!==" ";)n.push(e[r]),r++;for(;i<t.length&&t[i].tag!==" ";)n.push(t[i]),i++;e[r]?.tag===" "&&t[i]===void 0?(n.push(e[r]),r++):t[i]?.tag===" "&&e[r]===void 0&&(n.push(t[i]),i++)}return n}var Xy={unified:jy,context:Hy,normal:zy};var Ue=class extends Error{constructor(t){super(`the rendered diff does not say what the change set says (${t})`),this.name="FormatError"}};function Ps(e,t,n,r){if(n.length===0){if(r!=="")throw new Ue("there was nothing to print, and something was printed");return}let i;try{i=Ms(r)}catch(s){throw new Ue(`it does not read back (${s.message})`)}if(i.length!==1)throw new Ue(`${i.length} files read back, not one`);let o=i[0].blocks;if(o.length!==n.length)throw new Ue(`${o.length} blocks read back, not ${n.length}`);for(let[s,u]of o.entries()){let a=n[s];if(u.a0!==a.a0||u.a1!==a.a1||u.b0!==a.b0||u.b1!==a.b1)throw new Ue(`block ${s+1} reads back somewhere else`)}for(let s of i[0].hunks){let u=s.oldStart,a=s.newStart;for(let{tag:l,text:f}of s.lines){let c=l==="+"?t[a]:e[u];if(f!==c)throw new Ue(`a ${l==="+"?"added":l==="-"?"removed":"kept"} line is not the line it stands for`);l!=="+"&&u++,l!=="-"&&a++}}}function Fd(e,t,n,r){let i=[],o=0;for(;o<e.length;){let s=o;for(;s+1<e.length&&e[s+1].a0-e[s].a1<=2*t;)s++;let u=e[o],a=e[s];i.push({blocks:e.slice(o,s+1),a0:Math.max(0,u.a0-t),a1:Math.min(n,a.a1+t),b0:Math.max(0,u.b0-t),b1:Math.min(r,a.b1+t)}),o=s+1}return i}var Zy=`
|
|
99
107
|
\
|
|
100
|
-
`,
|
|
101
|
-
`)?"":
|
|
102
|
-
`;for(let l=i;l<o;l++)r+=
|
|
103
|
-
`);for(let l=s;l<u;l++)r+=
|
|
104
|
-
`;let a=s.a0,l=s.b0;for(let{a0:
|
|
105
|
-
`,o+=`*** ${
|
|
106
|
-
`,s.blocks.some(a=>a.a0<a.a1)&&(o+=
|
|
107
|
-
`,s.blocks.some(a=>a.b0<a.b1)&&(o+=
|
|
108
|
-
`;function
|
|
109
|
-
`:"";return s.style==="unified"?`${
|
|
108
|
+
`,lt=(e,t)=>e+t+(t.endsWith(`
|
|
109
|
+
`)?"":Zy);function Ad(e,t){return t>e+1?`${e+1},${t}`:`${t>e?e+1:e}`}function Td(e,t,n){let r="";for(let{a0:i,a1:o,b0:s,b1:u}of n){let a=i===o?"a":s===u?"d":"c";r+=Ad(i,o)+a+Ad(s,u)+`
|
|
110
|
+
`;for(let l=i;l<o;l++)r+=lt("< ",e[l]);a==="c"&&(r+=`---
|
|
111
|
+
`);for(let l=s;l<u;l++)r+=lt("> ",t[l])}return Ps(e,t,n,r),r}function Od(e,t){return t<=e?`${e},0`:t===e+1?`${e+1}`:`${e+1},${t-e}`}function _d(e,t,n,{context:r,label:i=null}){let o="";for(let s of Fd(n,r,e.length,t.length)){let u=i?i(s.a0):null;o+=`@@ -${Od(s.a0,s.a1)} +${Od(s.b0,s.b1)} @@${u===null?"":" "+u}
|
|
112
|
+
`;let a=s.a0,l=s.b0;for(let{a0:f,a1:c,b1:d}of s.blocks){for(;a<f;a++,l++)o+=lt(" ",e[a]);for(;a<c;a++)o+=lt("-",e[a]);for(;l<d;l++)o+=lt("+",t[l])}for(;a<s.a1;a++,l++)o+=lt(" ",e[a])}return Ps(e,t,n,o),o}function Id(e,t){return t<=e?`${e}`:t===e+1?`${e+1}`:`${e+1},${t}`}function Ld(e,t,n,{context:r,label:i=null}){let o="";for(let s of Fd(n,r,e.length,t.length)){let u=i?i(s.a0):null;o+=`***************${u===null?"":" "+u}
|
|
113
|
+
`,o+=`*** ${Id(s.a0,s.a1)} ****
|
|
114
|
+
`,s.blocks.some(a=>a.a0<a.a1)&&(o+=Cd(e,s.a0,s.a1,s.blocks,"a")),o+=`--- ${Id(s.b0,s.b1)} ----
|
|
115
|
+
`,s.blocks.some(a=>a.b0<a.b1)&&(o+=Cd(t,s.b0,s.b1,s.blocks,"b"))}return Ps(e,t,n,o),o}function Cd(e,t,n,r,i){let o=i+"1",s=i+"0",u=i==="a"?"b":"a",a="",l=t;for(let f of r){for(;l<f[s];l++)a+=lt(" ",e[l]);let c=f[u+"0"]<f[u+"1"]?"! ":i==="a"?"- ":"+ ";for(;l<f[o];l++)a+=lt(c,e[l])}for(;l<n;l++)a+=lt(" ",e[l]);return a}function Yy(e){let t=[];for(let n=0;;){let r=n;for(;n<e.length&&e[n];)n++;if(t.push(n>r),n===e.length)return t;n++}}function Ds(e,t,n){let r=t.length,i=Yy(n),o=0,s=0,u=0,a=()=>{if(o===r||e[u]!==e[o])return!1;for(t[u++]=0,t[o++]=1,s++;o<r&&t[o];)o++;return!0},l=()=>{if(u===0||e[u-1]!==e[o-1])return!1;for(t[--u]=1,t[--o]=0,s--;u>0&&t[u-1];)u--;return!0};for(let f=0;f<r;f++){if(!t[f]){s++;continue}for(u=f,o=f;o<r&&t[o];o++);let c=-1;for(let d=-1;d!==o-u;){for(d=o-u;l(););for(c=i[s]?o:-1;a();)i[s]&&(c=o)}if(c!==-1)for(let d=o-c;d>0;d--)l();f=o-1}}function Vy(e){let t=1;for(let n=e;n!==0;n>>=2)t<<=1;return Math.max(256,t)}function Rd(e,t,{ignoreCase:n=!1,whitespace:r="none",minimal:i=!1,slide:o=!0}={}){let s=li({ignoreCase:n,whitespace:r});if(s===null&&Us(e,t,null))return[];let{A:u,B:a}=Ky(e,t,s),l=new Uint8Array(u.length),f=new Uint8Array(a.length);Jy(u,a,l,f,i),o&&(Ds(u,l,f),Ds(a,f,l));let c=tx(l,f);return nx(e,t,c,s),c}function Us(e,t,n=null){if(e.length!==t.length)return!1;let r=n?(i,o)=>n(i)===n(o):(i,o)=>i===o;for(let i=0;i<e.length;i++)if(!r(e[i],t[i]))return!1;return!0}function Ky(e,t,n){let r=new Map,i=u=>{let a=n?n(u):u,l=r.get(a);return l===void 0&&(l=r.size,r.set(a,l)),l},o=new Int32Array(e.length),s=new Int32Array(t.length);for(let u=0;u<e.length;u++)o[u]=i(e[u]);for(let u=0;u<t.length;u++)s[u]=i(t[u]);return{A:o,B:s}}function Jy(e,t,n,r,i){let o=e.length+t.length+3,s={A:e,B:t,fd:new Int32Array(o),bd:new Int32Array(o),base:t.length+1,limit:Vy(e.length+t.length)},u=[{xoff:0,xlim:e.length,yoff:0,ylim:t.length,minimal:i}],a={xmid:0,ymid:0,loMinimal:!1,hiMinimal:!1};for(;u.length;){let{xoff:l,xlim:f,yoff:c,ylim:d,minimal:p}=u.pop();for(;l<f&&c<d&&e[l]===t[c];)l++,c++;for(;l<f&&c<d&&e[f-1]===t[d-1];)f--,d--;if(l===f){for(;c<d;c++)r[c]=1;continue}if(c===d){for(;l<f;l++)n[l]=1;continue}Qy(s,l,f,c,d,p,a),u.push({xoff:a.xmid,xlim:f,yoff:a.ymid,ylim:d,minimal:a.hiMinimal}),u.push({xoff:l,xlim:a.xmid,yoff:c,ylim:a.ymid,minimal:a.loMinimal})}}function Qy(e,t,n,r,i,o,s){let{A:u,B:a,fd:l,bd:f,base:c,limit:d}=e,p=n-r,h=t-i,m=n-i,g=t-r,b=m,x=m,S=g,E=g,M=(g-m&1)!==0;l[c+g]=t,f[c+m]=n;for(let D=1;;D++){E>h?l[c+--E-1]=-1:++E,S<p?l[c+ ++S+1]=-1:--S;for(let T=S;T>=E;T-=2){let ne=l[c+T+1],Le=l[c+T-1],z=Le<ne?ne:Le+1,ce=z-T;for(;z<n&&ce<i&&u[z]===a[ce];)z++,ce++;if(l[c+T]=z,M&&x<=T&&T<=b&&f[c+T]<=z){s.xmid=z,s.ymid=ce,s.loMinimal=s.hiMinimal=!0;return}}x>h?f[c+--x-1]=2147483647:++x,b<p?f[c+ ++b+1]=2147483647:--b;for(let T=b;T>=x;T-=2){let ne=f[c+T+1],Le=f[c+T-1],z=Le<ne?Le:ne-1,ce=z-T;for(;t<z&&r<ce&&u[z-1]===a[ce-1];)z--,ce--;if(f[c+T]=z,!M&&E<=T&&T<=S&&z<=l[c+T]){s.xmid=z,s.ymid=ce,s.loMinimal=s.hiMinimal=!0;return}}if(!(o||D<d)){ex(e,{xoff:t,xlim:n,yoff:r,ylim:i,fmin:E,fmax:S,bmin:x,bmax:b},s);return}}}function ex(e,t,n){let{fd:r,bd:i,base:o}=e,{xoff:s,xlim:u,yoff:a,ylim:l,fmin:f,fmax:c,bmin:d,bmax:p}=t,h=0,m=-1;for(let x=c;x>=f;x-=2){let S=Math.min(r[o+x],u),E=S-x;l<E&&(S=l+x,E=l),m<S+E&&(m=S+E,h=S)}let g=0,b=2147483647;for(let x=p;x>=d;x-=2){let S=Math.max(s,i[o+x]),E=S-x;E<a&&(S=a+x,E=a),S+E<b&&(b=S+E,g=S)}u+l-b<m-(s+a)?(n.xmid=h,n.ymid=m-h,n.loMinimal=!0,n.hiMinimal=!1):(n.xmid=g,n.ymid=b-g,n.loMinimal=!1,n.hiMinimal=!0)}function tx(e,t){let n=[],r=t.length,i=e.length,o=0,s=0;for(;o<i||s<r;){if(o<i&&s<r&&!e[o]&&!t[s]){o++,s++;continue}let u=o,a=s;for(;o<i&&e[o];)o++;for(;s<r&&t[s];)s++;if(u===o&&a===s)throw new xe("a kept line has no counterpart");n.push({a0:u,a1:o,b0:a,b1:s})}return n}function nx(e,t,n,r=null){let i=r?(u,a)=>r(u)===r(a):(u,a)=>u===a,o=0,s=0;for(let{a0:u,a1:a,b0:l,b1:f}of n){if(u<o||l<s||a<u||f<l||a>e.length||f>t.length)throw new xe("a block is out of order or out of range");if(u===a&&l===f)throw new xe("a block changes nothing");if(u-o!==l-s)throw new xe("the kept lines before a block differ in count");for(;o<u;o++,s++)if(!i(e[o],t[s]))throw new xe(`kept line ${o+1} does not match`);o=a,s=f}if(e.length-o!==t.length-s)throw new xe("the kept lines after the last block differ in count");for(;o<e.length;o++,s++)if(!i(e[o],t[s]))throw new xe(`kept line ${o+1} does not match`)}var xe=class extends Error{constructor(t){super(`the computed change set does not reconstruct the second file (${t})`),this.name="DiffError"}};var rx={unified:_d,context:Ld},Md=`Files differ
|
|
116
|
+
`;function ix(e,t,n){if(e===t)return"";let r=li(n);return r===null?Md:Us(Et(e),Et(t),r)?"":Md}function Kn(e,t,{format:n="unified",context:r=3,label:i=null,...o}={}){if(n==="brief")return ix(e,t,o);let s=Et(e),u=Et(t),{slide:a=n!=="normal"&&r>0,...l}=o,f=Rd(s,u,{...l,slide:a});return f.length===0?"":n==="normal"?Td(s,u,f):rx[n](s,u,f,{context:r,label:i})}var ox=[" 1970-01-01 00:00:00.000000000 +0000"," Thu Jan 1 00:00:00 1970"];function Pd(e,t,n,r,i){let{ctx:o,opts:s}=e,u=sx(s,t);if(u==="")return"";let a=c=>s.labels[c]??ss(n[c],o)+(r[c]?ox[s.style==="context"?1:0]:""),l=c=>s.labels[c]??ss(n[c],o),f=i?`diff${s.switches} ${l(0)} ${l(1)}
|
|
117
|
+
`:"";return s.style==="unified"?`${f}--- ${a(0)}
|
|
110
118
|
+++ ${a(1)}
|
|
111
|
-
${u}`:s.style==="context"?`${
|
|
119
|
+
${u}`:s.style==="context"?`${f}*** ${a(0)}
|
|
112
120
|
--- ${a(1)}
|
|
113
|
-
${u}`:
|
|
114
|
-
diff: Try 'diff --help' for more information.`,2);function
|
|
115
|
-
`,1)}}function
|
|
116
|
-
`)}function
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
`,
|
|
120
|
-
`,2,!0)
|
|
121
|
-
`,
|
|
122
|
-
`,
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
121
|
+
${u}`:f+u}function sx(e,t){let n=e.showFunction?He(t[0]):null;return Kn(t[0],t[1],{format:e.style??"normal",context:e.context,label:n?r=>ax(n,r):null,minimal:e.minimal,ignoreCase:e.ignoreCase,whitespace:e.whitespace})}var ux=/^[A-Za-z$_]/u;function ax(e,t){for(let n=t-1;n>=0;n--){if(!ux.test(e[n]))continue;let r=A(e[n].replace(/\n$/u,"")),i=Math.min(40,r.length);for(;i>0&&lx(r[i-1]);)i--;return fx(r.subarray(0,i))}return null}var lx=e=>e===32||e>=9&&e<=13;function fx(e){for(let t=e.length;t>Math.max(0,e.length-4);t--)try{return P(e.subarray(0,t))}catch{}return""}var cx=["q","s","r","N","a","i","w","b","Z","p","d","u","c","e","n","y","t","T","l","E","B","P","v","H"],dx=["brief","report-identical-files","recursive","new-file","text","ignore-case","ignore-all-space","ignore-space-change","ignore-trailing-space","strip-trailing-cr","show-c-function","minimal","normal","unified","context","ed","rcs","side-by-side","expand-tabs","initial-tab","paginate","ignore-tab-expansion","ignore-blank-lines","unidirectional-new-file","version","help","suppress-common-lines","speed-large-files","ignore-file-name-case","no-ignore-file-name-case","no-dereference","left-column"],Dd=["U","C","x","X","S","F","W","I","D"],Ud=["show-function-line","exclude-from","starting-file","from-file","to-file","ifdef","width","tabsize","horizon-lines","ignore-matching-lines","line-format","old-line-format","new-line-format","unchanged-line-format","old-group-format","new-group-format","unchanged-group-format","changed-group-format","color","palette"],px=["L","label","x","exclude"],hx=new Map([["e","ed script output"],["ed","ed script output"],["n","RCS output"],["rcs","RCS output"],["y","side-by-side output"],["side-by-side","side-by-side output"],["W","side-by-side output"],["width","side-by-side output"],["suppress-common-lines","side-by-side output"],["left-column","side-by-side output"],["t","tab expansion"],["expand-tabs","tab expansion"],["T","initial tabs"],["initial-tab","initial tabs"],["tabsize","tab expansion"],["E","tab expansion"],["ignore-tab-expansion","tab expansion"],["B","ignoring blank lines"],["ignore-blank-lines","ignoring blank lines"],["I","ignoring matching lines"],["ignore-matching-lines","ignoring matching lines"],["D","merged #ifdef output"],["ifdef","merged #ifdef output"],["l","pagination"],["paginate","pagination"],["F","a custom function regex"],["show-function-line","a custom function regex"],["X","reading exclusions from a file"],["exclude-from","reading exclusions from a file"],["S","a starting file"],["starting-file","a starting file"],["from-file","comparing one file to many"],["to-file","comparing one file to many"],["P","one-sided new files"],["unidirectional-new-file","one-sided new files"],["v","a version banner"],["version","a version banner"],["help","a help text"],["H","large-file heuristics"],["speed-large-files","large-file heuristics"],["horizon-lines","the horizon setting"],["ignore-file-name-case","case-insensitive names"],["no-ignore-file-name-case","case-insensitive names"],["no-dereference","symbolic links"],["color","colored output"],["palette","colored output"],["line-format","custom line formats"],["old-line-format","custom line formats"],["new-line-format","custom line formats"],["unchanged-line-format","custom line formats"],["old-group-format","custom group formats"],["new-group-format","custom group formats"],["unchanged-group-format","custom group formats"],["changed-group-format","custom group formats"]]),Jn=e=>y(`diff: ${e}
|
|
122
|
+
diff: Try 'diff --help' for more information.`,2);function mx(e){let t=[];for(let n=0;n<e.length;n++){let r=e[n];if(r==="--"){t.push(...e.slice(n));break}if(r==="--unified"||r==="--context")t.push("-"+(r==="--unified"?"u":"c"));else if(r.startsWith("--unified=")||r.startsWith("--context="))t.push(r.startsWith("--u")?"-U":"-C",r.slice(10));else{if(r.startsWith("--color"))return{refused:"colored output",label:r};t.push(r)}}return{tokens:t}}function Bd(e){let t=mx(e);if(t.refused)return{refused:k("option","diff",t.label.replace(/=.*/u,""),`diff: ${t.label}: ${t.refused} is not supported`,2)};let n;try{n=N(t.tokens,{short:cx,long:dx,valueShort:Dd,valueLong:Ud,repeatable:px})}catch(i){let o=O(i);return o?{refused:k(o.kind,"diff",o.detail,`diff: ${i.message}`,2)}:{error:Jn(i.message)}}let r={style:null,context:-1,labels:[],excludes:[],whitespace:"none",switches:bx(e)};for(let{name:i,value:o}of n.order){let s=hx.get(i),u=(i.length===1?"-":"--")+i;if(s)return{refused:k("option","diff",u,`diff: ${u}: ${s} is not supported`,2)};let a=gx(r,i,o);if(a)return{error:a}}return r.showFunction&&r.style===null&&(r.style="context"),r.context<0&&(r.context=3),n.positional.length<2?{error:Jn(`missing operand after '${n.positional[0]??"diff"}'`)}:n.positional.length>2?{error:Jn(`extra operand '${n.positional[2]}'`)}:{opts:r,operands:n.positional}}function gx(e,t,n){let r=i=>e.style!==null&&e.style!==i?Jn("conflicting output style options"):(e.style=i,null);switch(t){case"u":case"c":{let i=r(t==="u"?"unified":"context");return e.context<3&&(e.context=3),i}case"U":case"C":{let i=wx(n);if(i===null)return Jn(`invalid context length '${n}'`);let o=r(t==="U"?"unified":"context");return e.context<i&&(e.context=i),o}case"normal":return r("normal");case"q":case"brief":return e.brief=!0,null;case"s":case"report-identical-files":return e.identical=!0,null;case"r":case"recursive":return e.recursive=!0,null;case"N":case"new-file":return e.newFile=!0,null;case"a":case"text":return e.text=!0,null;case"i":case"ignore-case":return e.ignoreCase=!0,null;case"w":case"ignore-all-space":return e.whitespace="all",null;case"b":case"ignore-space-change":return e.whitespace!=="all"&&(e.whitespace="change"),null;case"Z":case"ignore-trailing-space":return e.whitespace==="none"&&(e.whitespace="trailing"),null;case"strip-trailing-cr":return e.stripCr=!0,null;case"p":case"show-c-function":return e.showFunction=!0,null;case"d":case"minimal":return e.minimal=!0,null;case"L":case"label":return e.labels.length===2?y("diff: too many file label options",2):(e.labels.push(n),null);case"x":case"exclude":return e.excludes.push(n),null;default:return null}}function wx(e){if(e==="")return 0;let t=we(e,"diff");return t.error?null:t.value}function bx(e){let t=[];for(let n=0;n<e.length;n++){let r=e[n];if(r==="--")break;!r.startsWith("-")||r==="-"||(t.push(r),yx(r)&&n+1<e.length&&t.push(e[++n]))}return t.map(n=>" "+te(n,{vars:new Map})).join("")}function yx(e){if(e.startsWith("--"))return!e.includes("=")&&(Ud.includes(e.slice(2))||e==="--label"||e==="--exclude");for(let t=1;t<e.length;t++){let n=e[t];if(Dd.includes(n)||n==="L")return t+1===e.length}return!1}function pi(e,t,n){let{ctx:r,opts:i}=e,o=vx(jd(e,t),jd(e,n));for(let[s,u,a]of o){let l=di(t,s),f=di(n,s),c=u?Wd(r,l):null,d=a?Wd(r,f):null;if(u&&a){kx(e,[l,f],[c,d]);continue}i.newFile?xx(e,[l,f],c??d,[u,a]):ke(e,`Only in ${u?t:n}: ${s}
|
|
123
|
+
`,1)}}function xx(e,[t,n],r,i){ci(r)?e.opts.recursive?zd(e,[t,n],i.map(o=>o?r:null)):ke(e,`Common subdirectories: ${t} and ${n}
|
|
124
|
+
`):Qn(e,t,n,!0,i)}function kx(e,[t,n],[r,i]){let{opts:o}=e,s=[r,i].indexOf("gone");if(s!==-1&&ci([r,i][1-s])){let u=[t,n][s];return ke(e,`diff: ${u}: ${v(e.ctx.cwd,u,e.ctx.fs).error}
|
|
125
|
+
`,2,!0)}if(ci(r)&&ci(i))o.recursive?zd(e,[t,n],[r,i]):ke(e,`Common subdirectories: ${t} and ${n}
|
|
126
|
+
`);else if(r===i||s!==-1)Qn(e,t,n,!0,[!0,!0]);else{let u=(a,l)=>o.labels[a]??l;ke(e,`File ${u(0,t)} is a ${qd[r]} while file ${u(1,n)} is a ${qd[i]}
|
|
127
|
+
`,1)}}var qd={dir:"directory",link:"directory",file:"regular file"},ci=e=>e==="dir"||e==="link";function Wd(e,t){let n=v(e.cwd,t,e.fs);return n.error?"gone":e.fs.isDir(n.path)?e.fs.isLink?.(v(e.cwd,t,e.fs,{follow:!1}).path)?"link":"dir":"file"}function zd(e,[t,n],[r,i]){for(let[o,s]of[[r,t],[i,n]])if(o==="link")throw new w("feature","symbolic link to a directory",`comparing what a symbolic link to a directory holds is not supported: ${s}`);pi(e,t,n)}function jd(e,t){let{ctx:n,opts:r}=e,i=v(n.cwd,t,n.fs);if(i.error||!n.fs.isDir(i.path))return[];let{dirs:o,files:s,links:u}=n.fs.listDir(i.path),a=[...o,...s,...u].sort(B);return r.excludes.length?a.filter(l=>!r.excludes.some(f=>Af(l,f))):a}function vx(e,t){let n=[],r=0,i=0;for(;r<e.length||i<t.length;){let o=r===e.length?1:i===t.length?-1:B(e[r],t[i]);o===0?(n.push([e[r++],!0,!0]),i++):o<0?n.push([e[r++],!0,!1]):n.push([t[i++],!1,!0])}return n}function Zd(e,t,n){let r=Bd(t);if(r.error)return r.error;if(r.refused)return r.refused;let{opts:i,operands:o}=r,s={ctx:n,opts:i,stdin:e,out:U(),status:0},[u,a]=o,l=o.map(f=>Hd(s,f));if(l[0]==="dir"&&l[1]==="dir"&&Sx(s,u,a))return s.out;if(l[0]==="dir"&&l[1]==="dir")pi(s,u,a);else if(l[0]==="dir"||l[1]==="dir"){let f=l[0]==="dir"?0:1,c=o[1-f];if(c==="-")return y("diff: cannot compare '-' to a directory",2);if(l[1-f]==="missing"){let d=v(s.ctx.cwd,c,s.ctx.fs).error;i.newFile&&d==="No such file or directory"?pi(s,u,a):ke(s,`diff: ${c}: ${d}
|
|
128
|
+
`,2,!0)}else{let d=di(o[f],et(c)),p=f===0?[d,c]:[c,d];Hd(s,d)==="missing"?ke(s,`diff: ${d}: No such file or directory
|
|
129
|
+
`,2,!0):Qn(s,p[0],p[1],!1)}}else Qn(s,u,a,!1);return s.out.exitCode=s.status,s.out}function di(e,t){let n=e.replace(/\/+$/u,"");return(n===""?"/":n+"/")+t}function Sx(e,t,n){return v(e.ctx.cwd,t,e.ctx.fs).path===v(e.ctx.cwd,n,e.ctx.fs).path}function Hd(e,t){if(t==="-")return"stdin";let n=v(e.ctx.cwd,t,e.ctx.fs);return n.error?"missing":e.ctx.fs.isDir(n.path)?"dir":"file"}function ke(e,t,n=0,r=!1){_(e.out,r?U(t):{...U(),stdout:t,events:[{fd:1,text:t}]}),e.status=Math.max(e.status,n)}function Qn(e,t,n,r,i=null){let{opts:o}=e,s=[t,n].map(p=>Nx(e,p)),u=s.map(p=>p.content===null),a=o.newFile&&!(u[0]&&u[1]),l=!1;for(let p=0;p<2;p++)!u[p]||(i?!i[p]:a)||(ke(e,`diff: ${[t,n][p]}: ${s[p].error??"No such file or directory"}
|
|
130
|
+
`,2,!0),l=!0);if(l)return;if(s[0].identity!==void 0&&s[0].identity===s[1].identity&&!u[0])return er(e,t,n);let f=p=>o.labels[p]??[t,n][p];if(!o.text&&s.some(Ex))return Gd(s)?er(e,t,n):ke(e,`${o.brief?"Files":"Binary files"} ${f(0)} and ${f(1)} differ
|
|
131
|
+
`,1);if(s.some(p=>p.content===void 0)){if(Gd(s))return er(e,t,n);if(o.brief&&!o.ignoreCase&&!o.stripCr&&o.whitespace==="none")return ke(e,`Files ${f(0)} and ${f(1)} differ
|
|
132
|
+
`,1)}for(let[p,h]of s.entries())h.content===void 0&&Gt(h.bytes,JSON.stringify(f(p)));let c=s.map(p=>p.content??"");if(o.stripCr&&(c=c.map($x)),o.brief)return Kn(c[0],c[1],{format:"brief",ignoreCase:o.ignoreCase,whitespace:o.whitespace})===""?er(e,t,n):ke(e,`Files ${f(0)} and ${f(1)} differ
|
|
133
|
+
`,1);let d;try{d=Pd(e,c,[t,n],u,r)}catch(p){if(!(p instanceof xe)&&!(p instanceof Ue))throw p;let h=`diff: ${t} ${n}: ${p.message}`,m=p instanceof xe?"change set verification":"diff rendering verification";_(e.out,k("feature","diff",m,h,2)),e.status=2;return}if(d==="")return er(e,t,n);ke(e,d,1)}function er(e,t,n){e.opts.identical&&ke(e,`Files ${t} and ${n} are identical
|
|
134
|
+
`)}var $x=e=>e.replace(/\r\n/gu,`
|
|
135
|
+
`),Ex=e=>e.content===void 0?e.bytes.includes(0):e.content?.includes("\0")===!0,Gd=([e,t])=>e.content!==void 0&&t.content!==void 0?e.content===t.content:vn(e.bytes??Xd,t.bytes??Xd),Xd=new Uint8Array;function Nx(e,t){let{ctx:n}=e;if(t==="-")return X(n),{content:e.stdin,identity:n.stdinHandle?.identity??Symbol("stdin")};let r=R(n,"diff",t);if(r.error||n.fs.isDir(r.path))return{content:null,bytes:null,identity:void 0,error:r.error};let{text:i,bytes:o}=mt(n.fs,r.path);return{content:i,bytes:o,identity:n.fs.fileIdentity?.(r.path)??r.path}}var an=(e,t,n)=>{throw new K(`malformed patch at line ${Math.min(t,e.lines.length-1)+1}: ${n??""}`)};function tr(e,t){return!!e.lines[t+1]?.startsWith("\\")}function Kd(e){let{lines:t}=e,n=e.pos,r=/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(?: (.*))?\n$/u.exec(t[n]??"");if(!r)return null;let i=n,o=Number(r[3]),s=Number(r[1]),u=r[2]===void 0?1:Number(r[2]),a=r[4]===void 0?1:Number(r[4]);u===0&&s++,a===0&&o++;let l=[],f=[],c=0,d=n,p=-1;for(n++;f.length<u||l.length<a;n+=1){let h=t[n]!==void 0;if(!h&&a-l.length>3)throw new K("unexpected end of file in patch");let m=h?t[n]:`
|
|
136
|
+
`;h&&(d=n);let g=m[0],b=m;g===" "||g===`
|
|
137
|
+
`?g=" ":b=m.slice(1),g!=="-"&&g!=="+"&&g!==" "&&an(e,n,m);let x=!1;g!=="+"&&(f.length>=u&&an(e,n,m),x=h&&f.length+1===u&&tr(e,n),x&&(b=b.replace(/\n$/u,"")),f.push({tag:g,text:b}),g===" "&&c++),g!=="-"&&(l.length>=a&&an(e,n,m),!x&&h&&l.length+1===a&&tr(e,n)&&(x=!0,b=b.replace(/\n$/u,"")),l.push({tag:g,text:b})),g!==" "&&(p===-1&&(p=c),c=0),x&&n++}return p===-1&&an(e,d,t[d]),e.pos=n,{oldStart:s,oldLines:f,newStart:o,newLines:l,prefix:p,suffix:c,fn:r[5]===void 0?null:" "+r[5],marks:null,line:i}}function Bs(e){let{lines:t}=e,n=e.pos;if(!t[n]?.startsWith("********"))return null;let r=n,i=/^\*+( .*)?\n$/u.exec(t[n])?.[1]??null,o=/^\*\*\* (\d+)(?:,(\d+))?/u.exec(t[++n]??"");if(!o)throw new K(`unexpected '***' at line ${n+1}: ${t[n]??""}`);let s=Yd(o),u=[],a=c=>/^--- (\d+)(?:,(\d+))? ----/u.exec(t[c]??"")??/^--- (\d+)(?:,(\d+))?/u.exec(t[c]??"");for(n++;!a(n);n++){if(t[n]===void 0||u.length>=s.count)throw new K(`no '---' found in patch at line ${r+1}`);u.push(Vd(e,n,u.length+1===s.count)),u.at(-1).skip&&n++}let l=Yd(a(n)),f=[];for(n++;f.length<l.count;n++){let c=t[n];if(c===void 0||!/^[ !+\-\t\n]/u.test(c)||c.startsWith("***"))break;f.push(Vd(e,n,f.length+1===l.count)),f.at(-1).skip&&n++}return f.length!==0&&f.length<l.count&&an(e,n,t[n]),e.pos=n,Ax({oldRange:s,oldSide:u,newRange:l,newSide:f,fn:i,line:r})}function Yd(e){let t=Number(e[1]),n=e[2]===void 0?t:Number(e[2]);return t===0&&e[2]===void 0?{first:1,count:0}:{first:t,count:n-t+1}}function Vd(e,t,n){let r=e.lines[t],i=r[0];i===" "||i===`
|
|
138
|
+
`?i=" ":(r=r.slice(1),(r[0]===" "||r[0]===" ")&&(r=r.slice(1)));let o=n&&tr(e,t);return{mark:i,text:o?r.replace(/\n$/u,""):r,skip:o}}function Ax({oldRange:e,oldSide:t,newRange:n,newSide:r,fn:i,line:o}){let s=r,u=t;if(t.length===0&&e.count&&(u=r.filter(p=>p.mark===" ")),r.length===0&&n.count&&(s=t.filter(p=>p.mark===" ")),u.length!==e.count||s.length!==n.count)throw new K(`replacement text or line numbers mangled in hunk at line ${o+1}`);let a=u.map(p=>({tag:p.mark===" "?" ":"-",text:p.text})),l=s.map(p=>({tag:p.mark===" "?" ":"+",text:p.text})),f=p=>{let h=0;for(let m of p){if(m.tag!==" ")break;h++}return h},c=Math.min(f(a),f(l)),d=Math.min(f(a.toReversed()),f(l.toReversed()));if(a.every(p=>p.tag===" ")&&l.every(p=>p.tag===" "))throw new K(`replacement text or line numbers mangled in hunk at line ${o+1}`);return{oldStart:e.first,oldLines:a,newStart:n.first,newLines:l,prefix:c,suffix:d,fn:i,marks:{old:u.map(p=>p.mark),new:s.map(p=>p.mark)},line:o}}function Jd(e){let{lines:t}=e,n=e.pos,r=/^(\d+)(?:,(\d+))?([acd])(\d+)(?:,(\d+))?[ \t]*\r?\n$/u.exec(t[n]??"");if(!r)return null;let i=n,o=Number(r[1]),s=r[3]==="a"?0:r[2]===void 0?1:Number(r[2])-o+1;r[3]==="a"&&o++;let u=Number(r[4]),a=r[5]===void 0?u:Number(r[5]);r[3]==="d"&&u++;let l=a-u+1;(s<0||l<0)&&an(e,n,t[n]);let f=[],c=[];n++;for(let d=0;d<s;d++,n++){if(t[n]===void 0)throw new K(`unexpected end of file in patch at line ${n}`);if(!/^<[ \t]/u.test(t[n]))throw new K(`'<' followed by space or tab expected at line ${n+1} of patch`);let p=d+1===s&&tr(e,n);c.push({tag:"-",text:p?t[n].slice(2).replace(/\n$/u,""):t[n].slice(2)}),p&&n++}if(r[3]==="c"){if(t[n]===void 0)throw new K(`unexpected end of file in patch at line ${n}`);if(!t[n].startsWith("-"))throw new K(`'---' expected at line ${n+1} of patch`);n++}for(let d=0;d<l;d++,n++){if(t[n]===void 0)throw new K(`unexpected end of file in patch at line ${n}`);if(!/^>[ \t]/u.test(t[n]))throw new K(`'>' followed by space or tab expected at line ${n+1} of patch`);let p=d+1===l&&tr(e,n);f.push({tag:"+",text:p?t[n].slice(2).replace(/\n$/u,""):t[n].slice(2)}),p&&n++}return e.pos=n,{oldStart:o,oldLines:c,newStart:u,newLines:f,prefix:0,suffix:0,fn:null,marks:null,line:i}}function hi(e){let t=(r,i,o)=>r.map(s=>({tag:s.tag===i?o:s.tag,text:s.text})),n=(r,i,o)=>r.map(s=>s===i?o:s);return{...e,oldStart:e.newStart,newStart:e.oldStart,oldLines:t(e.newLines,"+","-"),newLines:t(e.oldLines,"-","+"),marks:e.marks&&{old:n(e.marks.new,"+","-"),new:n(e.marks.old,"-","+")}}}var K=class extends Error{constructor(t){super(t),this.name="PatchFatal"}},ln=(e,t)=>{throw new w("feature",e,t)};function rp(e){let t=He(e);return t.length&&!t.at(-1).endsWith(`
|
|
128
139
|
`)&&(t[t.length-1]+=`
|
|
129
|
-
`),{lines:t,pos:0,base:0,empty:e===""}}var
|
|
130
|
-
`)&&(d.startsWith("@@ -")||
|
|
131
|
-
`&&
|
|
132
|
-
`,l+1)!==-1))break}i=r.slice(0,a),o=r.slice(a)}if(i==="/dev/null")return{stamp:0};let s=
|
|
133
|
-
`,r:"\r",t:" ",v:"\v","\\":"\\",'"':'"'};function
|
|
140
|
+
`),{lines:t,pos:0,base:0,empty:e===""}}var Ox=/^\d+(?:,\d+)?[acd]\d+(?:,\d+)?[ \t]*\r?\n$/u,Qd=/^(?:\d+(?:,\d+)?)?(?:[acdi]|s\/\.\/\/)[ \t]*\n$/u,ep=/^[0-9a-fA-F]+/u;function ip(e,{needHeader:t,strip:n,format:r}){let{lines:i}=e,o={names:{old:null,new:null,index:null},stamps:{old:-1,new:-1},timestrs:{old:null,new:null},says:[0,0],git:!1,rename:[!1,!1],copy:[!1,!1],extended:!1},s=t&&r!=="normal"&&r!=="ed",u=!1,a=-1,l=!1,f=!1;for(let c=e.pos;;c++){if(c>=i.length)return u&&ln("ed script","ed scripts are not supported"),o.extended?{...o,type:"unified",start:c,hunkLine:c,empty:!0}:null;let d=i[c],p=d.replace(/^[ \tX]+/u,""),h=/^\d/u.test(p)&&Ox.test(p);!s&&a<0&&(Qd.test(p)||h)&&(a=c,u=Qd.test(p));let m=Ix(d,o,n,f);if(m==="binary"&&ln("git binary patch","git binary diffs are not supported"),m==="prereq"&&ln("Prereq","Prereq: lines are not supported"),m==="git"&&o.extended)return{...o,type:"unified",start:c,hunkLine:c,empty:!0};m&&(s=!1);let g=d.startsWith("********");if(/^[ \t]+(?:@@ -\d|\*{8})/u.test(d)&&ln("indented patch","indented patches are not supported"),!s){if(d.endsWith(`\r
|
|
141
|
+
`)&&(d.startsWith("@@ -")||f)&&ln("CRLF patch","patches with CRLF line endings are not supported"),(r===null||r==="ed")&&a>=0&&d===`.
|
|
142
|
+
`&&ln("ed script","ed scripts are not supported"),(r===null||r==="unified")&&d.startsWith("@@ -"))return Fx(o,c,d);if((r===null||r==="context")&&f&&d.startsWith("*** "))return Tx(e,o,c,d);if((r===null||r==="normal")&&l&&(d.startsWith("< ")||d.startsWith("> ")))return{...o,type:"normal",start:c-1,hunkLine:c-1}}f=g,l=h}}function Ix(e,t,n,r){if(!r&&e.startsWith("*** ")||e.startsWith("+++ "))return qs(t,"old",e.slice(4),n);if(e.startsWith("Index:"))return t.names.index=sp(e.slice(6),n,!1).name,"index";if(e.startsWith("Prereq:"))return"prereq";if(e.startsWith("diff --git ")){let o=tp(e.slice(11),n),s=o.name===null?null:tp(o.rest,n);return t.names.old=s&&s.rest.trim()===""?o.name:null,t.names.new=t.names.old===null?null:s.name,t.git=!0,t.stamps.old=t.stamps.new=-1,"git"}if(t.git){let o=Cx(e,t);if(o)return o}let i=e;for(;i.startsWith("- ");)i=i.slice(2);return i.startsWith("--- ")?qs(t,"new",i.slice(4),n):null}function Cx(e,t){if(e.startsWith("index ")){let n=ep.exec(e.slice(6)),r=n?e.slice(6+n[0].length):"",i=r.startsWith("..")?ep.exec(r.slice(2)):null;return i?(t.says[0]=/^0+$/u.test(n[0])?2:0,t.says[1]=/^0+$/u.test(i[0])?2:0,t.extended=!0,"index"):null}return e.startsWith("old mode ")||e.startsWith("new mode ")?(t.extended=!0,"mode"):e.startsWith("deleted file mode ")?(t.says[1]=2,t.extended=!0,"mode"):e.startsWith("new file mode ")?(t.says[0]=2,t.extended=!0,"mode"):e.startsWith("rename from ")?(t.rename[0]=!0,t.extended=!0,"rename"):e.startsWith("rename to ")?(t.rename[1]=!0,t.extended=!0,"rename"):e.startsWith("copy from ")?(t.copy[0]=!0,t.extended=!0,"copy"):e.startsWith("copy to ")?(t.copy[1]=!0,t.extended=!0,"copy"):e.startsWith("GIT binary patch")?"binary":null}function qs(e,t,n,r){let i=sp(n,r,!0);return i.stamp!==void 0&&(e.stamps[t]=i.stamp),i.name!==void 0&&(e.names[t]=i.name,e.timestrs[t]=i.timestr),"name"}function Fx(e,t,n){let r={names:{...e.names,old:e.names.new,new:e.names.old},stamps:{old:e.stamps.new,new:e.stamps.old},timestrs:{old:e.timestrs.new,new:e.timestrs.old}},i=/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))?/u.exec(n),o=[...e.says];return i&&i[1]==="0"&&(o[0]=1+(r.stamps.old===0?1:0)),i&&i[3]==="0"&&(o[1]=1+(r.stamps.new===0?1:0)),{...e,...r,says:o,type:"unified",start:t,hunkLine:t}}function Tx(e,t,n,r){let i=[...t.says];/^\*\*\* 0(?!\d)/u.test(r)&&(i[0]=1+(t.stamps.old===0?1:0));let o={...e,pos:n-1};try{let s=Bs(o);s&&s.newLines.length===0&&s.newStart===1&&(i[1]=1+(t.stamps.new===0?1:0))}catch{}return{...t,says:i,type:"context",start:n-1,hunkLine:n-1}}function op(e,t){return t==="unified"?Kd(e):t==="context"?Bs(e):Jd(e)}function sp(e,t,n){let r=e.replace(/^[ \t\n\v\f\r]+/u,""),i,o;if(r.startsWith('"')){let a=ap(r);if(!a)return{};i=a.value,o=a.rest}else{let a=0;for(;a<r.length;a++){if(!/[ \t\n\v\f\r]/u.test(r[a]))continue;let l=a;for(;r[l]!==" "&&/[ \t\n\v\f\r]/u.test(r[l+1]??"");)l++;if(!(r[l]!==" "&&r.indexOf(n?" ":`
|
|
143
|
+
`,l+1)!==-1))break}i=r.slice(0,a),o=r.slice(a)}if(i==="/dev/null")return{stamp:0};let s=up(i,t);if(s===null)return{};let u=o.replace(/\r?\n$/u,"");return{name:s,timestr:u,stamp:n&&u!==""?_x(u):-1}}function _x(e){let t=/^\s*(\d{4})-(\d\d)-(\d\d)[ T](\d\d):(\d\d):(\d\d)(?:\.\d+)?\s*(?:([+-])(\d\d):?(\d\d))?/u.exec(e),n;if(t){let[,r,i,o,s,u,a,l,f,c]=t;n=Date.UTC(Number(r),Number(i)-1,Number(o),Number(s),Number(u),Number(a))/1e3,l&&(n-=(l==="-"?-1:1)*(Number(f)*3600+Number(c)*60))}else{let r=/^\s*[A-Z][a-z]{2} ([A-Z][a-z]{2}) +(\d+) (\d\d):(\d\d):(\d\d) (\d{4})/u.exec(e);if(!r)return-1;let i=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],[,o,s,u,a,l,f]=r;n=Date.UTC(Number(f),i.indexOf(o),Number(s),Number(u),Number(a),Number(l))/1e3}return n>-25*3600&&n<26*3600?0:n}function up(e,t){let n=t,r=0;for(let i=0;i<e.length;i++)if(e[i]==="/"){for(;e[i+1]==="/";)i++;(t<0||--n>=0)&&(r=i+1)}return(t<0||n<=0)&&r<e.length?e.slice(r):null}function tp(e,t){let n=e.replace(/^[ \t\n\v\f\r]+/u,""),r,i;if(n.startsWith('"')){let o=ap(n);if(!o)return{name:null,rest:""};r=o.value,i=o.rest}else{let o=n.search(/[ \t\n\v\f\r]/u);r=o<0?n:n.slice(0,o),i=o<0?"":n.slice(o)}return{name:up(r,t),rest:i}}var np={a:"\x07",b:"\b",f:"\f",n:`
|
|
144
|
+
`,r:"\r",t:" ",v:"\v","\\":"\\",'"':'"'};function ap(e){let t="";for(let n=1;n<e.length;n++){let r=e[n];if(r==='"')return{value:t,rest:e.slice(n+1)};if(r!=="\\"){t+=r;continue}let i=e[++n];if(i===void 0)return null;if(/[0-7]/u.test(i)){let o=/^[0-7]{1,3}/u.exec(e.slice(n))[0];t+=String.fromCodePoint(Number.parseInt(o,8)),n+=o.length-1}else if(i in np)t+=np[i];else return null}return null}function lp(e,t){let n=o=>o.split("/").length-1,r=o=>o.slice(o.lastIndexOf("/")+1).length,i=-1;for(let o=0;o<e.length;o++){let s=e[o];if(s===null||t[o])continue;if(i===-1){i=o;continue}let[u,a]=[n(s),n(e[i])];if(u!==a){u<a&&(i=o);continue}let[l,f]=[r(s),r(e[i])];if(l!==f){l<f&&(i=o);continue}s.length<e[i].length&&(i=o)}return i}function Ws(e,t){let{opts:n}=e;return(n.noReverse||!(n.force&&n.silent))&&e.say(t),n.noReverse?(e.say(` Skipping patch.
|
|
134
145
|
`),e.skipRest=!0,!1):n.force?(n.silent||e.say(` Applying it anyway.
|
|
135
146
|
`),!1):n.batch?(e.say(e.reverse?` Ignoring -R.
|
|
136
147
|
`:` Assuming -R.
|
|
@@ -138,23 +149,23 @@ diff: Try 'diff --help' for more information.`,2);function Sy(e){let t=[];for(le
|
|
|
138
149
|
`:` Assume -R? [n]
|
|
139
150
|
`),e.say(`Apply anyway? [n]
|
|
140
151
|
`),n.silent||e.say(`Skipping patch.
|
|
141
|
-
`),e.skipRest=!0,!1)}function
|
|
142
|
-
which ${l}!`)&&(e.reverse=!e.reverse)}return u}function
|
|
143
|
-
`),e.skipRest=!0),o===-1){if(n===null)return null;let u=r(n);return(!u.exists||!u.isDir)&&
|
|
152
|
+
`),e.skipRest=!0,!1)}function fp(e,t,n,r,i){let o=e.reverse?1:0,s=t.says,u=(i?0:1)<s[o^(i?1:0)];if(i&&s[o^(r?1:0)]===1&&s[1-o^(r?1:0)]===2)return!1;if(u){let a=r?"delete":i?"empty out":"create",l=r?"does not exist":i?"is already empty":"already exists";Ws(e,`The next patch${e.reverse?", when reversed,":""} would ${a} the file ${e.quote(n)},
|
|
153
|
+
which ${l}!`)&&(e.reverse=!e.reverse)}return u}function cp(e,t,n,r){let i=[t.names.old,t.names.new,t.names.index];(i[0]!==null||i[1]!==null)&&i[2]!==null&&(i[2]=null);let o=-1;if(n===null){let u=i.map(f=>f===null?null:r(f)),a=u.map(f=>f===null||!f.exists);o=lp(i,a);let l=i.findIndex(f=>f!==null);if(l!==-1&&(o===-1||!u[o].isDir)){let f=o===-1;fp(e,t,i[f?l:o],f,f||u[o].size===0)&&f&&(o=l)}o===-1&&t.says[e.reverse?1:0]&&(o=lp(i,i.map(()=>!1)))}if((t.rename[0]||t.rename[1]||t.copy[0]||t.copy[1])&&n===null&&!((o===0||o===1)&&i[0]!==null&&i[1]!==null)&&(e.say(`Cannot ${t.rename[0]||t.rename[1]?"rename":"copy"} file without two valid file names
|
|
154
|
+
`),e.skipRest=!0),o===-1){if(n===null)return null;let u=r(n);return(!u.exists||!u.isDir)&&fp(e,t,n,!u.exists,!u.exists||u.size===0),n}return i[o]}function pp(e){return{input:e,frozen:0,inOffset:0,outOffset:0,out:[]}}var Lx=(e,t)=>t<1||t>e.input.length?"":e.input[t-1];function Rx(e,t){let n=r=>r.replace(/\n$/u,"").replace(/[ \t]+$/u,"").replace(/[ \t]+/gu," ");return n(e)===n(t)}function mi(e,t,n,r,i,o,s){let u=t.oldLines,a=u.length-o;for(let l=n+r+i,f=i;f<a;f++,l++){let c=Lx(e,l),d=u[f].text;if(s?!Rx(c,d):c!==d)return!1}return!0}function dp(e,t,n,r){let i=t.oldStart+e.inOffset,o=t.oldLines.length,s=Math.max(t.prefix,t.suffix),u=n+t.prefix-s,a=n+t.suffix-s,l=e.input.length,f=l-(o-a)+1,c=e.frozen+1,d=f-i,p=i-c,h=Math.max(d,p);if(!o)return i;i<=p&&(p=i-1);let m=b=>(e.inOffset+=b,i+b);if(u<0&&t.oldStart<=1){if(a<0&&(o!==l||t.prefix<e.frozen))return 0;let b=1-i;return e.frozen<=t.prefix&&b<=d&&mi(e,t,i,b,0,a,r)?m(b):0}else u<0&&(u=0);if(a<0){let b=i-(l-o+1);return b<=p&&mi(e,t,i,-b,u,0,r)?m(-b):0}let g=d<0?i-f:p<0?i-c:0;for(let b=g;b<=h;b++){if(b<=d&&mi(e,t,i,b,u,a,r))return m(b);if(b<=p&&mi(e,t,i,-b,u,a,r))return m(-b)}return 0}function gi(e,t){if(e.frozen>t)return!1;for(;e.frozen<t;)e.frozen<e.input.length&&e.out.push(e.input[e.frozen]),e.frozen++;return!0}function Mx(e,t,n){let r=n-1,i=t.newLines,o=t.oldLines,s=0,u=0,a=()=>{throw new K(`Out-of-sync patch, lines ${t.line+1+u+1},${t.line+1+o.length+s+1} -- mangled text or line numbers, maybe?`)};for(;u<o.length;)if(o[u].tag==="-"){if(!gi(e,r+u))return!1;e.frozen++,u++}else{if(s>=i.length)break;if(i[s].tag==="+"){if(!gi(e,r+u))return!1;e.out.push(i[s++].text)}else i[s].tag===o[u].tag?(u++,s++):a()}for(;s<i.length&&i[s].tag==="+";s++){if(!gi(e,r+u))return!1;e.out.push(i[s].text)}return e.outOffset+=i.length-o.length,!0}var hp=e=>e.frozen>=e.input.length||gi(e,e.input.length),mp=e=>e.map((t,n)=>n<e.length-1&&!t.endsWith(`
|
|
144
155
|
`)?t+`
|
|
145
|
-
`:t).join("");function
|
|
146
|
-
`);else if(!o.silent&&(
|
|
147
|
-
`)}}return s}function
|
|
156
|
+
`:t).join("");function gp(e,t,n,r,i){let{opts:o}=e,s={count:0,failed:0,mismatch:!1,applyAnyway:!1};for(let u=n();u;u=n()){s.count++;let a=e.skipRest?{hunk:e.reverse?hi(u):u,where:0,fuzz:0}:Px(e,r,e.reverse?hi(u):u,s),{hunk:l,where:f,fuzz:c}=a,d=(f||l.oldStart)+r.outOffset,p=f===1&&t.says[e.reverse?1:0]===2&&r.input.length>0;if(e.skipRest||p||!f||!Mx(r,l,f))e.skipRejectFile||i.add(l,s.failed===0,r.outOffset,e.reverse),s.failed++,!e.skipRest&&!o.silent&&e.say(`Hunk #${s.count} FAILED at ${d}.
|
|
157
|
+
`);else if(!o.silent&&(c||r.inOffset)){let h=r.inOffset?` (offset ${r.inOffset} line${r.inOffset===1?"":"s"})`:"";e.say(`Hunk #${s.count} succeeded at ${d}${c?` with fuzz ${c}`:""}${h}.
|
|
158
|
+
`)}}return s}function Px(e,t,n,r){let{opts:i}=e,o=0,s=n,u=0,a=Math.min(i.fuzz,Math.max(s.prefix,s.suffix));do if(u=dp(t,s,o,i.loose),(!u||o||t.inOffset)&&(r.mismatch=!0),r.count===1&&!u&&!(i.force||r.applyAnyway)&&e.reverse===e.reverseFlag){let l=hi(s);u=dp(t,l,o,i.loose),u&&Ws(e,`${e.reverse?"Unreversed":"Reversed (or previously applied)"} patch detected!`)?(e.reverse=!e.reverse,s=l):u&&(r.applyAnyway=!0,o--,u=0)}while(!e.skipRest&&!u&&++o<=a);return{hunk:s,where:u,fuzz:o}}var nr=(e,t)=>e+t;function yp(e,t){let n="",r=(o,s)=>`${o} ${e.names[s]??"/dev/null"}${e.timestrs[s]??""}
|
|
148
159
|
`,i=e.names.index===null?"":`Index: ${e.names.index}
|
|
149
|
-
`;return{get text(){return n},add(o,s,u,a){let l=a?["new","old"]:["old","new"];t==="unified"?(s&&(n+=i+r("---",l[0])+r("+++",l[1])),n+=
|
|
150
|
-
`,o=0,s=0;for(;;s++,o++){for(;s<r.length&&r[s].tag==="-";s++)i+=
|
|
151
|
-
`;return o+=`*** ${
|
|
152
|
-
`,e.oldLines.forEach((s,u)=>{o+=
|
|
153
|
-
`,e.newLines.forEach((s,u)=>{o+=
|
|
154
|
-
patch: Try 'patch --help' for more information.`,2);function
|
|
155
|
-
`,events:[...s.events,{fd:2,text:
|
|
156
|
-
`}],exitCode:2};return
|
|
157
|
-
`;return{stdout:s.stdout,stderr:s.stderr+l,events:[...s.events,{fd:2,text:l}],exitCode:2}}return{stdout:s.stdout,stderr:s.stderr,events:s.events,exitCode:s.someFailed?1:0}}function
|
|
160
|
+
`;return{get text(){return n},add(o,s,u,a){let l=a?["new","old"]:["old","new"];t==="unified"?(s&&(n+=i+r("---",l[0])+r("+++",l[1])),n+=Dx(o,u)):(s&&(n+=i+r("***",l[0])+r("---",l[1])),n+=Ux(o,u,t))}}}var wp=(e,t)=>t===0?`${e-1},0`:t===1?`${e}`:`${e},${t}`;function Dx(e,t){let n=e.newLines,r=e.oldLines,i=`@@ -${wp(e.oldStart+t,r.length)} +${wp(e.newStart+t,n.length)} @@${e.fn??""}
|
|
161
|
+
`,o=0,s=0;for(;;s++,o++){for(;s<r.length&&r[s].tag==="-";s++)i+=nr("-",r[s].text);for(;o<n.length&&n[o].tag==="+";o++)i+=nr("+",n[o].text);if(s>=r.length)break;i+=nr(" ",r[s].text)}return i}function bp(e,t){let n=e+t-1;return n<e?"0":n===e?`${e}`:`${e},${n}`}function Ux(e,t,n){let r=n!=="normal",i=e.marks??(n==="normal"?Bx(e):qx(e)),o=`***************${e.fn??""}
|
|
162
|
+
`;return o+=`*** ${bp(e.oldStart+t,e.oldLines.length)}${r?" ****":""}
|
|
163
|
+
`,e.oldLines.forEach((s,u)=>{o+=nr(i.old[u]+" ",s.text)}),o+=`--- ${bp(e.newStart+t,e.newLines.length)}${r?" ----":" -----"}
|
|
164
|
+
`,e.newLines.forEach((s,u)=>{o+=nr(i.new[u]+" ",s.text)}),o}var Bx=e=>({old:e.oldLines.map(t=>t.tag),new:e.newLines.map(t=>t.tag)});function qx(e){let t=e.newLines.map(o=>o.tag),n=e.oldLines.map(o=>o.tag),r=0,i=0;for(;i<n.length;)if(n[i]==="-")if(r<t.length&&t[r]==="+"){do n[i++]="!";while(i<n.length&&n[i]==="-");do t[r++]="!";while(r<t.length&&t[r]==="+")}else do i++;while(i<n.length&&n[i]==="-");else if(r<t.length&&t[r]==="+")do r++;while(r<t.length&&t[r]==="+");else i++,r++;return{old:n,new:t}}var Wx=["R","N","f","t","s","b","l","E","T","Z","e","u","c","n","v"],jx=["reverse","forward","force","batch","silent","quiet","backup","ignore-whitespace","remove-empty-files","dry-run","verbose","unified","context","normal","ed","binary","no-backup-if-mismatch","backup-if-mismatch","posix","follow-symlinks","help","version","set-time","set-utc"],zx=["p","i","o","d","r","F","z","B","Y","V","g","D","x"],Hx=["strip","input","output","directory","reject-file","fuzz","suffix","prefix","basename-prefix","version-control","get","reject-format","quoting-style","read-only","merge","debug"],xp=new Map([["T","setting file times"],["Z","setting file times"],["set-time","setting file times"],["set-utc","setting file times"],["e","ed scripts"],["ed","ed scripts"],["v","a version banner"],["version","a version banner"],["help","a help text"],["verbose","verbose output"],["B","backup prefixes"],["prefix","backup prefixes"],["Y","backup prefixes"],["basename-prefix","backup prefixes"],["V","numbered backups"],["version-control","numbered backups"],["g","version control"],["get","version control"],["D","merged #ifdef output"],["x","debugging output"],["debug","debugging output"],["posix","POSIX mode"],["follow-symlinks","symbolic links"],["quoting-style","quoting styles"],["read-only","read-only handling"],["merge","merging"]]),kp=e=>y(`patch: ${e}
|
|
165
|
+
patch: Try 'patch --help' for more information.`,2);function Sp(e){for(let r of e){if(r==="--")break;let i=r.replace(/=.*/u,"");if(i==="--merge"||i==="--read-only")return{refused:k("option","patch",i,`patch: ${i}: ${xp.get(i.slice(2))} is not supported`,2)}}let t;try{t=N(e,{short:Wx,long:jx,valueShort:zx,valueLong:Hx})}catch(r){let i=O(r);return i?{refused:k(i.kind,"patch",i.detail,`patch: ${r.message}`,2)}:{error:kp(r.message)}}let n={strip:-1,input:null,output:null,directory:null,rejectFile:null,fuzz:2,suffix:".orig",format:null,rejectFormat:null,reverse:!1,noReverse:!1,force:!1,batch:!1,silent:!1,backup:!1,backupIfMismatch:!0,loose:!1,removeEmpty:!1,dryRun:!1};for(let{name:r,value:i}of t.order){let o=(r.length===1?"-":"--")+r,s=xp.get(r);if(s)return{refused:k("option","patch",o,`patch: ${o}: ${s} is not supported`,2)};let u=Gx(n,r,i);if(u)return{error:u}}return t.positional.length>2?{error:kp(`${t.positional[2]}: extra operand`)}:{opts:n,operands:t.positional}}function vp(e,t){if(!/^[+-]?\d+$/u.test(e))return{error:y(`patch: **** ${t} ${te(e,{vars:new Map})} is not a number`,2)};let n=Number(e);return n<0?{error:y(`patch: **** ${t} ${e} is negative`,2)}:{value:Math.min(n,Number.MAX_SAFE_INTEGER)}}function Gx(e,t,n){switch(t){case"p":case"strip":{let r=vp(n,"strip count");return r.error?r.error:(e.strip=r.value,null)}case"F":case"fuzz":{let r=vp(n,"fuzz factor");return r.error?r.error:(e.fuzz=r.value,null)}case"i":case"input":return e.input=n,null;case"o":case"output":return e.output=n,null;case"d":case"directory":return e.directory=n,null;case"r":case"reject-file":return e.rejectFile=n,null;case"z":case"suffix":return n===""?y("patch: **** backup suffix is empty",2):(e.suffix=n,null);case"R":case"reverse":return e.reverse=!0,null;case"N":case"forward":return e.noReverse=!0,null;case"f":case"force":return e.force=!0,null;case"t":case"batch":return e.batch=!0,null;case"s":case"silent":case"quiet":return e.silent=!0,null;case"b":case"backup":return e.backup=!0,null;case"l":case"ignore-whitespace":return e.loose=!0,null;case"E":case"remove-empty-files":return e.removeEmpty=!0,null;case"dry-run":return e.dryRun=!0,null;case"u":case"unified":return e.format="unified",null;case"c":case"context":return e.format="context",null;case"n":case"normal":return e.format="normal",null;case"no-backup-if-mismatch":return e.backupIfMismatch=!1,null;case"backup-if-mismatch":return e.backupIfMismatch=!0,null;case"reject-format":return n!=="unified"&&n!=="context"?y(`patch: **** unknown reject format ${n}`,2):(e.rejectFormat=n,null);default:return null}}function Ep(e,t,n){let r=Sp(t);if(r.error)return r.error;if(r.refused)return r.refused;let{opts:i,operands:o}=r,s={ctx:n,opts:i,dir:n.cwd,events:[],stdout:"",stderr:"",skipRest:!1,skipRejectFile:!1,reverse:i.reverse,reverseFlag:i.reverse,someFailed:!1,rejectsMade:new Set,output:""},u=i.output==="-"?2:1;s.quote=a=>te(a,n),s.say=a=>{u===1?s.stdout+=a:s.stderr+=a,s.events.push({fd:u,text:a})};try{if(i.directory!==null){let l=v(n.cwd,i.directory,n.fs);if(l.error||!n.fs.isDir(l.path))throw new K(`Can't change to directory ${te(i.directory,n)} : ${l.error??"Not a directory"}`);s.dir=l.path}let a=Xx(s,e,i.input??o[1]??null);Zx(s,rp(a),o[0]??null),i.output!==null&&i.output!=="-"&&bi(s,i.output,s.output,!1)}catch(a){if(!(a instanceof K)){let f=O(a);if(!f)throw a;let c=`patch: ${a.message}`,d={stdout:s.stdout,stderr:s.stderr+c+`
|
|
166
|
+
`,events:[...s.events,{fd:2,text:c+`
|
|
167
|
+
`}],exitCode:2};return re(d,f.kind,"patch",f.detail,c)}let l=`patch: **** ${a.message}
|
|
168
|
+
`;return{stdout:s.stdout,stderr:s.stderr+l,events:[...s.events,{fd:2,text:l}],exitCode:2}}return{stdout:s.stdout,stderr:s.stderr,events:s.events,exitCode:s.someFailed?1:0}}function Xx(e,t,n){if(n===null)return X(e.ctx),t;if(n==="-")return X(e.ctx),t;let r=R(e.ctx,"patch",n);if(r.error||e.ctx.fs.isDir(r.path))throw new K(`Can't open patch file ${te(n,e.ctx)} : ${r.error??"Is a directory"}`);return e.ctx.fs.readFile(r.path)}function Zx(e,t,n){let{opts:r}=e;for(;;){if(t.base!==0&&t.base>=t.lines.length)return;let i=ip(t,{needHeader:n===null,strip:r.strip,format:r.format});if(i===null){if(t.base===0&&!t.empty)throw new K("Only garbage was found in the patch input.");return}e.skipRest=!1,e.skipRejectFile=!1,e.reverse=e.reverseFlag;let o=cp(e,i,n,s=>yi(e,s));o===null&&(o=Yx(e,t,i)),e.skipRest&&(e.someFailed=!0),t.pos=i.start,Vx(e,t,i,o),t.base=t.pos}}function Yx(e,t,n){let{opts:r}=e;if(r.silent||(e.say(`can't find file to patch at input line ${n.hunkLine+1}
|
|
158
169
|
`),n.type!=="normal"&&e.say(r.strip===-1?`Perhaps you should have used the -p or --strip option?
|
|
159
170
|
`:`Perhaps you used the wrong -p or --strip option?
|
|
160
171
|
`)),t.base<n.start){e.say(`The text leading up to this was:
|
|
@@ -164,92 +175,92 @@ patch: Try 'patch --help' for more information.`,2);function yd(e){for(let r of
|
|
|
164
175
|
`):(e.say(`File to patch:
|
|
165
176
|
`),e.say(`Skip this patch? [y]
|
|
166
177
|
`),r.silent||e.say(`Skipping patch.
|
|
167
|
-
`)),e.skipRest=!0,null}function
|
|
168
|
-
`),e.skipRest=!0,e.someFailed=!0)),!e.skipRest&&!i.dryRun&&i.output===null&&(
|
|
169
|
-
`)}let l=
|
|
178
|
+
`)),e.skipRest=!0,null}function Vx(e,t,n,r){let{opts:i}=e,o=n.copy[0]||n.copy[1]||n.rename[0]||n.rename[1],s=null;e.skipRest||(s=i.output??(o?n.names[e.reverse?"old":"new"]:r));let u={exists:!1,isDir:!1,content:""};e.skipRest||(u=yi(e,r),(u.isDir||u.link)&&(e.say(`File ${te(r,e.ctx)} is not a regular file -- refusing to patch
|
|
179
|
+
`),e.skipRest=!0,e.someFailed=!0)),!e.skipRest&&!i.dryRun&&i.output===null&&(rr(e,s),o&&r!==s&&rr(e,r));let a=pp(He(u.exists?u.content:""));if(!e.skipRest&&!i.silent){let p=r!==s,h=!p&&(n.rename[0]||n.rename[1]),m=n.copy[0]||n.copy[1]?"copied":n.rename[0]||n.rename[1]?"renamed":"read",g=h?n.names[r===n.names.old?"new":"old"]:r,b=p||h?` (${h?"already ":""}${m} from ${g})`:"";e.say(`${i.dryRun?"checking":"patching"} file ${te(s,e.ctx)}${b}
|
|
180
|
+
`)}let l=yp(n,i.rejectFormat??n.type),c=gp(e,n,()=>n.empty?null:op(t,n.type),a,l);!e.skipRest&&!hp(a)&&(e.say(`misordered hunks! output would be garbled
|
|
170
181
|
Skipping patch.
|
|
171
|
-
`),e.skipRest=!0);let d=
|
|
172
|
-
`)),!r.dryRun){if(a.failed<a.count||
|
|
182
|
+
`),e.skipRest=!0);let d=mp(a.out);i.output!==null&&!e.skipRest&&(i.output==="-"?(e.stdout+=d,e.events.push({fd:1,text:d})):e.output+=d),!e.skipRest&&i.output===null&&Kx(e,n,{inname:r,outname:s,input:u,content:d,result:c,empty:a.out.length===0,renaming:o}),c.failed&&!e.skipRejectFile&&Jx(e,s,c,l.text)}function Kx(e,t,n){let{opts:r}=e,{inname:i,outname:o,input:s,content:u,result:a,empty:l,renaming:f}=n,c=r.backup||r.backupIfMismatch&&(a.mismatch||a.failed>0),d=t.says[e.reverse?0:1]===2;if(l&&(r.removeEmpty||d)){r.dryRun||$p(e,o,c);return}if(!l&&d&&(e.someFailed=!0,r.silent||e.say(`Not deleting file ${te(o,e.ctx)} as content differs from patch
|
|
183
|
+
`)),!r.dryRun){if(a.failed<a.count||f)bi(e,o,u,c),f&&i!==o&&(t.rename[0]||t.rename[1])&&$p(e,i,!1);else if(c){if(!s.exists)throw new K(`Can't reopen file ${te(o,e.ctx)} : No such file or directory`);bi(e,wi(e,o),s.content,!1)}}}function Jx(e,t,n,r){let{opts:i}=e;if(e.someFailed=!0,e.say(`${n.failed} out of ${n.count} hunk${n.count===1?"":"s"} ${e.skipRest?"ignored":"FAILED"}`),t===null||i.rejectFile==="-"){e.say(`
|
|
173
184
|
`);return}let o=i.rejectFile??t+".rej";if(i.dryRun){e.say(`
|
|
174
|
-
`);return}e.say(` -- saving rejects to file ${
|
|
175
|
-
`),
|
|
176
|
-
`)}function
|
|
177
|
-
`:"";if(i==="")return C(o);let{path:s,error:u}=
|
|
178
|
-
`)]:[];for(let
|
|
179
|
-
`)),!!r.has("R"))for(let
|
|
185
|
+
`);return}e.say(` -- saving rejects to file ${te(o,e.ctx)}
|
|
186
|
+
`),rr(e,o);let s=e.rejectsMade.has(G(e.dir,o));e.rejectsMade.add(G(e.dir,o));let u=s?yi(e,o).content:"";bi(e,o,u+r,!1)}var wi=(e,t)=>t+e.opts.suffix;function yi(e,t){let n=v(e.dir,t,e.ctx.fs,{follow:!1}),r=!n.error&&e.ctx.fs.isLink?.(n.path)===!0,i=v(e.dir,t,e.ctx.fs);if(i.error)return{exists:!1,isDir:!1,link:r,size:0,content:""};if(e.ctx.fs.isDir(i.path))return{exists:!0,isDir:!0,link:r,size:0,content:""};let o=e.ctx.fs.readFile(i.path);return{exists:!0,isDir:!1,link:r,size:o.length,content:o}}function rr(e,t){let n=ie(e.ctx.fs,e.dir,t,!1);if(!(e.ctx.writable&&n.startsWith("/tmp/")))throw new w("feature","read-only target",`${t}: file system is read-only`)}function bi(e,t,n,r){let{ctx:i}=e;rr(e,t);let o=v(e.dir,t,i.fs);try{if(!o.error){i.fs.replaceWritable(e.dir,t,n,r?wi(e,t):void 0);return}r&&i.fs.openWritable(e.dir,wi(e,t)),i.fs.openWritable(e.dir,t).write(n)}catch(s){throw new K(`Can't create file ${te(t,e.ctx)} : ${s?.fsError??s.message}`)}}function $p(e,t,n){let{ctx:r}=e;rr(e,t);let i=yi(e,t);i.exists&&(n&&r.fs.openWritable(e.dir,wi(e,t)).write(i.content),r.fs.removeWritable(e.dir,t))}var Np={du:td,stat:xd,realpath:dc,diff:Zd,patch:Ep};function Qx(e,t,n){return N(t),C(n.cwd+`
|
|
187
|
+
`)}function e2(e,t,n){let{positional:r}=N(t);if(r.length>1)return y("cd: too many arguments");if(!r.length&&n.vars.unsetNames.has("HOME"))return y("cd: HOME not set");let i=r[0]??rn(n);if(i==="-"){if(!n.vars.has("OLDPWD"))return y("cd: OLDPWD not set");i=n.vars.get("OLDPWD")}let o=r[0]==="-"?i+`
|
|
188
|
+
`:"";if(i==="")return C(o);let{path:s,error:u}=R(n,"cd",i);return u?y(`cd: ${i}: ${u}`):n.fs.isDir(s)?s!==G(n.cwd,i)?k("feature","cd","symbolic link cwd",`cd: ${i}: a working directory reached through a symbolic link is not supported (it leads to ${s})`):(n.vars.set("OLDPWD",n.cwd),n.vars.set("PWD",s),n.cwd=s,C(o)):y(`cd: ${i}: Not a directory`)}var t2={dir:"/",link:"@",file:""};function n2(e,t,n){let{flags:r,positional:i}=N(t,{short:["1","l","a","A","R","d","r","F","h"]}),o=r.has("l")?Ac(n,r.has("h")):null,s=(i.length?i:["."]).toSorted(B);r.has("r")&&s.reverse();let u=[],a=[],l=[],f=Zt(),c=r.has("a")||r.has("A"),d=x=>n.fs.isDir(x)?"dir":n.fs.isLink?.(x)?"link":"file",p=x=>r.has("F")?t2[x]:"",h=(x,S,E)=>({raw:x,abs:S,kind:E,name:E==="link"&&o?x:x+(x.endsWith("/")?"":p(E)),target:E==="link"?n.fs.readLink(S)+p(d(v(n.cwd,S,n.fs).path??"")):null}),m=(x,S)=>o?o.lines(x,S):x.map(E=>E.name),g=!(r.has("l")||r.has("F")||r.has("d"));for(let x of s){let{path:S,error:E}=R(n,"ls",x,{follow:!1}),M=E||!g||!n.fs.isLink?.(S)?S:v(n.cwd,x,n.fs).path;E?a.push(`ls: cannot access '${x}': ${E}`):r.has("d")||n.fs.isFile(S)||!n.fs.isDir(M)?l.push(h(x,S,d(S))):u.push({path:x,abs:M})}let b=l.length?[m(l,!1).join(`
|
|
189
|
+
`)]:[];for(let x of u){let S=[x];for(;S.length;){let{path:E,abs:M}=S.pop(),D=n.fs.listDir(M);c||f.collect(M,[...D.dirs,...D.files,...D.links]);let T=(z,ce)=>z.filter(zt=>c||!zt.startsWith(".")).map(zt=>h(zt,G(M,zt),ce)),ne=[...T(D.dirs,"dir"),...T(D.files,"file"),...T(D.links,"link")];r.has("a")&&ne.push(h(".",M,"dir"),h("..",G(M,".."),"dir")),ne.sort((z,ce)=>B(z.raw,ce.raw)),r.has("r")&&ne.reverse();let Le=m(ne,!0);if((s.length>1||r.has("R"))&&Le.unshift(E+":"),Le.length&&b.push(Le.join(`
|
|
190
|
+
`)),!!r.has("R"))for(let z of ne.toReversed())z.raw==="."||z.raw===".."||!n.fs.isDir(z.abs)||S.push({path:E.endsWith("/")?E+z.raw:E+"/"+z.raw,abs:z.abs})}}return f.emit(n.notes,"ls","Hidden entries are included with -a."),{stdout:b.length?b.join(`
|
|
180
191
|
|
|
181
192
|
`)+`
|
|
182
193
|
`:"",stderr:a.length?a.join(`
|
|
183
194
|
`)+`
|
|
184
|
-
`:"",exitCode:a.length?2:0}}function
|
|
185
|
-
`)}function
|
|
195
|
+
`:"",exitCode:a.length?2:0}}function r2(e,t){let{positional:n}=N(t);if(n.length===0)return de("basename PATH [SUFFIX]");if(n.length>2)return y(`basename: extra operand: ${n[2]}`);let r=n[0].replace(/\/+$/u,""),i=r===""?n[0]===""?"":"/":r.slice(r.lastIndexOf("/")+1);return C(i2(i,n[1])+`
|
|
196
|
+
`)}function i2(e,t){return!t||t===e||!e.endsWith(t)?e:e.slice(0,-t.length)}function o2(e,t){let{positional:n}=N(t);return n.length===0?de("dirname PATH"):C(n.map(r=>{let i=r.replace(/\/+$/u,""),o=i.lastIndexOf("/");return o<0?r.startsWith("/")?"/":".":i.slice(0,o).replace(/\/+$/u,"")||"/"}).join(`
|
|
186
197
|
`)+`
|
|
187
|
-
`)}var
|
|
188
|
-
`;continue}let g=
|
|
189
|
-
`),
|
|
198
|
+
`)}var Ap={pwd:Qx,cd:e2,ls:n2,find:Tc,tree:Oc,basename:r2,dirname:o2,...Np};function Ip(e,t,n){let{flags:r,positional:i}=N(t,{short:["n","b","s","v","E","T","A","e","t"]}),o=u=>u2(u,r),s=s2(i,e,n,o,r.size!==0);return ee(o(s.content),s)}function s2(e,t,n,r,i){let o=n.outputFds[1];if(!o?.path&&!n.outputFds[2]?.path)return Sn("cat",e,t,n);let s="",u=t,a="";for(let l of e.length?e:["-"]){let f=l==="-",c=f||l==="/dev/stdin",d=c?n.stdinHandle?.path:v(n.cwd,l,n.fs).path,p=c?n.stdinHandle?.identity:n.fs.fileIdentity?.(d);if(a&&Op(d,p,n.outputFds[2]))throw new w("feature","cat input modified by diagnostics","cat: reading an input after writing diagnostics to the same file is not supported");if(Op(d,p,o)){if((f?A(n.stdinHandle.content).length-A(u).length:0)<o.position+A(r(s)).length){a+=`cat: ${l}: input file is output file
|
|
199
|
+
`;continue}let g=f?u:c?n.stdinOrigin:n.fs.readFile(d);if(i&&g!=="")throw new w("feature","cat transforms its input file","cat: transforming an input file through its own output descriptor is not supported")}let h=Sn("cat",[l],u,n);s+=h.content,a+=h.stderr,(f||l==="/dev/stdin"&&!n.stdinFile)&&(u="")}return{content:s,stderr:a,failed:a!==""}}function Op(e,t,n){return!e||!n?.path?!1:t!==void 0&&n.identity!==void 0?t===n.identity:e===n.path}function u2(e,t){if(!t.size)return e;let n=t.has("E")||t.has("A")||t.has("e"),r=t.has("T")||t.has("A")||t.has("t"),i=t.has("v")||t.has("A")||t.has("e")||t.has("t"),o=t.has("s")?a2(e):e,s=0;return He(o).map(a=>{let l=a.endsWith(`
|
|
200
|
+
`),f=l?a.slice(0,-1):a,c=(t.has("b")?f!=="":t.has("n"))?`${String(++s).padStart(6)} `:"";return i?f=[...A(f)].map(d=>Cp(d,r)).join(""):(r&&(f=f.replaceAll(" ","^I")),n&&l&&f.endsWith("\r")&&(f=f.slice(0,-1)+"^M")),c+f+(l?n?`$
|
|
190
201
|
`:`
|
|
191
|
-
`:"")}).join("")}function
|
|
192
|
-
`)}var
|
|
193
|
-
`,t:" ",r:"\r",a:"\x07",f:"\f",v:"\v"};function
|
|
194
|
-
`)throw new Error(`unterminated ${t}`);if(n.codePointAt(0)>127)throw new Error("delimiter character is not a single-byte character");return n}function
|
|
202
|
+
`:"")}).join("")}function Cp(e,t){return e===9?t?"^I":" ":e>=128?"M-"+Cp(e-128,!0):e<32?"^"+String.fromCodePoint(e+64):e===127?"^?":String.fromCodePoint(e)}function a2(e){return e.replace(/(^|\n)\n+/gu,`$1
|
|
203
|
+
`)}var xi="sed: supported commands are p, P, n, N, d, D, a, i, c, g, G, h, H, x, w, q, =, y, :, b, t, T, { }, and s/regexp/replacement/[NgiIpw]",js=1e6,ki=16*1024*1024,Fp=64*1024*1024;function ve(e="script"){throw new w("feature",e,xi)}function vi(e){return e.gap?k("feature","sed",e.gap,`sed: ${e.message}`):e instanceof RangeError?k("feature","sed","regex runtime limit",`sed: ${e.message}`):Y(e,"sed",`sed: ${e.message.replace(/^sed: /u,"")}`,e.exitCode)}function Tp(e){let t=[],n=null;for(let r=0;r<e.length;r++){let i=e[r];if(i==="--"){t.push(...e.slice(r));break}if(i==="--in-place"||i.startsWith("--in-place=")){n=i==="--in-place"?"":i.slice(11);continue}if(i.startsWith("--")||!i.startsWith("-")){t.push(i),(i==="--expression"||i==="--file")&&r+1<e.length&&t.push(e[++r]);continue}let o=i;for(let s=1;s<i.length;s++){let u=i[s];if(u==="i"){n=i.slice(s+1),o=i.slice(0,s);break}if(u==="e"||u==="f"){t.push(i),s+1===i.length&&r+1<e.length&&t.push(e[++r]),o="";break}if(!"nErsz".includes(u))break}o&&(o!=="-"||i==="-")&&t.push(o)}return{tokens:t,inPlace:n}}function _p(e,t,n,r,i){if(e.files.length===0)return y("sed: no input files",4);let o=U(),s=new Set([...t,"s"]),u=!1;for(let a of e.files){let l=l2(a,n);if(l.error){if(_(o,n.flushOutput(l.error)),l.error.exitCode!==2)return Si(o,l.error);u=!0;continue}let f=i({...e,files:[l.path]},s),{content:c,...d}=f;if(_(o,d),f.failed||O(f))return Si(o,f);let p=f2(a,r),h;try{h=n.fs.replaceWritable(n.cwd,a,c,p)}catch(m){L(n,"sed",m?.path,m?.fsError);let g=Y(m,"sed",`sed: ${m.message}`,4);return _(o,g),Si(o,g)}if(!h){let m=zs(p??a);return _(o,m),Si(o,m)}if(f.quit)break}return u&&(o.exitCode=2),o}function l2(e,t){if(e==="/dev/null"||e==="/dev/stdin"&&!t.stdinFile||e==="/dev/stdout"&&!t.outputFds[1]?.path||e==="/dev/stderr"&&!t.outputFds[2]?.path)return{error:y(`sed: couldn't edit ${e}: not a regular file`,4)};if(e==="/dev/stdin"||e==="/dev/stdout"||e==="/dev/stderr")return{error:zs(e)};let n=R(t,"sed",e);if(n.error)return{error:y(fo("sed",e,n.error).trimEnd(),2)};if(t.fs.isDir(n.path))return{error:y(`sed: couldn't edit ${e}: not a regular file`,4)};let r=v(t.cwd,e,t.fs,{follow:!1}).path;return!t.writable||!r.startsWith("/tmp/")?{error:zs(e)}:n}function f2(e,t){if(!(t===""||t==="*"))return t.includes("*")?t.replaceAll("*",()=>e):e+t}function zs(e){return k("feature","sed","-i",`sed: ${e}: file system is read-only`)}function Si(e,t){let n=O(t);return n?re(e,n.kind,n.command,n.detail,n.message):e}function Hs(e,t){let n=!1;return(r,i)=>{e((n?t:"")+r+(i??"")),n=i===""}}function Lp(e,t){let n=new Map,r=0,i,o,s,u=()=>e.io.setReads([i,o?.identity]);function a(f,c){if(c==="")return;l(c),u();let d=e.outputFds[f];if(d?.path){d.write(c);return}if(d==="closed"){let p=new Error("write error: Bad file descriptor");throw p.exitCode=4,p}s[f===1?"stdout":"stderr"]+=c,s.events.push({fd:f,text:c})}function l(f){if(r+=f.length,r>Fp)throw new w("feature","output limit","sed: output limit exceeded")}return{start(f){return s=U(),o=f,i=void 0,u(),s},record(f){i=f?.identity,u()},finish(){i=void 0,o=null,u()},stream:a,account:l,openWrite(f){if(n.has(f))return n.get(f);let c;if(f==="/dev/null")c=()=>{};else if(f==="/dev/stdout"||f==="/dev/stderr")c=p=>a(f==="/dev/stdout"?1:2,p);else{let p;try{p=e.writable&&e.fs.openWritable(e.cwd,f)}catch(h){throw L(e,"sed",h?.path,h?.fsError),h.exitCode=4,h}if(!p)throw new w("feature","output file",`sed: ${f}: Read-only file system`);c=h=>{l(h),u(),p.write(h)}}let d=Hs(c,t);return n.set(f,d),d}}}function ir(e,t){let n=t.stdinHandle;if(!n)return e;let r=t.io.bufferReads(()=>t.fs.readIdentity(n.identity));if(r===n.content)return e;if(e!==n.content)throw new w("feature","modified redirected input","sed: reading an input file changed after partial consumption is not supported");return t.stdinHandle={...n,content:r},t.stdinOrigin=t.stdinLeft=r,r}function Rp(e,t,n,r,i,o){let s=e.length?e:["-"],u={stderr:"",failed:!1},a=0,l=0,f=t,c=null;function d(){for(;c===null||c.pos===c.content.length;){if(a===s.length)return!1;c=null;let h=s[a++];h==="-"?f=ir(f,n):h==="/dev/stdin"&&n.stdinHandle&&(n.stdinOrigin=n.io.bufferReads(()=>n.fs.readIdentity(n.stdinHandle.identity)));let m=rt("sed",[h],n,f);if(u.stderr+=m.stderr,u.failed||=m.failed,c=m.inputs.length?{...m.inputs[0],identity:c2(h,n),pos:0,first:!0}:null,m.stderr&&o&&o(m.stderr),m.entries.some(g=>g.kind==="dir"))return u.directory=!0,a=s.length,!1;c?.shared&&X(n,f),i&&(l=0)}return!0}function p(){if(!d())return null;let h=c.pos,m=c.content.indexOf(r,h),g=m<0?"":r,b=c.content.slice(h,m<0?c.content.length:m);c.pos=m<0?c.content.length:m+r.length,c.shared&&(f=c.content.slice(c.pos),X(n,f));let x=c.first;c.first=!1;let S;return{text:b,terminator:g,line:++l,reset:x,identity:c.identity,last:()=>S??=c.pos<c.content.length?!1:i||!d()}}return{next:p,status:u,get identity(){return c?.identity}}}function c2(e,t){return e==="-"||e==="/dev/stdin"?t.stdinHandle?.identity:t.fs.fileIdentity?.(v(t.cwd,e,t.fs).path??G(t.cwd,e))}var $i={n:`
|
|
204
|
+
`,t:" ",r:"\r",a:"\x07",f:"\f",v:"\v"};function or(e,t="substitute command"){let n=e.script[e.i++];if(n===void 0||n===`
|
|
205
|
+
`)throw new Error(`unterminated ${t}`);if(n.codePointAt(0)>127)throw new Error("delimiter character is not a single-byte character");return n}function Ei(e,t,n,r="substitute command"){let i="",o=!1;for(;e.i<e.script.length;){let s=e.script[e.i++];if(s===`
|
|
195
206
|
`)throw new Error(`unterminated ${r}`);if(s===t&&!o)return i;if(s==="\\"){let u=e.script[e.i++];if(u===void 0||u===`
|
|
196
207
|
`&&o)throw new Error(`unterminated ${r}`);if(u===`
|
|
197
208
|
`){i+=u;continue}i+=!o&&u===t&&(n||u!=="&")?u:s+u;continue}if(n&&s==="["&&!o){o=!0,i+=s,e.script[e.i]==="^"&&(i+=e.script[e.i++]),e.script[e.i]==="]"&&(i+=e.script[e.i++]);continue}if(n&&o&&s==="["&&/[:.=]/u.test(e.script[e.i]??"")){let u=e.script.indexOf(e.script[e.i]+"]",e.i+1);if(u<0)throw new Error("unterminated character class");if(e.script.slice(e.i,u).includes(`
|
|
198
|
-
`))throw new Error(`unterminated ${r}`);i+=s+e.script.slice(e.i,u+2),e.i=u+2;continue}n&&s==="]"&&(o=!1),i+=s}throw new Error(`unterminated ${r}`)}function
|
|
199
|
-
`)break;if(/\d/u.test(n)){if(t.nth!==null)throw new Error("multiple number options to substitute command");let r=/^\d*/u.exec(e.script.slice(e.i))[0];if(e.i+=r.length,t.nth=Number(n+r),t.nth===0)throw new Error("number option to substitute command may not be zero");Number.isSafeInteger(t.nth)||
|
|
200
|
-
`&&(e.textState.pending.raw=n)}
|
|
209
|
+
`))throw new Error(`unterminated ${r}`);i+=s+e.script.slice(e.i,u+2),e.i=u+2;continue}n&&s==="]"&&(o=!1),i+=s}throw new Error(`unterminated ${r}`)}function Mp(e){let t=or(e),n=Ei(e,t,!0),r=Ei(e,t,!1),i=h2(r),o=d2(e);if(n===""&&(o.ignoreCase||o.multiline))throw new Error("cannot specify modifiers on empty regexp");o.multiline&&Pp(o.multiline);let s=Xs(n,e.extended,!1,o.ignoreCase,e.locale);for(let u of i)if(typeof u=="number"&&u>s.re?.groupCount)throw new Error(`invalid reference \\${u} in replacement`);return{...s,parts:i,...o}}function d2(e){let t={global:!1,print:!1,nth:null};for(;e.i<e.script.length;){let n=e.script[e.i];if(/[;\n#}]/u.test(n))break;if(e.i++,!/[ \t]/u.test(n)){if(n==="\r"&&e.script[e.i]===`
|
|
210
|
+
`)break;if(/\d/u.test(n)){if(t.nth!==null)throw new Error("multiple number options to substitute command");let r=/^\d*/u.exec(e.script.slice(e.i))[0];if(e.i+=r.length,t.nth=Number(n+r),t.nth===0)throw new Error("number option to substitute command may not be zero");Number.isSafeInteger(t.nth)||ve("substitution occurrence limit")}else if(n==="g"||n==="p"){let r=n==="g"?"global":"print";if(t[r])throw new Error("multiple substitution flags");t[r]=!0}else if(n==="w"){Object.assign(t,Gs(e));break}else if(n==="i"||n==="I")t.ignoreCase=!0;else if(n==="m"||n==="M")t.multiline=n;else if(n==="e")Pp(n);else throw new Error(`unknown option to substitute command: '${n}'`)}}return t}function Pp(e){let t=e==="e"?"command evaluation":"multiline regex matching";throw new w("feature",`substitution flag ${e}`,`sed: substitution flag '${e}' (${t}) is not supported`)}function Gs(e){let t=/^[ \t]*([^\n]*)/u.exec(e.script.slice(e.i));e.i+=t[0].length;let n=t[1].split("\0",1)[0];if(n==="")throw new Error("missing filename in r/R/w/W commands");return e.openWrite?{writer:e.openWrite(n)}:{writeName:n}}function Xs(e,t,n=!1,r=!1,i=J){if(!e){if(r)throw new Error("cannot specify modifiers on empty regexp");return{re:null}}let o=Q(i);Xo(e,t,o.multibyte);let s=e.replace(/\\(.)/gu,(f,c)=>(c==="o"&&ve("regex escape"),Object.hasOwn($i,c)?$i[c]:f)),u=r?Dn(s,o):s,a=t?{source:Ho(u,o)}:Yr(u,o);if(a.error)throw new Error(a.error);p2(a.source,t),Vr(a.source);for(let[,f]of a.source.matchAll(/\\(.)/gu))/[1-9]/u.test(f)&&ve("regex backreferences");return{re:new at(Un(a.source,!0,o),!1,null,o),noSub:n,locale:i,ignoreCase:r,pattern:s}}function p2(e,t){let n=!1,r=0,i=!1,o=!1;for(let s=0;s<e.length;s++){let u=e[s];if(u==="\\"){let a=e[++s];n||(i=!"bB<>`'".includes(a),o=!1);continue}if(n){u==="]"&&(n=!1,i=!0,o=!1);continue}if(u==="["){n=!0;continue}if(u==="("){r++,i=!1,o=!1;continue}if(u===")"){if(--r<0)throw new Error("unmatched )")}else if(u==="|"||u==="^"||u==="$"){i=!1,o=!1;continue}else if("*+?{".includes(u)){let a=u==="{"?/^\{(?=\d|,)(\d*)(?:,(\d*))?\}/u.exec(e.slice(s)):null;if(u==="{"&&a===null)throw new Error("invalid repetition count");if(!i||!t&&o&&(u==="*"||u==="{"))throw new Error("Invalid preceding regular expression");a&&(s+=a[0].length-1),o=!0;continue}i=!0,o=!1}if(r>0)throw new Error("unmatched (")}function h2(e){let t=[];for(let n=0;n<e.length;n++){let r=e[n];if(r==="&"){t.push(0);continue}if(r!=="\\"){t.push(r);continue}let i=e[++n];/[0-9]/u.test(i)?t.push(Number(i)):i==="\\"||i==="&"?t.push(i):Object.hasOwn($i,i)?t.push($i[i]):ve("replacement escape")}return t}function Zs(e,t){if(/[\u0080-\u{10FFFF}]/u.test(e+t.re.src)){if(t.locale!==J)throw new w("feature","locale",`matching non-ASCII text in the ${t.locale} locale is not supported`);t.ignoreCase&&It.test(e+t.pattern)&&ve("case folding of Cyrillic Extended-C letters")}}function Ys(e,t,n=null){let r=e.re===null?t.last:e;if(!r)throw new Error("no previous regular expression");if(t.last=r,n!==null&&r.noSub){if(n>r.re.groupCount)throw new Error(`invalid reference \\${n} in replacement`);r.noSub=!1}return r}function Vs(e,t,n){let r=t.parts.reduce((l,f)=>typeof f=="number"?Math.max(l,f):l,0),i=Ys(t,n,r);Zs(e,i);let o=t.parts.some(l=>typeof l=="number"&&l>0&&l<=i.re.groupCount),s=0,u=t.nth&&!t.global?{search:(l,f)=>s?null:i.re.search(l,f)}:i.re;return{out:Pn(e,u,(l,f,c)=>{if(t.nth&&c<t.nth)return null;s++;let d=o?i.re.groups(e,l,f):null;return t.parts.map(p=>typeof p=="string"?p:p===0?e.slice(l,f):d?.[p]?.text??"").join("")},t.global||t.nth?"global":"first").out,count:s}}var Dp={a:7,f:12,n:10,r:13,t:9,v:11,"\n":10},Up={d:10,o:8,x:16};function qp(e,t){for(;/[ \t]/u.test(e.script[e.i]??"");)e.i++;if(e.i===e.script.length)throw new Error("expected \\ after 'a', 'c' or 'i'");if(t.text=null,e.textState.pending={command:t,raw:""},e.script[e.i]==="\\"){let n=e.script[++e.i];if(n===void 0)return;e.i++,n!==`
|
|
211
|
+
`&&(e.textState.pending.raw=n)}Js(e)}function Js(e){let t=e.textState.pending;if(!t)return;let n=t.raw;for(;e.i<e.script.length&&e.script[e.i]!==`
|
|
201
212
|
`;){let r=e.script[e.i++];if(r==="\\"){if(e.i===e.script.length){t.raw=n+`
|
|
202
|
-
`;return}n+=r+e.script[e.i++]}else n+=r}t.command.text=
|
|
203
|
-
`),e.textState.pending=null}function
|
|
213
|
+
`;return}n+=r+e.script[e.i++]}else n+=r}t.command.text=m2(n+`
|
|
214
|
+
`),e.textState.pending=null}function Qs(e){e?.pending&&(e.pending.command.text=e.pending.raw||null,e.pending=null)}function m2(e){return P(Ks(e))}function Ks(e){let t=A(e),n=[];for(let r=0;r<t.length;r++){let i=t[r];if(i!==92||r+1===t.length){n.push(i);continue}let o=String.fromCodePoint(t[++r]);if(Object.hasOwn(Dp,o)){n.push(Dp[o]);continue}if(Object.hasOwn(Up,o)){let s=Up[o],u=s===16?2:3,a=0,l=0;for(;a<u&&r+1<t.length;){let f=t[r+1],c=f>=48&&f<=57?f-48:(f|32)>=97&&(f|32)<=102?(f|32)-87:-1;if(c<0||c>=s)break;l=l*s+c,a++,r++}n.push(a?l&255:o.codePointAt(0))}else if(o==="c"){if(++r===t.length)continue;let s=t[r];if(s===92&&t[++r]!==92)throw new Error("recursive escaping after \\c not allowed");n.push((s>=97&&s<=122?s-32:s)^64)}else n.push(o.codePointAt(0))}return Uint8Array.from(n)}function Wp(e){let t=or(e,"'y' command"),n=Ks(Bp(e,t)),r=Ks(Bp(e,t)),i=e.byteLocale?n:[...P(n)],o=e.byteLocale?r:[...P(r)];if(i.length!==o.length)throw new Error("'y' command strings have different lengths");let s=e.byteLocale?Uint8Array.from({length:256},(u,a)=>a):new Map;for(let u=0;u<i.length;u++)e.byteLocale?s[i[u]]=o[u]:s.has(i[u])||s.set(i[u],o[u]);return{translation:s,byteLocale:e.byteLocale}}function Bp(e,t){let n="";for(;e.i<e.script.length;){let r=e.script[e.i++];if(r===`
|
|
204
215
|
`)break;if(r===t)return n;if(r!=="\\"){n+=r;continue}let i=e.script[e.i++];if(i===void 0)break;n+=i===t||i===`
|
|
205
|
-
`?i:r+i}throw new Error("unterminated 'y' command")}function
|
|
206
|
-
`,u=
|
|
207
|
-
`;continue}u!==-1?n.vars.set(l,(a?
|
|
208
|
-
`:o)}function
|
|
209
|
-
`,r.failed=!0,r.stop=!0,{bytes:[],end:e.length,stop:!0};let u=parseInt(e.slice(t+2,o),16);if(i==="x")return{bytes:[u],end:o};if(!
|
|
210
|
-
`))return e;let n=
|
|
216
|
+
`?i:r+i}throw new Error("unterminated 'y' command")}function jp(e,t){if(t.byteLocale)return P(A(e).map(r=>t.translation[r]));let n="";for(let r of e)n+=t.translation.get(r)??r;return n}function eu(e,t=!1,n=J,r=null){let i={script:e,i:0,extended:t,locale:n,byteLocale:Cr(n),textState:r??{},openWrite:r?.openWrite},o=[];for(Js(i);i.i<e.length;){if(/[;\n\r\f\v \t]/u.test(e[i.i])){i.i++;continue}e[i.i]==="#"&&ve("comments");let s=zp(i),u=null;if(s&&e[i.i]===","&&(i.i++,u=zp(i,!0),u===null))throw new Error("missing second address");e[i.i]==="~"&&ve("step address");let a=s?.type==="line"&&s.value===0;if(a&&u?.type!=="regex")throw new Error("line numbers must be >= 1");let l=!1;if(e[i.i]==="!"){for(l=!0,i.i++;/[ \t]/u.test(e[i.i]??"");)i.i++;if(e[i.i]==="!")throw new Error("multiple '!'s")}let f=e[i.i++],c={kind:f,start:s,end:u,active:a,negated:l};if(f&&"pPnNdD=gGhHx".includes(f))o.push(c);else if(f==="w"){o.push({...c,...Gs(i)});continue}else if(f===":"||f==="b"||f==="t"||f==="T"){o.push({...c,label:g2(i,c)});continue}else if(f==="s")o.push({...c,...Mp(i)});else if(f==="a"||f==="i"||f==="c")qp(i,c),o.push(c);else if(f==="y")o.push({...c,...Wp(i)});else if(f==="q"){if(u!==null)throw new Error("command only uses one address");let d=/^[ \t]*(\d*)/u.exec(e.slice(i.i));i.i+=d[0].length;let p=BigInt.asIntN(32,BigInt(d[1]||"0"));o.push({...c,exitCode:p===-1n?0:Number(BigInt.asUintN(8,p))})}else if(f==="{"){i.textState.blockDepth=(i.textState.blockDepth??0)+1,o.push(c);continue}else if(f==="}"){if(!i.textState.blockDepth)throw new Error("unexpected '}'");if(s!==null)throw new Error("'}' doesn't want any addresses");i.textState.blockDepth--,o.push(c)}else{if(f===void 0)throw new Error("missing command");if("QlLFzrRWev".includes(f))ve();else throw new Error(`unknown command: '${f}'`)}for(;/[ \t]/u.test(e[i.i]??"");)i.i++;if(e[i.i]==="#"&&ve("comments"),i.i<e.length&&!/[;\n}]/u.test(e[i.i]))throw new Error("extra characters after command")}return r===null&&Qs(i.textState),o}function tu(e,t){let n=[];for(let r=0;r<e.length;r++){let i=e[r];if(i.kind==="{"&&n.push(i),i.kind==="}"){if(n.length===0)throw new Error("unexpected '}'");n.pop().jump=r}}if(n.length)throw new Error("unmatched '{'");return Qs(t),w2(e),e}function g2(e,t){if(t.kind===":"&&t.start!==null)throw new Error("':' doesn't want any addresses");let n=/^[ \t]*([^ \t\n;}#]*)/u.exec(e.script.slice(e.i));e.i+=n[0].length;let r=n[1].split("\0",1)[0];if(t.kind===":"&&r==="")throw new Error("':' lacks a label");return r}function w2(e){let t=new Map;for(let n=0;n<e.length;n++)e[n].kind===":"&&t.set(e[n].label,n);for(let n=e.length-1;n>=0;n--){let r=e[n];if(!["b","t","T"].includes(r.kind))continue;let i=r.label===""?e.length:t.get(r.label);if(i===void 0)throw Object.assign(new Error(`can't find label for jump to \`${r.label}'`),{exitCode:4});r.jump=i}}function zp(e,t=!1){for(;/[ \t]/u.test(e.script[e.i]??"");)e.i++;e.script[e.i]==="~"&&ve("step address");let n=/^(\d+|\+[ \t]*\d+)/u.exec(e.script.slice(e.i)),r=null;if(n){let i=n[0][0]==="+";if(i&&!t)throw new Error("relative address requires a range");let o=Number(n[0].replace(/[ \t]/gu,""));Number.isSafeInteger(o)||ve("address limit"),e.i+=n[0].length,r={type:i?"offset":"line",value:o}}else if(e.script[e.i]==="$")e.i++,r={type:"last"};else if(e.script[e.i]==="/"||e.script[e.i]==="\\"){e.script[e.i]==="\\"&&e.i++;let i=or(e,"address regex"),o=Ei(e,i,!0,"address regex"),s=!1;for(;;){for(;/[ \t]/u.test(e.script[e.i]??"");)e.i++;let u=e.script[e.i];if(u!=="I"&&u!=="M")break;if(o==="")throw new Error("cannot specify modifiers on empty regexp");u==="M"&&ve("address regex flags"),s=!0,e.i++}r={type:"regex",...Xs(o,e.extended,!0,s,e.locale)}}for(;/[ \t]/u.test(e.script[e.i]??"");)e.i++;return r}function Hp(e,t,n,r,i){let{start:o,end:s}=e;if(o===null)return!0;if(s===null)return Ni(o,t,n,r,i);if(!e.active){if(o.type==="line"){if(e.closed||n<o.value)return!1}else if(!Ni(o,t,n,r,i))return!1;if(e.active=!0,s.type==="regex")return!0;if(s.type==="offset"&&(e.until=n+s.value),s.type==="line")return e.active=n<s.value,e.closed=!e.active,n<=s.value||Ni(o,t,n,r,i)}return s.type==="line"?(e.active=n<s.value,e.closed=!e.active,n<=s.value):((s.type==="offset"?n>=e.until:Ni(s,t,n,r,i))&&(e.active=!1,e.closed=!0),!0)}function Ni(e,t,n,r,i){if(e.type==="line")return n===e.value;if(e.type==="last")return typeof r=="function"?r():r;let o=Ys(e,i);return Zs(t,o),o.re.search(t)!==null}function nu(e,t,n,r=!1){let{output:i,delimiter:o}=e,s=t.has("n")||t.has("quiet")||t.has("silent"),u=t.has("s")||t.has("separate"),a=Rp(e.files,e.stdin,n,o,u,p=>i.stream(2,p)),l=i.start(a),f=[],c=Hs(r?p=>{i.account(p),f.push(p)}:p=>i.stream(1,p),o),d={delimiter:o,quiet:s,separate:u,hold:e.hold,regexState:e.regexState,budget:e.budget,emit:c,input:a,output:i};try{let p=b2(e.commands,d);l.quit=p!==null,l.exitCode=a.status.failed?a.status.directory?4:2:p??0,l.failed=a.status.failed}catch(p){let h=vi(p);_(l,h);let m=O(h);m&&re(l,m.kind,m.command,m.detail,m.message),l.failed=!0}finally{i.finish()}return r&&(l.content=f.join("")),l}function b2(e,t){let n=!0;for(let r=t.input.next();r;r=t.input.next()){if(n||t.separate&&r.reset){t.hold.text="";for(let s of e)s.active=s.start?.type==="line"&&s.start.value===0,s.closed=!1;n=!1}t.output.record(r);let i={...r,...t,append:[],exitCode:null,replaced:!1},o=y2(e,i);if(!t.quiet&&!o&&t.emit(i.text,i.terminator),i.exitCode!==null&&t.emit(""),Gp(i),i.exitCode!==null)return i.exitCode;t.output.record(null)}return null}function y2(e,t){for(let n=0;n<e.length;n++){if(++t.budget.steps>js)throw new w("feature","execution limit",`sed: execution limit reached after ${js} commands (infinite loop?)`);let r=e[n];if(r.kind==="}"||r.kind===":")continue;if(Hp(r,t.text,t.line,t.last,t.regexState)===!!r.negated){r.kind==="{"&&(n=r.jump);continue}let o=r.kind;if(o!=="{"){if(o==="b"||o==="t"||o==="T"){let s=o==="b"||(o==="t"?t.replaced:!t.replaced);o!=="b"&&(t.replaced=!1),s&&(n=r.jump-1);continue}if(o==="q"){t.exitCode=r.exitCode;break}if(o==="d")return!0;if(o==="D"){let s=t.text.indexOf(t.delimiter);if(s<0)return!0;t.text=t.text.slice(s+t.delimiter.length),n=-1;continue}if(o==="n"||o==="N"){if(!v2(t,o==="N"))return!0;continue}if(o==="c")return!r.active&&r.text!==null&&t.emit(r.text.slice(0,-1),t.delimiter),!0;if(x2(r,t),t.text.length>ki)throw new w("feature","pattern space limit","sed: pattern space limit exceeded")}}return!1}function x2(e,t){let{kind:n}=e;if(n==="a"){t.append.push(e.text);return}if(n==="i")e.text!==null&&t.emit(e.text.slice(0,-1),t.delimiter);else if(n==="p")t.emit(t.text,t.terminator);else if(n==="P"){let r=t.text.indexOf(t.delimiter);t.emit(r<0?t.text:t.text.slice(0,r),r<0?t.terminator:t.delimiter)}else if(n==="=")t.emit(String(t.line),t.delimiter);else if(n==="w")e.writer(t.text,t.terminator);else if("gGhHx".includes(n))k2(n,t);else if(n==="y")t.text=jp(t.text,e);else{let r=Vs(t.text,e,t.regexState);if(t.text=r.out,!r.count)return;t.replaced=!0,e.print&&t.emit(t.text,t.terminator),e.writer&&e.writer(t.text,t.terminator)}}function k2(e,t){let n=t.hold;if(e==="x"){let{text:r,terminator:i}=t;Object.assign(t,n),Object.assign(n,{text:r,terminator:i})}else{let r=e==="h"||e==="H"?t:n,i=r===n?t:n;i.text=e==="G"||e==="H"?i.text+t.delimiter+r.text:r.text,i.terminator=r.terminator}if(n.text.length>ki)throw new w("feature","hold space limit","sed: hold space limit exceeded")}function v2(e,t){if(!t&&!e.quiet&&e.emit(e.text,e.terminator),e.last())return t&&!e.quiet&&e.emit(e.text,e.terminator),!1;Gp(e);let n=e.input.next();if(!n)return t&&!e.quiet&&e.emit(e.text,e.delimiter),!1;let r=t?e.text+e.delimiter+n.text:n.text;if(r.length>ki)throw new w("feature","pattern space limit","sed: pattern space limit exceeded");return Object.assign(e,n,{text:r,replaced:!1}),e.output.record(n),!0}function Gp(e){if(e.append.length!==0){e.emit("");for(let t of e.append)e.emit(t??"");e.append.length=0}}function Xp(e,t,n){try{let{tokens:r,inPlace:i}=Tp(t),o=N(r,{short:["n","E","r","s","z"],long:["regexp-extended","quiet","silent","separate","null-data","zero-terminated"],repeatable:["e","expression","f","file"]}),s=o.flags.has("z")||o.flags.has("null-data")||o.flags.has("zero-terminated")?"\0":`
|
|
217
|
+
`,u=Lp(n,s),a=S2(o,e,n,u.openWrite);return a===null?y(xi):a.error?a.error:(Object.assign(a,{output:u,delimiter:s,hold:{text:"",terminator:s},regexState:{last:null},budget:{steps:0}}),a.stdin=ir(a.stdin,n),i===null?nu(a,o.flags,n):_p(a,o.flags,n,i,(l,f)=>nu(l,f,n,!0)))}catch(r){return vi(r)}}function S2({order:e,positional:t},n,r,i){let o=[],s={openWrite:i},u=!1,a=!1;for(let{name:l,value:f}of e){if((l==="E"||l==="r"||l==="regexp-extended")&&(u=!0),!["e","expression","f","file"].includes(l))continue;a=!0;let c=f;if(l==="f"||l==="file"){n=ir(n,r);let d=n,p=r.io.bufferReads(()=>rt("sed",[f],r,d));if(p.failed)return{error:y(p.stderr,4)};c=p.inputs[0].content,p.inputs[0].shared&&(n="")}for(let d of eu(c,u,r.locale,s))o.push(d)}return a?{commands:tu(o,s),files:t,stdin:n}:t.length===0?null:{commands:tu(eu(t[0],u,r.locale,s),s),files:t.slice(1),stdin:n}}var $2=new Set(["-b","-c","-g","-k","-p","-r","-s","-t","-u","-v","-w","-x","-G","-N","-O","-R","-S","-o"]),E2=new Set(["-nt","-ot","-ef","<",">"]),ur={__proto__:null,"-eq":(e,t)=>e===t,"-ne":(e,t)=>e!==t,"-lt":(e,t)=>e<t,"-le":(e,t)=>e<=t,"-gt":(e,t)=>e>t,"-ge":(e,t)=>e>=t},N2=String(oe).length,A2=new Set(["/dev/stdin","/dev/stdout","/dev/stderr"]);function Vp(e,t,n){return Jp("test",t,n)}function Kp(e,t,n){return t.at(-1)!=="]"?y("[: missing `]'",2):Jp("[",t.slice(0,-1),n)}function Jp(e,t,n){try{return{...C(),exitCode:ru(t,n)?0:1}}catch(r){return Y(r,e,`${e}: ${r.message}`,2)}}function ru(e,t){let[n,r,i]=e;if(e.length===0)return!1;if(e.length===1)return n!=="";if(e.length===2){if(n==="!")return r==="";if(n==="-n")return r!=="";if(n==="-z")return r==="";if(["-a","-e","-f","-d","-h","-L"].includes(n))return iu(n,r,t);throw $2.has(n)&&sr(n),new Error(`${n}: unary operator expected`)}if(e.length===3){if(r==="="||r==="==")return n===i;if(r==="!=")return n!==i;if(Object.hasOwn(ur,r))return ur[r](Zp(n),Zp(i));E2.has(r)&&sr(r),(r==="-a"||r==="-o")&&sr("compound expressions")}if(e.length<=4){if(n==="!")return!ru(e.slice(1),t);if(n==="("&&e.at(-1)===")")return ru(e.slice(1,-1),t)}throw e.some(o=>["-a","-o","!","(",")"].includes(o))&&sr("compound expressions"),new Error(e.length>3?"too many arguments":`${r}: binary operator expected`)}function Zp(e){let t=/^[ \t\n\r\f\v]*([+-]?)(\d+)[ \t]*$/u.exec(e);if(t&&t[0].length===e.length){let n=t[2].replace(/^0+/u,"")||"0";if(n.length<=N2){let r=BigInt(t[1]+n);if(r>=tt&&r<=oe)return r}}throw new Error(`${e}: integer expression expected`)}function iu(e,t,n){let r={isDir:u=>u==="/dev"||u==="/dev/fd"||n.fs.isDir(u),isFile:u=>u==="/dev/null"||Yp(u)||n.fs.isFile(u),isLink:u=>n.fs.isLink?.(u)===!0,readLink:u=>n.fs.readLink?.(u)},i=e==="-h"||e==="-L",{path:o,error:s}=v(n.cwd,t,r,{follow:!i});return s?!1:(Yp(o)&&sr("stream device metadata"),i?r.isLink(o):e==="-e"||e==="-a"?!0:e==="-d"?r.isDir(o):o!=="/dev/null"&&n.fs.isFile(o))}function Yp(e){return A2.has(e)||/^\/dev\/fd\/\d+$/u.test(e)}function sr(e){throw new w("feature",e,`${e} is not supported`)}function t1(e){let t=e.replace(/^[ \t\n\r\v\f]+|[ \t\n\r\v\f]+$/gu,""),n=/^[+-]?\d+$/u.test(t)?BigInt(t):null,r=n!==null&&n>=tt&&n<=oe?n:null;return{arg:t,n:r}}var fn=e=>({...e,halt:!0});function O2(e,t,n){let r=t[0]==="--"?t.slice(1):t;if(r.length===0)return fn({...C(),exitCode:n.lastExit});let{arg:i,n:o}=t1(r[0]);return o===null?fn(y(`exit: ${i}: numeric argument required`,2)):r.length>1?fn(y("exit: too many arguments")):fn({...C(),exitCode:Number((o%256n+256n)%256n)})}function Qp(e){return(t,n,r)=>{let i=n[0]==="--"?n.slice(1):n;if(i.length>1)return fn(y(`${e}: too many arguments`));let{arg:o,n:s}=t1(i[0]??"1");return s===null?fn(y(`${e}: ${o}: numeric argument required`,128)):s<=0?{...y(`${e}: ${o}: loop count out of range`),control:r.loopDepth?{type:"break",levels:r.loopDepth}:void 0}:r.loopDepth===0?y(`${e}: only meaningful in a \`for\`, \`while\` or \`until\` loop`,0):{...C(),control:{type:e,levels:Number(s>BigInt(r.loopDepth)?BigInt(r.loopDepth):s)}}}}function I2(e,t,n){let r=t[0]==="--",i=r?t.slice(1):t;if(i.length===0||!r&&i[0]==="-p")return k("option","export","-p","export: listing the environment is not supported (there is none)");let o="";for(let s of i){let u=s.indexOf("="),a=u>0&&s[u-1]==="+",l=u===-1?s:s.slice(0,a?u-1:u);if(!r&&s.startsWith("-"))return k("option","export",s,`export: option \`${s}\` is not supported`);if(!Ft.test(l)){o+=`export: \`${l}': not a valid identifier
|
|
218
|
+
`;continue}u!==-1?n.vars.set(l,(a?Bc(l,n):"")+s.slice(u+1)):n.vars.has(l)&&n.vars.set(l,n.vars.get(l))}return{stdout:"",stderr:o,exitCode:o?1:0}}function C2(e,t,n){let r=t[0]==="-v"?1:0,i=t[r]==="--";i&&r++;let o=t.slice(r);for(let s of o){if(!i&&s.startsWith("-"))return k("option","unset",s,`unset: option \`${s}\` is not supported`);if(s.includes("["))return k("feature","unset","array subscript","unset: array subscripts are not supported");if(s==="LANG")return k("feature","unset","LANG",`unset: LANG: ${Ir}`);n.vars.delete(s)}return C()}function F2(e,t,n){let r=null;for(let i=0;i<t.length;i++){let o=t[i];if(o==="-e"||o==="+e")r=o==="-e";else if((o==="-o"||o==="+o")&&t[i+1]==="errexit")r=o==="-o",i++;else return e1()}return r===null?e1():(n.errexit=r,C())}var e1=()=>k("feature","set","set","set: `set` is supported only as `set -e` or `set +e`",127),ou={exit:O2,break:Qp("break"),continue:Qp("continue"),export:I2,set:F2,unset:C2},n1=new Map([["return"," (there are no shell functions)"],["source"," (nothing can be sourced into this shell)"],[".","","`.` (source)"],"eval","exec",["read"," (there is no interactive input)"],["shift"," (there are no positional parameters)"],"shopt",["local"," (there are no shell functions)"],["declare","; use `NAME=value`"],["typeset","; use `NAME=value`"],["readonly","; use `NAME=value`"],["let"," (no arithmetic)"],["type","; use `which`"],["command","; run the command directly"],"builtin","hash","alias","unalias","trap",["wait"," (nothing runs in the background)"],["kill"," (there are no processes)"],["jobs"," (there are no processes)"],["bg"," (there are no processes)"],["fg"," (there are no processes)"],["disown"," (there are no processes)"],"suspend","times","ulimit","umask",["pushd","; use `cd`"],["popd","; use `cd -`"],"dirs","history","help","logout","getopts","mapfile","readarray","caller","enable","compgen","complete","bind","fc"].map(e=>{let[t,n="",r="`"+t+"`"]=Array.isArray(e)?e:[e];return[t,r+" is not supported"+n]}));function r1(e,t){let n=0,r=!0,i=!1;for(;n<t.length&&/^-[neE]+$/u.test(t[n]);n++)for(let s of t[n].slice(1))s==="n"?r=!1:i=s==="e";let o=t.slice(n).join(" ");if(i){let s=T2(o);o=s.text,s.stop&&(r=!1)}return C(r?o+`
|
|
219
|
+
`:o)}function T2(e){let t={a:7,b:8,e:27,E:27,f:12,n:10,r:13,t:9,v:11,"\\":92},n=[],r=o=>{for(let s of A(o))n.push(s)},i=o=>({text:P(Uint8Array.from(n)),stop:o});for(let o=0;o<e.length;o++){if(e[o]!=="\\"||o+1>=e.length){let l=e.indexOf("\\",o+1),f=l<0?e.length:l;r(e.slice(o,f)),o=f-1;continue}let s=e[++o];if(s==="c")return i(!0);if(s in t){n.push(t[s]);continue}if(s==="0"){let l="";for(;l.length<3&&/[0-7]/u.test(e[o+1]??"");)l+=e[++o];n.push(l===""?0:parseInt(l,8)&255);continue}let u=s==="x"?2:s==="u"?4:s==="U"?8:0;if(u>0&&/[0-9a-fA-F]/u.test(e[o+1]??"")){let l="";for(;l.length<u&&/[0-9a-fA-F]/u.test(e[o+1]??"");)l+=e[++o];let f=parseInt(l,16);if(s==="x")n.push(f);else{if(!Xe(f))throw new w("feature","echo Unicode escape","echo: escapes outside Unicode scalar values are not supported");r(String.fromCodePoint(f))}continue}let a=o+Ie(e,o);r("\\"+e.slice(o,a)),o=a-1}return i(!1)}var i1={a:7,b:8,e:27,E:27,f:12,n:10,r:13,t:9,v:11,"\\":92};function su(e,t,n,r){let i=e[t+1],o=t+2;if(i===void 0)return{bytes:[92],end:t+1};if(n&&i==="c")return{bytes:[],end:o,stop:!0};if(Object.hasOwn(i1,i))return{bytes:[i1[i]],end:o};if(!n&&`'"?`.includes(i))return{bytes:[i.codePointAt(0)],end:o};if(/[0-7]/u.test(i)){let u=n&&i==="0"?4:3;for(;o<t+1+u&&/[0-7]/u.test(e[o]??"");)o++;return{bytes:[parseInt(e.slice(t+1,o),8)&255],end:o}}let s=i==="x"?2:i==="u"?4:i==="U"?8:0;if(s){for(;o<t+2+s&&/[\da-fA-F]/u.test(e[o]??"");)o++;if(o===t+2||i!=="x"&&o!==t+2+s)return r.stderr+=`printf: missing hexadecimal number in escape
|
|
220
|
+
`,r.failed=!0,r.stop=!0,{bytes:[],end:e.length,stop:!0};let u=parseInt(e.slice(t+2,o),16);if(i==="x")return{bytes:[u],end:o};if(!Xe(u))throw new w("feature","Unicode escape","escapes outside Unicode scalar values are not supported");if(r.byteLocale&&u>127)throw new w("feature","Unicode escape in C locale","non-ASCII Unicode escapes in the C locale are not supported");return{bytes:A(String.fromCodePoint(u)),end:o}}return o=t+1+Ie(e,t+1),{bytes:A(e.slice(t,o)),end:o}}function o1(e,t){let n=[];for(let r=0;r<e.length;)if(e[r]==="\\"){let i=su(e,r,!0,t);for(let o of i.bytes)n.push(o);if(r=i.end,i.stop){t.stop=!0;break}}else{let i=e.indexOf("\\",r),o=i<0?e.length:i;for(let s of A(e.slice(r,o)))n.push(s);r=o}return Uint8Array.from(n)}var L2=/^%([-+ #0']*)(\d+|\*)?(?:\.(-?\d+|\*)?)?([hlLjzt]*)(.)?/su,R2=8e6;function s1(e,t,n){let r=t[0]==="--"?t.slice(1):t;if(r.length===0)return de("printf format [arguments]");if(t[0]!=="--"&&/^-./su.test(t[0])){let s=t[0].startsWith("-v")?"-v":t[0];return k("option","printf",s,`printf: option ${s} is not supported`,2)}let i={args:r.slice(1),index:0,chunks:[],size:0,stderr:"",failed:!1,stop:!1,byteLocale:ae(n)},o;try{if(r.some(s=>s.includes("\0")))throw new w("feature","NUL in argument","NUL bytes in command arguments are not supported");do{let s=i.index;if(P2(r[0],i),i.index===s)break}while(!i.stop&&i.index<i.args.length);o=C()}catch(s){o=Y(s,"printf",`printf: ${s.message}`)}try{o.stdout=M2(i)}catch(s){let u=O(o);u&&n.unsupported.add(u,"printf");let a=Y(s,"printf",`printf: ${s.message}`);a.stderr=o.stderr+a.stderr,o=a}return o.stderr=i.stderr+o.stderr,i.failed&&o.exitCode===0&&(o.exitCode=1),o}function qt(e,t){if(e.size+t.length>R2)throw new w("feature","format size limit","formatted output exceeds the output limit");t.length&&e.chunks.push(t),e.size+=t.length}function M2(e){let t=new Uint8Array(e.size),n=0;for(let r of e.chunks)t.set(r,n),n+=r.length;return P(t)}var uu=e=>e.args[e.index++];function P2(e,t){for(let n=0;n<e.length&&!t.stop;)if(e[n]==="\\"){let r=su(e,n,!1,t);qt(t,r.bytes),n=r.end}else if(e[n]==="%"){if(e[n+1]==="%"){qt(t,[37]),n+=2;continue}let r=D2(e.slice(n),t);n+=r.length;let i=uu(t);if("sbc".includes(r.conv))U2(i??"",r,t);else{let o="diouxX".includes(r.conv)?ai(ui(i,"ouxX".includes(r.conv),t),r):hd(i,r,t);qt(t,A(o))}}else{let r=n+1;for(;r<e.length&&e[r]!=="%"&&e[r]!=="\\";)r++;qt(t,A(e.slice(n,r))),n=r}}function D2(e,t){if(/^%[-+ #0'\d.*]*\$/u.test(e))throw new w("feature","positional format arguments","positional format arguments are not supported");let n=L2.exec(e),[,r,i,o,s,u]=n;if(u===void 0)throw new Error("missing format character");if(!"sbcdiouxXeEfFgG".includes(u))throw"aAqQnCS(p%I".includes(u)?new w("feature","%"+u,`format %${u} is not supported`):new Error(`invalid format character: ${u}`);if(s&&"sbc".includes(u))throw new w("feature","format length modifier","length modifiers on string and character formats are not supported");let a={conv:u,length:n[0].length,minus:r.includes("-"),plus:r.includes("+"),space:r.includes(" "),zero:r.includes("0"),alt:r.includes("#"),width:Number(i==="*"?ui(uu(t),!1,t):i??0),precision:o==="*"?Number(ui(uu(t),!1,t)):o===void 0?n[0].includes(".")?0:null:Number(o)};if(i==="*"&&Math.abs(a.width)>2147483647||o==="*"&&(a.precision<-2147483648||a.precision>2147483647))throw new w("feature","format size limit","star width or precision outside the signed 32-bit range is not supported");if(a.width<0&&(a.minus=!0,a.width=-a.width),a.precision<0&&(a.precision=null),a.width>Ee||a.precision>Ee)throw new w("feature","format size limit","format width or precision exceeds the output limit");return a}function U2(e,t,n){let r=t.conv==="b"?o1(e,n):A(e);t.conv==="c"?r=r.length?r.subarray(0,1):new Uint8Array(1):t.precision!==null&&(r=r.subarray(0,t.precision));let i=Math.max(0,t.width-r.length),o=i?new Uint8Array(i).fill(32):[];t.minus||qt(n,o),qt(n,r),t.minus&&qt(n,o)}function B2(e,t){if(!e.includes(`
|
|
221
|
+
`))return e;let n=ae(t);if(!n&&/[\u0080-\u009F\u2028\u2029]/u.test(e))throw new w("feature","filename quoting","wc: locale-sensitive filename quoting is not supported");let r=n?Array.from(A(e),u=>String.fromCodePoint(u)):[...e],i={7:"\\a",8:"\\b",9:"\\t",10:"\\n",11:"\\v",12:"\\f",13:"\\r"},o=!1,s="'";for(let u of r){let a=u.codePointAt(0);a<32||a===127||n&&a>127?(o||(s+="'$'"),s+=i[a]??"\\"+a.toString(8).padStart(3,"0"),o=!0):(u==="'"?s+="'\\''":s+=(o?"''":"")+u,o=!1)}return s+"'"}function u1(e,t,n,r,i){let o=[];for(let s of["l","w","m","c"])n[s]&&o.push(String(e[s]).padStart(r));return o.join(" ")+(t?" "+B2(t,i):"")}var q2=["**=","**","++","--","+=","-=","*=","/=","%=","^=","==","!=","<=",">=","&&","||","!~",">>","|&","+","-","*","/","%","^","!",">","<","|","?",":","~","$","=","(",")","{","}","[","]",";",","],W2=new Set(["number","string","name","builtin"]),j2=new Set([")","]","++","--"]),z2=/^(?:0[xX][0-9a-fA-F]+|\d+\.?\d*(?:[eE][+-]?\d+)?|\.\d+(?:[eE][+-]?\d+)?)/u,H2=e=>e!==void 0&&/[A-Za-z_]/u.test(e),G2=e=>e!==void 0&&/[A-Za-z0-9_]/u.test(e),a1=e=>e!==void 0&&e>="0"&&e<="9";function c1(e,t=null){let n=[],r=1,i=0,o=(u,a)=>n.push({type:u,value:a,line:r}),s=()=>{let u=n.at(-1);return u?W2.has(u.type)?!1:!(u.type==="punct"&&j2.has(u.value)):!0};for(;i<e.length;){let u=e[i];if(u===`
|
|
211
222
|
`){n.at(-1)?.type!=="newline"&&o("newline",`
|
|
212
223
|
`),r++,i++;continue}if(u===" "||u===" "||u==="\r"){i++;continue}if(u==="\\"&&(e[i+1]===`
|
|
213
224
|
`||e[i+1]==="\r"&&e[i+2]===`
|
|
214
225
|
`)){i+=e[i+1]===`
|
|
215
226
|
`?2:3,r++;continue}if(u==="#"){for(;i<e.length&&e[i]!==`
|
|
216
|
-
`;)i++;continue}if(u==='"'){let
|
|
217
|
-
`,t:" ",r:"\r",a:"\x07",b:"\b",f:"\f",v:"\v",'"':'"',"\\":"\\"};function
|
|
227
|
+
`;)i++;continue}if(u==='"'){let f=d1(e,i+1,t,r);o("string",f.value),i=f.end;continue}if(u==="/"&&s()){let f=Y2(e,i+1,r);o("regex",f.value),i=f.end;continue}if(a1(u)||u==="."&&a1(e[i+1])){let f=X2(e,i);o("number",f.value),i=f.end;continue}if(H2(u)){let f=i+1;for(;G2(e[f]);)f++;let c=e.slice(i,f);if(e.slice(f,f+2)==="::")throw new $("namespaces are not supported",r,"namespaces");i=f,nf.has(c)?o("keyword",c==="func"?"function":c):rf.has(c)?o("builtin",c):o(e[f]==="("?"funcname":"name",c);continue}let a=i,l=q2.find(f=>e.startsWith(f,a));if(u==="@")throw new $("typed regexes, indirect calls and source directives are not supported",r,"@ extensions");if(!l)throw new $(`unexpected character \`${u}\``,r);o("punct",l),i+=l.length}return o("eof",""),n}function X2(e,t){let n=z2.exec(e.slice(t))[0],r=n;return/^0[xX]/u.test(n)?r=String(Number.parseInt(n.slice(2),16)):/^0[0-7]+$/u.test(n)&&(r=String(Number.parseInt(n,8))),{value:r,end:t+n.length}}var l1={__proto__:null,n:`
|
|
228
|
+
`,t:" ",r:"\r",a:"\x07",b:"\b",f:"\f",v:"\v",'"':'"',"\\":"\\"};function Z2(e,t,n){let r=e[t+1];if(r===void 0)return{text:"\\",end:t+1};if(r in l1)return{text:l1[r],end:t+2};if(r>="0"&&r<="7"){let i=t+1;for(;i<t+4&&e[i]>="0"&&e[i]<="7";)i++;return{byte:Number.parseInt(e.slice(t+1,i),8)&255,end:i}}if(r==="x"&&/[0-9a-fA-F]/u.test(e[t+2]??"")){let i=t+2;for(;i<t+4&&/[0-9a-fA-F]/u.test(e[i]??"");)i++;return{byte:Number.parseInt(e.slice(t+2,i),16),end:i}}if(r.codePointAt(0)>127)throw new $("non-ASCII characters after an escape are not supported",null,"non-ASCII string escape");return n?.(`escape sequence \`\\${r}' treated as plain \`${r}'`),{text:r,end:t+2}}function d1(e,t,n,r=null){let i=[],o=t;for(;o<e.length;){let s=e[o];if(r!==null){if(s==='"')return{value:P(Uint8Array.from(i)),end:o+1};if(s===`
|
|
218
229
|
`)break;if(s==="\\"&&e[o+1]===`
|
|
219
|
-
`){o+=2;continue}}if(s==="\\"){let u=
|
|
220
|
-
`)break;if(o==="\\"){r+=2;continue}if(i){if(o==="["&&e[r+1]===":"){let s=e.indexOf(":]",r+2);if(s!==-1){r=s+2;continue}}o==="]"&&(i=!1),r++;continue}if(o==="["){i=!0,r++,e[r]==="^"&&r++,e[r]==="]"&&r++;continue}if(o==="/")return{value:e.slice(t,r),end:r+1};r++}throw new k("unterminated regexp",n)}function Qn(e,t=null){return up(e,0,t).value}function op(e,t){if(t.byte===void 0)for(let n of I(t.text))e.push(n);else e.push(t.byte)}var n1=new Set(["=","+=","-=","*=","/=","%=","^=","**="]),ap=new Set(["<","<=","==","!=",">",">="]),tr=e=>e.type==="var"||e.type==="index"||e.type==="field";function lp(e){let t=e.tok;return fp(e)||t.type==="regex"||t.type==="keyword"&&t.value==="getline"||t.type==="punct"&&["!","-","+"].includes(t.value)}function sn(e,t){let n=[we(e,t)];for(;e.accept(",");)e.skipNewlines(),n.push(we(e,t));return n}function we(e,t){let n=r1(e,t),r=e.tok;if(r.type==="punct"&&n1.has(r.value)){tr(n)||e.fail(`cannot assign to ${n.type==="regex"?"a regex":"a non-variable"} (left side of \`${r.value}\`)`),e.next();let i=we(e,t);return{type:"assign",op:r.value==="**="?"^=":r.value,target:n,value:i}}return n}function r1(e,t){let n=Ps(e,t);if(!e.accept("?"))return n;e.skipNewlines();let r=we(e,t);return e.skipNewlines(),e.expect(":"),e.skipNewlines(),{type:"cond",test:n,consequent:r,alternate:we(e,t)}}var i1=[["or",["||"]],["and",["&&"]],["in",["in"]],["match",["~","!~"]],["compare",[...ap]],["concat",[]],["binary",["+","-"]],["binary",["*","/","%"]]],o1=new Map(i1.flatMap(([e,t],n)=>t.map(r=>[r,{type:e,precedence:n}]))),s1={type:"concat",precedence:5};function Ps(e,t,n=0){let r=ci(e,t),i=1/0;for(;;){let o=e.tok;n<=4&&i>4&&!t.noGt&&(e.is("|")||e.is("|&"))&&e.fail(`command pipelines (\`"cmd" | getline\`) are not supported: ${Ar}`,'"cmd" | getline');let s=fp(e)?s1:o.type==="punct"||o.type==="keyword"&&o.value==="in"?o1.get(o.value):void 0;if(!s||s.precedence<n||s.precedence>i||t.noGt&&e.is(">"))return r;let{type:u,precedence:a}=s,l=u==="concat"?null:e.next().value;if(i=a,(u==="or"||u==="and")&&e.skipNewlines(),u==="in"){r={type:u,keys:[r],array:cp(e)};continue}let c=Ps(e,t,a+1);(l==="/"||l==="%")&&er(c)===0&&er(r)!==null&&e.fail(l==="/"?"division by zero attempted":"division by zero attempted in `%`"),u==="compare"&&u1(e,t)&&e.fail(`comparison operators do not chain (\`a ${l} b ${e.tok.value} c\`); parenthesize the first comparison`),u==="binary"||u==="compare"?r={type:u,op:l,left:r,right:c}:u==="match"?r={type:u,negate:l==="!~",left:r,right:c}:r={type:u,left:r,right:c}}}function cp(e){return e.tok.type!=="name"&&e.fail(`expected an array name after \`in\` but found \`${e.tok.value}\``),e.next().value}var u1=(e,t)=>e.tok.type==="punct"&&ap.has(e.tok.value)&&!(t.noGt&&e.tok.value===">");function fp(e){let t=e.tok;return t.type==="number"||t.type==="string"||t.type==="name"||t.type==="funcname"||t.type==="builtin"?!0:t.type==="punct"&&["$","(","++","--"].includes(t.value)}function dp(e,t){return Ps(e,t,5)}function er(e){if(e.type==="num")return e.value;if(e.type==="neg"||e.type==="plus"){let r=er(e.expr);return r===null?null:e.type==="neg"?-r:r}if(e.type!=="binary")return null;let t=er(e.left),n=er(e.right);return t===null||n===null?null:Ir(e.op,t,n)}var a1={__proto__:null,"!":"not","-":"neg","+":"plus"};function ci(e,t,n=!1){if(n&&(e.is("$")||e.is("++")||e.is("--")))return fi(e,t);let r=e.tok.type==="punct"&&a1[e.tok.value];return r?(e.next(),{type:r,expr:ci(e,t,n)}):n?hp(e,t):l1(e,t)}function l1(e,t){let n=pp(e,t);return!e.is("^")&&!e.is("**")?n:(e.next(),{type:"binary",op:"^",left:n,right:ci(e,t)})}function pp(e,t){let n=fi(e,t);for(;(e.is("++")||e.is("--"))&&tr(n);)n={type:"postinc",op:e.next().value,target:n};return n}function fi(e,t){if(e.accept("$"))return{type:"field",index:ci(e,t,!0)};if(e.is("++")||e.is("--")){let n=e.next().value,r=fi(e,t);return tr(r)||e.fail(`\`${n}\` needs a variable, field or array element`),{type:"preinc",op:n,target:r}}return hp(e,t)}function hp(e,t){let n=e.tok;switch(n.type){case"number":return e.next(),{type:"num",value:Number(n.value)};case"string":return e.next(),{type:"str",value:n.value};case"regex":return e.next(),{type:"regex",source:n.value,re:c1(e,n.value)};case"name":return f1(e);case"funcname":return d1(e);case"builtin":return h1(e);case"keyword":return n.value==="getline"?m1(e,t):e.unexpected();case"punct":return n.value==="("?p1(e):e.unexpected();default:return e.unexpected()}}function c1(e,t){try{return Ee(t,!1,n=>e.warn(n))}catch(n){return e.fail(n.message,n.gap??null)}}function Ds(e){if(!e.accept("["))return null;let t=sn(e,{});return e.expect("]"),e.is("[")&&e.fail("arrays of arrays are not supported","arrays of arrays"),t}function f1(e){let t=e.next().value,n=Ds(e);return n!==null?{type:"index",name:t,subs:n}:(e.is("(")&&e.funcs.has(t)&&e.fail(`function \`${t}\` called with space between name and \`(\``),{type:"var",name:t})}function d1(e){return{type:"call",name:e.next().value,args:mp(e)}}function mp(e){e.expect("(");let t=e.is(")")?[]:sn(e,{});return e.expect(")"),t}function p1(e){let t=0;for(;e.parens.get(e.i+1)===e.parens.get(e.i)-1;)e.next(),t++;e.next();let n=sn(e,{});if(e.expect(")"),n.length===1){for(;t-- >0;)e.expect(")");return n[0]}return e.isKw("in")||e.fail("a parenthesized list must be followed by `in ARRAY`"),e.next(),{type:"in",keys:n,array:cp(e)}}function h1(e){let t=e.next().value;if(Nr.has(t)&&e.fail(Nr.get(t),`${t}()`),!e.is("(")){if(t==="length")return{type:"builtin",name:t,args:[]};e.fail(`\`${t}\` needs parentheses: ${t}(...)`)}let n=mp(e),[r,i]=go[t];return(n.length<r||n.length>i)&&e.fail(`${t}() called with ${n.length} argument${n.length===1?"":"s"}; it takes ${r===i?r:`${r} to ${i===1/0?"any number":i}`}`),(t==="sub"||t==="gsub")&&n[2]&&!tr(n[2])&&e.fail(`${t}(): substitution into a temporary value is not supported`,"substitution into temporary value"),t==="split"&&n[1].type!=="var"&&e.fail("split(): second argument must be an array name"),t==="match"&&n[2]&&n[2].type!=="var"&&e.fail("match(): third argument must be an array name"),{type:"builtin",name:t,args:n}}function m1(e,t){e.next();let n=null;(e.tok.type==="name"||e.is("$"))&&(n=fi(e,t),tr(n)||e.fail("getline: target must be a variable, field or array element"));let r=null;return e.accept("<")&&(r=pp(e,t)),{type:"getline",target:n,file:r}}var g1=new Set(["/dev/stdout","/dev/stderr","/dev/null"]),Us=class{constructor(t,n){this.toks=t,this.i=0,this.warnings=n,this.funcs=new Set,this.parens=new Map;let r=[];for(let i=0;i+1<t.length;i++){let o=t[i],s=t[i+1];o.type==="punct"&&(o.value==="("?r.push(i):o.value===")"&&r.length>0&&this.parens.set(r.pop(),i)),o.type==="keyword"&&o.value==="function"&&(s.type==="name"||s.type==="funcname")&&this.funcs.add(s.value)}this.loopDepth=0,this.switchDepth=0,this.context="main"}get tok(){return this.toks[this.i]}peek(t){return this.toks[Math.min(this.i+t,this.toks.length-1)]}is(t,n="punct"){return this.tok.type===n&&this.tok.value===t}isKw(t){return this.is(t,"keyword")}next(){return this.toks[this.i++]}accept(t,n="punct"){return this.is(t,n)?this.next():null}expect(t,n="punct"){return this.is(t,n)||this.fail(`expected \`${t}\` but found ${Rt(this.tok)}`),this.next()}skipNewlines(){for(;this.tok.type==="newline";)this.i++}skipTerminators(){for(;this.tok.type==="newline"||this.is(";");)this.i++}fail(t,n=null){throw new k(t,this.tok.line,n)}warn(t){this.warnings.push(t)}unexpected(){this.fail(`unexpected ${Rt(this.tok)}`)}};function Rt(e){return e.type==="eof"?"end of program":e.type==="newline"?"newline":e.type==="string"?`string "${e.value}"`:e.type==="regex"?`regex /${e.value}/`:`\`${e.value}\``}var gp={__proto__:null,BEGIN:"begin",END:"end",BEGINFILE:"beginFile",ENDFILE:"endFile"};function yp(e){let t=[],n=new Us(sp(e,i=>t.push(i)),t),r={begin:[],end:[],beginFile:[],endFile:[],rules:[],functions:new Map,warnings:t};for(n.skipNewlines();n.tok.type!=="eof";)n.is(";")&&n.fail("each rule must have a pattern or an action part"),w1(n,r),n.accept(";"),n.skipNewlines();return r}function w1(e,t){if(e.isKw("function")){x1(e,t);return}if(e.tok.type==="keyword"&&e.tok.value in gp){let o=e.next().value;e.is("{")||e.fail(`${o} requires an action: ${o} { ... }`),t[gp[o]].push(...nr(e,o.toLowerCase()));return}if(e.is("{")){t.rules.push({pattern:null,action:nr(e,"main")});return}let n=we(e,{}),r=n;e.accept(",")&&(e.skipNewlines(),r={type:"range",from:n,to:we(e,{})});let i=e.is("{")?nr(e,"main"):null;i===null&&!(e.tok.type==="newline"||e.tok.type==="eof"||e.is(";"))&&e.unexpected(),t.rules.push({pattern:r,action:i})}function x1(e,t){e.next();let n=e.tok;n.type==="builtin"&&e.fail(`cannot redefine builtin function \`${n.value}\``),n.type!=="name"&&n.type!=="funcname"&&e.fail(`expected a function name but found ${Rt(n)}`),e.next();let r=n.value;t.functions.has(r)&&e.fail(`function \`${r}\` is defined twice`),e.expect("(");let i=[];for(;!e.is(")");){let o=e.tok;if(o.type!=="name"&&e.fail(`expected a parameter name but found ${Rt(o)}`),(o.value===r||i.includes(o.value))&&e.fail(`duplicate parameter \`${o.value}\` in function \`${r}\``),i.push(e.next().value),!e.accept(","))break;e.skipNewlines()}e.expect(")"),e.skipNewlines(),t.functions.set(r,{params:i,body:nr(e,"function")})}function nr(e,t=e.context){let n=e.context;e.context=t,e.expect("{");let r=[];for(e.skipTerminators();!e.is("}");)e.tok.type==="eof"&&e.fail("missing `}` at end of program"),r.push(Bs(e)),e.skipTerminators();return e.next(),e.context=n,r}function rr(e){if(e.is(";")||e.tok.type==="newline"){e.next();return}e.is("}")||e.tok.type==="eof"||e.unexpected()}var y1={__proto__:null,if:b1,while:v1,do:k1,for:S1,switch:E1,break:e=>un(e,"break"),continue:e=>un(e,"continue"),next:e=>un(e,"next"),nextfile:e=>un(e,"nextfile"),exit:e=>un(e,"exit"),return:e=>un(e,"return"),delete:N1,print:e=>xp(e,"print"),printf:e=>xp(e,"printf")};function Bs(e){if(e.is("{"))return{type:"block",body:nr(e)};if(e.is(";"))return e.next(),{type:"empty"};let t=e.tok.type==="keyword"?y1[e.tok.value]:void 0;if(t)return t(e);let n=we(e,{});return rr(e),{type:"expr",expr:n}}function an(e,t){e.skipNewlines(),t&&e.loopDepth++;let n=Bs(e);return t&&e.loopDepth--,n}function di(e){e.next(),e.expect("(");let t=we(e,{});return e.expect(")"),t}function b1(e){let t=di(e),n=an(e,!1),r=e.i;return e.skipNewlines(),e.isKw("else")?(e.next(),{type:"if",test:t,consequent:n,alternate:an(e,!1)}):(e.i=r,{type:"if",test:t,consequent:n,alternate:null})}function v1(e){return{type:"while",test:di(e),body:an(e,!0)}}function k1(e){e.next();let t=an(e,!0);e.skipTerminators(),e.isKw("while")||e.fail("`do` body must be followed by `while (...)`");let n=di(e);return rr(e),{type:"do",body:t,test:n}}function S1(e){if(e.next(),e.expect("("),e.tok.type==="name"&&e.peek(1).type==="keyword"&&e.peek(1).value==="in"&&e.peek(2).type==="name"&&e.peek(3).value===")"){let i=e.next().value;e.next();let o=e.next().value;return e.next(),{type:"forin",name:i,array:o,body:an(e,!0)}}let t=e.is(";")?null:we(e,{});e.expect(";"),e.skipNewlines();let n=e.is(";")?null:we(e,{});e.expect(";"),e.skipNewlines();let r=e.is(")")?null:we(e,{});return e.expect(")"),{type:"for",init:t,test:n,step:r,body:an(e,!0)}}function E1(e){let t=di(e);e.skipNewlines(),e.expect("{");let n=[],r=new Set;for(e.switchDepth++,e.skipTerminators();!e.is("}");e.skipTerminators()){let i=null;e.accept("case","keyword")?i=$1(e):e.accept("default","keyword")||e.fail(`expected \`case\` or \`default\` in switch body but found ${Rt(e.tok)}`);let o=i===null?"default":i.type==="regex"?`/${i.source}/`:String(i.value);r.has(o)&&e.fail(`duplicate case values in switch body: ${o}`),r.add(o),e.expect(":");let s=[];for(e.skipTerminators();!e.is("}")&&!e.isKw("case")&&!e.isKw("default");)e.tok.type==="eof"&&e.fail("missing `}` at end of program"),s.push(Bs(e)),e.skipTerminators();n.push({test:i,body:s})}return e.switchDepth--,e.next(),{type:"switch",expr:t,cases:n}}function $1(e){let t=e.accept("-")?-1:(e.accept("+"),1),n=e.tok;return n.type==="number"?(e.next(),{type:"num",value:t*Number(n.value)}):t===1&&n.type==="string"?(e.next(),{type:"str",value:n.value}):t===1&&n.type==="regex"?(e.next(),{type:"regex",source:n.value,re:Ee(n.value,!1,r=>e.warn(r))}):e.fail(`case value must be a number, string or regex constant, found ${Rt(n)}`)}function un(e,t){t==="break"&&e.loopDepth===0&&e.switchDepth===0&&e.fail("`break` is not allowed outside a loop or switch"),t==="continue"&&e.loopDepth===0&&e.fail("`continue` is not allowed outside a loop"),t==="next"&&e.context!=="main"&&e.context!=="function"&&e.fail(`\`next\` cannot be used in a ${e.context.toUpperCase()} action`),t==="nextfile"&&(e.context==="begin"||e.context==="end"||e.context==="endfile")&&e.fail(`\`nextfile\` cannot be used in a ${e.context.toUpperCase()} action`),t==="return"&&e.context!=="function"&&e.fail("`return` is only allowed inside a function"),e.next();let n={type:t};return(t==="exit"||t==="return")&&(n.value=lp(e)?we(e,{}):null),rr(e),n}function N1(e){e.next(),e.tok.type!=="name"&&e.fail(`\`delete\` needs an array name but found ${Rt(e.tok)}`);let t=e.next().value,n=Ds(e);return rr(e),{type:"delete",name:t,subs:n}}var wp=e=>e.is(";")||e.is("}")||e.is(">")||e.is(">>")||e.is("|")||e.is("|&")||e.tok.type==="newline"||e.tok.type==="eof";function xp(e,t){e.next();let n=null;if(e.is("(")){let i=e.i;e.next();let o=e.is(")")?[]:sn(e,{});e.accept(")")&&wp(e)?n=o:e.i=i}n===null&&(n=wp(e)?[]:sn(e,{noGt:!0})),t==="printf"&&n.length===0&&e.fail("printf needs a format string");let r=null;return(e.is("|")||e.is("|&"))&&e.fail(`output pipes (\`${t} ... | "cmd"\`) are not supported: ${Ar}`,`${t} | "cmd"`),(e.accept(">")||e.accept(">>"))&&(r=dp(e,{noGt:!0}),r.type==="str"&&!g1.has(r.value)&&e.fail(Ws(r.value),`${t} > FILE`)),rr(e),{type:t,args:n,dest:r}}function Ws(e){return`cannot redirect output to \`${e}\`: the filesystem is read-only (only /dev/stdout, /dev/stderr and /dev/null). To print a comparison, parenthesize it: print (a > b)`}var W=class{constructor(t){this.s=t,this.number=void 0,this.numeric=void 0}},ir="[ \\t\\n\\r\\f\\v]*",kp="[+-]?(?:\\d+\\.?\\d*|\\.\\d+)(?:[eE][+-]?\\d+)?",A1=new RegExp(`^${ir}${kp}${ir}$`,"u"),I1=new RegExp(`^${ir}(${kp})`,"u"),Sp=new RegExp(`^${ir}([+-])(inf|nan)${ir}$`,"iu"),zs=e=>A1.test(e)||Sp.test(e);function bp(e){let t=I1.exec(e);if(t)return Number(t[1]);let n=Sp.exec(e);return n?n[2].toLowerCase()==="nan"?Number.NaN:n[1]==="-"?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY:0}var qs=()=>new k("attempt to use an array in a scalar context");function B(e){if(typeof e=="number")return e;if(e===void 0)return 0;if(e instanceof W)return e.number??=bp(e.s);if(typeof e=="string")return bp(e);throw qs()}var pi=new Map;function Ep(e,t){if(Number.isNaN(e))throw new k("formatting signed NaN is not supported",null,"signed NaN");if(!Number.isFinite(e))return e<0?"-inf":"+inf";if(Number.isInteger(e))return Math.abs(e)<2**53?String(e):BigInt(e).toString();let n=pi.get(t);if(n===void 0){pi.size>64&&pi.clear(),n=qr(t);let r=n.filter(i=>typeof i!="string");if(r.length>1||r.some(i=>!"diouxXeEfFgG".includes(i.conv)||i.width==="*"||i.precision==="*"))throw new k("this numeric conversion format is not supported",null,"numeric conversion format");pi.set(t,n)}return n.map(r=>typeof r=="string"?r:Tt(e,r)).join("")}var $p=e=>typeof e=="string"?e:e instanceof W?e.s:"%.6g",O1=e=>$p(e.globals.get("CONVFMT")),C1=e=>$p(e.globals.get("OFMT"));function F(e,t){if(typeof e=="string")return tt(t,e);if(e instanceof W)return tt(t,e.s);if(typeof e=="number")return Ep(e,O1(t));if(e===void 0)return"";throw qs()}function tt(e,t){if(e.byteLocale&&/[\u0080-\u{10FFFF}]/u.test(t))throw new k("non-ASCII AWK text in a byte locale is not supported",null,"byte locale text");return t}function Mt(e,t=!1){return[...e].map(n=>{let r=t?n.toUpperCase():n.toLowerCase();if([...r].length!==1)throw new k("Unicode case expansion is not supported",null,"Unicode case mapping");return r}).join("")}function Np(e,t){return typeof e=="number"?Ep(e,C1(t)):F(e,t)}var js=e=>e.numeric??=zs(e.s),vp=e=>typeof e=="number"||e===void 0||e instanceof W&&js(e),De=e=>xe(e.globals.get("IGNORECASE"));function hi(e,t,n){if(vp(e)&&vp(t)){let o=B(e),s=B(t);return o<s?-1:o>s?1:o===s?0:Number.NaN}let r=F(e,n),i=F(t,n);return De(n)&&(r=Mt(r),i=Mt(i)),U(r,i)}function xe(e){if(typeof e=="number")return e!==0&&!Number.isNaN(e);if(typeof e=="string")return e!=="";if(e instanceof W)return js(e)?B(e)!==0:e.s!=="";if(e===void 0)return!1;throw qs()}var Hs=(e,t)=>Number.isSafeInteger(e)?String(e):F(e,t);function Gs(e){return e instanceof Map?"array":e===void 0?"untyped":typeof e=="number"?"number":e instanceof W&&js(e)?"strnum":"string"}function Ap(e,t,n){let{text:r}=e;if(e.pos>=r.length)return null;if(t==="")return F1(e);let i,o;if(t.length===1){let u=r.indexOf(t,e.pos);o=u===-1?r.length:u,i=u===-1?r.length:u+1}else{let u=bo(r,Ee(t,n),e.pos);o=u?.start??r.length,i=u?.end??r.length}let s=r.slice(e.pos,o);return e.pos=i,{rec:s,rt:r.slice(o,i)}}function F1(e){let{text:t}=e,n=e.pos;for(;t[n]===`
|
|
221
|
-
`;)n++;if(n>=t.length)return e.pos=n,null;let r=/\n\n+/gu;r.lastIndex=n;let i=r.exec(t);if(!i){e.pos=t.length;let o=t.slice(n).replace(/\n+$/u,"");return{rec:o,rt:t.slice(n+o.length)}}return e.pos=i.index+i[0].length,{rec:t.slice(n,i.index),rt:i[0]}}function
|
|
222
|
-
`))return e.split(t);if(n&&t==="^")throw new
|
|
223
|
-
]`:t;return vo(e,Ee(i,r))}function Ip(e){let t=e.split(/[ \t]+/u).filter(Boolean);return t.map((n,r)=>{let i=/^(?:(\+?\d+):)?(\+?\d+|\*)$/u.exec(n),o=i?.[1]===void 0?0:Number(i[1]),s=i?.[2]==="*"?4294967295:Number(i?.[2]);if(!i||i[1]!==void 0&&o===0||o>4294967295||!(s>0&&s<=4294967295)||i[2]==="*"&&r!==t.length-1)throw new k(`invalid FIELDWIDTHS value \`${e}'`);return{skip:o,width:s}})}function T1(e,t){let n=[...e],r=[],i=0;for(let{skip:o,width:s}of t){if(i>=n.length)break;i+=o,r.push(n.slice(i,i+s).join("")),i+=s}return r}function _1(e,t){let n=[],r=0;for(;r<e.length;){let i=t.search(e.slice(r));if(n.length>0&&i?.end===0&&(r+=ke(e,r),i=t.search(e.slice(r))),!i)break;n.push(e.slice(r+i.start,r+i.end)),r+=i.end}return n}function Op(e,t){let n=De(e);return e.fieldMode==="FIELDWIDTHS"?T1(t,e.widths):e.fieldMode==="FPAT"?_1(t,Ee(F(e.globals.get("FPAT"),e),n,e.warn)):Vs(t,F(e.globals.get("FS"),e),F(e.globals.get("RS"),e)==="",n)}var L1=/^([A-Za-z_][A-Za-z0-9_]*)=([^]*)$/u,Zs=e=>e!==void 0&&e.type==="exit",mi=class{constructor(t,n){this.ctx=t,this.stdin=n,this.idx=1,this.src=null,this.sawFile=!1,this.exitSignal=void 0,this.readers=new Map}next(t){for(;this.exitSignal===void 0;){if(this.src){let n=Ap(this.src,F(t.globals.get("RS"),t),De(t));if(n!==null)return t.globals.set("NR",B(t.globals.get("NR"))+1),t.globals.set("FNR",B(t.globals.get("FNR"))+1),t.globals.set("RT",n.rt),n.rec;this.closeFile(t);continue}if(!this.open(t))return null}return null}open(t){for(;this.idx<Math.trunc(B(t.globals.get("ARGC")));){if(++t.steps>Cn)throw new k("input operand scan exceeded execution limit",null,"execution limit");let n=F(t.globals.get("ARGV").get(String(this.idx++)),t);if(n==="")continue;t.globals.set("ARGIND",this.idx-1);let r=L1.exec(n);if(r){t.assign(r[1],new W(Qn(r[2],t.warn)));continue}this.sawFile=!0;let{text:i,error:o}=this.readOperand(n);if(o==="Is a directory"){this.failFile(t,n,o),this.exitSignal===void 0&&t.warn(`command line argument \`${n}' is a directory: skipped`);continue}if(o){let s=this.failFile(t,n,o);if(s!==void 0&&s.type==="nextfile")continue;if(this.exitSignal!==void 0)return!1;throw new k(`${n}: ${o}`)}if(this.use(t,n,i))return!0}return this.sawFile||this.exitSignal!==void 0?!1:(this.sawFile=!0,this.use(t,"-",this.takeStdin()))}readOperand(t){if(t==="/dev/null")return{text:""};if(t==="-"||t==="/dev/stdin")return{text:t==="/dev/stdin"&&this.ctx.stdinFile?this.ctx.stdinOrigin:this.takeStdin()};let{path:n,error:r}=P(this.ctx,"awk",t);return this.ctx.fs.isDir(n)?{error:"Is a directory"}:r?{error:r}:{text:this.ctx.fs.readFile(n)}}takeStdin(){let t=this.stdin;return this.stdin="",z(this.ctx),t}use(t,n,r){this.src={text:r,pos:0},t.globals.set("FILENAME",n),t.globals.set("FNR",0),t.globals.set("ERRNO","");let i=t.fileRule("begin");return Zs(i)?(this.exitSignal=i,this.src=null,!1):i!==void 0&&i.type==="nextfile"?(this.closeFile(t),!1):(tt(t,r),!0)}failFile(t,n,r){if(t.globals.set("ERRNO",r),!t.hasFileRules)return;t.globals.set("FILENAME",n),t.globals.set("FNR",0);let i=t.fileRule("begin");return Zs(i)&&(this.exitSignal=i),i}closeFile(t){this.src=null;let n=t.fileRule("end");Zs(n)&&(this.exitSignal=n)}readNamed(t,n){let r=this.readers.get(n);if(!r){let{text:o,error:s}=this.readOperand(n);if(s)return t.globals.set("ERRNO",s),{status:-1};r={text:tt(t,o),pos:0},this.readers.set(n,r)}let i=Ap(r,F(t.globals.get("RS"),t),De(t));return i===null?{status:0}:(t.globals.set("RT",i.rt),{status:1,record:i.rec})}close(t,n){return this.readers.delete(n)?0:(t.globals.set("ERRNO","close of redirection that was never opened"),-1)}};var R1=(e,t)=>({isRef:!0,scope:e,name:t}),or=e=>typeof e=="object"&&e!==null&&e.isRef===!0,sr=class extends Error{constructor(t){super(t.type),this.signal=t}},Tp=e=>new k(`attempt to use array \`${e}\` in a scalar context`);function gi(e,t){let n=e.frame;return n!==void 0&&n.has(t)?n:e.globals}function M1(e){let t=e;for(;or(t);)t=t.scope.get(t.name);return t instanceof Map?t:void 0}function ln(e,t){let n=gi(e,t).get(t);return or(n)?M1(n):n}var P1=new Set(["FS","FIELDWIDTHS","FPAT"]);function wi(e,t,n){let r=gi(e,t);if(r.get(t)instanceof Map)throw Tp(t);if(r===e.globals){if(t==="NF"){U1(e,n);return}if(t==="FIELDWIDTHS"&&(e.widths=Ip(F(n,e))),(t==="FPAT"||(t==="FS"||t==="RS")&&F(n,e).length>1)&&Ee(F(n,e),De(e),e.warn),P1.has(t)){e.fieldMode=t;let i=e.globals.get("PROCINFO");i instanceof Map&&i.set("FS",t)}}r.set(t,n)}function nt(e,t){let n=gi(e,t),r=t,i=n,o=i.get(r);if(o instanceof Map)return o;let s=or(o);for(;or(o);)i=o.scope,r=o.name,o=i.get(r);if(!(o instanceof Map)){if(o!==void 0)throw new k(`attempt to use scalar \`${r}\` as an array`);o=new Map,i.set(r,o)}return s&&n.set(t,o),o}function xi(e,t,n=new W(t)){e.record=t,e.recordValue=n,e.fields=[void 0,...Op(e,t).map(r=>new W(r))],e.nf=e.fields.length-1,e.globals.set("NF",e.nf)}function _p(e){let t=F(e.globals.get("OFS"),e);e.record=e.fields.slice(1).map(n=>F(n,e)).join(t),e.recordValue=e.record}function Lp(e,t){return t===0?e.recordValue:t<=e.nf?e.fields[t]:void 0}function D1(e,t,n){if(t===0){let r=F(n,e);xi(e,r,typeof n=="number"?r:n);return}for(;e.nf<t;)e.fields[++e.nf]="";e.fields[t]=n,e.globals.set("NF",e.nf),_p(e)}function U1(e,t){let n=Math.trunc(B(t));if(n<0)throw new k(`NF set to negative value ${n}`);for(;e.nf<n;)e.fields[++e.nf]="";e.fields.length=n+1,e.nf=n,e.globals.set("NF",n),_p(e)}function Rp(e,t){let n=B(O(e,t));if(!(n>=0))throw new k(`attempt to access field ${Number.isNaN(n)?n:Math.trunc(n)}`);return Math.trunc(n)}function ur(e,t){if(t.length===1)return Hs(O(e,t[0]),e);let n=F(e.globals.get("SUBSEP"),e);return t.map(r=>Hs(O(e,r),e)).join(n)}function Ys(e,t){return t.type==="var"?t:t.type==="index"?{type:"index",arr:nt(e,t.name),key:ur(e,t.subs)}:{type:"field",i:Rp(e,t.index)}}function Mp(e,t){return t.type==="var"?Pp(ln(e,t.name),t.name):t.type==="index"?t.arr.get(t.key):Lp(e,t.i)}function Ks(e,t,n){t.type==="var"?wi(e,t.name,n):t.type==="index"?t.arr.set(t.key,n):D1(e,t.i,n)}function Js(e,t,n){Ks(e,Ys(e,t),n)}function Cp(e,t,n){if(n===0&&(e==="/"||e==="%"))throw new k(e==="/"?"division by zero attempted":"division by zero attempted in `%`");return Ir(e,t,n)}var B1={__proto__:null,"<":e=>e<0,"<=":e=>e<=0,"==":e=>e===0,"!=":e=>e!==0,">":e=>e>0,">=":e=>e>=0};function rt(e,t){let n=De(e);return t.type==="regex"?n?Ee(t.source,!0):t.re:Ee(F(O(e,t),e),n,e.warn)}function Pp(e,t){if(e instanceof Map)throw Tp(t);return e}function Fp(e,t,n){let r=Ys(e,t.target),i=B(Mp(e,r)),o=t.op==="++"?i+1:i-1;return Ks(e,r,o),n?i:o}function O(e,t){switch(t.type){case"num":case"str":return t.value;case"regex":return rt(e,t).test(e.record)?1:0;case"var":return Pp(ln(e,t.name),t.name);case"index":{let n=nt(e,t.name),r=ur(e,t.subs),i=n.get(r);return i===void 0&&n.set(r,void 0),i}case"field":return Lp(e,Rp(e,t.index));case"assign":{let n=Ys(e,t.target),r=O(e,t.value);if(r instanceof Map)throw new k("attempt to use an array in a scalar context");return t.op!=="="&&(r=Cp(t.op[0],B(Mp(e,n)),B(r))),Ks(e,n,r),r}case"cond":return O(e,xe(O(e,t.test))?t.consequent:t.alternate);case"or":return xe(O(e,t.left))||xe(O(e,t.right))?1:0;case"and":return xe(O(e,t.left))&&xe(O(e,t.right))?1:0;case"not":return xe(O(e,t.expr))?0:1;case"neg":return-B(O(e,t.expr));case"plus":return B(O(e,t.expr));case"binary":return Cp(t.op,B(O(e,t.left)),B(O(e,t.right)));case"concat":return F(O(e,t.left),e)+F(O(e,t.right),e);case"compare":return B1[t.op](hi(O(e,t.left),O(e,t.right),e))?1:0;case"match":{let n=F(O(e,t.left),e);return rt(e,t.right).test(n)===t.negate?0:1}case"in":return nt(e,t.array).has(ur(e,t.keys))?1:0;case"preinc":return Fp(e,t,!1);case"postinc":return Fp(e,t,!0);case"call":return W1(e,t);case"builtin":return e.callBuiltin(e,t);case"getline":return q1(e,t);default:throw new k(`unknown expression: ${t.type}`)}}function W1(e,t){let n=e.program.functions.get(t.name);if(n===void 0)throw new k(`function \`${t.name}\` not defined`);if(t.args.length>n.params.length)throw new k(`function \`${t.name}\` called with ${t.args.length} arguments, but it accepts only ${n.params.length}`);if(e.callDepth>=wo)throw new k(`function call nesting deeper than ${wo} levels (runaway recursion?)`,null,"call depth limit");let r=e.frame,i=new Map;for(let o=0;o<n.params.length;o++)i.set(n.params[o],o<t.args.length?z1(e,t.args[o]):void 0);e.frame=i,e.callDepth++;try{let o=e.execStmts(e,n.body);if(o===void 0||o.type==="return")return o?.value;throw new sr(o)}finally{e.frame=r,e.callDepth--}}function z1(e,t){if(t.type!=="var")return O(e,t);let n=gi(e,t.name),r=n.get(t.name);return r instanceof Map||or(r)?r:r===void 0?R1(n,t.name):r}function q1(e,t){let n;if(t.file===null){if(n=e.input.next(e),n===null)return 0}else{let r=e.input.readNamed(e,F(O(e,t.file),e));if(r.status!==1)return r.status;n=r.record}return t.target===null?xi(e,n):Js(e,t.target,new W(n)),1}var Ge=(e,t)=>B(O(e,t)),Qs=2**32;function Up(e){return Number(BigInt.asUintN(32,BigInt(Math.trunc(e))))}var Bp=()=>({seed:1,state:Up(1)});function j1(e){e.rng.state=(e.rng.state+1831565813)%Qs;let t=e.rng.state;t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61);let n=t^t>>>14;return(n<0?n+Qs:n)/Qs}function H1(e,t){let n=e.rng.seed,r=t.length>0?Ge(e,t[0]):Math.floor(Date.now()/1e3);return e.rng.seed=r,e.rng.state=Up(r),n}function G1(e,t){let n=Ge(e,t[0]);return n<0&&e.warn(`log: received negative argument ${F(n,e)}`),Math.log(n)}function X1(e,t){let n=Ge(e,t[0]);return n<0&&e.warn(`sqrt: called with negative argument ${F(n,e)}`),Math.sqrt(n)}function Z1(e,t){let n=Ge(e,t[0]),r=Math.exp(n);return Number.isFinite(n)&&!Number.isFinite(r)&&e.warn(`exp: argument ${F(n,e)} is out of range`),r}function V1(e,t){let n=O(e,t[0]);if(typeof n=="number")return n;let r=n instanceof W?n.s:F(n,e),i=/^0[xX]([0-9a-fA-F]*)/u.exec(r);if(i)return i[1]===""?0:Number.parseInt(i[1],16);let o=/^0[0-7]+(?![.\deE0-9])/u.exec(r);return o?Number.parseInt(o[0],8):B(new W(r))}function ar(e,t,n,r){let i=Ge(e,n);if(i<0)throw new k(`${t}: argument ${r} negative value ${F(i,e)} is not allowed`);if(!Number.isFinite(i))throw new k(`${t}: argument ${r} is not a finite number`);return BigInt.asUintN(64,BigInt(Math.trunc(i)))}function tu(e){let t=e;for(;t>0n&&BigInt(Number(t))!==t;)t&=(1n<<BigInt(t.toString(2).length-1))-1n;return Number(t)}function eu(e,t){return(n,r)=>{if(r.length<2)throw new k(`${e}: called with less than two arguments`);let i=ar(n,e,r[0],1);for(let o=1;o<r.length;o++)i=t(i,ar(n,e,r[o],o+1));return tu(i)}}function Dp(e,t){return(n,r)=>{let i=ar(n,e,r[0],1),o=ar(n,e,r[1],2)%64n;return tu(BigInt.asUintN(64,t?i<<o:i>>o))}}var Wp={__proto__:null,sin:(e,t)=>Math.sin(Ge(e,t[0])),cos:(e,t)=>Math.cos(Ge(e,t[0])),atan2:(e,t)=>Math.atan2(Ge(e,t[0]),Ge(e,t[1])),exp:Z1,log:G1,sqrt:X1,int:(e,t)=>Math.trunc(Ge(e,t[0])),rand:j1,srand:H1,systime:()=>Math.floor(Date.now()/1e3),strtonum:V1,and:eu("and",(e,t)=>e&t),or:eu("or",(e,t)=>e|t),xor:eu("xor",(e,t)=>e^t),lshift:Dp("lshift",!0),rshift:Dp("rshift",!1),compl:(e,t)=>tu(BigInt.asUintN(64,~ar(e,"compl",t[0],1)))};var yi=new Map;function Y1(e){let t=yi.get(e);return t||(yi.size>=256&&yi.clear(),t=qr(e),yi.set(e,t)),t}function bi(e,t,n){let r=0,i=()=>{if(r>=n.length)throw new k("printf: not enough arguments to satisfy format string");return n[r++]},o="";for(let s of Y1(t)){if(typeof s=="string"){o+=s;continue}let u={...s};if(s.width==="*"){let a=Math.trunc(B(i()));a<0?(u.minus=!0,u.width=-a):u.width=a}if(s.precision==="*"){let a=Math.trunc(B(i()));u.precision=a<0?null:a}if(u.width>ye||u.precision>ye)throw new k(`printf: field width or precision above ${ye} is not supported`,null,"format size limit");o+=K1(e,u,i())}return o}function K1(e,t,n){if(t.conv==="s"){let r=F(n,e);return t.precision!==null&&(r=[...r].slice(0,t.precision).join("")),wt("",r,t,!1)}return t.conv==="c"?wt("",tt(e,J1(n)),t,!1):Tt(B(n),t)}function J1(e){if(typeof e=="number"||e instanceof W&&zs(e.s)){let r=Math.trunc(B(e));if(!ze(r))throw new k("printf: character code outside Unicode scalar values is not supported",null,"character code");return String.fromCodePoint(r)}let n=e instanceof W?e.s:e??"";return n===""?"\0":String.fromCodePoint(n.codePointAt(0))}var de=(e,t)=>F(O(e,t),e),zp=(e,t)=>B(O(e,t)),Q1={type:"field",index:{type:"num",value:0}};function ev(e,t){let n="";for(let r=0;r<e.length;r++){let i=e[r];if(i==="\\"){if(e[r+1]==="\\"&&e[r+2]==="\\"&&(e[r+3]==="&"||e[r+3]==="\\")){n+="\\"+e[r+3],r+=3;continue}if(e[r+1]==="\\"&&e[r+2]==="&"){n+="\\"+t,r+=2;continue}if(e[r+1]==="&"){n+="&",r++;continue}}n+=i==="&"?t:i}return n}function qp(e,t,n){let r=rt(e,t[0]),i=de(e,t[1]),o=t[2]??Q1,s=de(e,o),{out:u,count:a}=Tn(s,r,(l,c)=>ev(i,s.slice(l,c)),n?"global":"first");return a>0&&Js(e,o,u),a}function tv(e,t){let n="";for(let r=0;r<e.length;r++){let i=e[r];if(i==="\\"&&r+1===e.length)throw new k("gensub with a trailing replacement backslash is not supported",null,"gensub trailing backslash");if(i==="\\"&&r+1<e.length){let o=e[++r];o>="0"&&o<="9"?n+=t[Number(o)]?.text??"":n+=o;continue}n+=i==="&"?t[0].text:i}return n}function nv(e,t){let n=rt(e,t[0]),r=de(e,t[1]),i=O(e,t[2]),o=F(i,e),s=o.startsWith("g")||o.startsWith("G"),u=0;s||(u=Math.trunc(B(i)),u<1&&(e.warn(`gensub: third argument \`${o}' treated as 1`),u=1));let a=t[3]?de(e,t[3]):e.record,l=/(?:^|[^\\])(?:\\\\)*\\[1-9]/u.test(r);return Tn(a,n,(c,f,d)=>!s&&d!==u?null:tv(r,l?n.groups(a,c,f):[{text:a.slice(c,f)}]),s?"global":"nth").out}function rv(e,t){let n=de(e,t[0]),r=rt(e,t[1]),i=r.search(n,0),o=i?Array.from(n.slice(0,i.start)).length+1:0;if(e.globals.set("RSTART",o),e.globals.set("RLENGTH",i?Array.from(n.slice(i.start,i.end)).length:-1),t[2]){let s=nt(e,t[2].name);if(s.clear(),i){let u=F(e.globals.get("SUBSEP"),e);r.groups(n,i.start,i.end).forEach((a,l)=>{a!==void 0&&(s.set(String(l),new W(a.text)),s.set(`${l}${u}start`,Array.from(n.slice(0,a.start)).length+1),s.set(`${l}${u}length`,[...a.text].length))})}}return o}function iv(e,t){let n=de(e,t[0]),r=nt(e,t[1].name),i;t[2]===void 0?i=F(e.globals.get("FS"),e):t[2].type==="regex"?i=rt(e,t[2]):i=de(e,t[2]);let o=Vs(n,i,!1,De(e));return r.clear(),o.forEach((s,u)=>r.set(String(u+1),new W(s))),o.length}function ov(e,t){let n=[...de(e,t[0])],r=Math.trunc(zp(e,t[1])),i=Number.isNaN(r)?1:Math.max(r,1),o=n.length+1;if(t[2]){let s=Math.trunc(zp(e,t[2]));if(!(s>=1))return"";o=Math.min(o,i+s)}return o>i?n.slice(i-1,o-1).join(""):""}function sv(e,t){if(t.length===0)return[...e.record].length;if(t[0].type==="var"){let n=ln(e,t[0].name);return n instanceof Map?n.size:[...F(n,e)].length}return[...de(e,t[0])].length}function uv(e,t){let n=de(e,t[0]),r=de(e,t[1]);De(e)&&(n=Mt(n),r=Mt(r));let i=n.indexOf(r);return i<0?0:Array.from(n.slice(0,i)).length+1}function av(e,t){let n=de(e,t[0]);return n==="/dev/stdout"||n==="/dev/stderr"||n==="/dev/null"?0:e.input.close(e,n)}var lv=(e,t)=>t[0].type==="var"?Gs(ln(e,t[0].name)):Gs(O(e,t[0])),cv={__proto__:null,...Wp,length:sv,substr:ov,index:uv,split:iv,sub:(e,t)=>qp(e,t,!1),gsub:(e,t)=>qp(e,t,!0),gensub:nv,match:rv,sprintf:(e,t)=>bi(e,de(e,t[0]),t.slice(1).map(n=>O(e,n))),tolower:(e,t)=>Mt(de(e,t[0])),toupper:(e,t)=>Mt(de(e,t[0]),!0),close:av,fflush:()=>0,typeof:lv,isarray:(e,t)=>t[0].type==="var"&&ln(e,t[0].name)instanceof Map?1:0};function jp(e,t){let n=cv[t.name];if(!n)throw new k(`function \`${t.name}\` is not supported`,null,`${t.name}()`);return n(e,t.args)}var ki={type:"break"},ru={type:"continue"},fv={type:"next"},dv={type:"nextfile"},pv={type:"exit"};function Hp(e,t,n,r){let i=new Map([["0","awk"]]);r.forEach((u,a)=>i.set(String(a+1),new W(u)));let o=new Map([["FS"," "],["OFS"," "],["ORS",`
|
|
230
|
+
`){o+=2;continue}}if(s==="\\"){let u=Z2(e,o,n);f1(i,u),o=u.end}else{let u=String.fromCodePoint(e.codePointAt(o));f1(i,{text:u}),o+=u.length}}if(r!==null)throw new $("unterminated string",r);return{value:P(Uint8Array.from(i)),end:o}}function Y2(e,t,n){let r=t,i=!1;for(;r<e.length;){let o=e[r];if(o===`
|
|
231
|
+
`)break;if(o==="\\"){r+=2;continue}if(i){if(o==="["&&e[r+1]===":"){let s=e.indexOf(":]",r+2);if(s!==-1){r=s+2;continue}}o==="]"&&(i=!1),r++;continue}if(o==="["){i=!0,r++,e[r]==="^"&&r++,e[r]==="]"&&r++;continue}if(o==="/")return{value:e.slice(t,r),end:r+1};r++}throw new $("unterminated regexp",n)}function ar(e,t=null){return d1(e,0,t).value}function f1(e,t){if(t.byte===void 0)for(let n of A(t.text))e.push(n);else e.push(t.byte)}var V2=new Set(["=","+=","-=","*=","/=","%=","^=","**="]),p1=new Set(["<","<=","==","!=",">",">="]),fr=e=>e.type==="var"||e.type==="index"||e.type==="field";function h1(e){let t=e.tok;return g1(e)||t.type==="regex"||t.type==="keyword"&&t.value==="getline"||t.type==="punct"&&["!","-","+"].includes(t.value)}function cn(e,t){let n=[Se(e,t)];for(;e.accept(",");)e.skipNewlines(),n.push(Se(e,t));return n}function Se(e,t){let n=K2(e,t),r=e.tok;if(r.type==="punct"&&V2.has(r.value)){fr(n)||e.fail(`cannot assign to ${n.type==="regex"?"a regex":"a non-variable"} (left side of \`${r.value}\`)`),e.next();let i=Se(e,t);return{type:"assign",op:r.value==="**="?"^=":r.value,target:n,value:i}}return n}function K2(e,t){let n=au(e,t);if(!e.accept("?"))return n;e.skipNewlines();let r=Se(e,t);return e.skipNewlines(),e.expect(":"),e.skipNewlines(),{type:"cond",test:n,consequent:r,alternate:Se(e,t)}}var J2=[["or",["||"]],["and",["&&"]],["in",["in"]],["match",["~","!~"]],["compare",[...p1]],["concat",[]],["binary",["+","-"]],["binary",["*","/","%"]]],Q2=new Map(J2.flatMap(([e,t],n)=>t.map(r=>[r,{type:e,precedence:n}]))),ek={type:"concat",precedence:5};function au(e,t,n=0){let r=Ai(e,t),i=1/0;for(;;){let o=e.tok;n<=4&&i>4&&!t.noGt&&(e.is("|")||e.is("|&"))&&e.fail(`command pipelines (\`"cmd" | getline\`) are not supported: ${zr}`,'"cmd" | getline');let s=g1(e)?ek:o.type==="punct"||o.type==="keyword"&&o.value==="in"?Q2.get(o.value):void 0;if(!s||s.precedence<n||s.precedence>i||t.noGt&&e.is(">"))return r;let{type:u,precedence:a}=s,l=u==="concat"?null:e.next().value;if(i=a,(u==="or"||u==="and")&&e.skipNewlines(),u==="in"){r={type:u,keys:[r],array:m1(e)};continue}let f=au(e,t,a+1);(l==="/"||l==="%")&&lr(f)===0&&lr(r)!==null&&e.fail(l==="/"?"division by zero attempted":"division by zero attempted in `%`"),u==="compare"&&tk(e,t)&&e.fail(`comparison operators do not chain (\`a ${l} b ${e.tok.value} c\`); parenthesize the first comparison`),u==="binary"||u==="compare"?r={type:u,op:l,left:r,right:f}:u==="match"?r={type:u,negate:l==="!~",left:r,right:f}:r={type:u,left:r,right:f}}}function m1(e){return e.tok.type!=="name"&&e.fail(`expected an array name after \`in\` but found \`${e.tok.value}\``),e.next().value}var tk=(e,t)=>e.tok.type==="punct"&&p1.has(e.tok.value)&&!(t.noGt&&e.tok.value===">");function g1(e){let t=e.tok;return t.type==="number"||t.type==="string"||t.type==="name"||t.type==="funcname"||t.type==="builtin"?!0:t.type==="punct"&&["$","(","++","--"].includes(t.value)}function w1(e,t){return au(e,t,5)}function lr(e){if(e.type==="num")return e.value;if(e.type==="neg"||e.type==="plus"){let r=lr(e.expr);return r===null?null:e.type==="neg"?-r:r}if(e.type!=="binary")return null;let t=lr(e.left),n=lr(e.right);return t===null||n===null?null:Hr(e.op,t,n)}var nk={__proto__:null,"!":"not","-":"neg","+":"plus"};function Ai(e,t,n=!1){if(n&&(e.is("$")||e.is("++")||e.is("--")))return Oi(e,t);let r=e.tok.type==="punct"&&nk[e.tok.value];return r?(e.next(),{type:r,expr:Ai(e,t,n)}):n?y1(e,t):rk(e,t)}function rk(e,t){let n=b1(e,t);return!e.is("^")&&!e.is("**")?n:(e.next(),{type:"binary",op:"^",left:n,right:Ai(e,t)})}function b1(e,t){let n=Oi(e,t);for(;(e.is("++")||e.is("--"))&&fr(n);)n={type:"postinc",op:e.next().value,target:n};return n}function Oi(e,t){if(e.accept("$"))return{type:"field",index:Ai(e,t,!0)};if(e.is("++")||e.is("--")){let n=e.next().value,r=Oi(e,t);return fr(r)||e.fail(`\`${n}\` needs a variable, field or array element`),{type:"preinc",op:n,target:r}}return y1(e,t)}function y1(e,t){let n=e.tok;switch(n.type){case"number":return e.next(),{type:"num",value:Number(n.value)};case"string":return e.next(),{type:"str",value:n.value};case"regex":return e.next(),{type:"regex",source:n.value,re:ik(e,n.value)};case"name":return ok(e);case"funcname":return sk(e);case"builtin":return ak(e);case"keyword":return n.value==="getline"?lk(e,t):e.unexpected();case"punct":return n.value==="("?uk(e):e.unexpected();default:return e.unexpected()}}function ik(e,t){try{return Fe(t,!1,n=>e.warn(n))}catch(n){return e.fail(n.message,n.gap??null)}}function lu(e){if(!e.accept("["))return null;let t=cn(e,{});return e.expect("]"),e.is("[")&&e.fail("arrays of arrays are not supported","arrays of arrays"),t}function ok(e){let t=e.next().value,n=lu(e);return n!==null?{type:"index",name:t,subs:n}:(e.is("(")&&e.funcs.has(t)&&e.fail(`function \`${t}\` called with space between name and \`(\``),{type:"var",name:t})}function sk(e){return{type:"call",name:e.next().value,args:x1(e)}}function x1(e){e.expect("(");let t=e.is(")")?[]:cn(e,{});return e.expect(")"),t}function uk(e){let t=0;for(;e.parens.get(e.i+1)===e.parens.get(e.i)-1;)e.next(),t++;e.next();let n=cn(e,{});if(e.expect(")"),n.length===1){for(;t-- >0;)e.expect(")");return n[0]}return e.isKw("in")||e.fail("a parenthesized list must be followed by `in ARRAY`"),e.next(),{type:"in",keys:n,array:m1(e)}}function ak(e){let t=e.next().value;if(jr.has(t)&&e.fail(jr.get(t),`${t}()`),!e.is("(")){if(t==="length")return{type:"builtin",name:t,args:[]};e.fail(`\`${t}\` needs parentheses: ${t}(...)`)}let n=x1(e),[r,i]=Po[t];return(n.length<r||n.length>i)&&e.fail(`${t}() called with ${n.length} argument${n.length===1?"":"s"}; it takes ${r===i?r:`${r} to ${i===1/0?"any number":i}`}`),(t==="sub"||t==="gsub")&&n[2]&&!fr(n[2])&&e.fail(`${t}(): substitution into a temporary value is not supported`,"substitution into temporary value"),t==="split"&&n[1].type!=="var"&&e.fail("split(): second argument must be an array name"),t==="match"&&n[2]&&n[2].type!=="var"&&e.fail("match(): third argument must be an array name"),{type:"builtin",name:t,args:n}}function lk(e,t){e.next();let n=null;(e.tok.type==="name"||e.is("$"))&&(n=Oi(e,t),fr(n)||e.fail("getline: target must be a variable, field or array element"));let r=null;return e.accept("<")&&(r=b1(e,t)),{type:"getline",target:n,file:r}}var fk=new Set(["/dev/stdout","/dev/stderr","/dev/null"]),fu=class{constructor(t,n){this.toks=t,this.i=0,this.warnings=n,this.funcs=new Set,this.parens=new Map;let r=[];for(let i=0;i+1<t.length;i++){let o=t[i],s=t[i+1];o.type==="punct"&&(o.value==="("?r.push(i):o.value===")"&&r.length>0&&this.parens.set(r.pop(),i)),o.type==="keyword"&&o.value==="function"&&(s.type==="name"||s.type==="funcname")&&this.funcs.add(s.value)}this.loopDepth=0,this.switchDepth=0,this.context="main"}get tok(){return this.toks[this.i]}peek(t){return this.toks[Math.min(this.i+t,this.toks.length-1)]}is(t,n="punct"){return this.tok.type===n&&this.tok.value===t}isKw(t){return this.is(t,"keyword")}next(){return this.toks[this.i++]}accept(t,n="punct"){return this.is(t,n)?this.next():null}expect(t,n="punct"){return this.is(t,n)||this.fail(`expected \`${t}\` but found ${Wt(this.tok)}`),this.next()}skipNewlines(){for(;this.tok.type==="newline";)this.i++}skipTerminators(){for(;this.tok.type==="newline"||this.is(";");)this.i++}fail(t,n=null){throw new $(t,this.tok.line,n)}warn(t){this.warnings.push(t)}unexpected(){this.fail(`unexpected ${Wt(this.tok)}`)}};function Wt(e){return e.type==="eof"?"end of program":e.type==="newline"?"newline":e.type==="string"?`string "${e.value}"`:e.type==="regex"?`regex /${e.value}/`:`\`${e.value}\``}var k1={__proto__:null,BEGIN:"begin",END:"end",BEGINFILE:"beginFile",ENDFILE:"endFile"};function $1(e){let t=[],n=new fu(c1(e,i=>t.push(i)),t),r={begin:[],end:[],beginFile:[],endFile:[],rules:[],functions:new Map,warnings:t};for(n.skipNewlines();n.tok.type!=="eof";)n.is(";")&&n.fail("each rule must have a pattern or an action part"),ck(n,r),n.accept(";"),n.skipNewlines();return r}function ck(e,t){if(e.isKw("function")){dk(e,t);return}if(e.tok.type==="keyword"&&e.tok.value in k1){let o=e.next().value;e.is("{")||e.fail(`${o} requires an action: ${o} { ... }`),t[k1[o]].push(...cr(e,o.toLowerCase()));return}if(e.is("{")){t.rules.push({pattern:null,action:cr(e,"main")});return}let n=Se(e,{}),r=n;e.accept(",")&&(e.skipNewlines(),r={type:"range",from:n,to:Se(e,{})});let i=e.is("{")?cr(e,"main"):null;i===null&&!(e.tok.type==="newline"||e.tok.type==="eof"||e.is(";"))&&e.unexpected(),t.rules.push({pattern:r,action:i})}function dk(e,t){e.next();let n=e.tok;n.type==="builtin"&&e.fail(`cannot redefine builtin function \`${n.value}\``),n.type!=="name"&&n.type!=="funcname"&&e.fail(`expected a function name but found ${Wt(n)}`),e.next();let r=n.value;t.functions.has(r)&&e.fail(`function \`${r}\` is defined twice`),e.expect("(");let i=[];for(;!e.is(")");){let o=e.tok;if(o.type!=="name"&&e.fail(`expected a parameter name but found ${Wt(o)}`),(o.value===r||i.includes(o.value))&&e.fail(`duplicate parameter \`${o.value}\` in function \`${r}\``),i.push(e.next().value),!e.accept(","))break;e.skipNewlines()}e.expect(")"),e.skipNewlines(),t.functions.set(r,{params:i,body:cr(e,"function")})}function cr(e,t=e.context){let n=e.context;e.context=t,e.expect("{");let r=[];for(e.skipTerminators();!e.is("}");)e.tok.type==="eof"&&e.fail("missing `}` at end of program"),r.push(cu(e)),e.skipTerminators();return e.next(),e.context=n,r}function dr(e){if(e.is(";")||e.tok.type==="newline"){e.next();return}e.is("}")||e.tok.type==="eof"||e.unexpected()}var pk={__proto__:null,if:hk,while:mk,do:gk,for:wk,switch:bk,break:e=>dn(e,"break"),continue:e=>dn(e,"continue"),next:e=>dn(e,"next"),nextfile:e=>dn(e,"nextfile"),exit:e=>dn(e,"exit"),return:e=>dn(e,"return"),delete:xk,print:e=>S1(e,"print"),printf:e=>S1(e,"printf")};function cu(e){if(e.is("{"))return{type:"block",body:cr(e)};if(e.is(";"))return e.next(),{type:"empty"};let t=e.tok.type==="keyword"?pk[e.tok.value]:void 0;if(t)return t(e);let n=Se(e,{});return dr(e),{type:"expr",expr:n}}function pn(e,t){e.skipNewlines(),t&&e.loopDepth++;let n=cu(e);return t&&e.loopDepth--,n}function Ii(e){e.next(),e.expect("(");let t=Se(e,{});return e.expect(")"),t}function hk(e){let t=Ii(e),n=pn(e,!1),r=e.i;return e.skipNewlines(),e.isKw("else")?(e.next(),{type:"if",test:t,consequent:n,alternate:pn(e,!1)}):(e.i=r,{type:"if",test:t,consequent:n,alternate:null})}function mk(e){return{type:"while",test:Ii(e),body:pn(e,!0)}}function gk(e){e.next();let t=pn(e,!0);e.skipTerminators(),e.isKw("while")||e.fail("`do` body must be followed by `while (...)`");let n=Ii(e);return dr(e),{type:"do",body:t,test:n}}function wk(e){if(e.next(),e.expect("("),e.tok.type==="name"&&e.peek(1).type==="keyword"&&e.peek(1).value==="in"&&e.peek(2).type==="name"&&e.peek(3).value===")"){let i=e.next().value;e.next();let o=e.next().value;return e.next(),{type:"forin",name:i,array:o,body:pn(e,!0)}}let t=e.is(";")?null:Se(e,{});e.expect(";"),e.skipNewlines();let n=e.is(";")?null:Se(e,{});e.expect(";"),e.skipNewlines();let r=e.is(")")?null:Se(e,{});return e.expect(")"),{type:"for",init:t,test:n,step:r,body:pn(e,!0)}}function bk(e){let t=Ii(e);e.skipNewlines(),e.expect("{");let n=[],r=new Set;for(e.switchDepth++,e.skipTerminators();!e.is("}");e.skipTerminators()){let i=null;e.accept("case","keyword")?i=yk(e):e.accept("default","keyword")||e.fail(`expected \`case\` or \`default\` in switch body but found ${Wt(e.tok)}`);let o=i===null?"default":i.type==="regex"?`/${i.source}/`:String(i.value);r.has(o)&&e.fail(`duplicate case values in switch body: ${o}`),r.add(o),e.expect(":");let s=[];for(e.skipTerminators();!e.is("}")&&!e.isKw("case")&&!e.isKw("default");)e.tok.type==="eof"&&e.fail("missing `}` at end of program"),s.push(cu(e)),e.skipTerminators();n.push({test:i,body:s})}return e.switchDepth--,e.next(),{type:"switch",expr:t,cases:n}}function yk(e){let t=e.accept("-")?-1:(e.accept("+"),1),n=e.tok;return n.type==="number"?(e.next(),{type:"num",value:t*Number(n.value)}):t===1&&n.type==="string"?(e.next(),{type:"str",value:n.value}):t===1&&n.type==="regex"?(e.next(),{type:"regex",source:n.value,re:Fe(n.value,!1,r=>e.warn(r))}):e.fail(`case value must be a number, string or regex constant, found ${Wt(n)}`)}function dn(e,t){t==="break"&&e.loopDepth===0&&e.switchDepth===0&&e.fail("`break` is not allowed outside a loop or switch"),t==="continue"&&e.loopDepth===0&&e.fail("`continue` is not allowed outside a loop"),t==="next"&&e.context!=="main"&&e.context!=="function"&&e.fail(`\`next\` cannot be used in a ${e.context.toUpperCase()} action`),t==="nextfile"&&(e.context==="begin"||e.context==="end"||e.context==="endfile")&&e.fail(`\`nextfile\` cannot be used in a ${e.context.toUpperCase()} action`),t==="return"&&e.context!=="function"&&e.fail("`return` is only allowed inside a function"),e.next();let n={type:t};return(t==="exit"||t==="return")&&(n.value=h1(e)?Se(e,{}):null),dr(e),n}function xk(e){e.next(),e.tok.type!=="name"&&e.fail(`\`delete\` needs an array name but found ${Wt(e.tok)}`);let t=e.next().value,n=lu(e);return dr(e),{type:"delete",name:t,subs:n}}var v1=e=>e.is(";")||e.is("}")||e.is(">")||e.is(">>")||e.is("|")||e.is("|&")||e.tok.type==="newline"||e.tok.type==="eof";function S1(e,t){e.next();let n=null;if(e.is("(")){let i=e.i;e.next();let o=e.is(")")?[]:cn(e,{});e.accept(")")&&v1(e)?n=o:e.i=i}n===null&&(n=v1(e)?[]:cn(e,{noGt:!0})),t==="printf"&&n.length===0&&e.fail("printf needs a format string");let r=null;return(e.is("|")||e.is("|&"))&&e.fail(`output pipes (\`${t} ... | "cmd"\`) are not supported: ${zr}`,`${t} | "cmd"`),(e.accept(">")||e.accept(">>"))&&(r=w1(e,{noGt:!0}),r.type==="str"&&!fk.has(r.value)&&e.fail(du(r.value),`${t} > FILE`)),dr(e),{type:t,args:n,dest:r}}function du(e){return`cannot redirect output to \`${e}\`: the filesystem is read-only (only /dev/stdout, /dev/stderr and /dev/null). To print a comparison, parenthesize it: print (a > b)`}var j=class{constructor(t){this.s=t,this.number=void 0,this.numeric=void 0}},pr="[ \\t\\n\\r\\f\\v]*",A1="[+-]?(?:\\d+\\.?\\d*|\\.\\d+)(?:[eE][+-]?\\d+)?",kk=new RegExp(`^${pr}${A1}${pr}$`,"u"),vk=new RegExp(`^${pr}(${A1})`,"u"),O1=new RegExp(`^${pr}([+-])(inf|nan)${pr}$`,"iu"),pu=e=>kk.test(e)||O1.test(e);function E1(e){let t=vk.exec(e);if(t)return Number(t[1]);let n=O1.exec(e);return n?n[2].toLowerCase()==="nan"?Number.NaN:n[1]==="-"?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY:0}var hu=()=>new $("attempt to use an array in a scalar context");function W(e){if(typeof e=="number")return e;if(e===void 0)return 0;if(e instanceof j)return e.number??=E1(e.s);if(typeof e=="string")return E1(e);throw hu()}var Ci=new Map;function I1(e,t){if(Number.isNaN(e))throw new $("formatting signed NaN is not supported",null,"signed NaN");if(!Number.isFinite(e))return e<0?"-inf":"+inf";if(Number.isInteger(e))return Math.abs(e)<2**53?String(e):BigInt(e).toString();let n=Ci.get(t);if(n===void 0){Ci.size>64&&Ci.clear(),n=si(t);let r=n.filter(i=>typeof i!="string");if(r.length>1||r.some(i=>!"diouxXeEfFgG".includes(i.conv)||i.width==="*"||i.precision==="*"))throw new $("this numeric conversion format is not supported",null,"numeric conversion format");Ci.set(t,n)}return n.map(r=>typeof r=="string"?r:Ut(e,r)).join("")}var C1=e=>typeof e=="string"?e:e instanceof j?e.s:"%.6g",Sk=e=>C1(e.globals.get("CONVFMT")),$k=e=>C1(e.globals.get("OFMT"));function F(e,t){if(typeof e=="string")return ft(t,e);if(e instanceof j)return ft(t,e.s);if(typeof e=="number")return I1(e,Sk(t));if(e===void 0)return"";throw hu()}function ft(e,t){if(e.byteLocale&&/[\u0080-\u{10FFFF}]/u.test(t))throw new $("non-ASCII AWK text in a byte locale is not supported",null,"byte locale text");return t}function jt(e,t=!1){return[...e].map(n=>{let r=t?n.toUpperCase():n.toLowerCase();if([...r].length!==1)throw new $("Unicode case expansion is not supported",null,"Unicode case mapping");return r}).join("")}function F1(e,t){return typeof e=="number"?I1(e,$k(t)):F(e,t)}var mu=e=>e.numeric??=pu(e.s),N1=e=>typeof e=="number"||e===void 0||e instanceof j&&mu(e),Be=e=>$e(e.globals.get("IGNORECASE"));function Fi(e,t,n){if(N1(e)&&N1(t)){let o=W(e),s=W(t);return o<s?-1:o>s?1:o===s?0:Number.NaN}let r=F(e,n),i=F(t,n);return Be(n)&&(r=jt(r),i=jt(i)),B(r,i)}function $e(e){if(typeof e=="number")return e!==0&&!Number.isNaN(e);if(typeof e=="string")return e!=="";if(e instanceof j)return mu(e)?W(e)!==0:e.s!=="";if(e===void 0)return!1;throw hu()}var gu=(e,t)=>Number.isSafeInteger(e)?String(e):F(e,t);function wu(e){return e instanceof Map?"array":e===void 0?"untyped":typeof e=="number"?"number":e instanceof j&&mu(e)?"strnum":"string"}function T1(e,t,n){let{text:r}=e;if(e.pos>=r.length)return null;if(t==="")return Ek(e);let i,o;if(t.length===1){let u=r.indexOf(t,e.pos);o=u===-1?r.length:u,i=u===-1?r.length:u+1}else{let u=Wo(r,Fe(t,n),e.pos);o=u?.start??r.length,i=u?.end??r.length}let s=r.slice(e.pos,o);return e.pos=i,{rec:s,rt:r.slice(o,i)}}function Ek(e){let{text:t}=e,n=e.pos;for(;t[n]===`
|
|
232
|
+
`;)n++;if(n>=t.length)return e.pos=n,null;let r=/\n\n+/gu;r.lastIndex=n;let i=r.exec(t);if(!i){e.pos=t.length;let o=t.slice(n).replace(/\n+$/u,"");return{rec:o,rt:t.slice(n+o.length)}}return e.pos=i.index+i[0].length,{rec:t.slice(n,i.index),rt:i[0]}}function xu(e,t,n,r){if(e==="")return[];if(t instanceof at)return jo(e,t);if(t===" "){let o=e.replace(/^[ \t\n]+|[ \t\n]+$/gu,"");return o===""?[]:o.split(/[ \t\n]+/u)}if(t==="")return[...e];if(t.length===1&&(!n||t===`
|
|
233
|
+
`))return e.split(t);if(n&&t==="^")throw new $('paragraph splitting with FS="^" is not supported',null,"paragraph FS caret");let i=t.length===1?`[${"^$.[]|()*+?{}\\".includes(t)?"\\"+t:t}
|
|
234
|
+
]`:t;return jo(e,Fe(i,r))}function _1(e){let t=e.split(/[ \t]+/u).filter(Boolean);return t.map((n,r)=>{let i=/^(?:(\+?\d+):)?(\+?\d+|\*)$/u.exec(n),o=i?.[1]===void 0?0:Number(i[1]),s=i?.[2]==="*"?4294967295:Number(i?.[2]);if(!i||i[1]!==void 0&&o===0||o>4294967295||!(s>0&&s<=4294967295)||i[2]==="*"&&r!==t.length-1)throw new $(`invalid FIELDWIDTHS value \`${e}'`);return{skip:o,width:s}})}function Nk(e,t){let n=[...e],r=[],i=0;for(let{skip:o,width:s}of t){if(i>=n.length)break;i+=o,r.push(n.slice(i,i+s).join("")),i+=s}return r}function Ak(e,t){let n=[],r=0;for(;r<e.length;){let i=t.search(e.slice(r));if(n.length>0&&i?.end===0&&(r+=Ie(e,r),i=t.search(e.slice(r))),!i)break;n.push(e.slice(r+i.start,r+i.end)),r+=i.end}return n}function L1(e,t){let n=Be(e);return e.fieldMode==="FIELDWIDTHS"?Nk(t,e.widths):e.fieldMode==="FPAT"?Ak(t,Fe(F(e.globals.get("FPAT"),e),n,e.warn)):xu(t,F(e.globals.get("FS"),e),F(e.globals.get("RS"),e)==="",n)}var Ok=/^([A-Za-z_][A-Za-z0-9_]*)=([^]*)$/u,yu=e=>e!==void 0&&e.type==="exit",Ti=class{constructor(t,n){this.ctx=t,this.stdin=n,this.idx=1,this.src=null,this.sawFile=!1,this.exitSignal=void 0,this.readers=new Map}next(t){for(;this.exitSignal===void 0;){if(this.src){let n=T1(this.src,F(t.globals.get("RS"),t),Be(t));if(n!==null)return t.globals.set("NR",W(t.globals.get("NR"))+1),t.globals.set("FNR",W(t.globals.get("FNR"))+1),t.globals.set("RT",n.rt),n.rec;this.closeFile(t);continue}if(!this.open(t))return null}return null}open(t){for(;this.idx<Math.trunc(W(t.globals.get("ARGC")));){if(++t.steps>Mn)throw new $("input operand scan exceeded execution limit",null,"execution limit");let n=F(t.globals.get("ARGV").get(String(this.idx++)),t);if(n==="")continue;t.globals.set("ARGIND",this.idx-1);let r=Ok.exec(n);if(r){t.assign(r[1],new j(ar(r[2],t.warn)));continue}this.sawFile=!0;let{text:i,error:o}=this.readOperand(n);if(o==="Is a directory"){this.failFile(t,n,o),this.exitSignal===void 0&&t.warn(`command line argument \`${n}' is a directory: skipped`);continue}if(o){let s=this.failFile(t,n,o);if(s!==void 0&&s.type==="nextfile")continue;if(this.exitSignal!==void 0)return!1;throw new $(`${n}: ${o}`)}if(this.use(t,n,i))return!0}return this.sawFile||this.exitSignal!==void 0?!1:(this.sawFile=!0,this.use(t,"-",this.takeStdin()))}readOperand(t){if(t==="/dev/null")return{text:""};if(t==="-"||t==="/dev/stdin")return{text:t==="/dev/stdin"&&this.ctx.stdinFile?this.ctx.stdinOrigin:this.takeStdin()};let{path:n,error:r}=R(this.ctx,"awk",t);return this.ctx.fs.isDir(n)?{error:"Is a directory"}:r?{error:r}:{text:this.ctx.fs.readFile(n)}}takeStdin(){let t=this.stdin;return this.stdin="",X(this.ctx),t}use(t,n,r){this.src={text:r,pos:0},t.globals.set("FILENAME",n),t.globals.set("FNR",0),t.globals.set("ERRNO","");let i=t.fileRule("begin");return yu(i)?(this.exitSignal=i,this.src=null,!1):i!==void 0&&i.type==="nextfile"?(this.closeFile(t),!1):(ft(t,r),!0)}failFile(t,n,r){if(t.globals.set("ERRNO",r),!t.hasFileRules)return;t.globals.set("FILENAME",n),t.globals.set("FNR",0);let i=t.fileRule("begin");return yu(i)&&(this.exitSignal=i),i}closeFile(t){this.src=null;let n=t.fileRule("end");yu(n)&&(this.exitSignal=n)}readNamed(t,n){let r=this.readers.get(n);if(!r){let{text:o,error:s}=this.readOperand(n);if(s)return t.globals.set("ERRNO",s),{status:-1};r={text:ft(t,o),pos:0},this.readers.set(n,r)}let i=T1(r,F(t.globals.get("RS"),t),Be(t));return i===null?{status:0}:(t.globals.set("RT",i.rt),{status:1,record:i.rec})}close(t,n){return this.readers.delete(n)?0:(t.globals.set("ERRNO","close of redirection that was never opened"),-1)}};var Ik=(e,t)=>({isRef:!0,scope:e,name:t}),hr=e=>typeof e=="object"&&e!==null&&e.isRef===!0,mr=class extends Error{constructor(t){super(t.type),this.signal=t}},P1=e=>new $(`attempt to use array \`${e}\` in a scalar context`);function _i(e,t){let n=e.frame;return n!==void 0&&n.has(t)?n:e.globals}function Ck(e){let t=e;for(;hr(t);)t=t.scope.get(t.name);return t instanceof Map?t:void 0}function hn(e,t){let n=_i(e,t).get(t);return hr(n)?Ck(n):n}var Fk=new Set(["FS","FIELDWIDTHS","FPAT"]);function Li(e,t,n){let r=_i(e,t);if(r.get(t)instanceof Map)throw P1(t);if(r===e.globals){if(t==="NF"){_k(e,n);return}if(t==="FIELDWIDTHS"&&(e.widths=_1(F(n,e))),(t==="FPAT"||(t==="FS"||t==="RS")&&F(n,e).length>1)&&Fe(F(n,e),Be(e),e.warn,e.tables),Fk.has(t)){e.fieldMode=t;let i=e.globals.get("PROCINFO");i instanceof Map&&i.set("FS",t)}}r.set(t,n)}function ct(e,t){let n=_i(e,t),r=t,i=n,o=i.get(r);if(o instanceof Map)return o;let s=hr(o);for(;hr(o);)i=o.scope,r=o.name,o=i.get(r);if(!(o instanceof Map)){if(o!==void 0)throw new $(`attempt to use scalar \`${r}\` as an array`);o=new Map,i.set(r,o)}return s&&n.set(t,o),o}function Ri(e,t,n=new j(t)){e.record=t,e.recordValue=n,e.fields=[void 0,...L1(e,t).map(r=>new j(r))],e.nf=e.fields.length-1,e.globals.set("NF",e.nf)}function D1(e){let t=F(e.globals.get("OFS"),e);e.record=e.fields.slice(1).map(n=>F(n,e)).join(t),e.recordValue=e.record}function U1(e,t){return t===0?e.recordValue:t<=e.nf?e.fields[t]:void 0}function Tk(e,t,n){if(t===0){let r=F(n,e);Ri(e,r,typeof n=="number"?r:n);return}for(;e.nf<t;)e.fields[++e.nf]="";e.fields[t]=n,e.globals.set("NF",e.nf),D1(e)}function _k(e,t){let n=Math.trunc(W(t));if(n<0)throw new $(`NF set to negative value ${n}`);for(;e.nf<n;)e.fields[++e.nf]="";e.fields.length=n+1,e.nf=n,e.globals.set("NF",n),D1(e)}function B1(e,t){let n=W(I(e,t));if(!(n>=0))throw new $(`attempt to access field ${Number.isNaN(n)?n:Math.trunc(n)}`);return Math.trunc(n)}function gr(e,t){if(t.length===1)return gu(I(e,t[0]),e);let n=F(e.globals.get("SUBSEP"),e);return t.map(r=>gu(I(e,r),e)).join(n)}function ku(e,t){return t.type==="var"?t:t.type==="index"?{type:"index",arr:ct(e,t.name),key:gr(e,t.subs)}:{type:"field",i:B1(e,t.index)}}function q1(e,t){return t.type==="var"?W1(hn(e,t.name),t.name):t.type==="index"?t.arr.get(t.key):U1(e,t.i)}function vu(e,t,n){t.type==="var"?Li(e,t.name,n):t.type==="index"?t.arr.set(t.key,n):Tk(e,t.i,n)}function Su(e,t,n){vu(e,ku(e,t),n)}function R1(e,t,n){if(n===0&&(e==="/"||e==="%"))throw new $(e==="/"?"division by zero attempted":"division by zero attempted in `%`");return Hr(e,t,n)}var Lk={__proto__:null,"<":e=>e<0,"<=":e=>e<=0,"==":e=>e===0,"!=":e=>e!==0,">":e=>e>0,">=":e=>e>=0};function dt(e,t){let n=Be(e);return t.type==="regex"?n?Fe(t.source,!0,null,e.tables):t.re:Fe(F(I(e,t),e),n,e.warn,e.tables)}function W1(e,t){if(e instanceof Map)throw P1(t);return e}function M1(e,t,n){let r=ku(e,t.target),i=W(q1(e,r)),o=t.op==="++"?i+1:i-1;return vu(e,r,o),n?i:o}function I(e,t){switch(t.type){case"num":case"str":return t.value;case"regex":return dt(e,t).test(e.record)?1:0;case"var":return W1(hn(e,t.name),t.name);case"index":{let n=ct(e,t.name),r=gr(e,t.subs),i=n.get(r);return i===void 0&&n.set(r,void 0),i}case"field":return U1(e,B1(e,t.index));case"assign":{let n=ku(e,t.target),r=I(e,t.value);if(r instanceof Map)throw new $("attempt to use an array in a scalar context");return t.op!=="="&&(r=R1(t.op[0],W(q1(e,n)),W(r))),vu(e,n,r),r}case"cond":return I(e,$e(I(e,t.test))?t.consequent:t.alternate);case"or":return $e(I(e,t.left))||$e(I(e,t.right))?1:0;case"and":return $e(I(e,t.left))&&$e(I(e,t.right))?1:0;case"not":return $e(I(e,t.expr))?0:1;case"neg":return-W(I(e,t.expr));case"plus":return W(I(e,t.expr));case"binary":return R1(t.op,W(I(e,t.left)),W(I(e,t.right)));case"concat":return F(I(e,t.left),e)+F(I(e,t.right),e);case"compare":return Lk[t.op](Fi(I(e,t.left),I(e,t.right),e))?1:0;case"match":{let n=F(I(e,t.left),e);return dt(e,t.right).test(n)===t.negate?0:1}case"in":return ct(e,t.array).has(gr(e,t.keys))?1:0;case"preinc":return M1(e,t,!1);case"postinc":return M1(e,t,!0);case"call":return Rk(e,t);case"builtin":return e.callBuiltin(e,t);case"getline":return Pk(e,t);default:throw new $(`unknown expression: ${t.type}`)}}function Rk(e,t){let n=e.program.functions.get(t.name);if(n===void 0)throw new $(`function \`${t.name}\` not defined`);if(t.args.length>n.params.length)throw new $(`function \`${t.name}\` called with ${t.args.length} arguments, but it accepts only ${n.params.length}`);if(e.callDepth>=Do)throw new $(`function call nesting deeper than ${Do} levels (runaway recursion?)`,null,"call depth limit");let r=e.frame,i=new Map;for(let o=0;o<n.params.length;o++)i.set(n.params[o],o<t.args.length?Mk(e,t.args[o]):void 0);e.frame=i,e.callDepth++;try{let o=e.execStmts(e,n.body);if(o===void 0||o.type==="return")return o?.value;throw new mr(o)}finally{e.frame=r,e.callDepth--}}function Mk(e,t){if(t.type!=="var")return I(e,t);let n=_i(e,t.name),r=n.get(t.name);return r instanceof Map||hr(r)?r:r===void 0?Ik(n,t.name):r}function Pk(e,t){let n;if(t.file===null){if(n=e.input.next(e),n===null)return 0}else{let r=e.input.readNamed(e,F(I(e,t.file),e));if(r.status!==1)return r.status;n=r.record}return t.target===null?Ri(e,n):Su(e,t.target,new j(n)),1}var Je=(e,t)=>W(I(e,t)),$u=2**32;function z1(e){return Number(BigInt.asUintN(32,BigInt(Math.trunc(e))))}var H1=()=>({seed:1,state:z1(1)});function Dk(e){e.rng.state=(e.rng.state+1831565813)%$u;let t=e.rng.state;t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61);let n=t^t>>>14;return(n<0?n+$u:n)/$u}function Uk(e,t){let n=e.rng.seed,r=t.length>0?Je(e,t[0]):Math.floor(Date.now()/1e3);return e.rng.seed=r,e.rng.state=z1(r),n}function Bk(e,t){let n=Je(e,t[0]);return n<0&&e.warn(`log: received negative argument ${F(n,e)}`),Math.log(n)}function qk(e,t){let n=Je(e,t[0]);return n<0&&e.warn(`sqrt: called with negative argument ${F(n,e)}`),Math.sqrt(n)}function Wk(e,t){let n=Je(e,t[0]),r=Math.exp(n);return Number.isFinite(n)&&!Number.isFinite(r)&&e.warn(`exp: argument ${F(n,e)} is out of range`),r}function jk(e,t){let n=I(e,t[0]);if(typeof n=="number")return n;let r=n instanceof j?n.s:F(n,e),i=/^0[xX]([0-9a-fA-F]*)/u.exec(r);if(i)return i[1]===""?0:Number.parseInt(i[1],16);let o=/^0[0-7]+(?![.\deE0-9])/u.exec(r);return o?Number.parseInt(o[0],8):W(new j(r))}function wr(e,t,n,r){let i=Je(e,n);if(i<0)throw new $(`${t}: argument ${r} negative value ${F(i,e)} is not allowed`);if(!Number.isFinite(i))throw new $(`${t}: argument ${r} is not a finite number`);return BigInt.asUintN(64,BigInt(Math.trunc(i)))}function Nu(e){let t=e;for(;t>0n&&BigInt(Number(t))!==t;)t&=(1n<<BigInt(t.toString(2).length-1))-1n;return Number(t)}function Eu(e,t){return(n,r)=>{if(r.length<2)throw new $(`${e}: called with less than two arguments`);let i=wr(n,e,r[0],1);for(let o=1;o<r.length;o++)i=t(i,wr(n,e,r[o],o+1));return Nu(i)}}function j1(e,t){return(n,r)=>{let i=wr(n,e,r[0],1),o=wr(n,e,r[1],2)%64n;return Nu(BigInt.asUintN(64,t?i<<o:i>>o))}}var G1={__proto__:null,sin:(e,t)=>Math.sin(Je(e,t[0])),cos:(e,t)=>Math.cos(Je(e,t[0])),atan2:(e,t)=>Math.atan2(Je(e,t[0]),Je(e,t[1])),exp:Wk,log:Bk,sqrt:qk,int:(e,t)=>Math.trunc(Je(e,t[0])),rand:Dk,srand:Uk,systime:()=>Math.floor(Date.now()/1e3),strtonum:jk,and:Eu("and",(e,t)=>e&t),or:Eu("or",(e,t)=>e|t),xor:Eu("xor",(e,t)=>e^t),lshift:j1("lshift",!0),rshift:j1("rshift",!1),compl:(e,t)=>Nu(BigInt.asUintN(64,~wr(e,"compl",t[0],1)))};var Mi=new Map;function zk(e){let t=Mi.get(e);return t||(Mi.size>=256&&Mi.clear(),t=si(e),Mi.set(e,t)),t}function Pi(e,t,n){let r=0,i=()=>{if(r>=n.length)throw new $("printf: not enough arguments to satisfy format string");return n[r++]},o="";for(let s of zk(t)){if(typeof s=="string"){o+=s;continue}let u={...s};if(s.width==="*"){let a=Math.trunc(W(i()));a<0?(u.minus=!0,u.width=-a):u.width=a}if(s.precision==="*"){let a=Math.trunc(W(i()));u.precision=a<0?null:a}if(u.width>Ee||u.precision>Ee)throw new $(`printf: field width or precision above ${Ee} is not supported`,null,"format size limit");o+=Hk(e,u,i())}return o}function Hk(e,t,n){if(t.conv==="s"){let r=F(n,e);return t.precision!==null&&(r=[...r].slice(0,t.precision).join("")),$t("",r,t,!1)}return t.conv==="c"?$t("",ft(e,Gk(n)),t,!1):Ut(W(n),t)}function Gk(e){if(typeof e=="number"||e instanceof j&&pu(e.s)){let r=Math.trunc(W(e));if(!Xe(r))throw new $("printf: character code outside Unicode scalar values is not supported",null,"character code");return String.fromCodePoint(r)}let n=e instanceof j?e.s:e??"";return n===""?"\0":String.fromCodePoint(n.codePointAt(0))}var me=(e,t)=>F(I(e,t),e),X1=(e,t)=>W(I(e,t)),Xk={type:"field",index:{type:"num",value:0}};function Zk(e,t){let n="";for(let r=0;r<e.length;r++){let i=e[r];if(i==="\\"){if(e[r+1]==="\\"&&e[r+2]==="\\"&&(e[r+3]==="&"||e[r+3]==="\\")){n+="\\"+e[r+3],r+=3;continue}if(e[r+1]==="\\"&&e[r+2]==="&"){n+="\\"+t,r+=2;continue}if(e[r+1]==="&"){n+="&",r++;continue}}n+=i==="&"?t:i}return n}function Z1(e,t,n){let r=dt(e,t[0]),i=me(e,t[1]),o=t[2]??Xk,s=me(e,o),{out:u,count:a}=Pn(s,r,(l,f)=>Zk(i,s.slice(l,f)),n?"global":"first");return a>0&&Su(e,o,u),a}function Yk(e,t){let n="";for(let r=0;r<e.length;r++){let i=e[r];if(i==="\\"&&r+1===e.length)throw new $("gensub with a trailing replacement backslash is not supported",null,"gensub trailing backslash");if(i==="\\"&&r+1<e.length){let o=e[++r];o>="0"&&o<="9"?n+=t[Number(o)]?.text??"":n+=o;continue}n+=i==="&"?t[0].text:i}return n}function Vk(e,t){let n=dt(e,t[0]),r=me(e,t[1]),i=I(e,t[2]),o=F(i,e),s=o.startsWith("g")||o.startsWith("G"),u=0;s||(u=Math.trunc(W(i)),u<1&&(e.warn(`gensub: third argument \`${o}' treated as 1`),u=1));let a=t[3]?me(e,t[3]):e.record,l=/(?:^|[^\\])(?:\\\\)*\\[1-9]/u.test(r);return Pn(a,n,(f,c,d)=>!s&&d!==u?null:Yk(r,l?n.groups(a,f,c):[{text:a.slice(f,c)}]),s?"global":"nth").out}function Kk(e,t){let n=me(e,t[0]),r=dt(e,t[1]),i=r.search(n,0),o=i?Array.from(n.slice(0,i.start)).length+1:0;if(e.globals.set("RSTART",o),e.globals.set("RLENGTH",i?Array.from(n.slice(i.start,i.end)).length:-1),t[2]){let s=ct(e,t[2].name);if(s.clear(),i){let u=F(e.globals.get("SUBSEP"),e);r.groups(n,i.start,i.end).forEach((a,l)=>{a!==void 0&&(s.set(String(l),new j(a.text)),s.set(`${l}${u}start`,Array.from(n.slice(0,a.start)).length+1),s.set(`${l}${u}length`,[...a.text].length))})}}return o}function Jk(e,t){let n=me(e,t[0]),r=ct(e,t[1].name),i;t[2]===void 0?i=F(e.globals.get("FS"),e):t[2].type==="regex"?i=dt(e,t[2]):i=me(e,t[2]);let o=xu(n,i,!1,Be(e));return r.clear(),o.forEach((s,u)=>r.set(String(u+1),new j(s))),o.length}function Qk(e,t){let n=[...me(e,t[0])],r=Math.trunc(X1(e,t[1])),i=Number.isNaN(r)?1:Math.max(r,1),o=n.length+1;if(t[2]){let s=Math.trunc(X1(e,t[2]));if(!(s>=1))return"";o=Math.min(o,i+s)}return o>i?n.slice(i-1,o-1).join(""):""}function ev(e,t){if(t.length===0)return[...e.record].length;if(t[0].type==="var"){let n=hn(e,t[0].name);return n instanceof Map?n.size:[...F(n,e)].length}return[...me(e,t[0])].length}function tv(e,t){let n=me(e,t[0]),r=me(e,t[1]);Be(e)&&(n=jt(n),r=jt(r));let i=n.indexOf(r);return i<0?0:Array.from(n.slice(0,i)).length+1}function nv(e,t){let n=me(e,t[0]);return n==="/dev/stdout"||n==="/dev/stderr"||n==="/dev/null"?0:e.input.close(e,n)}var rv=(e,t)=>t[0].type==="var"?wu(hn(e,t[0].name)):wu(I(e,t[0])),iv={__proto__:null,...G1,length:ev,substr:Qk,index:tv,split:Jk,sub:(e,t)=>Z1(e,t,!1),gsub:(e,t)=>Z1(e,t,!0),gensub:Vk,match:Kk,sprintf:(e,t)=>Pi(e,me(e,t[0]),t.slice(1).map(n=>I(e,n))),tolower:(e,t)=>jt(me(e,t[0])),toupper:(e,t)=>jt(me(e,t[0]),!0),close:nv,fflush:()=>0,typeof:rv,isarray:(e,t)=>t[0].type==="var"&&hn(e,t[0].name)instanceof Map?1:0};function Y1(e,t){let n=iv[t.name];if(!n)throw new $(`function \`${t.name}\` is not supported`,null,`${t.name}()`);return n(e,t.args)}var Ui={type:"break"},Ou={type:"continue"},ov={type:"next"},sv={type:"nextfile"},uv={type:"exit"};function V1(e,t,n,r){let i=new Map([["0","awk"]]);r.forEach((u,a)=>i.set(String(a+1),new j(u)));let o=new Map([["FS"," "],["OFS"," "],["ORS",`
|
|
224
235
|
`],["RS",`
|
|
225
|
-
`],["RT",""],["NR",0],["NF",0],["FNR",0],["FILENAME",""],["SUBSEP",""],["CONVFMT","%.6g"],["OFMT","%.6g"],["RSTART",0],["RLENGTH",-1],["ERRNO",""],["IGNORECASE",0],["FIELDWIDTHS",""],["FPAT","[^[:space:]]+"],["ENVIRON",new
|
|
226
|
-
`),fileRule:u=>
|
|
227
|
-
`),a=2,
|
|
228
|
-
`),operands:t}}function
|
|
229
|
-
`,f
|
|
230
|
-
`,exitCode:124};if(
|
|
231
|
-
`)throw
|
|
232
|
-
`?(r&&t.push(i),i="",r=!1):(i+=s,r=!0)}if(n)throw
|
|
236
|
+
`],["RT",""],["NR",0],["NF",0],["FNR",0],["FILENAME",""],["SUBSEP",""],["CONVFMT","%.6g"],["OFMT","%.6g"],["RSTART",0],["RLENGTH",-1],["ERRNO",""],["IGNORECASE",0],["FIELDWIDTHS",""],["FPAT","[^[:space:]]+"],["ENVIRON",new Di("ENVIRON")],["PROCINFO",new Di("PROCINFO",[["FS","FS"]])],["ARGC",r.length+1],["ARGV",i],["ARGIND",0]]),s={program:e,globals:o,frame:void 0,callDepth:0,record:"",recordValue:new j(""),fields:[void 0],nf:0,fieldMode:"FS",out:[],errOut:[],steps:0,exitCode:0,ranges:[],rng:H1(),input:new Ti(t,n),byteLocale:ae(t),tables:Q(t.locale),hasFileRules:e.beginFile.length>0,callBuiltin:Y1,execStmts:Bi,assign:(u,a)=>Li(s,u,a),warn:u=>s.errOut.push(`awk: warning: ${u}
|
|
237
|
+
`),fileRule:u=>av(s,u)};return s}var Di=class extends Map{constructor(t,n=[]){super(n),this.systemName=t}check(t){if(!this.systemName||this.systemName==="PROCINFO"&&t==="FS")return;let n=this.systemName==="ENVIRON"?"ENVIRON":`PROCINFO[${t??"*"}]`;throw new $(`${n} is not supported without the corresponding environment or process metadata`,null,n)}get(t){return this.check(t),super.get(t)}has(t){return this.check(t),super.has(t)}set(t,n){return this.check(t),super.set(t,n)}delete(t){return this.check(t),super.delete(t)}clear(){return this.check(),super.clear()}get size(){return this.check(),super.size}keys(){return this.check(),super.keys()}values(){return this.check(),super.values()}entries(){return this.check(),super.entries()}[Symbol.iterator](){return this.check(),super[Symbol.iterator]()}};function K1(e){let{program:t}=e,n=Au(e,t.begin,"BEGIN"),r=t.rules.length>0||t.end.length>0||t.beginFile.length>0||t.endFile.length>0;return!J1(n)&&r&&lv(e),Au(e,t.end,"END"),e.exitCode}var J1=e=>e!==void 0&&e.type==="exit";function Au(e,t,n){let r=Q1(e,t);if(r!==void 0&&(r.type==="next"||r.type==="nextfile"&&(n==="BEGIN"||n==="END")))throw new $(`\`${r.type}' cannot be called from a ${n} rule`);return r}function av(e,t){let n=t==="begin"?e.program.beginFile:e.program.endFile;return n.length===0?void 0:Au(e,n,t==="begin"?"BEGINFILE":"ENDFILE")}function lv(e){for(;;){let t=e.input.next(e);if(t===null)return e.input.exitSignal;Ri(e,t);let n=fv(e);if(J1(n))return n;n!==void 0&&n.type==="nextfile"&&e.input.closeFile(e)}}function fv(e){let{rules:t}=e.program;for(let n=0;n<t.length;n++){let r=t[n];if(!cv(e,r,n))continue;if(r.action===null){Iu(e,null,e.record+F(e.globals.get("ORS"),e));continue}let i=Q1(e,r.action);if(i!==void 0)return i}}function Q1(e,t){try{return Bi(e,t)}catch(n){if(!(n instanceof mr))throw n;return n.signal}}function cv(e,t,n){let{pattern:r}=t;if(r===null)return!0;if(r.type!=="range")return $e(I(e,r));if(!e.ranges[n]){if(!$e(I(e,r.from)))return!1;e.ranges[n]=!0}return $e(I(e,r.to))&&(e.ranges[n]=!1),!0}function Bi(e,t){for(let n of t){let r=br(e,n);if(r!==void 0)return r}}function br(e,t){if(++e.steps>Mn)throw new $(`execution stopped after ${Mn} statements (infinite loop?)`,null,"execution limit");switch(t.type){case"block":return Bi(e,t.body);case"empty":return;case"expr":I(e,t.expr);return;case"print":return mv(e,t);case"printf":return gv(e,t);case"if":return $e(I(e,t.test))?br(e,t.consequent):t.alternate===null?void 0:br(e,t.alternate);case"while":case"do":case"for":return dv(e,t);case"forin":return pv(e,t);case"switch":return hv(e,t);case"break":return Ui;case"continue":return Ou;case"next":return ov;case"nextfile":return sv;case"exit":return wv(e,t);case"return":return{type:"return",value:t.value===null?void 0:I(e,t.value)};case"delete":{let n=ct(e,t.name);t.subs===null?n.clear():n.delete(gr(e,t.subs));return}default:throw new $(`unknown statement: ${t.type}`)}}function dv(e,t){t.init&&I(e,t.init);let n=!0;for(;t.type==="do"&&n||t.test===null||$e(I(e,t.test));){n=!1;let r=br(e,t.body);if(r===Ui)return;if(r!==void 0&&r!==Ou)return r;t.step&&I(e,t.step)}}function pv(e,t){let n=ct(e,t.array);for(let r of Array.from(n.keys())){Li(e,t.name,new j(r));let i=br(e,t.body);if(i===Ui)return;if(i!==void 0&&i!==Ou)return i}}function hv(e,t){let n=I(e,t.expr),r=o=>o.test.type==="regex"?dt(e,o.test).test(F(n,e)):Fi(n,o.test.value,e)===0,i=t.cases.findIndex(o=>o.test!==null&&r(o));if(i===-1&&(i=t.cases.findIndex(o=>o.test===null)),i!==-1)for(let o=i;o<t.cases.length;o++){let s=Bi(e,t.cases[o].body);if(s===Ui)return;if(s!==void 0)return s}}function Iu(e,t,n){if(t===null){e.out.push(n);return}let r=F(I(e,t),e);if(r==="/dev/stdout")e.out.push(n);else if(r==="/dev/stderr")e.errOut.push(n);else if(r!=="/dev/null")throw new $(du(r),null,"output redirection")}function mv(e,t){let n=F(e.globals.get("ORS"),e),r;if(t.args.length===0)r=e.record;else{let i=F(e.globals.get("OFS"),e);r=t.args.map(o=>F1(I(e,o),e)).join(i)}Iu(e,t.dest,r+n)}function gv(e,t){let n=t.args.map(r=>I(e,r));Iu(e,t.dest,Pi(e,F(n[0],e),n.slice(1)))}function wv(e,t){if(t.value!==null){let n=Math.trunc(W(I(e,t.value)));e.exitCode=(n%256+256)%256}return uv}var bv="awk [-F fs] [-v var=value] 'program' [file ...] | awk [-F fs] [-v var=value] -f progfile [file ...]",yv=/^([A-Za-z_][A-Za-z0-9_]*)=([^]*)$/u;function eh(e,t,n){let{values:r,positional:i}=N(kv(t),{valueShort:["F"],repeatable:["v","f"],stopAtFirstPositional:!0}),o=vv(r.get("f")??[],i,n);if(o.error)return o.error;let s;try{ft({byteLocale:ae(n)},o.text),s=$1(o.text)}catch(c){if(c instanceof RangeError)return k("feature","awk","parser depth limit",`awk: program too deeply nested (${c.message})`);if(O(c))return Y(c,"awk",`awk: ${c.message}`);if(!(c instanceof $))throw c;let d=c.line===null?`awk: ${c.message}`:`awk: syntax error at line ${c.line}: ${c.message}`;return c.gap===null?y(d):k("feature","awk",c.gap,d)}let u=V1(s,n,e,o.operands);for(let c of s.warnings)u.warn(c);let a,l=null;try{r.has("F")&&u.assign("FS",ar(r.get("F"),u.warn));for(let c of r.get("v")??[]){let d=yv.exec(c);if(!d)return y(`awk: -v: expected var=value but got \`${c}\``);u.assign(d[1],new j(ar(d[2],u.warn)))}a=K1(u)}catch(c){let d=O(c);if(!(c instanceof $)&&!(c instanceof RangeError)&&!d)throw c;u.errOut.push(`awk: ${c.message}
|
|
238
|
+
`),a=2,c instanceof RangeError&&(l={detail:"runtime limit",message:`awk: ${c.message}`}),c.gap&&(l={detail:c.gap,message:`awk: ${c.message}`}),d&&(l={detail:d.detail,message:`awk: ${c.message}`})}let f={stdout:u.out.join(""),stderr:u.errOut.join(""),exitCode:a};return l===null?f:re(f,"feature","awk",l.detail,l.message)}var xv=/^-[Fvf]\S*\s/su;function kv(e){let t=[];for(let n=0;n<e.length;n++){let r=e[n];if(r==="-F"||r==="-v"||r==="-f"){t.push(r),n+1<e.length&&t.push(e[++n]);continue}if(xv.test(r)){t.push(r.slice(0,2),r.slice(2));continue}if(!r.startsWith("-")||r==="-"||r==="--"){t.push(...e.slice(n));break}t.push(r)}return t}function vv(e,t,n){if(e.length===0)return t.length===0?{error:de(bv,2)}:{text:t[0],operands:t.slice(1)};let r=[];for(let i of e){let{path:o,error:s}=R(n,"awk",i);if(s||!n.fs.isFile(o))return{error:y(`awk: cannot open program file \`${i}\`: ${s??"Is a directory"}`,2)};r.push(n.fs.readFile(o))}return{text:r.join(`
|
|
239
|
+
`),operands:t}}function nh(e,t,n){let{flags:r,values:i,positional:o}=N(t,{short:["n","r","u","f","b","z"],valueShort:["t","o"],valueLong:["output"],repeatable:["k","o","output"]}),s=[...i.get("o")??[],...i.get("output")??[]];if(s.length>1)return y("sort: multiple output files specified",2);let u=i.get("t");if(u!==void 0&&A(u).length!==1)return y(`sort: multi-character tab '${u}'`,2);let a={n:r.has("n"),f:r.has("f"),b:r.has("b"),r:r.has("r")},l=Iv(i.get("k")??[],a);if(l.error)return l.error;let f=se("sort",o,e,n,{stopOnError:!0});if(f.failed)return{stdout:"",stderr:f.stderr,exitCode:2};let c=r.has("z")?"\0":`
|
|
240
|
+
`,d=f.inputs.flatMap(({content:g})=>pe(g,c)),p=l.specs.length?l.specs:[{start:1,...a}],h=_v(d,p,u,r.has("u"),a.r),m=he(h,c);return s.length===0?ee(m,f):Sv(s[0],m,n,f)}function Sv(e,t,n,r){if(e==="/dev/null")return ee("",r);if(e==="/dev/stdout")return ee(t,r);n.io?.setReads([]);let i;try{i=n.writable&&n.fs.openWritable(n.cwd,e),i&&i.write(t)}catch(o){return L(n,"sort",o?.path,o?.fsError),Y(o,"sort",`sort: open failed: ${o.message}`,2)}return i?ee("",r):k("feature","sort","-o",`sort: open failed: ${e}: Read-only file system`,2)}var $v="nrfb",Ev="bdfghiMnRrV",Nv=/^[ \t]*\+?(\d+)/u,Av=(e,t)=>y(`sort: ${e}: invalid count at start of '${t}'`,2),qi=(e,t)=>y(`sort: ${e}: invalid field specification '${t}'`,2);function Ov(e){let t=0,n=null,r=u=>{let a=Nv.exec(e.slice(t));return a===null?(n=Av(u,e.slice(t)),null):(t+=a[0].length,Number(a[1]))},i=u=>{let a=r(u);if(a===null)return null;let l=null;if(e[t]==="."&&(t++,l=r("invalid number after '.'"),l===null))return null;let f=t;for(;t<e.length&&/[a-zA-Z]/u.test(e[t]);)t++;return{field:a,offset:l,mods:e.slice(f,t)}},o=i("invalid number at field start");if(o===null)return{error:n};let s=null;return e[t]===","&&(t++,s=i("invalid number after ','"),s===null)?{error:n}:o.field===0||s?.field===0?{error:qi("field number is zero",e)}:o.offset===0?{error:qi("character offset is zero",e)}:t!==e.length?{error:qi("stray character in field spec",e)}:{from:o,to:s}}function Iv(e,t){let n=[];for(let r of e){let i=Ov(r);if(i.error)return{error:i.error};let{from:o,to:s}=i,u=o.mods+(s?.mods??"");for(let l of u)if(!$v.includes(l))return Ev.includes(l)?{error:k("option","sort",`-k${r}`,`sort: unknown key option \`${l}\` in ${r}`,2)}:{error:qi("stray character in field spec",r)};if(o.offset!==null||(s?.offset??0)!==0)return{error:k("option","sort",`-k${r}`,`sort: invalid key specification: ${r} (character offsets are not supported)`,2)};let a=u.length>0;n.push({start:o.field,end:s?.field,n:a?u.includes("n"):t.n,r:a?u.includes("r"):t.r,f:a?u.includes("f"):t.f,b:a?o.mods.includes("b"):t.b})}return{specs:n}}function Cv(e,t){let n=[];if(t!==void 0){let i=0;for(;;){let o=e.indexOf(t,i);if(o===-1){n.push([i,e.length]);break}n.push([i,o]),i=o+t.length}return n}let r=0;do{let i=r;for(;r<e.length&&/[ \t]/u.test(e[r]);)r++;for(;r<e.length&&!/[ \t]/u.test(e[r]);)r++;n.push([i,r])}while(r<e.length);return n}function Fv(e,t,n){if(t.start>n.length)return"";let r=n[t.start-1][0],i=t.end===void 0||t.end>n.length?e.length:n[t.end-1][1];if(t.b)for(;r<i&&/[ \t]/u.test(e[r]);)r++;return e.slice(r,Math.max(r,i))}var Tv=e=>e.replace(/[a-z]/gu,t=>t.toUpperCase());function _v(e,t,n,r,i){let o=t.every(l=>l.start===1&&l.end===void 0);if(o&&t.length===1&&!t[0].n&&!t[0].f&&!t[0].b)return e.sort(e.some(l=>/[\u{10000}-\u{10FFFF}]/u.test(l))?B:void 0),t[0].r&&e.reverse(),r?e.filter((l,f)=>f===0||l!==e[f-1]):e;let s=e.map(l=>{let f=o?[[0,l.length]]:Cv(l,n);return{line:l,keys:t.map(c=>{let d=Fv(l,c,f);return c.n?Lv(d):c.f?Tv(d):d})}}),u=(l,f)=>{for(let c=0;c<t.length;c++){let d=t[c],p=d.n?Rv(l.keys[c],f.keys[c]):B(l.keys[c],f.keys[c]);if(p!==0)return d.r?-p:p}return r?0:(i?-1:1)*B(l.line,f.line)};s.sort(u);let a=[];for(let l=0;l<s.length;l++)r&&l>0&&u(s[l-1],s[l])===0||a.push(s[l].line);return a}function Lv(e){let t=/^[ \t]*(-?)(?:(\d+)(?:\.(\d*))?|\.(\d+))/u.exec(e),n=(t?.[2]??"").replace(/^0+/u,"")||"0",r=(t?.[3]??t?.[4]??"").replace(/0+$/u,"");return{integer:n,fraction:r,negative:t?.[1]==="-"&&(n!=="0"||r!=="")}}var th=(e,t)=>e<t?-1:e>t?1:0;function Rv(e,t){if(e.negative!==t.negative)return e.negative?-1:1;let n=e.integer.length-t.integer.length||th(e.integer,t.integer)||th(e.fraction,t.fraction);return e.negative?-n:n}async function ih(e,t,n){let{flags:r,values:i,positional:o}=N(t,{short:["r","0"],valueShort:["n","I"],stopAtFirstPositional:!0}),[s="echo",...u]=o,a=i.get("I"),l=i.has("n")?we(i.get("n"),"xargs: -n"):{value:void 0};if(l.error)return l.error;if(l.value===0)return y("xargs: -n: must be at least 1");if(a==="")return y("xargs: -I: replacement string must not be empty");if(a!==void 0&&l.value!==void 0)return k("option","xargs","-I -n","xargs: combining replacement and chunk limits is not supported");if(X(n),!r.has("0")&&e.includes("\0"))return k("feature","xargs","NUL input","xargs: NUL input requires -0");let f;if(r.has("0"))f=pe(e,"\0");else if(a===void 0)f=Mv(e);else{if(/["'\\]/u.test(e))return k("feature","xargs","-I input quoting","xargs: quoted or escaped replacement lines are not supported");f=pe(e).map(m=>m.replace(/^[ \t\r\f\v]+/u,"")).filter(Boolean)}if(f.length===0&&(r.has("r")||a!==void 0))return C();let c=a===void 0?l.value??Math.max(1,f.length):1,d=0,p="",h="";for(let m=0;m<Math.max(1,f.length);m+=c){let g=f[m],b=a===void 0?[...u,...f.slice(m,m+c)]:u.map(S=>S.replaceAll(a,g)),x=await n.dispatch(s,b,"");if(h+=x.stdout,p+=x.stderr,x.exitCode===255)return{stdout:h,stderr:p+"xargs: "+s+`: exited with status 255; aborting
|
|
241
|
+
`,exitCode:124};if(x.exitCode===127&&!n.hasCommand(n.registry.resolveCommand(s)))return{stdout:h,stderr:p,exitCode:127};x.exitCode!==0&&(d=123)}return{stdout:h,stderr:p,exitCode:d}}var rh=e=>new Error(`unmatched ${e==="'"?"single":"double"} quote; by default quotes are special to xargs unless you use the -0 option`);function Mv(e){let t=[],n=null,r=!1,i="";for(let o=0;o<e.length;o++){let s=e[o];if(!(!r&&/[ \t\n\r\f\v]/u.test(s)))if(n)if(s===n)n=null;else{if(s===`
|
|
242
|
+
`)throw rh(n);i+=s}else if(s==='"'||s==="'")n=s,r=!0;else if(s==="\\"){if(o+1>=e.length)break;i+=e[++o],r=!0}else s===" "||s===" "||s===`
|
|
243
|
+
`?(r&&t.push(i),i="",r=!1):(i+=s,r=!0)}if(n)throw rh(n);return r&&t.push(i),t}function oh(e,t,n,r){let{values:i,positional:o,order:s}=N(Dv(n),{short:["q","v"],valueShort:["c","n"]}),u=s.findLast(b=>b.name==="n"||b.name==="c")?.name??"n",a=Ua(i.get(u)??"10",e+": -"+u);if(a.error)return a.error;let l=s.findLast(b=>b.name==="q"||b.name==="v"),f=l?l.name==="v":null,c=e==="head",d=a.sign==="+";if(c&&a.value===0&&a.sign!=="-")return sh(e,t,o,r,()=>"",{unit:u,banner:f,leftover:b=>b,readOptions:{noRead:!0}});if(!c&&a.value===0&&!d){if(!r.stdinFile&&(!o.length||o.includes("-")||o.includes("/dev/stdin"))){let b=fh(e,t,"",u,"standard input");b&&r.notes.add(b)}return C()}let p=b=>c?[0,a.sign==="-"?Math.max(0,b-a.value):a.value]:[d?Math.min(b,Math.max(0,a.value-1)):Math.max(0,b-a.value),b],h=b=>{if(u==="c")return lh(b,p);let x=c?a.sign==="-":!d,S=c||x?a.value:Math.max(0,a.value-1),E=ah(b,S,x);return c?b.slice(0,E):b.slice(E)},m=c?Pv(a,u,r):void 0;return sh(e,t,o,r,h,{unit:u,banner:f,leftover:m,readOptions:!c&&d?{stopOnDir:!0}:void 0})}function Pv(e,t,n){return e.sign==="-"||t==="n"&&!n.stdinFile?()=>"":t==="c"?r=>lh(r,i=>[Math.min(e.value,i),i]):r=>r.slice(ah(r,e.value))}function ah(e,t,n=!1){if(n){if(t===0)return e.length;let i=e.length-Number(e.endsWith(`
|
|
233
244
|
`));for(let o=0;o<t;o++)if(i<=0||(i=e.lastIndexOf(`
|
|
234
245
|
`,i-1),i<0))return 0;return i+1}let r=0;for(let i=0;i<t&&r<e.length;i++){let o=e.indexOf(`
|
|
235
|
-
`,r);r=o===-1?e.length:o+1}return r}function
|
|
236
|
-
`:""}==> ${
|
|
237
|
-
${
|
|
246
|
+
`,r);r=o===-1?e.length:o+1}return r}function Dv(e){return/^-\d+$/u.test(e[0]??"")?["-n",e[0].slice(1),...e.slice(1)]:e}function lh(e,t){let n=A(e),[r,i]=t(n.length);return r===0&&i>=n.length?e:P(n.subarray(r,i))}function sh(e,t,n,r,i,{unit:o,banner:s,leftover:u=()=>"",readOptions:a}){let l=se(e,n,t,r,a),f=s??n.length>1,c=l.entries.filter(m=>m.kind!=="missing"),d=[],p=[],h=null;for(let m=0;m<c.length;m++){let{name:g,kind:b,shared:x}=c[m],{content:S}=c[m];(x||g===null)&&(h!==null&&(S=h),h=u(S),X(r,h));let E=b==="dir"?"":i(S);if(b==="file"&&E!==S){let D=fh(e,S,E,o,Da(g,r));D&&p.push(D)}let M=g===null||g==="-"?"standard input":g;d.push(f?`${m>0?`
|
|
247
|
+
`:""}==> ${M} <==
|
|
248
|
+
${E}`:E)}for(let m of p)r.notes.add(m);return ee(d.join(""),l)}function Uv(e){let t=+(e.length>0&&!e.endsWith(`
|
|
238
249
|
`));for(let n=e.indexOf(`
|
|
239
250
|
`);n!==-1;n=e.indexOf(`
|
|
240
|
-
`,n+1))t++;return t}function
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
251
|
+
`,n+1))t++;return t}function fh(e,t,n,r,i){let o=r==="c"?l=>A(l).length:Uv,s=o(n),u=o(t);if(s>=u)return null;let a=(r==="c"?"byte":"line")+(u===1?"":"s");return`${e}: selected ${s} of ${u} ${a} from ${i}.`}function Bv(e,t,n){let{flags:r,positional:i}=N(t,{short:["l","w","c","m"]}),o=Wv(r),s=se("wc",i,e,n,{read:"as-held"}),u=i.length>1||Object.values(o).filter(Boolean).length>1,a=[],l={l:0,w:0,m:0,c:0};for(let{name:c,content:d,bytes:p,kind:h,shared:m}of s.entries.filter(g=>g.kind!=="missing")){let g=jv(p??d,n,o,u);a.push({counts:g,name:c,kind:h,shared:m}),l.l+=g.l,l.w+=g.w,l.m+=g.m,l.c+=g.c}let f=u?qv(a,n.stdinFile):1;return i.length>1&&a.push({counts:l,name:"total"}),ee(he(a.map(c=>u1(c.counts,c.name,o,f,n))),s)}function qv(e,t){let n=0,r=1;for(let{name:i,kind:o,shared:s,counts:u}of e)o==="dir"||(i===null||s)&&!t?r=7:n+=u.c;return Math.max(r,String(n).length)}function Wv(e){return e.size===0?{l:!0,w:!0,m:!1,c:!0}:{l:e.has("l"),w:e.has("w"),m:e.has("m"),c:e.has("c")}}function jv(e,t,n,r){let i=ae(t),o=n.c||r||n.m&&i?zv(e):0;return{l:n.l?Hv(e):0,w:n.w?Kv(e,t):0,m:n.m?i?o:Gv(e):0,c:o}}var zv=e=>typeof e=="string"?A(e).length:e.length;function Hv(e){let t=0,n=typeof e=="string"?`
|
|
252
|
+
`:10;for(let r=e.indexOf(n);r>=0;r=e.indexOf(n,r+1))t++;return t}function Gv(e){if(typeof e=="string")return e.length-(e.match(/[\u{10000}-\u{10FFFF}]/gu)??[]).length;let t=0;for(let n of Sr(e))n>=0&&t++;return t}var Xv=new Set([9,10,11,12,13,32]),Zv=new Set([160,8199,8239,8288]),Cu=1,Fu=0,Tu=2,Yv=Uint8Array.from({length:128},(e,t)=>Xv.has(t)?Cu:t>32&&t<127?Tu:Fu),Vv=(e,t)=>t.has("print",e)?t.has("space",e)||Zv.has(e)?Cu:Tu:Fu;function Kv(e,t){let n=Q(t.locale),r=0,i=!1;for(let o of Jv(e,t)){let s=o<0?Fu:o<128?Yv[o]:Vv(o,n);s===Cu?(i&&r++,i=!1):s===Tu&&(i=!0)}return i?r+1:r}function*Jv(e,t){if(typeof e!="string"){yield*ae(t)?e:Sr(e);return}if(ae(t)){yield*A(e);return}for(let n=0;n<e.length;){let r=e.codePointAt(n);yield r>=55296&&r<=57343?65533:r,n+=r>65535?2:1}}function Qv(e,t){let n=0;for(let r=0;r<t&&n<e.length;r++){for(;n<e.length&&/[ \t]/u.test(e[n]);)n++;for(;n<e.length&&!/[ \t]/u.test(e[n]);)n++}return e.slice(n)}function eS(e,t,n){let{flags:r,values:i,positional:o}=N(t,{short:["c","d","u","i","D"],valueShort:["f","s","w"]});if(o.length>2)return y(`uniq: extra operand: ${o[2]}`);if(o.length===2&&o[1]!=="-")return k("feature","uniq","output file","uniq: output files are not supported (filesystem is read-only)");let s=we(i.get("f")??"0","uniq: -f");if(s.error)return s.error;let u=we(i.get("s")??"0","uniq: -s");if(u.error)return u.error;let a=i.has("w")?we(i.get("w"),"uniq: -w"):{value:void 0};if(a.error)return a.error;let l=r.has("D"),f=r.has("c");if(l&&f)return y("uniq: printing all duplicated lines and repeat counts is meaningless");let c=Sn("uniq",o.slice(0,1),e,n),d=r.has("d"),p=r.has("u"),h=r.has("i"),m=E=>{let M=s.value>0?Qv(E,s.value):E;if(u.value===0&&a.value===void 0){let T=M.toWellFormed();return h?T.replace(/[A-Z]/gu,ne=>ne.toLowerCase()):T}let D=A(M).subarray(u.value,a.value===void 0?void 0:u.value+a.value);return(h?D.map(T=>T>=65&&T<=90?T+32:T):D).join(",")},g=pe(c.content),b=[],x=0,S=g.length?m(g[0]):null;for(let E=1;E<=g.length;E++){let M=E===g.length?null:m(g[E]);if(E<g.length&&M===S)continue;let D=E-x,T=D>=2;(l?T:!(d&&p)&&(d?T:!p||!T))&&(l?b.push(...g.slice(x+(p?1:0),E)):b.push(f?String(D).padStart(7)+" "+g[x]:g[x])),x=E,S=M}return ee(he(b),c)}function uh(){return C()}function tS(){return{stdout:"",stderr:"",exitCode:1}}var _u={grep:Kr,head:(e,t,n)=>oh("head",e,t,n),tail:(e,t,n)=>oh("tail",e,t,n),wc:Bv,sort:nh,uniq:eS,echo:r1,printf:s1,xargs:ih,awk:eh},ch={true:uh,false:tS,":":uh};var ph={test:Vp,cat:Ip,..._u,...Ap,...kc},dh=(e,t)=>(n,r,i)=>{let o=_u.grep(n,[t,...r],i),s=O(o);return s?re(o,s.kind,e,s.detail,s.message):o},hh={__proto__:null,sed:Xp,egrep:dh("egrep","-E"),fgrep:dh("fgrep","-F"),"[":Kp,...vc,...ch,...ou,...ph},nS=new Set(["cd",":",...Object.keys(ou)]),rS=e=>!!hh[e],iS=["ls","cd","cat","grep","rg","find","head","tail","wc","tree","du","stat","realpath","sort","uniq","cut","tr","awk","nl","tac","hexdump","base64","xargs","echo","printf","test","cp","rm","mkdir","touch","ln","diff","patch","pwd","seq","which","basename","dirname"],oS=uS(),sS=["grep","head","tail","wc","sort","uniq","cut","xargs","awk","tr","nl","tac","hexdump","cat","base64","diff","patch"];function uS(){let e=new Set(Object.keys(ph)),t=[];for(let n of iS)e.delete(n)&&t.push(n);return t.push(...[...e].sort()),t}var mh=Object.freeze(["/usr/local/bin/","/usr/bin/","/bin/","/sbin/"]);function gh(e,t){for(let n of mh)if(e.startsWith(n)){let r=e.slice(n.length);if(t(r))return r}return e}var aS=new Set(["test","[","true","false"]),lS=new Set(["grep","egrep","fgrep"]);function fS(e,t){let n=gh(e[0],t);return aS.has(n)?"status":lS.has(n)?Uf(e.slice(1))?"status":"search":"work"}function Lu(e){let t=Cl(e,rS),n=Object.freeze({__proto__:null,...hh,...t.handlers}),r=o=>!!n[o],i=Object.freeze([...oS,...t.names]);return Object.freeze({commands:n,names:i,pipeNames:Object.freeze([...sS,...t.pipeNames]),binPrefixes:mh,has:r,shellOnly:o=>nS.has(o),resolveCommand:o=>gh(o,r),chainRole:o=>fS(o,r),known:i.join(", ")})}var wh=Lu();function bh(e,t){let n=n1.get(e);return n!==void 0?k("feature",e,e,`${e}: ${n}`,127):k("command",e,e,`${e}: command not found. Available: ${t.known}`,127)}function xh(e,t,n){let r=hS(e);if(!r)return[];let{start:i,pipe:o,quote:s,words:u}=r;for(;cS.has(u[0]);)u.shift();if(dS.has(u[0]))return[];if(u[0]==="for"&&u.length<=2)return[];let a=e.slice(i),l=yh(a,s);if(!l)return[];let f=u.length===0,c=f?"":n.resolveCommand(yh(u[0],null)?.value??""),d=f?pS(l.value,o,n,t.functions):o?[]:gS(l,t,c==="cd"),p=e.slice(0,i),h=o&&a===""&&p.endsWith("|")?" ":"";return d.map(m=>p+h+a+mS(m.slice(l.value.length),s))}var cS=new Set(["!","{","do","then","else","elif","if","while","until"]),dS=new Set(["done","fi","}","esac"]);function pS(e,t,n,r){let i=t?n.pipeNames:n.names;for(let s of n.binPrefixes)if(e.startsWith(s))return i.filter(u=>u.startsWith(e.slice(s.length))).map(u=>s+u);if(e.startsWith("/")||e.startsWith("./"))return[];let o=[...r.keys()].filter(s=>!i.includes(s));return[...i,...o].filter(s=>s.startsWith(e))}function hS(e){let t=0,n=!1,r=null,i=!1,o=-1,s=[];for(let u=0;u<e.length;u++){let a=e[u];if(r==="'"){a===r&&(r=null);continue}if(a==="\\"&&(!r||'$`"\\\n'.includes(e[u+1]))){if(u+1===e.length)return null;e[++u]!==`
|
|
253
|
+
`&&(i=!0);continue}if(a==="`"||a==="$"&&e[u+1]==="(")return null;if(r){a===r&&(r=null);continue}if(a==="'"||a==='"'){r=a,i=!0;continue}if(a==="#"&&!i){let c=e.indexOf(`
|
|
254
|
+
`,u);if(c===-1)return null;u=c-1;continue}if(a===" "||a===" "){i&&s.push(e.slice(t,u)),t=u+1,i=!1;continue}let l=a==="|"&&e[u+1]==="|",f=a==="&"&&e[u+1]==="&";if(a==="|"||f||a===";"||a===`
|
|
255
|
+
`||a==="("||a===")"&&o===u-1){(l||f)&&u++,a==="("&&(o=u),t=u+1,n=a==="|"&&!l,s.length=0,i=!1;continue}i=!0}return{start:t,pipe:n,quote:r,words:s}}function yh(e,t){if(e==="")return{value:"",mask:null};try{let n=_r(e+(t??""));if(n.length!==1||n[0].kind!=="word")return null;let r=n[0];for(let i=0;i<r.value.length;i++){let o=r.mask?.[i]??"0";if(o!=="1"&&r.value[i]==="$"||o==="0"&&"*?[{".includes(r.value[i]))return null}return r}catch{return null}}function mS(e,t){return t==="'"?e.replaceAll("'","'\\''")+"'":t==='"'?e.replace(/[\\$`"]/gu,"\\$&")+'"':e.replace(/[\s\\'"`$&|;()<>*?[\]{}!#~]/gu,n=>n===`
|
|
244
256
|
`?`'
|
|
245
|
-
'`:"\\"+n)}function
|
|
246
|
-
`)
|
|
247
|
-
|
|
248
|
-
`}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
`
|
|
254
|
-
|
|
255
|
-
`,o]});return Oe`<pre class="stdout">${n}</pre>`}};customElements.define("bundle-terminal",gu);function iR(e,t){let n=document.createElement("bundle-terminal");return n.dataset.integrity=t??"",n.sources=e,n}export{iR as createTerminalElement};
|
|
257
|
+
'`:"\\"+n)}function gS(e,t,n=!1){let r=e.value,i=r.startsWith("~")&&(e.mask?.[0]??"0")==="0"&&!e.empty?.some(h=>h<=1)&&(r.length===1||(e.mask?.[1]??"0")==="0");if(i&&r==="~")return t.fs.isDir(v(t.cwd,rn(t),t.fs).path)?["~/"]:[];if(i&&!r.startsWith("~/"))return[];let o=r.lastIndexOf("/"),s=r.slice(0,o+1),u=r.slice(o+1),a=i?rn(t)+s.slice(1):s||".",l=v(t.cwd,a,t.fs).path;if(!t.fs.isDir(l))return[];let{dirs:f,files:c,links:d}=t.fs.listDir(l),p=f.map(h=>h+"/");for(let h of d)t.fs.isDir(v(l,h,t.fs).path)?p.push(h+"/"):n||p.push(h);return n||p.push(...c),p.filter(h=>h.startsWith(u)&&(u.startsWith(".")||!h.startsWith("."))).filter(h=>s!==""||u===""||!h.startsWith("-")).map(h=>s===""&&h.startsWith("-")?"./"+h:s+h)}async function kh(e,t,n,r=!1){let i=(t.substitutionDepth??0)+1;if(i>Yt)throw new w("feature","command substitution nesting limit",`command substitution nesting beyond ${Yt} levels is not supported`);let o=t.expansionFds[2],u=await fe(t,{substitutionDepth:i,outputFds:{1:"out",2:typeof o=="object"||o==="closed"?o:"err"},errexitOff:!0,closed:{out:!1,err:o==="closed"}},()=>St(t,()=>{let c;try{c=Nl(e,t.writable,t.registry.has)}catch(p){let h=O(p);if(!h){if(r)return y(`error: command substitution: ${p.message}`,2);throw new w("feature","command substitution syntax",`runtime command substitution syntax errors are not supported: ${p.message}`)}return t.unsupported.add(h),y(`error: ${p.message}`,1)}let d=c.length===1&&!c[0].negate&&c[0].stages.length===1?c[0].stages[0]:null;return d&&!d.group&&!d.loop&&!d.conditional&&!d.test&&d.words.length===0&&d.assigns.length===0&&d.redirs.length===1&&d.redirs[0].op==="read"&&d.words.push({value:"cat",mask:null}),n(c,t,{text:t.stdinLeft})}));t.lastExit=t.substitutionExit=u.exitCode;let a=u.stdout,l=u.stderr;if(a.includes("\0")){let c=a.length;a=a.replaceAll("\0","");let d=c-a.length;t.notes.add(`command substitution: discarded ${d} NUL ${d===1?"byte":"bytes"}.`),l+=`warning: command substitution: ignored null byte in input
|
|
258
|
+
`}Jr(t,l);let f=a.length;for(;f>0&&a[f-1]===`
|
|
259
|
+
`;)f--;return a.slice(0,f)}async function vh(e,t){return{stdout:"",stderr:"",exitCode:await mn(e,t)?0:1}}var Ru=async(e,t)=>(await Cs(e,t)).value;async function mn(e,t){let{kind:n}=e;if(n==="not")return!await mn(e.expression,t);if(n==="and")return await mn(e.left,t)&&await mn(e.right,t);if(n==="or")return await mn(e.left,t)||await mn(e.right,t);let{op:r}=e;if(n==="unary"){let u=await Ru(e.word,t);if(r==="-n")return u!=="";if(r==="-z")return u==="";if(["-a","-e","-f","-d"].includes(r))return iu(r,u,t);if(r==="-v")return wS(u,t);yr(r)}["<",">","-nt","-ot","-ef"].includes(r)&&yr(r);let i=await Ru(e.left,t);if(Object.hasOwn(ur,r)){let u=await Ru(e.right,t);return ur[r](Pt(i,t),Pt(u,t))}let o=await Cs(e.right,t);Bn(o)&&yr("extglob");let s=Te(en(o),{bash:!0}).test(i);return r==="!="?!s:s}function wS(e,t){return e.includes("[")&&yr("-v array subscript"),/^[ \t\n\r\f\v]*[+-]?0+[ \t]*$/u.test(e)&&yr("-v positional parameter"),/^[A-Za-z_][A-Za-z0-9_]*$/u.test(e)?vt(e,t).set:!1}function yr(e){throw new w("feature",`[[ ${e}`,`${e} in [[ is not supported`)}function $h(e,t,n,r){return e.define?(t.functions.set(e.define.name,e.define.body),U()):e.test?vh(e.test,t):e.group?vS(e,t,n,r):e.loop?e.loop.words?xS(e.loop,t,r):bS(e.loop,t,r):kS(e.conditional,t,n,r)}var Eh=1e4,Sh={kind:"feature",command:null,detail:"loop limit",message:`a loop running more than ${Eh} times is not supported`};async function bS(e,t,n){let r=U(),i={text:t.stdinLeft};t.loopDepth++;try{for(let o=0;;o++){if(o===Eh){t.unsupported.add(Sh),_(r,y(`error: ${Sh.message}`,1));break}let s=r.ignored,u=r.exitCode,a=await n(e.condition,t,i,!0);if(_(r,a),r.exitCode=u,r.ignored=s,a.halt||a.control)return{...r,halt:a.halt,control:a.control,blame:a.blame};if(a.exitCode===0==!!e.until)break;let l=await n(e.body,t,i);if(_(r,l),r.blame=l.blame,l.halt)return{...r,halt:!0};if(l.control?.levels>1)return{...r,control:{...l.control,levels:l.control.levels-1}};if(l.control?.type==="break")break}}finally{t.loopDepth--}return r}var yS={value:"for",mask:null};async function xS(e,t,n){let r=await Yn([yS,...e.words],t),i=U(),o={text:t.stdinLeft};t.loopDepth++;try{for(let s of r.argv.slice(1)){t.vars.set(e.name,s);let u=await n(e.body,t,o);if(_(i,u),i.blame=u.blame,u.halt)return{...i,halt:!0};if(u.control?.levels>1)return{...i,control:{...u.control,levels:u.control.levels-1}};if(u.control?.type==="break")break}}finally{t.loopDepth--}return i}async function kS(e,t,n,r){let i=U(),o={text:n};for(let u of e.branches){let a=await r(u.condition,t,o,!0);if(_(i,a),a.halt||a.control)return{...i,halt:a.halt,control:a.control,blame:a.blame};if(a.exitCode!==0)continue;let l=await r(u.body,t,o);return _(i,l),{...i,halt:l.halt,control:l.control,blame:l.blame}}if(!e.otherwise)return i.exitCode=0,i.ignored=!1,i;let s=await r(e.otherwise,t,o);return _(i,s),{...i,halt:s.halt,control:s.control,blame:s.blame}}async function vS(e,t,n,r){let i={text:n};return e.isolate?{...await St(t,()=>r(e.group,t,i)),halt:!1,control:void 0,ignored:!1}:r(e.group,t,i)}var SS=new Set(["sort","cat"]),$S=new Set(["wc","tac"]);function Mu(e){let t=null,n=null,r=o=>{t&&!t.bufferReads&&t.reads.push(o)},i=o=>{if(o!==void 0)for(let s=t;s;s=s.parent){if(!s.reads.includes(o)||s===t&&n?.scope===s&&(n.unsupported||s.buffered||n.fd===1&&(SS.has(s.name)||$S.has(s.name)&&!s.reads.slice(1).includes(o))))continue;if(s.failure)throw s.failure;let u=s===t&&n?.fd===2,a=u?"input modified by diagnostics":"streaming self-output",l=u?"reading input while diagnostics write to the same file is not supported":"writing to an actively read input file is not supported";throw s.failure=re(new w("feature",a,l),"feature",s.name,a,l),s.failure}};return e.observeIo?.({read:r,write:i}),{read:r,bufferOutput(){t&&(t.buffered=!0)},bufferReads(o){if(!t)return o();let s=t,u=s.bufferReads;s.bufferReads=!0;try{return o()}finally{s.bufferReads=u}},setReads(o){t&&(t.reads=o)},async run(o,s){let u=t;t={name:o,reads:[],parent:u};try{return await s()}finally{t=u}},output(o,s,u){let a=n;n={scope:t,fd:null,unsupported:!!O(o)};try{for(let l of Wn(o))l.text!==""&&(n.fd=l.fd,i(s.fds[l.fd]?.identity));return u((l,f)=>{n.fd=l.fd,f.write(l.text)})}finally{n=a}}}}function Du(e,t){let n={1:t.outputFds[1]?.path?t.outputFds[1]:"out",2:t.outputFds[2]?.path?t.outputFds[2]:"err"};return tn(e,{fds:n},t)}async function xr(e,t,n,r=!1){if(e.some(u=>u.background))throw new w("feature","&","background processes (`&`) are not supported");let i=U(),o=null,s=null;for(let[u,a]of e.entries()){if(a.warnings&&_(i,tn({...U(a.warnings),exitCode:i.exitCode,ignored:i.ignored},{fds:t.outputFds},t)),a.gate==="and"&&i.exitCode!==0){(s??=Pa()).skip(r?null:o,i.exitCode);continue}if(a.gate==="or"&&i.exitCode===0)continue;s?.flush(t.notes);let l=r||a.negate||ES(e,u),f=await(l?fe(t,{errexitOff:!0},()=>Nh(a.stages,t,n)):Nh(a.stages,t,n));if(_(i,f),a.negate&&!f.halt&&(i.exitCode=f.exitCode===0?1:0),l&&(i.ignored=!0),o=a.negate?null:f.blame,t.lastExit=i.exitCode,f.halt||f.control){Object.assign(i,{halt:f.halt,control:f.control});break}if(i.exitCode!==0&&!i.ignored&&t.errexit&&!t.errexitOff){i.halt=!0;break}}return s?.flush(t.notes),t.stdinLeft=n.text,Object.assign(i,{blame:o})}var ES=(e,t)=>["and","or"].includes(e[t+1]?.gate);async function Nh(e,t,n){let r=U(),i=n.text;for(let o=0;o<e.length;o++){let s=e[o],u=o===0,a="",l={...t.outputFds};o<e.length-1&&(l[1]={write(p){a+=p}});let f=i,c=()=>NS(s,t,f,u&&t.stdinFile,l,u?t.stdinPiped:!0),d=e.length>1?{...await St(t,c),ignored:!1}:await c();u&&(n.text=d.inputLeft),_(r,d),i=a,r.blame=d.blame,e.length===1&&(r.halt=d.halt,r.control=d.control)}return r}function NS(e,t,n,r,i,o){let s={fds:i,stdin:n,stdinFile:r,stdinPiped:o,stdinOrigin:r?t.stdinOrigin:null,stdinHandle:r?t.stdinHandle:null};return fe(t,{substitutionExit:null,expansionOutput:U(),expansionFds:i},()=>Pu(s,t,async()=>{let u=!e.group&&!e.loop&&!e.conditional&&!e.test&&!e.define,a,l;try{u&&(a=await Yn(e.words,t),a.argv.length===0?await TS(e.assigns,t):a.temps=await _S(e.assigns,t))}catch(m){l=Wi(t,m)}if(l)return _(t.expansionOutput,Ah(l,s,t)),{...t.expansionOutput,inputLeft:t.stdinLeft,halt:l.halt};let f=await AS(e,t,t.stdinLeft,r,i);t.expansionFds=f.fds;let c=!1,d=null,p=await Pu(f,t,()=>OS(t,async()=>{if(f.error)return f.error;if(!u){let x=await $h(e,t,f.stdin,xr);return c=!0,d=x.blame??null,x}let m=a.argv.length>0?a.argv[0]:null,g=m===null?void 0:t.functions.get(m);if(g){if(c=!0,t.calling.has(m)){let x=k("feature",m,"function recursion",`${m}: a function calling itself is not supported`);return t.unsupported.add(O(x)),x}t.calling.add(m);try{return await fe(t,{loopDepth:0},async()=>({...await Oh(a.temps,t,()=>xr(g,t,{text:f.stdin})),ignored:!1}))}finally{t.calling.delete(m)}}let b=await FS(t,a);return a.argv.length&&(d=Ma(t.registry.chainRole(a.argv),a.argv[0])),b})),h=f.inherited?t.stdinLeft:f.parentLeft;return _(t.expansionOutput,c?p:Ah(p,f,t)),{...t.expansionOutput,inputLeft:h,halt:p.halt,control:p.control,blame:d}}))}function Ah(e,t,n){try{return tn(e,t,n)}catch(r){return tn(Wi(n,r),t,n)}}async function AS(e,t,n,r,i){let o={...i},s=n,u=r,a=u?t.stdinOrigin:null,l=u?t.stdinHandle:null,f=!0,c=n,d=!1,p=m=>({error:m,fds:o,stdin:s,stdinFile:u,stdinPiped:d||t.stdinPiped,stdinOrigin:u?a:null,stdinHandle:u?l:null,inherited:f,parentLeft:c}),h=async m=>{let g=await fe(t,{expansionFds:o},()=>Pu({fds:o,stdin:s,stdinFile:u,stdinOrigin:a,stdinHandle:l},t,m));return s=t.stdinLeft,f&&(c=s),g};try{for(let m of e.redirs)if(m.op==="dup"){if(o[m.toFd]===void 0||o[m.toFd]==="closed")return p(y(`error: ${m.toFd}: Bad file descriptor`));o[m.fd]=o[m.toFd]}else if(m.op==="close")o[m.fd]="closed";else if(m.op==="to"){let g=m.target===void 0?await h(()=>Is(m.word,t)):{value:m.target};if(g.error)return p(y(`error: ${g.error}`));let b=g.value==="/dev/null"?"null":g.value==="/dev/stdout"?o[1]:g.value==="/dev/stderr"?o[2]:t.writable?t.fs.openWritable(t.cwd,g.value,m.append):null;if(b===null){let x=No(m.label,g.value,t.writable);return t.unsupported.add(O(x)),p(y(`error: ${x.message}`))}if(b==="closed")return p(y(`error: ${g.value}: No such file or directory`));o[m.fd]=b,m.both&&(o[2]=b)}else if(m.op==="text")s=m.expand?await h(()=>Dt(IS(m.body),t)):m.body,u=!1,f=!1;else if(m.op==="herestring")s=await h(()=>Dt(m.word,t))+`
|
|
260
|
+
`,u=!1,f=!1;else{let g=await h(()=>Is(m.word,t)),b=g.error?{error:y(`error: ${g.error}`)}:CS(g.value,t,u?a:s);if(b.error)return p(b.error);s=b.content,(g.value!=="/dev/stdin"||u)&&(f=!1),g.value!=="/dev/stdin"&&(u=g.value!=="/dev/null",a=u?s:null,l=b.handle,d=u)}if(u&&l){let m=t.io.bufferReads(()=>t.fs.readIdentity(l.identity));if(m!==l.content){if(f||s!==l.content)throw new w("feature","modified redirected input","reading an inherited input file after it changes is not supported");s=a=m,l={...l,content:m}}}}catch(m){return p(Wi(t,m))}return p()}function Wi(e,t){L(e,"shell",t?.path,t?.fsError);let n=O(t);return n&&e.unsupported.add(n),{...y(`error: ${Z(t)}`,1),...t?.halt?{halt:!0}:{}}}async function OS(e,t){try{return await t()}catch(n){return Wi(e,n)}}function Pu(e,t,n){let r={outputFds:e.fds,closed:{out:e.fds[1]==="closed",err:e.fds[2]==="closed"},stdinFile:!!e.stdinFile,stdinPiped:e.stdinPiped??t.stdinPiped,stdinOrigin:e.stdinOrigin,stdinHandle:e.stdinHandle};return t.stdinLeft=e.stdin,fe(t,r,n)}function IS(e){let t="",n="";for(let r=0;r<e.length;r++){let i=e[r],o=e[r+1];if(i==="\\"&&(o==="$"||o==="\\"||o==="`")){t+=o,n+="1",r++;continue}if(i==="`"){let s=ot(e,r);t+=s.raw,n+="2"+"1".repeat(s.raw.length-1),r+=s.raw.length-1;continue}if(i==="$"){let s=ut(e,r,0,!0);if(s?.command!==void 0||s?.parameter!==void 0||s?.arithmetic!==void 0){t+=s.raw,n+="2"+"1".repeat(s.raw.length-1),r+=s.raw.length-1;continue}}t+=i,n+="2"}return{value:t,mask:n}}function CS(e,t,n){if(e==="/dev/null")return{content:""};if(e==="/dev/stdin")return{content:n};let{path:r,error:i}=R(t,"shell",e);if(i)return{error:y(`error: ${e}: ${i}`)};if(t.fs.isFile(r)){let o=t.fs.readFile(r);return{content:o,handle:t.writable&&r.startsWith("/tmp/")?{path:r,content:o,identity:t.fs.fileIdentity(r)}:null}}return{error:y(`error: ${e}: Is a directory`)}}function FS(e,t){let{argv:n}=t;return n.length===0?{stdout:"",stderr:"",exitCode:e.substitutionExit??0}:Oh(t.temps,e,()=>e.invoke(n[0],n.slice(1),e.stdinLeft))}async function TS(e,t){for(let n of e)t.vars.set(n.name,await Dt(n.word,t,!0))}async function _S(e,t){if(e.length===0)return null;let n=t.vars,r=new Ke(n),i=new Set(e.map(o=>o.name));r.bound=new Set;try{await fe(t,{vars:r},async()=>{for(let o of e){r.expansionTargets=i;let s=await Dt(o.word,t,!0);r.expansionTargets=null,r.set(o.name,s)}})}finally{r.expansionTargets=null;for(let o of r.bound)i.has(o)||n.set(o,r.get(o))}return{vars:r,names:i}}async function Oh(e,t,n){if(!e)return n();let r=t.vars,i=new Ke(r),o=e.names;for(let s of o)i.set(s,e.vars.get(s));t.vars=i;try{return i.bound=new Set,await n()}finally{t.vars=r;for(let[s,u]of i)(!o.has(s)||i.bound?.has(s))&&r.set(s,u);for(let s of i.unsetNames)o.has(s)||r.delete(s)}}function Ch(e,t={}){let{fs:n,cwd:r,home:i,mount:o,writable:s,locale:u}=Wa(e,t),a=t.commands===void 0?wh:Lu(t.commands),l={fs:n,io:Mu(n),mount:o,writable:s,registry:a,createdAt:Date.now(),lock:{turn:Promise.resolve()}};return _h(Th(l,{cwd:r,home:i,user:t.user??"user",locale:u,...Fh()}),"createTerminal")}var Fh=()=>({vars:new Ke,functions:new Map,lastExit:0,errexit:!1}),LS=e=>({vars:new Ke(e.vars),functions:new Map(e.functions),lastExit:e.lastExit,errexit:e.errexit});function RS(e,t={}){let{cwd:n,home:r,user:i,locale:o,inherit:s}=ja(e,t),u=s?LS(e):Fh();return _h(Th(e,{cwd:n,home:r,user:i,locale:o,...u}),"fork")}function Th({fs:e,io:t,mount:n,writable:r,registry:i,createdAt:o,lock:s},u){let a={fs:e,io:t,mount:n,writable:r,registry:i,createdAt:o,lock:s,...u,calling:new Set,outputFds:{1:"out",2:"err"},loopDepth:0,closed:{out:!1,err:!1},stdinFile:!1,stdinPiped:!1,stdinOrigin:null,stdinHandle:null,stdinLeft:"",unsupported:zi(),notes:new Set};return a.dispatch=(l,f,c)=>fe(a,{stdinLeft:a.stdinLeft,stdinFile:!1,stdinPiped:!1,stdinOrigin:null,stdinHandle:null},()=>St(a,()=>Ih(l,f,c,a,!0))),a.flushOutput=l=>Du(l,a),a.hasCommand=l=>i.has(l)&&!i.shellOnly(l),a.invoke=(l,f,c)=>Ih(l,f,c,a),a.substitute=(l,f)=>kh(l,a,xr,f),a.runLine=l=>Lh(l,a),a}function _h(e,t){if(!e.fs.isDir(e.cwd))throw new Error(`${t}: cwd is not a directory: ${e.cwd}`);return{run:n=>PS(e,n),cwd:()=>e.cwd,complete:n=>xh(n,e,e.registry),fork:n=>RS(e,n)}}async function Ih(e,t,n,r,i=!1){let o=r.registry,s=o.resolveCommand(e),u=()=>{if((i||e!==s)&&o.shellOnly(s))return k("command",e,e,`${e}: shell builtin cannot be invoked as an external command`,127);let l=o.commands[s];return l?l(n,t,r):bh(e,o)},a=l=>Du(MS(r,os(e,l,r),s),r);try{return await r.io.run(s,async()=>a(await u()))}catch(l){L(r,e,l?.path,l?.fsError);let f=`${e}: ${Z(l)}`,c=O(l);return c&&r.unsupported.add({...c,command:c.command??e,message:f},c.command??s),a(y(f))}}function MS(e,t,n){let r=O(t);return r&&e.unsupported.add(r,n),t}function PS(e,t){let{lock:n}=e,r=n.turn.then(()=>Lh(t,e));return n.turn=r.then(()=>null,()=>null),r}function Lh(e,t){let n=zi();return fe(t,{unsupported:n,notes:new Set,discarded:new Set,stdinFile:!1,stdinPiped:!1,stdinOrigin:null,stdinHandle:null,closed:{out:!1,err:!1},outputFds:{1:"out",2:"err"}},async()=>{let r={stdout:"",stderr:"",exitCode:0},i={text:""};try{for(let o of Al(e,t.writable,t.registry.has)){let s=await xr(o,t,i);if(r.stdout+=s.stdout,r.stderr+=s.stderr,r.exitCode=s.exitCode,s.halt||s.control)break}}catch(o){let s=O(o);s&&n.add(s),t.lastExit=o.exitCode??(s?1:2),r.stderr+=`error: ${o.message}
|
|
261
|
+
`,r.exitCode=t.lastExit}return DS(r,t,n)})}var DS=(e,t,n)=>({stdout:e.stdout,stderr:e.stderr,exitCode:e.exitCode,cwd:t.cwd,unsupported:Object.freeze(n.entries),notes:Object.freeze([...t.notes,...lo(t.discarded,e.stderr,t.notes)])});var US={unified:[[/^--- /u,"bold"],[/^\+\+\+ /u,"bold"],[sn,"cyan"],[/^\+/u,"green"],[/^-/u,"red"],[/^\\ /u,"gray"]],context:[[Bt,"cyan"],[/^\*{3} \d/u,"cyan"],[/^--- \d/u,"cyan"],[/^\*{3} /u,"bold"],[/^--- /u,"bold"],[/^! /u,"yellow"],[/^\+ /u,"green"],[/^- /u,"red"]],normal:[[un,"cyan"],[/^< /u,"red"],[/^> /u,"green"],[/^---$/u,"gray"]]};function BS(e){return e.some(t=>Bt.test(t))?"context":e.some(t=>sn.test(t))?"unified":e.some(t=>un.test(t))?"normal":null}function Rh(e){let t=e.split(`
|
|
262
|
+
`),n=US[BS(t)];return n===void 0?null:t.map(r=>n.find(([i])=>i.test(r))?.[1]??null)}var qS={bold:"head",cyan:"hunk",green:"add",red:"del",yellow:"chg",gray:"meta"};function Mh(e){let t=Rh(e);return t===null?null:e.split(`
|
|
263
|
+
`).map((n,r)=>({text:n,kind:t[r]===null?"":qS[t[r]]??""}))}function Ph({stdout:e,stderr:t,unsupported:n}){return n.filter(r=>!t.includes(r.message)&&!e.includes(r.message)).map(r=>r.message)}var Dh=`:host{display:flex;flex-direction:column;position:relative;height:100%;min-height:0;background:var(--bg, #0c0c0c);color:var(--text, #e6edf3);font-family:ui-monospace,SF Mono,Menlo,Consolas,monospace;font-size:13px;line-height:1.45}.output{flex:1 1 auto;overflow-y:auto;overscroll-behavior:none;-webkit-app-region:no-drag;app-region:no-drag;scrollbar-gutter:stable;padding:12px 14px 6px;cursor:text}.banner{color:var(--muted, #8b949e);margin-bottom:8px;user-select:none}.banner .cmd{color:var(--accent, #58a6ff)}.banner .cmd:hover{text-decoration:underline}.line{white-space:pre-wrap;overflow-wrap:break-word}.cwd{color:var(--accent, #58a6ff)}.sigil{color:var(--muted, #8b949e)}.stdout,.stderr{margin:0 0 4px;font:inherit;white-space:pre-wrap;overflow-wrap:break-word}.stderr{color:var(--critical, #d8413a)}.diff-head{color:var(--text, #e6edf3);font-weight:600}.diff-hunk{color:var(--accent, #58a6ff)}.diff-add{color:var(--green, #3fb950)}.diff-del{color:var(--critical, #d8413a)}.diff-chg{color:var(--yellow, #d29922)}.diff-meta{color:var(--muted, #8b949e)}.form{flex:0 0 auto;display:flex;align-items:center;padding:8px 14px 10px;border-top:1px solid var(--border, #2c2c2c)}.form:focus-within{border-top-color:var(--accent, #58a6ff)}.form[aria-busy=true] .sigil{opacity:.4}.form[aria-busy=true] .input{caret-color:transparent}.form .cwd{flex:0 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;user-select:none}.form .sigil{flex:0 0 auto;user-select:none;margin:0 1ch}.input-wrap{flex:1 1 auto;min-width:0;position:relative;display:flex;align-items:center}.input{width:100%;background:transparent;border:none;outline:none;color:inherit;font:inherit;padding:0;position:relative}.ghost{position:absolute;inset:0;display:flex;align-items:center;font:inherit;white-space:pre;overflow:hidden;pointer-events:none;user-select:none;color:var(--muted, #8b949e);opacity:.55}.ghost-pad{color:transparent}.notes{position:absolute;top:8px;right:14px;z-index:2;display:flex;flex-direction:column;align-items:flex-end;gap:6px;max-width:min(52%,320px);pointer-events:none}.note{box-sizing:border-box;padding:5px 9px;border:1px solid var(--border, #2c2c2c);border-radius:5px;background:var(--bg, #0c0c0c);color:var(--muted, #8b949e);font-size:12px;line-height:1.4;text-align:left;overflow-wrap:break-word;animation:note-in .14s ease-out,note-out .4s ease-in var(--dwell-out, 5.6s) forwards}.note-gap{border-color:var(--warning, #d97706);color:var(--text, #e6edf3)}@keyframes note-in{0%{opacity:0;transform:translateY(-4px)}to{opacity:1;transform:none}}@keyframes note-out{to{opacity:0;transform:translateY(-4px)}}@media(prefers-reduced-motion:reduce){.note{animation:none}}
|
|
264
|
+
`;var Bu="/sources",jS={mount:Bu,home:"/",writable:"/tmp/"};function zS(e){let n=["ls","find /",`grep -r ${HS(e)} .`];if(!e||e.size===0)return n;let r=null;for(let[i,o]of e){if(typeof o!="string")continue;let s=GS(i);(r===null||s.length<r.length)&&(r=s)}return r&&n.push(`cat ${r} | head -n 20`),n}var Uu=["TODO","FIXME","XXX","HACK","NOTE","BUG","export","import","require","//"];function HS(e){if(!e||e.size===0)return Uu[0];for(let t of Uu)for(let n of e.values())if(typeof n=="string"&&n.includes(t))return t;return Uu[0]}function GS(e){return e.startsWith("./")?e.slice(2):e.startsWith("/")?e.slice(1):e}var qu=class e extends ju{static properties={sources:{attribute:!1},_lines:{state:!0},_input:{state:!0},_cwd:{state:!0},_ghost:{state:!0},_notes:{state:!0},_running:{state:!0}};static styles=zu(Dh);#n=null;#f=null;#t=[];#e=-1;#o="";#i=null;#s=null;static#h=200;#r=new Map;#m=0;static#g=3;static#w=400;constructor(){super(),this.sources=null,this._lines=[],this._input="",this._cwd=Bu,this._ghost="",this._notes=[],this._running=!1}willUpdate(t){t.has("sources")&&this.sources!==this.#f&&(this.#n=this.sources?Ch(this.sources,jS):null,this._cwd=this.#n?this.#n.cwd():Bu,this._lines=[{kind:"banner",commands:zS(this.sources)}],this.#t=[],this.#e=-1,this.#o="",this.#i=null,this._input="",this.#l(),this.#f=this.sources),t.has("_input")&&(this.#a(),this.#d())}connectedCallback(){super.connectedCallback(),this.updateComplete.then(()=>this.#c())}disconnectedCallback(){super.disconnectedCallback(),this.#a(),this.#l()}firstUpdated(){this.#u()}updated(t){(t.has("_lines")||t.has("sources"))&&this.#c()}#u(){let t=this.renderRoot.querySelector(".input");t&&t.focus()}#c(){let t=this.renderRoot.querySelector(".output");t&&(t.scrollTop=t.scrollHeight)}#b=async t=>{if(t.preventDefault(),!this.#n||this._running)return;let n=this._input,r=n.trim();if(r==="clear"){this._lines=[],this.#l(),this._input="",r.length>0&&(this.#t=[...this.#t,n]),this.#e=-1;return}let i=this._cwd;r.length>0&&(this.#t=[...this.#t,n]),this.#e=-1,this._input="";let o;this._running=!0;try{o=await this.#n.run(n)}catch(u){this._lines=[...this._lines,{kind:"prompt",cwd:i,text:n},{kind:"stderr",text:`${u?.message??u}
|
|
265
|
+
`}];return}finally{this._running=!1}this._cwd=o.cwd;let s=[...this._lines,{kind:"prompt",cwd:i,text:n}];o.stdout&&s.push({kind:"stdout",text:o.stdout,diff:Mh(o.stdout)}),o.stderr&&s.push({kind:"stderr",text:o.stderr}),this._lines=s,this.#v(o)};#y=t=>{if(t.key==="Tab"&&!t.shiftKey){t.preventDefault(),this.#x();return}this.#i=null,t.key==="ArrowUp"?(t.preventDefault(),this.#A()):t.key==="ArrowDown"&&(t.preventDefault(),this.#O()),this.#a(),this.#d()};#x(){if(!this.#n)return;let t=this.#i;if(t&&t.items[t.index]===this._input){t.index=(t.index+1)%t.items.length,this._input=t.items[t.index];return}let n=this.#n.complete(this._input);if(n.length===0){this.#i=null;return}this._input=n[0],this.#i=n.length>1?{items:n,index:0}:null}#a(){this._ghost="",this.#s!==null&&(clearTimeout(this.#s),this.#s=null)}#d(){this.#s=setTimeout(()=>{this.#s=null,this.#k()},e.#h)}#k(){if(!this.#n||this.#i)return;let t=this._input,n=t.slice(-1),r=t===""||n===" "||n==="|",i=/[\w./]/u.test(n);if(!r&&!i)return;let o=this.#n.complete(t);if(o.length===0)return;let s=o[0];!s.startsWith(t)||s===t||i&&o.includes(t)||(this._ghost=s.slice(t.length))}#v(t){let n=t.notes.map(r=>({text:r,kind:"note"}));for(let r of Ph(t))n.push({text:`silenced: ${r}`,kind:"gap"});this.#S(n)}#S(t){if(t.length===0)return;let n=[...this._notes];for(let{text:r,kind:i}of t){let o=n.findIndex(s=>s.text===r);o!==-1&&this.#p(n,o),n.push({id:++this.#m,text:r,kind:i,dwell:e.#$(r)})}for(;n.length>e.#g;)this.#p(n,0);for(let r of n)this.#r.has(r.id)||this.#r.set(r.id,setTimeout(()=>this.#N(r.id),r.dwell));this._notes=n}static#$(t){return Math.min(1e4,3200+t.length*55)}#p(t,n){let[r]=t.splice(n,1);this.#E(r.id)}#E(t){let n=this.#r.get(t);n!==void 0&&(clearTimeout(n),this.#r.delete(t))}#N(t){this.#r.delete(t),this._notes=this._notes.filter(n=>n.id!==t)}#l(){for(let t of this.#r.values())clearTimeout(t);this.#r.clear(),this._notes=[]}#A(){this.#t.length!==0&&(this.#e<0?(this.#o=this._input,this.#e=this.#t.length-1):this.#e=Math.max(0,this.#e-1),this._input=this.#t[this.#e])}#O(){if(this.#e<0)return;let t=this.#e+1;t>=this.#t.length?(this.#e=-1,this._input=this.#o,this.#o=""):(this.#e=t,this._input=this.#t[t])}#I=t=>{this._input=t.target.value};#C=t=>{this._input=t,this.#e=-1,this.#o="",this.#u()};#F=()=>{let t=this.renderRoot.getSelection?.()??document.getSelection();t&&!t.isCollapsed||this.#u()};render(){return Re`<div class="notes" role="log" aria-atomic="false">${Hu(this._notes,t=>t.id,t=>Re`<div class="note ${t.kind==="gap"?"note-gap":""}" style="--dwell-out: ${t.dwell-e.#w}ms">${t.text}</div>`)}</div><div class="output" @click="${this.#F}">${this._lines.map(t=>this.#T(t))}</div><form class="form" @submit="${this.#b}" aria-busy="${this._running?"true":"false"}"><span class="cwd">${this._cwd}</span><span class="sigil">$</span><div class="input-wrap">${this._ghost?Re`<div class="ghost" aria-hidden="true"><span class="ghost-pad">${this._input}</span>${this._ghost}</div>`:ji} <input class="input" type="text" aria-label="Terminal command" autocomplete="off" autocapitalize="off" autocorrect="off" spellcheck="false" .value="${this._input}" @input="${this.#I}" @keydown="${this.#y}"></div></form>`}#T(t){return t.kind==="banner"?Re`<div class="banner">Virtual shell over the bundle source tree. Try ${t.commands.map((n,r)=>Re`${r>0?", ":""}\`<span class="cmd" @click="${()=>this.#C(n)}">${n}</span>\``)}. ↑/↓ for history, Tab to complete.</div>`:t.kind==="prompt"?Re`<div class="line"><span class="cwd">${t.cwd}</span>${" "}<span class="sigil">$</span>${" "}${t.text}</div>`:t.kind==="stdout"?this.#_(t):t.kind==="stderr"?Re`<pre class="stderr">${t.text}</pre>`:ji}#_(t){if(!t.diff)return Re`<pre class="stdout">${t.text}</pre>`;let n=t.diff.flatMap((r,i)=>{let o=r.kind?Re`<span class="diff-${r.kind}">${r.text}</span>`:r.text;return i===0?[o]:[`
|
|
266
|
+
`,o]});return Re`<pre class="stdout">${n}</pre>`}};customElements.define("bundle-terminal",qu);function l_(e,t){let n=document.createElement("bundle-terminal");return n.dataset.integrity=t??"",n.sources=e,n}export{l_ as createTerminalElement};
|