Permalink
Browse files

Merge pull request #16 from afcowie/output-option

Output option
  • Loading branch information...
2 parents ecbcb1d + 93ccbf8 commit e8b354e42b2166eb9ea139614b0d3e3127f4037d @luqui committed Jun 3, 2014
Showing with 35 additions and 4 deletions.
  1. +1 −0 .gitignore
  2. +16 −3 Main.hs
  3. +17 −0 Makefile
  4. +1 −1 hothasktags.cabal
View
1 .gitignore
@@ -1 +1,2 @@
dist
+tags
View
19 Main.hs
@@ -5,7 +5,7 @@ module Main where
import qualified Language.Haskell.Exts.Annotated as L
import System.Console.CmdArgs
-import System.IO (hPutStrLn, stderr)
+import System.IO (hPutStrLn, stderr, stdout, IOMode(..), openFile, hClose)
import qualified Data.Map as Map
import qualified Language.Preprocessor.Cpphs as CPP
import Control.Monad (forM)
@@ -233,7 +233,7 @@ moduleFile (L.Module (L.SrcSpanInfo (L.SrcSpan file _ _ _ _) _) _ _ _ _) = file
moduleFile _ = error "Wtf is an XmlPage/XmlHybrid?"
data HotHasktags = HotHasktags {
- hh_files, hh_language, hh_define, hh_include, hh_cpphs :: [String] }
+ hh_files, hh_language, hh_define, hh_include, hh_output, hh_cpphs :: [String] }
deriving (Data,Typeable,Show)
defaultHotHasktags :: HotHasktags
@@ -257,6 +257,11 @@ defaultHotHasktags = HotHasktags {
\paths are currently interpreted as relative to the directory \
\containing the source file \
\-Ifoo is a shortcut for -c -Ifoo",
+ hh_output = []
+ &= name "output" &= name "O"
+ &= explicit
+ &= typ "FILE"
+ &= help "Name of output file. Default is to write to stdout",
hh_cpphs = []
&= name "cpp" &= name "c"
&= explicit
@@ -275,4 +280,12 @@ main = do
++ unknown
database <- makeDatabase exts conf
let tags = sort $ concatMap (\mod -> makeTags (moduleFile mod) (moduleScope database mod)) (Map.elems database)
- mapM_ putStrLn tags
+ handle <- case (hh_output conf) of
+ [] -> return stdout
+ file:_ -> openFile file WriteMode
+
+ mapM_ (hPutStrLn handle) tags
+
+ case (hh_output conf) of
+ [] -> return ()
+ _ -> hClose handle
View
17 Makefile
@@ -0,0 +1,17 @@
+all: build tags
+.PHONY: all build install
+
+build: dist/setup-config dist/build/hothasktags/hothasktags
+
+dist/setup-config: hothasktags.cabal
+ cabal install --only-dependencies
+ cabal configure
+
+dist/build/hothasktags/hothasktags: Main.hs
+ cabal build
+
+install:
+ cabal install
+
+tags: build
+ dist/build/hothasktags/hothasktags *.hs > tags
View
2 hothasktags.cabal
@@ -38,7 +38,7 @@ executable hothasktags
containers,
filepath,
haskell-src-exts >= 1.14,
- cpphs >= 1.11 && < 1.17,
+ cpphs >= 1.11 && < 1.19,
cmdargs
main-is: Main.hs
ghc-options: -W

0 comments on commit e8b354e

Please sign in to comment.