Files
HyperionOS/prod/hysh/bin/readlink

2 lines
1.5 KiB
Plaintext

local a=syscall.getTask(syscall.getpid()).name;local b={n=false,f=false,e=false,help=false}local c={}for d,e in ipairs({...})do if e:sub(1,2)=="--"then local f=e:sub(3)if b[f]==nil then print(a..": unrecognized option '"..e.."'")syscall.exit(1)return end;b[f]=true elseif e:sub(1,1)=="-"then for g=2,#e do local f=e:sub(g,g)if b[f]==nil then print(a..": invalid option '-"..f.."'")syscall.exit(1)return end;b[f]=true end else table.insert(c,e)end end;if b.help then print("Usage: "..a.." [OPTION]... FILE...")print("Print the resolved target of symbolic links.")print("")print("Options:")print(" -f canonicalize: follow every symlink; last component need not exist")print(" -e like -f but all components must exist")print(" -n do not output trailing newline")print(" --help display this help and exit")return end;if#c==0 then print(a..": missing operand")print("try '"..a.." --help' for more information.")syscall.exit(1)return end;local function h(i)if i:sub(1,1)~="/"then local j=syscall.getcwd()if j:sub(-1)~="/"then j=j.."/"end;i=j..i end;return i end;local k=false;for d,l in ipairs(c)do l=h(l)if b.f or b.e then local m,n=pcall(syscall.stat,l)if not m then if b.e then print(a..": "..l..": "..tostring(n))k=true else if not b.n then print(l)else printInline(l)end end else if not b.n then print(l)else printInline(l)end end else local m,o=pcall(syscall.readlink,l)if not m then print(a..": "..l..": "..tostring(o))k=true else if not b.n then print(o)else printInline(o)end end end end;if k then syscall.exit(1)end