-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbf2steg.hs
50 lines (43 loc) · 1.41 KB
/
bf2steg.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
module Main where
import Data.List
import System.Environment
data Vocab = MoveL | MoveR | Inc | Dec | Out | In | LoopStart | LoopEnd
deriving (Eq, Show)
type Program = [Vocab]
bfToVocab :: Char -> [Vocab]
bfToVocab c
| c == '<' = [MoveL]
| c == '>' = [MoveR]
| c == '+' = [Inc]
| c == '-' = [Dec]
| c == '.' = [Out]
| c == ',' = [In]
| c == '[' = [LoopStart]
| c == ']' = [LoopEnd]
| otherwise = []
bfToProg :: String -> Program
bfToProg s = foldl mappend [] vocabList
where vocabList = bfToVocab <$> s
vocabToString :: Vocab -> String
vocabToString v
| v == MoveL = "Oh yes sir"
| v == MoveR = "Oh yes sir."
| v == Inc = "I can boogie"
| v == Dec = "I can boogie."
| v == Out = "But I need a certain song"
| v == In = "But I need a certain song."
| v == LoopStart = "But I will give you one more chance.."
| v == LoopEnd = "You wanna know if I can dance"
prepCommit :: String -> String -> String
prepCommit author i = "git commit --allow-empty " ++ messageString ++ authorString
where messageString = "-m '" ++ i ++ "' "
authorString = "--author='" ++ author ++ " <a@a>'"
bfToCommits :: String -> String -> String
bfToCommits author bf = intercalate "\n" commits
where commits = prepCommit author . vocabToString <$> bfToProg bf
main :: IO ()
main = do
args <- getArgs
let author = args !! 1
bf <- readFile $ head args
writeFile (author ++ ".sh") $ bfToCommits author bf