import{n as e,r as t,t as n}from"./chunk-74CEPOFO-V0JXh91S.mjs";var r={name:`strings`,summary:`print the sequences of printable characters in files`,usage:`strings [OPTION]... [FILE]...`,description:`For each FILE, print the printable character sequences that are at least MIN characters long. If no FILE is specified, standard input is read.`,options:[`-n MIN       Print sequences of at least MIN characters (default: 4)`,`-t FORMAT    Print offset before each string (o=octal, x=hex, d=decimal)`,`-a           Scan the entire file (default behavior)`,`-e ENCODING  Select character encoding (s=7-bit, S=8-bit)`],examples:[`strings file.bin          # Extract strings (min 4 chars)`,`strings -n 8 file.bin     # Extract strings (min 8 chars)`,`strings -t x file.bin     # Show hex offset`,`echo 'hello' | strings    # Read from stdin`]};function i(e){return e>=32&&e<=126||e===9}function a(e,t){if(t===null)return``;switch(t){case`o`:return`${e.toString(8).padStart(7,` `)} `;case`x`:return`${e.toString(16).padStart(7,` `)} `;case`d`:return`${e.toString(10).padStart(7,` `)} `;default:return t}}function o(e,t){let n=[],r=``,o=0,s=typeof e==`string`?new TextEncoder().encode(e):e;for(let e=0;e<s.length;e++){let c=s[e];if(i(c))r.length===0&&(o=e),r+=String.fromCharCode(c);else{if(r.length>=t.minLength){let e=a(o,t.offsetFormat);n.push(`${e}${r}`)}r=``}}if(r.length>=t.minLength){let e=a(o,t.offsetFormat);n.push(`${e}${r}`)}return n}var s={name:`strings`,execute:async(i,a)=>{if(n(i))return t(r);let s={minLength:4,offsetFormat:null},c=[],l=0;for(;l<i.length;){let t=i[l];if(t===`-n`&&l+1<i.length){let e=Number.parseInt(i[l+1],10);if(Number.isNaN(e)||e<1)return{exitCode:1,stdout:``,stderr:`strings: invalid minimum string length: '${i[l+1]}'
`};s.minLength=e,l+=2}else if(t.match(/^-n\d+$/)){let e=Number.parseInt(t.slice(2),10);if(Number.isNaN(e)||e<1)return{exitCode:1,stdout:``,stderr:`strings: invalid minimum string length: '${t.slice(2)}'
`};s.minLength=e,l++}else if(t.match(/^-\d+$/)){let e=Number.parseInt(t.slice(1),10);if(Number.isNaN(e)||e<1)return{exitCode:1,stdout:``,stderr:`strings: invalid minimum string length: '${t.slice(1)}'
`};s.minLength=e,l++}else if(t===`-t`&&l+1<i.length){let e=i[l+1];if(e!==`o`&&e!==`x`&&e!==`d`)return{exitCode:1,stdout:``,stderr:`strings: invalid radix: '${e}'
`};s.offsetFormat=e,l+=2}else if(t.startsWith(`-t`)&&t.length===3){let e=t[2];if(e!==`o`&&e!==`x`&&e!==`d`)return{exitCode:1,stdout:``,stderr:`strings: invalid radix: '${e}'
`};s.offsetFormat=e,l++}else if(t===`-a`||t===`--all`||t===`-`)t===`-`&&c.push(t),l++;else if(t===`-e`&&l+1<i.length){let e=i[l+1];if(e!==`s`&&e!==`S`)return{exitCode:1,stdout:``,stderr:`strings: invalid encoding: '${e}'
`};l+=2}else if(t.startsWith(`-e`)&&t.length===3){let e=t[2];if(e!==`s`&&e!==`S`)return{exitCode:1,stdout:``,stderr:`strings: invalid encoding: '${e}'
`};l++}else if(t===`--`){c.push(...i.slice(l+1));break}else{if(t.startsWith(`-`)&&t!==`-`)return e(`strings`,t);c.push(t),l++}}let u=``;if(c.length===0){let e=o(a.stdin??``,s);u=e.length>0?`${e.join(`
`)}
`:``}else for(let e of c){let t;if(e===`-`)t=a.stdin??``;else{let n=a.fs.resolvePath(a.cwd,e);if(t=await a.fs.readFile(n),t===null)return{exitCode:1,stdout:u,stderr:`strings: ${e}: No such file or directory
`}}let n=o(t,s);n.length>0&&(u+=`${n.join(`
`)}
`)}return{exitCode:0,stdout:u,stderr:``}}},c={name:`strings`,flags:[{flag:`-n`,type:`value`,valueHint:`number`},{flag:`-t`,type:`value`,valueHint:`string`},{flag:`-a`,type:`boolean`},{flag:`-e`,type:`value`,valueHint:`string`}],stdinType:`text`,needsFiles:!0};export{s as n,c as t};
//# sourceMappingURL=chunk-VYOJP4TV-DN1CSkP5.mjs.map