Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
import System.Environment
import System.IO
data ArEntry = ArEntry {
fileName :: String, -- 0 15 File name ASCII
fileDate :: String, -- 16 27 File date Decimal
ownerID :: String, -- 28 33 Owner ID Decimal
groupID :: String, -- 34 39 Group ID Decimal
fileMode :: String, -- 40 47 File mode Octal
fileSize :: String, -- 48 57 File size Decimal
-- 58 59 Header magic "`\n"
fileData :: String -- 60 60+size File data
} deriving Show
main = do
[arFile] <- getArgs
hnd <- openBinaryFile arFile ReadMode
"!\n" <- hGetChars hnd 8
let loop = do
entry <- hGetArEntry hnd
print (fileName entry)
eof <- hIsEOF hnd
if eof then return ()
else loop
loop
hGetArEntry :: Handle -> IO ArEntry
hGetArEntry hnd = do
name <- hGetChars hnd 16
date <- hGetChars hnd 12
owner <- hGetChars hnd 6
group <- hGetChars hnd 6
mode <- hGetChars hnd 8
size <- hGetChars hnd 10
"`\n" <- hGetChars hnd 2
fdata <- hGetChars hnd (read size)
offset <- hTell hnd
eof <- hIsEOF hnd
if offset `mod` 2 == 0 || eof
then return ()
else do '\n' <- hGetChar hnd
return ()
return ArEntry {
fileName = name,
fileDate = date,
ownerID = owner,
groupID = group,
fileMode = mode,
fileSize = size,
fileData = fdata
}
hGetChars hnd n = mapM (\_ -> System.IO.hGetChar hnd) [1..n]