Commit ad65ed56 authored by Björn Peemöller 's avatar Björn Peemöller
Browse files

Added option --htmldir=dir for HTML generation

parent a2e61e50
...@@ -4,6 +4,9 @@ Change log for curry-frontend ...@@ -4,6 +4,9 @@ Change log for curry-frontend
Version 0.3.10 Version 0.3.10
============== ==============
* The HTML generation now accepts an option `--htmldir=dir` to specify
the output directory of the generated HTML files.
* Various improvements of the internal structure. * Various improvements of the internal structure.
* Improved status messages. The compilation status message are now of the form * Improved status messages. The compilation status message are now of the form
......
...@@ -23,6 +23,7 @@ module CompilerOpts ...@@ -23,6 +23,7 @@ module CompilerOpts
) where ) where
import Data.List (intercalate, nub) import Data.List (intercalate, nub)
import Data.Maybe (isJust)
import System.Console.GetOpt import System.Console.GetOpt
import System.Environment (getArgs, getProgName) import System.Environment (getArgs, getProgName)
import System.FilePath (splitSearchPath) import System.FilePath (splitSearchPath)
...@@ -45,6 +46,7 @@ data Options = Options ...@@ -45,6 +46,7 @@ data Options = Options
-- for libraries -- for libraries
, optImportPaths :: [FilePath] -- ^ directories to search in , optImportPaths :: [FilePath] -- ^ directories to search in
-- for imports -- for imports
, optHtmlDir :: Maybe FilePath -- ^ output directory for HTML
, optUseSubdir :: Bool -- ^ use subdir for output? , optUseSubdir :: Bool -- ^ use subdir for output?
, optInterface :: Bool -- ^ create a FlatCurry interface file? , optInterface :: Bool -- ^ create a FlatCurry interface file?
, optPrepOpts :: PrepOpts -- ^ preprocessor options , optPrepOpts :: PrepOpts -- ^ preprocessor options
...@@ -83,6 +85,7 @@ defaultOptions = Options ...@@ -83,6 +85,7 @@ defaultOptions = Options
, optForce = False , optForce = False
, optLibraryPaths = [] , optLibraryPaths = []
, optImportPaths = [] , optImportPaths = []
, optHtmlDir = Nothing
, optUseSubdir = True , optUseSubdir = True
, optInterface = True , optInterface = True
, optPrepOpts = defaultPrepOpts , optPrepOpts = defaultPrepOpts
...@@ -287,7 +290,7 @@ parseOptErr lift what table opt = case lookup3 opt table of ...@@ -287,7 +290,7 @@ parseOptErr lift what table opt = case lookup3 opt table of
renderOptErrTable :: OptErrTable opt -> String renderOptErrTable :: OptErrTable opt -> String
renderOptErrTable ds renderOptErrTable ds
= intercalate "\n" $ map (\(k, d, _) -> rpad maxLen k ++ ": " ++ d) ds = intercalate "\n" $ map (\(k, d, _) -> " " ++ rpad maxLen k ++ ": " ++ d) ds
where where
maxLen = maximum $ map (\(k, _, _) -> length k) ds maxLen = maximum $ map (\(k, _, _) -> length k) ds
rpad n x = x ++ replicate (n - length x) ' ' rpad n x = x ++ replicate (n - length x) ' '
...@@ -305,9 +308,6 @@ options = ...@@ -305,9 +308,6 @@ options =
, Option "" ["numeric-version"] , Option "" ["numeric-version"]
(NoArg (onOpts $ \ opts -> opts { optMode = ModeNumericVersion })) (NoArg (onOpts $ \ opts -> opts { optMode = ModeNumericVersion }))
"show the numeric version number and exit" "show the numeric version number and exit"
, Option "" ["html"]
(NoArg (onOpts $ \ opts -> opts { optMode = ModeHtml }))
"generate html code and exit"
-- verbosity -- verbosity
, mkOptDescr onOpts "v" ["verbosity"] "n" "verbosity level" verbDescriptions , mkOptDescr onOpts "v" ["verbosity"] "n" "verbosity level" verbDescriptions
, Option "q" ["no-verb"] , Option "q" ["no-verb"]
...@@ -325,6 +325,10 @@ options = ...@@ -325,6 +325,10 @@ options =
(ReqArg (withArg onOpts $ \ arg opts -> opts { optImportPaths = (ReqArg (withArg onOpts $ \ arg opts -> opts { optImportPaths =
nub $ optImportPaths opts ++ splitSearchPath arg}) "dir[:dir]") nub $ optImportPaths opts ++ splitSearchPath arg}) "dir[:dir]")
"search for imports in dir[:dir]" "search for imports in dir[:dir]"
, Option [] ["htmldir"]
(ReqArg (withArg onOpts $ \ arg opts -> opts { optHtmlDir =
Just arg }) "dir")
"write HTML documentation into directory `dir'"
, Option "" ["no-subdir"] , Option "" ["no-subdir"]
(NoArg (onOpts $ \ opts -> opts { optUseSubdir = False })) (NoArg (onOpts $ \ opts -> opts { optUseSubdir = False }))
("disable writing to `" ++ currySubdir ++ "' subdirectory") ("disable writing to `" ++ currySubdir ++ "' subdirectory")
...@@ -340,6 +344,9 @@ options = ...@@ -340,6 +344,9 @@ options =
addFlag WarnOverlapping (wnWarnFlags opts) })) addFlag WarnOverlapping (wnWarnFlags opts) }))
"do not print warnings for overlapping rules" "do not print warnings for overlapping rules"
-- target types -- target types
, Option "" ["html"]
(NoArg (onOpts $ \ opts -> opts { optMode = ModeHtml }))
"generate html code and exit"
, Option "" ["parse-only"] , Option "" ["parse-only"]
(NoArg (onOpts $ \ opts -> opts { optTargetTypes = (NoArg (onOpts $ \ opts -> opts { optTargetTypes =
nub $ Parsed : optTargetTypes opts })) nub $ Parsed : optTargetTypes opts }))
...@@ -439,11 +446,18 @@ removeFlag o opts = filter (/= o) opts ...@@ -439,11 +446,18 @@ removeFlag o opts = filter (/= o) opts
-- |Parse the command line arguments -- |Parse the command line arguments
parseOpts :: [String] -> (Options, [String], [String]) parseOpts :: [String] -> (Options, [String], [String])
parseOpts args = (opts, files, errs ++ errs2) parseOpts args = (opts, files, errs ++ errs2 ++ checkOpts opts files)
where where
(opts, errs2) = foldl (flip ($)) (defaultOptions, []) optErrs (opts, errs2) = foldl (flip ($)) (defaultOptions, []) optErrs
(optErrs, files, errs) = getOpt Permute options args (optErrs, files, errs) = getOpt Permute options args
-- |Check options and files and return a list of error messages
checkOpts :: Options -> [String] -> [String]
checkOpts opts _
| isJust (optHtmlDir opts) && (optMode opts) /= ModeHtml
= ["The option '--htmldir' is only valid for HTML generation mode"]
| otherwise = []
-- |Print the usage information of the command line tool. -- |Print the usage information of the command line tool.
usage :: String -> String usage :: String -> String
usage prog = usageInfo header options usage prog = usageInfo header options
......
...@@ -18,11 +18,11 @@ import Control.Monad.Trans.Either ...@@ -18,11 +18,11 @@ import Control.Monad.Trans.Either
import Data.Char (toLower) import Data.Char (toLower)
import Data.Maybe (fromMaybe, isJust) import Data.Maybe (fromMaybe, isJust)
import System.FilePath ((</>), dropFileName, takeBaseName)
import Curry.Base.Ident (QualIdent (..), unqualify) import Curry.Base.Ident (QualIdent (..), unqualify)
import Curry.Base.Message import Curry.Base.Message
import Curry.Base.Pretty (text) import Curry.Base.Pretty (text)
import Curry.Files.Filenames (dropExtension, takeFileName)
import Curry.Files.PathUtils (readModule, lookupCurryFile) import Curry.Files.PathUtils (readModule, lookupCurryFile)
import Curry.Syntax (Module, lexSource, parseModule) import Curry.Syntax (Module, lexSource, parseModule)
...@@ -37,12 +37,12 @@ import Modules (loadAndCheckModule, checkModuleHeader) ...@@ -37,12 +37,12 @@ import Modules (loadAndCheckModule, checkModuleHeader)
--- @param sourcefilename --- @param sourcefilename
source2html :: Options -> FilePath -> CYIO () source2html :: Options -> FilePath -> CYIO ()
source2html opts f = do source2html opts f = do
let baseName = dropExtension f let baseName = takeBaseName f
modulname = takeFileName baseName outDir = fromMaybe (dropFileName f) $ optHtmlDir opts
outFile = baseName ++ "_curry.html" outFile = outDir </> baseName ++ "_curry.html"
srcFile <- liftIO $ lookupCurryFile (optImportPaths opts) f srcFile <- liftIO $ lookupCurryFile (optImportPaths opts) f
program <- filename2program opts (fromMaybe f srcFile) program <- filename2program opts (fromMaybe f srcFile)
liftIO $ writeFile outFile (program2html modulname program) liftIO $ writeFile outFile (program2html baseName program)
--- @param importpaths --- @param importpaths
--- @param filename --- @param filename
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment