Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,11 @@
import Data.Char (chr, isAlpha, ord, toLower)
import Data.Bool (bool)
rot13 :: Char -> Char
rot13 c
| isAlpha c = chr $ bool (-) (+) ('m' >= toLower c) (ord c) 13
| otherwise = c
-- Simple test
main :: IO ()
main = print $ rot13 <$> "Abjurer nowhere"

View file

@ -0,0 +1,11 @@
import Data.Char (chr, isAlpha, ord, toLower)
import Data.Bool (bool)
rot13 :: Char -> Char
rot13 =
let rot = flip ((bool (-) (+) . ('m' >=) . toLower) <*> ord)
in (bool <*> chr . rot 13) <*> isAlpha
-- Simple test
main :: IO ()
main = print $ rot13 <$> "Abjurer nowhere"

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