tasks a-s

This commit is contained in:
Ingy döt Net 2013-04-10 23:57:08 -07:00
parent 47bf37c096
commit b83f433714
12433 changed files with 156208 additions and 123 deletions

View file

@ -0,0 +1,7 @@
import Data.Char
rot13 :: Char -> Char
rot13 c
| toLower c >= 'a' && toLower c <= 'm' = chr (ord c + 13)
| toLower c >= 'n' && toLower c <= 'z' = chr (ord c - 13)
| otherwise = c

View file

@ -0,0 +1,23 @@
import System.Environment
import System.IO
import System.Directory
import Control.Monad
hInteract :: (String -> String) -> Handle -> Handle -> IO ()
hInteract f hIn hOut =
hGetContents hIn >>= hPutStr hOut . f
processByTemp :: (Handle -> Handle -> IO ()) -> String -> IO ()
processByTemp f name = do
hIn <- openFile name ReadMode
let tmp = name ++ "$"
hOut <- openFile tmp WriteMode
f hIn hOut
hClose hIn
hClose hOut
removeFile name
renameFile tmp name
process :: (Handle -> Handle -> IO ()) -> [String] -> IO ()
process f [] = f stdin stdout
process f ns = mapM_ (processByTemp f) ns

View file

@ -0,0 +1,3 @@
main = do
names <- getArgs
process (hInteract (map rot13)) names