GaBuZoMeu/Registry/registry2txt.hs

36 lines
984 B
Haskell
Raw Normal View History

2023-06-08 21:49:35 +02:00
import qualified System.IO
import Registry.Utils
import Registry.Grammar (registry)
import Registry.Registry
infile = "./language-subtag-registry"
displayAll reg thistype =
(foldr (++) "" (map toString
(filter (onlyThisType thistype) reg)))
displayOne reg thistype thisvalue =
concat (map toString
(filter (onlyThisValue thistype thisvalue) reg))
toTextFile reg thetype = do
-- TODO: add the date in the filename
let outfile = "lsr-" ++ thetype ++ ".txt"
f <- System.IO.openFile (outfile) System.IO.WriteMode
System.IO.hPutStr f (displayAll reg thetype)
System.IO.hClose f
foreach [] func = return ()
foreach a func = do
func (head a)
foreach (tail a) func
main = do
f <- System.IO.openFile (infile) System.IO.ReadMode
input <- System.IO.hGetContents f
let theregistry = getRegistry input
foreach ["language", "script", "region", "variant", "redundant", "grandfathered"]
(toTextFile theregistry)