import{a as c,b as f,c as d}from"./chunk-74CEPOFO.js";import"./chunk-DXB73IDG.js";var m={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 p(n){return n>=32&&n<=126||n===9}function u(n,s){if(s===null)return"";switch(s){case"o":return`${n.toString(8).padStart(7," ")} `;case"x":return`${n.toString(16).padStart(7," ")} `;case"d":return`${n.toString(10).padStart(7," ")} `;default:return s}}function h(n,s){let o=[],r="",i=0,l=typeof n=="string"?new TextEncoder().encode(n):n;for(let e=0;e<l.length;e++){let t=l[e];if(p(t))r.length===0&&(i=e),r+=String.fromCharCode(t);else{if(r.length>=s.minLength){let a=u(i,s.offsetFormat);o.push(`${a}${r}`)}r=""}}if(r.length>=s.minLength){let e=u(i,s.offsetFormat);o.push(`${e}${r}`)}return o}var N={name:"strings",execute:async(n,s)=>{if(f(n))return c(m);let o={minLength:4,offsetFormat:null},r=[],i=0;for(;i<n.length;){let e=n[i];if(e==="-n"&&i+1<n.length){let t=Number.parseInt(n[i+1],10);if(Number.isNaN(t)||t<1)return{exitCode:1,stdout:"",stderr:`strings: invalid minimum string length: '${n[i+1]}'
`};o.minLength=t,i+=2}else if(e.match(/^-n\d+$/)){let t=Number.parseInt(e.slice(2),10);if(Number.isNaN(t)||t<1)return{exitCode:1,stdout:"",stderr:`strings: invalid minimum string length: '${e.slice(2)}'
`};o.minLength=t,i++}else if(e.match(/^-\d+$/)){let t=Number.parseInt(e.slice(1),10);if(Number.isNaN(t)||t<1)return{exitCode:1,stdout:"",stderr:`strings: invalid minimum string length: '${e.slice(1)}'
`};o.minLength=t,i++}else if(e==="-t"&&i+1<n.length){let t=n[i+1];if(t!=="o"&&t!=="x"&&t!=="d")return{exitCode:1,stdout:"",stderr:`strings: invalid radix: '${t}'
`};o.offsetFormat=t,i+=2}else if(e.startsWith("-t")&&e.length===3){let t=e[2];if(t!=="o"&&t!=="x"&&t!=="d")return{exitCode:1,stdout:"",stderr:`strings: invalid radix: '${t}'
`};o.offsetFormat=t,i++}else if(e==="-a"||e==="--all"||e==="-")e==="-"&&r.push(e),i++;else if(e==="-e"&&i+1<n.length){let t=n[i+1];if(t!=="s"&&t!=="S")return{exitCode:1,stdout:"",stderr:`strings: invalid encoding: '${t}'
`};i+=2}else if(e.startsWith("-e")&&e.length===3){let t=e[2];if(t!=="s"&&t!=="S")return{exitCode:1,stdout:"",stderr:`strings: invalid encoding: '${t}'
`};i++}else if(e==="--"){r.push(...n.slice(i+1));break}else{if(e.startsWith("-")&&e!=="-")return d("strings",e);r.push(e),i++}}let l="";if(r.length===0){let e=s.stdin??"",t=h(e,o);l=t.length>0?`${t.join(`
`)}
`:""}else for(let e of r){let t;if(e==="-")t=s.stdin??"";else{let g=s.fs.resolvePath(s.cwd,e);if(t=await s.fs.readFile(g),t===null)return{exitCode:1,stdout:l,stderr:`strings: ${e}: No such file or directory
`}}let a=h(t,o);a.length>0&&(l+=`${a.join(`
`)}
`)}return{exitCode:0,stdout:l,stderr:""}}};export{N as strings};
