Website Summary Files Commits Branches @commit @diff @stats
path: root / homework / 81248 / cToHtml / app / Main.hs
blob: b504b827c79d67dd92cf88f8e59ef5abe91e7ecf (plain) (blame)
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
module Main
    ( main
    ) where

import qualified Data.ByteString as BS

import           System.Environment (getArgs)

import           Lucid (renderToFile)

import           Clex.Lex (lexC)
import           Html (cToHtml)

main :: IO ()
main = do
    xs <- getArgs
    if length xs /= 3
    then putStrLn usage
    else do
        let [inFile, outFile, col] = xs
        file <- BS.readFile inFile
        renderToFile outFile $ cToHtml col $ either fail id $ lexC file

usage :: String
usage = " \nUsage: cToHtml inFile.c outFile.html <colour>\n\
        \    Converts inFile.c to a colourised version in which all\n\
        \    keywords, identifiers and literals are coloured in <colour>.\n\
        \    We rely on <colour> working in a style tag.\n\
        \    (we basically set \"color:<colour>\" as a style)\n"