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

Added option --htmldir=dir for HTML generation

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