Last active
October 12, 2017 08:35
-
-
Save serian/9829665 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- | |
RAZIEのお気に入りをDRAIEXに変換する | |
-} | |
import Data.ConfigFile | |
import Data.Either.Utils | |
import Data.Map | |
secds = [ | |
("NAME","Comment"), | |
("WORD", "Text"), | |
("AREC", "Rec"), | |
("APLY", ""), | |
("ICON", ""), | |
("PATH", "RecPath"), | |
("MAIL", "")] | |
secxdic = fromList secds | |
nopts = ["NAME","WORD","AREC","APLY","ICON","PATH","MAIL"] | |
typedic = fromList[("0", "[NAME]"), ("1", "[GENRE]"), ("2", "[M3U]"), ("3", "[URL]"), ("4", "[URL]"), ("5", "[MAIN]")] | |
main = do | |
val <- readfile emptyCP "Reserve.dat" | |
let cp = forceEither val | |
secs = tail $ sections cp | |
makeSecOut n cp [] nsecs = nsecs | |
makeSecOut n cp (sec:secs) nsecs = makeSecOut (n+1) cp secs $ Prelude.map tuple2str (makeSec n cp sec) : nsecs | |
putStrLn "[FAVORITE]" | |
printList2 $ reverse $ makeSecOut 0 cp secs [] | |
tuple2str :: (String, String) -> String | |
tuple2str t = fst t ++ "=" ++ snd t | |
makeSec :: Int -> ConfigParser -> SectionSpec -> [(String, String)] | |
makeSec n cp sec = let optsmap = fromList $ forceEither $ items cp sec | |
in reverse $ modSec n optsmap $ Prelude.map (\x -> (x, findWithDefault "" (findWithDefault "" x secxdic) optsmap)) nopts | |
modSec :: Int -> Map String String -> [(String, String)] -> [(String, String)] | |
modSec n optmap = Prelude.map (\t -> case fst t of | |
"WORD" -> ("WORD" ++ show n, findWithDefault "" (findWithDefault "" "Type" optmap) typedic ++ snd t) | |
"ICON" -> ("ICON" ++ show n, "Icon001.bmp") | |
otherwise -> (fst t ++ show n, snd t)) | |
printList2 :: [[String]] -> IO () | |
printList2 [] = putStr "" | |
printList2 (xs:xss) = do printList2in xs | |
printList2 xss | |
where printList2in [] = putStr "" | |
printList2in (x:xs) = do printList2in xs | |
putStrLn x | |
-- mapM (writeSec cp) secs | |
-- putStrLn $ show $ length secs | |
-- putStrLn $ show $ take 10 $ mapM (forceEither . items cp) secs | |
-- putStrLn $ show $ forceEither $ options cp "Item1" | |
-- putStrLn $ show $ length $ sections cp | |
-- mapM putStrLn $ sections cp | |
-- putStrLn $ forceEither $ get cp "file1" "user" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment