forked from bortzmeyer/GaBuZoMeu
41 lines
1.2 KiB
Haskell
41 lines
1.2 KiB
Haskell
import qualified System.IO as IO
|
|
|
|
import Registry.Utils
|
|
import Registry.Grammar (registry)
|
|
import Registry.Registry
|
|
|
|
import System.Directory (createDirectoryIfMissing)
|
|
|
|
infile = "./language-subtag-registry"
|
|
outdir = "./registry-html"
|
|
|
|
display reg thistype thisvalue =
|
|
-- We should always retrieve only one value, so we can take the head
|
|
toHTML ((filter (onlyThisValue thistype thisvalue)
|
|
(filter (onlyThisType thistype) reg)) !! 0)
|
|
|
|
toHTMLFiles reg thetype =
|
|
mapM (toHTMLfile reg thetype) (filter (onlyThisType thetype) reg)
|
|
|
|
toHTMLfile reg thistype thisvalue = do
|
|
let outfile = outdir ++ "/" ++ thistype ++ "/" ++ (toSubtag thisvalue) ++ ".html"
|
|
f <- IO.openFile (outfile) IO.WriteMode
|
|
IO.hPutStr f (display reg thistype (toSubtag thisvalue))
|
|
IO.hClose f
|
|
|
|
foreach [] func = return ()
|
|
foreach a func = do
|
|
func (head a)
|
|
foreach (tail a) func
|
|
|
|
main = do
|
|
f <- IO.openFile (infile) IO.ReadMode
|
|
input <- IO.hGetContents f
|
|
let theregistry = getRegistry input
|
|
foreach ["language", "script", "region", "variant",
|
|
"redundant", "grandfathered"]
|
|
(\arg ->
|
|
createDirectoryIfMissing True (outdir ++ "/" ++ arg) >>
|
|
toHTMLFiles theregistry arg)
|
|
|