From e657726555e1e7a494c5a759547b1d102d54c236 Mon Sep 17 00:00:00 2001 From: panne Date: Wed, 27 Aug 2003 07:50:03 +0000 Subject: [haddock @ 2003-08-27 07:50:02 by panne] * Made -D a short option for --dump-interface. * Made -m a short option for --ms-help. * Made -n a short option for --no-implicit-prelude. * Made -c a short option for --css. * Removed DocBook options from executable (they didn't do anything), but mark them as reserved in the docs. Note that the short option for DocBook output is now -S (from SGML) instead of -d. The latter is now a short option for --debug. * The order of the Options in the documentation now matches the order printed by Haddock itself. Note: Although changing the names of options is often a bad idea, I'd really like to make the options for the programs in fptools more consistent and compatible to the ones used in common GNU programs. --- doc/haddock.sgml | 167 +++++++++++++++++++++++++++++++---------------------- src/HaddockUtil.hs | 15 ++++- src/Main.hs | 58 +++++++++---------- 3 files changed, 137 insertions(+), 103 deletions(-) diff --git a/doc/haddock.sgml b/doc/haddock.sgml index ce1112bc..a74e91fc 100644 --- a/doc/haddock.sgml +++ b/doc/haddock.sgml @@ -225,19 +225,49 @@ - - - - + dir + =dir + + + + Generate files into dir + instead of the current directory. + + + + + path,file + =path,file + + - Output documentation in SGML DocBook format. NOTE: at - time of writing this is only partially implemented and - doesn't work. + Read the interface file in + file, which must have been + produced by running Haddock with the + option. The interface + describes a set of modules whose HTML documentation is + located in path (which may be a + relative pathname). The path is + optional, and defaults to .. + + This option allows Haddock to produce separate sets of + documentation with hyperlinks between them. The + path is used to direct hyperlinks + to point to the right files; so make sure you don't move the + HTML files later or these links will break. Using a + relative path means that a + documentation subtree can still be moved around without + breaking links. + + Multiple options may + be given. + file =file + @@ -254,6 +284,28 @@ + + dir + =dir + + + + + Use auxiliary files in dir. + + + + + + + + + + Reserved for future use (output documentation in SGML DocBook + format). + + + @@ -304,36 +356,9 @@ - path,file - =path,file - - - - Read the interface file in - file, which must have been - produced by running Haddock with the - option. The interface - describes a set of modules whose HTML documentation is - located in path (which may be a - relative pathname). The path is - optional, and defaults to .. - - This option allows Haddock to produce separate sets of - documentation with hyperlinks between them. The - path is used to direct hyperlinks - to point to the right files; so make sure you don't move the - HTML files later or these links will break. Using a - relative path means that a - documentation subtree can still be moved around without - breaking links. - - Multiple options may - be given. - - - - + + @@ -359,24 +384,25 @@ - - - + URL + =URL + + - Don't automatically import Prelude - in every module. Used when producing documentation for the - Prelude itself. + Include links to the source files in the generated + documentation, where URL is the + base URL where the source files can be found. - dir - =dir - - + file + =file + - Generate files into dir - instead of the current directory. + Specify a stylesheet to use instead of the default one + that comes with Haddock. It should specify certain classes: + see the default stylesheet for details. @@ -394,18 +420,6 @@ - - URL - =URL - - - - Include links to the source files in the generated - documentation, where URL is the - base URL where the source files can be found. - - - title =title @@ -421,6 +435,29 @@ + + + + + + + + Don't automatically import Prelude + in every module. Used when producing documentation for the + Prelude itself. + + + + + + + + + + Produce extra debugging output. + + + @@ -440,16 +477,6 @@ Output version information and exit. - - - =filename - - - Specify a stylesheet to use instead of the default one - that comes with Haddock. It should specify certain classes: - see the default stylesheet for details. - - diff --git a/src/HaddockUtil.hs b/src/HaddockUtil.hs index 9804fb6e..20d86b79 100644 --- a/src/HaddockUtil.hs +++ b/src/HaddockUtil.hs @@ -18,7 +18,7 @@ module HaddockUtil ( moduleHtmlFile, -- * Miscellaneous utilities - die, dieMsg, mapSnd, mapMaybeM, + getProgramName, bye, die, dieMsg, mapSnd, mapMaybeM, -- * HTML cross reference mapping html_xrefs_ref, html_xrefs, @@ -26,7 +26,7 @@ module HaddockUtil ( import HsSyn -import List ( intersect ) +import List ( intersect, isSuffixOf ) import Maybe import IO ( hPutStr, stderr ) import System @@ -261,11 +261,20 @@ moduleHtmlFile dir mod0 = dir ++ pathSeparator : mod0 ++ ".html" ----------------------------------------------------------------------------- -- misc. +getProgramName :: IO String +getProgramName = liftM (`withoutSuffix` ".bin") getProgName + where str `withoutSuffix` suff + | suff `isSuffixOf` str = take (length str - length suff) str + | otherwise = str + +bye :: String -> IO a +bye s = putStr s >> exitWith ExitSuccess + die :: String -> IO a die s = hPutStr stderr s >> exitWith (ExitFailure 1) dieMsg :: String -> IO a -dieMsg s = getProgName >>= \prog -> die (prog ++ ": " ++ s) +dieMsg s = getProgramName >>= \prog -> die (prog ++ ": " ++ s) mapSnd :: (b -> c) -> [(a,b)] -> [(a,c)] mapSnd _ [] = [] diff --git a/src/Main.hs b/src/Main.hs index ff85a038..3e4afca2 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -56,17 +56,17 @@ main = do cmdline <- getArgs case getOpt Permute options cmdline of (flags, args, [] ) -> run flags args - (_, _, errors) -> do prog <- getProgName + (_, _, errors) -> do prog <- getProgramName die (concat errors ++ usageInfo (usageHeader prog) options) usageHeader :: String -> String -usageHeader prog = prog ++ " [OPTION...] file...\n" +usageHeader prog = "Usage: " ++ prog ++ " [OPTION...] file...\n" data Flag = Flag_CSS String | Flag_Debug - | Flag_DocBook +-- | Flag_DocBook | Flag_DumpInterface FilePath | Flag_Heading String | Flag_Html @@ -84,32 +84,32 @@ data Flag options :: [OptDescr Flag] options = [ - Option ['d'] ["docbook"] (NoArg Flag_DocBook) - "output in docbook (SGML)", - Option ['D'] ["debug"] (NoArg Flag_Debug) - "extra debugging output", - Option ['h'] ["html"] (NoArg Flag_Html) - "output in HTML", Option ['o'] ["odir"] (ReqArg Flag_OutputDir "DIR") "directory in which to put the output files", - Option ['p'] ["prologue"] (ReqArg Flag_Prologue "FILE") - "file containing prologue text", + Option ['i'] ["read-interface"] (ReqArg Flag_ReadInterface "FILE") + "read an interface from FILE", + Option ['D'] ["dump-interface"] (ReqArg Flag_DumpInterface "FILE") + "dump an interface for these modules in FILE", + Option ['l'] ["lib"] (ReqArg Flag_Lib "DIR") + "location of Haddock's auxiliary files", +-- Option ['S'] ["docbook"] (NoArg Flag_DocBook) +-- "output in docbook (SGML)", + Option ['h'] ["html"] (NoArg Flag_Html) + "output in HTML", + Option ['m'] ["ms-help"] (NoArg Flag_MSHtmlHelp) + "produce Microsoft HTML Help files (with -h)", Option ['s'] ["source"] (ReqArg Flag_SourceURL "URL") "base URL for links to source code", + Option ['c'] ["css"] (ReqArg Flag_CSS "FILE") + "the CSS file to use for HTML output", + Option ['p'] ["prologue"] (ReqArg Flag_Prologue "FILE") + "file containing prologue text", Option ['t'] ["title"] (ReqArg Flag_Heading "TITLE") "page heading", - Option ['i'] ["read-interface"] (ReqArg Flag_ReadInterface "FILE") - "read an interface from FILE", - Option [] ["css"] (ReqArg Flag_CSS "FILE") - "The CSS file to use for HTML output", - Option [] ["dump-interface"] (ReqArg Flag_DumpInterface "FILE") - "dump an interface for these modules in FILE", - Option [] ["lib"] (ReqArg Flag_Lib "DIR") - "Location of Haddock's auxiliary files", - Option [] ["ms-help"] (NoArg Flag_MSHtmlHelp) - "Produce Microsoft HTML Help files (with -h)", - Option [] ["no-implicit-prelude"] (NoArg Flag_NoImplicitPrelude) - "Do not assume Prelude is imported", + Option ['n'] ["no-implicit-prelude"] (NoArg Flag_NoImplicitPrelude) + "do not assume Prelude is imported", + Option ['d'] ["debug"] (NoArg Flag_Debug) + "extra debugging output", Option ['?'] ["help"] (NoArg Flag_Help) "display this help and exit", Option ['V'] ["version"] (NoArg Flag_Version) @@ -122,13 +122,11 @@ saved_flags = unsafePerformIO (newIORef (error "no flags yet")) run :: [Flag] -> [FilePath] -> IO () run flags files = do when (Flag_Help `elem` flags) $ do - prog <- getProgName - putStrLn (usageInfo (usageHeader prog) options) - exitWith ExitSuccess + prog <- getProgramName + bye (usageInfo (usageHeader prog) options) - when (Flag_Version `elem` flags) $ do - putStrLn ("Haddock version " ++ projectVersion ++ ", (c) Simon Marlow 2002") - exitWith ExitSuccess + when (Flag_Version `elem` flags) $ + bye ("Haddock version " ++ projectVersion ++ ", (c) Simon Marlow 2002\n") let title = case [str | Flag_Heading str <- flags] of [] -> "" @@ -265,7 +263,7 @@ parse_file file = do (\h -> do stuff <- hGetContents h case parse stuff (SrcLoc 1 1) 1 0 [] of Ok _ e -> return e - Failed err -> die (file ++ ':':err) + Failed err -> die (file ++ ':':err ++ "\n") ) getPrologue :: [Flag] -> IO (Maybe Doc) -- cgit v1.2.3